Script.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. "appType" : ["process","portal"],
  12. "expand": false,
  13. "forceSearchInItem" : true
  14. },
  15. loadSelectItems: function(addToNext){
  16. var json = {};
  17. this.options.appType.each( function (type) {
  18. var container = new Element("div").inject(this.itemAreaNode);
  19. var action;
  20. if( type === "process" ){
  21. action = o2.Actions.load("x_processplatform_assemble_designer").ScriptAction.listPaging;
  22. }else if( type === "portal" ){
  23. action = o2.Actions.load("x_portal_assemble_designer").ScriptAction.listPaging;
  24. }else if( type === "cms" ){
  25. action = o2.Actions.load("x_cms_assemble_control").ScriptAction.listPaging;
  26. }
  27. var json = {};
  28. var array = [];
  29. action(1, 1000, {}, function( scriptJson ) {
  30. scriptJson.data.each(function (script) {
  31. var appName = script.portalName || script.applicationName || script.appName;
  32. var appId = script.portal || script.application || script.appId;
  33. if (!json[appId]) {
  34. json[appId] = {
  35. name: appName,
  36. applicationName: appName,
  37. appName: appName,
  38. application: appId,
  39. appId: appId
  40. };
  41. json[appId].scriptList = [];
  42. }
  43. script.appName = appName;
  44. script.appId = appId;
  45. script.appType = type;
  46. script.type = "script";
  47. json[appId].scriptList.push(script)
  48. }.bind(this));
  49. for (var application in json) {
  50. if (json[application].scriptList && json[application].scriptList.length) {
  51. array.push(json[application]);
  52. }
  53. }
  54. if( this.options.appType.length === 1 ){
  55. array.each( function (data) {
  56. var category = this._newItemCategory(data, this, container);
  57. }.bind(this))
  58. }else{
  59. var category = this._newItemCategory({
  60. name: MWF.xApplication.Selector.LP.appType[type],
  61. id: type,
  62. applicationList: array
  63. }, this, container);
  64. }
  65. }.bind(this))
  66. }.bind(this));
  67. },
  68. _scrollEvent: function(y){
  69. return true;
  70. },
  71. _getChildrenItemIds: function(data){
  72. return data.scriptList || [];
  73. },
  74. _newItemCategory: function(data, selector, item, level){
  75. return new MWF.xApplication.Selector.Script.ItemCategory(data, selector, item, level)
  76. },
  77. _listItemByKey: function(callback, failure, key){
  78. return false;
  79. },
  80. _getItem: function(callback, failure, id, async){
  81. this.queryAction.getTable(function(json){
  82. if (callback) callback.apply(this, [json]);
  83. }.bind(this), failure, ((typeOf(id)==="string") ? id : id.id), async);
  84. },
  85. _newItemSelected: function(data, selector, item){
  86. return new MWF.xApplication.Selector.Script.ItemSelected(data, selector, item)
  87. },
  88. _listItemByPinyin: function(callback, failure, key){
  89. return false;
  90. },
  91. _newItem: function(data, selector, container, level){
  92. return new MWF.xApplication.Selector.Script.Item(data, selector, container, level);
  93. }
  94. });
  95. MWF.xApplication.Selector.Script.Item = new Class({
  96. Extends: MWF.xApplication.Selector.Person.Item,
  97. _getShowName: function(){
  98. return this.data.name;
  99. },
  100. _setIcon: function(){
  101. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/default/icon/attr.png)");
  102. },
  103. loadSubItem: function(){
  104. return false;
  105. },
  106. checkSelectedSingle: function(){
  107. var selectedItem = this.selector.options.values.filter(function(item, index){
  108. if (typeOf(item)==="object"){
  109. if( this.data.id && item.id ){
  110. return this.data.id === item.id;
  111. }
  112. //return (this.data.id === item.id) || (this.data.name === item.name) ;
  113. }
  114. //if (typeOf(item)==="object") return (this.data.id === item.id) || (this.data.name === item.name) ;
  115. if (typeOf(item)==="string") return (this.data.id === item) || (this.data.name === item);
  116. return false;
  117. }.bind(this));
  118. if (selectedItem.length){
  119. this.selectedSingle();
  120. }
  121. },
  122. checkSelected: function(){
  123. var selectedItem = this.selector.selectedItems.filter(function(item, index){
  124. if( item.data.id && this.data.id){
  125. return item.data.id === this.data.id;
  126. }
  127. //return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  128. }.bind(this));
  129. if (selectedItem.length){
  130. //selectedItem[0].item = this;
  131. selectedItem[0].addItem(this);
  132. this.selectedItem = selectedItem[0];
  133. this.setSelected();
  134. }
  135. }
  136. });
  137. MWF.xApplication.Selector.Script.ItemSelected = new Class({
  138. Extends: MWF.xApplication.Selector.Person.ItemSelected,
  139. _getShowName: function(){
  140. return this.data.name;
  141. },
  142. _setIcon: function(){
  143. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/default/icon/attr.png)");
  144. },
  145. check: function(){
  146. if (this.selector.items.length){
  147. var items = this.selector.items.filter(function(item, index){
  148. //return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  149. if( item.data.id && this.data.id){
  150. return item.data.id === this.data.id;
  151. }
  152. }.bind(this));
  153. this.items = items;
  154. if (items.length){
  155. items.each(function(item){
  156. item.selectedItem = this;
  157. item.setSelected();
  158. }.bind(this));
  159. }
  160. }
  161. }
  162. });
  163. MWF.xApplication.Selector.Script.ItemCategory = new Class({
  164. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  165. clickItem: function (callback) {
  166. if (this._hasChild() ) {
  167. var firstLoaded = !this.loaded;
  168. this.loadSub(function () {
  169. if (firstLoaded && this._hasChild() ) {
  170. if (!this.selector.isFlatCategory) {
  171. this.children.setStyles({"display": "block", "height": "auto"});
  172. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  173. this.isExpand = true;
  174. }
  175. // this.checkSelectAll();
  176. } else {
  177. var display = this.children.getStyle("display");
  178. if (display === "none") {
  179. // this.selector.fireEvent("expand", [this] );
  180. this.children.setStyles({"display": "block", "height": "auto"});
  181. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  182. this.isExpand = true;
  183. } else {
  184. // this.selector.fireEvent("collapse", [this] );
  185. this.children.setStyles({"display": "none", "height": "0px"});
  186. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
  187. this.isExpand = false;
  188. }
  189. }
  190. if (callback) callback();
  191. }.bind(this));
  192. }
  193. },
  194. loadSub: function (callback) {
  195. if (!this.loaded) {
  196. if( this.data.scriptList ){
  197. this.data.scriptList.each(function (subItem, index) {
  198. var item = this.selector._newItem(subItem, this.selector, this.children, this.level + 1, this);
  199. this.selector.items.push(item);
  200. if(this.subItems)this.subItems.push( item );
  201. }.bind(this));
  202. }
  203. if ( this.data.applicationList ) {
  204. this.data.applicationList.each(function (subCategory, index) {
  205. var category = this.selector._newItemCategory(subCategory, this.selector, this.children, this.level + 1, this);
  206. this.subCategorys.push( category );
  207. }.bind(this));
  208. }
  209. this.loaded = true;
  210. if (callback) callback();
  211. } else {
  212. if (callback) callback();
  213. }
  214. },
  215. _getShowName: function(){
  216. return this.data.name;
  217. },
  218. _getTtiteText: function () {
  219. return this.data.name;
  220. },
  221. createNode: function(){
  222. this.node = new Element("div", {
  223. "styles": this.selector.css.selectorItemCategory_department
  224. }).inject(this.container);
  225. },
  226. _setIcon: function(){
  227. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/default/icon/applicationicon.png)");
  228. },
  229. _hasChild: function(){
  230. return ( this.data.scriptList && this.data.scriptList.length ) ||
  231. ( this.data.applicationList && this.data.applicationList.length);
  232. },
  233. afterLoad: function(){
  234. if ( this._hasChild() ){
  235. this.clickItem();
  236. }
  237. },
  238. check: function(){}
  239. });