web-apps/apps/common/main/lib/view/ExternalOleEditor.js

213 lines
8.7 KiB
JavaScript
Raw Normal View History

2022-03-10 16:21:29 +00:00
/*
*
* (c) Copyright Ascensio System SIA 2010-2022
*
* 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.
*
* 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
*
*/
/**
* ExternalOleEditor.js
*
* Created by Julia Radzhabova on 3/10/22
* Copyright (c) 2022 Ascensio System SIA. All rights reserved.
*
*/
define([
'common/main/lib/component/Window'
], function () { 'use strict';
Common.Views.ExternalOleEditor = Common.UI.Window.extend(_.extend({
initialize : function(options) {
2022-06-22 11:06:46 +00:00
var filter = Common.localStorage.getKeysFilter();
this.appPrefix = (filter && filter.length) ? filter.split(',')[0] : '';
2022-06-22 11:26:24 +00:00
var _options = {}, width = 900, height = 700;
2022-06-22 11:06:46 +00:00
var value = Common.localStorage.getItem(this.appPrefix + 'ole-editor-width');
value && (width = parseInt(value));
value = Common.localStorage.getItem(this.appPrefix + 'ole-editor-height');
value && (height = parseInt(value));
2022-03-10 16:21:29 +00:00
var _inner_height = Common.Utils.innerHeight() - Common.Utils.InternalSettings.get('window-inactive-area-top');
_.extend(_options, {
title: this.textTitle,
2022-06-22 11:06:46 +00:00
width: width,
height: (_inner_height - height)<0 ? _inner_height : height,
2022-06-22 11:26:24 +00:00
minwidth: 840,
2022-04-04 18:10:04 +00:00
minheight: 275,
2022-03-10 16:21:29 +00:00
cls: 'advanced-settings-dlg',
header: true,
toolclose: 'hide',
2022-04-01 13:12:20 +00:00
toolcallback: _.bind(this.onToolClose, this),
resizable: true
2022-03-10 16:21:29 +00:00
}, options);
2022-04-04 18:10:04 +00:00
this._headerFooterHeight = 85;
2022-03-10 16:21:29 +00:00
this.template = [
2022-04-04 18:10:04 +00:00
'<div id="id-ole-editor-container" class="box" style="height:' + (_options.height-this._headerFooterHeight) + 'px; padding: 0 5px;">',
2022-03-10 16:21:29 +00:00
'<div id="id-ole-editor-placeholder" style="width: 100%;height: 100%;"></div>',
'</div>',
'<div class="separator horizontal"></div>',
'<div class="footer" style="text-align: center;">',
'<button id="id-btn-ole-editor-apply" class="btn normal dlg-btn primary custom" result="ok" data-hint="1" data-hint-direction="bottom" data-hint-offset="big">' + this.textSave + '</button>',
'<button id="id-btn-ole-editor-cancel" class="btn normal dlg-btn" result="cancel" data-hint="1" data-hint-direction="bottom" data-hint-offset="big">' + this.textClose + '</button>',
'</div>'
].join('');
_options.tpl = _.template(this.template)(_options);
this.handler = _options.handler;
this._oleData = null;
this._isNewOle = true;
2022-06-22 11:06:46 +00:00
this.on('resize', _.bind(this.onWindowResize, this));
2022-03-10 16:21:29 +00:00
Common.UI.Window.prototype.initialize.call(this, _options);
},
render: function() {
Common.UI.Window.prototype.render.call(this);
2022-04-01 14:48:31 +00:00
this.boxEl = this.$window.find('.body > .box');
2022-03-10 16:21:29 +00:00
this.btnSave = new Common.UI.Button({
el: $('#id-btn-ole-editor-apply'),
disabled: true
});
this.btnCancel = new Common.UI.Button({
el: $('#id-btn-ole-editor-cancel')
});
this.$window.find('.dlg-btn').on('click', _.bind(this.onDlgBtnClick, this));
},
show: function() {
this.setPlaceholder();
Common.UI.Window.prototype.show.apply(this, arguments);
},
setOleData: function(data) {
this._oleData = data;
if (this._isExternalDocReady)
this.fireEvent('setoledata', this);
},
setEditMode: function(mode) {
this._isNewOle = !mode;
},
isEditMode: function() {
return !this._isNewOle;
},
setControlsDisabled: function(disable) {
this.btnSave.setDisabled(disable);
this.btnCancel.setDisabled(disable);
(disable) ? this.$window.find('.tool.close').addClass('disabled') : this.$window.find('.tool.close').removeClass('disabled');
},
onDlgBtnClick: function(event) {
if ( this.handler ) {
this.handler.call(this, event.currentTarget.attributes['result'].value);
return;
}
this.hide();
},
onToolClose: function() {
if ( this.handler ) {
this.handler.call(this, 'cancel');
return;
}
this.hide();
},
setHeight: function(height) {
if (height >= 0) {
var min = parseInt(this.$window.css('min-height'));
height < min && (height = min);
this.$window.height(height);
var header_height = (this.initConfig.header) ? parseInt(this.$window.find('> .header').css('height')) : 0;
this.$window.find('> .body').css('height', height-header_height);
2022-04-04 18:10:04 +00:00
this.$window.find('> .body > .box').css('height', height-this._headerFooterHeight);
2022-04-01 13:12:20 +00:00
}
},
2022-03-10 16:21:29 +00:00
2022-04-01 13:12:20 +00:00
setInCenter: function() {
var height = this.$window.height(),
top = (Common.Utils.innerHeight() - Common.Utils.InternalSettings.get('window-inactive-area-top') - parseInt(height)) / 2,
left = (Common.Utils.innerWidth() - parseInt(this.initConfig.width)) / 2;
2022-03-10 16:21:29 +00:00
2022-04-01 13:12:20 +00:00
this.$window.css('left',left);
this.$window.css('top', Common.Utils.InternalSettings.get('window-inactive-area-top') + top);
2022-03-10 16:21:29 +00:00
},
2022-04-01 14:48:31 +00:00
setInnerSize: function(width, height) {
var maxHeight = Common.Utils.innerHeight(),
maxWidth = Common.Utils.innerWidth(),
borders_width = (parseInt(this.$window.css('border-left-width')) + parseInt(this.$window.css('border-right-width'))),
2022-04-04 18:10:04 +00:00
paddings = (parseInt(this.boxEl.css('padding-left')) + parseInt(this.boxEl.css('padding-right')));
2022-04-01 14:48:31 +00:00
height += 90; // add toolbar and statusbar height
2022-04-04 18:10:04 +00:00
if (maxHeight<height + this._headerFooterHeight)
height = maxHeight - this._headerFooterHeight;
if (maxWidth<width + paddings + borders_width)
width = maxWidth - paddings - borders_width;
2022-04-01 14:48:31 +00:00
this.boxEl.css('height', height);
this.setHeight(height + this._headerFooterHeight);
2022-04-04 18:10:04 +00:00
this.setWidth(width + paddings + borders_width);
2022-04-01 14:48:31 +00:00
2022-04-04 18:10:04 +00:00
if (this.getLeft()<0)
this.$window.css('left', 0);
if (this.getTop() < Common.Utils.InternalSettings.get('window-inactive-area-top') )
this.$window.css('top', Common.Utils.InternalSettings.get('window-inactive-area-top'));
2022-03-10 16:21:29 +00:00
},
setPlaceholder: function(placeholder) {
this._placeholder = placeholder;
},
getPlaceholder: function() {
return this._placeholder;
},
2022-06-22 11:06:46 +00:00
onWindowResize: function (args) {
if (args && args[1]=='end') {
var value = this.getSize();
Common.localStorage.setItem(this.appPrefix + 'ole-editor-width', value[0]);
Common.localStorage.setItem(this.appPrefix + 'ole-editor-height', value[1]);
}
},
2022-03-10 16:21:29 +00:00
textSave: 'Save & Exit',
textClose: 'Close',
textTitle: 'Spreadsheet Editor'
}, Common.Views.ExternalOleEditor || {}));
});