diff options
| author | Thibault Delavallée <tde@openerp.com> | 2012-08-06 14:44:54 +0200 |
|---|---|---|
| committer | Thibault Delavallée <tde@openerp.com> | 2012-08-06 14:44:54 +0200 |
| commit | 5bfe0953b46ea29f90db57ca9a394717ddc35a8e (patch) | |
| tree | 07a365ee685887bd016d11123561e3432b5ead0c /addons/web/static/src/js | |
| parent | 38552a9c49eec29136c620ae99ebbc363fd45031 (diff) | |
| parent | 8cecaa14f3f9b3ed48adccf4ebf933e67cd8b714 (diff) | |
[MERGE] Merged with web/trunk.
bzr revid: tde@openerp.com-20120806124454-hgdw4vjzjuhfsg2n
Diffstat (limited to 'addons/web/static/src/js')
| -rw-r--r-- | addons/web/static/src/js/chrome.js | 49 | ||||
| -rw-r--r-- | addons/web/static/src/js/coresetup.js | 26 | ||||
| -rw-r--r-- | addons/web/static/src/js/view_form.js | 12 | ||||
| -rw-r--r-- | addons/web/static/src/js/view_list.js | 22 | ||||
| -rw-r--r-- | addons/web/static/src/js/views.js | 52 |
5 files changed, 110 insertions, 51 deletions
diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 7486d746496..0557fe56d5e 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -609,6 +609,55 @@ instance.web.Login = instance.web.Widget.extend({ }); instance.web.client_actions.add("login", "instance.web.Login"); +/** + * Client action to reload the whole interface. + * If params has an entry 'menu_id', it opens the given menu entry. + */ +instance.web.Reload = instance.web.Widget.extend({ + init: function(parent, params) { + this._super(parent); + this.menu_id = (params && params.menu_id) || false; + }, + start: function() { + var l = window.location; + var timestamp = new Date().getTime(); + var search = "?ts=" + timestamp; + if (l.search) { + search = l.search + "&ts=" + timestamp; + } + var hash = l.hash; + if (this.menu_id) { + hash = "#menu_id=" + this.menu_id; + } + var url = l.protocol + "//" + l.host + l.pathname + search + hash; + window.location = url; + } +}); +instance.web.client_actions.add("reload", "instance.web.Reload"); + +/** + * Client action to go back in breadcrumb history. + * If can't go back in history stack, will go back to home. + */ +instance.web.HistoryBack = instance.web.Widget.extend({ + init: function(parent, params) { + if (!parent.history_back()) { + window.location = '/' + (window.location.search || ''); + } + } +}); +instance.web.client_actions.add("history_back", "instance.web.HistoryBack"); + +/** + * Client action to go back home. + */ +instance.web.Home = instance.web.Widget.extend({ + init: function(parent, params) { + window.location = '/' + (window.location.search || ''); + } +}); +instance.web.client_actions.add("home", "instance.web.Home"); + instance.web.Menu = instance.web.Widget.extend({ template: 'Menu', init: function() { diff --git a/addons/web/static/src/js/coresetup.js b/addons/web/static/src/js/coresetup.js index 2f2fb4f7832..6ba62162e93 100644 --- a/addons/web/static/src/js/coresetup.js +++ b/addons/web/static/src/js/coresetup.js @@ -672,32 +672,6 @@ instance.connection.on('module_loaded', this, function () { */ instance.web.client_actions = new instance.web.Registry(); -/** - * Client action to reload the whole interface. - * If params has an entry 'menu_id', it opens the given menu entry. - */ -instance.web.Reload = instance.web.Widget.extend({ - init: function(parent, params) { - this._super(parent); - this.menu_id = (params && params.menu_id) || false; - }, - start: function() { - var l = window.location; - var timestamp = new Date().getTime(); - var search = "?ts=" + timestamp; - if (l.search) { - search = l.search + "&ts=" + timestamp; - } - var hash = l.hash; - if (this.menu_id) { - hash = "#menu_id=" + this.menu_id; - } - var url = l.protocol + "//" + l.host + l.pathname + search + hash; - window.location = url; - } -}); -instance.web.client_actions.add("reload", "instance.web.Reload"); - }; // vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax: diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 77a9c64822e..c4e13dabae2 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -151,7 +151,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM this.sidebar.add_items('other', [ { label: _t('Delete'), callback: self.on_button_delete }, { label: _t('Duplicate'), callback: self.on_button_duplicate }, - { label: _t('Set Default'), callback: function (item) { self.open_defaults_dialog(); } }, + { label: _t('Set Default'), callback: function (item) { self.open_defaults_dialog(); } } ]); } @@ -684,8 +684,12 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM }, on_button_cancel: function(event) { if (this.can_be_discarded()) { - this.to_view_mode(); - this.on_record_loaded(this.datarecord); + if (this.get('actual_mode') === 'create') { + this.trigger('history_back'); + } else { + this.to_view_mode(); + this.on_record_loaded(this.datarecord); + } } return false; }, @@ -3625,7 +3629,7 @@ instance.web.form.FieldMany2ManyTags = instance.web.form.AbstractField.extend(in $("textarea", this.$element).focusout(function() { self.$text.trigger("setInputData", ""); }).keydown(function(e) { - if (event.keyCode === 9 && self._drop_shown) { + if (e.which === $.ui.keyCode.TAB && self._drop_shown) { self.$text.textext()[0].autocomplete().selectFromDropdown(); } }); diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js index 9c7bf88db1a..57be3ca6db1 100644 --- a/addons/web/static/src/js/view_list.js +++ b/addons/web/static/src/js/view_list.js @@ -354,7 +354,7 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi this.sidebar.add_items('other', [ { label: _t("Import"), callback: this.on_sidebar_import }, { label: _t("Export"), callback: this.on_sidebar_export }, - { label: _t('Delete'), callback: this.do_delete_selected }, + { label: _t('Delete'), callback: this.do_delete_selected } ]); this.sidebar.add_toolbar(this.fields_view.toolbar); this.sidebar.$element.hide(); @@ -444,10 +444,6 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi id: '_group', tag: '', string: _t("Group"), meta: true, modifiers_for: function () { return {}; }, modifiers: {} - }, { - id: '_count', tag: '', string: '#', meta: true, - modifiers_for: function () { return {}; }, - modifiers: {} }); } @@ -880,9 +876,7 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi } this.$element.find('table:first').hide(); this.$element.prepend( - $('<div class="oe_view_nocontent">') - .append($('<img>', { src: '/web/static/src/img/view_empty_arrow.png' })) - .append($('<div>').html(this.options.action.help)) + $('<div class="oe_view_nocontent">').html(this.options.action.help) ); } }); @@ -1344,15 +1338,19 @@ instance.web.ListView.Groups = instance.web.Class.extend( /** @lends instance.we _t("Grouping on field '%s' is not possible because that field does not appear in the list view."), group.grouped_on)); } + var group_label; try { - $group_column.html(instance.web.format_cell( + group_label = instance.web.format_cell( row_data, group_column, { value_if_empty: _t("Undefined"), process_modifiers: false - })); + }); } catch (e) { - $group_column.html(row_data[group_column.id].value); + group_label = row_data[group_column.id].value; } + $group_column.text(_.str.sprintf("%s (%d)", + group_label, group.length)); + if (group.length && group.openable) { // Make openable if not terminal group & group_by_no_leaf $group_column.prepend('<span class="ui-icon ui-icon-triangle-1-e" style="float: left;">'); @@ -1364,8 +1362,6 @@ instance.web.ListView.Groups = instance.web.Class.extend( /** @lends instance.we } } self.indent($group_column, group.level); - // count column - $('<td>').text(group.length).appendTo($row); if (self.options.selectable) { $row.append('<td>'); diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index af4ae68737a..ae46d3d9ff1 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -14,6 +14,9 @@ instance.web.ActionManager = instance.web.Widget.extend({ this.dialog = null; this.dialog_widget = null; this.breadcrumbs = []; + this.on('history_back', this, function() { + return this.history_back(); + }); }, start: function() { this._super.apply(this, arguments); @@ -65,21 +68,46 @@ instance.web.ActionManager = instance.web.Widget.extend({ item.id = _.uniqueId('breadcrumb_'); this.breadcrumbs.push(item); }, + history_back: function() { + var last = this.breadcrumbs.slice(-1)[0]; + if (!last) { + return false; + } + var title = last.get_title(); + if (_.isArray(title) && title.length > 1) { + return this.select_breadcrumb(this.breadcrumbs.length - 1, title.length - 2); + } else if (this.breadcrumbs.length === 1) { + // Only one single titled item in breadcrumb, most of the time you want to trigger back to home + return false; + } else { + var prev = this.breadcrumbs[this.breadcrumbs.length - 2]; + title = prev.get_title(); + return this.select_breadcrumb(this.breadcrumbs.length - 2, _.isArray(title) ? title.length - 1 : undefined); + } + }, on_breadcrumb_clicked: function(ev) { var $e = $(ev.target); var id = $e.data('id'); - var item; + var index; for (var i = this.breadcrumbs.length - 1; i >= 0; i--) { - var it = this.breadcrumbs[i]; - if (it.id == id) { - item = it; + if (this.breadcrumbs[i].id == id) { + index = i; break; } - this.remove_breadcrumb(i); } - var index = $e.parent().find('.oe_breadcrumb_item[data-id=' + $e.data('id') + ']').index($e); - item.show(index, $e); + var subindex = $e.parent().find('.oe_breadcrumb_item[data-id=' + $e.data('id') + ']').index($e); + this.select_breadcrumb(index, subindex); + }, + select_breadcrumb: function(index, subindex) { + for (var i = this.breadcrumbs.length - 1; i >= 0; i--) { + if (i > index) { + this.remove_breadcrumb(i); + } + } + var item = this.breadcrumbs[index]; + item.show(subindex); this.inner_widget = item.widget; + return true; }, clear_breadcrumbs: function() { while (this.breadcrumbs.length) { @@ -166,6 +194,7 @@ instance.web.ActionManager = instance.web.Widget.extend({ var action = state.client_action; if(_.isString(action)) { action = { + type: 'ir.actions.client', tag: action, params: state, }; @@ -462,6 +491,13 @@ instance.web.ViewManager = instance.web.Widget.extend({ } var controller = new controllerclass(this, this.dataset, view.view_id, options); + controller.on('history_back', this, function() { + var am = self.getParent(); + if (am && am.trigger) { + return am.trigger('history_back'); + } + }); + controller.on("change:title", this, function() { if (self.active_view === view_type) { self.set_title(controller.get('title')); @@ -505,7 +541,7 @@ instance.web.ViewManager = instance.web.Widget.extend({ this.getParent().push_breadcrumb({ widget: this, action: this.action, - show: function(index, $e) { + show: function(index) { var view_to_select = views[index]; self.$element.show(); if (self.active_view !== view_to_select) { |
