+instance.web.BreadCrumb = instance.web.CallbackEnabled.extend({
+ init: function(parent) {
+ this._super(parent);
+ this.action_manager = parent;
+ this.items = [];
+ this.action_manager.$element.on('click', '.oe_breadcrumb_item', this.on_item_clicked);
+ },
+ push: function(item) {
+ item.show = item.show || function() {
+ item.widget.$element.show();
+ };
+ item.hide = item.hide || function() {
+ item.widget.$element.hide();
+ };
+ item.destroy = item.destroy || function() {
+ item.widget.destroy();
+ };
+ item.get_title = item.get_title || function() {
+ return item.title || item.widget.get('title');
+ };
+ console.log("breadcrumb push", item);
+ this.items.push(item);
+ },
+ push_actionmanager: function(am, view_type) {
+ var self = this;
+ var bookmarked_view = view_type || am.active_view || am.views_src[0].view_type;
+ this.push({
+ widget: am,
+ show: function() {
+ am.$element.show();
+ if (am.active_view !== bookmarked_view) {
+ am.on_mode_switch(bookmarked_view);
+ am.set_title();
+ }
+ },
+ get_title: function() {
+ return am.views[bookmarked_view].controller.get('title');
+ }
+ });
+ if (bookmarked_view !== 'form') {
+ am.on_mode_switch.add_first(function(mode) {
+ if (mode === 'form') {
+ self.push_actionmanager(am, 'form');
+ } else {
+ // select previous to form and remove form
+ }
+ });
+ }
+ },
+ pop: function() {
+ this.remove_item(this.items.length - 1);
+ this.select_item(this.items.length - 1);
+ },
+ get_title: function() {
+ return QWeb.render('BreadCrumb', { widget: this });
+ },
+ hide_items: function() {
+ _.each(this.items, function(i) {
+ i.hide();
+ });
+ },
+ on_item_clicked: function(ev) {
+ var $e = $(ev.target);
+ var index = $e.data('index');
+ this.select_item(index);
+ },
+ select_item: function(index) {
+ for (var i = index + 1; i < this.items.length; i += 1) {
+ this.remove_item(i);
+ }
+ var item = this.items[index];
+ if (item) {
+ item.show();
+ } else {
+ console.warn("Breadcrumb: Can't select item at index", index);
+ }
+ },
+ remove_item: function(index) {
+ console.log("Breadcrumb remove index", index);
+ var item = this.items.splice(index, 1)[0];
+ if (item) {
+ var dups = _.filter(this.items, function(it) {
+ return item.widget === it.widget;
+ });
+ if (dups.length === 0) {
+ console.log("Breadcrumb Destroy", item);
+ item.destroy();
+ }
+ } else {
+ console.warn("Breadcrumb: Can't remove item at index", index);
+ }
+ },
+ clear: function() {
+ while (this.items.length) {
+ this.remove_item(0);
+ }
+ },
+});
+
+instance.web.ViewManager = instance.web.Widget.extend({