Main.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. MWF.xApplication.FindDesigner.options.multitask = false;
  2. MWF.xApplication.FindDesigner.Main = new Class({
  3. Extends: MWF.xApplication.Common.Main,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "name": "FindDesigner",
  8. "mvcStyle": "style.css",
  9. "icon": "icon.png",
  10. "width": "1200",
  11. "height": "800",
  12. "isResize": true,
  13. "isMax": true,
  14. "layout": {
  15. "type": "leftRight",
  16. "percent": 0.3
  17. },
  18. "title": MWF.xApplication.FindDesigner.LP.title
  19. },
  20. onQueryLoad: function(){
  21. this.lp = MWF.xApplication.FindDesigner.LP;
  22. this.filterOption = {
  23. "keyword": "",
  24. "designerTypes": [],
  25. "caseSensitive": false,
  26. "matchWholeWord": false,
  27. "matchRegExp": false,
  28. "moduleList": []
  29. }
  30. this.selectedModules = [];
  31. this.selectedRange = [];
  32. o2.UD.getDataJson("findDesignerLayout", function(json){
  33. this.setOptions(json);
  34. }.bind(this), false);
  35. },
  36. loadApplication: function(callback){
  37. var url = this.path+this.options.style+"/view.html";
  38. this.content.loadHtml(url, {"bind": {"lp": this.lp}, "module": this}, function(){
  39. this.setSizeNode();
  40. if (callback) callback();
  41. }.bind(this));
  42. },
  43. initLayout: function(){
  44. this.listNode.set("style", "");
  45. this.previewNode.set("style", "");
  46. if (this.resizeDrag) this.resizeDrag.detach();
  47. if (this.sizeNodeFun) this.removeEvent("resize", this.sizeNodeFun);
  48. if (this.options.layout.type=="leftRight"){
  49. this.toLeftRight();
  50. }else{
  51. this.toTopBottom();
  52. }
  53. },
  54. setSizeNode: function(){
  55. this.initLayout();
  56. this["sizeNode_"+this.options.layout.type]();
  57. this["setResizeNode_"+this.options.layout.type]();
  58. this.sizeNodeFun = null;
  59. this.sizeNodeFun = this["sizeNode_"+this.options.layout.type].bind(this);
  60. this.addEvent("resize", this.sizeNodeFun);
  61. },
  62. sizeResultNode: function(){
  63. var size = this.content.getSize();
  64. var filterSzie = this.filterNode.getSize();
  65. var keywordSize = this.keywordNode.getSize();
  66. var rangeSize = this.rangeNode.getSize();
  67. var h = size.y-filterSzie.y-keywordSize.y-rangeSize.y;
  68. this.resultNode.setStyle("height", ""+h+"px");
  69. return h;
  70. },
  71. sizeNode_topBottom: function(){
  72. var h = this.sizeResultNode();
  73. var listHeight = h*this.options.layout.percent;
  74. this.listNode.setStyle("height", ""+listHeight+"px");
  75. var previewHeight = h*(1-this.options.layout.percent);
  76. this.previewNode.setStyle("height", ""+previewHeight+"px");
  77. var previewSeparatorSize = this.previewSeparatorNode.getSize();
  78. var previewTitleSize = this.previewTitleNode.getSize();
  79. var previewContentHeight = previewHeight - previewSeparatorSize.y - previewTitleSize.y;
  80. this.previewContentNode.setStyle("height", ""+previewContentHeight+"px");
  81. },
  82. sizeNode_leftRight: function(){
  83. var h = this.sizeResultNode();
  84. var w = this.resultNode.getSize().x;
  85. var listWidth = w*this.options.layout.percent;
  86. this.listNode.setStyle("width", ""+listWidth+"px");
  87. this.previewNode.setStyle("margin-left", ""+listWidth+"px");
  88. //var previewSeparatorSize = this.previewSeparatorNode.getSize();
  89. var previewTitleSize = this.previewTitleNode.getSize();
  90. var previewContentHeight = h - previewTitleSize.y;
  91. this.previewContentNode.setStyle("height", ""+previewContentHeight+"px");
  92. },
  93. setResizeNode_topBottom: function(){
  94. if (this.previewSeparatorNode){
  95. this.resizeDrag = new Drag(this.previewSeparatorNode, {
  96. "onStart": function(el, e){
  97. el.store("position", o2.eventPosition(e));
  98. el.store("initialSize", this.listNode.getSize());
  99. }.bind(this),
  100. "onDrag": function(el, e){
  101. var p = o2.eventPosition(e);
  102. var position = el.retrieve("position");
  103. var initialSize = el.retrieve("initialSize");
  104. var dy = position.y.toFloat()-p.y.toFloat();
  105. var height = initialSize.y-dy;
  106. var size = this.resultNode.getSize();
  107. this.options.layout.percent = height/size.y;
  108. if (this.options.layout.percent<0.1) this.options.layout.percent = 0.1;
  109. if (this.options.layout.percent>0.85) this.options.layout.percent = 0.85;
  110. this.sizeNode_topBottom();
  111. }.bind(this),
  112. "onComplete": function(){
  113. o2.UD.putData("findDesignerLayout", {"layout": this.options.layout});
  114. }.bind(this)
  115. });
  116. }
  117. },
  118. setResizeNode_leftRight: function(){
  119. if (this.previewSeparatorNode){
  120. this.resizeDrag = new Drag(this.previewSeparatorNode, {
  121. "onStart": function(el, e){
  122. el.store("position", o2.eventPosition(e));
  123. el.store("initialSize", this.listNode.getSize());
  124. }.bind(this),
  125. "onDrag": function(el, e){
  126. var p = o2.eventPosition(e);
  127. var position = el.retrieve("position");
  128. var initialSize = el.retrieve("initialSize");
  129. var dx = position.x.toFloat()-p.x.toFloat();
  130. var width = initialSize.x-dx;
  131. var size = this.resultNode.getSize();
  132. this.options.layout.percent = width/size.x;
  133. if (this.options.layout.percent<0.1) this.options.layout.percent = 0.1;
  134. if (this.options.layout.percent>0.85) this.options.layout.percent = 0.85;
  135. this.sizeNode_leftRight();
  136. }.bind(this),
  137. "onComplete": function(){
  138. o2.UD.putData("findDesignerLayout", {"layout": this.options.layout});
  139. }.bind(this)
  140. });
  141. }
  142. },
  143. checkFilter: function(e){
  144. if (e.target.hasClass("filterNode_item")) e.target.getElement("input").click();
  145. e.stopPropagation();
  146. },
  147. checkRange: function(e){
  148. if (e.target.hasClass("rangeType_Item")) e.target.getElement("input").click();
  149. e.stopPropagation();
  150. },
  151. overKeywordOption: function(e){
  152. if (e.target.hasClass("o2_findDesigner_keywordNode_optionItem")){
  153. if (!e.target.hasClass("optionItem_over")) e.target.addClass("optionItem_over");
  154. }
  155. },
  156. outKeywordOption: function(e){
  157. if (e.target.hasClass("o2_findDesigner_keywordNode_optionItem")) e.target.removeClass("optionItem_over");
  158. },
  159. setCaseSensitive: function(e){
  160. this.filterOption.caseSensitive = !this.filterOption.caseSensitive;
  161. this.caseSensitiveNode.removeClass("caseSensitiveNode_"+!this.filterOption.caseSensitive);
  162. this.caseSensitiveNode.addClass("caseSensitiveNode_"+this.filterOption.caseSensitive);
  163. },
  164. setMatchWholeWord: function(e){
  165. this.filterOption.matchWholeWord = !this.filterOption.matchWholeWord;
  166. this.matchWholeWordNode.removeClass("matchWholeWordNode_"+!this.filterOption.matchWholeWord);
  167. this.matchWholeWordNode.addClass("matchWholeWordNode_"+this.filterOption.matchWholeWord);
  168. },
  169. setMatchRegExp: function(e){
  170. this.filterOption.matchRegExp = !this.filterOption.matchRegExp;
  171. this.matchRegExpNode.removeClass("matchRegExpNode_"+!this.filterOption.matchRegExp);
  172. this.matchRegExpNode.addClass("matchRegExpNode_"+this.filterOption.matchRegExp);
  173. },
  174. layoutAddClass: function(flag){
  175. flag = flag || "";
  176. this.listNode.addClass("listNode"+flag);
  177. this.previewNode.addClass("previewNode"+flag);
  178. this.previewSeparatorNode.addClass("previewNode_separator"+flag);
  179. this.previewTitleNode.addClass("previewNode_title"+flag);
  180. this.previewTitleActionNode.addClass("previewNode_title_action"+flag);
  181. this.previewContentNode.addClass("previewNode_content"+flag);
  182. },
  183. layoutRemoveClass: function(flag){
  184. flag = flag || "";
  185. this.listNode.removeClass("listNode"+flag);
  186. this.previewNode.removeClass("previewNode"+flag);
  187. this.previewSeparatorNode.removeClass("previewNode_separator"+flag);
  188. this.previewTitleNode.removeClass("previewNode_title"+flag);
  189. this.previewTitleActionNode.removeClass("previewNode_title_action"+flag);
  190. this.previewContentNode.removeClass("previewNode_content"+flag);
  191. },
  192. toLeftRight: function(){
  193. this.layoutAddClass("_lr");
  194. this.layoutRemoveClass();
  195. this.options.layout.type="leftRight";
  196. },
  197. toTopBottom: function(){
  198. this.layoutAddClass();
  199. this.layoutRemoveClass("_lr");
  200. this.options.layout.type="topBottom";
  201. },
  202. changeLayout: function(){
  203. if (this.options.layout.type=="leftRight"){
  204. this.options.layout.type="topBottom";
  205. }else{
  206. this.options.layout.type="leftRight";
  207. }
  208. this.setSizeNode();
  209. o2.UD.putData("findDesignerLayout", {"layout": this.options.layout});
  210. },
  211. getSelectedRange: function(){
  212. this.selectedRange = [];
  213. var rangeInputs = this.rangeContentNode.getElements("input");
  214. rangeInputs.each(function(input){
  215. if (input.checked) this.selectedRange.push(input.get("value"));
  216. }.bind(this));
  217. },
  218. setSelectedRange: function(){
  219. if (this.selectedRange && this.selectedRange.length){
  220. var rangeInputs = this.rangeContentNode.getElements("input");
  221. rangeInputs.each(function(input){
  222. if (this.selectedRange.indexOf(input.get("value"))!=-1) input.set("checked", true);
  223. }.bind(this));
  224. }
  225. },
  226. removeRangeItem: function(item){
  227. item.destroy();
  228. var itemNodes = this.rangeSelectedContentNode.getChildren();
  229. if (!itemNodes.length) this.setSelectedRange();
  230. },
  231. selectFindRange: function(){
  232. o2.requireApp("Selector", "package", function(){
  233. new o2.O2Selector(this.content, {
  234. "values": this.selectedModules,
  235. "type": "PlatApp",
  236. "selectAllEnable": true,
  237. "onComplete": function(list){
  238. this.rangeSelectedContentNode.empty();
  239. //this.selectedModules = [];
  240. if (list.length){
  241. this.getSelectedRange();
  242. this.rangeContentNode.getElements("input").set("checked", false);
  243. o2.require("o2.widget.O2Identity", function(){
  244. list.each(function(app){
  245. //this.selectedModules.push(app.data);
  246. app.data.name = this.lp.service + "-" + app.data.name;
  247. var item = new o2.widget.O2Other(app.data, this.rangeSelectedContentNode, {"canRemove": true, "style": "find", "onRemove": function(item){this.removeRangeItem(item);}.bind(this)});
  248. item.node.store("data", item.data);
  249. }.bind(this));
  250. }.bind(this));
  251. }else{
  252. this.setSelectedRange();
  253. }
  254. }.bind(this)
  255. });
  256. }.bind(this));
  257. },
  258. getFindOption: function(){
  259. var filterTypes = [];
  260. filterItems = this.filterNode.getElements("input");
  261. filterItems.each(function(item){
  262. if (item.checked) filterTypes.push(item.get("value"));
  263. }.bind(this));
  264. var keyword = this.keywordInputNode.get("value");
  265. var moduleList = [];
  266. var itemNodes = this.rangeSelectedContentNode.getChildren();
  267. if (!itemNodes.length){
  268. this.getSelectedRange();
  269. this.selectedRange.each(function(type){
  270. moduleList.push({"moduleType": type, "flagList": []});
  271. });
  272. }else{
  273. var rangeApp = {};
  274. itemNodes.each(function(node){
  275. var data = node.retrieve("data");
  276. if (!rangeApp[data.moduleType]) rangeApp[data.moduleType] = [];
  277. rangeApp[data.moduleType].push(data.id);
  278. }.bind(this));
  279. Object.keys(rangeApp).each(function(k){
  280. moduleList.push({"moduleType": k, "flagList": rangeApp[k]});
  281. });
  282. }
  283. this.filterOption.keyword = keyword;
  284. this.filterOption.designerTypes = filterTypes;
  285. this.filterOption.moduleList = moduleList;
  286. return this.filterOption;
  287. }
  288. });