[SSE] Protect sheet
This commit is contained in:
parent
8bb87afdee
commit
bb9877ccca
|
@ -111,9 +111,7 @@ define([
|
||||||
var me = this,
|
var me = this,
|
||||||
btn,
|
btn,
|
||||||
win = new SSE.Views.ProtectDialog({
|
win = new SSE.Views.ProtectDialog({
|
||||||
title: me.view.txtWBTitle,
|
type: 'workbook',
|
||||||
txtDescription: me.view.txtWBDescription,
|
|
||||||
height: 306,
|
|
||||||
handler: function(result, value) {
|
handler: function(result, value) {
|
||||||
btn = result;
|
btn = result;
|
||||||
if (result == 'ok') {
|
if (result == 'ok') {
|
||||||
|
@ -168,25 +166,60 @@ define([
|
||||||
|
|
||||||
onSheetClick: function(state) {
|
onSheetClick: function(state) {
|
||||||
if (state) {
|
if (state) {
|
||||||
|
var me = this,
|
||||||
|
btn,
|
||||||
|
win = new SSE.Views.ProtectDialog({
|
||||||
|
type: 'sheet',
|
||||||
|
props: me.api.asc_getProtectedSheet(),
|
||||||
|
handler: function(result, value, props) {
|
||||||
|
btn = result;
|
||||||
|
if (result == 'ok') {
|
||||||
|
!props && (props = new Asc.CSheetProtection());
|
||||||
|
props.asc_setSheet(true);
|
||||||
|
value && props.asc_setPassword(value);
|
||||||
|
me.api.asc_setProtectedSheet(props);
|
||||||
|
}
|
||||||
|
Common.NotificationCenter.trigger('edit:complete');
|
||||||
|
}
|
||||||
|
}).on('close', function() {
|
||||||
|
if (btn!=='ok')
|
||||||
|
me.view.btnProtectSheet.toggle(false, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
win.show();
|
||||||
} else {
|
} else {
|
||||||
var me = this,
|
var me = this,
|
||||||
win = new Common.Views.OpenDialog({
|
btn,
|
||||||
|
props = me.api.asc_getProtectedSheet();
|
||||||
|
if (props.asc_isPassword()) {
|
||||||
|
var win = new Common.Views.OpenDialog({
|
||||||
title: me.view.txtSheetUnlockTitle,
|
title: me.view.txtSheetUnlockTitle,
|
||||||
closable: true,
|
closable: true,
|
||||||
type: Common.Utils.importTextType.DRM,
|
type: Common.Utils.importTextType.DRM,
|
||||||
txtOpenFile: me.view.txtSheetUnlockDescription,
|
txtOpenFile: me.view.txtSheetUnlockDescription,
|
||||||
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) {
|
||||||
|
props = new Asc.CSheetProtection();
|
||||||
|
props.asc_setSheet(false, value);
|
||||||
|
me.api.asc_setProtectedSheet(props);
|
||||||
}
|
}
|
||||||
Common.NotificationCenter.trigger('edit:complete');
|
Common.NotificationCenter.trigger('edit:complete');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}).on('close', function() {
|
||||||
|
if (btn!=='ok')
|
||||||
|
me.view.btnProtectSheet.toggle(true, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
win.show();
|
win.show();
|
||||||
|
} else {
|
||||||
|
props = new Asc.CSheetProtection();
|
||||||
|
props.asc_setSheet(false);
|
||||||
|
me.api.asc_setProtectedSheet(props);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -50,9 +50,10 @@ define([
|
||||||
_options = {};
|
_options = {};
|
||||||
|
|
||||||
_.extend(_options, {
|
_.extend(_options, {
|
||||||
width: 350,
|
title: options.type=='sheet' ? this.txtSheetTitle : this.txtWBTitle,
|
||||||
cls: 'modal-dlg',
|
cls: 'modal-dlg',
|
||||||
height : options.height || 306,
|
width: 350,
|
||||||
|
height: options.type=='sheet' ? 447 : 306,
|
||||||
buttons: [{
|
buttons: [{
|
||||||
value: 'ok',
|
value: 'ok',
|
||||||
caption: this.txtProtect
|
caption: this.txtProtect
|
||||||
|
@ -61,11 +62,13 @@ define([
|
||||||
|
|
||||||
this.handler = options.handler;
|
this.handler = options.handler;
|
||||||
this.txtDescription = options.txtDescription || '';
|
this.txtDescription = options.txtDescription || '';
|
||||||
|
this.type = options.type || 'workbook';
|
||||||
|
this.props = options.props;
|
||||||
|
|
||||||
this.template = options.template || [
|
this.template = options.template || [
|
||||||
'<div class="box">',
|
'<div class="box">',
|
||||||
'<div class="" style="margin-bottom: 10px;">',
|
'<div class="" style="margin-bottom: 10px;">',
|
||||||
'<label>' + t.txtDescription + '</label>',
|
'<label>' + (t.type=='sheet' ? t.txtSheetDescription : t.txtWBDescription) + '</label>',
|
||||||
'</div>',
|
'</div>',
|
||||||
'<div class="input-row">',
|
'<div class="input-row">',
|
||||||
'<label>' + t.txtPassword + ' (' + t.txtOptional + ')' + '</label>',
|
'<label>' + t.txtPassword + ' (' + t.txtOptional + ')' + '</label>',
|
||||||
|
@ -75,6 +78,12 @@ define([
|
||||||
'<label>' + t.txtRepeat + '</label>',
|
'<label>' + t.txtRepeat + '</label>',
|
||||||
'</div>',
|
'</div>',
|
||||||
'<div id="id-repeat-txt" class="input-row" style="margin-bottom: 10px;"></div>',
|
'<div id="id-repeat-txt" class="input-row" style="margin-bottom: 10px;"></div>',
|
||||||
|
'<% if (type=="sheet") { %>',
|
||||||
|
'<div class="input-row">',
|
||||||
|
'<label>' + t.txtAllow + '</label>',
|
||||||
|
'</div>',
|
||||||
|
'<div id="protect-dlg-options" class="" style="width: 100%; height: 139px; overflow: hidden;margin-bottom: 10px;"></div>',
|
||||||
|
'<% } %>',
|
||||||
'<label>' + t.txtWarning + '</label>',
|
'<label>' + t.txtWarning + '</label>',
|
||||||
'</div>'
|
'</div>'
|
||||||
].join('');
|
].join('');
|
||||||
|
@ -86,7 +95,6 @@ define([
|
||||||
render: function () {
|
render: function () {
|
||||||
Common.UI.Window.prototype.render.call(this);
|
Common.UI.Window.prototype.render.call(this);
|
||||||
|
|
||||||
if (this.$window) {
|
|
||||||
var me = this;
|
var me = this;
|
||||||
this.$window.find('.dlg-btn').on('click', _.bind(this.onBtnClick, this));
|
this.$window.find('.dlg-btn').on('click', _.bind(this.onBtnClick, this));
|
||||||
this.inputPwd = new Common.UI.InputField({
|
this.inputPwd = new Common.UI.InputField({
|
||||||
|
@ -108,17 +116,50 @@ define([
|
||||||
return me.txtIncorrectPwd;
|
return me.txtIncorrectPwd;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (this.type == 'sheet') {
|
||||||
|
this.optionsList = new Common.UI.ListView({
|
||||||
|
el: $('#protect-dlg-options', this.$window),
|
||||||
|
store: new Common.UI.DataViewStore(),
|
||||||
|
simpleAddMode: true,
|
||||||
|
scrollAlwaysVisible: true,
|
||||||
|
template: _.template(['<div class="listview inner" style=""></div>'].join('')),
|
||||||
|
itemTemplate: _.template([
|
||||||
|
'<div>',
|
||||||
|
'<label class="checkbox-indeterminate" style="position:absolute;">',
|
||||||
|
'<input id="pdcheckbox-<%= id %>" type="checkbox" class="button__checkbox">',
|
||||||
|
'<label for="pdcheckbox-<%= id %>" class="checkbox__shape" ></label>',
|
||||||
|
'</label>',
|
||||||
|
'<div id="<%= id %>" class="list-item" style="pointer-events:none; margin-left: 20px;display: flex;">',
|
||||||
|
'<div style="flex-grow: 1;"><%= Common.Utils.String.htmlEncode(value) %></div>',
|
||||||
|
'</div>',
|
||||||
|
'</div>'
|
||||||
|
].join(''))
|
||||||
|
});
|
||||||
|
this.optionsList.on({
|
||||||
|
'item:change': this.onItemChanged.bind(this),
|
||||||
|
'item:add': this.onItemChanged.bind(this),
|
||||||
|
'item:select': this.onCellCheck.bind(this)
|
||||||
|
});
|
||||||
|
this.optionsList.onKeyDown = _.bind(this.onListKeyDown, this);
|
||||||
|
this.optionsList.on('entervalue', _.bind(this.onPrimary, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.afterRender();
|
||||||
},
|
},
|
||||||
|
|
||||||
getFocusedComponents: function() {
|
getFocusedComponents: function() {
|
||||||
return [this.inputPwd, this.repeatPwd];
|
return this.optionsList ? [this.inputPwd, this.repeatPwd, this.optionsList] : [this.inputPwd, this.repeatPwd];
|
||||||
},
|
},
|
||||||
|
|
||||||
getDefaultFocusableComponent: function () {
|
getDefaultFocusableComponent: function () {
|
||||||
return this.inputPwd;
|
return this.inputPwd;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
afterRender: function() {
|
||||||
|
this._setDefaults(this.props);
|
||||||
|
},
|
||||||
|
|
||||||
onPrimary: function(event) {
|
onPrimary: function(event) {
|
||||||
this._handleInput('ok');
|
this._handleInput('ok');
|
||||||
return false;
|
return false;
|
||||||
|
@ -141,18 +182,147 @@ define([
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.handler.call(this, state, this.inputPwd.getValue());
|
this.handler.call(this, state, this.inputPwd.getValue(), this.getSheetSettings());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.close();
|
this.close();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_setDefaults: function (props) {
|
||||||
|
this.optionsList && this.updateOptionsList(props);
|
||||||
|
},
|
||||||
|
|
||||||
|
onItemChanged: function (view, record) {
|
||||||
|
var state = record.model.get('check');
|
||||||
|
if ( state == 'indeterminate' )
|
||||||
|
$('input[type=checkbox]', record.$el).prop('indeterminate', true);
|
||||||
|
else $('input[type=checkbox]', record.$el).prop({checked: state, indeterminate: false});
|
||||||
|
},
|
||||||
|
|
||||||
|
onCellCheck: function (listView, itemView, record) {
|
||||||
|
if (this.checkCellTrigerBlock)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var target = '', isLabel = false, bound = null;
|
||||||
|
|
||||||
|
var event = window.event ? window.event : window._event;
|
||||||
|
if (event) {
|
||||||
|
target = $(event.currentTarget).find('.list-item');
|
||||||
|
|
||||||
|
if (target.length) {
|
||||||
|
bound = target.get(0).getBoundingClientRect();
|
||||||
|
var _clientX = event.clientX*Common.Utils.zoom(),
|
||||||
|
_clientY = event.clientY*Common.Utils.zoom();
|
||||||
|
if (bound.left < _clientX && _clientX < bound.right &&
|
||||||
|
bound.top < _clientY && _clientY < bound.bottom) {
|
||||||
|
isLabel = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLabel || event.target.className.match('checkbox')) {
|
||||||
|
this.updateCellCheck(listView, record);
|
||||||
|
|
||||||
|
_.delay(function () {
|
||||||
|
listView.focus();
|
||||||
|
}, 100, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
onListKeyDown: function (e, data) {
|
||||||
|
var record = null, listView = this.optionsList;
|
||||||
|
|
||||||
|
if (listView.disabled) return;
|
||||||
|
if (_.isUndefined(undefined)) data = e;
|
||||||
|
|
||||||
|
if (data.keyCode == Common.UI.Keys.SPACE) {
|
||||||
|
data.preventDefault();
|
||||||
|
data.stopPropagation();
|
||||||
|
|
||||||
|
this.updateCellCheck(listView, listView.getSelectedRec());
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Common.UI.DataView.prototype.onKeyDown.call(this.optionsList, e, data);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
updateCellCheck: function (listView, record) {
|
||||||
|
if (record && listView) {
|
||||||
|
record.set('check', !record.get('check'));
|
||||||
|
// listView.scroller.update({minScrollbarLength : 40, alwaysVisibleY: true, suppressScrollX: true});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
updateOptionsList: function(props) {
|
||||||
|
var optionsArr = [
|
||||||
|
{ value: this.txtSelLocked, optionName: 'SelectLockedCells'},
|
||||||
|
{ value: this.txtSelUnLocked, optionName: 'SelectUnlockedCells'},
|
||||||
|
{ value: this.txtFormatCells, optionName: 'FormatCells'},
|
||||||
|
{ value: this.txtFormatCols, optionName: 'FormatColumns'},
|
||||||
|
{ value: this.txtFormatRows, optionName: 'FormatRows'},
|
||||||
|
{ value: this.txtInsCols, optionName: 'InsertColumns'},
|
||||||
|
{ value: this.txtInsRows, optionName: 'InsertRows'},
|
||||||
|
{ value: this.txtInsHyper, optionName: 'InsertHyperlinks'},
|
||||||
|
{ value: this.txtDelCols, optionName: 'DeleteColumns'},
|
||||||
|
{ value: this.txtDelRows, optionName: 'DeleteRows'},
|
||||||
|
{ value: this.txtSort, optionName: 'Sort'},
|
||||||
|
{ value: this.txtAutofilter, optionName: 'AutoFilter'},
|
||||||
|
{ value: this.txtPivot, optionName: 'PivotTables'},
|
||||||
|
{ value: this.txtObjs, optionName: 'Objects'},
|
||||||
|
{ value: this.txtScen, optionName: 'Scenarios'}
|
||||||
|
];
|
||||||
|
|
||||||
|
var arr = [];
|
||||||
|
optionsArr.forEach(function (item, index) {
|
||||||
|
arr.push(new Common.UI.DataViewModel({
|
||||||
|
selected : false,
|
||||||
|
allowSelected : true,
|
||||||
|
value : item.value,
|
||||||
|
optionName : item.optionName,
|
||||||
|
check : props && props['asc_get' + item.optionName] ? props['asc_get' + item.optionName]() : false
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
this.optionsList.store.reset(arr);
|
||||||
|
this.optionsList.scroller.update({minScrollbarLength : 40, alwaysVisibleY: true, suppressScrollX: true});
|
||||||
|
},
|
||||||
|
|
||||||
|
getSheetSettings: function() {
|
||||||
|
if (this.type !== 'sheet') return null;
|
||||||
|
|
||||||
|
var props = new Asc.CSheetProtection();
|
||||||
|
this.optionsList.store.each(function (item, index) {
|
||||||
|
props && props['asc_set' + item.get('optionName')] && props['asc_set' + item.get('optionName')](item.get('check'));
|
||||||
|
});
|
||||||
|
return props;
|
||||||
|
},
|
||||||
|
|
||||||
txtPassword : "Password",
|
txtPassword : "Password",
|
||||||
txtRepeat: 'Repeat password',
|
txtRepeat: 'Repeat password',
|
||||||
txtIncorrectPwd: 'Confirmation password is not identical',
|
txtIncorrectPwd: 'Confirmation password is not identical',
|
||||||
txtWarning: 'Warning: If you lose or forget the password, it cannot be recovered. Please keep it in a safe place.',
|
txtWarning: 'Warning: If you lose or forget the password, it cannot be recovered. Please keep it in a safe place.',
|
||||||
txtOptional: 'optional',
|
txtOptional: 'optional',
|
||||||
txtProtect: 'Protect'
|
txtProtect: 'Protect',
|
||||||
|
txtSelLocked: 'Select locked cells',
|
||||||
|
txtSelUnLocked: 'Select unlocked cells',
|
||||||
|
txtFormatCells: 'Format cells',
|
||||||
|
txtFormatCols: 'Format columns',
|
||||||
|
txtFormatRows: 'Format rows',
|
||||||
|
txtInsCols: 'Insert columns',
|
||||||
|
txtInsRows: 'Insert rows',
|
||||||
|
txtInsHyper: 'Insert hyperlink',
|
||||||
|
txtDelCols: 'Delete columns',
|
||||||
|
txtDelRows: 'Delete rows',
|
||||||
|
txtSort: 'Sort',
|
||||||
|
txtAutofilter: 'Use AutoFilter',
|
||||||
|
txtPivot: 'Use PivotTable and PivotChart',
|
||||||
|
txtObjs: 'Edit objects',
|
||||||
|
txtScen: 'Edit scenarios',
|
||||||
|
txtWBDescription: 'To prevent other users from viewing hidden worksheets, adding, moving, deleting, or hiding worksheets and renaming worksheets, you can protect the structure of your workbook with a password.',
|
||||||
|
txtWBTitle: 'Protect Workbook structure',
|
||||||
|
txtSheetDescription: 'Prevent unwanted changes from others by limiting their ability to edit.',
|
||||||
|
txtSheetTitle: 'Protect Sheet',
|
||||||
|
txtAllow: 'Allow all users of this sheet to'
|
||||||
|
|
||||||
}, SSE.Views.ProtectDialog || {}));
|
}, SSE.Views.ProtectDialog || {}));
|
||||||
});
|
});
|
||||||
|
|
|
@ -210,9 +210,6 @@ define([
|
||||||
txtLockedShape: 'Shape Locked',
|
txtLockedShape: 'Shape Locked',
|
||||||
txtLockedText: 'Lock Text',
|
txtLockedText: 'Lock Text',
|
||||||
txtHiddenFormula: 'Hidden Formulas',
|
txtHiddenFormula: 'Hidden Formulas',
|
||||||
txtProtect: 'Protect',
|
|
||||||
txtWBDescription: 'To prevent other users from viewing hidden worksheets, adding, moving, deleting, or hiding worksheets and renaming worksheets, you can protect the structure of your workbook with a password.',
|
|
||||||
txtWBTitle: 'Protect Workbook structure',
|
|
||||||
txtWBUnlockTitle: 'Unprotect Workbook',
|
txtWBUnlockTitle: 'Unprotect Workbook',
|
||||||
txtWBUnlockDescription: 'Enter a password to unprotect workbook',
|
txtWBUnlockDescription: 'Enter a password to unprotect workbook',
|
||||||
txtSheetUnlockTitle: 'Unprotect Sheet',
|
txtSheetUnlockTitle: 'Unprotect Sheet',
|
||||||
|
|
Loading…
Reference in a new issue