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

446 lines
18 KiB
JavaScript
Raw Normal View History

2016-12-19 11:44:02 +00:00
/*
*
* (c) Copyright Ascensio System Limited 2010-2016
*
* 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 Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* 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
* Copyright (c) 2016 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.NoteSettingsDialog = Common.Views.AdvancedSettingsWindow.extend(_.extend({
options: {
contentWidth: 300,
2016-12-20 14:34:01 +00:00
height: 380
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">',
2016-12-19 11:44:02 +00:00
'<label class="header">', me.textLocation,'</label>',
'</td>',
'</tr>',
'<tr>',
'<td class="padding-large">',
2016-12-23 12:29:16 +00:00
'<label class="input-label" style="margin-top: 4px;">', me.textFootnote,'</label>',
'<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>',
2016-12-23 12:29:16 +00:00
'<td>',
'<div class="padding-large"></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">',
2016-12-23 12:29:16 +00:00
'<div style="display: inline-block; margin-right: 10px;">',
'<label class="input-label">', me.textNumFormat,'</label>',
'<div id="note-settings-combo-format" class="input-group-nr" style="width:150px;"></div>',
'</div>','<div style="display: inline-block;">',
'<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>',
2016-12-23 12:29:16 +00:00
'<td>',
'<div class="padding-large"></div>',
2016-12-19 11:44:02 +00:00
'</td>',
'</tr>',
'<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">',
'<button class="btn normal dlg-btn primary" result="insert" style="margin-right: 10px; width: 86px;">' + me.textInsert + '</button>',
'<button class="btn normal dlg-btn primary" result="apply" style="margin-right: 10px; width: 86px;">' + me.textApply + '</button>',
'<button class="btn normal dlg-btn" result="cancel" style="width: 86px;">' + me.textCancel + '</button>',
'</div>'
].join('')
}, options);
this.api = options.api;
this.handler = options.handler;
this.props = options.props;
Common.Views.AdvancedSettingsWindow.prototype.initialize.call(this, this.options);
this.FormatType = 1;
this.StartValue = 1;
},
render: function() {
Common.Views.AdvancedSettingsWindow.prototype.render.call(this);
var me = this;
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-20 13:12:03 +00:00
{ displayValue: this.textPageBottom, value: Asc.c_oAscFootnotePos.section_footnote_PosPageBottom },
{ displayValue: this.textTextBottom, value: Asc.c_oAscFootnotePos.section_footnote_PosBeneathText }
2016-12-19 11:44:02 +00:00
]
});
2016-12-20 13:12:03 +00:00
this.cmbFootnote.setValue(Asc.c_oAscFootnotePos.section_footnote_PosPageBottom);
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: [
{ displayValue: '1, 2, 3,...', value: 1, maskExp: /[0-9]/, defValue: 1 },
{ displayValue: 'a, b, c,...', value: 5, maskExp: /[a-z]/, defValue: 'a' },
{ displayValue: 'A, B, C,...', value: 4, maskExp: /[A-Z]/, defValue: 'A' },
{ displayValue: 'i, ii, iii,...', value: 7, maskExp: /[ivxlcdm]/, defValue: 'i' },
{ displayValue: 'I, II, III,...', value: 3, maskExp: /[IVXLCDM]/, defValue: 'I' }
]
});
this.cmbFormat.setValue(this.FormatType);
this.cmbFormat.on('selected', _.bind(this.onFormatSelect, this));
// this.spnStart = new Common.UI.MetricSpinner({
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
});
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,
data: [
2016-12-20 13:12:03 +00:00
{ displayValue: this.textContinue, value: Asc.c_oAscFootnoteRestart.section_footnote_RestartContinuous },
{ displayValue: this.textEachSection, value: Asc.c_oAscFootnoteRestart.section_footnote_RestartEachSect },
{ displayValue: this.textEachPage, value: Asc.c_oAscFootnoteRestart.section_footnote_RestartEachPage }
2016-12-19 11:44:02 +00:00
]
});
2016-12-20 13:12:03 +00:00
this.cmbNumbering.setValue(Asc.c_oAscFootnoteRestart.section_footnote_RestartContinuous);
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-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: Asc.section_footnote_RestartContinuous },
{ displayValue: this.textSection, value: Asc.section_footnote_RestartEachSect }
]
});
this.cmbApply.setValue(Asc.section_footnote_RestartContinuous);
this.afterRender();
},
afterRender: function() {
this._setDefaults(this.props);
},
show: function() {
Common.Views.AdvancedSettingsWindow.prototype.show.apply(this, arguments);
},
_setDefaults: function (props) {
if (props) {
var val = props.get_Pos();
this.cmbFootnote.setValue(val);
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);
/*
2016-12-20 14:34:01 +00:00
val = props.get_Custom();
this.txtCustom.setValue(val);
this.cmbFormat.setDisabled(!_.isEmpty(val));
this.spnStart.setDisabled(!_.isEmpty(val));
2016-12-19 11:44:02 +00:00
val = props.get_ApplyTo();
this.cmbApply.setValue(val);
*/
}
},
getSettings: function () {
var props = new Asc.CAscFootnotePr();
props.put_Pos(this.cmbFootnote.getValue());
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);
// if (val==1)
2016-12-19 11:44:02 +00:00
props.put_NumStart(this.spnStart.getNumberValue());
2016-12-20 14:34:01 +00:00
// else
// props.put_NumStart(this.txtStart.getValue());
} else {
// props.set_Custom(val);
}
2016-12-19 11:44:02 +00:00
// props.put_ApplyTo(this.cmbApply.getValue());
return props;
},
onDlgBtnClick: function(event) {
var me = this;
var state = (typeof(event) == 'object') ? event.currentTarget.attributes['result'].value : event;
if (state == 'insert' || state == 'apply') {
this.handler && this.handler.call(this, state, (state == 'insert' || state == 'apply') ? this.getSettings() : undefined);
}
this.close();
},
onPrimary: function() {
return true;
},
onFormatSelect: function(combo, record) {
if (!record) return;
this.spnStart.setMask(record.maskExp);
var me = this;
switch (record.value) {
case 3: // I, II, III, ...
this.spnStart.options.toCustomFormat = this._10toRome;
this.spnStart.options.fromCustomFormat = this._Rometo10;
break;
case 7: // 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;
case 4: // A, B, C, ...
this.spnStart.options.toCustomFormat = this._10toS;
this.spnStart.options.fromCustomFormat = this._Sto10;
break;
case 5: // 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());
2016-12-19 11:44:02 +00:00
this.FormatType = record.value;
},
_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
},
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',
2016-12-20 14:34:01 +00:00
textCancel: 'Cancel',
textCustom: 'Custom Mark'
2016-12-19 11:44:02 +00:00
}, DE.Views.NoteSettingsDialog || {}))
});