Script.js 5.7 KB

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