diff --git a/apps/api/documents/api.js b/apps/api/documents/api.js index 455f8d4d7..a3cff0e83 100644 --- a/apps/api/documents/api.js +++ b/apps/api/documents/api.js @@ -203,6 +203,7 @@ _config.editorConfig.canRequestSendNotify = _config.events && !!_config.events.onRequestSendNotify; _config.editorConfig.mergeFolderUrl = _config.editorConfig.mergeFolderUrl || _config.editorConfig.saveAsUrl; _config.editorConfig.canRequestSaveAs = _config.events && !!_config.events.onRequestSaveAs; + _config.editorConfig.canRequestInsertImage = _config.events && !!_config.events.onRequestInsertImage; _config.frameEditorId = placeholderId; _config.events && !!_config.events.onReady && console.log("Obsolete: The onReady event is deprecated. Please use onAppReady instead."); @@ -561,6 +562,13 @@ }); }; + var _insertImage = function(data) { + _sendCommand({ + command: 'insertImage', + data: data + }); + }; + var _processMouse = function(evt) { var r = iframe.getBoundingClientRect(); var data = { @@ -603,7 +611,8 @@ destroyEditor : _destroyEditor, setUsers : _setUsers, showSharingSettings : _showSharingSettings, - setSharingSettings : _setSharingSettings + setSharingSettings : _setSharingSettings, + insertImage : _insertImage } }; diff --git a/apps/common/Gateway.js b/apps/common/Gateway.js index 53c0b1e65..5ba1710a2 100644 --- a/apps/common/Gateway.js +++ b/apps/common/Gateway.js @@ -110,6 +110,10 @@ if (Common === undefined) { 'setSharingSettings': function(data) { $me.trigger('setsharingsettings', data); + }, + + 'insertImage': function(data) { + $me.trigger('insertimage', data); } }; @@ -292,6 +296,10 @@ if (Common === undefined) { _postMessage({event:'onRequestSendNotify', data: emails}) }, + requestInsertImage: function () { + _postMessage({event:'onRequestInsertImage'}) + }, + on: function(event, handler){ var localHandler = function(event, data){ handler.call(me, data) diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index b02214660..eacd8804f 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -350,6 +350,7 @@ define([ this.appOptions.canRequestUsers = this.editorConfig.canRequestUsers; this.appOptions.canRequestSendNotify = this.editorConfig.canRequestSendNotify; this.appOptions.canRequestSaveAs = this.editorConfig.canRequestSaveAs; + this.appOptions.canRequestInsertImage = this.editorConfig.canRequestInsertImage; appHeader = this.getApplication().getController('Viewport').getView('Common.Views.Header'); appHeader.setCanBack(this.appOptions.canBackToFolder === true, (this.appOptions.canBackToFolder) ? this.editorConfig.customization.goback.text : '') diff --git a/apps/documenteditor/main/app/controller/Toolbar.js b/apps/documenteditor/main/app/controller/Toolbar.js index 38d4f5857..2c33652e4 100644 --- a/apps/documenteditor/main/app/controller/Toolbar.js +++ b/apps/documenteditor/main/app/controller/Toolbar.js @@ -323,6 +323,7 @@ define([ toolbar.btnInsertEquation.on('click', _.bind(this.onInsertEquationClick, this)); toolbar.mnuNoControlsColor.on('click', _.bind(this.onNoControlsColor, this)); toolbar.mnuControlsColorPicker.on('select', _.bind(this.onSelectControlsColor, this)); + Common.Gateway.on('insertimage', _.bind(this.insertImage, this)); $('#id-toolbar-menu-new-control-color').on('click', _.bind(this.onNewControlsColor, this)); $('#id-save-style-plus, #id-save-style-link', toolbar.$el).on('click', this.onMenuSaveStyle.bind(this)); @@ -1427,13 +1428,23 @@ define([ } })).show(); } else if (item.value === 'storage') { - (new Common.Views.SelectFileDlg({ - fileChoiceUrl: this.toolbar.mode.fileChoiceUrl.replace("{fileExt}", "").replace("{documentType}", "ImagesOnly") - })).on('selectfile', function(obj, file){ - me.toolbar.fireEvent('insertimage', me.toolbar); - me.api.AddImageUrl(file.url, undefined, true);// for loading from storage - Common.component.Analytics.trackEvent('ToolBar', 'Image'); - }).show(); + if (this.toolbar.mode.canRequestInsertImage) { + Common.Gateway.requestInsertImage(); + } else { + (new Common.Views.SelectFileDlg({ + fileChoiceUrl: this.toolbar.mode.fileChoiceUrl.replace("{fileExt}", "").replace("{documentType}", "ImagesOnly") + })).on('selectfile', function(obj, file){ + me.insertImage(file); + }).show(); + } + } + }, + + insertImage: function(data) { + if (data && data.url) { + this.toolbar.fireEvent('insertimage', this.toolbar); + this.api.AddImageUrl(data.url, undefined, data.token);// for loading from storage + Common.component.Analytics.trackEvent('ToolBar', 'Image'); } }, diff --git a/apps/presentationeditor/main/app/controller/Main.js b/apps/presentationeditor/main/app/controller/Main.js index 8cde163ce..eadff86e7 100644 --- a/apps/presentationeditor/main/app/controller/Main.js +++ b/apps/presentationeditor/main/app/controller/Main.js @@ -317,6 +317,7 @@ define([ this.appOptions.canRequestUsers = this.editorConfig.canRequestUsers; this.appOptions.canRequestSendNotify = this.editorConfig.canRequestSendNotify; this.appOptions.canRequestSaveAs = this.editorConfig.canRequestSaveAs; + this.appOptions.canRequestInsertImage = this.editorConfig.canRequestInsertImage; appHeader = this.getApplication().getController('Viewport').getView('Common.Views.Header'); appHeader.setCanBack(this.appOptions.canBackToFolder === true, (this.appOptions.canBackToFolder) ? this.editorConfig.customization.goback.text : '') diff --git a/apps/presentationeditor/main/app/controller/Toolbar.js b/apps/presentationeditor/main/app/controller/Toolbar.js index 4d32a2ae5..c2563c927 100644 --- a/apps/presentationeditor/main/app/controller/Toolbar.js +++ b/apps/presentationeditor/main/app/controller/Toolbar.js @@ -314,6 +314,7 @@ define([ toolbar.btnEditHeader.on('click', _.bind(this.onEditHeaderClick, this, 'header')); toolbar.btnInsDateTime.on('click', _.bind(this.onEditHeaderClick, this, 'datetime')); toolbar.btnInsSlideNum.on('click', _.bind(this.onEditHeaderClick, this, 'slidenum')); + Common.Gateway.on('insertimage', _.bind(this.insertImage, this)); this.onSetupCopyStyleButton(); }, @@ -1390,13 +1391,23 @@ define([ } })).show(); } else if (opts === 'storage') { - (new Common.Views.SelectFileDlg({ - fileChoiceUrl: me.toolbar.mode.fileChoiceUrl.replace("{fileExt}", "").replace("{documentType}", "ImagesOnly") - })).on('selectfile', function(obj, file){ - me.toolbar.fireEvent('insertimage', me.toolbar); - me.api.AddImageUrl(file.url, undefined, true);// for loading from storage; - Common.component.Analytics.trackEvent('ToolBar', 'Image'); - }).show(); + if (this.toolbar.mode.canRequestInsertImage) { + Common.Gateway.requestInsertImage(); + } else { + (new Common.Views.SelectFileDlg({ + fileChoiceUrl: this.toolbar.mode.fileChoiceUrl.replace("{fileExt}", "").replace("{documentType}", "ImagesOnly") + })).on('selectfile', function(obj, file){ + me.insertImage(file); + }).show(); + } + } + }, + + insertImage: function(data) { + if (data && data.url) { + this.toolbar.fireEvent('insertimage', this.toolbar); + this.api.AddImageUrl(data.url, undefined, data.token);// for loading from storage + Common.component.Analytics.trackEvent('ToolBar', 'Image'); } }, diff --git a/apps/spreadsheeteditor/main/app/controller/Main.js b/apps/spreadsheeteditor/main/app/controller/Main.js index c8be815d9..94d25fb03 100644 --- a/apps/spreadsheeteditor/main/app/controller/Main.js +++ b/apps/spreadsheeteditor/main/app/controller/Main.js @@ -323,6 +323,7 @@ define([ this.appOptions.canRequestUsers = this.editorConfig.canRequestUsers; this.appOptions.canRequestSendNotify = this.editorConfig.canRequestSendNotify; this.appOptions.canRequestSaveAs = this.editorConfig.canRequestSaveAs; + this.appOptions.canRequestInsertImage = this.editorConfig.canRequestInsertImage; this.headerView = this.getApplication().getController('Viewport').getView('Common.Views.Header'); this.headerView.setCanBack(this.appOptions.canBackToFolder === true, (this.appOptions.canBackToFolder) ? this.editorConfig.customization.goback.text : '') diff --git a/apps/spreadsheeteditor/main/app/controller/Toolbar.js b/apps/spreadsheeteditor/main/app/controller/Toolbar.js index 29b125961..731856662 100644 --- a/apps/spreadsheeteditor/main/app/controller/Toolbar.js +++ b/apps/spreadsheeteditor/main/app/controller/Toolbar.js @@ -365,6 +365,7 @@ define([ toolbar.btnImgForward.on('click', this.onImgArrangeSelect.bind(this, 'forward')); toolbar.btnImgBackward.on('click', this.onImgArrangeSelect.bind(this, 'backward')); toolbar.btnEditHeader.on('click', _.bind(this.onEditHeaderClick, this)); + Common.Gateway.on('insertimage', _.bind(this.insertImage, this)); this.onSetupCopyStyleButton(); } @@ -862,14 +863,23 @@ define([ } })).show(); } else if (item.value === 'storage') { - var me = this; - (new Common.Views.SelectFileDlg({ - fileChoiceUrl: me.toolbar.mode.fileChoiceUrl.replace("{fileExt}", "").replace("{documentType}", "ImagesOnly") - })).on('selectfile', function(obj, file){ - me.toolbar.fireEvent('insertimage', me.toolbar); - me.api.asc_addImageDrawingObject(file.url, undefined, true);// for loading from storage; - Common.component.Analytics.trackEvent('ToolBar', 'Image'); - }).show(); + if (this.toolbar.mode.canRequestInsertImage) { + Common.Gateway.requestInsertImage(); + } else { + (new Common.Views.SelectFileDlg({ + fileChoiceUrl: this.toolbar.mode.fileChoiceUrl.replace("{fileExt}", "").replace("{documentType}", "ImagesOnly") + })).on('selectfile', function(obj, file){ + me.insertImage(file); + }).show(); + } + } + }, + + insertImage: function(data) { + if (data && data.url) { + this.toolbar.fireEvent('insertimage', this.toolbar); + this.api.asc_addImageDrawingObject(data.url, undefined, data.token);// for loading from storage + Common.component.Analytics.trackEvent('ToolBar', 'Image'); } },