QueryImportModel.js 6.2 KB

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