changeset 867cf78ac8a8 in sao:default
details: https://hg.tryton.org/sao?cmd=changeset;node=867cf78ac8a8
description:
Add support for plugins and add translate view as example
issue7942
review54461002
diffstat:
CHANGELOG | 1 +
Gruntfile.js | 3 +-
src/plugins.js | 29 +++++++++++++++++++++++++
src/sao.js | 2 +
src/tab.js | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
5 files changed, 95 insertions(+), 7 deletions(-)
diffs (151 lines):
diff -r d869e4c6206e -r 867cf78ac8a8 CHANGELOG
--- a/CHANGELOG Thu Jan 17 17:17:17 2019 +0100
+++ b/CHANGELOG Fri Jan 18 10:23:13 2019 +0100
@@ -1,3 +1,4 @@
+* Add support for plugins
* Add support for expand, height and width attributes
* Add drag & drop support on attachment button
diff -r d869e4c6206e -r 867cf78ac8a8 Gruntfile.js
--- a/Gruntfile.js Thu Jan 17 17:17:17 2019 +0100
+++ b/Gruntfile.js Fri Jan 18 10:23:13 2019 +0100
@@ -21,7 +21,8 @@
'src/window.js',
'src/wizard.js',
'src/board.js',
- 'src/bus.js'
+ 'src/bus.js',
+ 'src/plugins.js'
];
// Project configuration.
diff -r d869e4c6206e -r 867cf78ac8a8 src/plugins.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/plugins.js Fri Jan 18 10:23:13 2019 +0100
@@ -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 -r d869e4c6206e -r 867cf78ac8a8 src/sao.js
--- a/src/sao.js Thu Jan 17 17:17:17 2019 +0100
+++ b/src/sao.js Fri Jan 18 10:23:13 2019 +0100
@@ -1085,6 +1085,8 @@
return false;
}
+ Sao.Plugins = [];
+
// Fix stacked modal
jQuery(document)
.on('show.bs.modal', '.modal', function(event) {
diff -r d869e4c6206e -r 867cf78ac8a8 src/tab.js
--- a/src/tab.js Thu Jan 17 17:17:17 2019 +0100
+++ b/src/tab.js Fri Jan 18 10:23:13 2019 +0100
@@ -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('<li/>', {
+ '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('<li/>', {
'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('<li/>', {
+ 'role': 'separator',
+ 'class': 'divider',
+ }));
+ }
+ kw_plugins.forEach(function(plugin) {
+ var name = plugin[0],
+ func = plugin[1];
+ jQuery('<li/>', {
+ 'role': 'presentation',
+ 'class': menu_action[0] + '_plugin',
+ }).append(
+ jQuery('<a/>', {
+ '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) {