Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 51 additions & 32 deletions ux/Multiselect.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,18 @@ Ext.define('Ux.field.Multiselect', {
},

applyClearButton: function(config) {
if (config) {
if (Ext.isBoolean(config)) {
config = {};
}

if (typeof config == "string") {
config = {
text: config
};
// ignore passed config
config = {
text: 'Select All',
ui: 'action',
height: '20px',
width: '40%',
listeners: {
tap: this.onClearButtonTap,
scope: this
}

Ext.applyIf(config, {
text: 'Clear',
ui: 'action',
height: '20px',
width: '40%',
listeners: {
tap: this.onClearButtonTap,
scope: this
}
});
}

};

return Ext.factory(config, 'Ext.Button', this.getClearButton());
},

Expand Down Expand Up @@ -104,9 +93,9 @@ Ext.define('Ux.field.Multiselect', {
}]
}, config));

if(listMode === 'SINGLE'){
me.listPanel.down('list').on('itemtap',me.onListTap,me);
}else{
me.listPanel.down('list').on('itemtap',me.onListTap,me);

if(listMode === 'MULTI'){
toolbar = me.listPanel.down('toolbar');
config = this.getClearButton();

Expand All @@ -122,24 +111,38 @@ Ext.define('Ux.field.Multiselect', {
* @private
*/
onListTap : function(list,index,target,record) {
this.setValue(record);
this.callParent();
if (this.getMode() === 'SINGLE') {
this.setValue(record);
this.callParent();
}
if (this.getClearButton()) {
if (this.listPanel.down('list').getSelectionCount() === this.getStore().getData().length) {
this.getClearButton().setText('Select None');
} else {
this.getClearButton().setText('Select All');
}
}
},
/**
* @private
*/
onDoneButtonTap: function(){
onDoneButtonTap: function() {
var records = this.listPanel.down('list').getSelection();
this.setValue(records);
this.superclass.onListTap.call(this);
},
/**
* @private
*/
onClearButtonTap: function(){
this.listPanel.down('list').deselectAll();
this.setValue(null);
this.superclass.onListTap.call(this);
onClearButtonTap: function() {
var num_of_options = this.getStore().getData().length;
if (this.listPanel.down('list').getSelectionCount() !== num_of_options) {
this.listPanel.down('list').selectAll();
this.getClearButton().setText('Select None');
} else {
this.listPanel.down('list').deselectAll();
this.getClearButton().setText('Select All');
}
},
/**
* @private
Expand Down Expand Up @@ -259,6 +262,14 @@ Ext.define('Ux.field.Multiselect', {
old = me.convertValue(oldValue,me.getDisplayField(),me.getValueField());

me.fireEvent('change', me, me.getValue(), old);

if (this.getClearButton()) {
if (this.getValue().length === this.getStore().getData().length) {
this.getClearButton().setText('Select None');
} else {
this.getClearButton().setText('Select All');
}
}
},
/**
* Shows the picker for the select field, whether that is a {@link Ext.picker.Picker} or a simple
Expand Down Expand Up @@ -295,6 +306,14 @@ Ext.define('Ux.field.Multiselect', {
list.deselectAll();
}

if (this.getClearButton()) {
if (this.getValue().length === this.getStore().getData().length) {
this.getClearButton().setText('Select None');
} else {
this.getClearButton().setText('Select All');
}
}

listPanel.showBy(me.getComponent(), (Ext.os.is.BlackBerry && Ext.os.version.getMajor() === 10) ? 't-b' : null);
},
/**
Expand Down