[DE] Add endnotes

This commit is contained in:
Julia Radzhabova 2020-07-29 14:50:24 +03:00
parent a9da5afdd4
commit 11af3400a7
3 changed files with 165 additions and 41 deletions

View file

@ -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;
}
},

View file

@ -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([
'<div class="menu-zoom" style="height: 25px;" ',
'<% if(!_.isUndefined(options.stopPropagation)) { %>',
'data-stopPropagation="true"',
'<% } %>', '>',
'<label class="title">' + me.textGotoEndnote + '</label>',
'<button id="id-menu-goto-endnote-next-' + index + '" type="button" style="float:right; margin: 2px 5px 0 0;" class="btn small btn-toolbar"><i class="icon menu__icon btn-nextitem">&nbsp;</i></button>',
'<button id="id-menu-goto-endnote-prev-' + index + '" type="button" style="float:right; margin-top: 2px;" class="btn small btn-toolbar"><i class="icon menu__icon btn-previtem">&nbsp;</i></button>',
'</div>'
].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 || {}));
});

View file

@ -65,18 +65,19 @@ define([
'<table cols="1" style="width: 100%;">',
'<tr>',
'<td class="padding-small">',
'<label class="header">', me.textLocation,'</label>',
'<label class="header">', me.textLocation,'</label>',
'</td>',
'</tr>',
'<tr>',
'<td class="padding-large">',
'<label class="input-label" style="margin-top: 4px;">', me.textFootnote,'</label>',
'<td class="padding-small">',
'<div id="note-settings-radio-foot" style="margin-top: 4px;display: inline-block"></div>',
'<div id="note-settings-combo-footnote" class="input-group-nr" style="display: inline-block; width:150px;float:right;"></div>',
'</td>',
'</tr>',
'<tr>',
'<td>',
'<div class="padding-large"></div>',
'<td class="padding-large">',
'<div id="note-settings-radio-end" style="margin-top: 4px;display: inline-block"></div>',
'<div id="note-settings-combo-endnote" class="input-group-nr" style="display: inline-block; width:150px;float:right;"></div>',
'</td>',
'</tr>',
'<tr>',
@ -107,11 +108,6 @@ define([
'<div id="note-settings-txt-custom"></div>',
'</td>',
'</tr>',
'<tr>',
'<td>',
'<div class="padding-large"></div>',
'</td>',
'</tr>',
'<tr>',
'<td class="padding-small">',
'<label class="header" style="margin-top: 4px;">', me.textApplyTo,'</label>',
@ -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 || {}))
});