[IMP] Indent HTML editor template names

bzr revid: ddm@openerp.com-20131129172749-0z6l9k9phieiw32b
This commit is contained in:
ddm 2013-11-29 18:27:49 +01:00
parent d32ece09db
commit 96fabb61b2
2 changed files with 41 additions and 6 deletions

View File

@ -129,6 +129,7 @@ class Website(openerp.addons.web.controllers.main.Home):
result.append({ result.append({
'name': v.inherit_option_id.name, 'name': v.inherit_option_id.name,
'id': v.id, 'id': v.id,
'inherit_id': v.inherit_id.id,
'header': True, 'header': True,
'active': False 'active': False
}) })
@ -136,6 +137,7 @@ class Website(openerp.addons.web.controllers.main.Home):
result.append({ result.append({
'name': v.name, 'name': v.name,
'id': v.id, 'id': v.id,
'inherit_id': v.inherit_id.id,
'header': False, 'header': False,
'active': (v.inherit_id.id == v.inherit_option_id.id) or (not optional and v.inherit_id.id) 'active': (v.inherit_id.id == v.inherit_option_id.id) or (not optional and v.inherit_id.id)
}) })

View File

@ -59,8 +59,12 @@
website.ace.ViewOption = openerp.Widget.extend({ website.ace.ViewOption = openerp.Widget.extend({
template: 'website.ace_view_option', template: 'website.ace_view_option',
init: function (parent, options) { init: function (parent, options) {
var indent = "- ";
this.view_id = options.id; this.view_id = options.id;
this.view_name = options.name; this.view_name = options.name;
for (var i = 0; i<options.level; i++) {
this.view_name = indent + this.view_name;
}
this._super(parent); this._super(parent);
}, },
}); });
@ -133,19 +137,48 @@
}, },
loadViews: function (views) { loadViews: function (views) {
var self = this; var self = this;
var activeViews = _.uniq(_.filter(views, function (view) {
return view.active;
}), false, function (view) {
return view.id;
});
var $viewList = self.$('#ace-view-list'); var $viewList = self.$('#ace-view-list');
_.each(activeViews, function (view) { var views = this.buildViewGraph(views);
_.each(views, function (view) {
if (view.id) { if (view.id) {
new website.ace.ViewOption(self, view).appendTo($viewList); new website.ace.ViewOption(self, view).appendTo($viewList);
self.loadView(view.id); self.loadView(view.id);
} }
}); });
}, },
buildViewGraph: function (views) {
var activeViews = _.uniq(_.filter(views, function (view) {
return view.active;
}), false, function (view) {
return view.id;
});
var index = {};
var roots = [];
_.each(activeViews, function (view) {
index[view.id] = view;
view.children = [];
});
_.each(index, function (view) {
var parentId = view.inherit_id;
if (parentId) {
index[parentId].children.push(view);
} else {
roots.push(view);
}
});
var result = [];
function visit (node, level) {
node.level = level;
result.push(node);
_.each(node.children, function (child) {
visit(child, level + 1);
});
}
_.each(roots, function (node) {
visit(node, 0);
});
return result;
},
loadView: function (id) { loadView: function (id) {
var viewId = parseInt(id, 10); var viewId = parseInt(id, 10);
var self = this; var self = this;