Script.js 10 KB

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