From 11af3400a73f69b5230740bb49745b0679389d58 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Wed, 29 Jul 2020 14:50:24 +0300 Subject: [PATCH] [DE] Add endnotes --- .../main/app/controller/Links.js | 45 ++++--- apps/documenteditor/main/app/view/Links.js | 46 ++++++- .../main/app/view/NoteSettingsDialog.js | 115 ++++++++++++++---- 3 files changed, 165 insertions(+), 41 deletions(-) diff --git a/apps/documenteditor/main/app/controller/Links.js b/apps/documenteditor/main/app/controller/Links.js index 4c3a5d09e..61ac6a4b1 100644 --- a/apps/documenteditor/main/app/controller/Links.js +++ b/apps/documenteditor/main/app/controller/Links.js @@ -46,7 +46,8 @@ define([ 'documenteditor/main/app/view/HyperlinkSettingsDialog', 'documenteditor/main/app/view/TableOfContentsSettings', 'documenteditor/main/app/view/BookmarksDialog', - 'documenteditor/main/app/view/CaptionDialog' + 'documenteditor/main/app/view/CaptionDialog', + 'documenteditor/main/app/view/NotesRemoveDialog' ], function () { 'use strict'; @@ -292,33 +293,37 @@ define([ case 'ins_footnote': this.api.asc_AddFootnote(); break; + case 'ins_endnote': + this.api.asc_AddEndnote(); + break; case 'delele': - Common.UI.warning({ - msg: this.view.confirmDeleteFootnotes, - buttons: ['yes', 'no'], - primary: 'yes', - callback: _.bind(function (btn) { - if (btn == 'yes') { - this.api.asc_RemoveAllFootnotes(); + (new DE.Views.NotesRemoveDialog({ + handler: function (dlg, result) { + if (result=='ok') { + var settings = dlg.getSettings(); + (settings.footnote || settings.endnote) && me.api.asc_RemoveAllFootnotes(settings.footnote, settings.endnote); } - Common.NotificationCenter.trigger('edit:complete', this.toolbar); - }, this) - }); + Common.NotificationCenter.trigger('edit:complete', me.toolbar); + } + })).show(); break; case 'settings': + var isEndNote = me.api.asc_IsCursorInEndnote(); (new DE.Views.NoteSettingsDialog({ api: me.api, handler: function (result, settings) { if (settings) { - me.api.asc_SetFootnoteProps(settings.props, settings.applyToAll); + settings.isEndNote ? me.api.asc_SetEndnoteProps(settings.props, settings.applyToAll) : + me.api.asc_SetFootnoteProps(settings.props, settings.applyToAll); if (result == 'insert') setTimeout(function() { - me.api.asc_AddFootnote(settings.custom); + settings.isEndNote ? me.api.asc_AddEndnote(settings.custom) : me.api.asc_AddFootnote(settings.custom); }, 1); } Common.NotificationCenter.trigger('edit:complete', me.toolbar); }, - props: me.api.asc_GetFootnoteProps() + isEndNote: isEndNote, + props: isEndNote ? me.api.asc_GetEndnoteProps() : me.api.asc_GetFootnoteProps() })).show(); break; case 'prev': @@ -333,6 +338,18 @@ define([ Common.NotificationCenter.trigger('edit:complete', me.toolbar); }, 50); break; + case 'prev-end': + this.api.asc_GotoEndnote(false); + setTimeout(function() { + Common.NotificationCenter.trigger('edit:complete', me.toolbar); + }, 50); + break; + case 'next-end': + this.api.asc_GotoEndnote(true); + setTimeout(function() { + Common.NotificationCenter.trigger('edit:complete', me.toolbar); + }, 50); + break; } }, diff --git a/apps/documenteditor/main/app/view/Links.js b/apps/documenteditor/main/app/view/Links.js index eb641576a..535fadd8b 100644 --- a/apps/documenteditor/main/app/view/Links.js +++ b/apps/documenteditor/main/app/view/Links.js @@ -96,6 +96,18 @@ define([ }); }); + this.btnsPrevEndNote.forEach(function(button) { + button.on('click', function (b, e) { + me.fireEvent('links:notes', ['prev-end']); + }); + }); + + this.btnsNextEndNote.forEach(function(button) { + button.on('click', function (b, e) { + me.fireEvent('links:notes', ['next-end']); + }); + }); + this.btnsHyperlink.forEach(function(button) { button.on('click', function (b, e) { me.fireEvent('links:hyperlink'); @@ -121,6 +133,8 @@ define([ this.btnsPrevNote = []; this.btnsNextNote = []; + this.btnsPrevEndNote = []; + this.btnsNextEndNote = []; this.paragraphControls = []; var me = this, @@ -221,6 +235,7 @@ define([ var _menu = new Common.UI.Menu({ items: [ {caption: me.mniInsFootnote, value: 'ins_footnote'}, + {caption: me.mniInsEndnote, value: 'ins_endnote'}, {caption: '--'}, new Common.UI.MenuItem({ template: _.template([ @@ -235,8 +250,22 @@ define([ ].join('')), stopPropagation: true }), + new Common.UI.MenuItem({ + template: _.template([ + '' + ].join('')), + stopPropagation: true + }), {caption: '--'}, {caption: me.mniDelFootnote, value: 'delele'}, + {caption: me.mniConvertNote, value: 'convert'}, {caption: me.mniNoteSettings, value: 'settings'} ] }); @@ -250,6 +279,14 @@ define([ el: $('#id-menu-goto-footnote-next-'+index), cls: 'btn-toolbar' })); + me.btnsPrevEndNote.push(new Common.UI.Button({ + el: $('#id-menu-goto-endnote-prev-'+index), + cls: 'btn-toolbar' + })); + me.btnsNextEndNote.push(new Common.UI.Button({ + el: $('#id-menu-goto-endnote-next-'+index), + cls: 'btn-toolbar' + })); }); me.btnsHyperlink.forEach( function(btn) { @@ -291,9 +328,9 @@ define([ textUpdatePages: 'Refresh page numbers only', tipNotes: 'Footnotes', mniInsFootnote: 'Insert Footnote', - mniDelFootnote: 'Delete All Footnotes', + mniDelFootnote: 'Delete All Notes', mniNoteSettings: 'Notes Settings', - textGotoFootnote: 'Go to Footnotes', + textGotoFootnote: 'Go to Footnote', capBtnInsFootnote: 'Footnotes', confirmDeleteFootnotes: 'Do you want to delete all footnotes?', capBtnInsLink: 'Hyperlink', @@ -301,7 +338,10 @@ define([ capBtnBookmarks: 'Bookmark', tipBookmarks: 'Create a bookmark', capBtnCaption: 'Caption', - tipCaption: 'Insert caption' + tipCaption: 'Insert caption', + mniConvertNote: 'Convert All Notes', + textGotoEndnote: 'Go to Endnote', + mniInsEndnote: 'Insert Endnote' } }()), DE.Views.Links || {})); }); \ No newline at end of file diff --git a/apps/documenteditor/main/app/view/NoteSettingsDialog.js b/apps/documenteditor/main/app/view/NoteSettingsDialog.js index 2c4bfc099..3f13ac7ef 100644 --- a/apps/documenteditor/main/app/view/NoteSettingsDialog.js +++ b/apps/documenteditor/main/app/view/NoteSettingsDialog.js @@ -65,18 +65,19 @@ define([ '', '', '', '', '', - '', '', '', - '', '', '', @@ -107,11 +108,6 @@ define([ '
', '', '', - '', - '', - '', '', '
', - '', + '', '
', - '', + '', + '
', '
', '
', - '
', + '
', + '
', + '
', '
', - '
', - '
', '', @@ -133,17 +129,50 @@ define([ this.api = options.api; this.handler = options.handler; this.props = options.props; + this.isEndNote = options.isEndNote || false; Common.Views.AdvancedSettingsWindow.prototype.initialize.call(this, this.options); - this.FormatType = 1; - this.StartValue = 1; + this._state = { + footnote: { + numbering: Asc.c_oAscFootnoteRestart.Continuous, + format: Asc.c_oAscNumberingFormat.Decimal, + start: 1 + }, + endnote: { + numbering: Asc.c_oAscFootnoteRestart.Continuous, + format: Asc.c_oAscNumberingFormat.LowerRoman, + start: 1 + }}; }, render: function() { Common.Views.AdvancedSettingsWindow.prototype.render.call(this); var me = this; + this.radioFootnote = new Common.UI.RadioBox({ + el: $('#note-settings-radio-foot'), + name: 'asc-radio-notes', + labelText: this.textFootnote, + checked: true + }); + this.radioFootnote.on('change', function(field, newValue, eOpts) { + if (newValue) { + me.changeNoteType(false); + } + }); + + this.radioEndnote = new Common.UI.RadioBox({ + el: $('#note-settings-radio-end'), + labelText: this.textEndnote, + name: 'asc-radio-notes' + }); + this.radioEndnote.on('change', function(field, newValue, eOpts) { + if (newValue) { + me.changeNoteType(true); + } + }); + this.cmbFootnote = new Common.UI.ComboBox({ el: $('#note-settings-combo-footnote'), cls: 'input-group-nr', @@ -156,6 +185,18 @@ define([ }); this.cmbFootnote.setValue(Asc.c_oAscFootnotePos.PageBottom); + this.cmbEndnote = new Common.UI.ComboBox({ + el: $('#note-settings-combo-endnote'), + cls: 'input-group-nr', + menuStyle: 'min-width: 150px;', + editable: false, + data: [ + { displayValue: this.textSectEnd, value: Asc.c_oAscFootnotePos.SectEnd }, + { displayValue: this.textPageBottom, value: Asc.c_oAscFootnotePos.PageBottom } + ] + }); + this.cmbEndnote.setValue(Asc.c_oAscFootnotePos.PageBottom); + this.cmbFormat = new Common.UI.ComboBox({ el: $('#note-settings-combo-format'), cls: 'input-group-nr', @@ -169,10 +210,9 @@ define([ { displayValue: 'I, II, III,...', value: Asc.c_oAscNumberingFormat.UpperRoman, maskExp: /[IVXLCDM]/, defValue: 'I' } ] }); - this.cmbFormat.setValue(this.FormatType); + this.cmbFormat.setValue(this._state.footnote.format); this.cmbFormat.on('selected', _.bind(this.onFormatSelect, this)); - // this.spnStart = new Common.UI.MetricSpinner({ this.spnStart = new Common.UI.CustomSpinner({ el: $('#note-settings-spin-start'), step: 1, @@ -185,16 +225,17 @@ define([ maskExp: /[0-9]/ }); + this._arrNumbering = [ + { displayValue: this.textContinue, value: Asc.c_oAscFootnoteRestart.Continuous }, + { displayValue: this.textEachSection, value: Asc.c_oAscFootnoteRestart.EachSect }, + { displayValue: this.textEachPage, value: Asc.c_oAscFootnoteRestart.EachPage } + ]; this.cmbNumbering = new Common.UI.ComboBox({ el: $('#note-settings-combo-numbering'), cls: 'input-group-nr', menuStyle: 'min-width: 150px;', editable: false, - data: [ - { displayValue: this.textContinue, value: Asc.c_oAscFootnoteRestart.Continuous }, - { displayValue: this.textEachSection, value: Asc.c_oAscFootnoteRestart.EachSect }, - { displayValue: this.textEachPage, value: Asc.c_oAscFootnoteRestart.EachPage } - ] + data: this._arrNumbering }); this.cmbNumbering.setValue(Asc.c_oAscFootnoteRestart.Continuous); @@ -239,9 +280,13 @@ define([ }, _setDefaults: function (props) { + + this.isEndNote ? this.radioEndnote.setValue(true, true) : this.radioFootnote.setValue(true, true); + this.changeNoteType(this.isEndNote); + if (props) { var val = props.get_Pos(); - this.cmbFootnote.setValue(val); + this.isEndNote ? this.cmbEndnote.setValue(val) : this.cmbFootnote.setValue(val); val = props.get_NumFormat(); this.cmbFormat.setValue(val); @@ -258,7 +303,7 @@ define([ getSettings: function () { var props = new Asc.CAscFootnotePr(); - props.put_Pos(this.cmbFootnote.getValue()); + props.put_Pos(this.isEndNote ? this.cmbEndnote.getValue() : this.cmbFootnote.getValue()); props.put_NumRestart(this.cmbNumbering.getValue()); var val = this.txtCustom.getValue(); @@ -268,7 +313,7 @@ define([ props.put_NumStart(this.spnStart.getNumberValue()); } - return {props: props, applyToAll: (this.cmbApply.getValue()==1), custom: _.isEmpty(val) ? undefined : val}; + return {props: props, applyToAll: (this.cmbApply.getValue()==1), custom: _.isEmpty(val) ? undefined : val, isEndNote: this.isEndNote}; }, onDlgBtnClick: function(event) { @@ -315,7 +360,7 @@ define([ } this.spnStart.setValue(this.spnStart.getValue()); - this.FormatType = record.value; + this._state[this.isEndNote ? 'endnote' : 'footnote'].format = record.value; }, _10toS: function(value) { @@ -411,6 +456,26 @@ define([ return result; }, + changeNoteType: function(isEndNote) { + this._state[this.isEndNote ? 'endnote' : 'footnote'].start = this.spnStart.getNumberValue(); // save prev start + this._state[this.isEndNote ? 'endnote' : 'footnote'].numbering = this.cmbNumbering.getValue(); // save prev numbering + + this.isEndNote = isEndNote; + + this.cmbFootnote.setDisabled(isEndNote); + this.cmbEndnote.setDisabled(!isEndNote); + + var state = this._state[isEndNote ? 'endnote' : 'footnote'], + arr = isEndNote ? this._arrNumbering.slice(0,2) : this._arrNumbering; + this.cmbNumbering.setData(arr); + this.cmbNumbering.setValue(state.numbering); + + this.cmbFormat.setValue(state.format); + this.onFormatSelect(this.cmbFormat, this.cmbFormat.getSelectedRecord()); + + this.spnStart.setValue(state.start); + }, + textTitle: 'Notes Settings', textLocation: 'Location', textFootnote: 'Footnote', @@ -428,7 +493,9 @@ define([ textSection: 'Current section', textApply: 'Apply', textInsert: 'Insert', - textCustom: 'Custom Mark' + textCustom: 'Custom Mark', + textSectEnd: 'End of section', + textEndnote: 'Endnote' }, DE.Views.NoteSettingsDialog || {})) }); \ No newline at end of file