Skip to content

Commit

Permalink
não lembro, mas foi refactorings gostosos
Browse files Browse the repository at this point in the history
  • Loading branch information
cmilfont committed Feb 19, 2013
1 parent 0450619 commit ba3bbff
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 35 deletions.
7 changes: 4 additions & 3 deletions app/assets/javascripts/app/controller/Dashboard.js
Expand Up @@ -2,9 +2,10 @@ Ext.define('Workout.controller.Dashboard', {
extend: 'Ext.app.Controller',
loadController: function(button) {
if(button.controller) {
Workout.getApplication()
.getController( button.controller )
.init(button);
var controller = Workout.getApplication()
.getController( button.controller );
if (!controller._initialized) controller.init();
controller.addTabPanel(button);
}
},
init: function() {
Expand Down
31 changes: 14 additions & 17 deletions app/assets/javascripts/app/controller/Exercicios.js
Expand Up @@ -6,36 +6,33 @@
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) {
var tabpanel = Ext.ComponentQuery.query("dtabpanel")[0];

tabpanel.addTab({
//models: ['Exercicio'],
//stores: ['Exercicios'],
// views: [
// 'exercicios.Grid',
// 'exercicios.Form',
// 'exercicios.Window'
// ],
addTabPanel: function(button) {
this.getTabPanel().addTab({
title: "Exercícios",
itemId: "tab-" + button.controller,
closable: true,
controller: button.controller,
xtype: 'exerciciogrid'
});

},
init: function(button) {

init: function() {
this.control({
"exerciciogrid": {
afterrender: function(grid) {
grid.store.load();
}
}
});

this.addTabPanel(button);

this._initialized = true;
},
getTabPanel: function() {
return Ext.ComponentQuery.query("dtabpanel")[0];
}
});
16 changes: 6 additions & 10 deletions app/assets/javascripts/app/controller/Rotinas.js
Expand Up @@ -20,8 +20,8 @@ Ext.define('Workout.controller.Rotinas', {
//views: ['rotinas.List', 'rotinas.Form', 'rotinas.ExercicioForm'],
//models: ['Rotina', 'RotinaTree','Item', 'Exercicio'],
//stores: ['Rotinas'],
init: function(button) {
this.addTabPanel(button);
init: function() {
if (!this._initialized) this._initialized = true;
},
addTabPanel: function(button) {
this.getTabPanel().addTab({
Expand All @@ -31,12 +31,8 @@ Ext.define('Workout.controller.Rotinas', {
controller: button.controller,
xtype: 'rotinaslist'
});

}

, getTabPanel: function() {
return Ext.ComponentQuery.query("tabpanel[itemId='tabs']")[0];
}


},
getTabPanel: function() {
return Ext.ComponentQuery.query("dtabpanel")[0];
}
});
10 changes: 8 additions & 2 deletions app/assets/javascripts/app/view/exercicios/Crud.js
Expand Up @@ -41,8 +41,14 @@ Ext.define("Workout.view.exercicios.Crud", {
fn: function(btn){
if(btn == "yes") {
var model = this.getSelectionModel().selected.first();
this.store.remove(model);
this.store.sync();
model.destroy({
success : function() {
this.store.remove(model);
//this.store.sync();
},
scope: this
});

}
}
});
Expand Down
5 changes: 5 additions & 0 deletions app/assets/javascripts/app/view/exercicios/Grid.js
Expand Up @@ -18,6 +18,11 @@ Ext.define("Workout.view.exercicios.Grid", {
{ text: "Excluir", handler: this.excluir, scope: this}
];
this.callParent();
// this.store.on('datachanged', function(store) {
// debugger;
// store.rejectChanges()
// //store.sync();
// });
},
store: Ext.createByAlias("store.exercicios")
});
2 changes: 1 addition & 1 deletion app/assets/javascripts/application.js
Expand Up @@ -10,7 +10,7 @@
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require ext-all
//= require ext-all-dev
//= require base
//= require_tree ./app/view/dashboard
//= require ./app/view/Viewport
Expand Down
7 changes: 6 additions & 1 deletion app/assets/javascripts/base.js
Expand Up @@ -18,11 +18,16 @@ Ext.onReady(function(){
message: exception[item]
});
}
if(operation.scope.getForm) {
if(operation.scope && operation.scope.getForm) {
var form = operation.scope.getForm();
var model = operation.scope.getForm().getRecord();
if(model) model.errors = errors;
operation.scope.getForm().markInvalid(errors);
} else {
var messages = errors.items.map(function(item, i){
return item.field + " <br/> " + item.message.map(function(msg, k){ return (i+1) + "." + (k+1) + ": " + msg }) + "";
})
Ext.Msg.alert('Erro(s)', messages );
}
});
}
Expand Down
12 changes: 11 additions & 1 deletion app/models/exercicio.rb
Expand Up @@ -2,6 +2,16 @@ class Exercicio < ActiveRecord::Base
attr_accessible :descricao, :titulo

validates_presence_of :titulo, :descricao
validates_uniqueness_of :titulo
validates_uniqueness_of :titulo

before_destroy :verificar_rotina

private
def verificar_rotina
empty = Item.where(:exercicio_id => self.id).empty?
msg = "Nao pode excluir esse exercicio porque ele participa de uma ou mais Rotinas"
self.errors[:base] << msg unless empty
empty
end

end

0 comments on commit ba3bbff

Please sign in to comment.