Add onRequestInsertImage event, insertImage method for inserting image from storage

This commit is contained in:
Julia Radzhabova 2019-07-26 14:49:53 +03:00
parent b9917f6dff
commit d45d04f0a1
8 changed files with 75 additions and 23 deletions

View file

@ -203,6 +203,7 @@
_config.editorConfig.canRequestSendNotify = _config.events && !!_config.events.onRequestSendNotify; _config.editorConfig.canRequestSendNotify = _config.events && !!_config.events.onRequestSendNotify;
_config.editorConfig.mergeFolderUrl = _config.editorConfig.mergeFolderUrl || _config.editorConfig.saveAsUrl; _config.editorConfig.mergeFolderUrl = _config.editorConfig.mergeFolderUrl || _config.editorConfig.saveAsUrl;
_config.editorConfig.canRequestSaveAs = _config.events && !!_config.events.onRequestSaveAs; _config.editorConfig.canRequestSaveAs = _config.events && !!_config.events.onRequestSaveAs;
_config.editorConfig.canRequestInsertImage = _config.events && !!_config.events.onRequestInsertImage;
_config.frameEditorId = placeholderId; _config.frameEditorId = placeholderId;
_config.events && !!_config.events.onReady && console.log("Obsolete: The onReady event is deprecated. Please use onAppReady instead."); _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 _processMouse = function(evt) {
var r = iframe.getBoundingClientRect(); var r = iframe.getBoundingClientRect();
var data = { var data = {
@ -603,7 +611,8 @@
destroyEditor : _destroyEditor, destroyEditor : _destroyEditor,
setUsers : _setUsers, setUsers : _setUsers,
showSharingSettings : _showSharingSettings, showSharingSettings : _showSharingSettings,
setSharingSettings : _setSharingSettings setSharingSettings : _setSharingSettings,
insertImage : _insertImage
} }
}; };

View file

@ -110,6 +110,10 @@ if (Common === undefined) {
'setSharingSettings': function(data) { 'setSharingSettings': function(data) {
$me.trigger('setsharingsettings', data); $me.trigger('setsharingsettings', data);
},
'insertImage': function(data) {
$me.trigger('insertimage', data);
} }
}; };
@ -292,6 +296,10 @@ if (Common === undefined) {
_postMessage({event:'onRequestSendNotify', data: emails}) _postMessage({event:'onRequestSendNotify', data: emails})
}, },
requestInsertImage: function () {
_postMessage({event:'onRequestInsertImage'})
},
on: function(event, handler){ on: function(event, handler){
var localHandler = function(event, data){ var localHandler = function(event, data){
handler.call(me, data) handler.call(me, data)

View file

@ -350,6 +350,7 @@ define([
this.appOptions.canRequestUsers = this.editorConfig.canRequestUsers; this.appOptions.canRequestUsers = this.editorConfig.canRequestUsers;
this.appOptions.canRequestSendNotify = this.editorConfig.canRequestSendNotify; this.appOptions.canRequestSendNotify = this.editorConfig.canRequestSendNotify;
this.appOptions.canRequestSaveAs = this.editorConfig.canRequestSaveAs; this.appOptions.canRequestSaveAs = this.editorConfig.canRequestSaveAs;
this.appOptions.canRequestInsertImage = this.editorConfig.canRequestInsertImage;
appHeader = this.getApplication().getController('Viewport').getView('Common.Views.Header'); appHeader = this.getApplication().getController('Viewport').getView('Common.Views.Header');
appHeader.setCanBack(this.appOptions.canBackToFolder === true, (this.appOptions.canBackToFolder) ? this.editorConfig.customization.goback.text : '') appHeader.setCanBack(this.appOptions.canBackToFolder === true, (this.appOptions.canBackToFolder) ? this.editorConfig.customization.goback.text : '')

View file

@ -323,6 +323,7 @@ define([
toolbar.btnInsertEquation.on('click', _.bind(this.onInsertEquationClick, this)); toolbar.btnInsertEquation.on('click', _.bind(this.onInsertEquationClick, this));
toolbar.mnuNoControlsColor.on('click', _.bind(this.onNoControlsColor, this)); toolbar.mnuNoControlsColor.on('click', _.bind(this.onNoControlsColor, this));
toolbar.mnuControlsColorPicker.on('select', _.bind(this.onSelectControlsColor, 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-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)); $('#id-save-style-plus, #id-save-style-link', toolbar.$el).on('click', this.onMenuSaveStyle.bind(this));
@ -1427,13 +1428,23 @@ define([
} }
})).show(); })).show();
} else if (item.value === 'storage') { } else if (item.value === 'storage') {
(new Common.Views.SelectFileDlg({ if (this.toolbar.mode.canRequestInsertImage) {
fileChoiceUrl: this.toolbar.mode.fileChoiceUrl.replace("{fileExt}", "").replace("{documentType}", "ImagesOnly") Common.Gateway.requestInsertImage();
})).on('selectfile', function(obj, file){ } else {
me.toolbar.fireEvent('insertimage', me.toolbar); (new Common.Views.SelectFileDlg({
me.api.AddImageUrl(file.url, undefined, true);// for loading from storage fileChoiceUrl: this.toolbar.mode.fileChoiceUrl.replace("{fileExt}", "").replace("{documentType}", "ImagesOnly")
Common.component.Analytics.trackEvent('ToolBar', 'Image'); })).on('selectfile', function(obj, file){
}).show(); 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');
} }
}, },

View file

@ -317,6 +317,7 @@ define([
this.appOptions.canRequestUsers = this.editorConfig.canRequestUsers; this.appOptions.canRequestUsers = this.editorConfig.canRequestUsers;
this.appOptions.canRequestSendNotify = this.editorConfig.canRequestSendNotify; this.appOptions.canRequestSendNotify = this.editorConfig.canRequestSendNotify;
this.appOptions.canRequestSaveAs = this.editorConfig.canRequestSaveAs; this.appOptions.canRequestSaveAs = this.editorConfig.canRequestSaveAs;
this.appOptions.canRequestInsertImage = this.editorConfig.canRequestInsertImage;
appHeader = this.getApplication().getController('Viewport').getView('Common.Views.Header'); appHeader = this.getApplication().getController('Viewport').getView('Common.Views.Header');
appHeader.setCanBack(this.appOptions.canBackToFolder === true, (this.appOptions.canBackToFolder) ? this.editorConfig.customization.goback.text : '') appHeader.setCanBack(this.appOptions.canBackToFolder === true, (this.appOptions.canBackToFolder) ? this.editorConfig.customization.goback.text : '')

View file

@ -314,6 +314,7 @@ define([
toolbar.btnEditHeader.on('click', _.bind(this.onEditHeaderClick, this, 'header')); toolbar.btnEditHeader.on('click', _.bind(this.onEditHeaderClick, this, 'header'));
toolbar.btnInsDateTime.on('click', _.bind(this.onEditHeaderClick, this, 'datetime')); toolbar.btnInsDateTime.on('click', _.bind(this.onEditHeaderClick, this, 'datetime'));
toolbar.btnInsSlideNum.on('click', _.bind(this.onEditHeaderClick, this, 'slidenum')); toolbar.btnInsSlideNum.on('click', _.bind(this.onEditHeaderClick, this, 'slidenum'));
Common.Gateway.on('insertimage', _.bind(this.insertImage, this));
this.onSetupCopyStyleButton(); this.onSetupCopyStyleButton();
}, },
@ -1390,13 +1391,23 @@ define([
} }
})).show(); })).show();
} else if (opts === 'storage') { } else if (opts === 'storage') {
(new Common.Views.SelectFileDlg({ if (this.toolbar.mode.canRequestInsertImage) {
fileChoiceUrl: me.toolbar.mode.fileChoiceUrl.replace("{fileExt}", "").replace("{documentType}", "ImagesOnly") Common.Gateway.requestInsertImage();
})).on('selectfile', function(obj, file){ } else {
me.toolbar.fireEvent('insertimage', me.toolbar); (new Common.Views.SelectFileDlg({
me.api.AddImageUrl(file.url, undefined, true);// for loading from storage; fileChoiceUrl: this.toolbar.mode.fileChoiceUrl.replace("{fileExt}", "").replace("{documentType}", "ImagesOnly")
Common.component.Analytics.trackEvent('ToolBar', 'Image'); })).on('selectfile', function(obj, file){
}).show(); 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');
} }
}, },

View file

@ -323,6 +323,7 @@ define([
this.appOptions.canRequestUsers = this.editorConfig.canRequestUsers; this.appOptions.canRequestUsers = this.editorConfig.canRequestUsers;
this.appOptions.canRequestSendNotify = this.editorConfig.canRequestSendNotify; this.appOptions.canRequestSendNotify = this.editorConfig.canRequestSendNotify;
this.appOptions.canRequestSaveAs = this.editorConfig.canRequestSaveAs; this.appOptions.canRequestSaveAs = this.editorConfig.canRequestSaveAs;
this.appOptions.canRequestInsertImage = this.editorConfig.canRequestInsertImage;
this.headerView = this.getApplication().getController('Viewport').getView('Common.Views.Header'); 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 : '') this.headerView.setCanBack(this.appOptions.canBackToFolder === true, (this.appOptions.canBackToFolder) ? this.editorConfig.customization.goback.text : '')

View file

@ -365,6 +365,7 @@ define([
toolbar.btnImgForward.on('click', this.onImgArrangeSelect.bind(this, 'forward')); toolbar.btnImgForward.on('click', this.onImgArrangeSelect.bind(this, 'forward'));
toolbar.btnImgBackward.on('click', this.onImgArrangeSelect.bind(this, 'backward')); toolbar.btnImgBackward.on('click', this.onImgArrangeSelect.bind(this, 'backward'));
toolbar.btnEditHeader.on('click', _.bind(this.onEditHeaderClick, this)); toolbar.btnEditHeader.on('click', _.bind(this.onEditHeaderClick, this));
Common.Gateway.on('insertimage', _.bind(this.insertImage, this));
this.onSetupCopyStyleButton(); this.onSetupCopyStyleButton();
} }
@ -862,14 +863,23 @@ define([
} }
})).show(); })).show();
} else if (item.value === 'storage') { } else if (item.value === 'storage') {
var me = this; if (this.toolbar.mode.canRequestInsertImage) {
(new Common.Views.SelectFileDlg({ Common.Gateway.requestInsertImage();
fileChoiceUrl: me.toolbar.mode.fileChoiceUrl.replace("{fileExt}", "").replace("{documentType}", "ImagesOnly") } else {
})).on('selectfile', function(obj, file){ (new Common.Views.SelectFileDlg({
me.toolbar.fireEvent('insertimage', me.toolbar); fileChoiceUrl: this.toolbar.mode.fileChoiceUrl.replace("{fileExt}", "").replace("{documentType}", "ImagesOnly")
me.api.asc_addImageDrawingObject(file.url, undefined, true);// for loading from storage; })).on('selectfile', function(obj, file){
Common.component.Analytics.trackEvent('ToolBar', 'Image'); me.insertImage(file);
}).show(); }).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');
} }
}, },