Tab$Page.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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.showTabIm();
  108. },
  109. "delete": function(e){
  110. var module = this;
  111. this.form.designer.confirm("warn", e, MWF.APPFD.LP.notice.deleteElementTitle, MWF.APPFD.LP.notice.deleteElement, 300, 120, function(){
  112. if (module.tab.containers.length<=1){
  113. module.tab.destroy();
  114. }else{
  115. var contentModule = module.page.contentNode.retrieve("module");
  116. module.destroy();
  117. module.tab.elements.erase(module);
  118. contentModule.destroy();
  119. module.tab.containers.erase(contentModule);
  120. module.page.closeTab();
  121. }
  122. this.close();
  123. }, function(){
  124. this.close();
  125. }, null);
  126. },
  127. destroy: function(){
  128. this.form.moduleList.erase(this);
  129. this.form.moduleNodeList.erase(this.node);
  130. this.form.moduleElementNodeList.erase(this.node);
  131. //this.tab.elements.erase(this);
  132. this.node.destroy();
  133. this.actionArea.destroy();
  134. delete this.form.json.moduleList[this.json.id];
  135. this.json = null;
  136. delete this.json;
  137. this.treeNode.destroy();
  138. },
  139. move: function(e){
  140. var pageNodes = [];
  141. this.tab.tabWidget.pages.each(function(page){
  142. if (page!=this.page){
  143. pageNodes.push(page.tabNode);
  144. }
  145. }.bind(this));
  146. this._createMoveNode();
  147. this._setNodeMove(pageNodes, e);
  148. },
  149. _createMoveNode: function(){
  150. this.moveNode = this.node.clone();
  151. this.moveNode.inject(this.form.node);
  152. this.moveNode.setStyles({
  153. "border": "2px dashed #ffa200",
  154. "opacity": 0.7,
  155. "position": "absolute"
  156. });
  157. },
  158. _onEnterOther: function(){
  159. // this.copyNode.setStyles(this.tab.tabWidget.css.tabNode);
  160. // this.copyNode.setStyles(this.css.moduleNodeShow);
  161. },
  162. _createCopyNode: function(){
  163. this.copyNode = new Element("div");
  164. this.copyNode.setStyles(this.css.moduleNodeShow);
  165. this.copyNode.addEvent("selectstart", function(){
  166. return false;
  167. });
  168. },
  169. _setNodeMove: function(droppables, e){
  170. this._setMoveNodePosition(e);
  171. var movePosition = this.moveNode.getPosition();
  172. var moveSize = this.moveNode.getSize();
  173. var tabPosition = this.tab.node.getPosition();
  174. var tabSize = this.tab.node.getSize();
  175. var nodeDrag = new Drag.Move(this.moveNode, {
  176. "droppables": droppables,
  177. "limit": {
  178. "x": [tabPosition.x, tabPosition.x+tabSize.x],
  179. "y": [movePosition.y, movePosition.y+moveSize.y]
  180. },
  181. "onEnter": function(dragging, inObj){
  182. var module = inObj.retrieve("module");
  183. if (module) module._dragIn(this);
  184. this._onEnterOther(dragging, inObj);
  185. }.bind(this),
  186. "onLeave": function(dragging, inObj){
  187. var module = inObj.retrieve("module");
  188. if (module) module._dragOut(this);
  189. this._onLeaveOther(dragging, inObj);
  190. }.bind(this),
  191. "onDrop": function(dragging, inObj){
  192. if (inObj){
  193. var module = inObj.retrieve("module");
  194. if (module) module._dragDrop(this);
  195. this._nodeDrop();
  196. if (module){
  197. this.page.contentNodeArea.inject(module.page.contentNodeArea, "before");
  198. }
  199. }else{
  200. this._dragCancel(dragging);
  201. }
  202. }.bind(this),
  203. "onCancel": function(dragging){
  204. this._dragCancel(dragging);
  205. }.bind(this)
  206. });
  207. nodeDrag.start(e);
  208. this.form.moveModule = this;
  209. this.form.recordCurrentSelectedModule = this.form.currentSelectedModule;
  210. this.form.selected();
  211. }
  212. });