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);
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 (title.length > 1) {
+ return this.select_breadcrumb(this.breadcrumbs.length - 1, title.length - 2);
+ } else {
+ return this.select_breadcrumb(this.breadcrumbs.length - 2);
+ }
+ },
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];
+ if (!item) {
+ // TODO fme: this will probably happens when an action contains only one form view (does not impact wizards)
+ console.warn("Could not select breadcrumb at index", index);
+ return false;
+ }
+ item.show(subindex);
this.inner_widget = item.widget;
+ return true;
},
clear_breadcrumbs: function() {
while (this.breadcrumbs.length) {
}
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'));
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) {