Tab$Page.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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. "name": "selectParent",
  40. "icon": "selectParent.png",
  41. "event": "click",
  42. "action": "selectParent",
  43. "title": MWF.APPFD.LP.formAction["selectParent"]
  44. }
  45. ],
  46. "injectActions" : null
  47. },
  48. initialize: function(tab, page, options){
  49. this.setOptions(options);
  50. this.path = "../x_component_process_FormDesigner/Module/Tab$Page/";
  51. this.cssPath = "../x_component_process_FormDesigner/Module/Tab$Page/"+this.options.style+"/css.wcss";
  52. this._loadCss();
  53. this.moduleType = "element";
  54. this.moduleName = "tab$Page";
  55. this.form = tab.form;
  56. this.tab = tab;
  57. this.page = page;
  58. },
  59. setAllStyles: function(){},
  60. _initModule: function(){
  61. this._setNodeProperty();
  62. if (!this.form.isSubform) this._createIconAction();
  63. this._setNodeEvent();
  64. if (this.form.moduleElementNodeList.indexOf(this.node)!=-1) this.form.moduleElementNodeList.erase(this.node);
  65. },
  66. load : function(json, node, parent){
  67. this.json = json;
  68. this.node= node;
  69. this.node.store("module", this);
  70. this.node.setStyles(this.css.moduleNode);
  71. if (!this.json.id){
  72. var id = this._getNewId(parent.json.id);
  73. this.json.id = id;
  74. }
  75. if (this.json.name) this.page.textNode.set("text", this.json.name);
  76. node.set({
  77. "MWFType": "tab$Page",
  78. "id": this.json.id
  79. });
  80. if (!this.form.json.moduleList[this.json.id]){
  81. this.form.json.moduleList[this.json.id] = this.json;
  82. }
  83. this._initModule();
  84. this._loadTreeNode(parent);
  85. this.parentContainer = this.treeNode.parentNode.module;
  86. this.page.setOptions({
  87. "onPostShow": function(){
  88. this.initialStyles = this.page.tab.css.tabNodeCurrent;
  89. this.node.store("normalBorder", this.page.tab.css.tabNodeCurrent);
  90. }.bind(this),
  91. "onPostHide": function(){
  92. this.initialStyles = this.page.tab.css.tabNode;
  93. this.node.store("normalBorder", this.page.tab.css.tabNode);
  94. }.bind(this)
  95. });
  96. this._setEditStyle_custom("id");
  97. this.json.moduleName = this.moduleName;
  98. if (this.json.width){
  99. if (this.json.width.toInt()>60) this.node.setStyle("width", ""+this.json.width+"px");
  100. }
  101. if( this.json.description ){
  102. this.node.set("title", this.json.description);
  103. }
  104. },
  105. //_dragIn: function(module){
  106. //this.treeNode.parentNode.module._dragIn(module);
  107. //},
  108. _setEditStyle_custom: function(name){
  109. if (name=="width"){
  110. if (this.json.width){
  111. if (this.json.width.toInt()>60) this.node.setStyle("width", ""+this.json.width+"px");
  112. }
  113. }
  114. if (name=="name"){
  115. this.page.textNode.set("text", this.json.name);
  116. }
  117. if( name=="description"){
  118. this.node.set("title", this.json.description);
  119. }
  120. },
  121. "addPage": function( ev ){
  122. debugger;
  123. var tabPageModule;
  124. var page = this.tab.addPage(null, function(module) {
  125. tabPageModule = module;
  126. });
  127. page.tabNode.inject(this.page.tabNode, "before");
  128. page.contentNodeArea.inject(this.page.contentNodeArea, "before");
  129. page.showTabIm();
  130. tabPageModule.addHistoryLog("add");
  131. },
  132. "delete": function(e){
  133. var module = this;
  134. this.form.designer.confirm("warn", e, MWF.APPFD.LP.notice.deleteElementTitle, MWF.APPFD.LP.notice.deleteElement, 300, 120, function(){
  135. if (module.tab.containers.length<=1){
  136. module.tab.addHistoryLog("delete");
  137. module.tab.destroy();
  138. }else{
  139. module.addHistoryLog("delete");
  140. module._delete();
  141. }
  142. this.close();
  143. }, function(){
  144. this.close();
  145. }, null);
  146. },
  147. addHistoryLog: function( operation, from, contentFrom ){
  148. if(!this.form.history)return;
  149. var module = this;
  150. var contentModule = module.page.contentNode.retrieve("module");
  151. var log = {
  152. "operation": operation,
  153. "type": "module",
  154. "moduleType": this.json.type,
  155. "moduleId": this.json.id
  156. };
  157. var to = {
  158. "json": Object.clone(module.json),
  159. "path": module.form.history.getPath(module.node),
  160. "content": {
  161. "json": Object.clone(contentModule.json),
  162. "path": module.form.history.getPath( module.page.contentNodeArea )
  163. }
  164. };
  165. if( operation !== "move" ){
  166. to.jsonObject = module.getJson();
  167. to.html = module.node.outerHTML;
  168. to.content.jsonObject = contentModule.getJson();
  169. to.content.html = module.page.contentNodeArea.outerHTML;
  170. }
  171. log.toList = [to];
  172. if( from || contentFrom ){
  173. if(!from)from = {};
  174. if(contentFrom)from.content = contentFrom;
  175. log.fromList = [from];
  176. }
  177. module.form.history.add( log, module);
  178. },
  179. _delete: function(){
  180. if (this.tab.containers.length<=1){
  181. this.tab.destroy();
  182. }else{
  183. var contentModule = this.page.contentNode.retrieve("module");
  184. this.destroy();
  185. this.tab.elements.erase(this);
  186. contentModule.destroy();
  187. this.tab.containers.erase(contentModule);
  188. this.page.closeTab();
  189. }
  190. },
  191. destroy: function(){
  192. this.form.moduleList.erase(this);
  193. this.form.moduleNodeList.erase(this.node);
  194. this.form.moduleElementNodeList.erase(this.node);
  195. //this.tab.elements.erase(this);
  196. this.node.destroy();
  197. this.actionArea.destroy();
  198. delete this.form.json.moduleList[this.json.id];
  199. this.json = null;
  200. delete this.json;
  201. this.treeNode.destroy();
  202. },
  203. move: function(e, operation){
  204. var pageNodes = [];
  205. this.tab.tabWidget.pages.each(function(page){
  206. if (page!=this.page){
  207. pageNodes.push(page.tabNode);
  208. }
  209. }.bind(this));
  210. this._createMoveNode();
  211. this._setNodeMove(pageNodes, e, operation || "move");
  212. },
  213. _createMoveNode: function(){
  214. this.moveNode = this.node.clone();
  215. this.moveNode.inject(this.form.node);
  216. this.moveNode.setStyles({
  217. "border": "2px dashed #ffa200",
  218. "opacity": 0.7,
  219. "position": "absolute"
  220. });
  221. },
  222. _onEnterOther: function(){
  223. // this.copyNode.setStyles(this.tab.tabWidget.css.tabNode);
  224. // this.copyNode.setStyles(this.css.moduleNodeShow);
  225. },
  226. _createCopyNode: function(){
  227. this.copyNode = new Element("div");
  228. this.copyNode.setStyles(this.css.moduleNodeShow);
  229. this.copyNode.addEvent("selectstart", function(){
  230. return false;
  231. });
  232. },
  233. _setNodeMove: function(droppables, e, operation){
  234. this._setMoveNodePosition(e);
  235. var movePosition = this.moveNode.getPosition();
  236. var moveSize = this.moveNode.getSize();
  237. var tabPosition = this.tab.node.getPosition();
  238. var tabSize = this.tab.node.getSize();
  239. this.operation = operation;
  240. if( this.form.history && operation === "move" ){
  241. this.fromLog = { "path": this.form.history.getPath( this.node ) };
  242. }
  243. var nodeDrag = new Drag.Move(this.moveNode, {
  244. "droppables": droppables,
  245. "limit": {
  246. "x": [tabPosition.x, tabPosition.x+tabSize.x],
  247. "y": [movePosition.y, movePosition.y+moveSize.y]
  248. },
  249. "onEnter": function(dragging, inObj){
  250. var module = inObj.retrieve("module");
  251. if (module) module._dragIn(this);
  252. this._onEnterOther(dragging, inObj);
  253. }.bind(this),
  254. "onLeave": function(dragging, inObj){
  255. var module = inObj.retrieve("module");
  256. if (module) module._dragOut(this);
  257. this._onLeaveOther(dragging, inObj);
  258. }.bind(this),
  259. "onDrop": function(dragging, inObj){
  260. if (inObj){
  261. var module = inObj.retrieve("module");
  262. this.historyAddDelay = true;
  263. if (module) module._dragDrop(this);
  264. this._nodeDrop( module );
  265. if (module){
  266. if(this.form.history && this.operation === "move" ){
  267. this.contentFromLog = { path: this.form.history.getPath( this.page.contentNodeArea ) };
  268. }
  269. this.page.contentNodeArea.inject(module.page.contentNodeArea, "before");
  270. if(this.operation)this.addHistoryLog( this.operation, this.fromLog, this.contentFromLog );
  271. }
  272. this.historyAddDelay = null;
  273. this.operation = null;
  274. this.fromLog = null;
  275. this.contentFromLog = null;
  276. }else{
  277. this._dragCancel(dragging);
  278. }
  279. }.bind(this),
  280. "onCancel": function(dragging){
  281. this._dragCancel(dragging);
  282. }.bind(this)
  283. });
  284. nodeDrag.start(e);
  285. this.form.moveModule = this;
  286. this.form.recordCurrentSelectedModule = this.form.currentSelectedModule;
  287. this.form.selected();
  288. },
  289. _preprocessingModuleData: function(){
  290. this.recoveryWidgetstyle = this.node.get("style");
  291. this.node.clearStyles();
  292. //if (this.initialStyles) this.node.setStyles(this.initialStyles);
  293. this.json.recoveryStyles = Object.clone(this.json.styles);
  294. if (this.json.recoveryStyles) Object.each(this.json.recoveryStyles, function(value, key){
  295. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1)){
  296. //需要运行时处理
  297. }else{
  298. this.node.setStyle(key, value);
  299. delete this.json.styles[key];
  300. }
  301. }.bind(this));
  302. },
  303. _recoveryModuleData: function(){
  304. if (this.recoveryWidgetstyle) this.node.set("style", this.recoveryWidgetstyle);
  305. this.recoveryWidgetstyle = null;
  306. if (this.json.recoveryStyles) this.json.styles = this.json.recoveryStyles;
  307. this.json.recoveryStyles = null;
  308. },
  309. setCustomStyles: function(){
  310. this._recoveryModuleData();
  311. //debugger;
  312. // var border = this.node.getStyle("border");
  313. // this.node.clearStyles();
  314. // this.node.setStyles(this.css.moduleNode);
  315. //
  316. // if (this.initialStyles) this.node.setStyles(this.initialStyles);
  317. // this.node.setStyle("border", border);
  318. //
  319. // if (this.json.styles) Object.each(this.json.styles, function(value, key){
  320. // if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1)){
  321. // var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  322. // var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  323. // if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  324. // value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  325. // }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  326. // value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  327. // }
  328. // if (value.indexOf("/x_portal_assemble_surface")!==-1){
  329. // value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  330. // }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  331. // value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  332. // }
  333. // }
  334. //
  335. // var reg = /^border\w*/ig;
  336. // if (!key.test(reg)){
  337. // if (key){
  338. // if (key.toString().toLowerCase()==="display"){
  339. // if (value.toString().toLowerCase()==="none"){
  340. // this.node.setStyle("opacity", 0.3);
  341. // }else{
  342. // this.node.setStyle("opacity", 1);
  343. // this.node.setStyle(key, value);
  344. // }
  345. // }else{
  346. // this.node.setStyle(key, value);
  347. // }
  348. // }
  349. // }
  350. // }.bind(this));
  351. }
  352. });