$Module.js 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147
  1. MWF.xApplication.process.FormDesigner.Module = MWF.xApplication.process.FormDesigner.Module || {};
  2. MWF.require("MWF.widget.Common", null, false);
  3. MWF.xDesktop.requireApp("process.FormDesigner", "Property", null, false);
  4. MWF.xApplication.process.FormDesigner.Module.$Module = MWF.FC$Module = new Class({
  5. Extends: MWF.widget.Common,
  6. Implements: [Options, Events],
  7. options: {
  8. "style": "default",
  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": "mousedown",
  21. "action": "copy",
  22. "title": MWF.APPFD.LP.formAction.copy
  23. },
  24. {
  25. "name": "delete",
  26. "icon": "delete1.png",
  27. "event": "click",
  28. "action": "delete",
  29. "title": MWF.APPFD.LP.formAction["delete"]
  30. }
  31. // {
  32. // "name": "styleBrush",
  33. // "icon": "styleBrush.png",
  34. // "event": "click",
  35. // "action": "styleBrush",
  36. // "title": MWF.APPFD.LP.formAction["styleBrush"]
  37. // }
  38. ],
  39. "actionNodeStyles": {
  40. "width": "16px",
  41. "height": "16px",
  42. "margin-left": "2px",
  43. "margin-right": "2px",
  44. "float": "left",
  45. "border": "1px solid #F1F1F1",
  46. "cursor": "pointer"
  47. },
  48. "injectActions" : [
  49. {
  50. "name" : "before",
  51. "styles" : "injectActionBefore",
  52. "event" : "click",
  53. "action" : "injectBefore",
  54. "title": MWF.APPFD.LP.formAction["insertBefore"]
  55. },
  56. {
  57. "name" : "after",
  58. "styles" : "injectActionAfter",
  59. "event" : "click",
  60. "action" : "injectAfter",
  61. "title": MWF.APPFD.LP.formAction["insertAfter"]
  62. }
  63. ],
  64. "propertyPath": "/x_component_process_FormDesigner/Module/Label/label.html"
  65. },
  66. _getNewId: function(prefix, moduleName){
  67. var p = "";
  68. if (prefix){
  69. p = prefix+"_";
  70. }
  71. if (!moduleName) moduleName = this.moduleName;
  72. var idx = 1;
  73. var id = p+moduleName;
  74. var type = (this.json) ? this.json.type : this.moduleName.capitalize();
  75. while (this.form.checkModuleId(id, type).elementConflict){
  76. //while (this.form.json.moduleList[id]){
  77. id = p+moduleName+"_"+idx;
  78. idx++;
  79. }
  80. return id;
  81. },
  82. load : function(json, node, parent){
  83. this.json = json;
  84. this.node= node;
  85. this.node.store("module", this);
  86. this.node.setStyles(this.css.moduleNode);
  87. this._loadNodeStyles();
  88. this._loadTreeNode(parent);
  89. this.parentContainer = this.treeNode.parentNode.module;
  90. this._initModule();
  91. this._setEditStyle_custom("id");
  92. this.json.moduleName = this.moduleName;
  93. },
  94. _loadNodeStyles: function(){
  95. },
  96. _loadNodeCustomStyles: function(){
  97. this.setCustomStyles();
  98. },
  99. _loadTreeNode: function(parent){
  100. var title = this.json.name || this.json.id;
  101. var text = "";
  102. if (this.json.type==="Common"){
  103. text = this.json.tagName+"(Common)";
  104. }else{
  105. text = this.json.type.substr(this.json.type.lastIndexOf("$")+1, this.json.type.length);
  106. }
  107. var o = {
  108. "expand": true,
  109. "title": this.json.id,
  110. "text": "<"+text+"> "+title,
  111. "icon": ""
  112. };
  113. o.action = function(){
  114. if (this.module) this.module.selected();
  115. };
  116. if (this.nextModule){
  117. this.treeNode = this.nextModule.treeNode.insertChild(o);
  118. }else{
  119. this.treeNode = parent.treeNode.appendChild(o);
  120. }
  121. this.treeNode.module = this;
  122. },
  123. copyStyles: function(from, to){
  124. if (!this.json[to]) this.json[to] = {};
  125. Object.each(from, function(style, key){
  126. //if (!this.json[to][key])
  127. this.json[to][key] = style;
  128. }.bind(this));
  129. },
  130. removeStyles: function(from, to){
  131. if (this.json[to]){
  132. Object.each(from, function(style, key){
  133. if (this.json[to][key] && this.json[to][key]==style){
  134. delete this.json[to][key];
  135. }
  136. //if (this.json[from][key]){
  137. // delete this.json[to][key];
  138. //}
  139. }.bind(this));
  140. }
  141. },
  142. setTemplateStyles: function(styles){
  143. if (styles.styles) this.copyStyles(styles.styles, "styles");
  144. if (styles.properties) this.copyStyles(styles.properties, "properties");
  145. },
  146. clearTemplateStyles: function(styles){
  147. if (styles){
  148. if (styles.styles) this.removeStyles(styles.styles, "styles");
  149. if (styles.properties) this.removeStyles(styles.properties, "properties");
  150. }
  151. },
  152. setStyleTemplate: function(){
  153. //if (this.form.stylesList){
  154. // if (this.form.json.formStyleType){
  155. // if (this.form.stylesList[this.form.json.formStyleType]){
  156. // if (this.form.stylesList[this.form.json.formStyleType][this.moduleName]){
  157. // this.setTemplateStyles(this.form.stylesList[this.form.json.formStyleType][this.moduleName]);
  158. // }
  159. // }
  160. // }
  161. //}
  162. if( this.form.templateStyles && this.form.templateStyles[this.moduleName] ){
  163. this.setTemplateStyles(this.form.templateStyles[this.moduleName]);
  164. }
  165. },
  166. setAllStyles: function(){
  167. this.setPropertiesOrStyles("styles");
  168. this.setPropertiesOrStyles("inputStyles");
  169. this.setPropertiesOrStyles("properties");
  170. this.reloadMaplist();
  171. },
  172. _initModule: function(){
  173. if (!this.json.isSaved) this.setStyleTemplate();
  174. this.setPropertiesOrStyles("styles");
  175. this.setPropertiesOrStyles("inputStyles");
  176. this.setPropertiesOrStyles("properties");
  177. this._setNodeProperty();
  178. if (!this.form.isSubform) this._createIconAction();
  179. this._setNodeEvent();
  180. this.json.isSaved = true;
  181. },
  182. _setNodeProperty: function(){},
  183. _createIconAction: function(){
  184. if (!this.actionArea){
  185. this.actionArea = new Element("div", {
  186. styles: {
  187. "display": "none",
  188. // "width": 18*this.options.actions.length,
  189. "position": "absolute",
  190. "background-color": "#F1F1F1",
  191. "padding": "1px",
  192. "padding-right": "0px",
  193. "border": "1px solid #AAA",
  194. "box-shadow": "0px 2px 5px #999",
  195. "opacity": 1,
  196. "z-index": 100
  197. }
  198. }).inject(this.form.container, "after");
  199. this.options.actions.each(function(action){
  200. var actionNode = new Element("div", {
  201. "styles": this.options.actionNodeStyles,
  202. "title": action.title
  203. }).inject(this.actionArea);
  204. actionNode.setStyle("background", "url("+this.path+this.options.style+"/icon/"+action.icon+") no-repeat left center");
  205. actionNode.addEvent(action.event, function(e){
  206. this[action.action](e);
  207. }.bind(this));
  208. actionNode.addEvents({
  209. "mouseover": function(e){
  210. e.target.setStyle("border", "1px solid #999");
  211. }.bind(this),
  212. "mouseout": function(e){
  213. e.target.setStyle("border", "1px solid #F1F1F1");
  214. }.bind(this)
  215. });
  216. }.bind(this));
  217. this._createCustomIconAction();
  218. }
  219. },
  220. _createCustomIconAction: function(){},
  221. _setActionAreaPosition: function(){
  222. var p = this.node.getPosition(this.form.node.getOffsetParent());
  223. var y = p.y-25;
  224. var x = p.x;
  225. this.actionArea.setPosition({"x": x, "y": y});
  226. },
  227. _moveTo: function(container){
  228. this.parentContainer = container;
  229. if (!this.node){
  230. this._createNode();
  231. }
  232. this._resetTreeNode();
  233. this.node.inject(container.node);
  234. },
  235. move: function(e){
  236. this._createMoveNode();
  237. var thisDisplay = this.node.getStyle("display");
  238. this.node.store("thisDisplay", thisDisplay);
  239. this.node.setStyle("display", "none");
  240. this._setNodeMove(e);
  241. },
  242. copy: function(e){
  243. this.copyTo().move(e);
  244. },
  245. copyTo: function(node){
  246. if (!node) node = this.form;
  247. var newNode = this.node.clone(true, true);
  248. var newModuleJson = Object.clone(this.json);
  249. newNode.inject(node.node);
  250. var className = this.moduleName.capitalize();
  251. var prefix = (this.form.moduleType=="page") ? "PC" : "FC";
  252. var newTool = new MWF[prefix+className](this.form);
  253. newTool.json = newModuleJson;
  254. newModuleJson.id = newTool._getNewId();
  255. newNode.set("id", newModuleJson.id);
  256. this.form.json.moduleList[newModuleJson.id] = newModuleJson;
  257. if (this.form.scriptDesigner) this.form.scriptDesigner.createModuleScript(newModuleJson);
  258. newTool.load(newModuleJson, newNode, node);
  259. return newTool;
  260. },
  261. "delete": function(e){
  262. var module = this;
  263. this.form.designer.shortcut = false;
  264. this.form.designer.confirm("warn", module.node, MWF.APPFD.LP.notice.deleteElementTitle, MWF.APPFD.LP.notice.deleteElement, 300, 120, function(){
  265. module.form.selected();
  266. module.form.designer.shortcut = true;
  267. module.destroy();
  268. this.close();
  269. }, function(){
  270. module.form.designer.shortcut = true;
  271. this.close();
  272. }, null);
  273. },
  274. styleBrush: function(){
  275. //@todo
  276. this.form.styleBrushContent = Object.clone(this.json.style);
  277. },
  278. _setNodeEvent: function(){
  279. if (this.form.moduleType!="subform"){
  280. if (!this.isSetEvents){
  281. this.node.addEvent("click", function(e){
  282. if (!this.form.noSelected) this.selected();
  283. this.form.noSelected = false;
  284. e.stopPropagation();
  285. }.bind(this));
  286. this.node.addEvent("mouseover", function(e){
  287. this.over();
  288. e.stopPropagation();
  289. }.bind(this));
  290. this.node.addEvent("mouseout", function(e){
  291. this.unOver();
  292. e.stopPropagation();
  293. }.bind(this));
  294. this.node.addEvent("copy", function(e){
  295. this.copyModule(e);
  296. });
  297. this._setOtherNodeEvent();
  298. this.isSetEvents = true;
  299. }
  300. }
  301. },
  302. copyModule: function(e){
  303. },
  304. _setOtherNodeEvent: function(){},
  305. over: function(){
  306. if (!this.form.moveModule) if (this.form.currentSelectedModule!=this){
  307. this.node.store("normalBorder", this.node.getBorder());
  308. this.node.setStyles({
  309. "border-width": "1px",
  310. "border-color": "#4e73ff"
  311. });
  312. }
  313. },
  314. unOver: function(){
  315. if (!this.form.moveModule) if (this.form.currentSelectedModule!=this){
  316. this.node.setStyles({
  317. "border-width": "1px",
  318. "border-color": "#333"
  319. });
  320. var border = this.node.retrieve("normalBorder");
  321. this.node.setStyles(border);
  322. }
  323. },
  324. _showActions: function(){
  325. if (this.actionArea){
  326. if (this.options.actions.length){
  327. this._setActionAreaPosition();
  328. this.actionArea.setStyle("display", "block");
  329. }
  330. }
  331. },
  332. _hideActions: function(){
  333. if (this.actionArea) this.actionArea.setStyle("display", "none");
  334. },
  335. selected: function(){
  336. if (this.form.currentSelectedModule){
  337. if (this.form.currentSelectedModule==this){
  338. return true;
  339. }else{
  340. this.form.currentSelectedModule.unSelected();
  341. }
  342. }
  343. if (this.form.propertyMultiTd){
  344. this.form.propertyMultiTd.hide();
  345. this.form.propertyMultiTd = null;
  346. }
  347. this.form.unSelectedMulti();
  348. this.node.setStyles({
  349. "border-width": "1px",
  350. "border-color": "red"
  351. });
  352. this._showActions();
  353. this.form.currentSelectedModule = this;
  354. if (this.treeNode){
  355. this.treeNode.selectNode();
  356. (new Fx.Scroll(this.form.designer.propertyDomScrollArea)).toElement(this.treeNode.node);
  357. // this.treeNode.node.scrollIntoView();
  358. }
  359. if (this.form.brushStyle){
  360. this.json.styles = Object.clone(this.form.brushStyle);
  361. this.setPropertiesOrStyles("styles");
  362. if (this.property) this.property.loadMaplist();
  363. }
  364. this.showProperty();
  365. },
  366. unSelected: function(){
  367. this.node.setStyles({
  368. "border-width": "1px",
  369. "border-color": "#333"
  370. });
  371. var border = this.node.retrieve("normalBorder");
  372. this.node.setStyles(border);
  373. this._hideActions();
  374. this.form.currentSelectedModule = null;
  375. this.hideProperty();
  376. },
  377. selectedMulti: function(){
  378. if (this.form.selectedModules.indexOf(this)==-1){
  379. this.form.selectedModules.push(this);
  380. this.node.setStyle("border-color", "red");
  381. }
  382. },
  383. unSelectedMulti: function(){
  384. if (this.form.selectedModules.indexOf(this)!=-1){
  385. this.form.selectedModules.erase(this);
  386. this.node.setStyle("border-color", "#333");
  387. }
  388. },
  389. showProperty: function(){
  390. if (!this.property){
  391. this.property = new MWF.xApplication.process.FormDesigner.Property(this, this.form.designer.propertyContentArea, this.form.designer, {
  392. "path": this.options.propertyPath,
  393. "onPostLoad": function(){
  394. this.property.show();
  395. }.bind(this)
  396. });
  397. this.property.load();
  398. }else{
  399. this.property.show();
  400. }
  401. },
  402. hideProperty: function(){
  403. if (this.property) this.property.hide();
  404. },
  405. create: function(data, e){
  406. this.json = data;
  407. this.json.id = this._getNewId();
  408. this._createMoveNode();
  409. this._setNodeMove(e);
  410. },
  411. _createMoveNode: function(){
  412. this.moveNode = new Element("div", {
  413. "MWFType": "label",
  414. "styles": this.css.moduleNodeMove,
  415. "text": "Text",
  416. "events": {
  417. "selectstart": function(){
  418. return false;
  419. }
  420. }
  421. }).inject(this.form.container);
  422. },
  423. _onEnterOther: function(dragging, inObj){
  424. },
  425. _onLeaveOther: function(dragging, inObj){
  426. },
  427. _onMoveEnter: function(dragging, inObj){
  428. var module = inObj.retrieve("module");
  429. if (module) module._dragIn(this);
  430. this._onEnterOther(dragging, inObj);
  431. },
  432. _setNodeMove: function(e){
  433. this._setMoveNodePosition(e);
  434. this.form.node.focus();
  435. var droppables = [this.form.node].concat(this.form.moduleElementNodeList, this.form.moduleContainerNodeList, this.form.moduleComponentNodeList);
  436. var nodeDrag = new Drag.Move(this.moveNode, {
  437. "droppables": droppables,
  438. "onEnter": function(dragging, inObj){
  439. this._onMoveEnter(dragging, inObj);
  440. }.bind(this),
  441. "onLeave": function(dragging, inObj){
  442. var module = inObj.retrieve("module");
  443. if (module) module._dragOut(this);
  444. this._onLeaveOther(dragging, inObj);
  445. }.bind(this),
  446. "onDrag": function(e){
  447. this._nodeDrag(e, nodeDrag);
  448. }.bind(this),
  449. "onDrop": function(dragging, inObj){
  450. if (inObj){
  451. var module = inObj.retrieve("module");
  452. if (module) module._dragDrop(this);
  453. this._nodeDrop( module );
  454. }else{
  455. this._dragCancel(dragging);
  456. }
  457. }.bind(this),
  458. "onCancel": function(dragging){
  459. this._dragCancel(dragging);
  460. }.bind(this)
  461. });
  462. nodeDrag.start(e);
  463. this.form.moveModule = this;
  464. this.form.recordCurrentSelectedModule = this.form.currentSelectedModule;
  465. // var d = (new Date()).getTime();
  466. this.form.selected();
  467. //var d1 = (new Date()).getTime();
  468. //alert((d1-d))
  469. },
  470. _setMoveNodePosition: function(e){
  471. // var x = e.event.clientX+2;
  472. // var y = e.event.clientY+2;
  473. var x = e.page.x+2;
  474. var y = e.page.y+2;
  475. this.moveNode.positionTo(x, y);
  476. // this.moveNode.setStyles({
  477. // "top": y,
  478. // "left": x
  479. // });
  480. },
  481. _getCopyNode: function(module){
  482. if (!this.copyNode) this._createCopyNode();
  483. this.copyNode.setStyles(this.css.moduleNodeShow);
  484. this.copyNode.empty();
  485. if (module){
  486. try{
  487. var display = module.node.getStyle("display").toString().toLowerCase();
  488. this.copyNode.setStyle("display", display);
  489. if (display==="inline" || display==="inline-block"){
  490. var h = module.node.getSize().y-2;
  491. this.copyNode.setStyle("height", ""+h+"px");
  492. //this.copyNode.setStyle("display", "inline");
  493. }
  494. }catch(e){}
  495. }
  496. // this.copyNode.setStyle("display", "block");
  497. return this.copyNode;
  498. },
  499. _createCopyNode: function(){
  500. this.copyNode = this.moveNode.clone();
  501. this.copyNode.setStyles(this.css.moduleNodeShow);
  502. this.copyNode.addEvent("selectstart", function(){
  503. return false;
  504. });
  505. },
  506. _showInjectAction : function( module ){
  507. if ( module.moveNode ){
  508. module.moveNode.setStyle("display","none");
  509. }
  510. this.draggingModule = module;
  511. //if( !this.node.getFirst() ){
  512. // this.inject( "top" );
  513. // return;
  514. //}
  515. if( !this.injectActionArea )this._createInjectAction();
  516. this.injectActionArea.setStyle("display","block");
  517. this._setInjectActionAreaPosition();
  518. this.injectActionEffect = new Fx.Morph(this.injectActionArea, {
  519. duration: 200,
  520. transition: Fx.Transitions.Sine.easeOut
  521. });
  522. this.injectActionEffect.start(this.form.css.injectActionArea_to);
  523. },
  524. _hideInjectAction : function(){
  525. this.draggingModule = null;
  526. if( this.injectActionArea ){
  527. this.injectActionArea.setStyle("display","none");
  528. // if (!this.injectActionEffect){
  529. // this.injectActionEffect = new Fx.Morph(this.injectActionArea, {
  530. // duration: 200,
  531. // transition: Fx.Transitions.Sine.easeOut
  532. // });
  533. // }
  534. //
  535. // var y = this.form.css.injectActionArea_to.top.toInt();
  536. // var x = this.form.css.injectActionArea_to.left.toInt();
  537. // y = y+60;
  538. // x = x+60;
  539. // // this.form.css.injectActionArea.top = ""+y+"px";
  540. // // this.form.css.injectActionArea.left = ""+x+"px";
  541. // this.injectActionEffect.start({
  542. // "width": "0px",
  543. // "height": "0px",
  544. // "top": ""+y+"px",
  545. // "left": ""+x+"px"
  546. // }).chain(function(){
  547. // this.injectActionArea.setStyle("display","none");
  548. // }.bind(this));
  549. }
  550. },
  551. _createInjectAction : function(){
  552. var css = this.form.css;
  553. if( !this.injectActionArea ){
  554. this.injectActionArea = new Element("div", { styles: css.injectActionArea }).inject(this.form.container, "after");
  555. this.injectActionTopBGNode = new Element("div", { styles : css.injectActionTopBGNode }).inject( this.injectActionArea );
  556. this.injectActionLeftBGNode = new Element("div", { styles : css.injectActionLeftBGNode }).inject( this.injectActionArea );
  557. this.injectActionRightBGNode = new Element("div", { styles : css.injectActionRightBGNode }).inject( this.injectActionArea );
  558. this.injectActionBottomBGNode = new Element("div", { styles : css.injectActionBottomBGNode }).inject( this.injectActionArea );
  559. var injectActions = {};
  560. this.options.injectActions.each( function( action ){
  561. injectActions[ action.name ] = action;
  562. });
  563. if( injectActions.before )this._createInjectActionNode( injectActions.before, this.injectActionTopBGNode );
  564. if( injectActions.top )this._createInjectActionNode( injectActions.top, this.injectActionLeftBGNode );
  565. if( injectActions.bottom )this._createInjectActionNode( injectActions.bottom, this.injectActionRightBGNode );
  566. if( injectActions.after )this._createInjectActionNode( injectActions.after, this.injectActionBottomBGNode );
  567. new Element("div", {
  568. styles : css.injectActionCancelNode,
  569. events : {
  570. click : function(){
  571. this.draggingModule._dragCancel();
  572. this._dragDrop( this.node, true );
  573. this._hideInjectAction();
  574. }.bind(this),
  575. mouseover : function(){
  576. this.setStyles( css.injectActionCancelNode_over )
  577. },
  578. mouseout : function(){
  579. this.setStyles( css.injectActionCancelNode )
  580. }
  581. }
  582. }).inject(this.injectActionArea);
  583. }
  584. },
  585. _createInjectActionNode : function( action, relativeNode ){
  586. var actionNode = new Element("div", {
  587. "styles": this.form.css[action.styles],
  588. "title": action.title
  589. }).inject( this.injectActionArea );
  590. actionNode.addEvent(action.event, function(e){
  591. this[action.action](e);
  592. }.bind(this));
  593. actionNode.addEvents({
  594. "mouseover": function(e){
  595. relativeNode.setStyle("background", "#ddd");
  596. this.draggingModule.copyNode.setStyle("display","");
  597. this.draggingModule.copyNode.inject( this.node, action.name );
  598. }.bind(this),
  599. "mouseout": function(e){
  600. relativeNode.setStyle("background", "transparent");
  601. }.bind(this)
  602. });
  603. relativeNode.set("title",action.title);
  604. relativeNode.addEvent(action.event, function(e){
  605. this[action.action](e);
  606. }.bind(this));
  607. relativeNode.setStyle("cursor","pointer");
  608. relativeNode.addEvents({
  609. "mouseover": function(e){
  610. relativeNode.setStyle("background", "#ddd");
  611. this.draggingModule.copyNode.setStyle("display","");
  612. this.draggingModule.copyNode.inject( this.node, action.name );
  613. }.bind(this),
  614. "mouseout": function(e){
  615. relativeNode.setStyle("background", "transparent");
  616. //this.draggingModule.copyNode.setStyle("display","none");
  617. }.bind(this)
  618. });
  619. },
  620. _setInjectActionAreaPosition: function(){
  621. var e = new Event(event);
  622. var formOffset = this.form.node.getOffsetParent().getPosition();
  623. //var p = this.node.getPosition(this.form.node.getOffsetParent());
  624. var y = e.page.y - formOffset.y;
  625. var x = e.page.x - formOffset.x;
  626. this.injectActionArea.setPosition({"x": x, "y": y});
  627. y = y-60;
  628. x = x-60;
  629. this.form.css.injectActionArea_to.top = ""+y+"px";
  630. this.form.css.injectActionArea_to.left = ""+x+"px";
  631. },
  632. injectBefore : function( e ){
  633. this.inject( "before" )
  634. },
  635. injectAfter : function( e ){
  636. this.inject( "after" )
  637. },
  638. injectTop : function( e ){
  639. this.inject( "top" )
  640. },
  641. injectBottom : function( e ){
  642. this.inject( "bottom" )
  643. },
  644. inject : function( position ){
  645. if ( this.draggingModule.moveNode ){
  646. this.draggingModule.moveNode.setStyle("display","");
  647. }
  648. this.draggingModule._dragComplete( this.node, position );
  649. this._dragDrop( this.node, true );
  650. this._hideInjectAction();
  651. },
  652. _nodeDrop: function( module ){
  653. if( this.dragTimeout ){
  654. window.clearTimeout( this.dragTimeout );
  655. this.dragTimeout = null;
  656. }
  657. if (this.parentContainer){
  658. var available = true;
  659. if( !this.options.injectActions )available = false;
  660. if( module && module.moduleName == "datagrid$Data" )available = false;
  661. if( module.parentContainer && module.parentContainer.moduleName == "datagrid$Data")available = false;
  662. var e = new Event(event);
  663. if( available && e.control ){
  664. if( this.copyNode )this.copyNode.setStyle("display","none");
  665. module._showInjectAction( this );
  666. }else{
  667. this._dragComplete();
  668. }
  669. }else{
  670. this._dragCancel();
  671. }
  672. },
  673. _dragComplete: function( relativeNode, position ){
  674. this.setStyleTemplate();
  675. if( this.injectNoticeNode )this.injectNoticeNode.destroy();
  676. var overflow = this.moveNode.retrieve("overflow");
  677. if( overflow ){
  678. this.moveNode.setStyle("overflow",overflow);
  679. this.moveNode.eliminate("overflow");
  680. }
  681. if (!this.node){
  682. this._createNode();
  683. }
  684. this._resetTreeNode();
  685. if( relativeNode && position ){
  686. this.node.inject( relativeNode, position );
  687. }else{
  688. this.node.inject(this.copyNode, "before");
  689. }
  690. this._initModule();
  691. var thisDisplay = this.node.retrieve("thisDisplay");
  692. if (thisDisplay){
  693. this.node.setStyle("display", thisDisplay);
  694. }
  695. if (this.copyNode) this.copyNode.destroy();
  696. if (this.moveNode) this.moveNode.destroy();
  697. this.moveNode = null;
  698. this.copyNode = null;
  699. this.nextModule = null;
  700. this.form.moveModule = null;
  701. this.form.json.moduleList[this.json.id] = this.json;
  702. if (this.form.scriptDesigner) this.form.scriptDesigner.createModuleScript(this.json);
  703. this.selected();
  704. },
  705. _resetTreeNode: function(){
  706. if (this.parentContainer){
  707. if (this.treeNode){
  708. if (this.treeNode.parentNode){
  709. var originalModule = this.treeNode.parentNode.module;
  710. // if (originalModule == this.parentContainer){
  711. // if (!this.nextModule) return true;
  712. // };
  713. }
  714. this.treeNode.destroy();
  715. }
  716. this._loadTreeNode(this.parentContainer);
  717. if (this.treeNode.parentNode){
  718. if (!this.treeNode.parentNode.options.expand) this.treeNode.parentNode.expandOrCollapse();
  719. }
  720. this._resetSubTreeNode(this.node)
  721. }
  722. },
  723. _resetSubTreeNode: function(node){
  724. var subNode = node.getFirst();
  725. while (subNode){
  726. var module = subNode.retrieve("module");
  727. if (module) module._resetTreeNode();
  728. this._resetSubTreeNode(subNode);
  729. subNode = subNode.getNext();
  730. }
  731. },
  732. _createNode: function(){
  733. this.node = this.moveNode.clone(true, true);
  734. this.node.clearStyles(false);
  735. this.node.setStyles(this.css.moduleNode);
  736. this.node.set("id", this.json.id);
  737. this.node.addEvent("selectstart", function(){
  738. return false;
  739. });
  740. },
  741. _dragCancel: function(){
  742. if( this.dragTimeout ){
  743. window.clearTimeout( this.dragTimeout );
  744. this.dragTimeout = null;
  745. }
  746. if (this.node){
  747. var thisDisplay = this.node.retrieve("thisDisplay");
  748. if (thisDisplay){
  749. this.node.setStyle("display", thisDisplay);
  750. }
  751. this.selected();
  752. }else{
  753. this.data = null;
  754. if (this.form.recordCurrentSelectedModule) this.form.recordCurrentSelectedModule.selected();
  755. }
  756. this._hideInjectAction();
  757. if (this.moveNode) this.moveNode.destroy();
  758. if (this.copyNode) this.copyNode.destroy();
  759. this.copyNode = null;
  760. this.moveNode = null;
  761. this.form.moveModule = null;
  762. },
  763. _nodeDrag: function(e, drag){
  764. if( !this.dragTimeout ){
  765. this.dragTimeout = window.setTimeout(function(){
  766. var overflow = this.moveNode.getStyle("overflow");
  767. if( overflow && overflow !== "visible" ){
  768. this.moveNode.store("overflow",overflow);
  769. this.moveNode.setStyle("overflow","visible");
  770. }
  771. this.injectNoticeNode = new Element("div", {
  772. styles : this.form.css.injectNoticeNode,
  773. text : MWF.APPFD.LP.formAction.injectNotice
  774. }).inject( this.moveNode );
  775. //if (this.copyNode) this.copyNode.destroy();
  776. }.bind(this), 5000);
  777. }
  778. if (this.inContainer){
  779. var p = this.inContainer.node.getCoordinates();
  780. var now = drag.mouse.now;
  781. var height = p.height*0.4;
  782. if (p.height>200) height = 100;
  783. var y = p.top.toFloat()+height.toFloat();
  784. if (this.inContainer == this.parentContainer){
  785. if (this.parentContainer!=this.form){
  786. if (now.x > p.left && now.x < p.right && now.y < y && now.y > p.top){
  787. this.parentContainer.node.setStyles(this.parentContainer.css.moduleNode);
  788. this.parentContainer.node.setStyles(this.parentContainer.json.styles);
  789. if(e.control ){
  790. this.inContainer._dragIn(this);
  791. }else{
  792. this.parentContainer._dragInLikeElement(this);
  793. }
  794. }
  795. }
  796. }else{
  797. if (now.x > p.left && now.x < p.right && now.y < p.bottom && now.y > y){
  798. this.parentContainer.node.setStyles(this.parentContainer.css.moduleNode);
  799. this.parentContainer.node.setStyles(this.parentContainer.json.styles);
  800. this.inContainer._dragIn(this);
  801. }
  802. }
  803. }
  804. },
  805. _setControlMode: function(flag){
  806. if (this.controlMode!=flag){
  807. this.controlMode = flag;
  808. this._setControlModeNode();
  809. }
  810. },
  811. deletePropertiesOrStyles: function(name, key){
  812. if (name=="properties"){
  813. try{
  814. this.node.removeProperty(key);
  815. }catch(e){}
  816. }
  817. },
  818. setPropertiesOrStyles: function(name){
  819. if (name=="styles"){
  820. try{
  821. this.setCustomStyles();
  822. }catch(e){}
  823. }
  824. if (name=="properties"){
  825. try{
  826. this.node.setProperties(this.json.properties);
  827. }catch(e){}
  828. }
  829. },
  830. setCustomNodeStyles: function(node, styles){
  831. var border = node.getStyle("border");
  832. node.clearStyles();
  833. //node.setStyles(styles);
  834. node.setStyle("border", border);
  835. Object.each(styles, function(value, key){
  836. var reg = /^border\w*/ig;
  837. if (!key.test(reg)){
  838. node.setStyle(key, value);
  839. }
  840. }.bind(this));
  841. },
  842. setCustomStyles: function(){
  843. var border = this.node.getStyle("border");
  844. this.node.clearStyles();
  845. this.node.setStyles(this.css.moduleNode);
  846. if (this.initialStyles) this.node.setStyles(this.initialStyles);
  847. this.node.setStyle("border", border);
  848. if (this.json.styles) Object.each(this.json.styles, function(value, key){
  849. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1)){
  850. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  851. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  852. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  853. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  854. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  855. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  856. }
  857. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  858. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  859. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  860. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  861. }
  862. }
  863. var reg = /^border\w*/ig;
  864. if (!key.test(reg)){
  865. if (key){
  866. if (key.toString().toLowerCase()==="display"){
  867. if (value.toString().toLowerCase()==="none"){
  868. this.node.setStyle("opacity", 0.3);
  869. }else{
  870. this.node.setStyle("opacity", 1);
  871. this.node.setStyle(key, value);
  872. }
  873. }else{
  874. this.node.setStyle(key, value);
  875. }
  876. }
  877. }
  878. //this.node.setStyle(key, value);
  879. }.bind(this));
  880. // Object.each(this.json.styles, function(value, key){
  881. // var reg = /^border\w*/ig;
  882. // if (!key.test(reg)){
  883. // if (key){
  884. // if (key.toString().toLowerCase()==="display"){
  885. // if (value.toString().toLowerCase()==="none"){
  886. // this.node.setStyle("opacity", 0.3);
  887. // }else{
  888. // this.node.setStyle("opacity", 1);
  889. // }
  890. // }else{
  891. // this.node.setStyle(key, value);
  892. // }
  893. // }
  894. // }
  895. // }.bind(this));
  896. },
  897. _setEditStyle: function(name, obj, oldValue){
  898. var title = "";
  899. var text = "";
  900. if (name==="name"){
  901. title = this.json.name || this.json.id;
  902. if (this.json.type==="Common"){
  903. text = text = this.json.tagName+"(Common)";
  904. }else{
  905. text = this.json.type.substr(this.json.type.lastIndexOf("$")+1, this.json.type.length);
  906. }
  907. this.treeNode.setText("<"+text+"> "+title);
  908. }
  909. if (name==="id"){
  910. title = this.json.name || this.json.id;
  911. if (!this.json.name){
  912. if (this.json.type==="Common"){
  913. text = text = this.json.tagName+"(Common)";
  914. }else{
  915. text = this.json.type.substr(this.json.type.lastIndexOf("$")+1, this.json.type.length);
  916. }
  917. this.treeNode.setText("<"+text+"> "+this.json.id);
  918. }
  919. this.treeNode.setTitle(this.json.id);
  920. this.node.set("id", this.json.id);
  921. }
  922. this._setEditStyle_custom(name, obj, oldValue);
  923. },
  924. reloadMaplist: function(){
  925. if (this.property) Object.each(this.property.maplists, function(map, name){ map.reload(this.json[name]);}.bind(this));
  926. },
  927. _setEditStyle_custom: function(name, obj, oldValue){
  928. },
  929. getHtml: function(){
  930. var copy = this.node.clone(true, true);
  931. copy.clearStyles(true);
  932. this.form._clearNoId(copy);
  933. var html = copy.outerHTML;
  934. copy.destroy();
  935. return html;
  936. },
  937. _getSubModuleJson: function(node, moduleJsons){
  938. var subNode = node.getFirst();
  939. while (subNode){
  940. var module = subNode.retrieve("module");
  941. if (module) {
  942. moduleJsons[module.json.id] = Object.clone(module.json);
  943. }
  944. this._getSubModuleJson(subNode, moduleJsons);
  945. subNode = subNode.getNext();
  946. }
  947. },
  948. getJson: function(){
  949. var json = Object.clone(this.json);
  950. var o = {};
  951. o[json.id] = json;
  952. this._getSubModuleJson(this.node, o);
  953. return o;
  954. }
  955. // dragInElement: function(dragging, inObj, module){
  956. // this.containerNode = module.containerNode;
  957. //
  958. // // var border = this.containerNode.retrieve("thisborder", null);
  959. // // if (!border){
  960. // var top = this.containerNode.getStyle("border-top");
  961. // var left = this.containerNode.getStyle("border-left");
  962. // var bottom = this.containerNode.getStyle("border-bottom");
  963. // var right = this.containerNode.getStyle("border-right");
  964. //
  965. // this.containerNode.store("thisborder", {"top": top, "left": left, "bottom": bottom, "right": right});
  966. // // }
  967. // this.containerNode.setStyles({"border": "1px solid #ffa200"});
  968. //
  969. // if (!this.copyNode) this.createCopyNode(dragging, inObj);
  970. // this.copyNode.inject(inObj, "before");
  971. // },
  972. // dragInContainer: function(dragging, inObj){
  973. // // var border = inObj.retrieve("thisborder", null);
  974. // // if (!border){
  975. // var top = inObj.getStyle("border-top");
  976. // var left = inObj.getStyle("border-left");
  977. // var bottom = inObj.getStyle("border-bottom");
  978. // var right = inObj.getStyle("border-right");
  979. // inObj.store("thisborder", {"top": top, "left": left, "bottom": bottom, "right": right});
  980. // // }
  981. //
  982. // inObj.setStyles({"border": "1px solid #ffa200"});
  983. //
  984. // if (!this.copyNode) this.createCopyNode(dragging, inObj);
  985. //
  986. // this.copyNode.inject(inObj);
  987. //
  988. // this.containerNode = inObj;
  989. // },
  990. //
  991. //
  992. // dragOutElement: function(dragging, inObj){
  993. // var border = this.containerNode.retrieve("thisborder");
  994. // if (border) {
  995. // this.containerNode.setStyles({
  996. // "border-top": border.top,
  997. // "border-left": border.left,
  998. // "border-bottom": border.bottom,
  999. // "border-right": border.right
  1000. // });
  1001. // }
  1002. // this.containerNode = null;
  1003. // },
  1004. // dragOutContainer: function(dragging, inObj){
  1005. // var border = inObj.retrieve("thisborder");
  1006. // if (border) {
  1007. // inObj.setStyles({
  1008. // "border-top": border.top,
  1009. // "border-left": border.left,
  1010. // "border-bottom": border.bottom,
  1011. // "border-right": border.right
  1012. // });
  1013. // // inObj.setStyles({"border": border});
  1014. // }
  1015. // if (!this.node){
  1016. // if (this.copyNode){
  1017. // this.copyNode.destroy();
  1018. // this.copyNode = null;
  1019. // }
  1020. // }
  1021. // this.containerNode = null;
  1022. // },
  1023. //
  1024. //
  1025. //
  1026. //
  1027. // dragCancel: function(dragging){
  1028. // if (this.node){
  1029. // var thisDisplay = this.node.retrieve("thisDisplay");
  1030. // if (thisDisplay){
  1031. // this.node.setStyle("display", thisDisplay);
  1032. // }
  1033. // this.selected();
  1034. // }else{
  1035. // this.data = null;
  1036. // if (this.form.recordCurrentSelectedModule) this.form.recordCurrentSelectedModule.selected();
  1037. // }
  1038. // if (dragging) dragging.destroy();
  1039. // if (this.copyNode) this.copyNode.destroy();
  1040. // this.copyNode = null;
  1041. // this.moveNode = null;
  1042. // this.form.moveModule = null;
  1043. // }
  1044. });