[PE] refactoring

This commit is contained in:
Maxim Kadushkin 2017-04-20 15:13:11 +03:00
parent 77e62ed696
commit b761758c9e

View file

@ -56,6 +56,7 @@ define([
], function () { 'use strict'; ], function () { 'use strict';
PE.Controllers.Main = Backbone.Controller.extend(_.extend((function() { PE.Controllers.Main = Backbone.Controller.extend(_.extend((function() {
var appHeader;
var ApplyEditRights = -255; var ApplyEditRights = -255;
var LoadingDocument = -256; var LoadingDocument = -256;
@ -255,10 +256,8 @@ define([
this.appOptions.canPlugins = false; this.appOptions.canPlugins = false;
this.plugins = this.editorConfig.plugins; this.plugins = this.editorConfig.plugins;
this.getApplication() appHeader = this.getApplication().getController('Viewport').getView('Common.Views.Header');
.getController('Viewport') appHeader.setCanBack(this.appOptions.canBackToFolder === true);
.getView('Common.Views.Header')
.setCanBack(this.appOptions.canBackToFolder === true);
if (this.editorConfig.lang) if (this.editorConfig.lang)
this.api.asc_setLocale(this.editorConfig.lang); this.api.asc_setLocale(this.editorConfig.lang);
@ -298,10 +297,7 @@ define([
this.api.asc_getEditorPermissions(this.editorConfig.licenseUrl, this.editorConfig.customerId); this.api.asc_getEditorPermissions(this.editorConfig.licenseUrl, this.editorConfig.customerId);
if (data.doc) { if (data.doc) {
this.getApplication() appHeader.setDocumentCaption(data.doc.title);
.getController('Viewport')
.getView('Common.Views.Header')
.setDocumentCaption(data.doc.title);
} }
}, },
@ -387,11 +383,7 @@ define([
var action = {id: id, type: type}; var action = {id: id, type: type};
this.stackLongActions.pop(action); this.stackLongActions.pop(action);
this.getApplication() appHeader.setDocumentCaption(this.api.asc_getDocumentName());
.getController('Viewport')
.getView('Common.Views.Header')
.setDocumentCaption(this.api.asc_getDocumentName());
this.updateWindowTitle(true); this.updateWindowTitle(true);
action = this.stackLongActions.get({type: Asc.c_oAscAsyncActionType.Information}); action = this.stackLongActions.get({type: Asc.c_oAscAsyncActionType.Information});
@ -400,12 +392,12 @@ define([
} else { } else {
if (id==Asc.c_oAscAsyncAction['Save'] || id==Asc.c_oAscAsyncAction['ForceSaveButton']) { if (id==Asc.c_oAscAsyncAction['Save'] || id==Asc.c_oAscAsyncAction['ForceSaveButton']) {
if (this._state.fastCoauth && this._state.usersCount>1) { if (this._state.fastCoauth && this._state.usersCount>1) {
var me = this; clearTimeout(this._state.timerSave);
me._state.timerSave = setTimeout(function () { this._state.timerSave = setTimeout(function () {
me.getApplication().getController('Statusbar').setStatusCaption(me.textChangesSaved, false, 3000); appHeader.setSaveStatus('end');
}, 500); }, 500);
} else } else
this.getApplication().getController('Statusbar').setStatusCaption(this.textChangesSaved, false, 3000); appHeader.setSaveStatus('end');
} else } else
this.getApplication().getController('Statusbar').setStatusCaption(''); this.getApplication().getController('Statusbar').setStatusCaption('');
} }
@ -564,11 +556,7 @@ define([
me.api.asc_registerCallback('asc_onCoAuthoringDisconnect', _.bind(me.onCoAuthoringDisconnect, me)); me.api.asc_registerCallback('asc_onCoAuthoringDisconnect', _.bind(me.onCoAuthoringDisconnect, me));
me.api.asc_registerCallback('asc_onPrint', _.bind(me.onPrint, me)); me.api.asc_registerCallback('asc_onPrint', _.bind(me.onPrint, me));
var application = me.getApplication(); appHeader.setDocumentCaption( me.api.asc_getDocumentName() );
application.getController('Viewport')
.getView('Common.Views.Header')
.setDocumentCaption(me.api.asc_getDocumentName());
me.updateWindowTitle(true); me.updateWindowTitle(true);
value = Common.localStorage.getItem("pe-settings-inputmode"); value = Common.localStorage.getItem("pe-settings-inputmode");
@ -754,12 +742,11 @@ define([
this._state.licenseWarning = (licType===Asc.c_oLicenseResult.Connections) && this.appOptions.canEdit && this.editorConfig.mode !== 'view'; this._state.licenseWarning = (licType===Asc.c_oLicenseResult.Connections) && this.appOptions.canEdit && this.editorConfig.mode !== 'view';
var headerView = this.getApplication().getController('Viewport').getView('Common.Views.Header');
this.appOptions.canBranding = (licType === Asc.c_oLicenseResult.Success) && (typeof this.editorConfig.customization == 'object'); this.appOptions.canBranding = (licType === Asc.c_oLicenseResult.Success) && (typeof this.editorConfig.customization == 'object');
if (this.appOptions.canBranding) if (this.appOptions.canBranding)
headerView.setBranding(this.editorConfig.customization); appHeader.setBranding(this.editorConfig.customization);
this.appOptions.canRename && headerView.setCanRename(true); this.appOptions.canRename && appHeader.setCanRename(true);
this.appOptions.canBrandingExt = params.asc_getCanBranding() && (typeof this.editorConfig.customization == 'object' || this.editorConfig.plugins); this.appOptions.canBrandingExt = params.asc_getCanBranding() && (typeof this.editorConfig.customization == 'object' || this.editorConfig.plugins);
if (this.appOptions.canBrandingExt) if (this.appOptions.canBrandingExt)
@ -786,14 +773,11 @@ define([
var app = this.getApplication(), var app = this.getApplication(),
viewport = app.getController('Viewport').getView('Viewport'), viewport = app.getController('Viewport').getView('Viewport'),
headerView = app.getController('Viewport').getView('Common.Views.Header'),
statusbarView = app.getController('Statusbar').getView('Statusbar'), statusbarView = app.getController('Statusbar').getView('Statusbar'),
documentHolder = app.getController('DocumentHolder').getView('DocumentHolder'); documentHolder = app.getController('DocumentHolder').getView('DocumentHolder');
if (headerView) { appHeader.setHeaderCaption(this.appOptions.isEdit ? 'Presentation Editor' : 'Presentation Viewer');
headerView.setHeaderCaption(this.appOptions.isEdit ? 'Presentation Editor' : 'Presentation Viewer'); appHeader.setVisible(!this.appOptions.nativeApp && !value && !this.appOptions.isDesktopApp);
headerView.setVisible(!this.appOptions.nativeApp && !value && !this.appOptions.isDesktopApp);
}
viewport && viewport.setMode(this.appOptions, true); viewport && viewport.setMode(this.appOptions, true);
statusbarView && statusbarView.setMode(this.appOptions); statusbarView && statusbarView.setMode(this.appOptions);
@ -1067,7 +1051,7 @@ define([
onCoAuthoringDisconnect: function() { onCoAuthoringDisconnect: function() {
// TODO: Disable all except 'Download As' and 'Print' // TODO: Disable all except 'Download As' and 'Print'
this.getApplication().getController('Viewport').getView('Viewport').setMode({isDisconnected:true}); this.getApplication().getController('Viewport').getView('Viewport').setMode({isDisconnected:true});
this.getApplication().getController('Viewport').getView('Common.Views.Header').setCanRename(false); appHeader.setCanRename(false);
this.appOptions.canRename = false; this.appOptions.canRename = false;
this._state.isDisconnected = true; this._state.isDisconnected = true;
// this.getFileMenu().setMode({isDisconnected:true}); // this.getFileMenu().setMode({isDisconnected:true});
@ -1113,29 +1097,16 @@ define([
if (this._state.isDocModified !== isModified || force) { if (this._state.isDocModified !== isModified || force) {
var title = this.defaultTitleText; var title = this.defaultTitleText;
var headerView = this.getApplication() if (!_.isEmpty(appHeader.getDocumentCaption()))
.getController('Viewport') title = appHeader.getDocumentCaption() + ' - ' + title;
.getView('Common.Views.Header');
if (!_.isEmpty(headerView.getDocumentCaption()))
title = headerView.getDocumentCaption() + ' - ' + title;
if (isModified) { if (isModified) {
clearTimeout(this._state.timerCaption);
if (!_.isUndefined(title)) { if (!_.isUndefined(title)) {
title = '* ' + title; title = '* ' + title;
headerView.setDocumentCaption(headerView.getDocumentCaption(), true);
} }
} else {
if (this._state.fastCoauth && this._state.usersCount>1) {
this._state.timerCaption = setTimeout(function () {
headerView.setDocumentCaption(headerView.getDocumentCaption(), false);
}, 500);
} else
headerView.setDocumentCaption(headerView.getDocumentCaption(), false);
} }
if (window.document.title != title) if ( window.document.title != title )
window.document.title = title; window.document.title = title;
Common.Gateway.setDocumentModified(isModified); Common.Gateway.setDocumentModified(isModified);
@ -1527,14 +1498,14 @@ define([
}, },
onDocumentName: function(name) { onDocumentName: function(name) {
this.getApplication().getController('Viewport').getView('Common.Views.Header').setDocumentCaption(name); appHeader.setDocumentCaption(name);
this.updateWindowTitle(true); this.updateWindowTitle(true);
}, },
onMeta: function(meta) { onMeta: function(meta) {
var app = this.getApplication(), var app = this.getApplication(),
filemenu = app.getController('LeftMenu').getView('LeftMenu').getMenu('file'); filemenu = app.getController('LeftMenu').getView('LeftMenu').getMenu('file');
app.getController('Viewport').getView('Common.Views.Header').setDocumentCaption(meta.title); appHeader.setDocumentCaption(meta.title);
this.updateWindowTitle(true); this.updateWindowTitle(true);
this.document.title = meta.title; this.document.title = meta.title;
filemenu.loadDocument({doc:this.document}); filemenu.loadDocument({doc:this.document});