diff options
| author | niv-openerp <nicolas.vanhoren@openerp.com> | 2011-06-22 16:51:53 +0200 |
|---|---|---|
| committer | niv-openerp <nicolas.vanhoren@openerp.com> | 2011-06-22 16:51:53 +0200 |
| commit | 9d32bef7c7fd2d9b654ae835b66109bb120dda7b (patch) | |
| tree | 20af5c3bef85a121fd5d532e3e669bbc73a1dce9 /addons/base/static/src | |
| parent | 46abe6600a40c0088cc83928e71167b9e816032e (diff) | |
| parent | 58291d4ab605ff5b9882bb84de537ce1ff6e73cf (diff) | |
[merge]
bzr revid: nicolas.vanhoren@openerp.com-20110622145153-1j0ntku8qndpij1o
Diffstat (limited to 'addons/base/static/src')
| -rw-r--r-- | addons/base/static/src/js/data.js | 21 | ||||
| -rw-r--r-- | addons/base/static/src/js/form.js | 11 | ||||
| -rw-r--r-- | addons/base/static/src/js/list.js | 20 | ||||
| -rw-r--r-- | addons/base/static/src/js/views.js | 32 |
4 files changed, 50 insertions, 34 deletions
diff --git a/addons/base/static/src/js/data.js b/addons/base/static/src/js/data.js index 736c31c1f7b..47e6d4fed3d 100644 --- a/addons/base/static/src/js/data.js +++ b/addons/base/static/src/js/data.js @@ -310,9 +310,10 @@ openerp.base.DataSet = openerp.base.Controller.extend( /** @lends openerp.base. context: this.context }, callback); }, - unlink: function(ids) { - // to implement in children - this.notification.notify("Unlink", ids); + unlink: function(ids, callback, error_callback) { + var self = this; + return this.call_and_eval("unlink", [ids, this.context], null, 1, + callback, error_callback); }, call: function (method, args, callback, error_callback) { return this.rpc('/base/dataset/call', { @@ -362,9 +363,12 @@ openerp.base.DataSetStatic = openerp.base.DataSet.extend({ set_ids: function (ids) { this.ids = ids; this.count = this.ids.length; + this.index = this.index <= this.count - 1 ? + this.index : (this.count > 0 ? this.count - 1 : 0); }, unlink: function(ids) { this.on_unlink(ids); + return $.Deferred().resolve({result: true}); }, on_unlink: function(ids) { this.set_ids(_.without.apply(null, [this.ids].concat(ids))); @@ -438,6 +442,17 @@ openerp.base.DataSetSearch = openerp.base.DataSet.extend({ this._sort.unshift((reverse ? '-' : '') + field); return undefined; + }, + unlink: function(ids, callback, error_callback) { + var self = this; + return this._super(ids, function(result) { + self.ids = _.without.apply(_, [self.ids].concat(ids)); + self.count = self.ids.length; + self.index = self.index <= self.count - 1 ? + self.index : (self.count > 0 ? self.count -1 : 0); + if (callback) + callback(result); + }, error_callback); } }); diff --git a/addons/base/static/src/js/form.js b/addons/base/static/src/js/form.js index c5227074bfc..09e9b39561d 100644 --- a/addons/base/static/src/js/form.js +++ b/addons/base/static/src/js/form.js @@ -252,18 +252,23 @@ openerp.base.FormView = openerp.base.View.extend( /** @lends openerp.base.FormV if (!this.ready) { return false; } - var invalid = false; - var values = {}; + var invalid = false, + values = {}, + first_invalid_field = null; for (var f in this.fields) { f = this.fields[f]; if (f.invalid) { invalid = true; f.update_dom(); + if (!first_invalid_field) { + first_invalid_field = f; + } } else if (f.touched) { values[f.name] = f.get_value(); } } if (invalid) { + first_invalid_field.focus(); this.on_invalid(); return false; } else { @@ -553,7 +558,7 @@ openerp.base.form.WidgetFrame = openerp.base.form.Widget.extend({ var widget_type = node.attrs.widget || type.type || node.tag; var widget = new (this.view.registry.get_object(widget_type)) (this.view, node); if (node.tag == 'field') { - if (node.attrs.default_focus == '1') { + if (!this.view.default_focus_field || node.attrs.default_focus == '1') { this.view.default_focus_field = widget; } if (node.attrs.nolabel != '1') { diff --git a/addons/base/static/src/js/list.js b/addons/base/static/src/js/list.js index bd2518dcb66..38162849e08 100644 --- a/addons/base/static/src/js/list.js +++ b/addons/base/static/src/js/list.js @@ -336,25 +336,7 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi } var self = this; return $.when(this.dataset.unlink(ids)).then(function () { - _(self.rows).chain() - .map(function (row, index) { - return { - index: index, - id: row.data.id.value - };}) - .filter(function (record) { - return _.contains(ids, record.id); - }) - .sort(function (a, b) { - // sort in reverse index order, so we delete from the end - // and don't blow up the following indexes (leading to - // removing the wrong records from the visible list) - return b.index - a.index; - }) - .each(function (record) { - self.rows.splice(record.index, 1); - }); - // TODO only refresh modified rows + self.reload_content(); }); }, /** diff --git a/addons/base/static/src/js/views.js b/addons/base/static/src/js/views.js index ce2ee2c72e6..8b87d9cbdbe 100644 --- a/addons/base/static/src/js/views.js +++ b/addons/base/static/src/js/views.js @@ -113,7 +113,8 @@ openerp.base.ViewManager = openerp.base.Controller.extend({ * @returns {jQuery.Deferred} new view loading promise */ on_mode_switch: function(view_type) { - var view_promise; + var self = this, + view_promise; this.active_view = view_type; var view = this.views[view_type]; if (!view.controller) { @@ -124,6 +125,16 @@ openerp.base.ViewManager = openerp.base.Controller.extend({ if (view.embedded_view) { controller.set_embedded_view(view.embedded_view); } + if (view_type === 'list' && this.flags.search_view === false && this.action && this.action['auto_search']) { + // In case the search view is not instanciated: manually call ListView#search + controller.on_loaded.add({ + callback: function () { + controller.do_search([self.action.domain], [self.action.context], []); + }, + position: 'last', + unique: true + }); + } view_promise = controller.start(); var self = this; $.when(view_promise).then(function() { @@ -132,6 +143,7 @@ openerp.base.ViewManager = openerp.base.Controller.extend({ this.views[view_type].controller = controller; } + if (this.searchview) { if (view.controller.searchable === false) { this.searchview.hide(); @@ -261,16 +273,18 @@ openerp.base.ViewManagerAction = openerp.base.ViewManager.extend({ } }); - // init search view - var searchview_id = this.action.search_view_id && this.action.search_view_id[0]; + if (this.flags.search_view !== false) { + // init search view + var searchview_id = this.action.search_view_id && this.action.search_view_id[0]; - var searchview_loaded = this.setup_search_view( - searchview_id || false, search_defaults); + var searchview_loaded = this.setup_search_view( + searchview_id || false, search_defaults); - // schedule auto_search - if (searchview_loaded != null && this.action['auto_search']) { - $.when(searchview_loaded, inital_view_loaded) - .then(this.searchview.do_search); + // schedule auto_search + if (searchview_loaded != null && this.action['auto_search']) { + $.when(searchview_loaded, inital_view_loaded) + .then(this.searchview.do_search); + } } }, stop: function() { |
