Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Material de aula

  • Loading branch information...
commit b86758f98cd48a1a2bd1caaf269ba910c8368279 1 parent 6ecaf2f
Christiano Milfont authored
6 app/assets/javascripts/app.js
View
@@ -0,0 +1,6 @@
+Ext.application({
+ name: "Workout",
+ appFolder: "/assets",
+ autoCreateViewport: true,
+ controllers: ['Exercicios']
+});
31 app/assets/javascripts/controller/Exercicios.js
View
@@ -0,0 +1,31 @@
+Ext.define('Workout.controller.Exercicios', {
+ extend: 'Ext.app.Controller',
+ requires: [ 'Workout.store.Exercicios'],
+ models: ['Exercicio'],
+ stores: ['Exercicios'],
+ views: ['exercicios.Grid', 'exercicios.Form', 'exercicios.Window'],
+ addTabPanel: function(button) {
+ console.log("Clicou em exercicio", this);
+ var tabpanel = Ext.ComponentQuery
+ .query("tabpanel[itemId='tabs']")[0];
+
+ tabpanel.addTab({
+ title: "Exercícios",
+ itemId: "tab-" + button.text,
+ closable: true,
+ xtype: 'exerciciogrid'
+ });
+ },
+ init: function() {
+ this.control({
+ "#exercicios": {
+ click: this.addTabPanel
+ },
+ "exerciciogrid": {
+ afterrender: function(grid) {
+ grid.store.load();
+ }
+ }
+ });
+ }
+});
7 app/assets/javascripts/model/Exercicio.js
View
@@ -0,0 +1,7 @@
+Ext.define('Workout.model.Exercicio', {
+ extend: 'Ext.data.Model',
+ fields: ['id','titulo', 'descricao'],
+ proxy: {
+ type: 'rest', format: 'json', url: '/exercicios'
+ }
+});
7 app/assets/javascripts/model/Item.js
View
@@ -0,0 +1,7 @@
+Ext.define('Workout.model.Item', {
+ extend: 'Ext.data.Model',
+ fields: [
+ 'id','repeticao', 'tempo', 'rotina_id', 'exercicio_id'
+ ],
+ belongsTo:[{model: 'Workout.model.Exercicio', associationKey: 'exercicio', getterName: 'exercicio'}]
+});
8 app/assets/javascripts/model/Rotina.js
View
@@ -0,0 +1,8 @@
+Ext.define('Workout.model.Rotina', {
+ extend: 'Ext.data.Model',
+ proxy: {
+ type: 'rest', format: 'json', url: '/rotinas'
+ },
+ fields: ['titulo', 'id'],
+ hasMany: [{model: "Workout.model.Item", name: "itens", associationKey: 'itens'}]
+});
5 app/assets/javascripts/store/Exercicios.js
View
@@ -0,0 +1,5 @@
+Ext.define('Workout.store.Exercicios', {
+ alias: 'store.exercicios',
+ extend: 'Ext.data.Store',
+ model: "Workout.model.Exercicio"
+});
5 app/assets/javascripts/store/Rotinas.js
View
@@ -0,0 +1,5 @@
+Ext.define('Workout.store.Rotinas', {
+ alias: 'store.rotinas',
+ extend: 'Ext.data.Store',
+ model: "Workout.model.Rotina"
+});
21 app/assets/javascripts/view/DashboardTabPanel.js
View
@@ -0,0 +1,21 @@
+Ext.define('Workout.view.DashboardTabPanel', {
+ alias: 'widget.dtabpanel',
+ extend: 'Ext.tab.Panel',
+ itemId: "tabs",
+ frame: true,
+ style: {
+ backgroundColor: "#3C8FC0"
+ },
+ activeTab: 0,
+ items: [{
+ title: 'Dashboard',
+ xtype: "panel",
+ html: 'Dashboard com os dados do usuaário'
+ }],
+
+ addTab: function(panel) {
+ var tab = this.down("[itemId='tab-" + panel.title + "']");
+ if(!tab) tab = this.add(panel);
+ this.setActiveTab(tab);
+ }
+});
24 app/assets/javascripts/view/DashboardToolbar.js
View
@@ -0,0 +1,24 @@
+Ext.define('Workout.view.DashboardToolbar', {
+ alias: 'widget.dtoolbar',
+ extend: 'Ext.toolbar.Toolbar',
+ style: {
+ backgroundColor: "#3C8FC0"
+ },
+ items: [
+ { xtype: 'tbtext', text: 'Workout', cls: 'home_title' },
+ '->',
+ { xtype: 'button', overCls: 'home_menu_over', cls: 'home_menu', pressedCls: "home_pressed", text: 'Rotinas', itemId: 'rotinas'},
+ { xtype: 'button', overCls: 'home_menu_over', cls: 'home_menu', pressedCls: "home_pressed", text: 'Treinos', itemId: 'treinos'},
+ { xtype: 'button', overCls: 'home_menu_over', cls: 'home_menu', pressedCls: "home_pressed", text: 'Exercícios', itemId: 'exercicios'},
+ {
+ xtype: 'splitbutton', overCls: 'home_split_over', cls: 'home_split', text : 'Perfil',
+ menu: {
+ items: [
+ {text: 'Item 1', handler: function(){ alert("Item 1 clicked"); }},
+ {text: 'Item 2', handler: function(){ alert("Item 2 clicked"); }}
+ ]
+ }
+ },
+ { xtype: 'tbspacer', width: 50 }
+ ]
+});
10 app/assets/javascripts/view/Viewport.js
View
@@ -0,0 +1,10 @@
+Ext.define('Workout.view.Viewport', {
+ extend: 'Ext.container.Viewport',
+ layout: 'border',
+ requires: ['Workout.view.DashboardTabPanel',
+ 'Workout.view.DashboardToolbar'],
+ items: [
+ { region: 'north', xtype: 'dtoolbar' },
+ { region: 'center', xtype: 'dtabpanel' }
+ ]
+})
28 app/assets/javascripts/view/exercicios/Crud.js
View
@@ -0,0 +1,28 @@
+Ext.define("Workout.view.exercicios.Crud", {
+ abrirJanela: function(button) {
+
+ var model = null;
+ if(button.text != "Cadastrar") {
+ model = this.getSelectionModel().selected.first();
+ if(!model) {
+ Ext.Error.notify = true;
+ Ext.Error.raise({ msg: 'Selecione um Exercício para editar' });
+ }
+
+ }
+
+ Ext.widget("exerciciowindow", {
+ title: "Salvar exercício",
+ boundary: this,
+ items: [{
+ xtype: "exercicioform",
+ callbackSave: this.adicionar,
+ callbackSaveScope: this,
+ exercicio: model
+ }]
+ }).show();
+ },
+ adicionar: function(model) {
+ this.store.loadData([model], true);
+ }
+});
33 app/assets/javascripts/view/exercicios/Form.js
View
@@ -0,0 +1,33 @@
+Ext.define("Workout.view.exercicios.Form", {
+ extend: "Ext.form.Panel",
+ alias: ["widget.exercicioform"],
+ frame: true,
+ items: [
+ {xtype: "hidden", name: "id"},
+ {xtype: "textfield", fieldLabel: "Título", name: "titulo"},
+ {xtype: "textfield", fieldLabel: "Descrição", name: "descricao"}
+ ],
+ initComponent: function() {
+ this.callParent();
+ if( this.exercicio )
+ this.getForm().loadRecord( this.exercicio );
+ },
+ callbackSave: Ext.emptyFn,
+ buttons: [
+ {
+ text: "Salvar",
+ handler: function() {
+ var panel = this.up("exercicioform");
+ var form = panel.getForm();
+ var json = form.getValues();
+ var model = Ext.create("Workout.model.Exercicio", json);
+ model.save({
+ callback: function() {
+ panel.callbackSave.call(panel.callbackSaveScope || panel,
+ model)
+ }
+ })
+ }
+ }
+ ]
+});
22 app/assets/javascripts/view/exercicios/Grid.js
View
@@ -0,0 +1,22 @@
+Ext.define("Workout.view.exercicios.Grid", {
+ extend: "Ext.grid.Panel",
+ alias: ["widget.exerciciogrid"],
+ mixins: {
+ crud: "Workout.view.exercicios.Crud"
+ },
+ columns: [
+ {text: "Título", dataIndex: "titulo"},
+ {text: "Descrição", dataIndex: "descricao"}
+ ],
+ selModel: {
+ allowDeselect: true
+ },
+ initComponent: function() {
+ this.tbar = [
+ { text: "Cadastrar", handler: this.abrirJanela, scope: this},
+ { text: "Editar", handler: this.abrirJanela, scope: this}
+ ];
+ this.callParent();
+ },
+ store: Ext.createByAlias("store.exercicios")
+});
17 app/assets/javascripts/view/exercicios/Window.js
View
@@ -0,0 +1,17 @@
+Ext.define("Workout.view.exercicios.Window", {
+ extend: "Ext.window.Window",
+ alias: ["widget.exerciciowindow"],
+ initComponent: function() {
+ var boundary = this.boundary;
+ if(boundary) {
+ this.renderTo = boundary.el.dom;
+ this.constrain = true;
+ this.on({
+ show: boundary.mask,
+ close: boundary.unmask,
+ scope: boundary
+ });
+ }
+ this.callParent();
+ }
+})
24 app/controllers/exercicios_controller.rb
View
@@ -4,7 +4,29 @@ class ExerciciosController < ApplicationController
def index
@exercicios = Exercicio.all
- respond_with @exercicios
+ respond_with @exercicios
+ end
+
+ def show
+ @exercicio = Exercicio.find params[:id]
+ respond_with @exercicio
+ end
+
+ def create
+ @exercicio = Exercicio.create params[:exercicio]
+ respond_with @exercicio
+ end
+
+ def update
+ @exercicio = Exercicio.find params[:id]
+ @exercicio.update_attributes params[:exercicio]
+ respond_with @exercicio
+ end
+
+ def destroy
+ @exercicio = Exercicio.find params[:id]
+ @exercicio.destroy
+ respond_with @exercicio
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.