From 599816e11c5ee87d15383daad9cd0e4fc18c61ba Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Fri, 20 Dec 2024 16:48:13 +0300 Subject: [PATCH] [PDF] Insert stamp --- apps/pdfeditor/main/app/controller/Toolbar.js | 45 +++++++++++++++++++ .../main/app/template/Toolbar.template | 4 ++ apps/pdfeditor/main/app/view/Toolbar.js | 24 +++++++++- apps/pdfeditor/main/locale/en.json | 2 + 4 files changed, 74 insertions(+), 1 deletion(-) diff --git a/apps/pdfeditor/main/app/controller/Toolbar.js b/apps/pdfeditor/main/app/controller/Toolbar.js index 9058a73eae..a694382247 100644 --- a/apps/pdfeditor/main/app/controller/Toolbar.js +++ b/apps/pdfeditor/main/app/controller/Toolbar.js @@ -251,6 +251,9 @@ define([ toolbar.chShowComments.on('change', _.bind(this.onShowCommentsChange, this)); toolbar.btnTextComment.on('click', _.bind(this.onBtnTextCommentClick, this)); toolbar.btnTextComment.menu.on('item:click', _.bind(this.onMenuTextCommentClick, this)); + toolbar.btnStamp.on('click', _.bind(this.onBtnStampClick, this)); + toolbar.btnStamp.menu.on('item:click', _.bind(this.onMenuStampClick, this)); + toolbar.btnStamp.menu.on('show:after', _.bind(this.onStampShowAfter, this)); // toolbar.btnRotate.on('click', _.bind(this.onRotateClick, this)); Common.NotificationCenter.on('leftmenu:save', _.bind(this.tryToSave, this)); Common.NotificationCenter.on('draw:start', _.bind(this.onDrawStart, this)); @@ -1141,6 +1144,48 @@ define([ Common.component.Analytics.trackEvent('ToolBar', 'Add Text'); }, + onBtnStampClick: function(btn, e) { + this.onInsertStamp(btn.options.stampType, btn, e); + }, + + onMenuStampClick: function(btn, e) { + var oldType = this.toolbar.btnStamp.options.stampType; + var newType = e.value; + + if(newType !== oldType){ + this.toolbar.btnStamp.options.stampType = newType; + } + this.onInsertStamp(newType, btn, e); + }, + + onInsertStamp: function(type, btn, e) { + this.api && this.api.AddStampAnnot(type); + + Common.NotificationCenter.trigger('edit:complete', this.toolbar, this.toolbar.btnStamp); + Common.component.Analytics.trackEvent('ToolBar', 'Add Stamp'); + }, + + onStampShowAfter: function(menu) { + var me = this; + if (menu.getItemsLength(true)<1 && this.api) { + var arr = this.api.asc_getPropertyEditorStamps(), + template = _.template([ + '', + '', + '' + ].join('')); + arr.forEach(function(item){ + var menuItem = new Common.UI.MenuItem({ + value: item.Type, + stampImage: item.Image, + template: template + }); + menu.addItem(menuItem, true); + }); + this.toolbar.btnStamp.options.stampType = arr[0].Type; + } + }, + onFillRequiredFields: function(isFilled) { this.toolbar && this.toolbar.btnSubmit && this.toolbar.lockToolbar(Common.enumLock.requiredNotFilled, !isFilled, {array: [this.toolbar.btnSubmit]}); }, diff --git a/apps/pdfeditor/main/app/template/Toolbar.template b/apps/pdfeditor/main/app/template/Toolbar.template index 40c5bccefa..c58bd4b524 100644 --- a/apps/pdfeditor/main/app/template/Toolbar.template +++ b/apps/pdfeditor/main/app/template/Toolbar.template @@ -176,6 +176,10 @@
+
+ +
+
diff --git a/apps/pdfeditor/main/app/view/Toolbar.js b/apps/pdfeditor/main/app/view/Toolbar.js index ec6ab807b7..90128b37b1 100644 --- a/apps/pdfeditor/main/app/view/Toolbar.js +++ b/apps/pdfeditor/main/app/view/Toolbar.js @@ -137,7 +137,7 @@ define([ if (!config.isPDFEdit) return; var _set = Common.enumLock, - arr = [] + arr = []; // tab Edit this.btnEditText = new Common.UI.Button({ id: 'id-toolbar-btn-edittext', @@ -882,6 +882,21 @@ define([ }); this.toolbarControls.push(this.chShowComments); + this.btnStamp = new Common.UI.Button({ + id: 'tlbtn-stamp', + cls: 'btn-toolbar x-huge icon-top', + caption: this.capBtnStamp, + split: true, + iconCls: 'toolbar__icon btn-stamp', + lock: [_set.disableOnStart], + dataHint: '1', + dataHintDirection: 'bottom', + dataHintOffset: 'small', + menu: true, + action: 'insert-stamp' + }); + this.toolbarControls.push(this.btnStamp); + this.btnStrikeout = new Common.UI.ButtonColored({ id: 'id-toolbar-btn-strikeout', cls: 'btn-toolbar', @@ -1343,6 +1358,7 @@ define([ _injectComponent('#slot-btn-underline', this.btnUnderline); _injectComponent('#slot-btn-highlight', this.btnHighlight); _injectComponent('#slot-btn-text-comment', this.btnTextComment); + _injectComponent('#slot-btn-stamp', this.btnStamp); this.btnEditMode ? _injectComponent('#slot-btn-tb-edit-mode', this.btnEditMode) : $host.findById('#slot-btn-tb-edit-mode').parents('.group').hide().next('.separator').hide(); }, @@ -1499,6 +1515,11 @@ define([ ] })); } + if (me.btnStamp) { + me.btnStamp.setMenu(new Common.UI.Menu({ + restoreHeight: 500 + })); + } }); }, @@ -1538,6 +1559,7 @@ define([ this.btnHighlight.updateHint(this.textHighlight); // this.btnTextComment.updateHint([this.tipInsertTextComment, this.tipInsertText]); this.btnTextComment.updateHint(this.tipInsertTextComment); + this.btnStamp.updateHint(this.tipInsertStamp); this.btnEditMode && this.btnEditMode.updateHint(this.tipEditMode); }, diff --git a/apps/pdfeditor/main/locale/en.json b/apps/pdfeditor/main/locale/en.json index cfb4a8326e..dc8b5c3628 100644 --- a/apps/pdfeditor/main/locale/en.json +++ b/apps/pdfeditor/main/locale/en.json @@ -2016,6 +2016,8 @@ "PDFE.Views.Toolbar.txtRotatePage": "Rotate page", "PDFE.Views.Toolbar.txtRotatePageRight": "Rotate page right", "PDFE.Views.Toolbar.txtRotateRight": "Rotate right", + "PDFE.Views.Toolbar.capBtnStamp": "Stamp", + "PDFE.Views.Toolbar.tipInsertStamp": "Insert stamp", "PDFE.Views.Toolbar.txtUngroup": "Ungroup", "PDFE.Views.ViewTab.textAlwaysShowToolbar": "Always Show Toolbar", "PDFE.Views.ViewTab.textDarkDocument": "Dark Document",