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