/* * * (c) Copyright Ascensio System SIA 2010-2019 * * 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 * */ /** * StatusBar View * * Created by Maxim Kadushkin on 27 March 2014 * Copyright (c) 2018 Ascensio System SIA. All rights reserved. * */ define([ 'text!spreadsheeteditor/main/app/template/StatusBar.template', 'tip', 'common/main/lib/component/TabBar', 'common/main/lib/component/Menu', 'common/main/lib/component/Window', 'common/main/lib/component/ThemeColorPalette' ], function(template){ 'use strict'; if (SSE.Views.Statusbar) { var RenameDialog = SSE.Views.Statusbar.RenameDialog; var CopyDialog = SSE.Views.Statusbar.CopyDialog; } SSE.Views.Statusbar = Common.UI.BaseView.extend(_.extend({ el: '#statusbar', template: _.template(template), events: function() { return { 'click #status-btn-tabfirst': _.bind(this.onBtnTabScroll, this, 'first'), 'click #status-btn-tabback': _.bind(this.onBtnTabScroll, this, 'backward'), 'click #status-btn-tabnext': _.bind(this.onBtnTabScroll, this, 'forward'), 'click #status-btn-tablast': _.bind(this.onBtnTabScroll, this, 'last') }; }, api: undefined, initialize: function (options) { _.extend(this, options); }, render: function () { var me = this; $(this.el).html(this.template({ scope: this })); this.editMode = false; this.rangeSelectionMode = Asc.c_oAscSelectionDialogType.None; this.btnZoomDown = new Common.UI.Button({ el: $('#status-btn-zoomdown',this.el), hint: this.tipZoomOut+' (Ctrl+-)', hintAnchor: 'top' }); this.btnZoomUp = new Common.UI.Button({ el: $('#status-btn-zoomup',this.el), hint: this.tipZoomIn+' (Ctrl++)', hintAnchor: 'top-right' }); this.btnScrollFirst = new Common.UI.Button({ el: $('#status-btn-tabfirst',this.el), hint: this.tipFirst, disabled: true, hintAnchor: 'top' }); this.btnScrollBack = new Common.UI.Button({ el: $('#status-btn-tabback',this.el), hint: this.tipPrev, disabled: true, hintAnchor: 'top' }); this.btnScrollNext = new Common.UI.Button({ el: $('#status-btn-tabnext',this.el), hint: this.tipNext, disabled: true, hintAnchor: 'top' }); this.btnScrollLast = new Common.UI.Button({ el: $('#status-btn-tablast',this.el), hint: this.tipLast, disabled: true, hintAnchor: 'top' }); this.btnAddWorksheet = new Common.UI.Button({ el: $('#status-btn-addtab',this.el), hint: this.tipAddTab, disabled: true, hintAnchor: 'top' }); this.cntZoom = new Common.UI.Button({ el: $('.cnt-zoom',this.el), hint: this.tipZoomFactor, hintAnchor: 'top' }); this.cntZoom.cmpEl.on({ 'show.bs.dropdown': function () { _.defer(function(){ me.cntZoom.cmpEl.find('ul').focus(); }, 100); }, 'hide.bs.dropdown': function () { _.defer(function(){ me.api.asc_enableKeyEvents(true); }, 100); } }); this.zoomMenu = new Common.UI.Menu({ style: 'margin-top:-5px;', menuAlign: 'bl-tl', items: [ { caption: "50%", value: 50 }, { caption: "75%", value: 75 }, { caption: "100%", value: 100 }, { caption: "125%", value: 125 }, { caption: "150%", value: 150 }, { caption: "175%", value: 175 }, { caption: "200%", value: 200 } ] }); this.zoomMenu.render($('.cnt-zoom',this.el)); this.zoomMenu.cmpEl.attr({tabindex: -1}); this.labelZoom = $('#status-label-zoom',this.$el); this.tabBarBox = $('#status-sheets-bar-box', this.el); this.tabbar = new Common.UI.TabBar({ el: '#status-sheets-bar', placement: 'bottom', draggable: false }).render(); this.tabbar.on({ 'tab:invisible' : _.bind(this.onTabInvisible, this), 'tab:changed' : _.bind(this.onSheetChanged, this), //'tab:manual' : _.bind(this.onAddTabClick, this), 'tab:contextmenu' : _.bind(this.onTabMenu, this), 'tab:dblclick' : _.bind(function () { if (me.editMode && (me.rangeSelectionMode !== Asc.c_oAscSelectionDialogType.Chart) && (me.rangeSelectionMode !== Asc.c_oAscSelectionDialogType.FormatTable)&& (me.rangeSelectionMode !== Asc.c_oAscSelectionDialogType.PrintTitles)) { me.fireEvent('sheet:changename'); } }, this), 'tab:move' : _.bind(function (selectTabs, index) { me.tabBarScroll = {scrollLeft: me.tabbar.scrollX}; if (_.isUndefined(selectTabs) || _.isUndefined(index) || (selectTabs && selectTabs.length === 1 && selectTabs[0] === index)) { return; } if (_.isArray(selectTabs)) { me.fireEvent('sheet:move', [selectTabs, false, true, undefined, index]); } else { var tabIndex = selectTabs; if (tabIndex < index) { ++index; } me.fireEvent('sheet:move', [undefined, false, true, tabIndex, index]); } }, this), 'tab:dragstart': _.bind(function (dataTransfer, selectTabs) { this.api.asc_closeCellEditor(); var arrTabs = [], arrName = [], me = this; var wc = me.api.asc_getWorksheetsCount(), items = [], i = -1; while (++i < wc) { if (!this.api.asc_isWorksheetHidden(i)) { items.push({ value: me.api.asc_getWorksheetName(i), inindex: i }); } } var arrSelectIndex = []; selectTabs.forEach(function (item) { arrSelectIndex.push(item.sheetindex); }); items.forEach(function (item) { if (arrSelectIndex.indexOf(item.inindex) !== -1) { arrTabs.push(item.inindex); arrName.push(item.value); } }); var stringSheet, arr = []; stringSheet = this.api.asc_StartMoveSheet(_.clone(arrTabs)); arr.push({type: 'onlyoffice', value: stringSheet}); arr.push({type: 'indexes', value: arrTabs}); arr.push({type: 'names', value: arrName}); arr.push({type: 'key', value: Common.Utils.InternalSettings.get("sse-doc-info-key")}); var json = JSON.stringify(arr); dataTransfer.setData("onlyoffice", json); this.dropTabs = selectTabs; }, this), 'tab:drop': _.bind(function (dataTransfer, index) { var data = dataTransfer.getData("onlyoffice"); if (data) { var arrData = JSON.parse(data); if (arrData) { var key = _.findWhere(arrData, {type: 'key'}).value; if (Common.Utils.InternalSettings.get("sse-doc-info-key") === key) { this.api.asc_moveWorksheet(index, _.findWhere(arrData, {type: 'indexes'}).value); Common.NotificationCenter.trigger('tabs:dragend', this); } else { var names = [], wc = this.api.asc_getWorksheetsCount(); while (wc--) { names.push(this.api.asc_getWorksheetName(wc).toLowerCase()); } var newNames = []; var arrNames = _.findWhere(arrData, {type: 'names'}).value; arrNames.forEach(function (name) { var ind = 0, name = name; var first = name; if (names.indexOf(name.toLowerCase()) !== -1) { while (true) { if (names.indexOf(name.toLowerCase()) === -1) { newNames.push(name); break; } else { ind++; name = first + '(' + ind + ')'; } } } else { newNames.push(name); } }); this.api.asc_EndMoveSheet(index, newNames, _.findWhere(arrData, {type: 'onlyoffice'}).value); } } } }, this), 'tab:dragend': _.bind(function (cut) { if (cut) { if (this.dropTabs.length > 0) { var arr = []; this.dropTabs.forEach(function (tab) { arr.push(tab.sheetindex); }); me.api.asc_deleteWorksheet(arr); } } this.dropTabs = undefined; Common.NotificationCenter.trigger('tabs:dragend', this); }, this) }); var menuHiddenItems = new Common.UI.Menu({ maxHeight: 260, menuAlign: 'tl-tr' }).on('show:after', function () { this.scroller.update({alwaysVisibleY: true}); }); menuHiddenItems.on('item:click', function(obj,item,e) { me.fireEvent('show:hidden', [me, item.value]); }); var menuColorItems = new Common.UI.Menu({ menuAlign: 'tl-tr', cls: 'color-tab', items: [ { template: _.template('
') }, { template: _.template('' + me.textNewColor + '') } ] }); function dummyCmp() { return { isDummy : true, on : function() {} } } me.mnuTabColor = dummyCmp(); this.tabMenu = new Common.UI.Menu({ menuAlign: 'bl-tl', items: [ {caption: this.itemInsert, value: 'ins'}, {caption: this.itemDelete, value: 'del'}, {caption: this.itemRename, value: 'ren'}, {caption: this.itemCopy, value: 'copy'}, {caption: this.itemMove, value: 'move'}, {caption: this.itemHide, value: 'hide'}, { caption: this.itemHidden, menu: menuHiddenItems }, { caption: this.itemTabColor, menu: menuColorItems }, { caption: '--' }, {caption: this.selectAllSheets, value: 'selectall'}, {caption: this.ungroupSheets, value: 'noselect'} ] }).on('render:after', function(btn) { var colorVal = $('
'); $('button:first-child', btn.cmpEl).append(colorVal); colorVal.css('background-color', btn.currentColor || 'transparent'); me.mnuTabColor = new Common.UI.ThemeColorPalette({ el: $('#id-tab-menu-color'), transparent: true }); me.mnuTabColor.on('select', function(picker, color) { me.fireEvent('sheet:setcolor', [color]); }); }); this.tabbar.$el.append('