[Common] DateView refactoring

This commit is contained in:
Julia Radzhabova 2019-06-27 14:18:01 +03:00
parent 7dd267c03e
commit 3bb1f0f7c4
21 changed files with 51 additions and 76 deletions

View file

@ -245,11 +245,7 @@ define([
var picker = this.menuPicker; var picker = this.menuPicker;
if (picker) { if (picker) {
var record = picker.getSelectedRec(); var record = picker.getSelectedRec();
this.fillComboView(record || picker.store.at(0), !!record, true);
if (record) {
record = record[0];
this.fillComboView(record || picker.store.at(0), !!record, true);
}
picker.onResize(); picker.onResize();
} }
@ -311,7 +307,7 @@ define([
}, },
onAfterHideMenu: function(e, isFromInputControl) { 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.showLast) ? this.menuPicker.showLastSelected() : this.menuPicker.deselectAll();
this.trigger('hide:after', this, e, isFromInputControl); this.trigger('hide:after', this, e, isFromInputControl);
}, },
@ -387,10 +383,7 @@ define([
var picker = this.menuPicker; var picker = this.menuPicker;
if (picker) { if (picker) {
var record = picker.getSelectedRec(); var record = picker.getSelectedRec();
if (record) { this.fillComboView(record || picker.store.at(0), false);
record = record[0];
this.fillComboView(record || picker.store.at(0), false);
}
} }
} }
}, },

View file

@ -389,17 +389,7 @@ define([
}, },
getSelectedRec: function() { getSelectedRec: function() {
if (this.multiSelect) { return (this.multiSelect) ? this.store.where({selected: true}) : this.store.findWhere({selected: true});
var items = [];
_.each(this.store.where({selected: true}), function(rec){
items.push(rec);
});
return items;
}
return this.store.where({selected: true});
}, },
onAddItem: function(record, store, opts) { onAddItem: function(record, store, opts) {
@ -601,7 +591,7 @@ define([
if (_.indexOf(this.moveKeys, data.keyCode)>-1 || data.keyCode==Common.UI.Keys.RETURN) { if (_.indexOf(this.moveKeys, data.keyCode)>-1 || data.keyCode==Common.UI.Keys.RETURN) {
data.preventDefault(); data.preventDefault();
data.stopPropagation(); data.stopPropagation();
var rec = this.getSelectedRec()[0]; var rec = this.getSelectedRec();
if (this.lastSelectedRec===null) if (this.lastSelectedRec===null)
this.lastSelectedRec = rec; this.lastSelectedRec = rec;
if (data.keyCode==Common.UI.Keys.RETURN) { if (data.keyCode==Common.UI.Keys.RETURN) {
@ -699,8 +689,7 @@ define([
this.scrollToRecord(this.lastSelectedRec); this.scrollToRecord(this.lastSelectedRec);
this.lastSelectedRec = null; this.lastSelectedRec = null;
} else { } else {
var rec = this.getSelectedRec()[0]; this.scrollToRecord(this.getSelectedRec());
if (rec) this.scrollToRecord(rec);
} }
}, },

View file

@ -314,9 +314,7 @@ define([
gotoBookmark: function(btn, eOpts){ gotoBookmark: function(btn, eOpts){
var rec = this.bookmarksList.getSelectedRec(); var rec = this.bookmarksList.getSelectedRec();
if (rec.length>0) { rec && this.props.asc_SelectBookmark(rec.get('value'));
this.props.asc_SelectBookmark(rec[0].get('value'));
}
}, },
addBookmark: function(btn, eOpts){ addBookmark: function(btn, eOpts){
@ -333,11 +331,11 @@ define([
deleteBookmark: function(btn, eOpts){ deleteBookmark: function(btn, eOpts){
var rec = this.bookmarksList.getSelectedRec(); var rec = this.bookmarksList.getSelectedRec();
if (rec.length>0) { if (rec) {
this.props.asc_RemoveBookmark(rec[0].get('value')); this.props.asc_RemoveBookmark(rec.get('value'));
var store = this.bookmarksList.store; var store = this.bookmarksList.store;
var idx = _.indexOf(store.models, rec[0]); var idx = _.indexOf(store.models, rec);
store.remove(rec[0]); store.remove(rec);
this.txtName.setValue(''); this.txtName.setValue('');
this.btnAdd.setDisabled(true); this.btnAdd.setDisabled(true);
this.btnGoto.setDisabled(true); this.btnGoto.setDisabled(true);
@ -350,13 +348,11 @@ define([
if (btn.cmpEl && btn.cmpEl.parent().hasClass('open')) return; if (btn.cmpEl && btn.cmpEl.parent().hasClass('open')) return;
var rec = this.bookmarksList.getSelectedRec(); var rec = this.bookmarksList.getSelectedRec();
if (rec.length>0) { rec && Common.Gateway.requestMakeActionLink({
Common.Gateway.requestMakeActionLink({ action: {
action: { type: "bookmark", data: rec.get('value')
type: "bookmark", data: rec[0].get('value') }
} });
});
}
}, },
onRadioSort: function(field, newValue, eOpts) { onRadioSort: function(field, newValue, eOpts) {

View file

@ -167,7 +167,7 @@ define([
if (this._isChartStylesChanged) { if (this._isChartStylesChanged) {
if (rec) if (rec)
this.cmbChartStyle.fillComboView(this.cmbChartStyle.menuPicker.getSelectedRec()[0],true); this.cmbChartStyle.fillComboView(this.cmbChartStyle.menuPicker.getSelectedRec(),true);
else else
this.cmbChartStyle.fillComboView(this.cmbChartStyle.menuPicker.store.at(0), true); this.cmbChartStyle.fillComboView(this.cmbChartStyle.menuPicker.store.at(0), true);
} }

View file

@ -252,7 +252,7 @@ define([
store.reset(arr); store.reset(arr);
} }
var rec = this.internalList.getSelectedRec(); 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 } else
this.btnOk.setDisabled(false); this.btnOk.setDisabled(false);
@ -338,14 +338,14 @@ define([
display = url; display = url;
} else { } else {
var rec = this.internalList.getSelectedRec(); var rec = this.internalList.getSelectedRec();
if (rec.length>0) { if (rec) {
props.put_Bookmark(rec[0].get('name')); props.put_Bookmark(rec.get('name'));
if (rec[0].get('index')==0) if (rec.get('index')==0)
props.put_TopOfDocument(); props.put_TopOfDocument();
var para = rec[0].get('headingParagraph'); var para = rec.get('headingParagraph');
if (para) if (para)
props.put_Heading(para); props.put_Heading(para);
display = rec[0].get('name'); display = rec.get('name');
} }
} }
@ -382,7 +382,7 @@ define([
} }
} else { } else {
var rec = this.internalList.getSelectedRec(); 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; return;
} }
if (this.inputDisplay.checkValidate() !== true) { if (this.inputDisplay.checkValidate() !== true) {

View file

@ -1121,10 +1121,10 @@ define([ 'text!documenteditor/main/app/template/ParagraphSettingsAdvanced.tem
removeTab: function(btn, eOpts){ removeTab: function(btn, eOpts){
var rec = this.tabList.getSelectedRec(); var rec = this.tabList.getSelectedRec();
if (rec.length>0) { if (rec) {
var store = this.tabList.store; var store = this.tabList.store;
var idx = _.indexOf(store.models, rec[0]); var idx = _.indexOf(store.models, rec);
store.remove(rec[0]); store.remove(rec);
if (idx>store.length-1) idx = store.length-1; if (idx>store.length-1) idx = store.length-1;
if (store.length>0) { if (store.length>0) {
this.tabList.selectByIndex(idx); this.tabList.selectByIndex(idx);

View file

@ -473,7 +473,7 @@ define([
if (this._isTemplatesChanged) { if (this._isTemplatesChanged) {
if (rec) if (rec)
this.cmbTableTemplate.fillComboView(this.cmbTableTemplate.menuPicker.getSelectedRec()[0],true); this.cmbTableTemplate.fillComboView(this.cmbTableTemplate.menuPicker.getSelectedRec(),true);
else else
this.cmbTableTemplate.fillComboView(this.cmbTableTemplate.menuPicker.store.at(0), true); this.cmbTableTemplate.fillComboView(this.cmbTableTemplate.menuPicker.store.at(0), true);
} }

View file

@ -150,7 +150,7 @@ define([
if (this._isChartStylesChanged) { if (this._isChartStylesChanged) {
if (rec) if (rec)
this.cmbChartStyle.fillComboView(this.cmbChartStyle.menuPicker.getSelectedRec()[0],true); this.cmbChartStyle.fillComboView(this.cmbChartStyle.menuPicker.getSelectedRec(),true);
else else
this.cmbChartStyle.fillComboView(this.cmbChartStyle.menuPicker.store.at(0), true); this.cmbChartStyle.fillComboView(this.cmbChartStyle.menuPicker.store.at(0), true);
} }

View file

@ -523,10 +523,10 @@ define([ 'text!presentationeditor/main/app/template/ParagraphSettingsAdvanced
removeTab: function(btn, eOpts){ removeTab: function(btn, eOpts){
var rec = this.tabList.getSelectedRec(); var rec = this.tabList.getSelectedRec();
if (rec.length>0) { if (rec) {
var store = this.tabList.store; var store = this.tabList.store;
var idx = _.indexOf(store.models, rec[0]); var idx = _.indexOf(store.models, rec);
store.remove(rec[0]); store.remove(rec);
if (idx>store.length-1) idx = store.length-1; if (idx>store.length-1) idx = store.length-1;
if (store.length>0) { if (store.length>0) {
this.tabList.selectByIndex(idx); this.tabList.selectByIndex(idx);

View file

@ -443,7 +443,7 @@ define([
if (this._isTemplatesChanged) { if (this._isTemplatesChanged) {
if (rec) if (rec)
this.cmbTableTemplate.fillComboView(this.cmbTableTemplate.menuPicker.getSelectedRec()[0],true); this.cmbTableTemplate.fillComboView(this.cmbTableTemplate.menuPicker.getSelectedRec(),true);
else else
this.cmbTableTemplate.fillComboView(this.cmbTableTemplate.menuPicker.store.at(0), true); this.cmbTableTemplate.fillComboView(this.cmbTableTemplate.menuPicker.store.at(0), true);
} }

View file

@ -274,7 +274,7 @@ define([
if (this._isTemplatesChanged) { if (this._isTemplatesChanged) {
if (rec) if (rec)
view.pivotStyles.fillComboView(view.pivotStyles.menuPicker.getSelectedRec()[0],true); view.pivotStyles.fillComboView(view.pivotStyles.menuPicker.getSelectedRec(),true);
else else
view.pivotStyles.fillComboView(view.pivotStyles.menuPicker.store.at(0), true); view.pivotStyles.fillComboView(view.pivotStyles.menuPicker.store.at(0), true);
} }

View file

@ -1014,7 +1014,7 @@ define([
data.preventDefault(); data.preventDefault();
data.stopPropagation(); data.stopPropagation();
this.updateCellCheck(listView, listView.getSelectedRec()[0]); this.updateCellCheck(listView, listView.getSelectedRec());
} else { } else {
Common.UI.DataView.prototype.onKeyDown.call(this.cellsList, e, data); Common.UI.DataView.prototype.onKeyDown.call(this.cellsList, e, data);

View file

@ -182,7 +182,7 @@ define([
if (this._isChartStylesChanged) { if (this._isChartStylesChanged) {
if (rec) if (rec)
this.cmbChartStyle.fillComboView(this.cmbChartStyle.menuPicker.getSelectedRec()[0],true); this.cmbChartStyle.fillComboView(this.cmbChartStyle.menuPicker.getSelectedRec(),true);
else else
this.cmbChartStyle.fillComboView(this.cmbChartStyle.menuPicker.store.at(0), true); this.cmbChartStyle.fillComboView(this.cmbChartStyle.menuPicker.store.at(0), true);
} }

View file

@ -1433,7 +1433,7 @@ define([ 'text!spreadsheeteditor/main/app/template/ChartSettingsDlg.template'
if (this.isChart) { if (this.isChart) {
var rec = this.mnuChartTypePicker.getSelectedRec(), 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); this.chartSettings.putType(type);
@ -1492,7 +1492,7 @@ define([ 'text!spreadsheeteditor/main/app/template/ChartSettingsDlg.template'
var isvalid; var isvalid;
if (!_.isEmpty(this.txtDataRange.getValue())) { if (!_.isEmpty(this.txtDataRange.getValue())) {
var rec = this.mnuChartTypePicker.getSelectedRec(), 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); 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) if (isvalid == Asc.c_oAscError.ID.No)

View file

@ -218,9 +218,7 @@ define([
show: function() { show: function() {
Common.UI.BaseView.prototype.show.call(this,arguments); Common.UI.BaseView.prototype.show.call(this,arguments);
var item = this.viewSettingsPicker.getSelectedRec(); var item = this.viewSettingsPicker.getSelectedRec();
if (item[0]) { item && item.get('panel').show();
item[0].get('panel').show();
}
}, },
setMode: function(mode) { setMode: function(mode) {

View file

@ -71,7 +71,6 @@ define([
'<label class="header">' + t.textGroupDescription + '</label>', '<label class="header">' + t.textGroupDescription + '</label>',
'<div id="formula-dlg-combo-group" class="input-group-nr" style="margin-top: 10px"/>', '<div id="formula-dlg-combo-group" class="input-group-nr" style="margin-top: 10px"/>',
'<label class="header" style="margin-top:10px">' + t.textListDescription + '</label>', '<label class="header" style="margin-top:10px">' + t.textListDescription + '</label>',
'<div id="formula-dlg-combo-functions" class="combo-functions"/>', '<div id="formula-dlg-combo-functions" class="combo-functions"/>',
'<label id="formula-dlg-args" style="margin-top: 7px">' + '</label>', '<label id="formula-dlg-args" style="margin-top: 7px">' + '</label>',

View file

@ -284,8 +284,8 @@ define([ 'text!spreadsheeteditor/main/app/template/NameManagerDlg.template',
var me = this, var me = this,
xy = me.$window.offset(), xy = me.$window.offset(),
rec = this.rangeList.getSelectedRec(), rec = this.rangeList.getSelectedRec(),
idx = _.indexOf(this.rangeList.store.models, rec[0]), idx = _.indexOf(this.rangeList.store.models, rec),
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; 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({ var win = new SSE.Views.NamedRangeEditDlg({
api: me.api, api: me.api,
@ -317,9 +317,9 @@ define([ 'text!spreadsheeteditor/main/app/template/NameManagerDlg.template',
onDeleteRange: function () { onDeleteRange: function () {
var rec = this.rangeList.getSelectedRec(); var rec = this.rangeList.getSelectedRec();
if (rec.length>0) { if (rec) {
this.currentNamedRange = _.indexOf(this.rangeList.store.models, rec[0]); this.currentNamedRange = _.indexOf(this.rangeList.store.models, rec);
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)); this.api.asc_delDefinedNames(new Asc.asc_CDefName(rec.get('name'), rec.get('range'), rec.get('scope'), rec.get('isTable'), undefined, undefined, undefined, true));
} }
}, },

View file

@ -150,7 +150,7 @@ define([
getSettings: function() { getSettings: function() {
var rec = this.rangeList.getSelectedRec(); 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() { onPrimary: function() {

View file

@ -522,10 +522,10 @@ define([ 'text!spreadsheeteditor/main/app/template/ParagraphSettingsAdvanced.
removeTab: function(btn, eOpts){ removeTab: function(btn, eOpts){
var rec = this.tabList.getSelectedRec(); var rec = this.tabList.getSelectedRec();
if (rec.length>0) { if (rec) {
var store = this.tabList.store; var store = this.tabList.store;
var idx = _.indexOf(store.models, rec[0]); var idx = _.indexOf(store.models, rec);
store.remove(rec[0]); store.remove(rec);
if (idx>store.length-1) idx = store.length-1; if (idx>store.length-1) idx = store.length-1;
if (store.length>0) { if (store.length>0) {
this.tabList.selectByIndex(idx); this.tabList.selectByIndex(idx);

View file

@ -738,7 +738,7 @@ define([
if (this.options.handler) { if (this.options.handler) {
this.options.handler.call(this, this.options.handler.call(this,
event.currentTarget.attributes['result'].value, active[0].get('inindex')); event.currentTarget.attributes['result'].value, active.get('inindex'));
} }
this.close(); this.close();
@ -746,7 +746,7 @@ define([
onPrimary: function() { onPrimary: function() {
if (this.options.handler) { 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(); this.close();

View file

@ -407,7 +407,7 @@ define([
if (this._isTemplatesChanged) { if (this._isTemplatesChanged) {
if (rec) if (rec)
this.cmbTableTemplate.fillComboView(this.cmbTableTemplate.menuPicker.getSelectedRec()[0],true); this.cmbTableTemplate.fillComboView(this.cmbTableTemplate.menuPicker.getSelectedRec(),true);
else else
this.cmbTableTemplate.fillComboView(this.cmbTableTemplate.menuPicker.store.at(0), true); this.cmbTableTemplate.fillComboView(this.cmbTableTemplate.menuPicker.store.at(0), true);
} }