/*
*
* (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'
], function () {
'use strict';
!DE.Views.FileMenuPanels && (DE.Views.FileMenuPanels = {});
DE.Views.FileMenuPanels.ViewSaveAs = Common.UI.BaseView.extend({
el: '#panel-saveas',
menu: undefined,
formats: [[
{name: 'DOCX', imgCls: 'docx', type: Asc.c_oAscFileType.DOCX},
{name: 'PDF', imgCls: 'pdf', type: Asc.c_oAscFileType.PDF},
{name: 'ODT', imgCls: 'odt', type: Asc.c_oAscFileType.ODT},
{name: 'TXT', imgCls: 'txt', type: Asc.c_oAscFileType.TXT}
],[
{name: 'DOTX', imgCls: 'dotx', type: Asc.c_oAscFileType.DOTX},
{name: 'PDFA', imgCls: 'pdfa', type: Asc.c_oAscFileType.PDFA},
{name: 'OTT', imgCls: 'ott', type: Asc.c_oAscFileType.OTT},
{name: 'RTF', imgCls: 'rtf', type: Asc.c_oAscFileType.RTF}
],[
{name: 'HTML (Zipped)', imgCls: 'html', type: Asc.c_oAscFileType.HTML}
]],
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 Text Document',
newDescriptionText : 'Create a new blank text document 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'
}, DE.Views.FileMenuPanels.CreateNew || {}));
DE.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.infoObj = {PageCount: 0, WordsCount: 0, ParagraphCount: 0, SymbolsCount: 0, SymbolsWSCount:0};
this.inProgress = false;
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');
// statistic info
this.lblStatPages = $markup.findById('#id-info-pages');
this.lblStatWords = $markup.findById('#id-info-words');
this.lblStatParagraphs = $markup.findById('#id-info-paragraphs');
this.lblStatSymbols = $markup.findById('#id-info-symbols');
this.lblStatSpaces = $markup.findById('#id-info-spaces');
// this.lblEditTime = $markup.find('#id-info-edittime');
// 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);
me.updateScroller(true);
}
});
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);
me.updateScroller();
}
}
});
!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.pnlInfo = $markup.find('.flex-settings').addBack().filter('.flex-settings');
this.pnlApply = $markup.findById('#fms-flex-apply');
this.rendered = true;
this.updateInfo(this.doc);
this.$el = $(node).html($markup);
if (_.isUndefined(this.scroller)) {
this.scroller = new Common.UI.Scroller({
el: this.pnlInfo,
suppressScrollX: true,
alwaysVisibleY: true
});
}
Common.NotificationCenter.on({
'window:resize': function() {
me.isVisible() && me.updateScroller();
}
});
return this;
},
show: function() {
Common.UI.BaseView.prototype.show.call(this,arguments);
this.updateStatisticInfo();
this.updateFileInfo();
this.scroller && this.scroller.scrollTop(0);
this.updateScroller();
},
hide: function() {
Common.UI.BaseView.prototype.hide.call(this,arguments);
this.stopUpdatingStatisticInfo();
},
updateScroller: function(destroy) {
if (this.scroller) {
this.scroller.update(destroy ? {} : undefined);
this.pnlInfo.toggleClass('bordered', this.scroller.isVisible());
}
},
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(Common.Utils.UserInfoParser.getParsedName(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);
},
updateStatisticInfo: function() {
if ( this.api && this.doc ) {
this.api.startGetDocInfo();
}
},
stopUpdatingStatisticInfo: function() {
if ( this.api ) {
this.api.stopGetDocInfo();
}
},
setApi: function(o) {
this.api = o;
this.api.asc_registerCallback('asc_onGetDocInfoStart', _.bind(this._onGetDocInfoStart, this));
this.api.asc_registerCallback('asc_onGetDocInfoStop', _.bind(this._onGetDocInfoEnd, this));
this.api.asc_registerCallback('asc_onDocInfo', _.bind(this._onDocInfo, this));
this.api.asc_registerCallback('asc_onGetDocInfoEnd', _.bind(this._onGetDocInfoEnd, this));
// this.api.asc_registerCallback('asc_onDocumentName', _.bind(this.onDocumentName, this));
this.api.asc_registerCallback('asc_onLockCore', _.bind(this.onLockCore, this));
this.updateInfo(this.doc);
return this;
},
setMode: function(mode) {
this.mode = mode;
this.inputAuthor.setVisible(mode.isEdit);
this.pnlApply.toggleClass('hidden', !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;
},
_onGetDocInfoStart: function() {
var me = this;
this.inProgress = true;
this.infoObj = {PageCount: 0, WordsCount: 0, ParagraphCount: 0, SymbolsCount: 0, SymbolsWSCount:0};
_.defer(function(){
if (!me.inProgress) return;
me.lblStatPages.text(me.txtLoading);
me.lblStatWords.text(me.txtLoading);
me.lblStatParagraphs.text(me.txtLoading);
me.lblStatSymbols.text(me.txtLoading);
me.lblStatSpaces.text(me.txtLoading);
}, 2000);
},
_onDocInfo: function(obj) {
if (obj) {
if (obj.get_PageCount()>-1)
this.infoObj.PageCount = obj.get_PageCount();
if (obj.get_WordsCount()>-1)
this.infoObj.WordsCount = obj.get_WordsCount();
if (obj.get_ParagraphCount()>-1)
this.infoObj.ParagraphCount = obj.get_ParagraphCount();
if (obj.get_SymbolsCount()>-1)
this.infoObj.SymbolsCount = obj.get_SymbolsCount();
if (obj.get_SymbolsWSCount()>-1)
this.infoObj.SymbolsWSCount = obj.get_SymbolsWSCount();
}
},
_onGetDocInfoEnd: function() {
this.inProgress = false;
this.lblStatPages.text(this.infoObj.PageCount);
this.lblStatWords.text(this.infoObj.WordsCount);
this.lblStatParagraphs.text(this.infoObj.ParagraphCount);
this.lblStatSymbols.text(this.infoObj.SymbolsCount);
this.lblStatSpaces.text(this.infoObj.SymbolsWSCount);
},
onDocumentName: function(name) {
// this.lblTitle.text((name) ? name : '-');
},
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',
txtPages: 'Pages',
txtWords: 'Words',
txtParagraphs: 'Paragraphs',
txtSymbols: 'Symbols',
txtSpaces: 'Symbols with spaces',
txtLoading: 'Loading...',
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'
}, DE.Views.FileMenuPanels.DocumentInfo || {}));
DE.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([
'
" : "")+ tipText;
this.cntSignatureView.html(this.templateSignature({tipText: tipText, hasSigned: (hasValid || hasInvalid), hasRequested: hasRequested}));
},
updateEncrypt: function() {
this.cntPasswordView.toggleClass('hidden', this.btnAddPwd.isVisible());
},
strProtect: 'Protect Document',
strSignature: 'With Signature',
txtView: 'View signatures',
txtEdit: 'Edit document',
txtSigned: 'Valid signatures has been added to the document. The document is protected from editing.',
txtSignedInvalid: 'Some of the digital signatures in document are invalid or could not be verified. The document is protected from editing.',
txtRequestedSignatures: 'This document needs to be signed.',
notcriticalErrorTitle: 'Warning',
txtEditWarning: 'Editing will remove the signatures from the document. Are you sure you want to continue?',
strEncrypt: 'With Password',
txtEncrypted: 'This document has been protected by password'
}, DE.Views.FileMenuPanels.ProtectDoc || {}));
});