This commit is contained in:
nikita_bartoshuk
2025-10-27 23:25:35 +03:00
parent 3d89ed327b
commit 7308737d6a
3 changed files with 261 additions and 52 deletions

View File

@ -53,6 +53,9 @@ define([
sdkViewName : '#id_main',
initialize: function () {
this._initSettings = true;
this.spinners = [];
this.addListeners({
'HeaderFooterTab': {
'header:editremove': _.bind(this.editRemoveHeader, this),
@ -60,10 +63,111 @@ define([
'headerfooter:pagecount': _.bind(this.onInsertPageCountClick, this),
'headerfooter:pospick': _.bind(this.onInsertPageNumberClick, this),
'headerfooter:inspagenumber': _.bind(this.onInsertPageNumberMenuClick, this),
'headerfooter:headerfooterpos': _.bind(this.onNumPositionChange, this),
'headerfooter:difffirst': _.bind(this.onDiffFirstChange, this),
'headerfooter:diffoddeven': _.bind(this.onDiffOddEvenChange, this),
'headerfooter:sameas': _.bind(this.onSameAsChange, this),
},
});
},
onDiffFirstChange: function (field) {
if (this.api)
this.api.HeadersAndFooters_DifferentFirstPage(field.getValue()=='checked');
this.fireEvent('editcomplete', this);
},
onDiffOddEvenChange: function (field) {
if (this.api)
this.api.HeadersAndFooters_DifferentOddandEvenPage((field.getValue()=='checked'));
this.fireEvent('editcomplete', this);
},
onSameAsChange: function(field, newValue, oldValue, eOpts){
if (this.api)
this.api.HeadersAndFooters_LinkToPrevious((field.getValue()=='checked'));
this.fireEvent('editcomplete', this);
},
ChangeSettings: function(prop) {
if (this._initSettings)
this.createDelayedElements();
// this.disableControls(this._locked);
if (prop) {
var value = prop.get_Type();
if (this._state.PositionType !== value) {
this._state.PositionType = value;
}
value = prop.get_Position();
if ( Math.abs(this._state.Position-value)>0.001 ) {
this.numPosition.setValue(Common.Utils.Metric.fnRecalcFromMM(value), true);
this._state.Position = value;
}
value = prop.get_DifferentFirst();
if ( this._state.DiffFirst!==value ) {
this.view.chDiffFirst.setValue(value, true);
this._state.DiffFirst=value;
}
value = prop.get_DifferentEvenOdd();
if ( this._state.DiffOdd!==value ) {
this.view.chDiffOddEven.setValue(value, true);
this._state.DiffOdd=value;
}
value = prop.get_LinkToPrevious();
if ( this._state.SameAs!==value ) {
this.view.chSameAs.setDisabled(value===null || this._locked);
this.view.chSameAs.setValue(value==true, true);
this._state.SameAs=value;
}
value = prop.get_StartPageNumber();
if ( this._state.Numbering!==value && value !== null) {
// if (value<0)
// this.radioPrev.setValue(true, true);
// else {
// this.radioFrom.setValue(true, true);
// this.numFrom.setValue(value, true);
// }
this._state.Numbering=value;
}
value = prop.get_NumFormat();
if ( this._state.NumFormat!==value) {
// this.fillFormatCombo(value);
this._state.NumFormat = value;
}
}
},
createDelayedElements: function() {
this.spinners.push(this.view.numHeaderPosition);
this.spinners.push(this.view.numFooterPosition);
this.updateMetricUnit();
this._initSettings = false;
},
updateMetricUnit: function() {
if (this.spinners) {
for (var i=0; i<this.spinners.length; i++) {
var spinner = this.spinners[i];
spinner.setDefaultUnit(Common.Utils.Metric.getCurrentMetricName());
spinner.setStep(Common.Utils.Metric.getCurrentMetric()==Common.Utils.Metric.c_MetricUnits.pt ? 1 : 0.01);
}
this.numPosition && this.numPosition.setValue(Common.Utils.Metric.fnRecalcFromMM(this._state.Position), true);
}
},
onNumPositionChange: function(field, isHeader, newValue, oldValue, eOpts){
if (this.api)
this.api.put_HeadersAndFootersDistance(Common.Utils.Metric.fnRecalcToMM(field.getNumberValue()), isHeader);
},
onInsertPageNumberClick: function(picker, item, record, e) {
if (this.api)
this.api.put_PageNum(record.get('data').type, record.get('data').subtype);
@ -76,29 +180,33 @@ define([
},
onInsertPageNumberMenuClick: function (item) {
var me = this
if (this.api) {
if (item.value === 'current') {
this.api.put_PageNum(-1);
} else if (item.value === 'format') {
var me = this;
me._docProtectDlg = new DE.Views.PageNumberingDlg({
me._docPageNumberingDlg = new DE.Views.PageNumberingDlg({
props: me.appConfig,
handler: function(result, value, props) {
numbering: this._state.Numbering,
numFormat: this._state.NumFormat,
mode: this.mode,
handler: function(result, from, format) {
if (result == 'ok') {
var protection = me.api.asc_getDocumentProtection() || new AscCommonWord.CDocProtect();
protection.asc_setEditType(props);
protection.asc_setPassword(value);
me.api.asc_setDocumentProtection(protection);
const pageProps = new Asc.SectionPageNumProps();
pageProps.put_Start(from);
pageProps.put_Format(format);
me.api.asc_SetSectionPageNumProps(pageProps);
}
Common.NotificationCenter.trigger('edit:complete');
}
}).on('close', function() {
me._docProtectDlg = undefined;
me._docPageNumberingDlg = undefined;
});
me._docProtectDlg.show();
me._docPageNumberingDlg.show();
}
this.fireEvent('editcomplete', this);
this.fireEvent('editcomplete', this);
}
},
@ -144,13 +252,23 @@ define([
if (api) {
this.api = api;
this.api.asc_registerCallback('asc_onCoAuthoringDisconnect', _.bind(this.onCoAuthoringDisconnect, this));
this.api.asc_registerCallback('asc_onFocusObject', _.bind(this.onApiFocusObject, this));
Common.NotificationCenter.on('api:disconnect', _.bind(this.onCoAuthoringDisconnect, this));
}
return this;
},
onApiFocusObject: function (selected) {
for (var i = 0; i < selected.length; i++) {
if (selected[i].asc_getObjectType() === Asc.c_oAscTypeSelectElement.Header) {
this.ChangeSettings(selected[i].asc_getObjectValue());
};
};
},
setConfig: function(config) {
var mode = config.mode;
this.mode = mode;
this.toolbar = config.toolbar;
this.view = this.createView('HeaderFooterTab', {
toolbar: this.toolbar.toolbar,

View File

@ -107,7 +107,22 @@ define([
});
this.btnInsPageNumber.menu.on('item:click', function (menu, item, e) {
me.fireEvent('headerfooter:inspagenumber', [item]);
})
});
this.numHeaderPosition.on('change', function(field){
me.fireEvent('headerfooter:headerfooterpos', [field, true]);}
);
this.numFooterPosition.on('change', function(field){
me.fireEvent('headerfooter:headerfooterpos', [field, false]);}
);
this.chDiffFirst.on('change', function(field, newValue, oldValue, eOpts){
me.fireEvent('headerfooter:difffirst', [field]);}
);
this.chDiffOddEven.on('change', function(field, newValue, oldValue, eOpts){
me.fireEvent('headerfooter:diffoddeven', [field]);}
);
this.chSameAs.on('change', function(field, newValue, oldValue, eOpts){
me.fireEvent('headerfooter:sameas', [field]);}
);
},
initialize: function (options) {
@ -194,9 +209,10 @@ define([
dataHintDirection: 'bottom',
dataHintOffset: 'big',
});
// this.spinners.push(this.numHeaderPosition);
this.lockedControls.push(this.numHeaderPosition);
this.numHeaderPosition.on('inputleave', function(){ me.fireEvent('editcomplete', me);});
this.numFooterPosition = new Common.UI.MetricSpinner({
step: .1,
width: 85,
@ -208,7 +224,6 @@ define([
dataHintDirection: 'bottom',
dataHintOffset: 'big',
});
// this.spinners.push(this.numFooterPosition);
this.lockedControls.push(this.numFooterPosition);
this.chDiffFirst = new Common.UI.CheckBox({
@ -235,37 +250,11 @@ define([
});
this.lockedControls.push(this.chSameAs);
this._arrNumbers = [
{ displayValue: '1, 2, 3,...', value: Asc.c_oAscNumberingFormat.Decimal },
{ displayValue: '- 1 -, - 2 -, - 3 -,...', value: Asc.c_oAscNumberingFormat.NumberInDash },
{ displayValue: 'a, b, c,...', value: Asc.c_oAscNumberingFormat.LowerLetter },
{ displayValue: 'A, B, C,...', value: Asc.c_oAscNumberingFormat.UpperLetter },
{ displayValue: 'i, ii, iii,...', value: Asc.c_oAscNumberingFormat.LowerRoman },
{ displayValue: 'I, II, III,...', value: Asc.c_oAscNumberingFormat.UpperRoman }
];
if (Common.Locale.getDefaultLanguage() === 'ru') {
this._arrNumbers = this._arrNumbers.concat([
{ displayValue: 'а, б, в,...', value: Asc.c_oAscNumberingFormat.RussianLower },
{ displayValue: 'А, Б, В,...', value: Asc.c_oAscNumberingFormat.RussianUpper }
]);
}
this.loadRecent();
Common.Utils.lockControls(_set.disableOnStart, true, {array: this.lockedControls});
Common.UI.LayoutManager.addControls(this.lockedControls);
Common.NotificationCenter.on('app:ready', this.onAppReady.bind(this));
},
loadRecent: function(){
var sRecents = Common.localStorage.getItem('de-recent-header-formats');
if(sRecents !== ''){
sRecents = JSON.parse(sRecents);
}
if(_.isArray(sRecents)){
this.recentNumTypes = sRecents;
}
},
render: function (el) {
if ( el ) el.html( this.getPanel() );

View File

@ -56,8 +56,12 @@ define([], function () {
}, 'cancel']
}, options);
this.handler = options.handler;
this.recentNumTypes = [];
this.handler = options.handler;
this.props = options.props;
this.numbering = options.numbering;
this.numFormat = options.numFormat;
this.mode = options.mode;
this.template = options.template || [
'<div class="box">',
@ -119,6 +123,23 @@ define([], function () {
ariaLabel: this.textFrom
});
this._arrNumbers = [
{ displayValue: '1, 2, 3,...', value: Asc.c_oAscNumberingFormat.Decimal },
{ displayValue: '- 1 -, - 2 -, - 3 -,...', value: Asc.c_oAscNumberingFormat.NumberInDash },
{ displayValue: 'a, b, c,...', value: Asc.c_oAscNumberingFormat.LowerLetter },
{ displayValue: 'A, B, C,...', value: Asc.c_oAscNumberingFormat.UpperLetter },
{ displayValue: 'i, ii, iii,...', value: Asc.c_oAscNumberingFormat.LowerRoman },
{ displayValue: 'I, II, III,...', value: Asc.c_oAscNumberingFormat.UpperRoman }
];
if (Common.Locale.getDefaultLanguage() === 'ru') {
this._arrNumbers = this._arrNumbers.concat([
{ displayValue: 'а, б, в,...', value: Asc.c_oAscNumberingFormat.RussianLower },
{ displayValue: 'А, Б, В,...', value: Asc.c_oAscNumberingFormat.RussianUpper }
]);
}
this.loadRecent();
this.cmbFormat = new Common.UI.ComboBox({
el : $('#id-headerfooter-combo-format'),
cls: 'input-group-nr',
@ -133,6 +154,16 @@ define([], function () {
dataHintOffset: 'big'
});
if (this.numbering < 0) {
this.rbPrev.setValue(true, true);
} else {
this.rbFrom.setValue(true, true);
this.numFrom.setValue(this.numbering, true);
}
this.fillFormatCombo(this.numFormat);
this.cmbFormat.on('selected', _.bind(this.onFormatSelect, this));
this.btnOk = _.find(this.getFooterButtons(), function (item) {
return (item.$el && item.$el.find('.primary').addBack().filter('.primary').length>0);
}) || new Common.UI.Button({ el: this.$window.find('.primary') });
@ -140,12 +171,85 @@ define([], function () {
this.afterRender();
},
getFocusedComponents: function() {
return [this.rbPrev,].concat(this.getFooterButtons());
loadRecent: function(){
var sRecents = Common.localStorage.getItem('de-recent-header-formats');
if(sRecents !== ''){
sRecents = JSON.parse(sRecents);
}
if(_.isArray(sRecents)){
this.recentNumTypes = sRecents;
}
},
getDefaultFocusableComponent: function () {
return this.inputPwd;
onFormatSelect: function (combo, record) {
if (record.value === -2) {
this.addNewListType();
}
},
addNewListType: function() {
var me = this,
btn,
win = new DE.Views.ListTypesAdvanced({
modal: true,
lang: me.mode.lang,
}).on('close', function(obj){
// (btn!=='ok') && me.cmbFormat.setValue(me._state.NumFormat);
console.log(obj)
});
win.show();
},
fillFormatCombo: function(format) {
if (format !== Asc.c_oAscNumberingFormat.None && format !== undefined && format !== null)
this.checkRecentNum(format);
var store = [].concat(this._arrNumbers),
me = this;
this.recentNumTypes.forEach(function(item) {
if (item!==null && item!==undefined) {
item = parseInt(item);
store.push({ displayValue: AscCommon.IntToNumberFormat(1, item, me.mode.lang) + ', ' + AscCommon.IntToNumberFormat(2, item, me.mode.lang) + ', ' + AscCommon.IntToNumberFormat(3, item, me.mode.lang) + ',...', value: item });
}
});
store.push({ displayValue: 'More types', value: -2 });
this.cmbFormat.setData(store);
this.cmbFormat.setValue(format !== Asc.c_oAscNumberingFormat.None && format !== undefined && format !== null ? format : '');
},
checkRecentNum: function(format){
if (format===null || format===undefined) return;
for(var i = 0; i < this._arrNumbers.length; ++i){
if(this._arrNumbers[i].value === format){
return;
}
}
if(this.recentNumTypes.length === 0){
this.recentNumTypes.push(format);
this.saveRecentNum();
return;
}
for (var i = 0; i < this.recentNumTypes.length; ++i){
if(this.recentNumTypes[i] === format){
this.recentNumTypes.splice(i, 1);
break;
}
}
this.recentNumTypes.splice(0, 0, format);
if(this.recentNumTypes.length > nMaxRecent){
this.recentNumTypes.splice(nMaxRecent, this.recentNumTypes.length - nMaxRecent);
}
this.saveRecentNum();
},
saveRecentNum: function(){
var sJSON = JSON.stringify(this.recentNumTypes);
Common.localStorage.setItem('de-recent-header-formats', sJSON);
},
getFocusedComponents: function() {
return [this.rbPrev,].concat(this.getFooterButtons());
},
afterRender: function() {
@ -162,22 +266,20 @@ define([], function () {
},
_handleInput: function(state) {
var me = this;
if (state === 'ok' && this.btnOk.isDisabled())
return;
if (this.handler) {
if (state === 'ok') {
if (this.inputPwd.checkValidate() !== true) {
this.inputPwd.focus();
return;
}
if (this.inputPwd.getValue() !== this.repeatPwd.getValue()) {
this.repeatPwd.checkValidate();
this.repeatPwd.focus();
return;
if (this.rbPrev.getValue()) {
me.from = -1;
} else {
me.from = this.numFrom.getValue();
}
me.format = this.cmbFormat.getValue();
}
this.handler.call(this, state, this.inputPwd.getValue(), (state == 'ok') ? this.getSettings() : undefined);
this.handler.call(this, state, me.from, me.format);
}
this.close();