From 3bb1f0f7c4c73fb79d9b126626bdfd6222ef4e9c Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Thu, 27 Jun 2019 14:18:01 +0300 Subject: [PATCH] [Common] DateView refactoring --- .../main/lib/component/ComboDataView.js | 13 +++------- apps/common/main/lib/component/DataView.js | 17 +++---------- .../main/app/view/BookmarksDialog.js | 24 ++++++++----------- .../main/app/view/ChartSettings.js | 2 +- .../main/app/view/HyperlinkSettingsDialog.js | 14 +++++------ .../app/view/ParagraphSettingsAdvanced.js | 6 ++--- .../main/app/view/TableSettings.js | 2 +- .../main/app/view/ChartSettings.js | 2 +- .../app/view/ParagraphSettingsAdvanced.js | 6 ++--- .../main/app/view/TableSettings.js | 2 +- .../main/app/controller/PivotTable.js | 2 +- .../main/app/view/AutoFilterDialog.js | 2 +- .../main/app/view/ChartSettings.js | 2 +- .../main/app/view/ChartSettingsDlg.js | 4 ++-- .../main/app/view/FileMenuPanels.js | 4 +--- .../main/app/view/FormulaDialog.js | 1 - .../main/app/view/NameManagerDlg.js | 10 ++++---- .../main/app/view/NamedRangePasteDlg.js | 2 +- .../app/view/ParagraphSettingsAdvanced.js | 6 ++--- .../main/app/view/Statusbar.js | 4 ++-- .../main/app/view/TableSettings.js | 2 +- 21 files changed, 51 insertions(+), 76 deletions(-) diff --git a/apps/common/main/lib/component/ComboDataView.js b/apps/common/main/lib/component/ComboDataView.js index 289b79814..c10d000ca 100644 --- a/apps/common/main/lib/component/ComboDataView.js +++ b/apps/common/main/lib/component/ComboDataView.js @@ -245,11 +245,7 @@ define([ var picker = this.menuPicker; if (picker) { var record = picker.getSelectedRec(); - - if (record) { - record = record[0]; - this.fillComboView(record || picker.store.at(0), !!record, true); - } + this.fillComboView(record || picker.store.at(0), !!record, true); picker.onResize(); } @@ -311,7 +307,7 @@ define([ }, onAfterHideMenu: function(e, isFromInputControl) { - this.menuPicker.selectedBeforeHideRec = this.menuPicker.getSelectedRec()[0]; // for DataView - onKeyDown - Return key + this.menuPicker.selectedBeforeHideRec = this.menuPicker.getSelectedRec(); // for DataView - onKeyDown - Return key (this.showLast) ? this.menuPicker.showLastSelected() : this.menuPicker.deselectAll(); this.trigger('hide:after', this, e, isFromInputControl); }, @@ -387,10 +383,7 @@ define([ var picker = this.menuPicker; if (picker) { var record = picker.getSelectedRec(); - if (record) { - record = record[0]; - this.fillComboView(record || picker.store.at(0), false); - } + this.fillComboView(record || picker.store.at(0), false); } } }, diff --git a/apps/common/main/lib/component/DataView.js b/apps/common/main/lib/component/DataView.js index 86f0b0c8b..67a027902 100644 --- a/apps/common/main/lib/component/DataView.js +++ b/apps/common/main/lib/component/DataView.js @@ -389,17 +389,7 @@ define([ }, getSelectedRec: function() { - if (this.multiSelect) { - - var items = []; - _.each(this.store.where({selected: true}), function(rec){ - items.push(rec); - }); - - return items; - } - - return this.store.where({selected: true}); + return (this.multiSelect) ? this.store.where({selected: true}) : this.store.findWhere({selected: true}); }, onAddItem: function(record, store, opts) { @@ -601,7 +591,7 @@ define([ if (_.indexOf(this.moveKeys, data.keyCode)>-1 || data.keyCode==Common.UI.Keys.RETURN) { data.preventDefault(); data.stopPropagation(); - var rec = this.getSelectedRec()[0]; + var rec = this.getSelectedRec(); if (this.lastSelectedRec===null) this.lastSelectedRec = rec; if (data.keyCode==Common.UI.Keys.RETURN) { @@ -699,8 +689,7 @@ define([ this.scrollToRecord(this.lastSelectedRec); this.lastSelectedRec = null; } else { - var rec = this.getSelectedRec()[0]; - if (rec) this.scrollToRecord(rec); + this.scrollToRecord(this.getSelectedRec()); } }, diff --git a/apps/documenteditor/main/app/view/BookmarksDialog.js b/apps/documenteditor/main/app/view/BookmarksDialog.js index fc77ab283..685ac1ea4 100644 --- a/apps/documenteditor/main/app/view/BookmarksDialog.js +++ b/apps/documenteditor/main/app/view/BookmarksDialog.js @@ -314,9 +314,7 @@ define([ gotoBookmark: function(btn, eOpts){ var rec = this.bookmarksList.getSelectedRec(); - if (rec.length>0) { - this.props.asc_SelectBookmark(rec[0].get('value')); - } + rec && this.props.asc_SelectBookmark(rec.get('value')); }, addBookmark: function(btn, eOpts){ @@ -333,11 +331,11 @@ define([ deleteBookmark: function(btn, eOpts){ var rec = this.bookmarksList.getSelectedRec(); - if (rec.length>0) { - this.props.asc_RemoveBookmark(rec[0].get('value')); + if (rec) { + this.props.asc_RemoveBookmark(rec.get('value')); var store = this.bookmarksList.store; - var idx = _.indexOf(store.models, rec[0]); - store.remove(rec[0]); + var idx = _.indexOf(store.models, rec); + store.remove(rec); this.txtName.setValue(''); this.btnAdd.setDisabled(true); this.btnGoto.setDisabled(true); @@ -350,13 +348,11 @@ define([ if (btn.cmpEl && btn.cmpEl.parent().hasClass('open')) return; var rec = this.bookmarksList.getSelectedRec(); - if (rec.length>0) { - Common.Gateway.requestMakeActionLink({ - action: { - type: "bookmark", data: rec[0].get('value') - } - }); - } + rec && Common.Gateway.requestMakeActionLink({ + action: { + type: "bookmark", data: rec.get('value') + } + }); }, onRadioSort: function(field, newValue, eOpts) { diff --git a/apps/documenteditor/main/app/view/ChartSettings.js b/apps/documenteditor/main/app/view/ChartSettings.js index 3739a0205..c0eedc91d 100644 --- a/apps/documenteditor/main/app/view/ChartSettings.js +++ b/apps/documenteditor/main/app/view/ChartSettings.js @@ -167,7 +167,7 @@ define([ if (this._isChartStylesChanged) { if (rec) - this.cmbChartStyle.fillComboView(this.cmbChartStyle.menuPicker.getSelectedRec()[0],true); + this.cmbChartStyle.fillComboView(this.cmbChartStyle.menuPicker.getSelectedRec(),true); else this.cmbChartStyle.fillComboView(this.cmbChartStyle.menuPicker.store.at(0), true); } diff --git a/apps/documenteditor/main/app/view/HyperlinkSettingsDialog.js b/apps/documenteditor/main/app/view/HyperlinkSettingsDialog.js index ddd2328a2..34bdb9c88 100644 --- a/apps/documenteditor/main/app/view/HyperlinkSettingsDialog.js +++ b/apps/documenteditor/main/app/view/HyperlinkSettingsDialog.js @@ -252,7 +252,7 @@ define([ store.reset(arr); } var rec = this.internalList.getSelectedRec(); - this.btnOk.setDisabled(rec.length<1 || rec[0].get('level')==0 && rec[0].get('index')>0); + this.btnOk.setDisabled(!rec || rec.get('level')==0 && rec.get('index')>0); } else this.btnOk.setDisabled(false); @@ -338,14 +338,14 @@ define([ display = url; } else { var rec = this.internalList.getSelectedRec(); - if (rec.length>0) { - props.put_Bookmark(rec[0].get('name')); - if (rec[0].get('index')==0) + if (rec) { + props.put_Bookmark(rec.get('name')); + if (rec.get('index')==0) props.put_TopOfDocument(); - var para = rec[0].get('headingParagraph'); + var para = rec.get('headingParagraph'); if (para) props.put_Heading(para); - display = rec[0].get('name'); + display = rec.get('name'); } } @@ -382,7 +382,7 @@ define([ } } else { var rec = this.internalList.getSelectedRec(); - if (rec.length<1 || rec[0].get('level')==0 && rec[0].get('index')>0) + if (!rec || rec.get('level')==0 && rec.get('index')>0) return; } if (this.inputDisplay.checkValidate() !== true) { diff --git a/apps/documenteditor/main/app/view/ParagraphSettingsAdvanced.js b/apps/documenteditor/main/app/view/ParagraphSettingsAdvanced.js index dfa5b1de4..15bdcfbfc 100644 --- a/apps/documenteditor/main/app/view/ParagraphSettingsAdvanced.js +++ b/apps/documenteditor/main/app/view/ParagraphSettingsAdvanced.js @@ -1121,10 +1121,10 @@ define([ 'text!documenteditor/main/app/template/ParagraphSettingsAdvanced.tem removeTab: function(btn, eOpts){ var rec = this.tabList.getSelectedRec(); - if (rec.length>0) { + if (rec) { var store = this.tabList.store; - var idx = _.indexOf(store.models, rec[0]); - store.remove(rec[0]); + var idx = _.indexOf(store.models, rec); + store.remove(rec); if (idx>store.length-1) idx = store.length-1; if (store.length>0) { this.tabList.selectByIndex(idx); diff --git a/apps/documenteditor/main/app/view/TableSettings.js b/apps/documenteditor/main/app/view/TableSettings.js index a728cfc1d..ad1d1f911 100644 --- a/apps/documenteditor/main/app/view/TableSettings.js +++ b/apps/documenteditor/main/app/view/TableSettings.js @@ -473,7 +473,7 @@ define([ if (this._isTemplatesChanged) { if (rec) - this.cmbTableTemplate.fillComboView(this.cmbTableTemplate.menuPicker.getSelectedRec()[0],true); + this.cmbTableTemplate.fillComboView(this.cmbTableTemplate.menuPicker.getSelectedRec(),true); else this.cmbTableTemplate.fillComboView(this.cmbTableTemplate.menuPicker.store.at(0), true); } diff --git a/apps/presentationeditor/main/app/view/ChartSettings.js b/apps/presentationeditor/main/app/view/ChartSettings.js index 4dca67511..f742fb087 100644 --- a/apps/presentationeditor/main/app/view/ChartSettings.js +++ b/apps/presentationeditor/main/app/view/ChartSettings.js @@ -150,7 +150,7 @@ define([ if (this._isChartStylesChanged) { if (rec) - this.cmbChartStyle.fillComboView(this.cmbChartStyle.menuPicker.getSelectedRec()[0],true); + this.cmbChartStyle.fillComboView(this.cmbChartStyle.menuPicker.getSelectedRec(),true); else this.cmbChartStyle.fillComboView(this.cmbChartStyle.menuPicker.store.at(0), true); } diff --git a/apps/presentationeditor/main/app/view/ParagraphSettingsAdvanced.js b/apps/presentationeditor/main/app/view/ParagraphSettingsAdvanced.js index c29988007..8c16332fb 100644 --- a/apps/presentationeditor/main/app/view/ParagraphSettingsAdvanced.js +++ b/apps/presentationeditor/main/app/view/ParagraphSettingsAdvanced.js @@ -523,10 +523,10 @@ define([ 'text!presentationeditor/main/app/template/ParagraphSettingsAdvanced removeTab: function(btn, eOpts){ var rec = this.tabList.getSelectedRec(); - if (rec.length>0) { + if (rec) { var store = this.tabList.store; - var idx = _.indexOf(store.models, rec[0]); - store.remove(rec[0]); + var idx = _.indexOf(store.models, rec); + store.remove(rec); if (idx>store.length-1) idx = store.length-1; if (store.length>0) { this.tabList.selectByIndex(idx); diff --git a/apps/presentationeditor/main/app/view/TableSettings.js b/apps/presentationeditor/main/app/view/TableSettings.js index aa3ba303b..6944d3052 100644 --- a/apps/presentationeditor/main/app/view/TableSettings.js +++ b/apps/presentationeditor/main/app/view/TableSettings.js @@ -443,7 +443,7 @@ define([ if (this._isTemplatesChanged) { if (rec) - this.cmbTableTemplate.fillComboView(this.cmbTableTemplate.menuPicker.getSelectedRec()[0],true); + this.cmbTableTemplate.fillComboView(this.cmbTableTemplate.menuPicker.getSelectedRec(),true); else this.cmbTableTemplate.fillComboView(this.cmbTableTemplate.menuPicker.store.at(0), true); } diff --git a/apps/spreadsheeteditor/main/app/controller/PivotTable.js b/apps/spreadsheeteditor/main/app/controller/PivotTable.js index f31ff7be5..2e8e33f82 100644 --- a/apps/spreadsheeteditor/main/app/controller/PivotTable.js +++ b/apps/spreadsheeteditor/main/app/controller/PivotTable.js @@ -274,7 +274,7 @@ define([ if (this._isTemplatesChanged) { if (rec) - view.pivotStyles.fillComboView(view.pivotStyles.menuPicker.getSelectedRec()[0],true); + view.pivotStyles.fillComboView(view.pivotStyles.menuPicker.getSelectedRec(),true); else view.pivotStyles.fillComboView(view.pivotStyles.menuPicker.store.at(0), true); } diff --git a/apps/spreadsheeteditor/main/app/view/AutoFilterDialog.js b/apps/spreadsheeteditor/main/app/view/AutoFilterDialog.js index 71a36ce1b..e6fa99c44 100644 --- a/apps/spreadsheeteditor/main/app/view/AutoFilterDialog.js +++ b/apps/spreadsheeteditor/main/app/view/AutoFilterDialog.js @@ -1014,7 +1014,7 @@ define([ data.preventDefault(); data.stopPropagation(); - this.updateCellCheck(listView, listView.getSelectedRec()[0]); + this.updateCellCheck(listView, listView.getSelectedRec()); } else { Common.UI.DataView.prototype.onKeyDown.call(this.cellsList, e, data); diff --git a/apps/spreadsheeteditor/main/app/view/ChartSettings.js b/apps/spreadsheeteditor/main/app/view/ChartSettings.js index 68cf3afdf..5159c589b 100644 --- a/apps/spreadsheeteditor/main/app/view/ChartSettings.js +++ b/apps/spreadsheeteditor/main/app/view/ChartSettings.js @@ -182,7 +182,7 @@ define([ if (this._isChartStylesChanged) { if (rec) - this.cmbChartStyle.fillComboView(this.cmbChartStyle.menuPicker.getSelectedRec()[0],true); + this.cmbChartStyle.fillComboView(this.cmbChartStyle.menuPicker.getSelectedRec(),true); else this.cmbChartStyle.fillComboView(this.cmbChartStyle.menuPicker.store.at(0), true); } diff --git a/apps/spreadsheeteditor/main/app/view/ChartSettingsDlg.js b/apps/spreadsheeteditor/main/app/view/ChartSettingsDlg.js index 2e82f80d8..cb64f5a10 100644 --- a/apps/spreadsheeteditor/main/app/view/ChartSettingsDlg.js +++ b/apps/spreadsheeteditor/main/app/view/ChartSettingsDlg.js @@ -1433,7 +1433,7 @@ define([ 'text!spreadsheeteditor/main/app/template/ChartSettingsDlg.template' if (this.isChart) { var rec = this.mnuChartTypePicker.getSelectedRec(), - type = (rec && rec.length>0) ? rec[0].get('type') : this.currentChartType; + type = (rec) ? rec.get('type') : this.currentChartType; this.chartSettings.putType(type); @@ -1492,7 +1492,7 @@ define([ 'text!spreadsheeteditor/main/app/template/ChartSettingsDlg.template' var isvalid; if (!_.isEmpty(this.txtDataRange.getValue())) { var rec = this.mnuChartTypePicker.getSelectedRec(), - type = (rec && rec.length>0) ? rec[0].get('type') : this.currentChartType; + type = (rec) ? rec.get('type') : this.currentChartType; isvalid = this.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.Chart, this.txtDataRange.getValue(), true, this.cmbDataDirect.getValue()==0, type); if (isvalid == Asc.c_oAscError.ID.No) diff --git a/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js b/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js index e5e83fbd8..0d686fc36 100644 --- a/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js +++ b/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js @@ -218,9 +218,7 @@ define([ show: function() { Common.UI.BaseView.prototype.show.call(this,arguments); var item = this.viewSettingsPicker.getSelectedRec(); - if (item[0]) { - item[0].get('panel').show(); - } + item && item.get('panel').show(); }, setMode: function(mode) { diff --git a/apps/spreadsheeteditor/main/app/view/FormulaDialog.js b/apps/spreadsheeteditor/main/app/view/FormulaDialog.js index 2322c7cfe..a2e7747d6 100644 --- a/apps/spreadsheeteditor/main/app/view/FormulaDialog.js +++ b/apps/spreadsheeteditor/main/app/view/FormulaDialog.js @@ -71,7 +71,6 @@ define([ '', '
', - '', '
', '', diff --git a/apps/spreadsheeteditor/main/app/view/NameManagerDlg.js b/apps/spreadsheeteditor/main/app/view/NameManagerDlg.js index 8f7cf01c6..7e1db263b 100644 --- a/apps/spreadsheeteditor/main/app/view/NameManagerDlg.js +++ b/apps/spreadsheeteditor/main/app/view/NameManagerDlg.js @@ -284,8 +284,8 @@ define([ 'text!spreadsheeteditor/main/app/template/NameManagerDlg.template', var me = this, xy = me.$window.offset(), rec = this.rangeList.getSelectedRec(), - idx = _.indexOf(this.rangeList.store.models, rec[0]), - oldname = (isEdit && rec.length>0) ? new Asc.asc_CDefName(rec[0].get('name'), rec[0].get('range'), rec[0].get('scope'), rec[0].get('isTable'), undefined, undefined, undefined, true) : null; + idx = _.indexOf(this.rangeList.store.models, rec), + oldname = (isEdit && rec.length>0) ? new Asc.asc_CDefName(rec.get('name'), rec.get('range'), rec.get('scope'), rec.get('isTable'), undefined, undefined, undefined, true) : null; var win = new SSE.Views.NamedRangeEditDlg({ api: me.api, @@ -317,9 +317,9 @@ define([ 'text!spreadsheeteditor/main/app/template/NameManagerDlg.template', onDeleteRange: function () { var rec = this.rangeList.getSelectedRec(); - if (rec.length>0) { - this.currentNamedRange = _.indexOf(this.rangeList.store.models, rec[0]); - this.api.asc_delDefinedNames(new Asc.asc_CDefName(rec[0].get('name'), rec[0].get('range'), rec[0].get('scope'), rec[0].get('isTable'), undefined, undefined, undefined, true)); + if (rec) { + this.currentNamedRange = _.indexOf(this.rangeList.store.models, rec); + this.api.asc_delDefinedNames(new Asc.asc_CDefName(rec.get('name'), rec.get('range'), rec.get('scope'), rec.get('isTable'), undefined, undefined, undefined, true)); } }, diff --git a/apps/spreadsheeteditor/main/app/view/NamedRangePasteDlg.js b/apps/spreadsheeteditor/main/app/view/NamedRangePasteDlg.js index 54f86f95e..44fea2bc6 100644 --- a/apps/spreadsheeteditor/main/app/view/NamedRangePasteDlg.js +++ b/apps/spreadsheeteditor/main/app/view/NamedRangePasteDlg.js @@ -150,7 +150,7 @@ define([ getSettings: function() { var rec = this.rangeList.getSelectedRec(); - return (rec.length>0) ? (new Asc.asc_CDefName(rec[0].get('name'), rec[0].get('range'), rec[0].get('scope'), rec[0].get('isTable'), undefined, undefined, undefined, true)) : null; + return (rec) ? (new Asc.asc_CDefName(rec.get('name'), rec.get('range'), rec.get('scope'), rec.get('isTable'), undefined, undefined, undefined, true)) : null; }, onPrimary: function() { diff --git a/apps/spreadsheeteditor/main/app/view/ParagraphSettingsAdvanced.js b/apps/spreadsheeteditor/main/app/view/ParagraphSettingsAdvanced.js index 24cc31f88..1007f9a0f 100644 --- a/apps/spreadsheeteditor/main/app/view/ParagraphSettingsAdvanced.js +++ b/apps/spreadsheeteditor/main/app/view/ParagraphSettingsAdvanced.js @@ -522,10 +522,10 @@ define([ 'text!spreadsheeteditor/main/app/template/ParagraphSettingsAdvanced. removeTab: function(btn, eOpts){ var rec = this.tabList.getSelectedRec(); - if (rec.length>0) { + if (rec) { var store = this.tabList.store; - var idx = _.indexOf(store.models, rec[0]); - store.remove(rec[0]); + var idx = _.indexOf(store.models, rec); + store.remove(rec); if (idx>store.length-1) idx = store.length-1; if (store.length>0) { this.tabList.selectByIndex(idx); diff --git a/apps/spreadsheeteditor/main/app/view/Statusbar.js b/apps/spreadsheeteditor/main/app/view/Statusbar.js index 5f93bd61d..247da69e5 100644 --- a/apps/spreadsheeteditor/main/app/view/Statusbar.js +++ b/apps/spreadsheeteditor/main/app/view/Statusbar.js @@ -738,7 +738,7 @@ define([ if (this.options.handler) { this.options.handler.call(this, - event.currentTarget.attributes['result'].value, active[0].get('inindex')); + event.currentTarget.attributes['result'].value, active.get('inindex')); } this.close(); @@ -746,7 +746,7 @@ define([ onPrimary: function() { if (this.options.handler) { - this.options.handler.call(this, 'ok', this.listNames.getSelectedRec()[0].get('inindex')); + this.options.handler.call(this, 'ok', this.listNames.getSelectedRec().get('inindex')); } this.close(); diff --git a/apps/spreadsheeteditor/main/app/view/TableSettings.js b/apps/spreadsheeteditor/main/app/view/TableSettings.js index f3932796b..810f49060 100644 --- a/apps/spreadsheeteditor/main/app/view/TableSettings.js +++ b/apps/spreadsheeteditor/main/app/view/TableSettings.js @@ -407,7 +407,7 @@ define([ if (this._isTemplatesChanged) { if (rec) - this.cmbTableTemplate.fillComboView(this.cmbTableTemplate.menuPicker.getSelectedRec()[0],true); + this.cmbTableTemplate.fillComboView(this.cmbTableTemplate.menuPicker.getSelectedRec(),true); else this.cmbTableTemplate.fillComboView(this.cmbTableTemplate.menuPicker.store.at(0), true); }