From ee088b2b374ba242535972b75c227ea1ae201f02 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Wed, 6 Nov 2024 17:26:22 +0300 Subject: [PATCH] Fix bug 68668 --- .../app/controller/ApplicationController.js | 12 +- .../main/app/controller/DocumentHolder.js | 106 +++++++++++++++++- .../main/app/controller/Toolbar.js | 2 + .../main/app/view/FormSettings.js | 36 +----- apps/documenteditor/main/locale/en.json | 3 + .../main/app/controller/DocumentHolder.js | 4 +- 6 files changed, 119 insertions(+), 44 deletions(-) diff --git a/apps/documenteditor/forms/app/controller/ApplicationController.js b/apps/documenteditor/forms/app/controller/ApplicationController.js index 0b1185e911..e9f8719289 100644 --- a/apps/documenteditor/forms/app/controller/ApplicationController.js +++ b/apps/documenteditor/forms/app/controller/ApplicationController.js @@ -1178,7 +1178,13 @@ define([ if (lock == Asc.c_oAscSdtLockType.SdtContentLocked || lock==Asc.c_oAscSdtLockType.ContentLocked) return; } - this.onShowImageActions(obj, x, y); + if (obj.pr && obj.pr.is_Signature()) { // select signature picture only from local file + me.api.asc_addImage(obj.pr); + setTimeout(function(){ + me.api.asc_UncheckContentControlButtons(); + }, 500); + } else + this.onShowImageActions(obj, x, y); break; case Asc.c_oAscContentControlSpecificType.DropDownList: case Asc.c_oAscContentControlSpecificType.ComboBox: @@ -1199,7 +1205,7 @@ define([ menuContainer = menu ? this.boxSdk.find(Common.Utils.String.format('#menu-container-{0}', menu.id)) : null, me = this; - this.internalFormObj = obj && obj.pr ? obj.pr.get_InternalId() : null; + this.internalFormObj = obj ? obj.pr : null; this._fromShowContentControls = true; Common.UI.Menu.Manager.hideAll(); @@ -1288,7 +1294,7 @@ define([ }, setImageUrl: function(url, token) { - this.api.asc_SetContentControlPictureUrl(url, this.internalFormObj && this.internalFormObj.pr ? this.internalFormObj.pr.get_InternalId() : null, token); + this.api.asc_SetContentControlPictureUrl(url, this.internalFormObj ? this.internalFormObj.get_InternalId() : null, token); }, insertImage: function(data) { // gateway diff --git a/apps/documenteditor/main/app/controller/DocumentHolder.js b/apps/documenteditor/main/app/controller/DocumentHolder.js index dfd9d8c60d..cfa22742aa 100644 --- a/apps/documenteditor/main/app/controller/DocumentHolder.js +++ b/apps/documenteditor/main/app/controller/DocumentHolder.js @@ -236,6 +236,8 @@ define([ if (this.mode.isEdit || this.mode.isRestrictedEdit && this.mode.canFillForms) { this.api.asc_registerCallback('asc_onShowContentControlsActions',_.bind(this.onShowContentControlsActions, this)); this.api.asc_registerCallback('asc_onHideContentControlsActions',_.bind(this.onHideContentControlsActions, this)); + Common.NotificationCenter.on('storage:image-insert', _.bind(this.insertImageFromStorage, this)); + Common.NotificationCenter.on('forms:image-select', _.bind(this.selectFormImage, this));// select from right pane } this.api.asc_registerCallback('onPluginContextMenu', _.bind(this.onPluginContextMenu, this)); this.documentHolder.setApi(this.api); @@ -1757,11 +1759,13 @@ define([ Common.NotificationCenter.trigger('edit:complete', me.toolbar); } })).show(); + } else if (obj.pr && obj.pr.is_Signature()) { // select signature picture only from local file + this.api.asc_addImage(obj.pr); + setTimeout(function(){ + me.api.asc_UncheckContentControlButtons(); + }, 500); } else - this.api.asc_addImage(obj); - setTimeout(function(){ - me.api.asc_UncheckContentControlButtons(); - }, 500); + this.onShowImageActions(obj, x, y); break; case Asc.c_oAscContentControlSpecificType.DropDownList: case Asc.c_oAscContentControlSpecificType.ComboBox: @@ -1770,6 +1774,100 @@ define([ } }, + onShowImageActions: function(obj, x, y) { + var cmpEl = this.documentHolder.cmpEl, + menu = this.imageControlMenu, + menuContainer = menu ? cmpEl.find(Common.Utils.String.format('#menu-container-{0}', menu.id)) : null, + me = this; + + this.internalFormObj = obj ? obj.pr : null; + this._fromShowContentControls = true; + Common.UI.Menu.Manager.hideAll(); + + if (!menu) { + this.imageControlMenu = menu = new Common.UI.Menu({ + maxHeight: 207, + menuAlign: 'tl-bl', + items: [ + {caption: this.documentHolder.mniImageFromFile, value: 0}, + {caption: this.documentHolder.mniImageFromUrl, value: 1}, + {caption: this.documentHolder.mniImageFromStorage, value: 2, visible: this.mode.canRequestInsertImage || this.mode.fileChoiceUrl && this.mode.fileChoiceUrl.indexOf("{documentType}")>-1} + ] + }); + menu.on('item:click', function(menu, item) { + setTimeout(function(){ + me.onImageSelect(menu, item); + }, 1); + setTimeout(function(){ + me.api.asc_UncheckContentControlButtons(); + }, 500); + }); + + // Prepare menu container + if (!menuContainer || menuContainer.length < 1) { + menuContainer = $(Common.Utils.String.format('', menu.id)); + cmpEl.append(menuContainer); + } + + menu.render(menuContainer); + menu.cmpEl.attr({tabindex: "-1"}); + menu.on('hide:after', function(){ + if (!me._fromShowContentControls) + me.api.asc_UncheckContentControlButtons(); + }); + } + menuContainer.css({left: x, top : y}); + menuContainer.attr('data-value', 'prevent-canvas-click'); + this._preventClick = true; + menu.show(); + + _.delay(function() { + menu.cmpEl.focus(); + }, 10); + this._fromShowContentControls = false; + }, + + selectFormImage: function(item, obj) { + this.internalFormObj = obj; + this.onImageSelect(null, item); + }, + + onImageSelect: function(menu, item) { + if (item.value==1) { + var me = this; + (new Common.Views.ImageFromUrlDialog({ + handler: function(result, value) { + if (result == 'ok') { + if (me.api) { + var checkUrl = value.replace(/ /g, ''); + if (!_.isEmpty(checkUrl)) { + me.setImageUrl(checkUrl); + } + } + } + me.fireEvent('editcomplete', me); + } + })).show(); + } else if (item.value==2) { + Common.NotificationCenter.trigger('storage:image-load', 'control'); + } else { + if (this._isFromFile) return; + this._isFromFile = true; + this.api.asc_addImage(this.internalFormObj); + this._isFromFile = false; + } + }, + + setImageUrl: function(url, token) { + this.api && this.api.asc_SetContentControlPictureUrl(url, this.internalFormObj ? this.internalFormObj.get_InternalId() : null, token); + }, + + insertImageFromStorage: function(data) { + if (data && data._urls && data.c=='control') { + this.setImageUrl(data._urls[0], data.token); + } + }, + onApiLockDocumentProps: function() { this._state.lock_doc = true; }, diff --git a/apps/documenteditor/main/app/controller/Toolbar.js b/apps/documenteditor/main/app/controller/Toolbar.js index 18b1788b93..81d5b9f20e 100644 --- a/apps/documenteditor/main/app/controller/Toolbar.js +++ b/apps/documenteditor/main/app/controller/Toolbar.js @@ -286,6 +286,7 @@ define([ Common.NotificationCenter.on('leftmenu:save', _.bind(this.tryToSave, this)); this.onBtnChangeState('undo:disabled', toolbar.btnUndo, toolbar.btnUndo.isDisabled()); this.onBtnChangeState('redo:disabled', toolbar.btnRedo, toolbar.btnRedo.isDisabled()); + Common.Gateway.on('insertimage', _.bind(this.insertImage, this)); }, attachUIEvents: function(toolbar) { @@ -490,6 +491,7 @@ define([ this.api.asc_registerCallback('asc_onCanRedo', _.bind(this.onApiCanRevert, this, 'redo')); this.api.asc_registerCallback('asc_onCanCopyCut', _.bind(this.onApiCanCopyCut, this)); this.api.asc_registerCallback('asc_onChangeViewerTargetType', _.bind(this.onChangeViewerTargetType, this)); + Common.NotificationCenter.on('storage:image-load', _.bind(this.openImageFromStorage, this)); } } this.api.asc_registerCallback('onPluginToolbarMenu', _.bind(this.onPluginToolbarMenu, this)); diff --git a/apps/documenteditor/main/app/view/FormSettings.js b/apps/documenteditor/main/app/view/FormSettings.js index 5770ff3fb3..3519a34fba 100644 --- a/apps/documenteditor/main/app/view/FormSettings.js +++ b/apps/documenteditor/main/app/view/FormSettings.js @@ -831,7 +831,6 @@ define([ // this.api.asc_registerCallback('asc_onParaSpacingLine', _.bind(this._onLineSpacing, this)); this.api.asc_registerCallback('asc_onUpdateOFormRoles', _.bind(this.onRefreshRolesList, this)); } - Common.NotificationCenter.on('storage:image-insert', _.bind(this.insertImageFromStorage, this)); return this; }, @@ -1152,41 +1151,8 @@ define([ this.fireEvent('editcomplete', this); }, - setImageUrl: function(url, token) { - this.api.asc_SetContentControlPictureUrl(url, this.internalId, token); - }, - - insertImageFromStorage: function(data) { - if (data && data._urls && data.c=='control') { - this.setImageUrl(data._urls[0], data.token); - } - }, - onImageSelect: function(menu, item) { - if (item.value==1) { - var me = this; - (new Common.Views.ImageFromUrlDialog({ - handler: function(result, value) { - if (result == 'ok') { - if (me.api) { - var checkUrl = value.replace(/ /g, ''); - if (!_.isEmpty(checkUrl)) { - me.setImageUrl(checkUrl); - } - } - } - me.fireEvent('editcomplete', me); - } - })).show(); - } else if (item.value==2) { - Common.NotificationCenter.trigger('storage:image-load', 'control'); - } else { - if (this._isFromFile) return; - this._isFromFile = true; - if (this.api) this.api.asc_addImage(this._originalProps); - this.fireEvent('editcomplete', this); - this._isFromFile = false; - } + Common.NotificationCenter.trigger('forms:image-select', item, this._originalProps); }, onColorBGSelect: function(btn, color) { diff --git a/apps/documenteditor/main/locale/en.json b/apps/documenteditor/main/locale/en.json index 06074f68de..462819c22c 100644 --- a/apps/documenteditor/main/locale/en.json +++ b/apps/documenteditor/main/locale/en.json @@ -2099,6 +2099,9 @@ "DE.Views.DocumentHolder.unicodeText": "Unicode", "DE.Views.DocumentHolder.updateStyleText": "Update %1 style", "DE.Views.DocumentHolder.vertAlignText": "Vertical alignment", + "DE.Views.DocumentHolder.mniImageFromFile": "Image from File", + "DE.Views.DocumentHolder.mniImageFromStorage": "Image from Storage", + "DE.Views.DocumentHolder.mniImageFromUrl": "Image from URL", "DE.Views.DropcapSettingsAdvanced.strBorders": "Borders & Fill", "DE.Views.DropcapSettingsAdvanced.strDropcap": "Drop cap", "DE.Views.DropcapSettingsAdvanced.strMargins": "Margins", diff --git a/apps/pdfeditor/main/app/controller/DocumentHolder.js b/apps/pdfeditor/main/app/controller/DocumentHolder.js index 8cb0eb3059..5841e096fc 100644 --- a/apps/pdfeditor/main/app/controller/DocumentHolder.js +++ b/apps/pdfeditor/main/app/controller/DocumentHolder.js @@ -1437,7 +1437,7 @@ define([ menuContainer = menu ? cmpEl.find(Common.Utils.String.format('#menu-container-{0}', menu.id)) : null, me = this; - this.internalFormObj = obj && obj.pr ? obj.pr.get_InternalId() : null; + this.internalFormObj = obj ? obj.pr : null; this._fromShowContentControls = true; Common.UI.Menu.Manager.hideAll(); @@ -1526,7 +1526,7 @@ define([ }, setImageUrl: function(url, token) { - this.api.asc_SetContentControlPictureUrl(url, this.internalFormObj && this.internalFormObj.pr ? this.internalFormObj.pr.get_InternalId() : null, token); + this.api.asc_SetContentControlPictureUrl(url, this.internalFormObj ? this.internalFormObj.get_InternalId() : null, token); }, insertImage: function(data) { // gateway