/*
*
* (c) Copyright Ascensio System SIA 2010-2019
*
* 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
*
*/
/**
* FileMenuPanels.js
*
* Contains views for menu 'File'
*
* Created by Maxim Kadushkin on 20 February 2014
* Copyright (c) 2018 Ascensio System SIA. All rights reserved.
*
*/
define([
'common/main/lib/view/DocumentAccessDialog',
'common/main/lib/view/AutoCorrectDialog',
'common/main/lib/component/CheckBox'
], function () {
'use strict';
!PE.Views.FileMenuPanels && (PE.Views.FileMenuPanels = {});
PE.Views.FileMenuPanels.ViewSaveAs = Common.UI.BaseView.extend({
el: '#panel-saveas',
menu: undefined,
formats: [[
{name: 'PPTX', imgCls: 'pptx', type: Asc.c_oAscFileType.PPTX},
{name: 'PDF', imgCls: 'pdf', type: Asc.c_oAscFileType.PDF},
{name: 'ODP', imgCls: 'odp', type: Asc.c_oAscFileType.ODP}
],[
{name: 'POTX', imgCls: 'potx', type: Asc.c_oAscFileType.POTX},
{name: 'PDFA', imgCls: 'pdfa', type: Asc.c_oAscFileType.PDFA},
{name: 'OTP', imgCls: 'otp', type: Asc.c_oAscFileType.OTP}
]],
template: _.template([
'
'
].join('')),
initialize: function(options) {
Common.UI.BaseView.prototype.initialize.call(this,arguments);
this.menu = options.menu;
},
render: function() {
this.$el.html(this.template({
scope: this,
docs: this.options[0].docs
}));
if (_.isUndefined(this.scroller)) {
this.scroller = new Common.UI.Scroller({
el: this.$el,
suppressScrollX: true,
alwaysVisibleY: true
});
}
return this;
},
show: function() {
Common.UI.BaseView.prototype.show.call(this,arguments);
this.scroller && this.scroller.update();
},
_onBlankDocument: function() {
if ( this.menu )
this.menu.fireEvent('create:new', [this.menu, 'blank']);
},
_onDocumentTemplate: function(e) {
if ( this.menu )
this.menu.fireEvent('create:new', [this.menu, e.currentTarget.attributes['template'].value]);
},
fromBlankText : 'From Blank',
newDocumentText : 'New Presentation',
newDescriptionText : 'Create a new blank presentation which you will be able to style and format after it is created during the editing. Or choose one of the templates to start a document of a certain type or purpose where some styles have already been pre-applied.',
fromTemplateText : 'From Template',
noTemplatesText : 'There are no templates'
}, PE.Views.FileMenuPanels.CreateNew || {}));
PE.Views.FileMenuPanels.DocumentInfo = Common.UI.BaseView.extend(_.extend({
el: '#panel-info',
menu: undefined,
initialize: function(options) {
Common.UI.BaseView.prototype.initialize.call(this,arguments);
this.rendered = false;
this.template = _.template([
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
// '
',
// '
',
// '
',
// '
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
',
'
'
].join(''));
this.menu = options.menu;
this.coreProps = null;
this.authors = [];
this._locked = false;
},
render: function(node) {
var me = this;
var $markup = $(me.template({scope: me}));
// server info
this.lblPlacement = $markup.findById('#id-info-placement');
this.lblOwner = $markup.findById('#id-info-owner');
this.lblUploaded = $markup.findById('#id-info-uploaded');
// edited info
var keyDownBefore = function(input, e){
if (e.keyCode === Common.UI.Keys.ESC) {
var newVal = input._input.val(),
oldVal = input.getValue();
if (newVal !== oldVal) {
input.setValue(oldVal);
e.stopPropagation();
}
}
};
this.inputTitle = new Common.UI.InputField({
el : $markup.findById('#id-info-title'),
style : 'width: 200px;',
placeHolder : this.txtAddText,
validateOnBlur: false
}).on('keydown:before', keyDownBefore);
this.inputSubject = new Common.UI.InputField({
el : $markup.findById('#id-info-subject'),
style : 'width: 200px;',
placeHolder : this.txtAddText,
validateOnBlur: false
}).on('keydown:before', keyDownBefore);
this.inputComment = new Common.UI.InputField({
el : $markup.findById('#id-info-comment'),
style : 'width: 200px;',
placeHolder : this.txtAddText,
validateOnBlur: false
}).on('keydown:before', keyDownBefore);
// modify info
this.lblModifyDate = $markup.findById('#id-info-modify-date');
this.lblModifyBy = $markup.findById('#id-info-modify-by');
// creation info
this.lblDate = $markup.findById('#id-info-date');
this.lblApplication = $markup.findById('#id-info-appname');
this.tblAuthor = $markup.findById('#id-info-author table');
this.trAuthor = $markup.findById('#id-info-add-author').closest('tr');
this.authorTpl = '
';
this.tblAuthor.on('click', function(e) {
var btn = $markup.find(e.target);
if (btn.hasClass('close') && !btn.hasClass('disabled')) {
var el = btn.closest('tr'),
idx = me.tblAuthor.find('tr').index(el);
el.remove();
me.authors.splice(idx, 1);
}
});
this.inputAuthor = new Common.UI.InputField({
el : $markup.findById('#id-info-add-author'),
style : 'width: 200px;',
validateOnBlur: false,
placeHolder: this.txtAddAuthor
}).on('changed:after', function(input, newValue, oldValue, e) {
if (newValue == oldValue) return;
var val = newValue.trim();
if (!!val && val !== oldValue.trim()) {
var isFromApply = e && e.relatedTarget && (e.relatedTarget.id == 'fminfo-btn-apply');
val.split(/\s*[,;]\s*/).forEach(function(item){
var str = item.trim();
if (str) {
me.authors.push(item);
if (!isFromApply) {
var div = $(Common.Utils.String.format(me.authorTpl, Common.Utils.String.htmlEncode(str)));
me.trAuthor.before(div);
}
}
});
!isFromApply && me.inputAuthor.setValue('');
}
}).on('keydown:before', keyDownBefore);
this.btnApply = new Common.UI.Button({
el: $markup.findById('#fminfo-btn-apply')
});
this.btnApply.on('click', _.bind(this.applySettings, this));
this.rendered = true;
this.updateInfo(this.doc);
this.$el = $(node).html($markup);
if (_.isUndefined(this.scroller)) {
this.scroller = new Common.UI.Scroller({
el: this.$el,
suppressScrollX: true,
alwaysVisibleY: true
});
}
return this;
},
show: function() {
Common.UI.BaseView.prototype.show.call(this,arguments);
this.updateFileInfo();
this.scroller && this.scroller.update();
},
hide: function() {
Common.UI.BaseView.prototype.hide.call(this,arguments);
},
updateInfo: function(doc) {
if (!this.doc && doc && doc.info) {
doc.info.author && console.log("Obsolete: The 'author' parameter of the document 'info' section is deprecated. Please use 'owner' instead.");
doc.info.created && console.log("Obsolete: The 'created' parameter of the document 'info' section is deprecated. Please use 'uploaded' instead.");
}
this.doc = doc;
if (!this.rendered)
return;
var visible = false;
doc = doc || {};
if (doc.info) {
// server info
if (doc.info.folder )
this.lblPlacement.text( doc.info.folder );
visible = this._ShowHideInfoItem(this.lblPlacement, doc.info.folder!==undefined && doc.info.folder!==null) || visible;
var value = doc.info.owner || doc.info.author;
if (value)
this.lblOwner.text(value);
visible = this._ShowHideInfoItem(this.lblOwner, !!value) || visible;
value = doc.info.uploaded || doc.info.created;
if (value)
this.lblUploaded.text(value);
visible = this._ShowHideInfoItem(this.lblUploaded, !!value) || visible;
} else
this._ShowHideDocInfo(false);
$('tr.divider.general', this.el)[visible?'show':'hide']();
var appname = (this.api) ? this.api.asc_getAppProps() : null;
if (appname) {
appname = (appname.asc_getApplication() || '') + ' ' + (appname.asc_getAppVersion() || '');
this.lblApplication.text(appname);
}
this._ShowHideInfoItem(this.lblApplication, !!appname);
this.coreProps = (this.api) ? this.api.asc_getCoreProps() : null;
if (this.coreProps) {
var value = this.coreProps.asc_getCreated();
if (value)
this.lblDate.text(value.toLocaleString(this.mode.lang, {year: 'numeric', month: '2-digit', day: '2-digit'}) + ' ' + value.toLocaleString(this.mode.lang, {timeStyle: 'short'}));
this._ShowHideInfoItem(this.lblDate, !!value);
}
},
updateFileInfo: function() {
if (!this.rendered)
return;
var me = this,
props = (this.api) ? this.api.asc_getCoreProps() : null,
value;
this.coreProps = props;
// var app = (this.api) ? this.api.asc_getAppProps() : null;
// if (app) {
// value = app.asc_getTotalTime();
// if (value)
// this.lblEditTime.text(value + ' ' + this.txtMinutes);
// }
// this._ShowHideInfoItem(this.lblEditTime, !!value);
if (props) {
var visible = false;
value = props.asc_getModified();
if (value)
this.lblModifyDate.text(value.toLocaleString(this.mode.lang, {year: 'numeric', month: '2-digit', day: '2-digit'}) + ' ' + value.toLocaleString(this.mode.lang, {timeStyle: 'short'}));
visible = this._ShowHideInfoItem(this.lblModifyDate, !!value) || visible;
value = props.asc_getLastModifiedBy();
if (value)
this.lblModifyBy.text(value);
visible = this._ShowHideInfoItem(this.lblModifyBy, !!value) || visible;
$('tr.divider.modify', this.el)[visible?'show':'hide']();
value = props.asc_getTitle();
this.inputTitle.setValue(value || '');
value = props.asc_getSubject();
this.inputSubject.setValue(value || '');
value = props.asc_getDescription();
this.inputComment.setValue(value || '');
this.inputAuthor.setValue('');
this.tblAuthor.find('tr:not(:last-of-type)').remove();
this.authors = [];
value = props.asc_getCreator();//"123\"\"\"\<\>,456";
value && value.split(/\s*[,;]\s*/).forEach(function(item) {
var div = $(Common.Utils.String.format(me.authorTpl, Common.Utils.String.htmlEncode(item)));
me.trAuthor.before(div);
me.authors.push(item);
});
this.tblAuthor.find('.close').toggleClass('hidden', !this.mode.isEdit);
!this.mode.isEdit && this._ShowHideInfoItem(this.tblAuthor, !!this.authors.length);
}
this.SetDisabled();
},
_ShowHideInfoItem: function(el, visible) {
el.closest('tr')[visible?'show':'hide']();
return visible;
},
_ShowHideDocInfo: function(visible) {
this._ShowHideInfoItem(this.lblPlacement, visible);
this._ShowHideInfoItem(this.lblOwner, visible);
this._ShowHideInfoItem(this.lblUploaded, visible);
},
setMode: function(mode) {
this.mode = mode;
this.inputAuthor.setVisible(mode.isEdit);
this.btnApply.setVisible(mode.isEdit);
this.tblAuthor.find('.close').toggleClass('hidden', !mode.isEdit);
if (!mode.isEdit) {
this.inputTitle._input.attr('placeholder', '');
this.inputSubject._input.attr('placeholder', '');
this.inputComment._input.attr('placeholder', '');
this.inputAuthor._input.attr('placeholder', '');
}
this.SetDisabled();
return this;
},
setApi: function(o) {
this.api = o;
this.api.asc_registerCallback('asc_onLockCore', _.bind(this.onLockCore, this));
this.updateInfo(this.doc);
return this;
},
onLockCore: function(lock) {
this._locked = lock;
this.updateFileInfo();
},
SetDisabled: function() {
var disable = !this.mode.isEdit || this._locked;
this.inputTitle.setDisabled(disable);
this.inputSubject.setDisabled(disable);
this.inputComment.setDisabled(disable);
this.inputAuthor.setDisabled(disable);
this.tblAuthor.find('.close').toggleClass('disabled', this._locked);
this.tblAuthor.toggleClass('disabled', disable);
this.btnApply.setDisabled(this._locked);
},
applySettings: function() {
if (this.coreProps && this.api) {
this.coreProps.asc_putTitle(this.inputTitle.getValue());
this.coreProps.asc_putSubject(this.inputSubject.getValue());
this.coreProps.asc_putDescription(this.inputComment.getValue());
this.coreProps.asc_putCreator(this.authors.join(';'));
this.api.asc_setCoreProps(this.coreProps);
}
this.menu.hide();
},
txtPlacement: 'Location',
txtOwner: 'Owner',
txtUploaded: 'Uploaded',
txtAppName: 'Application',
txtEditTime: 'Total Editing time',
txtTitle: 'Title',
txtSubject: 'Subject',
txtComment: 'Comment',
txtModifyDate: 'Last Modified',
txtModifyBy: 'Last Modified By',
txtCreated: 'Created',
txtAuthor: 'Author',
txtAddAuthor: 'Add Author',
txtAddText: 'Add Text',
txtMinutes: 'min',
okButtonText: 'Apply'
}, PE.Views.FileMenuPanels.DocumentInfo || {}));
PE.Views.FileMenuPanels.DocumentRights = Common.UI.BaseView.extend(_.extend({
el: '#panel-rights',
menu: undefined,
initialize: function(options) {
Common.UI.BaseView.prototype.initialize.call(this,arguments);
this.rendered = false;
this.template = _.template([
'