From d8d54bae860009e6d82d4d10a409f850d32662b8 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Fri, 20 Aug 2021 15:53:45 +0300 Subject: [PATCH] [SSE] Check adding protected range --- .../main/app/view/ProtectDialog.js | 26 +++++++++++++++++-- .../main/app/view/ProtectRangesDlg.js | 5 ++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/apps/spreadsheeteditor/main/app/view/ProtectDialog.js b/apps/spreadsheeteditor/main/app/view/ProtectDialog.js index b6ada3867..5890a4e4f 100644 --- a/apps/spreadsheeteditor/main/app/view/ProtectDialog.js +++ b/apps/spreadsheeteditor/main/app/view/ProtectDialog.js @@ -64,6 +64,8 @@ define([ this.txtDescription = options.txtDescription || ''; this.type = options.type || 'workbook'; this.props = options.props; + this.names = options.names; + this.isEdit = options.isEdit; this.api = options.api; this.template = options.template || [ @@ -164,7 +166,25 @@ define([ blankError : this.txtEmpty, style : 'width: 100%;', maxLength: 255, - validateOnBlur: false + validateOnBlur: false, + validateOnChange: false, + validation : function(value) { + if (value=='') return true; + + var res = me.api.asc_checkProtectedRangeName(value); + switch (res) { + case Asc.c_oAscDefinedNameReason.WrongName: + return me.textInvalidName; + break; + case Asc.c_oAscDefinedNameReason.Existed: + return (me.isEdit && me.props.asc_getName().toLowerCase() == value.toLowerCase()) ? true : me.textExistName; + case Asc.c_oAscDefinedNameReason.OK: + var index = me.names.indexOf(value.toLowerCase()); + return (index<0 || me.isEdit && me.props.asc_getName().toLowerCase() == value.toLowerCase()) ? true : me.textExistName; + default: + return me.textInvalidName; + } + } }); this.txtDataRange = new Common.UI.InputFieldBtn({ el : $('#id-range-txt'), @@ -429,7 +449,9 @@ define([ txtRange: 'Range', txtEmpty: 'This field is required', textSelectData: 'Select Data', - textInvalidRange: 'ERROR! Invalid cells range' + textInvalidRange: 'ERROR! Invalid cells range', + textInvalidName: 'The range title must begin with a letter and may only contain letters, numbers, and spaces.', + textExistName: 'ERROR! Range with such a title already exists' }, SSE.Views.ProtectDialog || {})); }); diff --git a/apps/spreadsheeteditor/main/app/view/ProtectRangesDlg.js b/apps/spreadsheeteditor/main/app/view/ProtectRangesDlg.js index 66701f65f..9e0356252 100644 --- a/apps/spreadsheeteditor/main/app/view/ProtectRangesDlg.js +++ b/apps/spreadsheeteditor/main/app/view/ProtectRangesDlg.js @@ -248,11 +248,16 @@ define([ 'text!spreadsheeteditor/main/app/template/ProtectRangesDlg.template', props = new Asc.CProtectedRange(); props.asc_setSqref(me.api.asc_getActiveRangeStr(Asc.referenceType.A)); } + var names = []; + this.rangeList.store.each(function(item){ + names.push(item.get('name').toLowerCase()); + }); var win = new SSE.Views.ProtectDialog({ title : isEdit ? me.txtEditRange : me.txtNewRange, type : 'range', props : props, + names : names, isEdit : isEdit, api : me.api, buttons : ['ok', 'cancel'],