diff --git a/apps/common/main/lib/component/FocusManager.js b/apps/common/main/lib/component/FocusManager.js index 120f00d7e..1158d4b5a 100644 --- a/apps/common/main/lib/component/FocusManager.js +++ b/apps/common/main/lib/component/FocusManager.js @@ -150,10 +150,8 @@ Common.UI.FocusManager = new(function() { addTraps(_windows[e.cid]); } - if (e && e.getDefaultFocusableComponent()) - setTimeout(function(){ - e.getDefaultFocusableComponent().focus(); - }, 100); + var el = e ? e.getDefaultFocusableComponent() : null; + el && setTimeout(function(){ el.focus(); }, 100); }, 'modal:close': function(e, last) { if (e && e.cid && _windows[e.cid]) { diff --git a/apps/common/main/lib/component/Window.js b/apps/common/main/lib/component/Window.js index 9ede2b633..b131629ba 100644 --- a/apps/common/main/lib/component/Window.js +++ b/apps/common/main/lib/component/Window.js @@ -985,7 +985,6 @@ define([ }, getDefaultFocusableComponent: function() { - return undefined; }, cancelButtonText: 'Cancel', diff --git a/apps/common/main/lib/view/ExtendedColorDialog.js b/apps/common/main/lib/view/ExtendedColorDialog.js index 5ad485937..a5b9d4906 100644 --- a/apps/common/main/lib/view/ExtendedColorDialog.js +++ b/apps/common/main/lib/view/ExtendedColorDialog.js @@ -150,6 +150,10 @@ define([ return [this.spinR, this.spinG, this.spinB, {cmp: this.textColor, selector: 'input'}]; }, + getDefaultFocusableComponent: function () { + return this.getChild('#extended-text-color'); + }, + onChangeColor: function(o, color) { this.colorNew.css({'background-color' : color}); @@ -272,15 +276,6 @@ define([ me.stopevents = false; }, - show: function() { - Common.UI.Window.prototype.show.apply(this, arguments); - - var me = this; - _.delay(function(){ - me.getChild('#extended-text-color').focus(); - },50); - }, - onPrimary: function() { this.trigger('onmodalresult', 1); this.close(true); diff --git a/apps/common/main/lib/view/InsertTableDialog.js b/apps/common/main/lib/view/InsertTableDialog.js index d29492142..e9890a80f 100644 --- a/apps/common/main/lib/view/InsertTableDialog.js +++ b/apps/common/main/lib/view/InsertTableDialog.js @@ -105,17 +105,16 @@ define([ }); // this.udColumns.on('entervalue', _.bind(this.onPrimary, this)); // this.udRows.on('entervalue', _.bind(this.onPrimary, this)); - var me = this; - setTimeout(function(){ - me.udColumns.focus(); - }, 100); - }, getFocusedComponents: function() { return [this.udColumns, this.udRows]; }, + getDefaultFocusableComponent: function () { + return this.udColumns; + }, + onBtnClick: function(event) { if (this.options.handler) { this.options.handler.call(this, event.currentTarget.attributes['result'].value, { diff --git a/apps/documenteditor/main/app/view/CaptionDialog.js b/apps/documenteditor/main/app/view/CaptionDialog.js index b7141a365..5beb4b80b 100644 --- a/apps/documenteditor/main/app/view/CaptionDialog.js +++ b/apps/documenteditor/main/app/view/CaptionDialog.js @@ -350,17 +350,12 @@ define([ return [this.txtCaption, this.cmbPosition, this.cmbLabel, this.cmbNumbering, this.cmbChapter, this.cmbSeparator]; }, - afterRender: function() { - this._setDefaults(this.props); - - var me = this; - setTimeout(function(){ - me.txtCaption.focus(); - }, 100); + getDefaultFocusableComponent: function () { + return this.txtCaption; }, - show: function() { - Common.Views.AdvancedSettingsWindow.prototype.show.apply(this, arguments); + afterRender: function() { + this._setDefaults(this.props); }, close: function() { diff --git a/apps/documenteditor/main/app/view/CellsAddDialog.js b/apps/documenteditor/main/app/view/CellsAddDialog.js index 7eb5004a6..3b86c7abd 100644 --- a/apps/documenteditor/main/app/view/CellsAddDialog.js +++ b/apps/documenteditor/main/app/view/CellsAddDialog.js @@ -127,17 +127,16 @@ define([ var $window = this.getChild(); $window.find('.dlg-btn').on('click', _.bind(this.onBtnClick, this)); - - var me = this; - setTimeout(function(){ - me.spnCount.focus(); - }, 100); }, getFocusedComponents: function() { return [this.cmbRowCol, this.spnCount]; }, + getDefaultFocusableComponent: function () { + return this.spnCount; + }, + _handleInput: function(state) { if (this.options.handler) { this.options.handler.call(this, state, this.getSettings()); diff --git a/apps/documenteditor/main/app/view/DateTimeDialog.js b/apps/documenteditor/main/app/view/DateTimeDialog.js index 4d57c2dc6..78029d768 100644 --- a/apps/documenteditor/main/app/view/DateTimeDialog.js +++ b/apps/documenteditor/main/app/view/DateTimeDialog.js @@ -173,16 +173,16 @@ define([ }); this._setDefaults(); - - setTimeout(function(){ - me.cmbLang.focus(); - }, 100); }, getFocusedComponents: function() { return [this.cmbLang, {cmp: this.listFormats, selector: '.listview'}]; }, + getDefaultFocusableComponent: function () { + return this.cmbLang; + }, + _setDefaults: function () { this.props = new Asc.CAscDateTime(); if (this.lang) { diff --git a/apps/documenteditor/main/app/view/EditListItemDialog.js b/apps/documenteditor/main/app/view/EditListItemDialog.js index 19703a140..852ce4cc8 100644 --- a/apps/documenteditor/main/app/view/EditListItemDialog.js +++ b/apps/documenteditor/main/app/view/EditListItemDialog.js @@ -129,13 +129,8 @@ define([ return [this.inputName, this.inputValue]; }, - show: function() { - Common.UI.Window.prototype.show.apply(this, arguments); - - var me = this; - _.delay(function(){ - me.inputName.focus(); - },50); + getDefaultFocusableComponent: function () { + return this.inputName; }, onPrimary: function(event) { diff --git a/apps/documenteditor/main/app/view/ListSettingsDialog.js b/apps/documenteditor/main/app/view/ListSettingsDialog.js index e4d455f53..b934d052e 100644 --- a/apps/documenteditor/main/app/view/ListSettingsDialog.js +++ b/apps/documenteditor/main/app/view/ListSettingsDialog.js @@ -358,10 +358,6 @@ define([ }); }, - show: function() { - Common.UI.Window.prototype.show.apply(this, arguments); - }, - updateThemeColors: function() { this.colors.updateColors(Common.Utils.ThemeColor.getEffectColors(), Common.Utils.ThemeColor.getStandartColors()); }, diff --git a/apps/documenteditor/main/app/view/NoteSettingsDialog.js b/apps/documenteditor/main/app/view/NoteSettingsDialog.js index d34caf72b..83b479591 100644 --- a/apps/documenteditor/main/app/view/NoteSettingsDialog.js +++ b/apps/documenteditor/main/app/view/NoteSettingsDialog.js @@ -286,17 +286,12 @@ define([ return [this.cmbFootnote, this.cmbEndnote, this.cmbFormat, this.spnStart, this.cmbNumbering, this.txtCustom, this.cmbApply]; }, - afterRender: function() { - this._setDefaults(this.props); - - var me = this; - setTimeout(function(){ - me.cmbFormat.focus(); - }, 100); + getDefaultFocusableComponent: function () { + return this.cmbFormat; }, - show: function() { - Common.Views.AdvancedSettingsWindow.prototype.show.apply(this, arguments); + afterRender: function() { + this._setDefaults(this.props); }, _setDefaults: function (props) { diff --git a/apps/documenteditor/main/app/view/PageMarginsDialog.js b/apps/documenteditor/main/app/view/PageMarginsDialog.js index cf8f8641b..9cacd6a63 100644 --- a/apps/documenteditor/main/app/view/PageMarginsDialog.js +++ b/apps/documenteditor/main/app/view/PageMarginsDialog.js @@ -306,17 +306,16 @@ define([ this.window.find('.dlg-btn').on('click', _.bind(this.onBtnClick, this)); this.updateMetricUnit(); - - var me = this; - setTimeout(function(){ - me.spnTop.focus(); - }, 100); }, getFocusedComponents: function() { return [this.spnTop, this.spnBottom, this.spnLeft, this.spnRight, this.spnGutter, this.cmbGutterPosition, this.cmbOrientation, this.cmbMultiplePages]; }, + getDefaultFocusableComponent: function () { + return this.spnTop; + }, + _handleInput: function(state) { if (this.options.handler) { if (state == 'ok') { diff --git a/apps/documenteditor/main/app/view/PageSizeDialog.js b/apps/documenteditor/main/app/view/PageSizeDialog.js index 9f233f36b..4b080b633 100644 --- a/apps/documenteditor/main/app/view/PageSizeDialog.js +++ b/apps/documenteditor/main/app/view/PageSizeDialog.js @@ -167,17 +167,16 @@ define([ $window.find('.dlg-btn').on('click', _.bind(this.onBtnClick, this)); this.updateMetricUnit(); - - var me = this; - setTimeout(function(){ - me.cmbPreset.focus(); - }, 100); }, getFocusedComponents: function() { return [this.cmbPreset, this.spnWidth, this.spnHeight]; }, + getDefaultFocusableComponent: function () { + return this.cmbPreset; + }, + _handleInput: function(state) { if (this.options.handler) { this.options.handler.call(this, this, state); diff --git a/apps/documenteditor/main/app/view/StyleTitleDialog.js b/apps/documenteditor/main/app/view/StyleTitleDialog.js index f014bd61b..c49039411 100644 --- a/apps/documenteditor/main/app/view/StyleTitleDialog.js +++ b/apps/documenteditor/main/app/view/StyleTitleDialog.js @@ -115,13 +115,8 @@ define([ return [this.inputTitle, this.cmbNextStyle]; }, - show: function() { - Common.UI.Window.prototype.show.apply(this, arguments); - - var me = this; - _.delay(function(){ - me.inputTitle.focus(); - },500); + getDefaultFocusableComponent: function () { + return this.inputTitle; }, getTitle: function () { diff --git a/apps/documenteditor/main/app/view/TableFormulaDialog.js b/apps/documenteditor/main/app/view/TableFormulaDialog.js index ab6418ca7..7a2c04fb0 100644 --- a/apps/documenteditor/main/app/view/TableFormulaDialog.js +++ b/apps/documenteditor/main/app/view/TableFormulaDialog.js @@ -169,17 +169,12 @@ define([ return [this.inputFormula, this.cmbFormat, this.cmbFunction, this.cmbBookmark]; }, - onSelectItem: function(picker, item, record, e){ - this.btnOk.setDisabled(record.get('level')==0 && record.get('index')>0); + getDefaultFocusableComponent: function () { + return this.inputFormula; }, - show: function() { - Common.UI.Window.prototype.show.apply(this, arguments); - - var me = this; - _.delay(function(){ - me.inputFormula.focus(); - },500); + onSelectItem: function(picker, item, record, e){ + this.btnOk.setDisabled(record.get('level')==0 && record.get('index')>0); }, afterRender: function() { diff --git a/apps/documenteditor/main/app/view/WatermarkSettingsDialog.js b/apps/documenteditor/main/app/view/WatermarkSettingsDialog.js index 730107a61..b38825d16 100644 --- a/apps/documenteditor/main/app/view/WatermarkSettingsDialog.js +++ b/apps/documenteditor/main/app/view/WatermarkSettingsDialog.js @@ -387,13 +387,17 @@ define(['text!documenteditor/main/app/template/WatermarkSettings.template', return [ this.cmbLang, this.cmbText, this.cmbFonts, this.cmbFontSize, this.cmbScale ]; }, + getDefaultFocusableComponent: function () { + if (!this.cmbLang.isDisabled()) + return this.cmbLang; + else if (!this.cmbScale.isDisabled()) + return this.cmbScale; + }, + focusControls: function() { - var me = this; - setTimeout(function(){ - if (!me.cmbLang.isDisabled()) - me.cmbLang.focus(); - else if (!me.cmbScale.isDisabled()) - me.cmbScale.focus(); + var el = this.getDefaultFocusableComponent(); + el && setTimeout(function(){ + el.focus(); }, 10); }, @@ -453,14 +457,9 @@ define(['text!documenteditor/main/app/template/WatermarkSettings.template', }); }, - show: function() { - Common.Views.AdvancedSettingsWindow.prototype.show.apply(this, arguments); - - this.focusControls(); - }, - loadLanguages: function() { - var me = this; + var me = this, + focus = false; var callback = function(languages) { var data = []; me.languages = languages; @@ -478,8 +477,10 @@ define(['text!documenteditor/main/app/template/WatermarkSettings.template', me.text && me.cmbText.setValue(me.text); } else me.cmbLang.setDisabled(true); + focus && me.focusControls(); }; var languages = DE.Views.WatermarkText.get(); + focus = !languages; if (languages) callback(languages); else diff --git a/apps/presentationeditor/main/app/view/DateTimeDialog.js b/apps/presentationeditor/main/app/view/DateTimeDialog.js index a632bc0f0..d4f2d332d 100644 --- a/apps/presentationeditor/main/app/view/DateTimeDialog.js +++ b/apps/presentationeditor/main/app/view/DateTimeDialog.js @@ -173,16 +173,16 @@ define([ }); this._setDefaults(); - - setTimeout(function(){ - me.cmbLang.focus(); - }, 100); }, getFocusedComponents: function() { return [this.cmbLang, {cmp: this.listFormats, selector: '.listview'}]; }, + getDefaultFocusableComponent: function () { + return this.cmbLang; + }, + _setDefaults: function () { this.props = new AscCommonSlide.CAscDateTime(); if (this.lang) { diff --git a/apps/presentationeditor/main/app/view/HeaderFooterDialog.js b/apps/presentationeditor/main/app/view/HeaderFooterDialog.js index 97584dcf0..718d65979 100644 --- a/apps/presentationeditor/main/app/view/HeaderFooterDialog.js +++ b/apps/presentationeditor/main/app/view/HeaderFooterDialog.js @@ -191,21 +191,20 @@ define(['text!presentationeditor/main/app/template/HeaderFooterDialog.template', return [ this.cmbFormat, this.cmbLang, this.inputFixed, this.inputFooter ]; }, - focusControls: function() { - var me = this; - setTimeout(function(){ - if (!me.cmbFormat.isDisabled()) - me.cmbFormat.focus(); - else if (!me.inputFixed.isDisabled()) - me.inputFixed.focus(); - else if (!me.inputFooter.isDisabled()) - me.inputFooter.focus(); - }, 10); + getDefaultFocusableComponent: function () { + if (!this.cmbFormat.isDisabled()) + return this.cmbFormat; + else if (!this.inputFixed.isDisabled()) + return this.inputFixed; + else if (!this.inputFooter.isDisabled()) + return this.inputFooter; }, - show: function() { - Common.Views.AdvancedSettingsWindow.prototype.show.apply(this, arguments); - this.focusControls(); + focusControls: function() { + var el = this.getDefaultFocusableComponent(); + el && setTimeout(function(){ + el.focus(); + }, 10); }, afterRender: function() { diff --git a/apps/presentationeditor/main/app/view/SlideSizeSettings.js b/apps/presentationeditor/main/app/view/SlideSizeSettings.js index d2a7483b1..128af22fe 100644 --- a/apps/presentationeditor/main/app/view/SlideSizeSettings.js +++ b/apps/presentationeditor/main/app/view/SlideSizeSettings.js @@ -202,17 +202,16 @@ define([ $window.find('.dlg-btn').on('click', _.bind(this.onBtnClick, this)); this.updateMetricUnit(); - - var me = this; - setTimeout(function(){ - me.cmbSlideSize.focus(); - }, 100); }, getFocusedComponents: function() { return [this.cmbSlideSize, this.spnWidth, this.spnHeight, this.cmbSlideOrientation]; }, + getDefaultFocusableComponent: function () { + return this.cmbSlideSize; + }, + _handleInput: function(state) { if (this.options.handler) { this.options.handler.call(this, this, state); diff --git a/apps/spreadsheeteditor/main/app/view/AdvancedSeparatorDialog.js b/apps/spreadsheeteditor/main/app/view/AdvancedSeparatorDialog.js index 8cd508504..63a0e3d74 100644 --- a/apps/spreadsheeteditor/main/app/view/AdvancedSeparatorDialog.js +++ b/apps/spreadsheeteditor/main/app/view/AdvancedSeparatorDialog.js @@ -102,6 +102,10 @@ define([ return [this.inputDecimalSeparator, this.inputThousandsSeparator]; }, + getDefaultFocusableComponent: function () { + return this.inputDecimalSeparator; + }, + afterRender: function() { this._setDefaults(this.props); }, @@ -113,15 +117,6 @@ define([ } }, - show: function() { - Common.UI.Window.prototype.show.apply(this, arguments); - - var me = this; - _.delay(function(){ - me.inputDecimalSeparator.cmpEl.find('input').focus(); - },50); - }, - onPrimary: function(event) { this._handleInput('ok'); return false; diff --git a/apps/spreadsheeteditor/main/app/view/AutoFilterDialog.js b/apps/spreadsheeteditor/main/app/view/AutoFilterDialog.js index faffb3603..a7d8eb979 100644 --- a/apps/spreadsheeteditor/main/app/view/AutoFilterDialog.js +++ b/apps/spreadsheeteditor/main/app/view/AutoFilterDialog.js @@ -193,15 +193,8 @@ define([ return [this.cmbCondition1, this.cmbValue1, this.cmbCondition2, this.cmbValue2]; }, - show: function () { - Common.UI.Window.prototype.show.call(this); - - var me = this; - _.defer(function () { - if (me.cmbValue1) { - me.cmbValue1.focus(); - } - }, 500); + getDefaultFocusableComponent: function () { + return this.cmbValue1; }, close: function () { @@ -418,15 +411,8 @@ define([ return [this.cmbType, this.spnCount, this.cmbItem, this.cmbFields]; }, - show: function () { - Common.UI.Window.prototype.show.call(this); - - var me = this; - _.defer(function () { - if (me.spnCount) { - me.spnCount.focus(); - } - }, 500); + getDefaultFocusableComponent: function () { + return this.spnCount; }, close: function () { @@ -661,15 +647,8 @@ define([ return [this.cmbFields, this.cmbCondition1, this.inputValue, this.inputValue2]; }, - show: function () { - Common.UI.Window.prototype.show.call(this); - - var me = this; - _.defer(function () { - if (me.inputValue) { - me.inputValue.focus(); - } - }, 500); + getDefaultFocusableComponent: function () { + return this.inputValue; }, close: function () { diff --git a/apps/spreadsheeteditor/main/app/view/ChartDataRangeDialog.js b/apps/spreadsheeteditor/main/app/view/ChartDataRangeDialog.js index d5dd63265..e9e70fa3d 100644 --- a/apps/spreadsheeteditor/main/app/view/ChartDataRangeDialog.js +++ b/apps/spreadsheeteditor/main/app/view/ChartDataRangeDialog.js @@ -170,16 +170,18 @@ define([ this.lblRange3 = $window.find('#id-dlg-chart-range-lbl3'); $window.find('.dlg-btn').on('click', _.bind(this.onBtnClick, this)); - - setTimeout(function(){ - me.inputRange1.cmpEl.find('input').focus(); - }, 10); }, getFocusedComponents: function() { return [this.inputRange1, this.inputRange2, this.inputRange3]; }, + getDefaultFocusableComponent: function () { + if (this._alreadyRendered) return; // focus only at first show + this._alreadyRendered = true; + return this.inputRange1; + }, + onPrimary: function() { this._handleInput('ok'); return false; diff --git a/apps/spreadsheeteditor/main/app/view/CreatePivotDialog.js b/apps/spreadsheeteditor/main/app/view/CreatePivotDialog.js index 0f8e1f062..943c54311 100644 --- a/apps/spreadsheeteditor/main/app/view/CreatePivotDialog.js +++ b/apps/spreadsheeteditor/main/app/view/CreatePivotDialog.js @@ -168,17 +168,14 @@ define([ return [this.txtSourceRange, this.txtDestRange]; }, - afterRender: function() { - this._setDefaults(this.props); - - var me = this; - _.delay(function(){ - me.txtSourceRange.focus(); - },50); + getDefaultFocusableComponent: function () { + if (this._alreadyRendered) return; // focus only at first show + this._alreadyRendered = true; + return this.txtSourceRange; }, - show: function() { - Common.Views.AdvancedSettingsWindow.prototype.show.apply(this, arguments); + afterRender: function() { + this._setDefaults(this.props); }, _setDefaults: function (props) { diff --git a/apps/spreadsheeteditor/main/app/view/FormatSettingsDialog.js b/apps/spreadsheeteditor/main/app/view/FormatSettingsDialog.js index f46d9b3f6..0970a6e74 100644 --- a/apps/spreadsheeteditor/main/app/view/FormatSettingsDialog.js +++ b/apps/spreadsheeteditor/main/app/view/FormatSettingsDialog.js @@ -255,12 +255,12 @@ define([ return [this.cmbFormat, this.spnDecimal, this.cmbSymbols, this.cmbNegative, this.cmbType, this.cmbCode]; }, + getDefaultFocusableComponent: function () { + return this.cmbFormat; + }, + afterRender: function() { this._setDefaults(this.props); - var cmp = this.cmbFormat; - setTimeout(function(){ - (cmp.$el || $(cmp.el)).find('.form-control').focus(); - }, 10); }, show: function() { diff --git a/apps/spreadsheeteditor/main/app/view/FormulaDialog.js b/apps/spreadsheeteditor/main/app/view/FormulaDialog.js index 05504aa4b..00575b40a 100644 --- a/apps/spreadsheeteditor/main/app/view/FormulaDialog.js +++ b/apps/spreadsheeteditor/main/app/view/FormulaDialog.js @@ -128,6 +128,10 @@ define([ return [this.inputSearch, this.cmbFuncGroup, {cmp: this.cmbListFunctions, selector: '.listview'}]; }, + getDefaultFocusableComponent: function () { + return this.inputSearch; + }, + show: function (group) { if (this.$window) { var main_width, main_height, top, left, win_height = this.initConfig.height; @@ -152,13 +156,7 @@ define([ group && this.cmbFuncGroup.setValue(group); (group || this.cmbFuncGroup.getValue()=='Last10') && this.fillFunctions(this.cmbFuncGroup.getValue()); - if (this.cmbListFunctions) { - this.inputSearch.setValue(''); - var me = this; - setTimeout(function () { - me.inputSearch.$el.find('input').focus(); - }, 100); - } + this.inputSearch.setValue(''); this._preventCloseCellEditor = false; }, diff --git a/apps/spreadsheeteditor/main/app/view/HyperlinkSettingsDialog.js b/apps/spreadsheeteditor/main/app/view/HyperlinkSettingsDialog.js index 6ff845a12..1f27023bc 100644 --- a/apps/spreadsheeteditor/main/app/view/HyperlinkSettingsDialog.js +++ b/apps/spreadsheeteditor/main/app/view/HyperlinkSettingsDialog.js @@ -255,10 +255,6 @@ define([ return [this.inputUrl, {cmp: this.internalList, selector: '.treeview'}, this.inputRange, this.inputDisplay, this.inputTip]; }, - show: function() { - Common.UI.Window.prototype.show.apply(this, arguments); - }, - setSettings: function(settings) { if (settings) { var me = this; diff --git a/apps/spreadsheeteditor/main/app/view/NameManagerDlg.js b/apps/spreadsheeteditor/main/app/view/NameManagerDlg.js index aeb1097f3..8c3d28bde 100644 --- a/apps/spreadsheeteditor/main/app/view/NameManagerDlg.js +++ b/apps/spreadsheeteditor/main/app/view/NameManagerDlg.js @@ -175,12 +175,8 @@ define([ 'text!spreadsheeteditor/main/app/template/NameManagerDlg.template', return [ this.cmbFilter, {cmp: this.rangeList, selector: '.listview'} ]; }, - show: function() { - Common.Views.AdvancedSettingsWindow.prototype.show.apply(this, arguments); - var me = this; - _.delay(function () { - me.rangeList.focus(); - }, 100, me); + getDefaultFocusableComponent: function () { + return this.rangeList; }, afterRender: function() { diff --git a/apps/spreadsheeteditor/main/app/view/NamedRangeEditDlg.js b/apps/spreadsheeteditor/main/app/view/NamedRangeEditDlg.js index 52f753885..5abade9c7 100644 --- a/apps/spreadsheeteditor/main/app/view/NamedRangeEditDlg.js +++ b/apps/spreadsheeteditor/main/app/view/NamedRangeEditDlg.js @@ -179,17 +179,19 @@ define([ return [this.inputName, this.cmbScope, this.txtDataRange]; }, + getDefaultFocusableComponent: function () { + if (this._alreadyRendered) return; // focus only at first show + this._alreadyRendered = true; + return this.inputName; + }, + afterRender: function() { this._setDefaults(this.props); this.setTitle((this.isEdit) ? this.txtTitleEdit : this.txtTitleNew); this.api.asc_registerCallback('asc_onLockDefNameManager', this.wrapEvents.onLockDefNameManager); this.api.asc_registerCallback('asc_onRefreshDefNameList', this.wrapEvents.onRefreshDefNameList); - - var me = this; - _.delay(function(){ - me.inputName.focus(); - },200); }, + }, show: function() { Common.Views.AdvancedSettingsWindow.prototype.show.apply(this, arguments); diff --git a/apps/spreadsheeteditor/main/app/view/PageMarginsDialog.js b/apps/spreadsheeteditor/main/app/view/PageMarginsDialog.js index de23fe256..8a12e4371 100644 --- a/apps/spreadsheeteditor/main/app/view/PageMarginsDialog.js +++ b/apps/spreadsheeteditor/main/app/view/PageMarginsDialog.js @@ -146,11 +146,6 @@ define([ $window.find('.dlg-btn').on('click', _.bind(this.onBtnClick, this)); $window.find('input').on('keypress', _.bind(this.onKeyPress, this)); - var cmp = this.spnTop; - setTimeout(function(){ - (cmp.$el || $(cmp.el)).find('.form-control').focus(); - }, 10); - this.updateMetricUnit(); }, @@ -158,6 +153,10 @@ define([ return this.spinners; }, + getDefaultFocusableComponent: function () { + return this.spnTop; + }, + _handleInput: function(state) { if (this.options.handler) this.options.handler.call(this, this, state); diff --git a/apps/spreadsheeteditor/main/app/view/PrintSettings.js b/apps/spreadsheeteditor/main/app/view/PrintSettings.js index a19d93f25..ac6eeb42f 100644 --- a/apps/spreadsheeteditor/main/app/view/PrintSettings.js +++ b/apps/spreadsheeteditor/main/app/view/PrintSettings.js @@ -276,11 +276,6 @@ define([ 'text!spreadsheeteditor/main/app/template/PrintSettings.template', var value = Common.localStorage.getItem("sse-hide-print-settings"); this.extended = (value!==null && parseInt(value)==0); this.handlerShowDetails(this.btnHide); - - var me = this; - setTimeout(function(){ - me.cmbRange.focus(); - },100); }, getFocusedComponents: function() { @@ -288,6 +283,12 @@ define([ 'text!spreadsheeteditor/main/app/template/PrintSettings.template', this.spnMarginTop, this.spnMarginBottom, this.spnMarginLeft, this.spnMarginRight]; }, + getDefaultFocusableComponent: function () { + if (this._alreadyRendered) return; // focus only at first show + this._alreadyRendered = true; + return this.cmbRange; + }, + addCustomScale: function (add) { if (add) { this.cmbLayout.setData([ diff --git a/apps/spreadsheeteditor/main/app/view/PrintTitlesDialog.js b/apps/spreadsheeteditor/main/app/view/PrintTitlesDialog.js index 58c7834af..732c02da8 100644 --- a/apps/spreadsheeteditor/main/app/view/PrintTitlesDialog.js +++ b/apps/spreadsheeteditor/main/app/view/PrintTitlesDialog.js @@ -184,16 +184,18 @@ define([ $window.find('input').on('keypress', _.bind(this.onKeyPress, this)); this.setSettings(); - - setTimeout(function(){ - me.txtRangeTop.focus(); - },100); }, getFocusedComponents: function() { return [this.txtRangeTop, this.txtRangeLeft]; }, + getDefaultFocusableComponent: function () { + if (this._alreadyRendered) return; // focus only at first show + this._alreadyRendered = true; + return this.txtRangeTop; + }, + isRangeValid: function() { if (this.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.PrintTitles, this.txtRangeTop.getValue(), false) == Asc.c_oAscError.ID.DataRangeError) { this.txtRangeTop.focus(); diff --git a/apps/spreadsheeteditor/main/app/view/ScaleDialog.js b/apps/spreadsheeteditor/main/app/view/ScaleDialog.js index 9189c170d..8397b25a8 100644 --- a/apps/spreadsheeteditor/main/app/view/ScaleDialog.js +++ b/apps/spreadsheeteditor/main/app/view/ScaleDialog.js @@ -171,6 +171,10 @@ define([ return [this.cmbScaleWidth, this.cmbScaleHeight, this.spnScale]; }, + getDefaultFocusableComponent: function () { + return this.radioScaleTo.getValue() ? this.spnScale : this.cmbScaleWidth; + }, + afterRender: function() { this._setDefaults(this._originalProps); }, @@ -256,13 +260,6 @@ define([ } this.spnScale.setValue((scale !== null && scale !== undefined) ? scale : '', true); - var me = this; - setTimeout(function(){ - if (me.radioScaleTo.getValue()) - me.spnScale.focus(); - else - me.cmbScaleWidth.focus(); - },100); } }, diff --git a/apps/spreadsheeteditor/main/app/view/ValueFieldSettingsDialog.js b/apps/spreadsheeteditor/main/app/view/ValueFieldSettingsDialog.js index 2fa63e9f7..b665ce353 100644 --- a/apps/spreadsheeteditor/main/app/view/ValueFieldSettingsDialog.js +++ b/apps/spreadsheeteditor/main/app/view/ValueFieldSettingsDialog.js @@ -192,22 +192,18 @@ define([ this.lblSourceName = this.$window.find('#value-field-settings-source'); this.afterRender(); - - setTimeout(function(){ - me.inputCustomName.focus(); - },100); }, getFocusedComponents: function() { return [this.inputCustomName, this.cmbSummarize]; }, - afterRender: function() { - this._setDefaults(this.props); + getDefaultFocusableComponent: function () { + return this.inputCustomName; }, - show: function() { - Common.Views.AdvancedSettingsWindow.prototype.show.apply(this, arguments); + afterRender: function() { + this._setDefaults(this.props); }, _setDefaults: function (props) {