SelectExplorer.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. MWF.xDesktop.requireApp("process.ProcessManager", "Explorer", null, false);
  2. MWF.xApplication.query.QueryManager.SelectExplorer = new Class({
  3. Extends: MWF.xApplication.process.ProcessManager.Explorer,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "tooltip": {
  8. "create": MWF.xApplication.query.QueryManager.LP.select.create,
  9. "search": MWF.xApplication.query.QueryManager.LP.select.search,
  10. "searchText": MWF.xApplication.query.QueryManager.LP.select.searchText,
  11. "noElement": MWF.xApplication.query.QueryManager.LP.select.noSelectNoticeText
  12. }
  13. },
  14. _createElement: function(e){
  15. this.pageTemplateList = null;
  16. this.defalutPageTemplateList = null;
  17. var _self = this;
  18. var createDefaultPage = function(e, template){
  19. layout.desktop.getPageDesignerStyle(function(){
  20. var options = {
  21. "style": layout.desktop.pageDesignerStyle,
  22. "template": template,
  23. "onQueryLoad": function(){
  24. this.actions = _self.app.restActions;
  25. this.application = _self.app.options.application;
  26. }
  27. };
  28. layout.desktop.openApplication(e, "portal.PageDesigner", options);
  29. }.bind(this));
  30. };
  31. var createPage = function(e, template){
  32. layout.desktop.getPageDesignerStyle(function(){
  33. var options = {
  34. "style": layout.desktop.pageDesignerStyle,
  35. "templateId": template,
  36. "onQueryLoad": function(){
  37. this.actions = _self.app.restActions;
  38. this.application = _self.app.options.application;
  39. }
  40. };
  41. layout.desktop.openApplication(e, "portal.PageDesigner", options);
  42. }.bind(this));
  43. };
  44. var createTemplateMaskNode = new Element("div", {"styles": this.css.createTemplateMaskNode}).inject(this.app.content);
  45. var createTemplateAreaNode = new Element("div", {"styles": this.css.createFormTemplateAreaNode}).inject(this.app.content);
  46. createTemplateAreaNode.fade("in");
  47. var createTemplateTitleNode = new Element("div", {"styles": this.css.createTemplateFormTitleNode, "text": this.app.lp.createSelectTemplate}).inject(createTemplateAreaNode);
  48. var createTemplateCategoryNode = new Element("div", {"styles": this.css.createTemplateFormCategoryNode}).inject(createTemplateAreaNode);
  49. var createTemplateCategoryTitleNode = new Element("div", {"styles": this.css.createTemplateFormCategoryTitleNode, "text": this.app.lp.templateCategory}).inject(createTemplateCategoryNode);
  50. var createTemplateContentNode = new Element("div", {"styles": this.css.createTemplateFormContentNode}).inject(createTemplateAreaNode);
  51. var createTemplateCategoryAllNode = new Element("div", {"styles": this.css.createTemplateFormCategoryItemNode, "text": this.app.lp.all}).inject(createTemplateCategoryNode);
  52. createTemplateCategoryAllNode.addEvent("click", function(){
  53. loadAllTemplates();
  54. });
  55. this.app.restActions.listPageTemplateCategory(function(json){
  56. json.data.each(function(d){
  57. var createTemplateCategoryItemNode = new Element("div", {"styles": this.css.createTemplateFormCategoryItemNode, "text": d.name+"("+ d.count+")", "value": d.name}).inject(createTemplateCategoryNode);
  58. createTemplateCategoryItemNode.addEvent("click", function(){
  59. createTemplateContentNode.empty();
  60. createTemplateCategoryNode.getElements("div").each(function(node, i){
  61. if (i>0) node.setStyles(_self.css.createTemplateFormCategoryItemNode);
  62. });
  63. this.setStyles(_self.css.createTemplateFormCategoryItemNode_current);
  64. loadTemplates(this.get("value"));
  65. });
  66. }.bind(this));
  67. }.bind(this));
  68. var resize = function(){
  69. var size = this.app.content.getSize();
  70. var y = (size.y*0.1)/2;
  71. var x = (size.x*0.1)/2;
  72. if (y<0) y=0;
  73. if (x<0) x=0;
  74. createTemplateAreaNode.setStyles({
  75. "top": ""+y+"px",
  76. "left": ""+x+"px"
  77. });
  78. y = size.y*0.9-createTemplateCategoryNode.getSize().y-70;
  79. createTemplateContentNode.setStyle("height", ""+y+"px");
  80. }.bind(this);
  81. resize();
  82. this.app.addEvent("resize", resize);
  83. var getDefaultPageTemplateList = function(callback){
  84. if (this.defalutPageTemplateList){
  85. if (callback) callback();
  86. }else{
  87. var url = "../x_component_portal_PageDesigner/Module/Page/template/templates.json";
  88. MWF.getJSON(url, function(json){
  89. this.defalutPageTemplateList = json;
  90. if (callback) callback();
  91. }.bind(this));
  92. }
  93. }.bind(this);
  94. var loadDefaultTemplate = function(){
  95. getDefaultPageTemplateList(function(){
  96. this.defalutPageTemplateList.each(function(template){
  97. var templateNode = new Element("div", {"styles": this.css.formTemplateNode}).inject(createTemplateContentNode);
  98. var templateIconNode = new Element("div", {"styles": this.css.formTemplateIconNode}).inject(templateNode);
  99. var templateTitleNode = new Element("div", {"styles": this.css.formTemplateTitleNode, "text": template.title}).inject(templateNode);
  100. templateNode.store("template", template.name);
  101. var templateIconImgNode = new Element("img", {"styles": this.css.formTemplateIconImgNode}).inject(templateIconNode);
  102. templateIconImgNode.set("src", "../x_component_portal_PageDesigner/Module/Page/template/"+template.icon);
  103. templateNode.addEvents({
  104. "mouseover": function(){this.setStyles(_self.css.formTemplateNode_over)},
  105. "mouseout": function(){this.setStyles(_self.css.formTemplateNode)},
  106. "mousedown": function(){this.setStyles(_self.css.formTemplateNode_down)},
  107. "mouseup": function(){this.setStyles(_self.css.formTemplateNode_over)},
  108. "click": function(e){
  109. createDefaultPage(e, this.retrieve("template"));
  110. _self.app.removeEvent("resize", resize);
  111. createTemplateAreaNode.destroy();
  112. createTemplateMaskNode.destroy();
  113. }
  114. });
  115. }.bind(this))
  116. }.bind(this));
  117. }.bind(this);
  118. var getPageTemplateList = function(callback){
  119. if (this.pageTemplateList){
  120. if (callback) callback();
  121. }else{
  122. this.app.restActions.listPageTemplate(function(json){
  123. this.pageTemplateList = json.data;
  124. if (callback) callback();
  125. }.bind(this));
  126. }
  127. }.bind(this);
  128. var loadTemplates = function(category){
  129. getPageTemplateList(function(){
  130. Object.each(this.pageTemplateList, function(v, k){
  131. var flag = (category) ? (k==category) : true;
  132. if (flag){
  133. v.each(function(template){
  134. var templateNode = new Element("div", {"styles": this.css.formTemplateNode}).inject(createTemplateContentNode);
  135. var templateIconNode = new Element("div", {"styles": this.css.formTemplatePreviewNode}).inject(templateNode);
  136. var templateTitleNode = new Element("div", {"styles": this.css.formTemplateTitleNode, "text": template.name}).inject(templateNode);
  137. templateNode.store("template", template.id);
  138. templateIconNode.set("html", template.outline);
  139. var templateActionNode = new Element("img", {"styles": this.css.formTemplateActionNode}).inject(templateIconNode);
  140. templateActionNode.addEvent("click", function(e){
  141. var thisNode = this.getParent().getParent();
  142. var id = thisNode.retrieve("template");
  143. _self.app.confirm("wram", e, _self.app.lp.page.deletePageTemplateTitle, _self.app.lp.page.deletePageTemplate, 300, 120, function(){
  144. _self.app.restActions.deletePageTemplate(id, function(json){
  145. thisNode.destroy();
  146. }.bind(this));
  147. this.close();
  148. }, function(){
  149. this.close();
  150. });
  151. e.stopPropagation();
  152. });
  153. templateNode.addEvents({
  154. "mouseover": function(){
  155. this.setStyles(_self.css.formTemplateNode_over);
  156. if (templateActionNode) templateActionNode.setStyle("display", "block");
  157. },
  158. "mouseout": function(){
  159. this.setStyles(_self.css.formTemplateNode);
  160. if (templateActionNode) templateActionNode.setStyle("display", "none");
  161. },
  162. "mousedown": function(){this.setStyles(_self.css.formTemplateNode_down)},
  163. "mouseup": function(){this.setStyles(_self.css.formTemplateNode_over)},
  164. "click": function(e){
  165. createForm(e, this.retrieve("template"));
  166. _self.app.removeEvent("resize", resize);
  167. createTemplateAreaNode.destroy();
  168. createTemplateMaskNode.destroy();
  169. }
  170. });
  171. }.bind(this));
  172. }
  173. }.bind(this));
  174. }.bind(this));
  175. }.bind(this);
  176. var loadAllTemplates = function(){
  177. createTemplateContentNode.empty();
  178. createTemplateCategoryNode.getElements("div").each(function(node, i){
  179. if (i>0) node.setStyles(_self.css.createTemplateFormCategoryItemNode);
  180. });
  181. createTemplateCategoryAllNode.setStyles(_self.css.createTemplateFormCategoryItemNode_current);
  182. loadDefaultTemplate();
  183. loadTemplates();
  184. };
  185. loadAllTemplates();
  186. createTemplateMaskNode.addEvent("click", function(){
  187. this.app.removeEvent("resize", resize);
  188. createTemplateAreaNode.destroy();
  189. createTemplateMaskNode.destroy();
  190. }.bind(this));
  191. },
  192. _loadItemDataList: function(callback){
  193. this.app.restActions.listSelect(this.app.options.application.id,callback);
  194. },
  195. _getItemObject: function(item){
  196. return new MWF.xApplication.query.QueryManager.SelectExplorer.Select(this, item);
  197. },
  198. deleteItems: function(){
  199. this.hideDeleteAction();
  200. while (this.deleteMarkItems.length){
  201. var item = this.deleteMarkItems.shift();
  202. if (this.deleteMarkItems.length){
  203. item.deleteSelect();
  204. }else{
  205. item.deleteSelect(function(){
  206. // this.reloadItems();
  207. //this.hideDeleteAction();
  208. }.bind(this));
  209. }
  210. }
  211. }
  212. });
  213. MWF.xApplication.query.QueryManager.SelectExplorer.Select= new Class({
  214. Extends: MWF.xApplication.process.ProcessManager.Explorer.Item,
  215. _open: function(e){
  216. var _self = this;
  217. var options = {
  218. "onQueryLoad": function(){
  219. this.actions = _self.explorer.actions;
  220. this.category = _self;
  221. this.options.id = _self.data.id;
  222. this.application = _self.explorer.app.options.application;
  223. }
  224. };
  225. this.explorer.app.desktop.openApplication(e, "query.SelectDesigner", options);
  226. },
  227. _getIcon: function(){
  228. var x = (Math.random()*49).toInt();
  229. return "process_icon_"+x+".png";
  230. },
  231. _getLnkPar: function(){
  232. return {
  233. "icon": this.explorer.path+this.explorer.options.style+"/processIcon/lnk.png",
  234. "title": this.data.name,
  235. "par": "query.SelectDesigner#{\"id\": \""+this.data.id+"\"}"
  236. };
  237. },
  238. deleteSelect: function(callback){
  239. this.explorer.actions.deleteSelect(this.data.id, function(){
  240. this.node.destroy();
  241. if (callback) callback();
  242. }.bind(this));
  243. }
  244. });