QueryStatement.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. MWF.xApplication.Selector = MWF.xApplication.Selector || {};
  2. MWF.xDesktop.requireApp("Selector", "Person", null, false);
  3. MWF.xApplication.Selector.QueryStatement = new Class({
  4. Extends: MWF.xApplication.Selector.Person,
  5. options: {
  6. "style": "default",
  7. "count": 0,
  8. "title": "",
  9. "values": [],
  10. "names": [],
  11. "expand": false,
  12. "forceSearchInItem" : true,
  13. "viewEnable": ""
  14. },
  15. setInitTitle: function(){
  16. this.setOptions({"title": MWF.xApplication.Selector.LP.selectStatement});
  17. },
  18. _init : function(){
  19. this.selectType = "querystatement";
  20. this.className = "QueryStatement";
  21. },
  22. loadSelectItems: function(addToNext){
  23. var filter = typeOf(this.options.viewEnable) === "boolean" ? {
  24. viewEnable: this.options.viewEnable
  25. } : {};
  26. this.queryAction.listApplication(function(json){
  27. if (json.data.length){
  28. json.data.each(function(data){
  29. if (!data.statementList){
  30. this.queryAction.listStatement(data.id, filter,function(statementsJson){
  31. data.statementList = statementsJson.data;
  32. }.bind(this), null, false);
  33. }
  34. if (data.statementList && data.statementList.length){
  35. var category = this._newItemCategory(data, this, this.itemAreaNode);
  36. data.statementList.each(function(d){
  37. d.applicationName = data.name;
  38. var item = this._newItem(d, this, category.children);
  39. this.items.push(item);
  40. }.bind(this));
  41. }
  42. }.bind(this));
  43. }
  44. }.bind(this));
  45. },
  46. _scrollEvent: function(y){
  47. return true;
  48. },
  49. _getChildrenItemIds: function(data){
  50. return data.statementList || [];
  51. },
  52. _newItemCategory: function(data, selector, item, level){
  53. return new MWF.xApplication.Selector.QueryStatement.ItemCategory(data, selector, item, level)
  54. },
  55. _listItemByKey: function(callback, failure, key){
  56. return false;
  57. },
  58. _getItem: function(callback, failure, id, async){
  59. this.queryAction.getStatement(function(json){
  60. if (callback) callback.apply(this, [json]);
  61. }.bind(this), failure, ((typeOf(id)==="string") ? id : id.id), async);
  62. },
  63. _newItemSelected: function(data, selector, item){
  64. return new MWF.xApplication.Selector.QueryStatement.ItemSelected(data, selector, item)
  65. },
  66. _listItemByPinyin: function(callback, failure, key){
  67. return false;
  68. },
  69. _newItem: function(data, selector, container, level){
  70. return new MWF.xApplication.Selector.QueryStatement.Item(data, selector, container, level);
  71. }
  72. });
  73. MWF.xApplication.Selector.QueryStatement.Item = new Class({
  74. Extends: MWF.xApplication.Selector.Person.Item,
  75. _getShowName: function(){
  76. return this.data.name;
  77. },
  78. _setIcon: function(){
  79. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/default/icon/view.png)");
  80. },
  81. loadSubItem: function(){
  82. return false;
  83. },
  84. checkSelectedSingle: function(){
  85. var selectedItem = this.selector.options.values.filter(function(item, index){
  86. if (typeOf(item)==="object"){
  87. if( this.data.id && item.id ){
  88. return this.data.id === item.id;
  89. }else{
  90. return this.data.name === item.name;
  91. }
  92. //return (this.data.id === item.id) || (this.data.name === item.name) ;
  93. }
  94. //if (typeOf(item)==="object") return (this.data.id === item.id) || (this.data.name === item.name) ;
  95. if (typeOf(item)==="string") return (this.data.id === item) || (this.data.name === item);
  96. return false;
  97. }.bind(this));
  98. if (selectedItem.length){
  99. this.selectedSingle();
  100. }
  101. },
  102. checkSelected: function(){
  103. var selectedItem = this.selector.selectedItems.filter(function(item, index){
  104. if( item.data.id && this.data.id){
  105. return item.data.id === this.data.id;
  106. }else{
  107. return item.data.name === this.data.name;
  108. }
  109. //return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  110. }.bind(this));
  111. if (selectedItem.length){
  112. //selectedItem[0].item = this;
  113. selectedItem[0].addItem(this);
  114. this.selectedItem = selectedItem[0];
  115. this.setSelected();
  116. }
  117. }
  118. });
  119. MWF.xApplication.Selector.QueryStatement.ItemSelected = new Class({
  120. Extends: MWF.xApplication.Selector.Person.ItemSelected,
  121. _getShowName: function(){
  122. return this.data.name;
  123. },
  124. _setIcon: function(){
  125. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/default/icon/view.png)");
  126. },
  127. check: function(){
  128. if (this.selector.items.length){
  129. var items = this.selector.items.filter(function(item, index){
  130. //return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  131. if( item.data.id && this.data.id){
  132. return item.data.id === this.data.id;
  133. }else{
  134. return item.data.name === this.data.name;
  135. }
  136. }.bind(this));
  137. this.items = items;
  138. if (items.length){
  139. items.each(function(item){
  140. item.selectedItem = this;
  141. item.setSelected();
  142. }.bind(this));
  143. }
  144. }
  145. }
  146. });
  147. MWF.xApplication.Selector.QueryStatement.ItemCategory = new Class({
  148. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  149. _getShowName: function(){
  150. return this.data.name;
  151. },
  152. createNode: function(){
  153. this.node = new Element("div", {
  154. "styles": this.selector.css.selectorItemCategory_department
  155. }).inject(this.container);
  156. },
  157. _setIcon: function(){
  158. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/default/icon/applicationicon.png)");
  159. },
  160. _hasChild: function(){
  161. return (this.data.statementList && this.data.statementList.length);
  162. },
  163. check: function(){}
  164. });