You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

349 lines
14 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. /*
  16. * Note that this control will most likely remain as an example, and not as a core Ext form
  17. * control. However, the API will be changing in a future release and so should not yet be
  18. * treated as a final, stable API at this time.
  19. */
  20. /**
  21. * @class Ext.ux.form.ItemSelector
  22. * @extends Ext.form.Field
  23. * A control that allows selection of between two Ext.ux.form.MultiSelect controls.
  24. *
  25. * @history
  26. * 2008-06-19 bpm Original code contributed by Toby Stuart (with contributions from Robert Williams)
  27. *
  28. * @constructor
  29. * Create a new ItemSelector
  30. * @param {Object} config Configuration options
  31. * @xtype itemselector
  32. */
  33. Ext.ux.form.ItemSelector = Ext.extend(Ext.form.Field, {
  34. hideNavIcons:false,
  35. imagePath:"",
  36. iconUp:"up2.gif",
  37. iconDown:"down2.gif",
  38. iconLeft:"left2.gif",
  39. iconRight:"right2.gif",
  40. iconTop:"top2.gif",
  41. iconBottom:"bottom2.gif",
  42. drawUpIcon:true,
  43. drawDownIcon:true,
  44. drawLeftIcon:true,
  45. drawRightIcon:true,
  46. drawTopIcon:true,
  47. drawBotIcon:true,
  48. delimiter:',',
  49. bodyStyle:null,
  50. border:false,
  51. defaultAutoCreate:{tag: "div"},
  52. /**
  53. * @cfg {Array} multiselects An array of {@link Ext.ux.form.MultiSelect} config objects, with at least all required parameters (e.g., store)
  54. */
  55. multiselects:null,
  56. initComponent: function(){
  57. Ext.ux.form.ItemSelector.superclass.initComponent.call(this);
  58. this.addEvents({
  59. 'rowdblclick' : true,
  60. 'change' : true
  61. });
  62. },
  63. onRender: function(ct, position){
  64. Ext.ux.form.ItemSelector.superclass.onRender.call(this, ct, position);
  65. // Internal default configuration for both multiselects
  66. var msConfig = [{
  67. legend: 'Available',
  68. draggable: true,
  69. droppable: true,
  70. width: 100,
  71. height: 100
  72. },{
  73. legend: 'Selected',
  74. droppable: true,
  75. draggable: true,
  76. width: 100,
  77. height: 100
  78. }];
  79. this.fromMultiselect = new Ext.ux.form.MultiSelect(Ext.applyIf(this.multiselects[0], msConfig[0]));
  80. this.fromMultiselect.on('dblclick', this.onRowDblClick, this);
  81. this.toMultiselect = new Ext.ux.form.MultiSelect(Ext.applyIf(this.multiselects[1], msConfig[1]));
  82. this.toMultiselect.on('dblclick', this.onRowDblClick, this);
  83. var p = new Ext.Panel({
  84. bodyStyle:this.bodyStyle,
  85. border:this.border,
  86. layout:"table",
  87. layoutConfig:{columns:3}
  88. });
  89. p.add(this.fromMultiselect);
  90. var icons = new Ext.Panel({header:false});
  91. p.add(icons);
  92. p.add(this.toMultiselect);
  93. p.render(this.el);
  94. icons.el.down('.'+icons.bwrapCls).remove();
  95. // ICON HELL!!!
  96. if (this.imagePath!="" && this.imagePath.charAt(this.imagePath.length-1)!="/")
  97. this.imagePath+="/";
  98. this.iconUp = this.imagePath + (this.iconUp || 'up2.gif');
  99. this.iconDown = this.imagePath + (this.iconDown || 'down2.gif');
  100. this.iconLeft = this.imagePath + (this.iconLeft || 'left2.gif');
  101. this.iconRight = this.imagePath + (this.iconRight || 'right2.gif');
  102. this.iconTop = this.imagePath + (this.iconTop || 'top2.gif');
  103. this.iconBottom = this.imagePath + (this.iconBottom || 'bottom2.gif');
  104. var el=icons.getEl();
  105. this.toTopIcon = el.createChild({tag:'img', src:this.iconTop, style:{cursor:'pointer', margin:'2px'}});
  106. el.createChild({tag: 'br'});
  107. this.upIcon = el.createChild({tag:'img', src:this.iconUp, style:{cursor:'pointer', margin:'2px'}});
  108. el.createChild({tag: 'br'});
  109. this.addIcon = el.createChild({tag:'img', src:this.iconRight, style:{cursor:'pointer', margin:'2px'}});
  110. el.createChild({tag: 'br'});
  111. this.removeIcon = el.createChild({tag:'img', src:this.iconLeft, style:{cursor:'pointer', margin:'2px'}});
  112. el.createChild({tag: 'br'});
  113. this.downIcon = el.createChild({tag:'img', src:this.iconDown, style:{cursor:'pointer', margin:'2px'}});
  114. el.createChild({tag: 'br'});
  115. this.toBottomIcon = el.createChild({tag:'img', src:this.iconBottom, style:{cursor:'pointer', margin:'2px'}});
  116. this.toTopIcon.on('click', this.toTop, this);
  117. this.upIcon.on('click', this.up, this);
  118. this.downIcon.on('click', this.down, this);
  119. this.toBottomIcon.on('click', this.toBottom, this);
  120. this.addIcon.on('click', this.fromTo, this);
  121. this.removeIcon.on('click', this.toFrom, this);
  122. if (!this.drawUpIcon || this.hideNavIcons) { this.upIcon.dom.style.display='none'; }
  123. if (!this.drawDownIcon || this.hideNavIcons) { this.downIcon.dom.style.display='none'; }
  124. if (!this.drawLeftIcon || this.hideNavIcons) { this.addIcon.dom.style.display='none'; }
  125. if (!this.drawRightIcon || this.hideNavIcons) { this.removeIcon.dom.style.display='none'; }
  126. if (!this.drawTopIcon || this.hideNavIcons) { this.toTopIcon.dom.style.display='none'; }
  127. if (!this.drawBotIcon || this.hideNavIcons) { this.toBottomIcon.dom.style.display='none'; }
  128. var tb = p.body.first();
  129. this.el.setWidth(p.body.first().getWidth());
  130. p.body.removeClass();
  131. this.hiddenName = this.name;
  132. var hiddenTag = {tag: "input", type: "hidden", value: "", name: this.name};
  133. this.hiddenField = this.el.createChild(hiddenTag);
  134. },
  135. doLayout: function(){
  136. if(this.rendered){
  137. this.fromMultiselect.fs.doLayout();
  138. this.toMultiselect.fs.doLayout();
  139. }
  140. },
  141. afterRender: function(){
  142. Ext.ux.form.ItemSelector.superclass.afterRender.call(this);
  143. this.toStore = this.toMultiselect.store;
  144. this.toStore.on('add', this.valueChanged, this);
  145. this.toStore.on('remove', this.valueChanged, this);
  146. this.toStore.on('load', this.valueChanged, this);
  147. this.valueChanged(this.toStore);
  148. },
  149. toTop : function() {
  150. var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
  151. var records = [];
  152. if (selectionsArray.length > 0) {
  153. selectionsArray.sort();
  154. for (var i=0; i<selectionsArray.length; i++) {
  155. record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
  156. records.push(record);
  157. }
  158. selectionsArray = [];
  159. for (var i=records.length-1; i>-1; i--) {
  160. record = records[i];
  161. this.toMultiselect.view.store.remove(record);
  162. this.toMultiselect.view.store.insert(0, record);
  163. selectionsArray.push(((records.length - 1) - i));
  164. }
  165. }
  166. this.toMultiselect.view.refresh();
  167. this.toMultiselect.view.select(selectionsArray);
  168. },
  169. toBottom : function() {
  170. var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
  171. var records = [];
  172. if (selectionsArray.length > 0) {
  173. selectionsArray.sort();
  174. for (var i=0; i<selectionsArray.length; i++) {
  175. record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
  176. records.push(record);
  177. }
  178. selectionsArray = [];
  179. for (var i=0; i<records.length; i++) {
  180. record = records[i];
  181. this.toMultiselect.view.store.remove(record);
  182. this.toMultiselect.view.store.add(record);
  183. selectionsArray.push((this.toMultiselect.view.store.getCount()) - (records.length - i));
  184. }
  185. }
  186. this.toMultiselect.view.refresh();
  187. this.toMultiselect.view.select(selectionsArray);
  188. },
  189. up : function() {
  190. var record = null;
  191. var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
  192. selectionsArray.sort();
  193. var newSelectionsArray = [];
  194. if (selectionsArray.length > 0) {
  195. for (var i=0; i<selectionsArray.length; i++) {
  196. record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
  197. if ((selectionsArray[i] - 1) >= 0) {
  198. this.toMultiselect.view.store.remove(record);
  199. this.toMultiselect.view.store.insert(selectionsArray[i] - 1, record);
  200. newSelectionsArray.push(selectionsArray[i] - 1);
  201. }
  202. }
  203. this.toMultiselect.view.refresh();
  204. this.toMultiselect.view.select(newSelectionsArray);
  205. }
  206. },
  207. down : function() {
  208. var record = null;
  209. var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
  210. selectionsArray.sort();
  211. selectionsArray.reverse();
  212. var newSelectionsArray = [];
  213. if (selectionsArray.length > 0) {
  214. for (var i=0; i<selectionsArray.length; i++) {
  215. record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
  216. if ((selectionsArray[i] + 1) < this.toMultiselect.view.store.getCount()) {
  217. this.toMultiselect.view.store.remove(record);
  218. this.toMultiselect.view.store.insert(selectionsArray[i] + 1, record);
  219. newSelectionsArray.push(selectionsArray[i] + 1);
  220. }
  221. }
  222. this.toMultiselect.view.refresh();
  223. this.toMultiselect.view.select(newSelectionsArray);
  224. }
  225. },
  226. fromTo : function() {
  227. var selectionsArray = this.fromMultiselect.view.getSelectedIndexes();
  228. var records = [];
  229. if (selectionsArray.length > 0) {
  230. for (var i=0; i<selectionsArray.length; i++) {
  231. record = this.fromMultiselect.view.store.getAt(selectionsArray[i]);
  232. records.push(record);
  233. }
  234. if(!this.allowDup)selectionsArray = [];
  235. for (var i=0; i<records.length; i++) {
  236. record = records[i];
  237. if(this.allowDup){
  238. var x=new Ext.data.Record();
  239. record.id=x.id;
  240. delete x;
  241. this.toMultiselect.view.store.add(record);
  242. }else{
  243. this.fromMultiselect.view.store.remove(record);
  244. this.toMultiselect.view.store.add(record);
  245. selectionsArray.push((this.toMultiselect.view.store.getCount() - 1));
  246. }
  247. }
  248. }
  249. this.toMultiselect.view.refresh();
  250. this.fromMultiselect.view.refresh();
  251. var si = this.toMultiselect.store.sortInfo;
  252. if(si){
  253. this.toMultiselect.store.sort(si.field, si.direction);
  254. }
  255. this.toMultiselect.view.select(selectionsArray);
  256. },
  257. toFrom : function() {
  258. var selectionsArray = this.toMultiselect.view.getSelectedIndexes();
  259. var records = [];
  260. if (selectionsArray.length > 0) {
  261. for (var i=0; i<selectionsArray.length; i++) {
  262. record = this.toMultiselect.view.store.getAt(selectionsArray[i]);
  263. records.push(record);
  264. }
  265. selectionsArray = [];
  266. for (var i=0; i<records.length; i++) {
  267. record = records[i];
  268. this.toMultiselect.view.store.remove(record);
  269. if(!this.allowDup){
  270. this.fromMultiselect.view.store.add(record);
  271. selectionsArray.push((this.fromMultiselect.view.store.getCount() - 1));
  272. }
  273. }
  274. }
  275. this.fromMultiselect.view.refresh();
  276. this.toMultiselect.view.refresh();
  277. var si = this.fromMultiselect.store.sortInfo;
  278. if (si){
  279. this.fromMultiselect.store.sort(si.field, si.direction);
  280. }
  281. this.fromMultiselect.view.select(selectionsArray);
  282. },
  283. valueChanged: function(store) {
  284. var record = null;
  285. var values = [];
  286. for (var i=0; i<store.getCount(); i++) {
  287. record = store.getAt(i);
  288. values.push(record.get(this.toMultiselect.valueField));
  289. }
  290. this.hiddenField.dom.value = values.join(this.delimiter);
  291. this.fireEvent('change', this, this.getValue(), this.hiddenField.dom.value);
  292. },
  293. getValue : function() {
  294. return this.hiddenField.dom.value;
  295. },
  296. onRowDblClick : function(vw, index, node, e) {
  297. if (vw == this.toMultiselect.view){
  298. this.toFrom();
  299. } else if (vw == this.fromMultiselect.view) {
  300. this.fromTo();
  301. }
  302. return this.fireEvent('rowdblclick', vw, index, node, e);
  303. },
  304. reset: function(){
  305. range = this.toMultiselect.store.getRange();
  306. this.toMultiselect.store.removeAll();
  307. this.fromMultiselect.store.add(range);
  308. var si = this.fromMultiselect.store.sortInfo;
  309. if (si){
  310. this.fromMultiselect.store.sort(si.field, si.direction);
  311. }
  312. this.valueChanged(this.toMultiselect.store);
  313. }
  314. });
  315. Ext.reg('itemselector', Ext.ux.form.ItemSelector);
  316. //backwards compat
  317. Ext.ux.ItemSelector = Ext.ux.form.ItemSelector;