Added "Close File" button to the password dialog. Send api event "onRequestClose" when Close File (or Esc) is selected.

This commit is contained in:
Julia Radzhabova 2018-02-06 13:54:40 +03:00
parent 1703a115e1
commit 11a3706785
16 changed files with 91 additions and 42 deletions

View file

@ -189,6 +189,7 @@
_config.editorConfig.canHistoryRestore = _config.events && !!_config.events.onRequestRestore;
_config.editorConfig.canSendEmailAddresses = _config.events && !!_config.events.onRequestEmailAddresses;
_config.editorConfig.canRequestEditRights = _config.events && !!_config.events.onRequestEditRights;
_config.editorConfig.canRequestClose = _config.events && !!_config.events.onRequestClose;
_config.frameEditorId = placeholderId;
_config.events && !!_config.events.onReady && console.log("Obsolete: The onReady event is deprecated. Please use onAppReady instead.");

View file

@ -250,6 +250,10 @@ if (Common === undefined) {
_postMessage({ event: 'onDocumentReady' });
},
requestClose: function() {
_postMessage({event: 'onRequestClose'});
},
on: function(event, handler){
var localHandler = function(event, data){
handler.call(me, data)

View file

@ -191,7 +191,10 @@ define([
event.preventDefault();
event.stopPropagation();
if (this.initConfig.closable !== false) {
this.initConfig.toolclose=='hide' ? this.hide() : this.close();
if (this.initConfig.toolcallback)
this.initConfig.toolcallback.call(this);
else
(this.initConfig.toolclose=='hide') ? this.hide() : this.close();
}
return false;
}

View file

@ -54,14 +54,15 @@ define([
_options = {};
_.extend(_options, {
closable: false,
closable : false,
width : 250,
height : (options.type == Asc.c_oAscAdvancedOptionsID.CSV) ? 205 : 155,
contentWidth : 390,
header : true,
cls : 'open-dlg',
contentTemplate : '',
title : (options.type == Asc.c_oAscAdvancedOptionsID.DRM) ? t.txtTitleProtected : t.txtTitle.replace('%1', (options.type == Asc.c_oAscAdvancedOptionsID.CSV) ? 'CSV' : 'TXT')
title : (options.type == Asc.c_oAscAdvancedOptionsID.DRM) ? t.txtTitleProtected : t.txtTitle.replace('%1', (options.type == Asc.c_oAscAdvancedOptionsID.CSV) ? 'CSV' : 'TXT'),
toolcallback : _.bind(t.onToolClose, t)
}, options);
@ -84,18 +85,21 @@ define([
'<% } %>',
'</div>',
'</div>',
'<div class="separator horizontal"/>',
'<div class="footer center">',
'<button class="btn normal dlg-btn primary" result="ok" style="margin-right:10px;">' + t.okButtonText + '</button>',
'<% if (closable) { %>',
'<button class="btn normal dlg-btn" result="cancel">' + t.closeButtonText + '</button>',
'<% } %>',
'</div>'
].join('');
this.handler = options.handler;
this.type = options.type;
this.codepages = options.codepages;
this.settings = options.settings;
this.validatePwd = options.validatePwd || false;
this.handler = _options.handler;
this.type = _options.type;
this.closable = _options.closable;
this.codepages = _options.codepages;
this.settings = _options.settings;
this.validatePwd = _options.validatePwd || false;
_options.tpl = _.template(this.template)(_options);
@ -106,7 +110,8 @@ define([
if (this.$window) {
var me = this;
this.$window.find('.tool').hide();
if (!this.closable)
this.$window.find('.tool').hide();
this.$window.find('.dlg-btn').on('click', _.bind(this.onBtnClick, this));
if (this.type == Asc.c_oAscAdvancedOptionsID.DRM) {
this.inputPwd = new Common.UI.InputField({
@ -120,11 +125,11 @@ define([
this.$window.find('input').on('keypress', _.bind(this.onKeyPress, this));
} else {
this.initCodePages();
this.onPrimary = function() {
me.onBtnClick();
return false;
};
}
this.onPrimary = function() {
me._handleInput('ok');
return false;
};
}
},
@ -141,25 +146,36 @@ define([
}
},
onBtnClick: function (event) {
onKeyPress: function(event) {
if (event.keyCode == Common.UI.Keys.RETURN) {
this._handleInput('ok');
} else if (this.closable && event.keyCode == Common.UI.Keys.ESC)
this._handleInput('cancel');
},
onBtnClick: function(event) {
this._handleInput(event.currentTarget.attributes['result'].value);
},
onToolClose: function() {
this._handleInput('cancel');
},
_handleInput: function(state) {
if (this.handler) {
if (this.cmbEncoding) {
var delimiter = this.cmbDelimiter ? this.cmbDelimiter.getValue() : null,
delimiterChar = (delimiter == -1) ? this.inputDelimiter.getValue() : null;
(delimiter == -1) && (delimiter = null);
this.handler.call(this, this.cmbEncoding.getValue(), delimiter, delimiterChar);
} else
this.handler.call(this, this.inputPwd.getValue());
} else {
this.handler.call(this, state, this.inputPwd.getValue());
}
}
this.close();
},
onKeyPress: function(event) {
if (event.keyCode == Common.UI.Keys.RETURN)
this.onBtnClick();
},
initCodePages: function () {
var i, c, codepage, encodedata = [], listItems = [], length = 0;
@ -381,7 +397,8 @@ define([
txtPassword : "Password",
txtTitleProtected : "Protected File",
txtOther: 'Other',
txtIncorrectPwd: 'Password is incorrect.'
txtIncorrectPwd: 'Password is incorrect.',
closeButtonText: 'Close File'
}, Common.Views.OpenDialog || {}));
});

View file

@ -610,6 +610,8 @@ define([
},
onShortcut: function(s, e) {
if (!this.mode) return;
switch (s) {
case 'replace':
case 'search':

View file

@ -1065,6 +1065,7 @@ define([
this.appOptions.isOffline = this.api.asc_isOffline();
this.appOptions.isReviewOnly = this.permissions.review === true && this.permissions.edit === false;
this.appOptions.canRequestEditRights = this.editorConfig.canRequestEditRights;
this.appOptions.canRequestClose = this.editorConfig.canRequestClose;
this.appOptions.canEdit = (this.permissions.edit !== false || this.permissions.review === true) && // can edit or review
(this.editorConfig.canRequestEditRights || this.editorConfig.mode !== 'view') && // if mode=="view" -> canRequestEditRights must be defined
(!this.appOptions.isReviewOnly || this.appOptions.canLicense); // if isReviewOnly==true -> canLicense must be true
@ -1861,14 +1862,18 @@ define([
});
} else if (type == Asc.c_oAscAdvancedOptionsID.DRM) {
me._state.openDlg = new Common.Views.OpenDialog({
closable: me.appOptions.canRequestClose,
type: type,
validatePwd: !!me._state.isDRM,
handler: function (value) {
handler: function (result, value) {
me.isShowOpenDialog = false;
if (me && me.api) {
me.api.asc_setAdvancedOptions(type, new Asc.asc_CDRMAdvancedOptions(value));
me.loadMask && me.loadMask.show();
}
if (result == 'ok') {
if (me.api) {
me.api.asc_setAdvancedOptions(type, new Asc.asc_CDRMAdvancedOptions(value));
me.loadMask && me.loadMask.show();
}
} else
Common.Gateway.requestClose();
me._state.openDlg = null;
}
});

View file

@ -221,7 +221,7 @@ define([
},
show: function(panel, opts) {
if (this.isVisible() && panel===undefined) return;
if (this.isVisible() && panel===undefined || !this.mode) return;
var defPanel = (this.mode.canDownload && (!this.mode.isDesktopApp || !this.mode.isOffline)) ? 'saveas' : 'info';
if (!panel)

View file

@ -183,6 +183,7 @@
"Common.Views.OpenDialog.txtPassword": "Password",
"Common.Views.OpenDialog.txtTitle": "Choose %1 options",
"Common.Views.OpenDialog.txtTitleProtected": "Protected File",
"Common.Views.OpenDialog.closeButtonText": "Close File",
"Common.Views.PasswordDialog.cancelButtonText": "Cancel",
"Common.Views.PasswordDialog.okButtonText": "OK",
"Common.Views.PasswordDialog.txtDescription": "A password is required to open this document",

View file

@ -463,6 +463,8 @@ define([
},
onShortcut: function(s, e) {
if (!this.mode) return;
var previewPanel = PE.getController('Viewport').getView('DocumentPreview');
switch (s) {

View file

@ -831,6 +831,7 @@ define([
this.appOptions.canCoAuthoring = !this.appOptions.isLightVersion;
/** coauthoring end **/
this.appOptions.canRequestEditRights = this.editorConfig.canRequestEditRights;
this.appOptions.canRequestClose = this.editorConfig.canRequestClose;
this.appOptions.canEdit = this.permissions.edit !== false && // can edit
(this.editorConfig.canRequestEditRights || this.editorConfig.mode !== 'view'); // if mode=="view" -> canRequestEditRights must be defined
this.appOptions.isEdit = this.appOptions.canLicense && this.appOptions.canEdit && this.editorConfig.mode !== 'view';
@ -1711,14 +1712,18 @@ define([
me = this;
if (type == Asc.c_oAscAdvancedOptionsID.DRM) {
me._state.openDlg = new Common.Views.OpenDialog({
closable: me.appOptions.canRequestClose,
type: type,
validatePwd: !!me._state.isDRM,
handler: function (value) {
handler: function (result, value) {
me.isShowOpenDialog = false;
if (me && me.api) {
me.api.asc_setAdvancedOptions(type, new Asc.asc_CDRMAdvancedOptions(value));
me.loadMask && me.loadMask.show();
}
if (result == 'ok') {
if (me.api) {
me.api.asc_setAdvancedOptions(type, new Asc.asc_CDRMAdvancedOptions(value));
me.loadMask && me.loadMask.show();
}
} else
Common.Gateway.requestClose();
me._state.openDlg = null;
}
});

View file

@ -216,7 +216,7 @@ define([
},
show: function(panel) {
if (this.isVisible() && panel===undefined) return;
if (this.isVisible() && panel===undefined || !this.mode) return;
var defPanel = (this.mode.canDownload && (!this.mode.isDesktopApp || !this.mode.isOffline)) ? 'saveas' : 'info';
if (!panel)

View file

@ -116,6 +116,7 @@
"Common.Views.OpenDialog.txtPassword": "Password",
"Common.Views.OpenDialog.txtTitle": "Choose %1 options",
"Common.Views.OpenDialog.txtTitleProtected": "Protected File",
"Common.Views.OpenDialog.closeButtonText": "Close File",
"Common.Views.PasswordDialog.cancelButtonText": "Cancel",
"Common.Views.PasswordDialog.okButtonText": "OK",
"Common.Views.PasswordDialog.txtDescription": "A password is required to open this document",

View file

@ -662,6 +662,8 @@ define([
/** coauthoring end **/
onShortcut: function(s, e) {
if (!this.mode) return;
if (this.mode.isEditDiagram && s!='escape') return false;
if (this.mode.isEditMailMerge && s!='escape' && s!='search') return false;

View file

@ -881,6 +881,7 @@ define([
this.appOptions.canModifyFilter = true;
this.appOptions.canRequestEditRights = this.editorConfig.canRequestEditRights;
this.appOptions.canRequestClose = this.editorConfig.canRequestClose;
this.appOptions.canEdit = this.permissions.edit !== false && // can edit
(this.editorConfig.canRequestEditRights || this.editorConfig.mode !== 'view'); // if mode=="view" -> canRequestEditRights must be defined
this.appOptions.isEdit = (this.appOptions.canLicense || this.appOptions.isEditDiagram || this.appOptions.isEditMailMerge) && this.permissions.edit !== false && this.editorConfig.mode !== 'view';
@ -1533,14 +1534,18 @@ define([
});
} else if (type == Asc.c_oAscAdvancedOptionsID.DRM) {
me._state.openDlg = new Common.Views.OpenDialog({
closable: me.appOptions.canRequestClose,
type: type,
validatePwd: !!me._state.isDRM,
handler: function (value) {
handler: function (result, value) {
me.isShowOpenDialog = false;
if (me && me.api) {
me.api.asc_setAdvancedOptions(type, new Asc.asc_CDRMAdvancedOptions(value));
me.loadMask && me.loadMask.show();
}
if (result == 'ok') {
if (me && me.api) {
me.api.asc_setAdvancedOptions(type, new Asc.asc_CDRMAdvancedOptions(value));
me.loadMask && me.loadMask.show();
}
} else
Common.Gateway.requestClose();
me._state.openDlg = null;
}
});

View file

@ -205,7 +205,7 @@ define([
},
show: function(panel) {
if (this.isVisible() && panel===undefined) return;
if (this.isVisible() && panel===undefined || !this.mode) return;
var defPanel = (this.mode.canDownload && (!this.mode.isDesktopApp || !this.mode.isOffline)) ? 'saveas' : 'info';
if (!panel)
@ -220,7 +220,7 @@ define([
hide: function() {
this.$el.hide();
this.api.asc_enableKeyEvents(true);
this.api && this.api.asc_enableKeyEvents(true);
this.fireEvent('menu:hide', [this]);
},

View file

@ -102,6 +102,7 @@
"Common.Views.OpenDialog.txtTab": "Tab",
"Common.Views.OpenDialog.txtTitle": "Choose %1 options",
"Common.Views.OpenDialog.txtTitleProtected": "Protected File",
"Common.Views.OpenDialog.closeButtonText": "Close File",
"Common.Views.PasswordDialog.cancelButtonText": "Cancel",
"Common.Views.PasswordDialog.okButtonText": "OK",
"Common.Views.PasswordDialog.txtDescription": "A password is required to open this document",