Script.js 7.1 KB

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