diff --git a/web_shortcuts/model/view_sc.py b/web_shortcuts/model/view_sc.py index 0e79788b..7931fe31 100644 --- a/web_shortcuts/model/view_sc.py +++ b/web_shortcuts/model/view_sc.py @@ -29,39 +29,36 @@ from openerp.osv import orm, fields -class view_sc(orm.Model): - _name = 'ir.ui.view_sc' +class web_shortcut(orm.Model): + _name = 'web.shortcut' _columns = { - 'name': fields.char('Shortcut Name', size=64), # Kept for backwards compatibility only - resource name used instead (translatable) - 'res_id': fields.integer('Resource Ref.', help="Reference of the target resource, whose model/table depends on the 'Resource Name' field."), - 'sequence': fields.integer('Sequence'), - 'user_id': fields.many2one('res.users', 'User Ref.', required=True, ondelete='cascade', select=True), - 'resource': fields.char('Resource Name', size=64, required=True, select=True) + 'name': fields.char('Shortcut Name', size=64), + 'menu_id': fields.many2one('ir.ui.menu'), + 'user_id': fields.many2one('res.users', 'User Ref.', required=True, + ondelete='cascade', select=True), } - def _auto_init(self, cr, context=None): - super(view_sc, self)._auto_init(cr, context) - cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = \'ir_ui_view_sc_user_id_resource\'') - if not cr.fetchone(): - cr.execute('CREATE INDEX ir_ui_view_sc_user_id_resource ON ir_ui_view_sc (user_id, resource)') - - def get_sc(self, cr, uid, user_id, model='ir.ui.menu', context=None): - ids = self.search(cr, uid, [('user_id','=',user_id),('resource','=',model)], context=context) - results = self.read(cr, uid, ids, ['res_id'], context=context) - name_map = dict(self.pool.get(model).name_get(cr, uid, [x['res_id'] for x in results], context=context)) + def get_user_shortcuts(self, cr, uid, user_id, context=None): + ids = self.search(cr, uid, [('user_id', '=', user_id)], + context=context) + results = self.read(cr, uid, ids, ['menu_id'], context=context) + name_map = dict(self.pool.get('ir.ui.menu') + .name_get(cr, uid, [x['menu_id'][0] for x in results], + context=context)) # Make sure to return only shortcuts pointing to exisintg menu items. - filtered_results = filter(lambda result: result['res_id'] in name_map, results) + filtered_results = filter(lambda result: result['menu_id'][0] in + name_map, results) for result in filtered_results: - result.update(name=name_map[result['res_id']]) + result.update(name=name_map[result['menu_id'][0]]) return filtered_results - _order = 'sequence,name' + _order = 'name' _defaults = { - 'resource': 'ir.ui.menu', 'user_id': lambda obj, cr, uid, context: uid, } _sql_constraints = [ - ('shortcut_unique', 'unique(res_id, resource, user_id)', 'Shortcut for this menu already exists!'), + ('shortcut_unique', 'unique(menu_id,user_id)', + 'Shortcut for this menu already exists!'), ] # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/web_shortcuts/static/src/js/web_shortcuts.js b/web_shortcuts/static/src/js/web_shortcuts.js index af763462..943def16 100644 --- a/web_shortcuts/static/src/js/web_shortcuts.js +++ b/web_shortcuts/static/src/js/web_shortcuts.js @@ -33,7 +33,7 @@ instance.web_shortcuts.Shortcuts = instance.web.Widget.extend({ this.on('display', this, this.display); this.on('remove', this, this.remove); this.on('click', this, this.click); - this.model = new instance.web.Model('ir.ui.view_sc'); + this.model = new instance.web.Model('web.shortcut'); }, start: function() { var self = this; @@ -46,9 +46,8 @@ instance.web_shortcuts.Shortcuts = instance.web.Widget.extend({ load: function() { var self = this; this.$el.find('.oe_systray_shortcuts_items').empty(); - return this.model.call('get_sc', [ + return this.model.call('get_user_shortcuts', [ instance.session.uid, - 'ir.ui.menu', instance.web.pyeval.eval('context', {}) ]).done(function(shortcuts) { _.each(shortcuts, function(sc) { @@ -138,8 +137,7 @@ instance.web.ViewManagerAction.include({ } else { shortcuts_menu.trigger('add', { 'user_id': self.session.uid, - 'res_id': self.session.active_id, - 'resource': 'ir.ui.menu', + 'menu_id': self.session.active_id, 'name': self.action.name }); } diff --git a/web_shortcuts/static/src/xml/web_shortcuts.xml b/web_shortcuts/static/src/xml/web_shortcuts.xml index 8500eb63..260e8d87 100644 --- a/web_shortcuts/static/src/xml/web_shortcuts.xml +++ b/web_shortcuts/static/src/xml/web_shortcuts.xml @@ -13,7 +13,7 @@
  • - +