web-apps/apps/documenteditor/main/app/view/Statusbar.js

407 lines
16 KiB
JavaScript
Raw Normal View History

2016-04-01 13:17:09 +00:00
/*
*
* (c) Copyright Ascensio System SIA 2010-2019
2016-04-01 13:17:09 +00:00
*
* 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.
2016-04-01 13:17:09 +00:00
*
* 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
*
*/
2016-03-11 00:48:53 +00:00
/**
* StatusBar View
*
* Created by Maxim Kadushkin
2018-03-01 12:16:38 +00:00
* Copyright (c) 2018 Ascensio System SIA. All rights reserved.
2016-03-11 00:48:53 +00:00
*
*/
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'
],
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, state) {
2017-03-29 09:01:34 +00:00
var $parent = menu.$el.parent();
2016-03-11 00:48:53 +00:00
$parent.find('#status-label-lang').text(item.caption);
2019-01-28 13:51:07 +00:00
this.langMenu.prevTip = item.value.value;
2016-03-11 00:48:53 +00:00
this.fireEvent('langchanged', [this, item.value.code, item.caption]);
}
function _onAppReady(config) {
var me = this;
me.btnZoomToPage.updateHint(me.tipFitPage);
me.btnZoomToWidth.updateHint(me.tipFitWidth);
me.btnZoomDown.updateHint(me.tipZoomOut + Common.Utils.String.platformKey('Ctrl+-'));
me.btnZoomUp.updateHint(me.tipZoomIn + Common.Utils.String.platformKey('Ctrl++'));
2017-12-05 12:08:17 +00:00
if (me.btnLanguage && me.btnLanguage.cmpEl) {
me.btnLanguage.updateHint(me.tipSetLang);
me.btnLanguage.cmpEl.on({
'show.bs.dropdown': function () {
_.defer(function () {
me.btnLanguage.cmpEl.find('ul').focus();
}, 100);
},
'hide.bs.dropdown': function () {
_.defer(function () {
me.api.asc_enableKeyEvents(true);
}, 100);
},
'click': function (e) {
if (me.btnLanguage.isDisabled()) {
return false;
}
}
2017-12-05 12:08:17 +00:00
});
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]);
});
}
2016-03-11 00:48:53 +00:00
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 = {};
var me = this;
this.$layout = $(this.template({
2017-03-29 11:03:12 +00:00
textGotoPage: this.goToPageText,
textPageNumber: Common.Utils.String.format(this.pageIndexText, 1, 1)
2016-03-11 00:48:53 +00:00
}));
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'
});
2016-03-11 00:48:53 +00:00
this.btnZoomDown = new Common.UI.Button({
hintAnchor: 'top'
});
this.btnZoomUp = new Common.UI.Button({
hintAnchor: 'top-right'
});
this.btnLanguage = new Common.UI.Button({
// el: panelLang,
hintAnchor: 'top-left',
disabled: true
2016-03-11 00:48:53 +00:00
});
this.langMenu = new Common.UI.Menu({
2019-01-28 13:51:07 +00:00
cls: 'lang-menu',
2016-03-11 00:48:53 +00:00
style: 'margin-top:-5px;',
2019-01-28 13:51:07 +00:00
restoreHeight: 300,
2016-03-11 00:48:53 +00:00
itemTemplate: _.template([
'<a id="<%= id %>" tabindex="-1" type="menuitem" style="padding-left: 28px !important;" langval="<%= options.value.value %>">',
'<i class="icon <% if (options.spellcheck) { %> img-toolbarmenu spellcheck-lang <% } %>"></i>',
'<%= caption %>',
2016-03-11 00:48:53 +00:00
'</a>'
].join('')),
2019-07-11 11:35:24 +00:00
menuAlign: 'bl-tl',
search: true
2016-03-11 00:48:53 +00:00
});
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.txtGoToPage = new Common.UI.InputField({
allowBlank : true,
validateOnChange: true,
style : 'width: 60px;',
maskExp: /[0-9]/,
validation : function(value) {
if (/(^[0-9]+$)/.test(value)) {
value = parseInt(value);
if (undefined !== value && value > 0 && value <= me.pages.get('count'))
return true;
}
return me.txtPageNumInvalid;
}
});
2016-03-11 00:48:53 +00:00
var promise = new Promise(function (accept, reject) {
accept();
});
2016-03-11 00:48:53 +00:00
Common.NotificationCenter.on('app:ready', function(mode) {
promise.then( _onAppReady.bind(this, mode) );
}.bind(this));
},
2016-03-11 00:48:53 +00:00
2017-04-10 13:39:03 +00:00
render: function(config) {
var me = this;
2016-03-11 00:48:53 +00:00
function _btn_render(button, slot) {
2017-04-12 12:59:21 +00:00
button.setElement(slot, false);
button.render();
}
2016-03-11 00:48:53 +00:00
this.fireEvent('render:before', [this.$layout]);
_btn_render(me.btnZoomToPage, $('#btn-zoom-topage', me.$layout));
_btn_render(me.btnZoomToWidth, $('#btn-zoom-towidth', me.$layout));
_btn_render(me.cntZoom, $('.cnt-zoom',me.$layout));
_btn_render(me.btnZoomDown, $('#btn-zoom-down', me.$layout));
_btn_render(me.btnZoomUp, $('#btn-zoom-up', me.$layout));
_btn_render(me.txtGoToPage, $('#status-goto-page', me.$layout));
2017-04-10 13:39:03 +00:00
if ( !config || config.isEdit ) {
var panelLang = $('.cnt-lang', me.$layout);
_btn_render(me.btnLanguage, panelLang);
2017-04-10 13:39:03 +00:00
me.langMenu.render(panelLang);
me.langMenu.cmpEl.attr({tabindex: -1});
me.langMenu.prevTip = 'en';
}
2017-04-10 13:39:03 +00:00
me.zoomMenu.render($('.cnt-zoom',me.$layout));
me.zoomMenu.cmpEl.attr({tabindex: -1});
this.$el.html(me.$layout);
this.fireEvent('render:after', [this]);
2016-03-11 00:48:53 +00:00
return this;
},
setApi: function(api) {
this.api = api;
if (this.api) {
this.api.asc_registerCallback('asc_onCountPages', _.bind(_onCountPages, this));
this.api.asc_registerCallback('asc_onCurrentPage', _.bind(_onCurrentPage, this));
Common.NotificationCenter.on('api:disconnect', _.bind(this.onApiCoAuthoringDisconnect, this));
2016-03-11 00:48:53 +00:00
}
return this;
},
setMode: function(mode) {
this.mode = mode;
},
setVisible: function(visible) {
visible
? this.show()
: this.hide();
},
reloadLanguages: function(array) {
this.langMenu.removeAll();
2016-03-11 00:48:53 +00:00
_.each(array, function(item) {
this.langMenu.addItem({
2019-01-28 13:51:07 +00:00
caption : item['displayValue'],
value : {value: item['value'], code: item['code']},
2016-03-11 00:48:53 +00:00
checkable : true,
2019-01-28 13:51:07 +00:00
checked : this.langMenu.saved == item['displayValue'],
spellcheck : item['spellcheck'],
2016-03-11 00:48:53 +00:00
toggleGroup : 'language'
});
}, this);
if (this.langMenu.items.length>0) {
this.btnLanguage.setDisabled(!!this.mode.isDisconnected);
}
2016-03-11 00:48:53 +00:00
},
setLanguage: function(info) {
2019-01-28 13:51:07 +00:00
if (this.langMenu.prevTip != info.value && info.code !== undefined) {
2016-03-11 00:48:53 +00:00
var $parent = $(this.langMenu.el.parentNode, this.$el);
2019-01-28 13:51:07 +00:00
$parent.find('#status-label-lang').text(info.displayValue);
2016-03-11 00:48:53 +00:00
2019-01-28 13:51:07 +00:00
this.langMenu.prevTip = info.value;
2016-03-11 00:48:53 +00:00
2019-01-28 13:51:07 +00:00
var index = $parent.find('ul li a:contains("'+info.displayValue+'")').parent().index();
2017-11-13 09:14:34 +00:00
if (index < 0) {
2019-01-28 13:51:07 +00:00
this.langMenu.saved = info.displayValue;
2017-11-13 09:14:34 +00:00
this.langMenu.clearAll();
} else
2019-01-28 13:51:07 +00:00
this.langMenu.items[index].setChecked(true);
2016-03-11 00:48:53 +00:00
}
},
showStatusMessage: function(message) {
$('.statusbar #label-action').text(message);
},
clearStatusMessage: function() {
$('.statusbar #label-action').text('');
},
SetDisabled: function(disable) {
var langs = this.langMenu.items.length>0;
this.btnLanguage.setDisabled(disable || !langs);
2016-03-11 00:48:53 +00:00
},
onApiCoAuthoringDisconnect: function() {
this.setMode({isDisconnected:true});
this.SetDisabled(true);
},
2016-03-11 00:48:53 +00:00
pageIndexText : 'Page {0} of {1}',
goToPageText : 'Go to Page',
2016-09-26 12:07:51 +00:00
tipFitPage : 'Fit to Page',
tipFitWidth : 'Fit to Width',
2016-03-11 00:48:53 +00:00
tipZoomIn : 'Zoom In',
tipZoomOut : 'Zoom Out',
tipZoomFactor : 'Magnification',
tipSetLang : 'Set Text Language',
txtPageNumInvalid : 'Page number invalid',
textTrackChanges : 'Track Changes',
textChangesPanel : 'Changes panel'
2016-03-11 00:48:53 +00:00
}, DE.Views.Statusbar || {}));
}
);