Script.js 10 KB

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