Merge pull request #2013 from ONLYOFFICE/feature/multiselect-for-DataView
Multiselect for data view
This commit is contained in:
commit
fcba6435a9
|
@ -393,18 +393,36 @@ define([
|
|||
|
||||
if (suspendEvents)
|
||||
this.suspendEvents();
|
||||
|
||||
if (!this.multiSelect) {
|
||||
this.extremeSeletedRec = record;
|
||||
if (!this.multiSelect || ( !this.pressedShift && !this.pressedCtrl) || !this.currentSelectedRec || (this.pressedShift && this.currentSelectedRec == record)) {
|
||||
_.each(this.store.where({selected: true}), function(rec){
|
||||
rec.set({selected: false});
|
||||
});
|
||||
|
||||
if (record) {
|
||||
record.set({selected: true});
|
||||
this.currentSelectedRec = record;
|
||||
}
|
||||
} else {
|
||||
if (record)
|
||||
record.set({selected: !record.get('selected')});
|
||||
if (record) {
|
||||
if(this.pressedCtrl) {
|
||||
record.set({selected: !record.get('selected')});
|
||||
this.currentSelectedRec = record;
|
||||
}
|
||||
else if(this.pressedShift){
|
||||
var me =this;
|
||||
var inRange=false;
|
||||
_.each(me.store.models, function(rec){
|
||||
if(me.currentSelectedRec == rec || record == rec){
|
||||
inRange = !inRange;
|
||||
rec.set({selected: true});
|
||||
}
|
||||
else {
|
||||
rec.set({selected: (inRange)});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (suspendEvents)
|
||||
|
@ -708,13 +726,22 @@ define([
|
|||
onKeyDown: function (e, data) {
|
||||
if ( this.disabled ) return;
|
||||
if (data===undefined) data = e;
|
||||
if (_.indexOf(this.moveKeys, data.keyCode)>-1 || data.keyCode==Common.UI.Keys.RETURN) {
|
||||
|
||||
if(this.multiSelect) {
|
||||
if (data.keyCode == Common.UI.Keys.CTRL) {
|
||||
this.pressedCtrl = true;
|
||||
} else if (data.keyCode == Common.UI.Keys.SHIFT) {
|
||||
this.pressedShift = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (_.indexOf(this.moveKeys, data.keyCode)>-1 || data.keyCode==Common.UI.Keys.RETURN) {
|
||||
data.preventDefault();
|
||||
data.stopPropagation();
|
||||
var rec = this.getSelectedRec();
|
||||
if (this.lastSelectedRec===null)
|
||||
var rec =(this.multiSelect) ? this.extremeSeletedRec : this.getSelectedRec();
|
||||
if (this.lastSelectedRec === null)
|
||||
this.lastSelectedRec = rec;
|
||||
if (data.keyCode==Common.UI.Keys.RETURN) {
|
||||
if (data.keyCode == Common.UI.Keys.RETURN) {
|
||||
this.lastSelectedRec = null;
|
||||
if (this.selectedBeforeHideRec) // only for ComboDataView menuPicker
|
||||
rec = this.selectedBeforeHideRec;
|
||||
|
@ -724,6 +751,7 @@ define([
|
|||
if (this.parentMenu)
|
||||
this.parentMenu.hide();
|
||||
} else {
|
||||
this.pressedCtrl=false;
|
||||
var idx = _.indexOf(this.store.models, rec);
|
||||
if (idx<0) {
|
||||
if (data.keyCode==Common.UI.Keys.LEFT) {
|
||||
|
@ -804,12 +832,20 @@ define([
|
|||
}
|
||||
},
|
||||
|
||||
onKeyUp: function(e){
|
||||
if(e.keyCode == Common.UI.Keys.SHIFT)
|
||||
this.pressedShift = false;
|
||||
if(e.keyCode == Common.UI.Keys.CTRL)
|
||||
this.pressedCtrl = false;
|
||||
},
|
||||
|
||||
attachKeyEvents: function() {
|
||||
if (this.enableKeyEvents && this.handleSelect) {
|
||||
var el = $(this.el).find('.inner').addBack().filter('.inner');
|
||||
el.addClass('canfocused');
|
||||
el.attr('tabindex', this.tabindex.toString());
|
||||
el.on((this.parentMenu && this.useBSKeydown) ? 'dataview:keydown' : 'keydown', _.bind(this.onKeyDown, this));
|
||||
el.on((this.parentMenu && this.useBSKeydown) ? 'dataview:keyup' : 'keyup', _.bind(this.onKeyUp, this));
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -819,7 +855,11 @@ define([
|
|||
this.scrollToRecord(this.lastSelectedRec);
|
||||
this.lastSelectedRec = null;
|
||||
} else {
|
||||
this.scrollToRecord(this.getSelectedRec());
|
||||
var selectedRec = this.getSelectedRec();
|
||||
if (!this.multiSelect)
|
||||
this.scrollToRecord(selectedRec);
|
||||
else if(selectedRec && selectedRec.length > 0)
|
||||
this.scrollToRecord(selectedRec[selectedRec.length - 1]);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -86,6 +86,7 @@ define([ 'text!spreadsheeteditor/main/app/template/WatchDialog.template',
|
|||
|
||||
this.watchList = new Common.UI.ListView({
|
||||
el: $('#watch-dialog-list', this.$window),
|
||||
multiSelect: true,
|
||||
store: new Common.UI.DataViewStore(),
|
||||
simpleAddMode: true,
|
||||
itemTemplate: _.template([
|
||||
|
@ -191,7 +192,8 @@ define([ 'text!spreadsheeteditor/main/app/template/WatchDialog.template',
|
|||
if (this._deletedIndex!==undefined) {
|
||||
var store = this.watchList.store;
|
||||
(store.length>0) && this.watchList.selectByIndex(this._deletedIndex<store.length ? this._deletedIndex : store.length-1);
|
||||
this.watchList.scrollToRecord(this.watchList.getSelectedRec());
|
||||
var selectedRec = this.watchList.getSelectedRec();
|
||||
(selectedRec && selectedRec.length > 0) && this.watchList.scrollToRecord(selectedRec[0]);
|
||||
this._fromKeyDown && this.watchList.focus();
|
||||
this._fromKeyDown = false;
|
||||
this._deletedIndex=undefined;
|
||||
|
@ -228,10 +230,15 @@ define([ 'text!spreadsheeteditor/main/app/template/WatchDialog.template',
|
|||
},
|
||||
|
||||
onDeleteWatch: function() {
|
||||
var me = this;
|
||||
var rec = this.watchList.getSelectedRec();
|
||||
if (rec) {
|
||||
this._deletedIndex = this.watchList.store.indexOf(rec);
|
||||
this.api.asc_deleteCellWatches([rec.get('props')]);
|
||||
var props=[];
|
||||
_.each(rec, function (r, i) {
|
||||
me._deletedIndex = me.watchList.store.indexOf(r)-props.length;
|
||||
props[i] =r.get('props');
|
||||
});
|
||||
this.api.asc_deleteCellWatches(props);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -254,7 +261,8 @@ define([ 'text!spreadsheeteditor/main/app/template/WatchDialog.template',
|
|||
},
|
||||
|
||||
updateButtons: function() {
|
||||
this.btnDelete.setDisabled(this.watchList.store.length<1 || !this.watchList.getSelectedRec());
|
||||
var rec = this.watchList.getSelectedRec();
|
||||
this.btnDelete.setDisabled(!(rec && rec.length>0));
|
||||
this.watchList.scroller && this.watchList.scroller.update({alwaysVisibleY: true});
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in a new issue