From eecfd0a5ff6c399b014d54d10e18bb161bba27aa Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Mon, 11 Oct 2021 13:05:49 +0300 Subject: [PATCH] Refactoring input for password --- apps/common/main/lib/component/InputField.js | 100 ++++--------------- apps/spreadsheeteditor/main/locale/ru.json | 2 + 2 files changed, 24 insertions(+), 78 deletions(-) diff --git a/apps/common/main/lib/component/InputField.js b/apps/common/main/lib/component/InputField.js index 08894d125..51c77c548 100644 --- a/apps/common/main/lib/component/InputField.js +++ b/apps/common/main/lib/component/InputField.js @@ -483,6 +483,7 @@ define([ this._button = new Common.UI.Button({ el: this.cmpEl.find('button'), + iconCls: this.options.iconCls, hint: this.options.btnHint || '' }); this._button.on('click', _.bind(this.onButtonClick, this)); @@ -545,7 +546,7 @@ define([ } })()); - Common.UI.InputFieldBtnPassword = Common.UI.InputFieldBtn.extend((function() { + Common.UI.InputFieldBtnPassword = Common.UI.InputFieldBtn.extend(_.extend((function() { return { options: { id: null, @@ -563,88 +564,31 @@ define([ validateOnBlur: true, disabled: false, editable: true, - iconCls: 'btn-select-range', + iconCls: 'btn-sheet-view', btnHint: '', repeatInput: null, showPwdOnClick: true }, + + initialize : function(options) { + options = options || {}; + options.btnHint = options.btnHint || this.textHintShowPwd; + + Common.UI.InputFieldBtn.prototype.initialize.call(this, options); + + this.hidePwd = true; + this.repeatInput= this.options.repeatInput; + }, + render: function (parentEl) { - var me = this; + Common.UI.InputFieldBtn.prototype.render.call(this, parentEl); - if (!me.rendered) { - this.cmpEl = $(this.template({ - id : this.id, - cls : this.cls, - style : this.style, - value : this.value, - type : 'password', - name : this.name, - placeHolder : this.placeHolder, - spellcheck : this.spellcheck, - iconCls : this.options.iconCls, - scope : me - })); - - if (parentEl) { - this.setElement(parentEl, false); - parentEl.html(this.cmpEl); - } else { - this.$el.html(this.cmpEl); - } - } else { - this.cmpEl = this.$el; - } - - if (!me.rendered) { - var el = this.cmpEl; - - this._button = new Common.UI.Button({ - el: this.cmpEl.find('button'), - hint: this.options.btnHint || '' - }); - this._button.on('click', _.bind(this.onButtonClick, this)); - - this._input = this.cmpEl.find('input').addBack().filter('input'); - - if (this.editable) { - this._input.on('blur', _.bind(this.onInputChanged, this)); - this._input.on('keypress', _.bind(this.onKeyPress, this)); - this._input.on('keydown', _.bind(this.onKeyDown, this)); - this._input.on('keyup', _.bind(this.onKeyUp, this)); - if (this.validateOnChange) this._input.on('input', _.bind(this.onInputChanging, this)); - if (this.maxLength) this._input.attr('maxlength', this.maxLength); - } - - this.hidePwd = true; - this.repeatInput= this.options.repeatInput; - this._btnElm = this._button.$el; - this._button.setIconCls('btn-sheet-view'); - this._input.on('input', _.bind(this.checkPasswordType, this)); - this._button.updateHint(this.textHintShowPwd); - if(this.options.showPwdOnClick) - this._button.on('click', _.bind(this.passwordClick, this)); - else - this._btnElm.on('mousedown', _.bind(this.passwordShow, this)); - - - - this.setEditable(this.editable); - - if (this.disabled) - this.setDisabled(this.disabled); - - if (this._input.closest('.asc-window').length>0) - var onModalClose = function() { - var errorTip = el.find('.input-error').data('bs.tooltip'); - if (errorTip) errorTip.tip().remove(); - Common.NotificationCenter.off({'modal:close': onModalClose}); - }; - Common.NotificationCenter.on({'modal:close': onModalClose}); - } - - me.rendered = true; - if (me.value) - me.setValue(me.value); + this._btnElm = this._button.$el; + this._input.on('input', _.bind(this.checkPasswordType, this)); + if(this.options.showPwdOnClick) + this._button.on('click', _.bind(this.passwordClick, this)); + else + this._btnElm.on('mousedown', _.bind(this.passwordShow, this)); return this; }, @@ -698,5 +642,5 @@ define([ textHintShowPwd: 'Show password', textHintHidePwd: 'Hide password' } - })()); + })(), Common.UI.InputFieldBtnPassword || {})); }); \ No newline at end of file diff --git a/apps/spreadsheeteditor/main/locale/ru.json b/apps/spreadsheeteditor/main/locale/ru.json index 3dfc56406..e8c14e46e 100644 --- a/apps/spreadsheeteditor/main/locale/ru.json +++ b/apps/spreadsheeteditor/main/locale/ru.json @@ -114,6 +114,8 @@ "Common.UI.ExtendedColorDialog.textNew": "Новый", "Common.UI.ExtendedColorDialog.textRGBErr": "Введено некорректное значение.
Пожалуйста, введите числовое значение от 0 до 255.", "Common.UI.HSBColorPicker.textNoColor": "Без цвета", + "Common.UI.InputFieldBtnPassword.textHintShowPwd": "Показать пароль", + "Common.UI.InputFieldBtnPassword.textHintHidePwd": "Скрыть пароль", "Common.UI.SearchDialog.textHighlight": "Выделить результаты", "Common.UI.SearchDialog.textMatchCase": "С учетом регистра", "Common.UI.SearchDialog.textReplaceDef": "Введите текст для замены",