merge upstream
bzr revid: chs@openerp.com-20121010121128-5a4axyc3jdekp6q6
This commit is contained in:
@@ -121,6 +121,10 @@ openerp.web.corelib = function(instance) {
|
||||
|
||||
// The dummy class constructor
|
||||
function Class() {
|
||||
if(this.constructor !== instance.web.Class){
|
||||
throw new Error("You can only instanciate objects with the 'new' operator");
|
||||
return null;
|
||||
}
|
||||
// All construction is actually done in the init method
|
||||
if (!initializing && this.init) {
|
||||
var ret = this.init.apply(this, arguments);
|
||||
|
||||
@@ -126,6 +126,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
|
||||
self.on("change:actual_mode", self, self.init_pager);
|
||||
self.init_pager();
|
||||
});
|
||||
self.on("load_record", self, self.load_record);
|
||||
instance.web.bus.on('clear_uncommitted_changes', this, function(e) {
|
||||
if (!this.can_be_discarded()) {
|
||||
e.preventDefault();
|
||||
@@ -172,10 +173,10 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
|
||||
} else {
|
||||
this.$el.find('.oe_form_buttons').replaceWith(this.$buttons);
|
||||
}
|
||||
this.$buttons.on('click','.oe_form_button_create',this.on_button_create);
|
||||
this.$buttons.on('click','.oe_form_button_edit',this.on_button_edit);
|
||||
this.$buttons.on('click','.oe_form_button_save',this.on_button_save);
|
||||
this.$buttons.on('click','.oe_form_button_cancel',this.on_button_cancel);
|
||||
this.$buttons.on('click', '.oe_form_button_create', this.on_button_create);
|
||||
this.$buttons.on('click', '.oe_form_button_edit', this.on_button_edit);
|
||||
this.$buttons.on('click', '.oe_form_button_save', this.on_button_save);
|
||||
this.$buttons.on('click', '.oe_form_button_cancel', this.on_button_cancel);
|
||||
|
||||
this.$sidebar = this.options.$sidebar || this.$el.find('.oe_form_sidebar');
|
||||
if (!this.sidebar && this.options.$sidebar) {
|
||||
@@ -331,7 +332,9 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
|
||||
fields.push('display_name');
|
||||
return self.dataset.read_index(fields, {
|
||||
context: { 'bin_size': true, 'future_display_name' : true }
|
||||
}).pipe(self.on_record_loaded);
|
||||
}).pipe(function(r) {
|
||||
self.trigger('load_record', r);
|
||||
});
|
||||
});
|
||||
}
|
||||
return shown.pipe(function() {
|
||||
@@ -354,7 +357,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
|
||||
}
|
||||
this._super();
|
||||
},
|
||||
on_record_loaded: function(record) {
|
||||
load_record: function(record) {
|
||||
var self = this, set_values = [];
|
||||
if (!record) {
|
||||
this.set({ 'title' : undefined });
|
||||
@@ -413,12 +416,14 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
|
||||
* @return {$.Deferred}
|
||||
*/
|
||||
load_defaults: function () {
|
||||
var self = this;
|
||||
var keys = _.keys(this.fields_view.fields);
|
||||
if (keys.length) {
|
||||
return this.dataset.default_get(keys)
|
||||
.pipe(this.on_record_loaded);
|
||||
return this.dataset.default_get(keys).pipe(function(r) {
|
||||
self.trigger('load_record', r);
|
||||
});
|
||||
}
|
||||
return this.on_record_loaded({});
|
||||
return self.trigger('load_record', {});
|
||||
},
|
||||
on_form_changed: function() {
|
||||
this.trigger("view_content_has_changed");
|
||||
@@ -752,9 +757,10 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
|
||||
this.trigger('history_back');
|
||||
} else {
|
||||
this.to_view_mode();
|
||||
this.on_record_loaded(this.datarecord);
|
||||
this.trigger('load_record', this.datarecord);
|
||||
}
|
||||
}
|
||||
this.trigger('on_button_cancel');
|
||||
return false;
|
||||
},
|
||||
on_button_new: function() {
|
||||
@@ -952,9 +958,15 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
|
||||
} else {
|
||||
var fields = _.keys(self.fields_view.fields);
|
||||
fields.push('display_name');
|
||||
return self.dataset.read_index(fields, {
|
||||
context : { 'bin_size' : true, 'future_display_name' : true }
|
||||
}).pipe(self.on_record_loaded);
|
||||
return self.dataset.read_index(fields,
|
||||
{
|
||||
context: {
|
||||
'bin_size': true,
|
||||
'future_display_name': true
|
||||
}
|
||||
}).pipe(function(r) {
|
||||
self.trigger('load_record', r);
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -2971,7 +2983,7 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc
|
||||
title: _t("Open: ") + self.string
|
||||
}
|
||||
);
|
||||
pop.on('on_write_complete', self, function(){
|
||||
pop.on('write_completed', self, function(){
|
||||
self.display_value = {};
|
||||
self.render_value();
|
||||
self.focus();
|
||||
@@ -3369,9 +3381,9 @@ instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({
|
||||
if (self.get("effective_readonly")) {
|
||||
$(".oe_form_buttons", controller.$el).children().remove();
|
||||
}
|
||||
controller.on_record_loaded.add_last(function() {
|
||||
once.resolve();
|
||||
});
|
||||
controller.on("load_record", self, function(){
|
||||
once.resolve();
|
||||
});
|
||||
controller.on_pager_action.add_first(function() {
|
||||
self.save_any_view();
|
||||
});
|
||||
@@ -3380,10 +3392,13 @@ instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({
|
||||
}
|
||||
def.resolve();
|
||||
});
|
||||
this.viewmanager.on_mode_switch.add_first(function(n_mode, b, c, d, e) {
|
||||
this.viewmanager.on("switch_mode", self, function(n_mode, b, c, d, e) {
|
||||
$.when(self.save_any_view()).then(function() {
|
||||
if(n_mode === "list")
|
||||
$.async_when().then(function() {self.reload_current_view();});
|
||||
if (n_mode === "list") {
|
||||
$.async_when().then(function() {
|
||||
self.reload_current_view();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
this.is_setted.then(function() {
|
||||
@@ -3551,7 +3566,7 @@ instance.web.form.One2ManyViewManager = instance.web.ViewManager.extend({
|
||||
});
|
||||
this.__ignore_blur = false;
|
||||
},
|
||||
switch_view: function(mode, unused) {
|
||||
switch_mode: function(mode, unused) {
|
||||
if (mode !== 'form') {
|
||||
return this._super(mode, unused);
|
||||
}
|
||||
@@ -4120,7 +4135,7 @@ instance.web.form.Many2ManyListView = instance.web.ListView.extend(/** @lends in
|
||||
title: _t("Open: ") + this.m2m_field.string,
|
||||
readonly: this.getParent().get("effective_readonly")
|
||||
});
|
||||
pop.on('on_write_complete', self, self.reload_content);
|
||||
pop.on('write_completed', self, self.reload_content);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -4189,7 +4204,7 @@ instance.web.form.FieldMany2ManyKanban = instance.web.form.AbstractField.extend(
|
||||
self.initial_is_loaded.resolve();
|
||||
loaded.resolve();
|
||||
});
|
||||
this.kanban_view.do_switch_view.add_last(_.bind(this.open_popup, this));
|
||||
this.kanban_view.on('switch_mode', this, this.open_popup);
|
||||
$.async_when().then(function () {
|
||||
self.kanban_view.appendTo(self.$el);
|
||||
});
|
||||
@@ -4368,7 +4383,7 @@ instance.web.form.AbstractFormPopup = instance.web.Widget.extend({
|
||||
this.dataset.write_function = function(id, data, options, sup) {
|
||||
var fct = self.options.write_function || sup;
|
||||
return fct.call(this, id, data, options).then(function() {
|
||||
self.trigger('on_write_complete');
|
||||
self.trigger('write_completed');
|
||||
});
|
||||
};
|
||||
this.dataset.parent_view = this.options.parent_view;
|
||||
|
||||
@@ -626,7 +626,7 @@ openerp.web.list_editable = function (instance) {
|
||||
},
|
||||
start: function () {
|
||||
var self = this;
|
||||
var _super = this._super();
|
||||
var _super = this._super();
|
||||
this.form.embedded_view = this._validate_view(
|
||||
this.delegate.edition_view(this));
|
||||
var form_ready = this.form.appendTo(this.$el).then(
|
||||
@@ -708,10 +708,9 @@ openerp.web.list_editable = function (instance) {
|
||||
var self = this;
|
||||
var form = self.form;
|
||||
var loaded = record
|
||||
? form.on_record_loaded(_.extend({}, record))
|
||||
? form.trigger('load_record', _.extend({}, record))
|
||||
: form.load_defaults();
|
||||
|
||||
return loaded.pipe(function () {
|
||||
return $.when(loaded).pipe(function () {
|
||||
return form.do_show({reload: false});
|
||||
}).pipe(function () {
|
||||
self.record = form.datarecord;
|
||||
|
||||
@@ -417,7 +417,7 @@ instance.web.ViewManager = instance.web.Widget.extend({
|
||||
this._super();
|
||||
var self = this;
|
||||
this.$el.find('.oe_view_manager_switch a').click(function() {
|
||||
self.on_mode_switch($(this).data('view-type'));
|
||||
self.switch_mode($(this).data('view-type'));
|
||||
}).tipsy();
|
||||
var views_ids = {};
|
||||
_.each(this.views_src, function(view) {
|
||||
@@ -439,24 +439,17 @@ instance.web.ViewManager = instance.web.Widget.extend({
|
||||
}
|
||||
// If no default view defined, switch to the first one in sequence
|
||||
var default_view = this.flags.default_view || this.views_src[0].view_type;
|
||||
return this.on_mode_switch(default_view);
|
||||
return this.switch_mode(default_view);
|
||||
},
|
||||
/**
|
||||
* Asks the view manager to switch visualization mode.
|
||||
*
|
||||
* @param {String} view_type type of view to display
|
||||
* @param {Boolean} [no_store=false] don't store the view being switched to on the switch stack
|
||||
* @returns {jQuery.Deferred} new view loading promise
|
||||
*/
|
||||
on_mode_switch: function(view_type, no_store, view_options) {
|
||||
switch_mode: function(view_type, no_store, view_options) {
|
||||
var self = this;
|
||||
var view = this.views[view_type];
|
||||
var view_promise;
|
||||
var form = this.views['form'];
|
||||
if (!view || (form && form.controller && !form.controller.can_be_discarded())) {
|
||||
self.trigger('switch_mode', view_type, no_store, view_options);
|
||||
return $.Deferred().reject();
|
||||
}
|
||||
|
||||
if (!no_store) {
|
||||
this.views_history.push(view_type);
|
||||
}
|
||||
@@ -474,13 +467,12 @@ instance.web.ViewManager = instance.web.Widget.extend({
|
||||
this.searchview[(view.controller.searchable === false || this.searchview.hidden) ? 'hide' : 'show']();
|
||||
}
|
||||
|
||||
this.$el
|
||||
.find('.oe_view_manager_switch a').parent().removeClass('active');
|
||||
this.$el.find('.oe_view_manager_switch a').parent().removeClass('active');
|
||||
this.$el
|
||||
.find('.oe_view_manager_switch a').filter('[data-view-type="' + view_type + '"]')
|
||||
.parent().addClass('active');
|
||||
|
||||
return $.when(view_promise).then(function () {
|
||||
r = $.when(view_promise).then(function () {
|
||||
_.each(_.keys(self.views), function(view_name) {
|
||||
var controller = self.views[view_name].controller;
|
||||
if (controller) {
|
||||
@@ -501,7 +493,9 @@ instance.web.ViewManager = instance.web.Widget.extend({
|
||||
}
|
||||
}
|
||||
});
|
||||
self.trigger('switch_mode', view_type, no_store, view_options);
|
||||
});
|
||||
return r;
|
||||
},
|
||||
do_create_view: function(view_type) {
|
||||
// Lazy loading of views
|
||||
@@ -530,7 +524,7 @@ instance.web.ViewManager = instance.web.Widget.extend({
|
||||
if (view.embedded_view) {
|
||||
controller.set_embedded_view(view.embedded_view);
|
||||
}
|
||||
controller.do_switch_view.add_last(_.bind(this.switch_view, this));
|
||||
controller.on('switch_mode', self, this.switch_mode);
|
||||
|
||||
controller.do_prev_view.add_last(this.on_prev_view);
|
||||
var container = this.$el.find(".oe_view_manager_view_" + view_type);
|
||||
@@ -552,7 +546,7 @@ instance.web.ViewManager = instance.web.Widget.extend({
|
||||
add_breadcrumb: function(on_reverse_breadcrumb) {
|
||||
var self = this;
|
||||
var views = [this.active_view || this.views_src[0].view_type];
|
||||
this.on_mode_switch.add(function(mode) {
|
||||
this.on('switch_mode', self, function(mode) {
|
||||
var last = views.slice(-1)[0];
|
||||
if (mode !== last) {
|
||||
if (mode !== 'form') {
|
||||
@@ -568,7 +562,7 @@ instance.web.ViewManager = instance.web.Widget.extend({
|
||||
var view_to_select = views[index];
|
||||
self.$el.show();
|
||||
if (self.active_view !== view_to_select) {
|
||||
self.on_mode_switch(view_to_select);
|
||||
self.switch_mode(view_to_select);
|
||||
}
|
||||
},
|
||||
get_title: function() {
|
||||
@@ -598,18 +592,10 @@ instance.web.ViewManager = instance.web.Widget.extend({
|
||||
on_reverse_breadcrumb: on_reverse_breadcrumb,
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Method used internally when a view asks to switch view. This method is meant
|
||||
* to be extended by child classes to change the default behavior, which simply
|
||||
* consist to switch to the asked view.
|
||||
*/
|
||||
switch_view: function(view_type, no_store, options) {
|
||||
return this.on_mode_switch(view_type, no_store, options);
|
||||
},
|
||||
/**
|
||||
* Returns to the view preceding the caller view in this manager's
|
||||
* navigation history (the navigation history is appended to via
|
||||
* on_mode_switch)
|
||||
* switch_mode)
|
||||
*
|
||||
* @param {Object} [options]
|
||||
* @param {Boolean} [options.created=false] resource was created
|
||||
@@ -623,12 +609,12 @@ instance.web.ViewManager = instance.web.Widget.extend({
|
||||
if (options.created && current_view === 'form' && previous_view === 'list') {
|
||||
// APR special case: "If creation mode from list (and only from a list),
|
||||
// after saving, go to page view (don't come back in list)"
|
||||
return this.on_mode_switch('form');
|
||||
return this.switch_mode('form');
|
||||
} else if (options.created && !previous_view && this.action && this.action.flags.default_view === 'form') {
|
||||
// APR special case: "If creation from dashboard, we have no previous view
|
||||
return this.on_mode_switch('form');
|
||||
return this.switch_mode('form');
|
||||
}
|
||||
return this.on_mode_switch(previous_view, true);
|
||||
return this.switch_mode(previous_view, true);
|
||||
},
|
||||
/**
|
||||
* Sets up the current viewmanager's search view.
|
||||
@@ -897,7 +883,7 @@ instance.web.ViewManagerAction = instance.web.ViewManager.extend({
|
||||
}, action || {});
|
||||
this.do_action(action);
|
||||
},
|
||||
on_mode_switch: function (view_type, no_store, options) {
|
||||
switch_mode: function (view_type, no_store, options) {
|
||||
var self = this;
|
||||
|
||||
return $.when(this._super.apply(this, arguments)).then(function () {
|
||||
@@ -932,7 +918,7 @@ instance.web.ViewManagerAction = instance.web.ViewManager.extend({
|
||||
if (state.view_type && state.view_type !== this.active_view) {
|
||||
defs.push(
|
||||
this.views[this.active_view].deferred.pipe(function() {
|
||||
return self.on_mode_switch(state.view_type, true);
|
||||
return self.switch_mode(state.view_type, true);
|
||||
})
|
||||
);
|
||||
}
|
||||
@@ -1271,6 +1257,7 @@ instance.web.View = instance.web.Widget.extend({
|
||||
* @param {String} view view type to switch to
|
||||
*/
|
||||
do_switch_view: function(view) {
|
||||
this.trigger('switch_mode',view);
|
||||
},
|
||||
/**
|
||||
* Cancels the switch to the current view, switches to the previous one
|
||||
|
||||
@@ -239,23 +239,23 @@ instance.web.DiagramView = instance.web.View.extend({
|
||||
title: _t("Open: ") + title
|
||||
}
|
||||
);
|
||||
|
||||
pop.on_write.add(function() {
|
||||
pop.on('on_write_complete', self, function() {
|
||||
self.dataset.read_index(_.keys(self.fields_view.fields)).pipe(self.on_diagram_loaded);
|
||||
});
|
||||
|
||||
|
||||
var form_fields = [self.parent_field];
|
||||
var form_controller = pop.view_form;
|
||||
|
||||
form_controller.on_record_loaded.add_first(function() {
|
||||
form_controller.on("load_record", self, function(){
|
||||
_.each(form_fields, function(fld) {
|
||||
if (!(fld in form_controller.fields)) { return; }
|
||||
var field = form_controller.fields[fld];
|
||||
field.$input.prop('disabled', true);
|
||||
field.$drop_down.unbind();
|
||||
field.$menu_btn.unbind();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
},
|
||||
|
||||
// Creates a popup to add a node to the diagram
|
||||
@@ -280,7 +280,7 @@ instance.web.DiagramView = instance.web.View.extend({
|
||||
var form_controller = pop.view_form;
|
||||
var form_fields = [this.parent_field];
|
||||
|
||||
form_controller.on_record_loaded.add_last(function() {
|
||||
form_controller.on("load_record", self, function(){
|
||||
_.each(form_fields, function(fld) {
|
||||
if (!(fld in form_controller.fields)) { return; }
|
||||
var field = form_controller.fields[fld];
|
||||
@@ -303,7 +303,7 @@ instance.web.DiagramView = instance.web.View.extend({
|
||||
title: _t("Open: ") + title
|
||||
}
|
||||
);
|
||||
pop.on_write.add(function() {
|
||||
pop.on('on_write_complete', self, function() {
|
||||
self.dataset.read_index(_.keys(self.fields_view.fields)).pipe(self.on_diagram_loaded);
|
||||
});
|
||||
},
|
||||
@@ -339,12 +339,13 @@ instance.web.DiagramView = instance.web.View.extend({
|
||||
|
||||
var form_controller = pop.view_form;
|
||||
|
||||
form_controller.on_record_loaded.add_last(function () {
|
||||
|
||||
form_controller.on("load_record", self, function(){
|
||||
form_controller.fields[self.connectors.attrs.source].set_value(node_source_id);
|
||||
form_controller.fields[self.connectors.attrs.source].dirty = true;
|
||||
form_controller.fields[self.connectors.attrs.destination].set_value(node_dest_id);
|
||||
form_controller.fields[self.connectors.attrs.destination].dirty = true;
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
on_pager_action: function(action) {
|
||||
|
||||
@@ -211,7 +211,7 @@ instance.web_gantt.GanttView = instance.web.View.extend({
|
||||
on_task_display: function(task) {
|
||||
var self = this;
|
||||
var pop = new instance.web.form.FormOpenPopup(self);
|
||||
pop.on('on_write_complete',self,self.reload);
|
||||
pop.on('write_completed',self,self.reload);
|
||||
pop.show_element(
|
||||
self.dataset.model,
|
||||
task.id,
|
||||
|
||||
@@ -194,7 +194,7 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
|
||||
});
|
||||
var am = instance.webclient.action_manager;
|
||||
var form = am.dialog_widget.views.form.controller;
|
||||
form.on_button_cancel.add_last(am.dialog.on_close);
|
||||
form.on("on_button_cancel", self, am.dialog.on_close);
|
||||
form.on_created.add_last(function(r) {
|
||||
(new instance.web.DataSet(self, self.group_by_field.relation)).name_get([r.result]).then(function(new_record) {
|
||||
am.dialog.on_close();
|
||||
@@ -672,7 +672,7 @@ instance.web_kanban.KanbanGroup = instance.web.Widget.extend({
|
||||
});
|
||||
var am = instance.webclient.action_manager;
|
||||
var form = am.dialog_widget.views.form.controller;
|
||||
form.on_button_cancel.add_last(am.dialog.on_close);
|
||||
form.on("on_button_cancel", self, am.dialog.on_close);
|
||||
form.on_saved.add_last(function() {
|
||||
am.dialog.on_close();
|
||||
self.view.do_reload();
|
||||
|
||||
@@ -23,14 +23,14 @@ openerp.web_tests = function (instance) {
|
||||
on_everything_loaded: function (slice) {
|
||||
var records = slice[0].records;
|
||||
if (!records.length) {
|
||||
this.form.on_record_loaded({});
|
||||
this.form.trigger("load_record", {});
|
||||
return;
|
||||
}
|
||||
this.form.on_record_loaded(records[0]);
|
||||
this.form.trigger("load_record", records[0]);
|
||||
_(records.slice(1)).each(function (record, index) {
|
||||
this.dataset.index = index+1;
|
||||
this.form.reposition($('<div>').appendTo(this.$el));
|
||||
this.form.on_record_loaded(record);
|
||||
this.form.trigger("load_record", record);
|
||||
}, this);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1014,8 +1014,8 @@ instance.web_view_editor.ViewEditor = instance.web.Widget.extend({
|
||||
var action_manager = new instance.web.ActionManager(self);
|
||||
$.when(action_manager.do_action(action)).then(function() {
|
||||
var controller = action_manager.dialog_widget.views['form'].controller;
|
||||
controller.on_button_cancel.add_last(function(){
|
||||
action_manager.destroy()
|
||||
controller.on("on_button_cancel", self, function(){
|
||||
action_manager.destroy();
|
||||
});
|
||||
controller.do_save.add_last(function(){
|
||||
action_manager.destroy();
|
||||
|
||||
Reference in New Issue
Block a user