From 4b4bef4e0b63b20ed82535091822a9dee7cdee77 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Thu, 7 Dec 2017 17:46:13 +0300 Subject: [PATCH] Added groups for plugins. --- apps/common/main/lib/controller/Plugins.js | 11 ++++++++++- apps/common/main/lib/model/Plugin.js | 4 +++- .../documenteditor/main/app/controller/Main.js | 18 +++++++++++++++--- .../main/app/controller/Main.js | 18 +++++++++++++++--- .../main/app/controller/Main.js | 18 +++++++++++++++--- 5 files changed, 58 insertions(+), 11 deletions(-) diff --git a/apps/common/main/lib/controller/Plugins.js b/apps/common/main/lib/controller/Plugins.js index c5d98ef50..be37b5b57 100644 --- a/apps/common/main/lib/controller/Plugins.js +++ b/apps/common/main/lib/controller/Plugins.js @@ -192,13 +192,22 @@ define([ if ( me.$toolbarPanelPlugins ) { me.$toolbarPanelPlugins.empty(); - var _group = $('
'); + var _group = $('
'), + rank = -1; collection.each(function (model) { + var new_rank = model.get('groupRank'); + if (new_rank!==rank && rank>-1) { + _group.appendTo(me.$toolbarPanelPlugins); + $('
').appendTo(me.$toolbarPanelPlugins); + _group = $('
'); + } + var btn = me.panelPlugins.createPluginButton(model); if (btn) { var $slot = $('').appendTo(_group); btn.render($slot); } + rank = new_rank; }); _group.appendTo(me.$toolbarPanelPlugins); } diff --git a/apps/common/main/lib/model/Plugin.js b/apps/common/main/lib/model/Plugin.js index 8069a9c29..2b1b73602 100644 --- a/apps/common/main/lib/model/Plugin.js +++ b/apps/common/main/lib/model/Plugin.js @@ -84,7 +84,9 @@ define([ pluginObj: undefined, allowSelected: false, selected: false, - visible: true + visible: true, + groupName: '', + groupRank: 0 } } }); diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index 17ae18aea..6794bfd05 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -1994,15 +1994,27 @@ define([ baseUrl : item.baseUrl, variations: variationsArr, currentVariation: 0, - visible: pluginVisible + visible: pluginVisible, + groupName: (item.group) ? item.group.name : '', + groupRank: (item.group) ? item.group.rank : 0 })); }); if ( uiCustomize!==false ) // from ui customizer in editor config or desktop event this.UICustomizePlugins = arrUI; - if ( !uiCustomize ) { - if (pluginStore) pluginStore.add(arr); + if ( !uiCustomize && pluginStore) { + arr = pluginStore.models.concat(arr); + arr.sort(function(a, b){ + var rank_a = a.get('groupRank'), + rank_b = b.get('groupRank'); + if (rank_a < rank_b) + return (rank_a==0) ? 1 : -1; + if (rank_a > rank_b) + return (rank_b==0) ? -1 : 1; + return 0; + }); + pluginStore.reset(arr); this.appOptions.canPlugins = !pluginStore.isEmpty(); } } else if (!uiCustomize){ diff --git a/apps/presentationeditor/main/app/controller/Main.js b/apps/presentationeditor/main/app/controller/Main.js index dfa2c8e2c..1fc3d1ff7 100644 --- a/apps/presentationeditor/main/app/controller/Main.js +++ b/apps/presentationeditor/main/app/controller/Main.js @@ -1766,15 +1766,27 @@ define([ baseUrl : item.baseUrl, variations: variationsArr, currentVariation: 0, - visible: pluginVisible + visible: pluginVisible, + groupName: (item.group) ? item.group.name : '', + groupRank: (item.group) ? item.group.rank : 0 })); }); if (uiCustomize!==false) // from ui customizer in editor config or desktop event this.UICustomizePlugins = arrUI; - if ( !uiCustomize ) { - if (pluginStore) pluginStore.add(arr); + if ( !uiCustomize && pluginStore) { + arr = pluginStore.models.concat(arr); + arr.sort(function(a, b){ + var rank_a = a.get('groupRank'), + rank_b = b.get('groupRank'); + if (rank_a < rank_b) + return (rank_a==0) ? 1 : -1; + if (rank_a > rank_b) + return (rank_b==0) ? -1 : 1; + return 0; + }); + pluginStore.reset(arr); this.appOptions.canPlugins = !pluginStore.isEmpty(); } } else if (!uiCustomize){ diff --git a/apps/spreadsheeteditor/main/app/controller/Main.js b/apps/spreadsheeteditor/main/app/controller/Main.js index 1729e2d0e..28bdbc31f 100644 --- a/apps/spreadsheeteditor/main/app/controller/Main.js +++ b/apps/spreadsheeteditor/main/app/controller/Main.js @@ -1962,15 +1962,27 @@ define([ baseUrl : item.baseUrl, variations: variationsArr, currentVariation: 0, - visible: pluginVisible + visible: pluginVisible, + groupName: (item.group) ? item.group.name : '', + groupRank: (item.group) ? item.group.rank : 0 })); }); if (uiCustomize!==false) // from ui customizer in editor config or desktop event this.UICustomizePlugins = arrUI; - if (!uiCustomize) { - if (pluginStore) pluginStore.add(arr); + if ( !uiCustomize && pluginStore) { + arr = pluginStore.models.concat(arr); + arr.sort(function(a, b){ + var rank_a = a.get('groupRank'), + rank_b = b.get('groupRank'); + if (rank_a < rank_b) + return (rank_a==0) ? 1 : -1; + if (rank_a > rank_b) + return (rank_b==0) ? -1 : 1; + return 0; + }); + pluginStore.reset(arr); this.appOptions.canPlugins = !pluginStore.isEmpty(); } } else if (!uiCustomize){