diff --git a/CHANGELOG b/CHANGELOG index 6985758a24..d90ec24c1b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Add support for plugins * Add support for expand, height and width attributes * Add drag & drop support on attachment button diff --git a/Gruntfile.js b/Gruntfile.js index 0626359c6c..5e40908ab6 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -21,7 +21,8 @@ module.exports = function(grunt) { 'src/window.js', 'src/wizard.js', 'src/board.js', - 'src/bus.js' + 'src/bus.js', + 'src/plugins.js' ]; // Project configuration. diff --git a/src/plugins.js b/src/plugins.js new file mode 100644 index 0000000000..011c7e3031 --- /dev/null +++ b/src/plugins.js @@ -0,0 +1,29 @@ +/* This file is part of Tryton. The COPYRIGHT file at the top level of + this repository contains the full copyright notices and license terms. */ + +(function() { + 'use strict'; + + var Translate = {}; + Translate.translate_view = function(data) { + var model = data.model; + Sao.Tab.create({ + model: 'ir.translation', + domain: [['model', '=', model]], + mode: ['tree', 'form'], + name: Sao.i18n.gettext('Translate view'), + }); + }; + Translate.get_plugins = function(model) { + var access = Sao.common.MODELACCESS.get(model); + if (access.create && access.write) { + return [ + [Sao.i18n.gettext('Translate view'), Translate.translate_view], + ]; + } else { + return []; + } + }; + + Sao.Plugins.push(Translate); +}()); diff --git a/src/sao.js b/src/sao.js index 3e582e2f3e..3bb159b02d 100644 --- a/src/sao.js +++ b/src/sao.js @@ -1085,6 +1085,8 @@ var Sao = {}; return false; } + Sao.Plugins = []; + // Fix stacked modal jQuery(document) .on('show.bs.modal', '.modal', function(event) { diff --git a/src/tab.js b/src/tab.js index 6e01d59cd8..1510a68de1 100644 --- a/src/tab.js +++ b/src/tab.js @@ -565,13 +565,20 @@ var menu = button.find('.dropdown-menu'); button.click(function() { menu.find('.' + menu_action[0] + '_button').remove(); - var buttons = screen.get_buttons(); + menu.find('.divider').remove(); + menu.find('.' + menu_action[0] + '_plugin').remove(); + var buttons = screen.get_buttons().filter( + function(button) { + return menu_action[0] == ( + button.attributes.keyword || 'action'); + }); + if (buttons.length) { + menu.append(jQuery('
  • ', { + 'role': 'separator', + 'class': 'divider', + })); + } buttons.forEach(function(button) { - var button_kw = (button.attributes.keyword || - 'action'); - if (button_kw != menu_action[0]) { - return; - } var item = jQuery('
  • ', { 'role': 'presentation', 'class': menu_action[0] + '_button' @@ -589,6 +596,54 @@ }) .appendTo(menu); }); + + var kw_plugins = []; + Sao.Plugins.forEach(function(plugin) { + plugin.get_plugins(screen.model.name).forEach( + function(spec) { + var name = spec[0], + func = spec[1], + keyword = spec[2] || 'action'; + if (keyword != menu_action[0]) { + return; + } + kw_plugins.push([name, func]); + }); + }); + if (kw_plugins.length) { + menu.append(jQuery('
  • ', { + 'role': 'separator', + 'class': 'divider', + })); + } + kw_plugins.forEach(function(plugin) { + var name = plugin[0], + func = plugin[1]; + jQuery('
  • ', { + 'role': 'presentation', + 'class': menu_action[0] + '_plugin', + }).append( + jQuery('', { + 'role': 'menuitem', + 'href': '#', + 'tabindex': -1, + }).append(name)) + .click(function(evt) { + evt.preventDefault(); + var ids = screen.current_view.selected_records() + .map(function(record) { + return record.id; + }); + var id = screen.current_record ? + screen.current_record.id : null; + func({ + 'model': screen.model.name, + 'ids': ids, + 'id': id, + }); + }) + .appendTo(menu); + }); }); toolbars[menu_action[0]].forEach(function(action) {