149 lines
5 KiB
JavaScript
149 lines
5 KiB
JavaScript
|
/**
|
||
|
* Statusbar.js
|
||
|
*
|
||
|
* Statusbar controller
|
||
|
*
|
||
|
* Created by Maxim Kadushkin on 8 April 2014
|
||
|
* Copyright (c) 2014 Ascensio System SIA. All rights reserved.
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
define([
|
||
|
'core',
|
||
|
'presentationeditor/main/app/view/Statusbar'
|
||
|
], function () {
|
||
|
'use strict';
|
||
|
|
||
|
PE.Controllers.Statusbar = Backbone.Controller.extend(_.extend({
|
||
|
models: [],
|
||
|
collections: [],
|
||
|
views: [
|
||
|
'Statusbar'
|
||
|
],
|
||
|
|
||
|
initialize: function() {
|
||
|
this.addListeners({
|
||
|
'Statusbar': {
|
||
|
}
|
||
|
});
|
||
|
this._state = {
|
||
|
zoom_type: undefined,
|
||
|
zoom_percent: undefined
|
||
|
};
|
||
|
},
|
||
|
|
||
|
events: function() {
|
||
|
return {
|
||
|
'click #btn-zoom-down': _.bind(this.zoomDocument,this,'down'),
|
||
|
'click #btn-zoom-up': _.bind(this.zoomDocument,this,'up')
|
||
|
};
|
||
|
},
|
||
|
|
||
|
onLaunch: function() {
|
||
|
this.statusbar = this.createView('Statusbar', {
|
||
|
storeUsers: this.getApplication().getCollection('Common.Collections.Users')
|
||
|
}).render();
|
||
|
this.statusbar.$el.css('z-index', 1);
|
||
|
|
||
|
this.bindViewEvents(this.statusbar, this.events);
|
||
|
|
||
|
$('#status-label-zoom').css('min-width', 70);
|
||
|
|
||
|
this.statusbar.btnZoomToPage.on('click', _.bind(this.onBtnZoomTo, this, 'topage'));
|
||
|
this.statusbar.btnZoomToWidth.on('click', _.bind(this.onBtnZoomTo, this, 'towidth'));
|
||
|
this.statusbar.zoomMenu.on('item:click', _.bind(this.menuZoomClick, this));
|
||
|
this.statusbar.btnPreview.on('click', _.bind(this.onPreview, this));
|
||
|
},
|
||
|
|
||
|
setApi: function(api) {
|
||
|
this.api = api;
|
||
|
this.api.asc_registerCallback('asc_onZoomChange', _.bind(this._onZoomChange, this));
|
||
|
|
||
|
this.statusbar.setApi(api);
|
||
|
},
|
||
|
|
||
|
onBtnZoomTo: function(d, b, e) {
|
||
|
this._state.zoom_type = undefined;
|
||
|
this._state.zoom_percent = undefined;
|
||
|
if (!b.pressed)
|
||
|
this.api.zoomCustomMode(); else
|
||
|
this.api[d=='topage'?'zoomFitToPage':'zoomFitToWidth']();
|
||
|
Common.NotificationCenter.trigger('edit:complete', this.statusbar);
|
||
|
},
|
||
|
|
||
|
zoomDocument: function(d, e) {
|
||
|
this._state.zoom_type = undefined;
|
||
|
this._state.zoom_percent = undefined;
|
||
|
switch (d) {
|
||
|
case 'up': this.api.zoomIn(); break;
|
||
|
case 'down': this.api.zoomOut(); break;
|
||
|
}
|
||
|
Common.NotificationCenter.trigger('edit:complete', this.statusbar);
|
||
|
},
|
||
|
|
||
|
menuZoomClick: function(menu, item) {
|
||
|
this._state.zoom_type = undefined;
|
||
|
this._state.zoom_percent = undefined;
|
||
|
this.api.zoom(item.value);
|
||
|
Common.NotificationCenter.trigger('edit:complete', this.statusbar);
|
||
|
},
|
||
|
|
||
|
onPreview: function(btn, e) {
|
||
|
var previewPanel = PE.getController('Viewport').getView('DocumentPreview');
|
||
|
if (previewPanel) {
|
||
|
previewPanel.show();
|
||
|
if (!this.statusbar.mode.isDesktopApp)
|
||
|
this.fullScreen(document.documentElement);
|
||
|
|
||
|
if (this.api) {
|
||
|
var current = this.api.getCurrentPage();
|
||
|
this.api.StartDemonstration('presentation-preview', _.isNumber(current) ? current : 0);
|
||
|
|
||
|
Common.component.Analytics.trackEvent('Status Bar', 'Preview');
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
|
||
|
fullScreen: function(element) {
|
||
|
if (element) {
|
||
|
if(element.requestFullscreen) {
|
||
|
element.requestFullscreen();
|
||
|
} else if(element.webkitRequestFullscreen) {
|
||
|
element.webkitRequestFullscreen();
|
||
|
} else if(element.mozRequestFullScreen) {
|
||
|
element.mozRequestFullScreen();
|
||
|
} else if(element.msRequestFullscreen) {
|
||
|
element.msRequestFullscreen();
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
|
||
|
/*
|
||
|
* api events
|
||
|
* */
|
||
|
|
||
|
_onZoomChange: function(percent, type) {
|
||
|
if (this._state.zoom_type !== type) {
|
||
|
this.statusbar.btnZoomToPage.toggle(type == 2, true);
|
||
|
this.statusbar.btnZoomToWidth.toggle(type == 1, true);
|
||
|
this._state.zoom_type = type;
|
||
|
}
|
||
|
if (this._state.zoom_percent !== percent) {
|
||
|
$('#status-label-zoom').text(Common.Utils.String.format(this.zoomText, percent));
|
||
|
this._state.zoom_percent = percent;
|
||
|
}
|
||
|
},
|
||
|
|
||
|
setStatusCaption: function(text) {
|
||
|
if (text.length)
|
||
|
this.statusbar.showStatusMessage(text); else
|
||
|
this.statusbar.clearStatusMessage();
|
||
|
},
|
||
|
|
||
|
createDelayedElements: function() {
|
||
|
this.statusbar.$el.css('z-index', '');
|
||
|
},
|
||
|
|
||
|
zoomText : 'Zoom {0}%'
|
||
|
}, PE.Controllers.Statusbar || {}));
|
||
|
});
|