Tab$Page.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. MWF.xApplication.process.FormDesigner.Module = MWF.xApplication.process.FormDesigner.Module || {};
  2. MWF.xDesktop.requireApp("process.FormDesigner", "Module.$Element", null, false);
  3. MWF.xApplication.process.FormDesigner.Module.Tab$Page = MWF.FCTab$Page = new Class({
  4. Extends: MWF.FC$Element,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "propertyPath": "/x_component_process_FormDesigner/Module/Tab$Page/tab$Page.html",
  9. "actions": [
  10. {
  11. "name": "move",
  12. "icon": "move1.png",
  13. "event": "mousedown",
  14. "action": "move",
  15. "title": MWF.APPFD.LP.formAction.move
  16. },
  17. //{
  18. // "name": "copy",
  19. // "icon": "copy1.png",
  20. // "event": "click",
  21. // "action": "copy",
  22. // "title": MWF.APPFD.LP.formAction.copy
  23. //},
  24. {
  25. "name": "add",
  26. "icon": "add.png",
  27. "event": "click",
  28. "action": "addPage",
  29. "title": MWF.APPFD.LP.formAction.add
  30. },
  31. {
  32. "name": "delete",
  33. "icon": "delete1.png",
  34. "event": "click",
  35. "action": "delete",
  36. "title": MWF.APPFD.LP.formAction["delete"]
  37. }
  38. ]
  39. },
  40. initialize: function(tab, page, options){
  41. this.setOptions(options);
  42. this.path = "/x_component_process_FormDesigner/Module/Tab$Page/";
  43. this.cssPath = "/x_component_process_FormDesigner/Module/Tab$Page/"+this.options.style+"/css.wcss";
  44. this._loadCss();
  45. this.moduleType = "element";
  46. this.moduleName = "tab$Page";
  47. this.form = tab.form;
  48. this.tab = tab;
  49. this.page = page;
  50. },
  51. setAllStyles: function(){},
  52. _initModule: function(){
  53. this._setNodeProperty();
  54. if (!this.form.isSubform) this._createIconAction();
  55. this._setNodeEvent();
  56. if (this.form.moduleElementNodeList.indexOf(this.node)!=-1) this.form.moduleElementNodeList.erase(this.node);
  57. },
  58. load : function(json, node, parent){
  59. this.json = json;
  60. this.node= node;
  61. this.node.store("module", this);
  62. this.node.setStyles(this.css.moduleNode);
  63. if (!this.json.id){
  64. var id = this._getNewId(parent.json.id);
  65. this.json.id = id;
  66. }
  67. if (this.json.name) this.page.textNode.set("text", this.json.name);
  68. node.set({
  69. "MWFType": "tab$Page",
  70. "id": this.json.id
  71. });
  72. if (!this.form.json.moduleList[this.json.id]){
  73. this.form.json.moduleList[this.json.id] = this.json;
  74. }
  75. this._initModule();
  76. this._loadTreeNode(parent);
  77. this.parentContainer = this.treeNode.parentNode.module;
  78. this.page.setOptions({
  79. "onPostShow": function(){
  80. this.initialStyles = this.page.tab.css.tabNodeCurrent;
  81. this.node.store("normalBorder", this.page.tab.css.tabNodeCurrent);
  82. }.bind(this),
  83. "onPostHide": function(){
  84. this.initialStyles = this.page.tab.css.tabNode;
  85. this.node.store("normalBorder", this.page.tab.css.tabNode);
  86. }.bind(this)
  87. });
  88. this._setEditStyle_custom("id");
  89. this.json.moduleName = this.moduleName;
  90. },
  91. //_dragIn: function(module){
  92. //this.treeNode.parentNode.module._dragIn(module);
  93. //},
  94. _setEditStyle_custom: function(name){
  95. if (name=="width"){
  96. if (this.json.width){
  97. if (this.json.width.toInt()>60) this.node.setStyle("width", ""+this.json.width+"px");
  98. }
  99. }
  100. if (name=="name"){
  101. this.page.textNode.set("text", this.json.name);
  102. }
  103. },
  104. "addPage": function(){
  105. var page = this.tab.addPage();
  106. page.tabNode.inject(this.page.tabNode, "before");
  107. page.contentNodeArea.inject(this.page.contentNodeArea, "before");
  108. page.showTabIm();
  109. },
  110. "delete": function(e){
  111. var module = this;
  112. this.form.designer.confirm("warn", e, MWF.APPFD.LP.notice.deleteElementTitle, MWF.APPFD.LP.notice.deleteElement, 300, 120, function(){
  113. if (module.tab.containers.length<=1){
  114. module.tab.destroy();
  115. }else{
  116. var contentModule = module.page.contentNode.retrieve("module");
  117. module.destroy();
  118. module.tab.elements.erase(module);
  119. contentModule.destroy();
  120. module.tab.containers.erase(contentModule);
  121. module.page.closeTab();
  122. }
  123. this.close();
  124. }, function(){
  125. this.close();
  126. }, null);
  127. },
  128. destroy: function(){
  129. this.form.moduleList.erase(this);
  130. this.form.moduleNodeList.erase(this.node);
  131. this.form.moduleElementNodeList.erase(this.node);
  132. //this.tab.elements.erase(this);
  133. this.node.destroy();
  134. this.actionArea.destroy();
  135. delete this.form.json.moduleList[this.json.id];
  136. this.json = null;
  137. delete this.json;
  138. this.treeNode.destroy();
  139. },
  140. move: function(e){
  141. var pageNodes = [];
  142. this.tab.tabWidget.pages.each(function(page){
  143. if (page!=this.page){
  144. pageNodes.push(page.tabNode);
  145. }
  146. }.bind(this));
  147. this._createMoveNode();
  148. this._setNodeMove(pageNodes, e);
  149. },
  150. _createMoveNode: function(){
  151. this.moveNode = this.node.clone();
  152. this.moveNode.inject(this.form.node);
  153. this.moveNode.setStyles({
  154. "border": "2px dashed #ffa200",
  155. "opacity": 0.7,
  156. "position": "absolute"
  157. });
  158. },
  159. _onEnterOther: function(){
  160. // this.copyNode.setStyles(this.tab.tabWidget.css.tabNode);
  161. // this.copyNode.setStyles(this.css.moduleNodeShow);
  162. },
  163. _createCopyNode: function(){
  164. this.copyNode = new Element("div");
  165. this.copyNode.setStyles(this.css.moduleNodeShow);
  166. this.copyNode.addEvent("selectstart", function(){
  167. return false;
  168. });
  169. },
  170. _setNodeMove: function(droppables, e){
  171. this._setMoveNodePosition(e);
  172. var movePosition = this.moveNode.getPosition();
  173. var moveSize = this.moveNode.getSize();
  174. var tabPosition = this.tab.node.getPosition();
  175. var tabSize = this.tab.node.getSize();
  176. var nodeDrag = new Drag.Move(this.moveNode, {
  177. "droppables": droppables,
  178. "limit": {
  179. "x": [tabPosition.x, tabPosition.x+tabSize.x],
  180. "y": [movePosition.y, movePosition.y+moveSize.y]
  181. },
  182. "onEnter": function(dragging, inObj){
  183. var module = inObj.retrieve("module");
  184. if (module) module._dragIn(this);
  185. this._onEnterOther(dragging, inObj);
  186. }.bind(this),
  187. "onLeave": function(dragging, inObj){
  188. var module = inObj.retrieve("module");
  189. if (module) module._dragOut(this);
  190. this._onLeaveOther(dragging, inObj);
  191. }.bind(this),
  192. "onDrop": function(dragging, inObj){
  193. if (inObj){
  194. var module = inObj.retrieve("module");
  195. if (module) module._dragDrop(this);
  196. this._nodeDrop();
  197. if (module){
  198. this.page.contentNodeArea.inject(module.page.contentNodeArea, "before");
  199. }
  200. }else{
  201. this._dragCancel(dragging);
  202. }
  203. }.bind(this),
  204. "onCancel": function(dragging){
  205. this._dragCancel(dragging);
  206. }.bind(this)
  207. });
  208. nodeDrag.start(e);
  209. this.form.moveModule = this;
  210. this.form.recordCurrentSelectedModule = this.form.currentSelectedModule;
  211. this.form.selected();
  212. }
  213. });