GroupList.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. Ext.define('uas.panel.GroupList', {
  2. extend: 'Ext.view.View',
  3. xtype: 'grouplist',
  4. constructor: function (config) {
  5. var me = this, cfg = Ext.apply({}, config);
  6. if (cfg.groups) {
  7. var data = [];
  8. cfg.groups.forEach(function(group){
  9. if (group.items) {
  10. var index = 0;
  11. group.items.forEach(function(item){
  12. data.push({
  13. text: item.text,
  14. value: item.itemId,
  15. group: group.text,
  16. groupIndex: index++
  17. });
  18. });
  19. }
  20. });
  21. cfg.store = new Ext.data.Store({
  22. fields: ['text', 'value', 'group', 'groupIndex'],
  23. data: data
  24. });
  25. }
  26. me.callParent([
  27. cfg
  28. ]);
  29. },
  30. scrollable: true,
  31. baseCls: Ext.baseCSSPrefix + 'grouplist',
  32. itemCls: Ext.baseCSSPrefix + 'grouplist-item',
  33. trackOver: true,
  34. tpl: [
  35. '<div class="x-grouplist-innerCt"><tpl for=".">',
  36. '<tpl if="groupIndex == 0">',
  37. '<div class="x-grouplist-header">{group}</div>',
  38. '</tpl>',
  39. '<div role="option" class="x-grouplist-item">{text}</div>',
  40. '</tpl></div>',
  41. ],
  42. initComponent: function() {
  43. var me = this,
  44. baseCls = me.baseCls,
  45. itemCls = me.itemCls;
  46. me.selectedItemCls = baseCls + '-selected';
  47. if (me.trackOver) {
  48. me.overItemCls = baseCls + '-item-over';
  49. }
  50. me.itemSelector = '.' + itemCls;
  51. if (me.floating) {
  52. me.addCls(baseCls + '-floating');
  53. }
  54. me.callParent();
  55. },
  56. getItemValue: function (item) {
  57. return item.get('value');
  58. }
  59. });