/*
* (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
*
*/
define([
'text!documenteditor/main/app/template/StatusBar.template',
'jquery',
'underscore',
'backbone',
'tip',
'common/main/lib/component/Menu',
'common/main/lib/component/Window',
'documenteditor/main/app/model/Pages',
'common/main/lib/component/InputField',
],
function(template, $, _, Backbone){
'use strict';
function _onCountPages(count){
this.pages.set('count', count);
}
function _onCurrentPage(number){
this.pages.set('current', number+1);
}
var _tplPages = _.template('Page <%= current %> of <%= count %>');
function _updatePagesCaption(model,value,opts) {
$('.statusbar #label-pages',this.$el).text(
Common.Utils.String.format(this.pageIndexText, model.get('current'), model.get('count')) );
}
function _clickLanguage(menu, item) {
this.langMenu.prevTip = item.value;
this.btnLanguage.setCaption(item.caption);
this.fireEvent('langchanged', [this, item.code, item.caption]);
}
function _onAppReady(config) {
var me = this;
me.btnZoomToPage.updateHint(me.tipFitPage);
me.btnZoomToWidth.updateHint(me.tipFitWidth);
DE.getController('Common.Controllers.Shortcuts').updateShortcutHints({
ZoomOut: {
btn: me.btnZoomDown,
label: me.tipZoomOut
},
ZoomIn: {
btn: me.btnZoomUp,
label: me.tipZoomIn
}
});
if (config.canUseSelectHandTools) {
me.btnSelectTool.updateHint(me.tipSelectTool);
me.btnHandTool.updateHint(me.tipHandTool);
}
if (me.btnLanguage && me.btnLanguage.cmpEl) {
me.btnLanguage.updateHint(me.tipSetLang);
me.langMenu.on('item:click', _.bind(_clickLanguage, this));
}
me.cntZoom.updateHint(me.tipZoomFactor);
me.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);
}
});
me.txtGoToPage.on({
'keypress:after': function (input, e) {
if (e.keyCode === Common.UI.Keys.RETURN) {
var box = me.$el.find('#status-goto-box'),
edit = box.find('input[type=text]'), page = parseInt(edit.val());
if (!page || page-- > me.pages.get('count') || page < 0) {
edit.select();
return false;
}
box.focus(); // for IE
box.parent().removeClass('open');
me.api.goToPage(page);
me.api.asc_enableKeyEvents(true);
return false;
}
},
'keyup:after': function (input, e) {
if (e.keyCode === Common.UI.Keys.ESC) {
var box = me.$el.find('#status-goto-box');
box.focus(); // for IE
box.parent().removeClass('open');
me.api.asc_enableKeyEvents(true);
return false;
}
}
});
var goto = me.$el.find('#status-goto-box');
goto.on('click', function() {
return false;
});
goto.parent().on({
'show.bs.dropdown': function () {
me.txtGoToPage.setValue(me.api.getCurrentPage() + 1);
me.txtGoToPage.checkValidate();
var edit = me.txtGoToPage.$el.find('input');
_.defer(function(){
edit.focus().select();
}, 100);
},
'hide.bs.dropdown': function () {
var box = me.$el.find('#status-goto-box');
if (me.api && box) {
box.focus(); // for IE
box.parent().removeClass('open');
me.api.asc_enableKeyEvents(true);
}
}
});
me.zoomMenu.on('item:click', function(menu, item) {
me.fireEvent('zoom:value', [item.value]);
});
me.btnDocInfo.menu.on('show:after', _.bind(this.onDocInfoShow, this));
me.onChangeProtectDocument();
}
DE.Views.Statusbar = Backbone.View.extend(_.extend({
el: '#statusbar',
template: _.template(template),
events: {
},
api: undefined,
pages: undefined,
initialize: function (options) {
_.extend(this, options);
this.pages = new DE.Models.Pages({current:1, count:1});
this.pages.on('change', _.bind(_updatePagesCaption,this));
this._state = {
docProtection: {
isReadOnly: false,
isReviewOnly: false,
isFormsOnly: false,
isCommentsOnly: false
}
};
this._isDisabled = false;
var me = this;
this.$layout = $(this.template({
textGotoPage: this.goToPageText,
textPageNumber: Common.Utils.String.format(this.pageIndexText, 1, 1)
}));
this.btnSelectTool = new Common.UI.Button({
hintAnchor: 'top',
toggleGroup: 'select-tools',
enableToggle: true,
allowDepress: false
});
this.btnHandTool = new Common.UI.Button({
hintAnchor: 'top',
toggleGroup: 'select-tools',
enableToggle: true,
allowDepress: false
});
this.btnZoomToPage = new Common.UI.Button({
hintAnchor: 'top',
toggleGroup: 'status-zoom',
enableToggle: true
});
this.btnZoomToWidth = new Common.UI.Button({
hintAnchor: 'top',
toggleGroup: 'status-zoom',
enableToggle: true
});
this.cntZoom = new Common.UI.Button({
hintAnchor: 'top'
});
this.btnZoomDown = new Common.UI.Button({
hintAnchor: 'top'
});
this.btnZoomUp = new Common.UI.Button({
hintAnchor: 'top-right'
});
this.btnLanguage = new Common.UI.Button({
cls : 'btn-toolbar',
scaling : false,
caption : 'English – United States',
hintAnchor : 'top-left',
disabled: true,
dataHint : '0',
dataHintDirection: 'top',
menu: true
});
this.langMenu = new Common.UI.MenuSimple({
cls: 'lang-menu shifted-right',
style: 'margin-top:-5px;',
restoreHeight: 285,
itemTemplate: _.template([
'',
'