From 475a2bcbbe4f8ae80d81d1504aaf06208dacdc56 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Wed, 11 Sep 2019 17:26:20 +0300 Subject: [PATCH] [DE] Add caption for object --- .../main/app/controller/Links.js | 19 +- .../main/app/template/Toolbar.template | 1 + .../main/app/view/CaptionDialog.js | 285 ++++++++++++++++++ apps/documenteditor/main/app/view/Links.js | 18 +- 4 files changed, 320 insertions(+), 3 deletions(-) create mode 100644 apps/documenteditor/main/app/view/CaptionDialog.js diff --git a/apps/documenteditor/main/app/controller/Links.js b/apps/documenteditor/main/app/controller/Links.js index 1e034c149..aa04c6039 100644 --- a/apps/documenteditor/main/app/controller/Links.js +++ b/apps/documenteditor/main/app/controller/Links.js @@ -45,7 +45,8 @@ define([ 'documenteditor/main/app/view/NoteSettingsDialog', 'documenteditor/main/app/view/HyperlinkSettingsDialog', 'documenteditor/main/app/view/TableOfContentsSettings', - 'documenteditor/main/app/view/BookmarksDialog' + 'documenteditor/main/app/view/BookmarksDialog', + 'documenteditor/main/app/view/CaptionDialog' ], function () { 'use strict'; @@ -66,7 +67,8 @@ define([ 'links:update': this.onTableContentsUpdate, 'links:notes': this.onNotesClick, 'links:hyperlink': this.onHyperlinkClick, - 'links:bookmarks': this.onBookmarksClick + 'links:bookmarks': this.onBookmarksClick, + 'links:caption': this.onCaptionClick }, 'DocumentHolder': { 'links:contents': this.onTableContents, @@ -332,6 +334,19 @@ define([ })).show(); }, + onCaptionClick: function(btn) { + var me = this; + (new DE.Views.CaptionDialog({ + api: me.api, + handler: function (result, settings) { + if (result == 'ok') { + me.api.asc_AddObjectCaption(settings); + } + Common.NotificationCenter.trigger('edit:complete', me.toolbar); + } + })).show(); + }, + onShowContentControlsActions: function(action, x, y) { var menu = (action==1) ? this.view.contentsUpdateMenu : this.view.contentsMenu, documentHolderView = this.getApplication().getController('DocumentHolder').documentHolder, diff --git a/apps/documenteditor/main/app/template/Toolbar.template b/apps/documenteditor/main/app/template/Toolbar.template index e9d7ae2c0..c50e0c0e7 100644 --- a/apps/documenteditor/main/app/template/Toolbar.template +++ b/apps/documenteditor/main/app/template/Toolbar.template @@ -152,6 +152,7 @@
+
diff --git a/apps/documenteditor/main/app/view/CaptionDialog.js b/apps/documenteditor/main/app/view/CaptionDialog.js new file mode 100644 index 000000000..d5b06749c --- /dev/null +++ b/apps/documenteditor/main/app/view/CaptionDialog.js @@ -0,0 +1,285 @@ +/* + * + * (c) Copyright Ascensio System SIA 2010-2019 + * + * This program is a free software product. You can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License (AGPL) + * version 3 as published by the Free Software Foundation. In accordance with + * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect + * that Ascensio System SIA expressly excludes the warranty of non-infringement + * of any third-party rights. + * + * This program is distributed WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For + * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html + * + * You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha + * street, Riga, Latvia, EU, LV-1050. + * + * The interactive user interfaces in modified source and object code versions + * of the Program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU AGPL version 3. + * + * Pursuant to Section 7(b) of the License you must retain the original Product + * logo when distributing the program. Pursuant to Section 7(e) we decline to + * grant you any rights under trademark law for use of our trademarks. + * + * All the Product's GUI elements, including illustrations and icon sets, as + * well as technical writing content are licensed under the terms of the + * Creative Commons Attribution-ShareAlike 4.0 International. See the License + * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + * + */ + +/** + * CaptionDialog.js + * + * Created by Julia Radzhabova on 10.09.2019 + * Copyright (c) 2019 Ascensio System SIA. All rights reserved. + * + */ +define([ + 'common/main/lib/util/utils', + 'common/main/lib/component/MetricSpinner', + 'common/main/lib/component/ComboBox', + 'common/main/lib/view/AdvancedSettingsWindow' +], function () { 'use strict'; + + DE.Views.CaptionDialog = Common.Views.AdvancedSettingsWindow.extend(_.extend({ + options: { + contentWidth: 351, + height: 330 + }, + + initialize : function(options) { + var me = this; + + _.extend(this.options, { + title: this.textTitle, + template: [ + '
', + '
', + '
', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '
', + '', + '
', + '
', + '', + '
', + '
', + '', + '
', + '
', + '', + '', + '', + '
', + '', + '
', + '
', + '', + '
', + '
', + '
', + '', + '
', + '
', + '', + '
', + '
', + '', + '
', + '
', + '
', + '
', + '' + ].join('') + }, options); + + this.api = options.api; + this.handler = options.handler; + this.props = options.props; + + Common.Views.AdvancedSettingsWindow.prototype.initialize.call(this, this.options); + }, + + render: function() { + Common.Views.AdvancedSettingsWindow.prototype.render.call(this); + var me = this; + + this.txtCaption = new Common.UI.InputField({ + el : $('#caption-txt-caption'), + allowBlank : false, + value : '' + }); + + this.cmbPosition = new Common.UI.ComboBox({ + el: $('#caption-combo-position'), + cls: 'input-group-nr', + menuStyle: 'min-width: 75px;', + editable: false, + data: [ + { displayValue: this.textBefore, value: Asc.c_oAscFootnotePos.PageBottom }, + { displayValue: this.textAfter, value: Asc.c_oAscFootnotePos.BeneathText } + ] + }); + this.cmbPosition.setValue(Asc.c_oAscFootnotePos.PageBottom); + + this.cmbLabel = new Common.UI.ComboBox({ + el: $('#caption-combo-label'), + cls: 'input-group-nr', + menuStyle: 'min-width: 150px;', + editable: true, + data: [] + }); + + this.btnAdd = new Common.UI.Button({ + el: $('#caption-btn-add'), + disabled: true + }); + // this.btnAdd.on('click', _.bind(this.addLabel, this)); + + this.btnDelete = new Common.UI.Button({ + el: $('#caption-btn-delete'), + disabled: true + }); + // this.btnDelete.on('click', _.bind(this.deleteLabel, this)); + + this.cmbNumbering = new Common.UI.ComboBox({ + el: $('#caption-combo-numbering'), + cls: 'input-group-nr', + menuStyle: 'min-width: 150px;', + editable: false, + data: [ + { displayValue: '1, 2, 3,...', value: Asc.c_oAscNumberingFormat.Decimal, maskExp: /[0-9]/, defValue: 1 }, + { displayValue: 'a, b, c,...', value: Asc.c_oAscNumberingFormat.LowerLetter, maskExp: /[a-z]/, defValue: 'a' }, + { displayValue: 'A, B, C,...', value: Asc.c_oAscNumberingFormat.UpperLetter, maskExp: /[A-Z]/, defValue: 'A' }, + { displayValue: 'i, ii, iii,...', value: Asc.c_oAscNumberingFormat.LowerRoman, maskExp: /[ivxlcdm]/, defValue: 'i' }, + { displayValue: 'I, II, III,...', value: Asc.c_oAscNumberingFormat.UpperRoman, maskExp: /[IVXLCDM]/, defValue: 'I' } + ] + }); + this.cmbNumbering.setValue(Asc.c_oAscNumberingFormat.Decimal); + // this.cmbNumbering.on('selected', _.bind(this.onFormatSelect, this)); + + this.chChapter = new Common.UI.CheckBox({ + el: $('#caption-checkbox-chapter'), + labelText: this.textChapterInc + }); + this.chChapter.on('change', function(field, newValue, oldValue) { + me.cmbChapter.setDisabled(newValue!=='checked'); + me.cmbSeparator.setDisabled(newValue!=='checked'); + }); + + this.cmbChapter = new Common.UI.ComboBox({ + el: $('#caption-combo-chapter'), + cls: 'input-group-nr', + menuStyle: 'min-width: 150px;', + editable: false, + disabled: true, + data: [] + }); + // this.cmbChapter.setValue(0); + // this.cmbChapter.on('selected', _.bind(this.onFormatSelect, this)); + + this.cmbSeparator = new Common.UI.ComboBox({ + el: $('#caption-combo-separator'), + cls: 'input-group-nr', + menuStyle: 'min-width: 150px;', + editable: false, + disabled: true, + data: [ + { displayValue: '- (' + this.textHyphen + ')', value: Asc.c_oAscTabLeader.Hyphen }, + { displayValue: '. (' + this.textPeriod + ')', value: Asc.c_oAscTabLeader.Dot }, + { displayValue: ': (' + this.textColon + ')', value: Asc.c_oAscTabLeader.Hyphen }, + { displayValue: '-- (' + this.textLongDash + ')', value: Asc.c_oAscTabLeader.Hyphen }, + { displayValue: '-- (' + this.textDash + ')', value: Asc.c_oAscTabLeader.Hyphen } + ] + }); + // this.cmbSeparator.setValue(Asc.c_oAscNumberingFormat.Decimal); + // this.cmbSeparator.on('selected', _.bind(this.onFormatSelect, this)); + + this.lblExample = this.$window.find('#caption-label-example'); + + this.afterRender(); + }, + + afterRender: function() { + this._setDefaults(this.props); + }, + + show: function() { + Common.Views.AdvancedSettingsWindow.prototype.show.apply(this, arguments); + }, + + _setDefaults: function (props) { + if (props) { + } + }, + + getSettings: function () { + return {}; + }, + + onDlgBtnClick: function(event) { + this._handleInput((typeof(event) == 'object') ? event.currentTarget.attributes['result'].value : event); + }, + + onPrimary: function() { + this._handleInput('insert'); + return false; + }, + + _handleInput: function(state) { + this.handler && this.handler.call(this, state, (state == 'ok') ? this.getSettings() : undefined); + this.close(); + }, + + textTitle: 'Insert Caption', + textCaption: 'Caption', + textInsert: 'Insert', + textLabel: 'Label', + textAdd: 'Add label', + textDelete: 'Delete label', + textNumbering: 'Numbering', + textChapterInc: 'Include chapter number', + textChapter: 'Chapter starts with style', + textSeparator: 'Use separator', + textExamples: 'Examples: Table 2-A, Image 1.IV', + textBefore: 'Before', + textAfter: 'After', + textHyphen: 'hyphen', + textPeriod: 'period', + textColon: 'colon', + textLongDash: 'em-dash', + textDash: 'en-dash' + + }, DE.Views.CaptionDialog || {})) +}); \ No newline at end of file diff --git a/apps/documenteditor/main/app/view/Links.js b/apps/documenteditor/main/app/view/Links.js index c9b83f9d4..25792eeab 100644 --- a/apps/documenteditor/main/app/view/Links.js +++ b/apps/documenteditor/main/app/view/Links.js @@ -105,6 +105,10 @@ define([ this.btnBookmarks.on('click', function (b, e) { me.fireEvent('links:bookmarks'); }); + + this.btnCaption.on('click', function (b, e) { + me.fireEvent('links:caption'); + }); } return { @@ -147,6 +151,15 @@ define([ Common.Utils.injectComponent($host.find('#slot-btn-bookmarks'), this.btnBookmarks); this.paragraphControls.push(this.btnBookmarks); + this.btnCaption = new Common.UI.Button({ + cls: 'btn-toolbar x-huge icon-top', + iconCls: 'btn-bookmarks', + caption: this.capBtnCaption, + disabled: true + }); + Common.Utils.injectComponent($host.find('#slot-btn-caption'), this.btnCaption); + this.paragraphControls.push(this.btnCaption); + this._state = {disabled: false}; Common.NotificationCenter.on('app:ready', this.onAppReady.bind(this)); }, @@ -242,6 +255,7 @@ define([ }); me.btnBookmarks.updateHint(me.tipBookmarks); + me.btnCaption.updateHint(me.tipCaption); setEvents.call(me); }); @@ -283,7 +297,9 @@ define([ capBtnInsLink: 'Hyperlink', tipInsertHyperlink: 'Add Hyperlink', capBtnBookmarks: 'Bookmark', - tipBookmarks: 'Create a bookmark' + tipBookmarks: 'Create a bookmark', + capBtnCaption: 'Caption', + tipCaption: 'Insert caption' } }()), DE.Views.Links || {})); }); \ No newline at end of file