web-apps/apps/documenteditor/main/app/view/NoteSettingsDialog.js

501 lines
21 KiB
JavaScript
Raw Normal View History

2016-12-19 11:44:02 +00:00
/*
*
* (c) Copyright Ascensio System SIA 2010-2019
2016-12-19 11:44:02 +00:00
*
* 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.
2016-12-19 11:44:02 +00:00
*
* 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
*
*/
/**
* NoteSettingsDialog.js.js
*
* Created by Julia Radzhabova on 18.12.2016
2018-03-01 12:16:38 +00:00
* Copyright (c) 2018 Ascensio System SIA. All rights reserved.
2016-12-19 11:44:02 +00:00
*
*/
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.NoteSettingsDialog = Common.Views.AdvancedSettingsWindow.extend(_.extend({
options: {
contentWidth: 300,
2019-09-11 08:38:08 +00:00
height: 380,
buttons: null
2016-12-19 11:44:02 +00:00
},
initialize : function(options) {
var me = this;
_.extend(this.options, {
title: this.textTitle,
template: [
'<div class="box" style="height:' + (me.options.height - 85) + 'px;">',
2016-12-23 12:29:16 +00:00
'<div class="content-panel" style="padding: 0 5px;"><div class="inner-content">',
2016-12-19 11:44:02 +00:00
'<div class="settings-panel active">',
2016-12-23 12:29:16 +00:00
'<table cols="1" style="width: 100%;">',
2016-12-19 11:44:02 +00:00
'<tr>',
2016-12-23 12:29:16 +00:00
'<td class="padding-small">',
2020-07-29 11:50:24 +00:00
'<label class="header">', me.textLocation,'</label>',
2016-12-19 11:44:02 +00:00
'</td>',
'</tr>',
'<tr>',
2020-07-29 11:50:24 +00:00
'<td class="padding-small">',
'<div id="note-settings-radio-foot" style="margin-top: 4px;display: inline-block"></div>',
2016-12-23 12:29:16 +00:00
'<div id="note-settings-combo-footnote" class="input-group-nr" style="display: inline-block; width:150px;float:right;"></div>',
2016-12-19 11:44:02 +00:00
'</td>',
'</tr>',
'<tr>',
2020-07-29 11:50:24 +00:00
'<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>',
2016-12-19 11:44:02 +00:00
'</td>',
'</tr>',
'<tr>',
2016-12-23 12:29:16 +00:00
'<td class="padding-small">',
2016-12-19 11:44:02 +00:00
'<label class="header">', me.textFormat,'</label>',
'</td>',
'</tr>',
'<tr>',
'<td class="padding-small">',
2017-04-24 08:09:06 +00:00
'<div style="display: inline-block; margin-right: 10px; vertical-align: middle;">',
2016-12-23 12:29:16 +00:00
'<label class="input-label">', me.textNumFormat,'</label>',
'<div id="note-settings-combo-format" class="input-group-nr" style="width:150px;"></div>',
2017-04-24 08:09:06 +00:00
'</div>','<div style="display: inline-block; vertical-align: middle;">',
2016-12-23 12:29:16 +00:00
'<label class="input-label">', me.textStart,'</label>',
'<div id="note-settings-spin-start"></div>',
'</div>',
2016-12-19 11:44:02 +00:00
'</td>',
'</tr>',
'<tr>',
2016-12-23 12:29:16 +00:00
'<td class="padding-small">',
2016-12-19 11:44:02 +00:00
'<label class="input-label">', me.textNumbering, '</label>',
2016-12-23 12:29:16 +00:00
'<div id="note-settings-combo-numbering" class="input-group-nr" style="width:150px;"></div>',
2016-12-19 11:44:02 +00:00
'</td>',
'</tr>',
2016-12-20 14:34:01 +00:00
'<tr>',
2016-12-23 12:29:16 +00:00
'<td class="padding-large">',
2016-12-20 14:34:01 +00:00
'<label class="input-label">', me.textCustom, '</label>',
'<div id="note-settings-txt-custom"></div>',
'</td>',
'</tr>',
2016-12-19 11:44:02 +00:00
'<tr>',
'<td class="padding-small">',
2016-12-23 12:29:16 +00:00
'<label class="header" style="margin-top: 4px;">', me.textApplyTo,'</label>',
'<div id="note-settings-combo-apply" class="input-group-nr" style="display: inline-block; width:150px;float:right;"></div>',
2016-12-19 11:44:02 +00:00
'</td>',
'</tr>',
'</table>',
'</div></div>',
'</div>',
'</div>',
'<div class="footer center">',
2019-09-11 08:38:08 +00:00
'<button class="btn normal dlg-btn primary" result="insert" style="width: 86px;">' + me.textInsert + '</button>',
'<button id="note-settings-btn-apply" class="btn normal dlg-btn" result="apply" style="width: 86px;">' + me.textApply + '</button>',
2019-09-10 06:47:19 +00:00
'<button class="btn normal dlg-btn" result="cancel" style="width: 86px;">' + me.cancelButtonText + '</button>',
2016-12-19 11:44:02 +00:00
'</div>'
].join('')
}, options);
this.api = options.api;
this.handler = options.handler;
this.props = options.props;
2020-07-29 11:50:24 +00:00
this.isEndNote = options.isEndNote || false;
2016-12-19 11:44:02 +00:00
Common.Views.AdvancedSettingsWindow.prototype.initialize.call(this, this.options);
2020-07-29 11:50:24 +00:00
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
}};
2016-12-19 11:44:02 +00:00
},
render: function() {
Common.Views.AdvancedSettingsWindow.prototype.render.call(this);
var me = this;
2020-07-29 11:50:24 +00:00
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);
}
});
2016-12-19 11:44:02 +00:00
this.cmbFootnote = new Common.UI.ComboBox({
el: $('#note-settings-combo-footnote'),
cls: 'input-group-nr',
2016-12-23 12:29:16 +00:00
menuStyle: 'min-width: 150px;',
2016-12-19 11:44:02 +00:00
editable: false,
data: [
2016-12-26 10:54:36 +00:00
{ displayValue: this.textPageBottom, value: Asc.c_oAscFootnotePos.PageBottom },
{ displayValue: this.textTextBottom, value: Asc.c_oAscFootnotePos.BeneathText }
2016-12-19 11:44:02 +00:00
]
});
2016-12-26 10:54:36 +00:00
this.cmbFootnote.setValue(Asc.c_oAscFootnotePos.PageBottom);
2016-12-19 11:44:02 +00:00
2020-07-29 11:50:24 +00:00
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);
2016-12-19 11:44:02 +00:00
this.cmbFormat = new Common.UI.ComboBox({
el: $('#note-settings-combo-format'),
cls: 'input-group-nr',
2016-12-23 12:29:16 +00:00
menuStyle: 'min-width: 150px;',
2016-12-19 11:44:02 +00:00
editable: false,
data: [
2017-02-22 08:05:48 +00:00
{ 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' }
2016-12-19 11:44:02 +00:00
]
});
2020-07-29 11:50:24 +00:00
this.cmbFormat.setValue(this._state.footnote.format);
2016-12-19 11:44:02 +00:00
this.cmbFormat.on('selected', _.bind(this.onFormatSelect, this));
this.spnStart = new Common.UI.CustomSpinner({
2016-12-19 11:44:02 +00:00
el: $('#note-settings-spin-start'),
step: 1,
2016-12-23 12:29:16 +00:00
width: 85,
2016-12-19 11:44:02 +00:00
defaultUnit : "",
value: 1,
2016-12-19 11:44:02 +00:00
maxValue: 16383,
minValue: 1,
allowDecimal: false,
maskExp: /[0-9]/
2016-12-19 11:44:02 +00:00
});
2020-07-29 11:50:24 +00:00
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 }
];
2016-12-19 11:44:02 +00:00
this.cmbNumbering = new Common.UI.ComboBox({
el: $('#note-settings-combo-numbering'),
cls: 'input-group-nr',
2016-12-23 12:29:16 +00:00
menuStyle: 'min-width: 150px;',
2016-12-19 11:44:02 +00:00
editable: false,
2020-07-29 11:50:24 +00:00
data: this._arrNumbering
2016-12-19 11:44:02 +00:00
});
2016-12-26 10:54:36 +00:00
this.cmbNumbering.setValue(Asc.c_oAscFootnoteRestart.Continuous);
2016-12-19 11:44:02 +00:00
2016-12-20 14:34:01 +00:00
this.txtCustom = new Common.UI.InputField({
el : $('#note-settings-txt-custom'),
allowBlank : true,
validateOnChange: true,
validateOnBlur: false,
2016-12-23 12:29:16 +00:00
style : 'width: 85px; vertical-align: middle;',
2016-12-20 14:34:01 +00:00
value : ''
}).on ('changing', function (input, value) {
me.cmbFormat.setDisabled(value.length>0);
me.spnStart.setDisabled(value.length>0);
2016-12-26 10:54:36 +00:00
me.btnApply.setDisabled(value.length>0);
2016-12-20 14:34:01 +00:00
});
2016-12-19 11:44:02 +00:00
this.cmbApply = new Common.UI.ComboBox({
el: $('#note-settings-combo-apply'),
cls: 'input-group-nr',
2016-12-23 12:29:16 +00:00
menuStyle: 'min-width: 150px;',
2016-12-19 11:44:02 +00:00
editable: false,
data: [
{ displayValue: this.textDocument, value: 1 },
{ displayValue: this.textSection, value: 0 }
2016-12-19 11:44:02 +00:00
]
});
this.cmbApply.setValue(1);
2016-12-19 11:44:02 +00:00
2016-12-26 10:54:36 +00:00
this.btnApply = new Common.UI.Button({
el: $('#note-settings-btn-apply')
});
2016-12-19 11:44:02 +00:00
this.afterRender();
},
afterRender: function() {
this._setDefaults(this.props);
},
show: function() {
Common.Views.AdvancedSettingsWindow.prototype.show.apply(this, arguments);
},
_setDefaults: function (props) {
2020-07-29 11:50:24 +00:00
this.isEndNote ? this.radioEndnote.setValue(true, true) : this.radioFootnote.setValue(true, true);
this.changeNoteType(this.isEndNote);
2016-12-19 11:44:02 +00:00
if (props) {
var val = props.get_Pos();
2020-07-29 11:50:24 +00:00
this.isEndNote ? this.cmbEndnote.setValue(val) : this.cmbFootnote.setValue(val);
2016-12-19 11:44:02 +00:00
val = props.get_NumFormat();
this.cmbFormat.setValue(val);
this.onFormatSelect(this.cmbFormat, this.cmbFormat.getSelectedRecord());
2016-12-19 11:44:02 +00:00
val = props.get_NumStart();
this.spnStart.setValue(val);
val = props.get_NumRestart();
this.cmbNumbering.setValue(val);
}
},
getSettings: function () {
var props = new Asc.CAscFootnotePr();
2020-07-29 11:50:24 +00:00
props.put_Pos(this.isEndNote ? this.cmbEndnote.getValue() : this.cmbFootnote.getValue());
2016-12-19 11:44:02 +00:00
props.put_NumRestart(this.cmbNumbering.getValue());
2016-12-20 14:34:01 +00:00
var val = this.txtCustom.getValue();
if (_.isEmpty(val)) {
val = this.cmbFormat.getValue();
props.put_NumFormat(val);
2016-12-19 11:44:02 +00:00
props.put_NumStart(this.spnStart.getNumberValue());
2016-12-20 14:34:01 +00:00
}
2016-12-19 11:44:02 +00:00
2020-07-29 11:50:24 +00:00
return {props: props, applyToAll: (this.cmbApply.getValue()==1), custom: _.isEmpty(val) ? undefined : val, isEndNote: this.isEndNote};
2016-12-19 11:44:02 +00:00
},
onDlgBtnClick: function(event) {
2019-07-31 14:26:28 +00:00
this._handleInput((typeof(event) == 'object') ? event.currentTarget.attributes['result'].value : event);
2016-12-19 11:44:02 +00:00
},
onPrimary: function() {
2019-07-31 14:26:28 +00:00
this._handleInput('insert');
return false;
},
_handleInput: function(state) {
this.handler && this.handler.call(this, state, (state == 'insert' || state == 'apply') ? this.getSettings() : undefined);
this.close();
2016-12-19 11:44:02 +00:00
},
onFormatSelect: function(combo, record) {
if (!record) return;
this.spnStart.setMask(record.maskExp);
var me = this;
switch (record.value) {
2017-02-22 08:05:48 +00:00
case Asc.c_oAscNumberingFormat.UpperRoman: // I, II, III, ...
this.spnStart.options.toCustomFormat = this._10toRome;
this.spnStart.options.fromCustomFormat = this._Rometo10;
break;
2017-02-22 08:05:48 +00:00
case Asc.c_oAscNumberingFormat.LowerRoman: // i, ii, iii, ...
this.spnStart.options.toCustomFormat = function(value) { return me._10toRome(value).toLocaleLowerCase(); };
this.spnStart.options.fromCustomFormat = function(value) { return me._Rometo10(value.toLocaleUpperCase()); };
break;
2017-02-22 08:05:48 +00:00
case Asc.c_oAscNumberingFormat.UpperLetter: // A, B, C, ...
this.spnStart.options.toCustomFormat = this._10toS;
this.spnStart.options.fromCustomFormat = this._Sto10;
break;
2017-02-22 08:05:48 +00:00
case Asc.c_oAscNumberingFormat.LowerLetter: // a, b, c, ...
this.spnStart.options.toCustomFormat = function(value) { return me._10toS(value).toLocaleLowerCase(); };
this.spnStart.options.fromCustomFormat = function(value) { return me._Sto10(value.toLocaleUpperCase()); };
break;
default: // 1, 2, 3, ...
this.spnStart.options.toCustomFormat = function(value) { return value; };
this.spnStart.options.fromCustomFormat = function(value) { return value; };
break;
2016-12-19 11:44:02 +00:00
}
this.spnStart.setValue(this.spnStart.getValue());
2020-07-29 11:50:24 +00:00
this._state[this.isEndNote ? 'endnote' : 'footnote'].format = record.value;
2016-12-19 11:44:02 +00:00
},
_10toS: function(value) {
value = parseInt(value);
2016-12-19 11:44:02 +00:00
var n = Math.ceil(value / 26),
code = String.fromCharCode((value-1) % 26 + "A".charCodeAt(0)) ,
result = '';
for (var i=0; i<n; i++ ) {
result += code;
}
return result;
},
_Sto10: function(str) {
if ( str.length<1 || (new RegExp('[^' + str.charAt(0) + ']')).test(str) || !/[A-Z]/.test(str)) return 1;
2016-12-19 11:44:02 +00:00
var n = str.length-1,
result = str.charCodeAt(0) - "A".charCodeAt(0) + 1;
result += 26*n;
return result;
},
2016-12-19 11:44:02 +00:00
_10toRome: function(value) {
value = parseInt(value);
var result = '',
digits = [
['M', 1000],
['CM', 900],
['D', 500],
['CD', 400],
['C', 100],
['XC', 90],
['L', 50],
['XL', 40],
['X', 10],
['IX', 9],
['V', 5],
['IV', 4],
['I', 1]
];
var val = digits[0][1],
div = Math.floor(value / val),
n = 0;
for (var i=0; i<div; i++)
result += digits[n][0];
value -= div * val;
n++;
while (value>0) {
val = digits[n][1];
div = value - val;
if (div>=0) {
result += digits[n][0];
value = div;
} else
n++;
}
return result;
},
_Rometo10: function(str) {
if ( !/[IVXLCDM]/.test(str) || str.length<1 ) return 1;
var digits = {
'I': 1,
'V': 5,
'X': 10,
'L': 50,
'C': 100,
'D': 500,
'M': 1000
};
var n = str.length-1,
result = digits[str.charAt(n)],
prev = result;
for (var i=n-1; i>=0; i-- ) {
var val = digits[str.charAt(i)];
if (val<prev) {
if (prev/val>10) return 1;
val *= -1;
}
result += val;
}
return result;
2016-12-19 11:44:02 +00:00
},
2020-07-29 11:50:24 +00:00
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);
},
2016-12-19 11:44:02 +00:00
textTitle: 'Notes Settings',
textLocation: 'Location',
textFootnote: 'Footnote',
textPageBottom: 'Bottom of page',
textTextBottom: 'Below text',
textFormat: 'Format',
textNumFormat: 'Number Format',
textStart: 'Start at',
textNumbering: 'Numbering',
textContinue: 'Continuous',
textEachPage: 'Restart each page',
textEachSection: 'Restart each section',
textApplyTo: 'Apply changes to',
textDocument: 'Whole document',
textSection: 'Current section',
textApply: 'Apply',
textInsert: 'Insert',
2020-07-29 11:50:24 +00:00
textCustom: 'Custom Mark',
textSectEnd: 'End of section',
textEndnote: 'Endnote'
2016-12-19 11:44:02 +00:00
}, DE.Views.NoteSettingsDialog || {}))
});