[imp] refactored mode in form view

bzr revid: nicolas.vanhoren@openerp.com-20120410100741-v14iaff7t4t60u2t
This commit is contained in:
niv-openerp 2012-04-10 12:07:41 +02:00
parent 33d2603596
commit 711de6f686
1 changed files with 13 additions and 10 deletions

View File

@ -45,7 +45,8 @@ openerp.web.FormView = openerp.web.View.extend({
this.has_been_loaded = $.Deferred(); this.has_been_loaded = $.Deferred();
this.translatable_fields = []; this.translatable_fields = [];
_.defaults(this.options, { _.defaults(this.options, {
"not_interactible_on_create": false "not_interactible_on_create": false,
"initial_mode": "view",
}); });
this.is_initialized = $.Deferred(); this.is_initialized = $.Deferred();
this.mutating_mutex = new $.Mutex(); this.mutating_mutex = new $.Mutex();
@ -112,8 +113,8 @@ openerp.web.FormView = openerp.web.View.extend({
} }
}]); }]);
} }
var initial_mode = 'view'; var initial_mode = this.options.initial_mode;
if (this.getParent().action) { if (this.getParent() && this.getParent().action) {
switch (this.getParent().action.target) { switch (this.getParent().action.target) {
case 'new': case 'new':
case 'inline': case 'inline':
@ -121,7 +122,8 @@ openerp.web.FormView = openerp.web.View.extend({
break; break;
} }
} }
this.do_switch_mode(initial_mode); this.on("change:mode", this, this.switch_mode);
this.set({mode: initial_mode});
this.has_been_loaded.resolve(); this.has_been_loaded.resolve();
return $.when(); return $.when();
}, },
@ -449,7 +451,8 @@ openerp.web.FormView = openerp.web.View.extend({
return $.Deferred().reject(); return $.Deferred().reject();
} }
}, },
do_switch_mode: function(mode) { switch_mode: function() {
var mode = this.get("mode");
var self = this; var self = this;
if(mode=="view") { if(mode=="view") {
self.$buttons.find('.oe_form_buttons_edit').hide(); self.$buttons.find('.oe_form_buttons_edit').hide();
@ -469,12 +472,12 @@ openerp.web.FormView = openerp.web.View.extend({
on_button_save: function() { on_button_save: function() {
var self = this; var self = this;
return this.do_save().then(function(result) { return this.do_save().then(function(result) {
self.do_switch_mode("view"); self.set({mode: "view"});
}); });
}, },
on_button_cancel: function() { on_button_cancel: function() {
if (this.can_be_discarded()) { if (this.can_be_discarded()) {
this.do_switch_mode("view"); this.set({mode: "view"});
} }
}, },
on_button_new: function() { on_button_new: function() {
@ -497,11 +500,11 @@ openerp.web.FormView = openerp.web.View.extend({
return def.promise(); return def.promise();
}, },
on_button_edit: function() { on_button_edit: function() {
return this.do_switch_mode("edit"); return this.set({mode: "edit"});
}, },
on_button_create: function() { on_button_create: function() {
this.dataset.index = null; this.dataset.index = null;
this.do_switch_mode("edit"); this.set({mode: "edit"});
this.do_show(); this.do_show();
}, },
on_button_duplicate: function() { on_button_duplicate: function() {
@ -511,7 +514,7 @@ openerp.web.FormView = openerp.web.View.extend({
self.dataset.call('copy', [self.datarecord.id, {}, self.dataset.context]).then(function(new_id) { self.dataset.call('copy', [self.datarecord.id, {}, self.dataset.context]).then(function(new_id) {
return self.on_created({ result : new_id }); return self.on_created({ result : new_id });
}).then(function() { }).then(function() {
return self.do_switch_mode(1); return self.set({mode: "edit"});
}).then(function() { }).then(function() {
def.resolve(); def.resolve();
}); });