[IMP] Save menu is working
bzr revid: fme@openerp.com-20131029143346-nu9skoj5s06hwgw6
This commit is contained in:
parent
7ac3061c42
commit
07b9cf0f02
|
@ -412,6 +412,22 @@ class website_menu(osv.osv):
|
|||
|
||||
return menu_items[0]
|
||||
|
||||
def save(self, cr, uid, website_id, data=[], context=None):
|
||||
def replace_id(old_id, new_id):
|
||||
for menu in data:
|
||||
if menu['id'] == old_id:
|
||||
menu['id'] = new_id
|
||||
if menu['parent_id'] == old_id:
|
||||
menu['parent_id'] = new_id
|
||||
for menu in data:
|
||||
old_id = menu['id']
|
||||
if isinstance(old_id, str):
|
||||
new_id = self.create(cr, uid, {'name': menu['name']}, context=context)
|
||||
replace_id(old_id, new_id)
|
||||
for menu in data:
|
||||
self.write(cr, uid, [menu['id']], menu, context=context)
|
||||
return True
|
||||
|
||||
class ir_attachment(osv.osv):
|
||||
_inherit = "ir.attachment"
|
||||
def _website_url_get(self, cr, uid, ids, name, arg, context=None):
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
}),
|
||||
init: function (menu) {
|
||||
this.menu = menu;
|
||||
this.root_menu_id = menu.id;
|
||||
this.flat = this.flatenize(menu);
|
||||
this._super();
|
||||
},
|
||||
start: function () {
|
||||
|
@ -22,34 +24,75 @@
|
|||
listType: 'ul',
|
||||
handle: 'div',
|
||||
items: 'li',
|
||||
maxLevels: 2,
|
||||
toleranceElement: '> div',
|
||||
forcePlaceholderSize: true,
|
||||
opacity: 0.6,
|
||||
placeholder: 'oe_menu_placeholder',
|
||||
tolerance: 'pointer',
|
||||
attribute: 'data-menu-id',
|
||||
expression: '()(.+)', // nestedSortable takes the second match of an expression (*sigh*)
|
||||
});
|
||||
return r;
|
||||
},
|
||||
flatenize: function (node, dict) {
|
||||
dict = dict || {};
|
||||
var self = this;
|
||||
dict[node.id] = node;
|
||||
node.children.forEach(function (child) {
|
||||
self.flatenize(child, dict);
|
||||
});
|
||||
return dict;
|
||||
},
|
||||
add_menu: function () {
|
||||
var self = this;
|
||||
var dialog = new website.menu.AddMenuDialog();
|
||||
dialog.on('add-menu', this, function (link) {
|
||||
var context = {
|
||||
submenu: {
|
||||
name: link[2] || link[0],
|
||||
new_window: link[1],
|
||||
url: link[0],
|
||||
children: [],
|
||||
},
|
||||
var new_menu = {
|
||||
id: _.uniqueId('new-'),
|
||||
name: link[2] || link[0],
|
||||
url: link[0],
|
||||
new_window: link[1],
|
||||
parent_id: false,
|
||||
sequence: 0,
|
||||
children: [],
|
||||
};
|
||||
self.flat[new_menu.id] = new_menu;
|
||||
self.$('.oe_menu_editor').append(
|
||||
openerp.qweb.render(
|
||||
'website.menu.dialog.submenu', context));
|
||||
'website.menu.dialog.submenu', { submenu: new_menu }));
|
||||
});
|
||||
dialog.appendTo(document.body);
|
||||
},
|
||||
save: function () {
|
||||
debugger
|
||||
var self = this;
|
||||
var new_menu = this.$('.oe_menu_editor').nestedSortable('toArray', {startDepthCount: 0});
|
||||
var levels = [];
|
||||
var data = [];
|
||||
var context = website.get_context();
|
||||
// Resquence, re-tree and remove useless data
|
||||
new_menu.forEach(function (menu) {
|
||||
if (menu.item_id) {
|
||||
levels[menu.depth] = (levels[menu.depth] || 0) + 1;
|
||||
var mobj = self.flat[menu.item_id];
|
||||
mobj.sequence = levels[menu.depth];
|
||||
mobj.parent_id = (menu.parent_id|0) || menu.parent_id || self.root_menu_id;
|
||||
delete(mobj.children);
|
||||
delete(mobj.level);
|
||||
data.push(mobj);
|
||||
}
|
||||
});
|
||||
openerp.jsonRpc('/web/dataset/call_kw', 'call', {
|
||||
model: 'website.menu',
|
||||
method: 'save',
|
||||
args: [[context.website_id], data],
|
||||
kwargs: {
|
||||
context: context
|
||||
},
|
||||
}).then(function (menu) {
|
||||
self.close();
|
||||
website.reload();
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<templates id="template" xml:space="preserve">
|
||||
<t t-name="website.menu.dialog.submenu">
|
||||
<li>
|
||||
<li t-att-data-menu-id="submenu.id">
|
||||
<div>
|
||||
<t t-esc="submenu.name"/>
|
||||
<button type="button" class="btn-xs pull-right delete-menu btn-danger">
|
||||
|
|
Loading…
Reference in New Issue