/* * (c) Copyright Ascensio System SIA 2010-2024 * * 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-6 Ernesta Birznieka-Upish * street, Riga, Latvia, EU, LV-1050. * * 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 * */ /** * HeaderFooterTab.js * * Created on 10.21.2025 * */ define([ 'core', 'documenteditor/main/app/view/HeaderFooterTab' ], function () { 'use strict'; DE.Controllers.HeaderFooterTab = Backbone.Controller.extend(_.extend({ models : [], collections : [ ], views : [ 'HeaderFooterTab' ], sdkViewName : '#id_main', initialize: function () { this.spinners = []; this._state = { HeaderPosition: 12.5, FooterPosition: 12.5, DiffFirst: false, DiffOdd: false, SameAs: false, Numbering: undefined }; this.addListeners({ 'HeaderFooterTab': { '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), 'headerfooter:close': _.bind(this.onTabClose, this), 'headerfooter:editremove': _.bind(this.onHeaderFooterEditRemove, this), 'headerfooter:insdatetime': _.bind(this.onInsDateTimeClick, this), 'headerfooter:insfield': _.bind(this.onInsFieldClick, this, 'add'), 'headerfooter:insimage': _.bind(this.onInsertImageClick, this) }, 'DocumentHolder': { 'field:edit': this.onInsFieldClick.bind(this, 'edit') }, }); }, onInsertImageClick: function(menu, item, e) { var me = this; if (item.value === 'file') { this.view.fireEvent('insertimage'); if (this.api) setTimeout(function() {me.api.asc_addImage();}, 1); Common.NotificationCenter.trigger('edit:complete', me.view); // Common.component.Analytics.trackEvent('ToolBar', 'Image'); } else if (item.value === 'url') { (new Common.Views.ImageFromUrlDialog({ handler: function(result, value) { if (result == 'ok') { if (me.api) { var checkUrl = value.replace(/ /g, ''); if (!_.isEmpty(checkUrl)) { me.view.fireEvent('insertimage'); me.api.AddImageUrl([checkUrl]); // Common.component.Analytics.trackEvent('ToolBar', 'Image'); } } Common.NotificationCenter.trigger('edit:complete', me.toolbar); } } })).show(); } else if (item.value === 'storage') { Common.NotificationCenter.trigger('storage:image-load', 'add'); } }, onInsFieldClick: function(type) { var me = this; (new Common.Views.TextInputDialog({ width: 450, title: me.textFieldTitle, label: me.textFieldLabel, description: me.textFieldExample, value: type==='edit' ? me.api.asc_GetComplexFieldInstruction() : '', handler: function(result, value) { if (result == 'ok') { if (me.api) { type==='edit' ? me.api.asc_EditComplexFieldInstruction(value) : me.api.asc_AddComplexFieldWithInstruction(value); } } Common.NotificationCenter.trigger('edit:complete', me.toolbar); } })).show(); }, onInsDateTimeClick: function () { var me = this; (new DE.Views.DateTimeDialog({ api: this.api, lang: this._state.lang, handler: function(result, value) { if (result == 'ok') { if (me.api) { me.api.asc_addDateTime(value); } } Common.NotificationCenter.trigger('edit:complete', me.toolbar); } })).show(); }, onHeaderFooterEditRemove: function (item) { if (this.api) { switch (item.value) { case 'edit-header': this.api.GoToHeader(this.api.getCurrentPage()); break; case 'edit-footer': this.api.GoToFooter(this.api.getCurrentPage()); break; case 'remove-header': this.api.asc_RemoveHeader(this.api.getCurrentPage()); break; case 'remove-footer': this.api.asc_RemoveFooter(this.api.getCurrentPage()); break; } Common.NotificationCenter.trigger('edit:complete', this.toolbar); } }, onTabClose: function () { if (this.api) { this.api.asc_CancelHdrFtrEditing(); } }, 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) { var me = this; this.createDelayedElements(); if (prop) { var value = prop.get_HeaderMargin(); if ( Math.abs(this._state.HeaderPosition-value)>0.001 ) { this.view.numHeaderPosition.setValue(Common.Utils.Metric.fnRecalcFromMM(value), true); this._state.HeaderPosition = value; } value = prop.get_FooterMargin(); if ( Math.abs(this._state.FooterPosition-value)>0.001 ) { this.view.numFooterPosition.setValue(Common.Utils.Metric.fnRecalcFromMM(value), true); this._state.FooterPosition = 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.setValue(value==true, true); this._state.SameAs=value; } value = prop.get_StartPageNumber(); if ( this._state.Numbering!==value && value !== null) { this._state.Numbering=value; } value = prop.get_NumFormat(); if ( this._state.NumFormat!==value) { this._state.NumFormat = value; } Common.Utils.lockControls(Common.enumLock.linkToPrevious, this._state.SameAs===null, {array: [this.view.chSameAs]}) } }, createDelayedElements: function() { if (this.spinners.length === 0) { this.spinners.push(this.view.numHeaderPosition); this.spinners.push(this.view.numFooterPosition); } this.updateMetricUnit(); }, updateMetricUnit: function() { if (this.spinners) { for (var i=0; i