diff --git a/apps/common/main/lib/controller/Plugins.js b/apps/common/main/lib/controller/Plugins.js index 99d34e7194..3d6289a414 100644 --- a/apps/common/main/lib/controller/Plugins.js +++ b/apps/common/main/lib/controller/Plugins.js @@ -197,6 +197,7 @@ define([ this.api.asc_registerCallback("asc_onPluginWindowResize", _.bind(this.onPluginWindowResize, this)); this.api.asc_registerCallback("asc_onPluginWindowMouseUp", _.bind(this.onPluginWindowMouseUp, this)); this.api.asc_registerCallback("asc_onPluginWindowMouseMove", _.bind(this.onPluginWindowMouseMove, this)); + this.api.asc_registerCallback("asc_onPluginWindowActivate", _.bind(this.openUIPlugin, this)); this.loadPlugins(); } @@ -494,6 +495,15 @@ define([ }); } }); + for (var key in this.viewPlugins.customPluginPanels) { + var panel = this.viewPlugins.customPluginPanels[key], + menu = panel.menu === 'right' ? iconsInRightMenu : iconsInLeftMenu; + menu.push({ + guid: panel.frameId, + baseUrl: panel.baseUrl, + parsedIcons: this.viewPlugins.parseIcons(panel.icons) + }); + } if (iconsInLeftMenu.length > 0) { me.viewPlugins.fireEvent('pluginsleft:updateicons', [iconsInLeftMenu]); } @@ -610,10 +620,10 @@ define([ this.viewPlugins.pluginPanels[pluginGuid].on('render:after', _.bind(this.onAfterRender, this, this.viewPlugins.pluginPanels[pluginGuid], pluginGuid)); }, - openUIPlugin: function (guid) { - var model = this.viewPlugins.storePlugins.findWhere({guid: guid}), - menu = model.get('menu'); - this.viewPlugins.fireEvent(menu === 'right' ? 'pluginsright:open' : 'pluginsleft:open', [guid]); + openUIPlugin: function (id) { + var model = this.viewPlugins.storePlugins.findWhere({guid: id}), + menu = model ? model.get('menu') : (this.viewPlugins.customPluginPanels[id] && this.viewPlugins.customPluginPanels[id].menu); + this.viewPlugins.fireEvent(menu === 'right' ? 'pluginsright:open' : 'pluginsleft:open', [id]); }, onPluginShow: function(plugin, variationIndex, frameId, urlAddition) { @@ -737,7 +747,7 @@ define([ }, onToolClose: function(panel) { - this.api.asc_pluginButtonClick(-1, panel ? panel._state.insidePlugin : undefined); + this.api.asc_pluginButtonClick(-1, panel && panel._state.insidePlugin, panel && panel.frameId); }, onPluginMouseUp: function(x, y) { @@ -1064,13 +1074,16 @@ define([ // Plugin can create windows onPluginWindowShow: function(frameId, variation) { if (variation.isVisual) { - if (this.customPluginsDlg[frameId]) return; + if (this.customPluginsDlg[frameId] || this.viewPlugins.customPluginPanels[frameId]) return; var lang = this.appOptions && this.appOptions.lang ? this.appOptions.lang.split(/[\-_]/)[0] : 'en'; var url = variation.url, // full url - isSystem = (true === variation.isSystem) || (Asc.PluginType.System === variation.type); + isSystem = (true === variation.isSystem) || (Asc.PluginType.System === variation.type), + isPanel = variation.type === 'panel'; var visible = (this.appOptions.isEdit || variation.isViewer && (variation.isDisplayedInViewer!==false)) && _.contains(variation.EditorsSupport, this.editor) && !isSystem; - if (visible && !variation.isInsideMode) { + if (visible && isPanel) { + this.onPluginPanelShow(frameId, variation, lang); + } else if (visible && !variation.isInsideMode) { var me = this, isCustomWindow = variation.isCustomWindow, arrBtns = variation.buttons, @@ -1136,8 +1149,17 @@ define([ }, onPluginWindowClose: function(frameId) { - if (this.customPluginsDlg[frameId]) + if (this.customPluginsDlg[frameId]) { this.customPluginsDlg[frameId].close(); + } else if (this.viewPlugins.customPluginPanels[frameId]) { + var panel = this.viewPlugins.customPluginPanels[frameId]; + if (panel && panel.iframePlugin) { + panel.closeInsideMode(); + panel.$el.remove(); + delete this.viewPlugins.customPluginPanels[frameId]; + this.viewPlugins.fireEvent(panel.menu === 'right' ? 'pluginsright:close' : 'pluginsleft:close', [frameId]); + } + } }, onPluginWindowResize: function(frameId, size, minSize, maxSize, callback ) { @@ -1165,6 +1187,49 @@ define([ if (this.customPluginsDlg[frameId].binding.resize) this.customPluginsDlg[frameId].binding.resize({ pageX: x*Common.Utils.zoom()+offset.left, pageY: y*Common.Utils.zoom()+offset.top }); } else Common.NotificationCenter.trigger('frame:mousemove', { pageX: x*Common.Utils.zoom()+this._moveOffset.x, pageY: y*Common.Utils.zoom()+this._moveOffset.y }); + }, + + onPluginPanelShow: function (frameId, variation, lang) { + var guid = variation.guid, + menu = this.isPDFEditor ? 'left' : variation.menu; + !menu && (menu = 'left'); + + var description = variation.description; + if (typeof variation.descriptionLocale == 'object') + description = variation.descriptionLocale[lang] || variation.descriptionLocale['en'] || description || ''; + + var model = this.viewPlugins.storePlugins.findWhere({guid: guid}), + modes = model.get('variations'), + icons = variation.icons ? variation.icons : modes[model.get('currentVariation')].get('icons'), + parsedIcons = this.viewPlugins.parseIcons(icons), + icon_url = model.get('baseUrl') + parsedIcons['normal']; + + var $button = $('
'), + button = new Common.UI.Button({ + parentEl: $button, + cls: 'btn-category plugin-buttons', + hint: description, + enableToggle: true, + toggleGroup: menu === 'right' ? 'tabpanelbtnsGroup' : 'leftMenuGroup', + iconImg: icon_url, + onlyIcon: true, + value: frameId, + type: 'plugin' + }); + var $panel = $('
'); + this.viewPlugins.fireEvent(menu === 'right' ? 'plugins:addtoright' : 'plugins:addtoleft', [button, $button, $panel]); + this.viewPlugins.customPluginPanels[frameId] = new Common.Views.PluginPanel({ + el: '#panel-plugins-' + frameId, + menu: menu, + frameId: frameId, + baseUrl: model.get('baseUrl'), + icons: icons + }); + this.viewPlugins.customPluginPanels[frameId].on('render:after', _.bind(this.onAfterRender, this, this.viewPlugins.customPluginPanels[frameId], frameId)); + + if (!this.viewPlugins.customPluginPanels[frameId].openInsideMode(description, variation.url, frameId, guid)) + this.api.asc_pluginButtonClick(-1, guid, frameId); } + }, Common.Controllers.Plugins || {})); }); diff --git a/apps/common/main/lib/view/Plugins.js b/apps/common/main/lib/view/Plugins.js index 66b1ea954f..8e10609f4a 100644 --- a/apps/common/main/lib/view/Plugins.js +++ b/apps/common/main/lib/view/Plugins.js @@ -65,6 +65,7 @@ define([ }; this.lockedControls = []; this.pluginPanels = {}; + this.customPluginPanels = {}; Common.UI.BaseView.prototype.initialize.call(this, arguments); }, @@ -505,18 +506,23 @@ define([ this.fireEvent('hide', this ); }, - showPluginPanel: function (show, guid) { - var model = this.storePlugins.findWhere({guid: guid}), - menu = model.get('menu'); + showPluginPanel: function (show, id) { + var panel = this.pluginPanels[id] ? this.pluginPanels[id] : this.customPluginPanels[id], + menu = this.pluginPanels[id] ? this.storePlugins.findWhere({guid: id}).get('menu') : panel.menu; if (show) { for (var key in this.pluginPanels) { if (this.pluginPanels[key].menu === menu) { this.pluginPanels[key].$el.removeClass('active'); } } - this.pluginPanels[guid].$el.addClass('active'); + for (var key in this.customPluginPanels) { + if (this.customPluginPanels[key].menu === menu) { + this.customPluginPanels[key].$el.removeClass('active'); + } + } + panel.$el.addClass('active'); } else { - this.pluginPanels[guid].$el.removeClass('active'); + panel.$el.removeClass('active'); this.fireEvent(menu === 'right' ? 'pluginsright:hide' : 'pluginsleft:hide', this); } //this.updateLeftPluginButton(guid);