[ADD] Added breadcrumb history_back. Fix create/discard

bzr revid: fme@openerp.com-20120802165440-zl6lonpv7uvw67k6
This commit is contained in:
Fabien Meghazi 2012-08-02 18:54:40 +02:00
parent 2c57c15491
commit 84f258b4f1
2 changed files with 49 additions and 10 deletions

View File

@ -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;
},

View File

@ -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 (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) {
@ -462,6 +490,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 +540,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) {