Permalink
Browse files

Implementação de comportamento dos botões de Rotina

  • Loading branch information...
1 parent 00e4516 commit ef4c35cab321065896ca8fb3b37fff0b9d0ef6af @cmilfont committed Dec 22, 2012
View
2 app/assets/javascripts/controller/Rotinas.js
@@ -1,6 +1,6 @@
Ext.define('Workout.controller.Rotinas', {
extend: 'Ext.app.Controller',
- views: ['rotina.List', 'rotina.Form'],
+ views: ['rotina.List', 'rotina.Form', 'exercicio.Combo'],
models: ['Rotina', 'Item', 'Exercicio'],
init: function() {
this.control({
View
5 app/assets/javascripts/model/Exercicio.js
@@ -1,4 +1,7 @@
Ext.define('Workout.model.Exercicio', {
extend: 'Ext.data.Model',
- fields: ['id','titulo', 'descricao']
+ fields: ['id','titulo', 'descricao'],
+ proxy: {
+ type: 'rest', format: 'json', url: '/exercicios'
+ }
});
View
1 app/assets/javascripts/store/RotinaStore.js
@@ -23,6 +23,7 @@ Ext.define('Workout.store.RotinaStore', {
adicionarItem: function(item){
this.appendChild({
leaf: true,
+ item: item,
exercicio: item.exercicio().get("titulo")
})
}
View
11 app/assets/javascripts/view/Viewport.js
@@ -5,11 +5,8 @@ Ext.define('Workout.view.Viewport', {
style: {
backgroundColor: "#3C8FC0"
},
- initComponent: function() {
- this.items = [
- { region: 'north', xtype: 'dtoolbar' },
- { region: 'center', xtype: 'dtabpanel' }
- ];
- this.callParent();
- }
+ items: [
+ { region: 'north', xtype: 'dtoolbar' },
+ { region: 'center', xtype: 'dtabpanel' }
+ ]
});
View
31 app/assets/javascripts/view/exercicio/Combo.js
@@ -0,0 +1,31 @@
+Ext.define("Workout.view.exercicio.Combo", {
+ extend: 'Ext.form.field.ComboBox',
+ alias: ["widget.exerciciocombo"],
+ name: "exercicio_id",
+ displayField: 'titulo',
+ valueField: 'id',
+ fieldLabel: 'Exercício',
+ store: { model: "Workout.model.Exercicio" },
+ template: '<div>{titulo} - <a data-id="{id}">editar</a> </div>',
+ setupListConfig: function() {
+ var combo = this;
+ return {
+ getInnerTpl: function() {
+ return combo.template;
+ },
+ listeners: {
+ el: {
+ click: function(evento, el) {
+ var id = evento.getTarget().getAttribute("data-id");
+ console.log("Id dele: ", id);
+ return false;
+ }
+ }
+ }
+ };
+ },
+ initComponent: function() {
+ this.listConfig = this.setupListConfig();
+ this.callParent();
+ },
+});
View
5 app/assets/javascripts/view/rotina/Form.js
@@ -1,8 +1,3 @@
-//1 - adicionar um hidden no form para o id
-//2 - passar um model na config do form e setar no Basic com loadRecod
-//3 - quando clicar no save, pegar o model original via getRecord
-//4 - save e quando terminar, atualizar o item na tree
-
Ext.define('Workout.view.rotina.Form', {
extend: 'Ext.form.Panel',
alias: 'widget.rotinaform',
View
36 app/assets/javascripts/view/rotina/List.js
@@ -16,7 +16,8 @@ Ext.define('Workout.view.rotina.List', {
this.tbar = [
{ xtype: 'button', text: 'Cadastrar' , pressed: true, handler: this.abrirJanela, scope: this},
{ xtype: 'button', text: 'Editar', itemId: 'editar', disabled: true, pressed: true, handler: this.abrirJanela, scope: this },
- { xtype: 'button', text: 'Excluir', itemId: 'excluir', disabled: true, pressed: true, handler: this.excluir, scope: this }
+ { xtype: 'button', text: 'Excluir', itemId: 'excluir', disabled: true, pressed: true, handler: this.excluir, scope: this },
+ "-"
];
this.callParent(arguments);
this.on({
@@ -71,12 +72,37 @@ Ext.define('Workout.view.rotina.List', {
}
},
- desabilitarAoSelecionar: function() {
+ desabilitarAoSelecionar: function(rowModel, model, index, eOpts) {
this.down("#editar").disable();
this.down("#excluir").disable();
+
+ var vincular = this.down("#vincular"),
+ editarexercicio = this.down("#editarexercicio"),
+ desvincular = this.down("#desvincular");
+ if(vincular) vincular.destroy();
+ if(editarexercicio) editarexercicio.destroy();
+ if(desvincular) desvincular.destroy();
},
- habilitarAoSelecionar: function() {
- this.down("#editar").enable();
- this.down("#excluir").enable();
+ habilitarAoSelecionar: function(rowModel, model, index, eOpts) {
+ var docked = this.getDockedItems()[0];
+ if(!model.raw.item) {
+ this.down("#editar").enable();
+ this.down("#excluir").enable();
+ docked.add({ text: "Vincular Exercicio", handler: this.vincularExercicio, pressed: true, itemId: "vincular" })
+ } else {
+ docked.add({ text: "Editar Exercicio", handler: function(){}, pressed: true, itemId: "editarexercicio" })
+ docked.add({ text: "Desvincular Exercicio", handler: function(){}, pressed: true, itemId: "desvincular" })
+ }
+ },
+ vincularExercicio: function() {
+ var tree = this;
+ Ext.create("Ext.window.Window", {
+ items: [{
+ xtype: "form", itemId: "exercicioForm", width: 400,
+ items:[
+ {xtype: "exerciciocombo"}
+ ]
+ }]
+ }).show()
}
});
View
10 app/controllers/exercicios_controller.rb
@@ -0,0 +1,10 @@
+class ExerciciosController < ApplicationController
+
+ respond_to :json, :html
+
+ def index
+ @exercicios = Exercicio.all
+ respond_with @exercicios
+ end
+
+end
View
2 app/helpers/exercicios_helper.rb
@@ -0,0 +1,2 @@
+module ExerciciosHelper
+end
View
2 app/models/rotina.rb
@@ -1,5 +1,5 @@
class Rotina < ActiveRecord::Base
attr_accessible :titulo
has_many :itens
- #validates_presence_of :titulo
+ validates_presence_of :titulo
end
View
1 config/routes.rb
@@ -1,6 +1,7 @@
Workout::Application.routes.draw do
resources :rotinas
+ resources :exercicios
root :to => 'home#index'

0 comments on commit ef4c35c

Please sign in to comment.