Commit 7b86f889 authored by Julia Radzhabova's avatar Julia Radzhabova

[DE] Изменена структура плагинов.

parent 229d7110
...@@ -107,37 +107,62 @@ ...@@ -107,37 +107,62 @@
chat: false, chat: false,
comments: false comments: false
}, },
plugins: [{ plugins: {
name: "chess (fen)", url: '../../../../sdkjs-plugins/',
guid: "{FFE1F462-1EA2-4391-990D-4CC84940B754}", pluginsData: [{
url: "chess/index.html", name : "chess (fen)",
icons: ["chess/icon.png", "chess/icon2x.png"], guid : "{FFE1F462-1EA2-4391-990D-4CC84940B754}",
isVisual: true,
initDataType: 2, variations : [
isUpdateOleOnResize: true,
buttons: [{text:"Ok",primary:true},{text:"Cancel",primary:false}]
},
{ {
name: "glavred", description : "chess",
guid: "{B631E142-E40B-4B4C-90B9-2D00222A286E}", url : "chess/index.html",
url: "glavred/index.html",
icons: ["glavred/icon.png", "glavred/icon2x.png"], icons : ["chess/icon.png", "chess/icon@2x.png"],
isVisual: true, isViewer : true,
initDataType: 1, EditorsSupport : ["word", "cell", "slide"],
isUpdateOleOnResize: false,
buttons: [{text:"Ok",primary:true}] isVisual : true,
}, isModal : true,
isInsideMode : false,
initDataType : "ole",
initData : "",
isUpdateOleOnResize : true,
buttons : [ { text: "Ok", primary: true },
{ text: "Cancel", primary: false } ]
}
]
},
{
name : "glavred",
guid : "{B631E142-E40B-4B4C-90B9-2D00222A286E}",
variations : [
{ {
name: "bold", description : "glavred",
guid: "{14E46CC2-5E56-429C-9D55-1032B596D928}", url : "glavred/index.html",
url: "bold/index.html",
icons: ["bold/icon.png", "bold/icon2x.png"], icons : ["glavred/icon.png", "glavred/icon@2x.png"],
isVisual: false, isViewer : true,
initDataType: 0, EditorsSupport : ["word", "cell", "slide"],
isUpdateOleOnResize: false,
buttons: [] isVisual : true,
isModal : true,
isInsideMode : false,
initDataType : "text",
initData : "",
isUpdateOleOnResize : false,
buttons : [ { text: "Ok", primary: true } ]
} }
] ]
}
}
}, },
events: { events: {
'onReady': <document ready callback>, 'onReady': <document ready callback>,
......
...@@ -68,24 +68,6 @@ define([ ...@@ -68,24 +68,6 @@ define([
setApi: function(api) { setApi: function(api) {
this.api = api; this.api = api;
var me = this;
var storePlugins = this.getApplication().getCollection('Common.Collections.Plugins'),
arr = [];
storePlugins.each(function(item){
var plugin = new Asc.CPlugin();
plugin.set_Name(item.get('name'));
plugin.set_Guid(item.get('guid'));
plugin.set_Url(item.get('url'));
plugin.set_Icons(item.get('icons'));
plugin.set_Visual(item.get('isVisual'));
plugin.set_InitDataType(item.get('initDataType'));
plugin.set_UpdateOleOnResize(item.get('isUpdateOleOnResize'));
plugin.set_Buttons(item.get('buttons'));
item.set('pluginObj', plugin);
arr.push(plugin);
});
this.api.asc_pluginsRegister(this.panelPlugins.pluginsPath, arr);
this.api.asc_registerCallback("asc_onPluginShow", _.bind(this.onPluginShow, this)); this.api.asc_registerCallback("asc_onPluginShow", _.bind(this.onPluginShow, this));
this.api.asc_registerCallback("asc_onPluginClose", _.bind(this.onPluginClose, this)); this.api.asc_registerCallback("asc_onPluginClose", _.bind(this.onPluginClose, this));
...@@ -93,21 +75,59 @@ define([ ...@@ -93,21 +75,59 @@ define([
}, },
setMode: function(mode) { setMode: function(mode) {
if (mode.canPlugins) {
this.panelPlugins.pluginsPath = mode.pluginsPath;
this.updatePluginsList();
}
}, },
onAfterRender: function(historyView) { onAfterRender: function(historyView) {
historyView.viewPluginsList.on('item:click', _.bind(this.onSelectPlugin, this)); historyView.viewPluginsList.on('item:click', _.bind(this.onSelectPlugin, this));
}, },
updatePluginsList: function() {
var me = this;
var storePlugins = this.getApplication().getCollection('Common.Collections.Plugins'),
arr = [];
storePlugins.each(function(item){
var plugin = new Asc.CPlugin();
plugin.set_Name(item.get('name'));
plugin.set_Guid(item.get('guid'));
var variations = item.get('variations'),
variationsArr = [];
variations.forEach(function(itemVar){
var variation = new Asc.CPluginVariation();
variation.set_Description(itemVar.get('description'));
variation.set_Url(itemVar.get('url'));
variation.set_Icons(itemVar.get('icons'));
variation.set_Visual(itemVar.get('isVisual'));
variation.set_Viewer(itemVar.get('isViewer'));
variation.set_EditorsSupport(itemVar.get('EditorsSupport'));
variation.set_Modal(itemVar.get('isModal'));
variation.set_InsideMode(itemVar.get('isInsideMode'));
variation.set_InitDataType(itemVar.get('initDataType'));
variation.set_InitData(itemVar.get('initData'));
variation.set_UpdateOleOnResize(itemVar.get('isUpdateOleOnResize'));
variation.set_Buttons(itemVar.get('buttons'));
variationsArr.push(variation);
});
plugin.set_Variations(variationsArr);
item.set('pluginObj', plugin);
arr.push(plugin);
});
this.api.asc_pluginsRegister(this.panelPlugins.pluginsPath, arr);
},
onSelectPlugin: function(picker, item, record){ onSelectPlugin: function(picker, item, record){
this.api.asc_pluginRun(record.get('guid'), ''); this.api.asc_pluginRun(record.get('guid'), record.get('currentVariation'), '');
}, },
onPluginShow: function(plugin) { onPluginShow: function(plugin) {
if (!plugin.get_Visual()) return; var variation = plugin.get_Variations()[0];
if (!variation.get_Visual()) return;
var me = this, var me = this,
arrBtns = plugin.get_Buttons(), arrBtns = variation.get_Buttons(),
newBtns = {}; newBtns = {};
if (_.isArray(arrBtns)) { if (_.isArray(arrBtns)) {
...@@ -118,7 +138,7 @@ define([ ...@@ -118,7 +138,7 @@ define([
me.pluginDlg = new Common.Views.PluginDlg({ me.pluginDlg = new Common.Views.PluginDlg({
title: plugin.get_Name(), title: plugin.get_Name(),
url: me.panelPlugins.pluginsPath + plugin.get_Url(), url: me.panelPlugins.pluginsPath + variation.get_Url(),
buttons: newBtns, buttons: newBtns,
toolcallback: _.bind(this.onToolClose, this) toolcallback: _.bind(this.onToolClose, this)
}); });
...@@ -130,7 +150,7 @@ define([ ...@@ -130,7 +150,7 @@ define([
me.pluginDlg.show(); me.pluginDlg.show();
}, },
onPluginClose: function(plugin) { onPluginClose: function() {
if (this.pluginDlg) if (this.pluginDlg)
this.pluginDlg.close(); this.pluginDlg.close();
}, },
......
...@@ -48,18 +48,34 @@ define([ ...@@ -48,18 +48,34 @@ define([
], function(_, Backbone){ ], function(_, Backbone){
'use strict'; 'use strict';
Common.Models.PluginVariation = Backbone.Model.extend({
defaults: function() {
return {
description: "",
url: "",
index: 0,
icons: undefined,
isViewer: false,
EditorsSupport: ["word", "cell", "slide"],
isVisual: false,
isModal: false,
isInsideMode: false,
initDataType: 0,
initData: "",
isUpdateOleOnResize: false,
buttons: []
}
}
});
Common.Models.Plugin = Backbone.Model.extend({ Common.Models.Plugin = Backbone.Model.extend({
defaults: function() { defaults: function() {
return { return {
id: Common.UI.getId(), id: Common.UI.getId(),
name : '', name : '',
guid: Common.UI.getId(), guid: Common.UI.getId(),
url : undefined, variations: [],
icons : undefined, currentVariation: 0,
isVisual: false,
initDataType: undefined,
isUpdateOleOnResize : false,
buttons: [{text:"Ok",primary:true},{text:"Cancel",primary:false}],
pluginObj: undefined, pluginObj: undefined,
allowSelected: false, allowSelected: false,
selected: false selected: false
......
...@@ -75,7 +75,7 @@ define([ ...@@ -75,7 +75,7 @@ define([
el: $('#plugins-list'), el: $('#plugins-list'),
store: this.storePlugins, store: this.storePlugins,
enableKeyEvents: false, enableKeyEvents: false,
itemTemplate: _.template('<div id="<%= id %>" class="item-plugins" style="background-image: url(' + this.pluginsPath + '<%= icons[(window.devicePixelRatio > 1) ? 1 : 0] %>); background-position: 0 0;"></div>') itemTemplate: _.template('<div id="<%= id %>" class="item-plugins" style="background-image: url(' + this.pluginsPath + '<%= variations[currentVariation].get("icons")[(window.devicePixelRatio > 1) ? 1 : 0] %>); background-position: 0 0;"></div>')
}); });
this.trigger('render:after', this); this.trigger('render:after', this);
......
...@@ -174,14 +174,18 @@ define([ ...@@ -174,14 +174,18 @@ define([
if (this.mode.canUseHistory) if (this.mode.canUseHistory)
this.leftMenu.setOptionsPanel('history', this.getApplication().getController('Common.Controllers.History').getView('Common.Views.History')); this.leftMenu.setOptionsPanel('history', this.getApplication().getController('Common.Controllers.History').getView('Common.Views.History'));
this.enablePlugins();
Common.util.Shortcuts.resumeEvents();
return this;
},
enablePlugins: function() {
if (this.mode.canPlugins) { if (this.mode.canPlugins) {
this.leftMenu.btnPlugins.show(); this.leftMenu.btnPlugins.show();
this.leftMenu.setOptionsPanel('plugins', this.getApplication().getController('Common.Controllers.Plugins').getView('Common.Views.Plugins')); this.leftMenu.setOptionsPanel('plugins', this.getApplication().getController('Common.Controllers.Plugins').getView('Common.Views.Plugins'));
} else } else
this.leftMenu.btnPlugins.hide(); this.leftMenu.btnPlugins.hide();
Common.util.Shortcuts.resumeEvents();
return this;
}, },
clickMenuFileItem: function(menu, action, isopts) { clickMenuFileItem: function(menu, action, isopts) {
......
...@@ -138,7 +138,7 @@ define([ ...@@ -138,7 +138,7 @@ define([
// Initialize api gateway // Initialize api gateway
this.editorConfig = {}; this.editorConfig = {};
this.appOptions = {}; this.appOptions = {};
this.plugins = []; this.plugins = undefined;
Common.Gateway.on('init', _.bind(this.loadConfig, this)); Common.Gateway.on('init', _.bind(this.loadConfig, this));
Common.Gateway.on('showmessage', _.bind(this.onExternalMessage, this)); Common.Gateway.on('showmessage', _.bind(this.onExternalMessage, this));
Common.Gateway.on('opendocument', _.bind(this.loadDocument, this)); Common.Gateway.on('opendocument', _.bind(this.loadDocument, this));
...@@ -243,6 +243,8 @@ define([ ...@@ -243,6 +243,8 @@ define([
this.appOptions.canBackToFolder = (this.editorConfig.canBackToFolder!==false) && (typeof (this.editorConfig.customization) == 'object') this.appOptions.canBackToFolder = (this.editorConfig.canBackToFolder!==false) && (typeof (this.editorConfig.customization) == 'object')
&& (typeof (this.editorConfig.customization.goback) == 'object') && !_.isEmpty(this.editorConfig.customization.goback.url); && (typeof (this.editorConfig.customization.goback) == 'object') && !_.isEmpty(this.editorConfig.customization.goback.url);
this.appOptions.canBack = this.editorConfig.nativeApp !== true && this.appOptions.canBackToFolder === true; this.appOptions.canBack = this.editorConfig.nativeApp !== true && this.appOptions.canBackToFolder === true;
this.appOptions.canPlugins = false;
this.plugins = this.editorConfig.plugins;
this.getApplication() this.getApplication()
.getController('Viewport') .getController('Viewport')
...@@ -254,9 +256,6 @@ define([ ...@@ -254,9 +256,6 @@ define([
if (this.appOptions.location == 'us' || this.appOptions.location == 'ca') if (this.appOptions.location == 'us' || this.appOptions.location == 'ca')
Common.Utils.Metric.setDefaultMetric(Common.Utils.Metric.c_MetricUnits.inch); Common.Utils.Metric.setDefaultMetric(Common.Utils.Metric.c_MetricUnits.inch);
this.plugins = this.editorConfig.plugins;
this.appOptions.canPlugins = (this.plugins && this.plugins.length>0);
}, },
loadDocument: function(data) { loadDocument: function(data) {
...@@ -831,6 +830,8 @@ define([ ...@@ -831,6 +830,8 @@ define([
application.getController('Common.Controllers.ExternalMergeEditor').setApi(this.api).loadConfig({config:this.editorConfig, customization: this.editorConfig.customization}); application.getController('Common.Controllers.ExternalMergeEditor').setApi(this.api).loadConfig({config:this.editorConfig, customization: this.editorConfig.customization});
pluginsController.setApi(this.api); pluginsController.setApi(this.api);
this.updatePluginsList(this.plugins);
this.api.asc_registerCallback('asc_onPluginsInit', _.bind(this.updatePluginsList, this));
documentHolderController.setApi(me.api); documentHolderController.setApi(me.api);
documentHolderController.createDelayedElements(); documentHolderController.createDelayedElements();
...@@ -1010,9 +1011,6 @@ define([ ...@@ -1010,9 +1011,6 @@ define([
var translateArt = new Asc.asc_TextArtTranslate(); var translateArt = new Asc.asc_TextArtTranslate();
translateArt.asc_setDefaultText(this.txtArt); translateArt.asc_setDefaultText(this.txtArt);
this.api.asc_setTextArtTranslate(translateArt); this.api.asc_setTextArtTranslate(translateArt);
if (this.appOptions.canPlugins)
this.updatePluginsList();
} }
}, },
...@@ -1696,25 +1694,50 @@ define([ ...@@ -1696,25 +1694,50 @@ define([
if (url) this.iframePrint.src = url; if (url) this.iframePrint.src = url;
}, },
updatePluginsList: function() { updatePluginsList: function(plugins) {
var pluginStore = this.getApplication().getCollection('Common.Collections.Plugins'); var pluginStore = this.getApplication().getCollection('Common.Collections.Plugins');
if (pluginStore && this.plugins) { if (pluginStore && plugins) {
var arr = []; var arr = [];
this.plugins.forEach(function(item){ plugins.pluginsData.forEach(function(item){
var variations = item.variations,
variationsArr = [];
variations.forEach(function(itemVar){
variationsArr.push(new Common.Models.PluginVariation({
description: itemVar.description,
index: itemVar.index,
url : itemVar.url,
icons : itemVar.icons,
isViewer: itemVar.isViewer,
EditorsSupport: itemVar.EditorsSupport,
isVisual: itemVar.isVisual,
isModal: itemVar.isModal,
isInsideMode: itemVar.isInsideMode,
initDataType: itemVar.initDataType,
initData: itemVar.initData,
isUpdateOleOnResize : itemVar.isUpdateOleOnResize,
buttons: itemVar.buttons
}));
});
arr.push(new Common.Models.Plugin({ arr.push(new Common.Models.Plugin({
name : item.name, name : item.name,
guid: item.guid, guid: item.guid,
url : item.url, variations: variationsArr,
icons : item.icons, currentVariation: 0
isVisual: item.isVisual,
initDataType: item.initDataType,
isUpdateOleOnResize : item.isUpdateOleOnResize,
buttons: item.buttons
})); }));
}); });
pluginStore.reset(arr); pluginStore.reset(arr);
this.appOptions.pluginsPath = (plugins.url);
this.appOptions.canPlugins = (arr.length>0);
} else {
this.appOptions.pluginsPath = '';
this.appOptions.canPlugins = false;
} }
if (this.appOptions.canPlugins)
this.getApplication().getController('Common.Controllers.Plugins').setMode(this.appOptions);
this.getApplication().getController('LeftMenu').enablePlugins();
}, },
leavePageText: 'You have unsaved changes in this document. Click \'Stay on this Page\' then \'Save\' to save them. Click \'Leave this Page\' to discard all the unsaved changes.', leavePageText: 'You have unsaved changes in this document. Click \'Stay on this Page\' then \'Save\' to save them. Click \'Leave this Page\' to discard all the unsaved changes.',
......
...@@ -245,7 +245,7 @@ define([ ...@@ -245,7 +245,7 @@ define([
if (name == 'history') { if (name == 'history') {
this.panelHistory = panel.render('#left-panel-history'); this.panelHistory = panel.render('#left-panel-history');
} else } else
if (name == 'plugins') { if (name == 'plugins' && !this.panelPlugins) {
this.panelPlugins = panel.render('#left-panel-plugins'); this.panelPlugins = panel.render('#left-panel-plugins');
} }
}, },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment