/* * * (c) Copyright Ascensio System SIA 2010-2022 * * 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. * * 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 * */ /** * * ExternalLinksDlg.js * * Created by Julia.Radzhabova on 26.07.22 * Copyright (c) 2022 Ascensio System SIA. All rights reserved. * */ define([ 'common/main/lib/view/AdvancedSettingsWindow', 'common/main/lib/component/ListView' ], function () { 'use strict'; SSE.Views = SSE.Views || {}; SSE.Views.ExternalLinksDlg = Common.Views.AdvancedSettingsWindow.extend(_.extend({ options: { alias: 'ExternalLinksDlg', contentWidth: 450, height: 294, buttons: null }, initialize: function (options) { var me = this; _.extend(this.options, { title: this.txtTitle, template: [ '
', '
', '
', '', '', '', '', '', '', '', '
', '', '', // '', // '', '
', '', '', '', '
', '
', '
', '
', '' ].join('') }, options); this.api = options.api; this.handler = options.handler; this.isUpdating = options.isUpdating || false; this.linkStatus = []; this.wrapEvents = { onUpdateExternalReferenceList: _.bind(this.refreshList, this) }; Common.Views.AdvancedSettingsWindow.prototype.initialize.call(this, this.options); }, render: function () { Common.Views.AdvancedSettingsWindow.prototype.render.call(this); var me = this; this.linksList = new Common.UI.ListView({ el: $('#external-links-list', this.$window), store: new Common.UI.DataViewStore(), simpleAddMode: true, itemTemplate: _.template([ '
', '
<%= value %>
', '
<%= status %>
', '
' ].join('')), tabindex: 1 }); this.btnUpdate = new Common.UI.Button({ parentEl: $('#external-links-btn-update', this.$window), cls: 'btn-text-split-default auto', caption: this.textUpdate, split: true, menu : new Common.UI.Menu({ style: 'min-width:100px;', items: [ { caption: this.textUpdate, value: 0 }, { caption: this.textUpdateAll, value: 1 }] }) }); var el = $(this.btnUpdate.cmpEl.find('button')[0]); el.css('min-width', Math.max(87, el.outerWidth()) + 'px'); this.btnUpdate.on('click', _.bind(this.onUpdate, this)); this.btnUpdate.menu.on('item:click', _.bind(this.onUpdateMenu, this)); this.btnDelete = new Common.UI.Button({ parentEl: $('#external-links-btn-delete', this.$window), cls: 'btn-text-split-default auto', caption: this.textDelete, split: true, menu : new Common.UI.Menu({ style: 'min-width:100px;', items: [ { caption: this.textDelete, value: 0 }, { caption: this.textDeleteAll, value: 1 }] }) }); $(this.btnDelete.cmpEl.find('button')[0]).css('min-width', '87px'); this.btnDelete.on('click', _.bind(this.onDelete, this)); this.btnDelete.menu.on('item:click', _.bind(this.onDeleteMenu, this)); this.btnOpen = new Common.UI.Button({ el: $('#external-links-btn-open', this.$window) }); this.btnOpen.on('click', _.bind(this.onOpen, this)); this.btnChange = new Common.UI.Button({ el: $('#external-links-btn-change', this.$window) }); this.btnChange.on('click', _.bind(this.onChange, this)); this.afterRender(); }, afterRender: function() { this._setDefaults(); this.api.asc_registerCallback('asc_onUpdateExternalReferenceList', this.wrapEvents.onUpdateExternalReferenceList); this.isUpdating && this.setIsUpdating(this.isUpdating, true); }, getFocusedComponents: function() { return [ this.btnUpdate, this.btnDelete, this.btnOpen, this.btnChange, this.linksList ]; }, close: function () { this.api.asc_unregisterCallback('asc_onUpdateExternalReferenceList', this.wrapEvents.onUpdateExternalReferenceList); Common.Views.AdvancedSettingsWindow.prototype.close.call(this); }, getDefaultFocusableComponent: function () { return this.linksList; }, _setDefaults: function (props) { this.refreshList(); }, refreshList: function() { var arr = []; var links = this.api.asc_getExternalReferences(); if (links) { for (var i=0; i0) && this.linksList.selectByIndex(0); this.updateButtons(); }, onUpdate: function() { if (this.isUpdating) return; var rec = this.linksList.getSelectedRec(); rec && this.api.asc_updateExternalReferences([rec.get('externalRef')]); }, onUpdateMenu: function(menu, item) { if (this.isUpdating) return; if (item.value == 1) { var arr = []; this.linksList.store.each(function(item){ arr.push(item.get('externalRef')); }, this); (arr.length>0) && this.api.asc_updateExternalReferences(arr); } else this.onUpdate(); }, onDelete: function() { if (this.isUpdating) return; var rec = this.linksList.getSelectedRec(); rec && this.api.asc_removeExternalReferences([rec.get('externalRef')]); this.refreshList(); }, onDeleteMenu: function(menu, item) { if (this.isUpdating) return; if (item.value == 1) { var arr = []; this.linksList.store.each(function(item){ arr.push(item.get('externalRef')); }, this); (arr.length>0) && this.api.asc_removeExternalReferences(arr); this.refreshList(); } else this.onDelete(); }, onOpen: function() { }, onChange: function() { }, updateButtons: function() { var selected = this.linksList.store.length>0 && !!this.linksList.getSelectedRec(); this.btnUpdate.setDisabled(!selected || this.isUpdating); this.btnDelete.setDisabled(!selected || this.isUpdating); this.btnOpen.setDisabled(!selected || this.isUpdating); this.btnChange.setDisabled(!selected || this.isUpdating); }, setIsUpdating: function(status, immediately) { console.log(status); immediately = immediately || !status; // set timeout when start updating only this.isUpdating = status; if (!status && this.timerId) { clearTimeout(this.timerId); this.timerId = 0; } if (immediately) { this.updateButtons(); this.btnUpdate.setCaption(status ? this.textUpdating : this.textUpdate); } else if (!this.timerId) { var me = this; me.timerId = setTimeout(function () { me.updateButtons(); me.btnUpdate.setCaption(status ? me.textUpdating : me.textUpdate); },500); } !status && this.refreshList(); }, setLinkStatus: function(id, result) { if (!id) return; this.linkStatus[id] = result || this.textOk; }, txtTitle: 'External Links', textUpdate: 'Update Values', textUpdateAll: 'Update All', textSource: 'Source', closeButtonText: 'Close', textDelete: 'Break Links', textDeleteAll: 'Break All Links', textOpen: 'Open Source', textChange: 'Change Source', textStatus: 'Status', textOk: 'OK', textUnknown: 'Unknown', textUpdating: 'Updating...' }, SSE.Views.ExternalLinksDlg || {})); });