CheckGroup.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /**
  2. * DB: CG
  3. * value以逗号隔开
  4. */
  5. Ext.define('erp.view.core.form.CheckGroup', {
  6. extend: 'Ext.form.FieldContainer',
  7. alias: 'widget.checkgroup',
  8. layout: 'hbox',
  9. height: 22,
  10. value: "",
  11. items: [],
  12. separator: ',',
  13. initComponent : function(){
  14. this.columnWidth = 1;
  15. this.callParent(arguments);
  16. var me = this;
  17. Ext.Ajax.request({
  18. url : basePath + 'common/getFieldsData.action',
  19. async: false,
  20. params: {
  21. caller: 'DbfindSetUI',
  22. fields: 'ds_whichdbfind,ds_likefield,ds_uifixedcondition',
  23. condition: 'ds_whichui=\'' + me.name + '\' AND ds_caller is null'
  24. },
  25. method : 'post',
  26. callback : function(options,success,response){
  27. var localJson = new Ext.decode(response.responseText);
  28. if(localJson.exceptionInfo){
  29. showError(localJson.exceptionInfo);return;
  30. }
  31. if(localJson.success){
  32. if(localJson.data != null){
  33. me.getFieldValues(localJson.data.ds_whichdbfind,
  34. localJson.data.ds_likefield, localJson.data.ds_uifixedcondition, me.name);
  35. }
  36. }
  37. }
  38. });
  39. },
  40. getFieldValues: function(caller, field, condition){
  41. var me = this;
  42. Ext.Ajax.request({
  43. url : basePath + 'common/getFieldDatas.action',
  44. async: false,
  45. params: {
  46. caller: caller,
  47. field: field,
  48. condition: condition
  49. },
  50. method : 'post',
  51. callback : function(options,success,response){
  52. var localJson = new Ext.decode(response.responseText);
  53. if(localJson.exceptionInfo){
  54. showError(localJson.exceptionInfo);return null;
  55. }
  56. if(localJson.success){
  57. if(localJson.data != null){
  58. me.setValue(localJson.data.replace(/#/g, me.separator));
  59. }
  60. } else {
  61. return;
  62. }
  63. }
  64. });
  65. },
  66. changeValue: function(){
  67. var me = this,
  68. items = Ext.ComponentQuery.query('checkbox[checked=true]');
  69. if(items.length > 0) {
  70. me.value = '';
  71. Ext.each(items, function(item){
  72. if(me.value != '') {
  73. me.value += ' OR ';
  74. }
  75. if(me.value ==''){
  76. me.value += item.boxLabel + "'";
  77. }else{
  78. me.value += me.name + "='" + item.boxLabel + "'";
  79. }
  80. });
  81. } else {
  82. me.value = null;
  83. }
  84. if(me.value != null){
  85. me.value = me.value.substring(0,me.value.length-1);
  86. }
  87. },
  88. listeners: {
  89. afterrender: function(){
  90. this.getEl().dom.childNodes[1].style.height = 22;
  91. this.getEl().dom.childNodes[1].style.overflow = 'hidden';
  92. }
  93. },
  94. reset: function(){
  95. },
  96. getValue: function(){
  97. },
  98. isValid: function(){
  99. return true;
  100. },
  101. setValue: function(value){
  102. var me = this;
  103. if(!Ext.isEmpty(value)){
  104. var arr = value.split(me.separator);
  105. Ext.each(arr, function(v, idx){
  106. me.insert(idx, {
  107. xtype: 'checkbox',
  108. boxLabel: v,
  109. name: me.name,
  110. flex: 1,
  111. listeners: {
  112. change: function(f){
  113. me.changeValue();
  114. }
  115. }
  116. });
  117. });
  118. }
  119. },
  120. clear: function(){
  121. this.removeAll();
  122. },
  123. checkValue: function(value){
  124. var me = this;
  125. if(!Ext.isEmpty(value)){
  126. var arr = value.split(me.separator),
  127. a;
  128. Ext.each(me.items.items, function(item){
  129. item.setValue(false);
  130. item.hide();
  131. });
  132. Ext.each(arr, function(v, idx){
  133. a = me.down('checkbox[boxLabel=' + v + ']');
  134. if(a) {
  135. a.show();
  136. }
  137. });
  138. }
  139. }
  140. });