Script.js 12 KB

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