[Desktop] refactoring

This commit is contained in:
Maxim Kadushkin 2022-12-19 23:48:45 +03:00
parent 57749f4fe1
commit b823c308db

View file

@ -278,157 +278,159 @@ define([
});
}
const _onAppReady = function (opts) {
_.extend(config, opts);
!!native && native.execCommand('doc:onready', '');
$('.toolbar').addClass('editor-native-color');
}
const _onDocumentReady = function () {
if ( config.isEdit ) {
function get_locked_message (t) {
switch (t) {
// case Asc.c_oAscLocalRestrictionType.Nosafe:
case Asc.c_oAscLocalRestrictionType.ReadOnly:
return Common.Locale.get("tipFileReadOnly",{name:"Common.Translation", default: "Document is read only. You can make changes and save its local copy later."});
default: return Common.Locale.get("tipFileLocked",{name:"Common.Translation", default: "Document is locked for editing. You can make changes and save its local copy later."});
}
}
const header = webapp.getController('Viewport').getView('Common.Views.Header');
const api = webapp.getController('Main').api;
const locktype = api.asc_getLocalRestrictions ? api.asc_getLocalRestrictions() : Asc.c_oAscLocalRestrictionType.None;
if ( Asc.c_oAscLocalRestrictionType.None !== locktype ) {
features.readonly = true;
header.setDocumentReadOnly(true);
api.asc_setLocalRestrictions(Asc.c_oAscLocalRestrictionType.None);
(new Common.UI.SynchronizeTip({
extCls: 'no-arrow',
placement: 'bottom',
target: $('.toolbar'),
text: get_locked_message(locktype),
showLink: false,
})).on('closeclick', function () {
this.close();
}).show();
native.execCommand('webapps:features', JSON.stringify(features));
api.asc_registerCallback('asc_onDocumentName', function () {
if ( features.readonly ) {
if ( api.asc_getLocalRestrictions() == Asc.c_oAscLocalRestrictionType.None ) {
features.readonly = false;
header.setDocumentReadOnly(false);
native.execCommand('webapps:features', JSON.stringify(features));
}
}
});
}
_checkHelpAvailable.call(this);
}
}
const _onHidePreloader = function (mode) {
features.viewmode = !mode.isEdit;
features.crypted = mode.isCrypted;
native.execCommand('webapps:features', JSON.stringify(features));
titlebuttons = {};
if ( mode.isEdit ) {
var header = webapp.getController('Viewport').getView('Common.Views.Header');
{
header.btnHome = (new Common.UI.Button({
cls: 'btn-header',
iconCls: 'toolbar__icon icon--inverse btn-home',
visible: false,
hint: 'Show Main window',
dataHint:'0',
dataHintDirection: 'right',
dataHintOffset: '10, -18',
dataHintTitle: 'K'
})).render($('#box-document-title #slot-btn-dt-home'));
titlebuttons['home'] = {btn: header.btnHome};
header.btnHome.on('click', function (e) {
native.execCommand('title:button', JSON.stringify({click: "home"}));
});
$('#id-box-doc-name').on({
'dblclick': function (e) {
native.execCommand('title:dblclick', JSON.stringify({x: e.originalEvent.screenX, y: e.originalEvent.screenY}))
},
'mousedown': function (e) {
native.execCommand('title:mousedown', JSON.stringify({x: e.originalEvent.screenX, y: e.originalEvent.screenY}))
},
'mousemove': function (e) {
native.execCommand('title:mousemove', JSON.stringify({x: e.originalEvent.screenX, y: e.originalEvent.screenY}))
},
'mouseup': function (e) {
native.execCommand('title:mouseup', JSON.stringify({x: e.originalEvent.screenX, y: e.originalEvent.screenY}))
}
});
}
if (!!header.btnSave) {
titlebuttons['save'] = {btn: header.btnSave};
var iconname = /\s?([^\s]+)$/.exec(titlebuttons.save.btn.$icon.attr('class'));
!!iconname && iconname.length && (titlebuttons.save.icon = btnsave_icons[iconname]);
}
if (!!header.btnPrint)
titlebuttons['print'] = {btn: header.btnPrint};
if (!!header.btnPrintQuick) {
titlebuttons['quickprint'] = {
btn: header.btnPrintQuick,
visible: header.btnPrintQuick.isVisible(),
};
}
if (!!header.btnUndo)
titlebuttons['undo'] = {btn: header.btnUndo};
if (!!header.btnRedo)
titlebuttons['redo'] = {btn: header.btnRedo};
for (var i in titlebuttons) {
titlebuttons[i].btn.options.signals = ['disabled'];
titlebuttons[i].btn.on('disabled', _onTitleButtonDisabled.bind(this, i));
}
if (!!titlebuttons.save) {
titlebuttons.save.btn.options.signals.push('icon:changed');
titlebuttons.save.btn.on('icon:changed', _onSaveIconChanged.bind(this));
}
}
if ( !!config.callback_editorconfig ) {
config.callback_editorconfig();
delete config.callback_editorconfig;
}
if ( native.features.singlewindow !== undefined ) {
// $('#box-document-title .hedset')[native.features.singlewindow ? 'hide' : 'show']();
!!titlebuttons.home && titlebuttons.home.btn.setVisible(native.features.singlewindow);
}
}
return {
init: function (opts) {
_.extend(config, opts);
if ( config.isDesktopApp ) {
const me = this;
let is_win_xp = nativevars && nativevars.os === 'winxp';
Common.UI.Themes.setAvailable(!is_win_xp);
Common.NotificationCenter.on('app:ready', function (opts) {
_.extend(config, opts);
!!native && native.execCommand('doc:onready', '');
$('.toolbar').addClass('editor-native-color');
});
Common.NotificationCenter.on('document:ready', function () {
if ( config.isEdit ) {
function get_locked_message (t) {
switch (t) {
// case Asc.c_oAscLocalRestrictionType.Nosafe:
case Asc.c_oAscLocalRestrictionType.ReadOnly:
return Common.Locale.get("tipFileReadOnly",{name:"Common.Translation", default: "Document is read only. You can make changes and save its local copy later."});
default: return Common.Locale.get("tipFileLocked",{name:"Common.Translation", default: "Document is locked for editing. You can make changes and save its local copy later."});
}
}
const header = webapp.getController('Viewport').getView('Common.Views.Header');
const api = webapp.getController('Main').api;
const locktype = api.asc_getLocalRestrictions ? api.asc_getLocalRestrictions() : Asc.c_oAscLocalRestrictionType.None;
if ( Asc.c_oAscLocalRestrictionType.None !== locktype ) {
features.readonly = true;
header.setDocumentReadOnly(true);
api.asc_setLocalRestrictions(Asc.c_oAscLocalRestrictionType.None);
(new Common.UI.SynchronizeTip({
extCls: 'no-arrow',
placement: 'bottom',
target: $('.toolbar'),
text: get_locked_message(locktype),
showLink: false,
})).on('closeclick', function () {
this.close();
}).show();
native.execCommand('webapps:features', JSON.stringify(features));
api.asc_registerCallback('asc_onDocumentName', function () {
if ( features.readonly ) {
if ( api.asc_getLocalRestrictions() == Asc.c_oAscLocalRestrictionType.None ) {
features.readonly = false;
header.setDocumentReadOnly(false);
native.execCommand('webapps:features', JSON.stringify(features));
}
}
});
}
_checkHelpAvailable.call(me);
}
});
Common.NotificationCenter.on('app:face', function (mode) {
features.viewmode = !mode.isEdit;
features.crypted = mode.isCrypted;
native.execCommand('webapps:features', JSON.stringify(features));
titlebuttons = {};
if ( mode.isEdit ) {
var header = webapp.getController('Viewport').getView('Common.Views.Header');
{
header.btnHome = (new Common.UI.Button({
cls: 'btn-header',
iconCls: 'toolbar__icon icon--inverse btn-home',
visible: false,
hint: 'Show Main window',
dataHint:'0',
dataHintDirection: 'right',
dataHintOffset: '10, -18',
dataHintTitle: 'K'
})).render($('#box-document-title #slot-btn-dt-home'));
titlebuttons['home'] = {btn: header.btnHome};
header.btnHome.on('click', function (e) {
native.execCommand('title:button', JSON.stringify({click: "home"}));
});
$('#id-box-doc-name').on({
'dblclick': function (e) {
native.execCommand('title:dblclick', JSON.stringify({x: e.originalEvent.screenX, y: e.originalEvent.screenY}))
},
'mousedown': function (e) {
native.execCommand('title:mousedown', JSON.stringify({x: e.originalEvent.screenX, y: e.originalEvent.screenY}))
},
'mousemove': function (e) {
native.execCommand('title:mousemove', JSON.stringify({x: e.originalEvent.screenX, y: e.originalEvent.screenY}))
},
'mouseup': function (e) {
native.execCommand('title:mouseup', JSON.stringify({x: e.originalEvent.screenX, y: e.originalEvent.screenY}))
}
});
}
if (!!header.btnSave) {
titlebuttons['save'] = {btn: header.btnSave};
var iconname = /\s?([^\s]+)$/.exec(titlebuttons.save.btn.$icon.attr('class'));
!!iconname && iconname.length && (titlebuttons.save.icon = btnsave_icons[iconname]);
}
if (!!header.btnPrint)
titlebuttons['print'] = {btn: header.btnPrint};
if (!!header.btnPrintQuick) {
titlebuttons['quickprint'] = {
btn: header.btnPrintQuick,
visible: header.btnPrintQuick.isVisible(),
};
}
if (!!header.btnUndo)
titlebuttons['undo'] = {btn: header.btnUndo};
if (!!header.btnRedo)
titlebuttons['redo'] = {btn: header.btnRedo};
for (var i in titlebuttons) {
titlebuttons[i].btn.options.signals = ['disabled'];
titlebuttons[i].btn.on('disabled', _onTitleButtonDisabled.bind(this, i));
}
if (!!titlebuttons.save) {
titlebuttons.save.btn.options.signals.push('icon:changed');
titlebuttons.save.btn.on('icon:changed', _onSaveIconChanged.bind(this));
}
}
if ( !!config.callback_editorconfig ) {
config.callback_editorconfig();
delete config.callback_editorconfig;
}
if ( native.features.singlewindow !== undefined ) {
// $('#box-document-title .hedset')[native.features.singlewindow ? 'hide' : 'show']();
!!titlebuttons.home && titlebuttons.home.btn.setVisible(native.features.singlewindow);
}
});
Common.NotificationCenter.on({
'app:ready': _onAppReady,
'document:ready': _onDocumentReady.bind(this),
'app:face': _onHidePreloader.bind(this),
'modal:show': _onModalDialog.bind(this, 'open'),
'modal:close': _onModalDialog.bind(this, 'close'),
'modal:hide': _onModalDialog.bind(this, 'hide'),