[SSE] Use sdk protect functions

This commit is contained in:
Julia Radzhabova 2021-06-22 12:16:38 +03:00
parent 05099e883c
commit 8bb87afdee

View file

@ -82,6 +82,7 @@ define([
setApi: function (api) { setApi: function (api) {
if (api) { if (api) {
this.api = api; this.api = api;
this.api.asc_registerCallback('asc_onChangeProtectWorkbook',_.bind(this.onChangeProtectWorkbook, this));
this.api.asc_registerCallback('asc_onCoAuthoringDisconnect',_.bind(this.onCoAuthoringDisconnect, this)); this.api.asc_registerCallback('asc_onCoAuthoringDisconnect',_.bind(this.onCoAuthoringDisconnect, this));
} }
}, },
@ -108,38 +109,60 @@ define([
onWorkbookClick: function(state) { onWorkbookClick: function(state) {
if (state) { if (state) {
var me = this, var me = this,
btn,
win = new SSE.Views.ProtectDialog({ win = new SSE.Views.ProtectDialog({
title: me.view.txtWBTitle, title: me.view.txtWBTitle,
txtDescription: me.view.txtWBDescription, txtDescription: me.view.txtWBDescription,
height: 306, height: 306,
handler: function(result, props) { handler: function(result, value) {
btn = result;
if (result == 'ok') { if (result == 'ok') {
me.api.asc_setProtectedWorkbook(me.api.asc_getProtectedWorkbook()); var props = new Asc.CWorkbookProtection();
props.asc_setLockStructure(true);
value && props.asc_setPassword(value);
me.api.asc_setProtectedWorkbook(props);
} }
Common.NotificationCenter.trigger('edit:complete'); Common.NotificationCenter.trigger('edit:complete');
} }
}).on('close', function() {
if (btn!=='ok')
me.view.btnProtectWB.toggle(false, true);
}); });
win.show(); win.show();
} else { } else {
var me = this, var me = this,
win = new Common.Views.OpenDialog({ btn,
props = me.api.asc_getProtectedWorkbook();
if (props.asc_isPassword()) {
var win = new Common.Views.OpenDialog({
title: me.view.txtWBUnlockTitle, title: me.view.txtWBUnlockTitle,
closable: true, closable: true,
type: Common.Utils.importTextType.DRM, type: Common.Utils.importTextType.DRM,
txtOpenFile: me.view.txtWBUnlockDescription, txtOpenFile: me.view.txtWBUnlockDescription,
validatePwd: false, validatePwd: false,
handler: function (result, value) { handler: function (result, value) {
btn = result;
if (result == 'ok') { if (result == 'ok') {
if (me.api) { if (me.api) {
me.api.asc_setProtectedWorkbook(me.api.asc_getProtectedWorkbook()); props = new Asc.CWorkbookProtection();
props.asc_setLockStructure(false, value);
me.api.asc_setProtectedWorkbook(props);
} }
Common.NotificationCenter.trigger('edit:complete'); Common.NotificationCenter.trigger('edit:complete');
} }
} }
}).on('close', function() {
if (btn!=='ok')
me.view.btnProtectWB.toggle(true, true);
}); });
win.show(); win.show();
} else {
props = new Asc.CWorkbookProtection();
props.asc_setLockStructure(false);
me.api.asc_setProtectedWorkbook(props);
}
} }
}, },
@ -194,6 +217,10 @@ define([
}); });
}, },
onChangeProtectWorkbook: function() {
this.view.btnProtectWB.toggle(this.api.asc_isProtectedWorkbook(), true);
},
onCoAuthoringDisconnect: function() { onCoAuthoringDisconnect: function() {
this.SetDisabled(true); this.SetDisabled(true);
} }