$Module.js 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159
  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.styles);
  277. if (this.json.inputStyles) this.form.inputStyleBrushContent = Object.clone(this.json.inputStyles);
  278. },
  279. _setNodeEvent: function(){
  280. if (this.form.moduleType!="subform" && this.form.moduleType!="subpage"){
  281. if (!this.isSetEvents){
  282. this.node.addEvent("click", function(e){
  283. if (!this.form.noSelected) this.selected();
  284. this.form.noSelected = false;
  285. e.stopPropagation();
  286. }.bind(this));
  287. this.node.addEvent("mouseover", function(e){
  288. this.over();
  289. e.stopPropagation();
  290. }.bind(this));
  291. this.node.addEvent("mouseout", function(e){
  292. this.unOver();
  293. e.stopPropagation();
  294. }.bind(this));
  295. this.node.addEvent("copy", function(e){
  296. this.copyModule(e);
  297. });
  298. this._setOtherNodeEvent();
  299. this.isSetEvents = true;
  300. }
  301. }
  302. },
  303. copyModule: function(e){
  304. },
  305. _setOtherNodeEvent: function(){},
  306. over: function(){
  307. if (!this.form.moveModule) if (this.form.currentSelectedModule!=this){
  308. this.node.store("normalBorder", this.node.getBorder());
  309. this.node.setStyles({
  310. "border-width": "1px",
  311. "border-color": "#4e73ff"
  312. });
  313. }
  314. },
  315. unOver: function(){
  316. if (!this.form.moveModule) if (this.form.currentSelectedModule!=this){
  317. this.node.setStyles({
  318. "border-width": "1px",
  319. "border-color": "#333"
  320. });
  321. var border = this.node.retrieve("normalBorder");
  322. this.node.setStyles(border);
  323. }
  324. },
  325. _showActions: function(){
  326. if (this.actionArea){
  327. if (this.options.actions.length){
  328. this._setActionAreaPosition();
  329. this.actionArea.setStyle("display", "block");
  330. }
  331. }
  332. },
  333. _hideActions: function(){
  334. if (this.actionArea) this.actionArea.setStyle("display", "none");
  335. },
  336. selected: function(){
  337. if (this.form.currentSelectedModule){
  338. if (this.form.currentSelectedModule==this){
  339. return true;
  340. }else{
  341. this.form.currentSelectedModule.unSelected();
  342. }
  343. }
  344. if (this.form.propertyMultiTd){
  345. this.form.propertyMultiTd.hide();
  346. this.form.propertyMultiTd = null;
  347. }
  348. this.form.unSelectedMulti();
  349. this.node.setStyles({
  350. "border-width": "1px",
  351. "border-color": "red"
  352. });
  353. this._showActions();
  354. this.form.currentSelectedModule = this;
  355. if (this.treeNode){
  356. this.treeNode.selectNode();
  357. (new Fx.Scroll(this.form.designer.propertyDomScrollArea)).toElement(this.treeNode.node);
  358. // this.treeNode.node.scrollIntoView();
  359. }
  360. if (this.form.brushStyle){
  361. this.json.styles = Object.clone(this.form.brushStyle);
  362. this.setPropertiesOrStyles("styles");
  363. if (this.property) this.property.loadMaplist();
  364. }
  365. if (this.form.brushInputStyle){
  366. this.json.inputStyles = Object.clone(this.form.brushInputStyle);
  367. this.setPropertiesOrStyles("inputStyles");
  368. if (this.property) this.property.loadMaplist();
  369. }
  370. this.showProperty();
  371. },
  372. unSelected: function(){
  373. this.node.setStyles({
  374. "border-width": "1px",
  375. "border-color": "#333"
  376. });
  377. var border = this.node.retrieve("normalBorder");
  378. this.node.setStyles(border);
  379. this._hideActions();
  380. this.form.currentSelectedModule = null;
  381. this.hideProperty();
  382. },
  383. selectedMulti: function(){
  384. if (this.form.selectedModules.indexOf(this)==-1){
  385. this.form.selectedModules.push(this);
  386. this.node.setStyle("border-color", "red");
  387. }
  388. },
  389. unSelectedMulti: function(){
  390. if (this.form.selectedModules.indexOf(this)!=-1){
  391. this.form.selectedModules.erase(this);
  392. this.node.setStyle("border-color", "#333");
  393. }
  394. },
  395. showProperty: function(){
  396. if (!this.property){
  397. this.property = new MWF.xApplication.process.FormDesigner.Property(this, this.form.designer.propertyContentArea, this.form.designer, {
  398. "path": this.options.propertyPath,
  399. "onPostLoad": function(){
  400. this.property.show();
  401. }.bind(this)
  402. });
  403. this.property.load();
  404. }else{
  405. this.property.show();
  406. }
  407. },
  408. hideProperty: function(){
  409. if (this.property) this.property.hide();
  410. },
  411. create: function(data, e){
  412. this.json = data;
  413. this.json.id = this._getNewId();
  414. this._createMoveNode();
  415. this._setNodeMove(e);
  416. },
  417. createImmediately: function(data, relativeNode, position, selectDisabled){
  418. this.json = data;
  419. this.json.id = this._getNewId();
  420. this._createMoveNode();
  421. this._dragComplete( relativeNode, position, selectDisabled );
  422. },
  423. _createMoveNode: function(){
  424. this.moveNode = new Element("div", {
  425. "MWFType": "label",
  426. "styles": this.css.moduleNodeMove,
  427. "text": "Text",
  428. "events": {
  429. "selectstart": function(){
  430. return false;
  431. }
  432. }
  433. }).inject(this.form.container);
  434. },
  435. _onEnterOther: function(dragging, inObj){
  436. },
  437. _onLeaveOther: function(dragging, inObj){
  438. },
  439. _onMoveEnter: function(dragging, inObj){
  440. var module = inObj.retrieve("module");
  441. if (module) module._dragIn(this);
  442. this._onEnterOther(dragging, inObj);
  443. },
  444. _setNodeMove: function(e){
  445. this._setMoveNodePosition(e);
  446. this.form.node.focus();
  447. var droppables = [this.form.node].concat(this.form.moduleElementNodeList, this.form.moduleContainerNodeList, this.form.moduleComponentNodeList);
  448. var nodeDrag = new Drag.Move(this.moveNode, {
  449. "droppables": droppables,
  450. "onEnter": function(dragging, inObj){
  451. this._onMoveEnter(dragging, inObj);
  452. }.bind(this),
  453. "onLeave": function(dragging, inObj){
  454. var module = inObj.retrieve("module");
  455. if (module) module._dragOut(this);
  456. this._onLeaveOther(dragging, inObj);
  457. }.bind(this),
  458. "onDrag": function(e){
  459. this._nodeDrag(e, nodeDrag);
  460. }.bind(this),
  461. "onDrop": function(dragging, inObj){
  462. if (inObj){
  463. var module = inObj.retrieve("module");
  464. if (module) module._dragDrop(this);
  465. this._nodeDrop( module );
  466. }else{
  467. this._dragCancel(dragging);
  468. }
  469. }.bind(this),
  470. "onCancel": function(dragging){
  471. this._dragCancel(dragging);
  472. }.bind(this)
  473. });
  474. nodeDrag.start(e);
  475. this.form.moveModule = this;
  476. this.form.recordCurrentSelectedModule = this.form.currentSelectedModule;
  477. // var d = (new Date()).getTime();
  478. this.form.selected();
  479. //var d1 = (new Date()).getTime();
  480. //alert((d1-d))
  481. },
  482. _setMoveNodePosition: function(e){
  483. // var x = e.event.clientX+2;
  484. // var y = e.event.clientY+2;
  485. var x = e.page.x+2;
  486. var y = e.page.y+2;
  487. this.moveNode.positionTo(x, y);
  488. // this.moveNode.setStyles({
  489. // "top": y,
  490. // "left": x
  491. // });
  492. },
  493. _getCopyNode: function(module){
  494. if (!this.copyNode) this._createCopyNode();
  495. this.copyNode.setStyles(this.css.moduleNodeShow);
  496. this.copyNode.empty();
  497. if (module){
  498. try{
  499. var display = module.node.getStyle("display").toString().toLowerCase();
  500. this.copyNode.setStyle("display", display);
  501. if (display==="inline" || display==="inline-block"){
  502. var h = module.node.getSize().y-2;
  503. this.copyNode.setStyle("height", ""+h+"px");
  504. //this.copyNode.setStyle("display", "inline");
  505. }
  506. }catch(e){}
  507. }
  508. // this.copyNode.setStyle("display", "block");
  509. return this.copyNode;
  510. },
  511. _createCopyNode: function(){
  512. this.copyNode = this.moveNode.clone();
  513. this.copyNode.setStyles(this.css.moduleNodeShow);
  514. this.copyNode.addEvent("selectstart", function(){
  515. return false;
  516. });
  517. },
  518. _showInjectAction : function( module ){
  519. if ( module.moveNode ){
  520. module.moveNode.setStyle("display","none");
  521. }
  522. this.draggingModule = module;
  523. //if( !this.node.getFirst() ){
  524. // this.inject( "top" );
  525. // return;
  526. //}
  527. if( !this.injectActionArea )this._createInjectAction();
  528. this.injectActionArea.setStyle("display","block");
  529. this._setInjectActionAreaPosition();
  530. this.injectActionEffect = new Fx.Morph(this.injectActionArea, {
  531. duration: 200,
  532. transition: Fx.Transitions.Sine.easeOut
  533. });
  534. this.injectActionEffect.start(this.form.css.injectActionArea_to);
  535. },
  536. _hideInjectAction : function(){
  537. this.draggingModule = null;
  538. if( this.injectActionArea ){
  539. this.injectActionArea.setStyle("display","none");
  540. // if (!this.injectActionEffect){
  541. // this.injectActionEffect = new Fx.Morph(this.injectActionArea, {
  542. // duration: 200,
  543. // transition: Fx.Transitions.Sine.easeOut
  544. // });
  545. // }
  546. //
  547. // var y = this.form.css.injectActionArea_to.top.toInt();
  548. // var x = this.form.css.injectActionArea_to.left.toInt();
  549. // y = y+60;
  550. // x = x+60;
  551. // // this.form.css.injectActionArea.top = ""+y+"px";
  552. // // this.form.css.injectActionArea.left = ""+x+"px";
  553. // this.injectActionEffect.start({
  554. // "width": "0px",
  555. // "height": "0px",
  556. // "top": ""+y+"px",
  557. // "left": ""+x+"px"
  558. // }).chain(function(){
  559. // this.injectActionArea.setStyle("display","none");
  560. // }.bind(this));
  561. }
  562. },
  563. _createInjectAction : function(){
  564. var css = this.form.css;
  565. if( !this.injectActionArea ){
  566. this.injectActionArea = new Element("div", { styles: css.injectActionArea }).inject(this.form.container, "after");
  567. this.injectActionTopBGNode = new Element("div", { styles : css.injectActionTopBGNode }).inject( this.injectActionArea );
  568. this.injectActionLeftBGNode = new Element("div", { styles : css.injectActionLeftBGNode }).inject( this.injectActionArea );
  569. this.injectActionRightBGNode = new Element("div", { styles : css.injectActionRightBGNode }).inject( this.injectActionArea );
  570. this.injectActionBottomBGNode = new Element("div", { styles : css.injectActionBottomBGNode }).inject( this.injectActionArea );
  571. var injectActions = {};
  572. this.options.injectActions.each( function( action ){
  573. injectActions[ action.name ] = action;
  574. });
  575. if( injectActions.before )this._createInjectActionNode( injectActions.before, this.injectActionTopBGNode );
  576. if( injectActions.top )this._createInjectActionNode( injectActions.top, this.injectActionLeftBGNode );
  577. if( injectActions.bottom )this._createInjectActionNode( injectActions.bottom, this.injectActionRightBGNode );
  578. if( injectActions.after )this._createInjectActionNode( injectActions.after, this.injectActionBottomBGNode );
  579. new Element("div", {
  580. styles : css.injectActionCancelNode,
  581. events : {
  582. click : function(){
  583. this.draggingModule._dragCancel();
  584. this._dragDrop( this.node, true );
  585. this._hideInjectAction();
  586. }.bind(this),
  587. mouseover : function(){
  588. this.setStyles( css.injectActionCancelNode_over )
  589. },
  590. mouseout : function(){
  591. this.setStyles( css.injectActionCancelNode )
  592. }
  593. }
  594. }).inject(this.injectActionArea);
  595. }
  596. },
  597. _createInjectActionNode : function( action, relativeNode ){
  598. var actionNode = new Element("div", {
  599. "styles": this.form.css[action.styles],
  600. "title": action.title
  601. }).inject( this.injectActionArea );
  602. actionNode.addEvent(action.event, function(e){
  603. this[action.action](e);
  604. }.bind(this));
  605. actionNode.addEvents({
  606. "mouseover": function(e){
  607. relativeNode.setStyle("background", "#ddd");
  608. this.draggingModule.copyNode.setStyle("display","");
  609. this.draggingModule.copyNode.inject( this.node, action.name );
  610. }.bind(this),
  611. "mouseout": function(e){
  612. relativeNode.setStyle("background", "transparent");
  613. }.bind(this)
  614. });
  615. relativeNode.set("title",action.title);
  616. relativeNode.addEvent(action.event, function(e){
  617. this[action.action](e);
  618. }.bind(this));
  619. relativeNode.setStyle("cursor","pointer");
  620. relativeNode.addEvents({
  621. "mouseover": function(e){
  622. relativeNode.setStyle("background", "#ddd");
  623. this.draggingModule.copyNode.setStyle("display","");
  624. this.draggingModule.copyNode.inject( this.node, action.name );
  625. }.bind(this),
  626. "mouseout": function(e){
  627. relativeNode.setStyle("background", "transparent");
  628. //this.draggingModule.copyNode.setStyle("display","none");
  629. }.bind(this)
  630. });
  631. },
  632. _setInjectActionAreaPosition: function(){
  633. var e = new Event(event);
  634. var formOffset = this.form.node.getOffsetParent().getPosition();
  635. //var p = this.node.getPosition(this.form.node.getOffsetParent());
  636. var y = e.page.y - formOffset.y;
  637. var x = e.page.x - formOffset.x;
  638. this.injectActionArea.setPosition({"x": x, "y": y});
  639. y = y-60;
  640. x = x-60;
  641. this.form.css.injectActionArea_to.top = ""+y+"px";
  642. this.form.css.injectActionArea_to.left = ""+x+"px";
  643. },
  644. injectBefore : function( e ){
  645. this.inject( "before" )
  646. },
  647. injectAfter : function( e ){
  648. this.inject( "after" )
  649. },
  650. injectTop : function( e ){
  651. this.inject( "top" )
  652. },
  653. injectBottom : function( e ){
  654. this.inject( "bottom" )
  655. },
  656. inject : function( position ){
  657. if ( this.draggingModule.moveNode ){
  658. this.draggingModule.moveNode.setStyle("display","");
  659. }
  660. this.draggingModule._dragComplete( this.node, position );
  661. this._dragDrop( this.node, true );
  662. this._hideInjectAction();
  663. },
  664. _nodeDrop: function( module ){
  665. if( this.dragTimeout ){
  666. window.clearTimeout( this.dragTimeout );
  667. this.dragTimeout = null;
  668. }
  669. if (this.parentContainer){
  670. var available = true;
  671. if( !this.options.injectActions )available = false;
  672. if( module && module.moduleName == "datagrid$Data" )available = false;
  673. if( module.parentContainer && module.parentContainer.moduleName == "datagrid$Data")available = false;
  674. var e = new Event(event);
  675. if( available && e.control ){
  676. if( this.copyNode )this.copyNode.setStyle("display","none");
  677. module._showInjectAction( this );
  678. }else{
  679. this._dragComplete();
  680. }
  681. }else{
  682. this._dragCancel();
  683. }
  684. },
  685. _dragComplete: function( relativeNode, position, selectDisabled ){
  686. this.setStyleTemplate();
  687. if( this.injectNoticeNode )this.injectNoticeNode.destroy();
  688. var overflow = this.moveNode.retrieve("overflow");
  689. if( overflow ){
  690. this.moveNode.setStyle("overflow",overflow);
  691. this.moveNode.eliminate("overflow");
  692. }
  693. if (!this.node){
  694. this._createNode();
  695. }
  696. this._resetTreeNode();
  697. if( relativeNode && position ){
  698. this.node.inject( relativeNode, position );
  699. }else{
  700. this.node.inject(this.copyNode, "before");
  701. }
  702. this._initModule();
  703. var thisDisplay = this.node.retrieve("thisDisplay");
  704. if (thisDisplay){
  705. this.node.setStyle("display", thisDisplay);
  706. }
  707. if (this.copyNode) this.copyNode.destroy();
  708. if (this.moveNode) this.moveNode.destroy();
  709. this.moveNode = null;
  710. this.copyNode = null;
  711. this.nextModule = null;
  712. this.form.moveModule = null;
  713. this.form.json.moduleList[this.json.id] = this.json;
  714. if (this.form.scriptDesigner) this.form.scriptDesigner.createModuleScript(this.json);
  715. if( !selectDisabled )this.selected();
  716. },
  717. _resetTreeNode: function(){
  718. if (this.parentContainer){
  719. if (this.treeNode){
  720. if (this.treeNode.parentNode){
  721. var originalModule = this.treeNode.parentNode.module;
  722. // if (originalModule == this.parentContainer){
  723. // if (!this.nextModule) return true;
  724. // };
  725. }
  726. this.treeNode.destroy();
  727. }
  728. this._loadTreeNode(this.parentContainer);
  729. if (this.treeNode.parentNode){
  730. if (!this.treeNode.parentNode.options.expand) this.treeNode.parentNode.expandOrCollapse();
  731. }
  732. this._resetSubTreeNode(this.node)
  733. }
  734. },
  735. _resetSubTreeNode: function(node){
  736. var subNode = node.getFirst();
  737. while (subNode){
  738. var module = subNode.retrieve("module");
  739. if (module) module._resetTreeNode();
  740. this._resetSubTreeNode(subNode);
  741. subNode = subNode.getNext();
  742. }
  743. },
  744. _createNode: function(){
  745. this.node = this.moveNode.clone(true, true);
  746. this.node.clearStyles(false);
  747. this.node.setStyles(this.css.moduleNode);
  748. this.node.set("id", this.json.id);
  749. this.node.addEvent("selectstart", function(){
  750. return false;
  751. });
  752. },
  753. _dragCancel: function(){
  754. if( this.dragTimeout ){
  755. window.clearTimeout( this.dragTimeout );
  756. this.dragTimeout = null;
  757. }
  758. if (this.node){
  759. var thisDisplay = this.node.retrieve("thisDisplay");
  760. if (thisDisplay){
  761. this.node.setStyle("display", thisDisplay);
  762. }
  763. this.selected();
  764. }else{
  765. this.data = null;
  766. if (this.form.recordCurrentSelectedModule) this.form.recordCurrentSelectedModule.selected();
  767. }
  768. this._hideInjectAction();
  769. if (this.moveNode) this.moveNode.destroy();
  770. if (this.copyNode) this.copyNode.destroy();
  771. this.copyNode = null;
  772. this.moveNode = null;
  773. this.form.moveModule = null;
  774. },
  775. _nodeDrag: function(e, drag){
  776. if( !this.dragTimeout ){
  777. this.dragTimeout = window.setTimeout(function(){
  778. var overflow = this.moveNode.getStyle("overflow");
  779. if( overflow && overflow !== "visible" ){
  780. this.moveNode.store("overflow",overflow);
  781. this.moveNode.setStyle("overflow","visible");
  782. }
  783. this.injectNoticeNode = new Element("div", {
  784. styles : this.form.css.injectNoticeNode,
  785. text : MWF.APPFD.LP.formAction.injectNotice
  786. }).inject( this.moveNode );
  787. //if (this.copyNode) this.copyNode.destroy();
  788. }.bind(this), 5000);
  789. }
  790. if (this.inContainer){
  791. var p = this.inContainer.node.getCoordinates();
  792. var now = drag.mouse.now;
  793. var height = p.height*0.4;
  794. if (p.height>200) height = 100;
  795. var y = p.top.toFloat()+height.toFloat();
  796. if (this.inContainer == this.parentContainer){
  797. if (this.parentContainer!=this.form){
  798. if (now.x > p.left && now.x < p.right && now.y < y && now.y > p.top){
  799. this.parentContainer.node.setStyles(this.parentContainer.css.moduleNode);
  800. this.parentContainer.node.setStyles(this.parentContainer.json.styles);
  801. if(e.control ){
  802. this.inContainer._dragIn(this);
  803. }else{
  804. this.parentContainer._dragInLikeElement(this);
  805. }
  806. }
  807. }
  808. }else{
  809. if (now.x > p.left && now.x < p.right && now.y < p.bottom && now.y > y){
  810. this.parentContainer.node.setStyles(this.parentContainer.css.moduleNode);
  811. this.parentContainer.node.setStyles(this.parentContainer.json.styles);
  812. this.inContainer._dragIn(this);
  813. }
  814. }
  815. }
  816. },
  817. _setControlMode: function(flag){
  818. if (this.controlMode!=flag){
  819. this.controlMode = flag;
  820. this._setControlModeNode();
  821. }
  822. },
  823. deletePropertiesOrStyles: function(name, key){
  824. if (name=="properties"){
  825. try{
  826. this.node.removeProperty(key);
  827. }catch(e){}
  828. }
  829. },
  830. setPropertiesOrStyles: function(name){
  831. if (name=="styles"){
  832. try{
  833. this.setCustomStyles();
  834. }catch(e){}
  835. }
  836. if (name=="properties"){
  837. try{
  838. this.node.setProperties(this.json.properties);
  839. }catch(e){}
  840. }
  841. },
  842. setCustomNodeStyles: function(node, styles){
  843. var border = node.getStyle("border");
  844. node.clearStyles();
  845. //node.setStyles(styles);
  846. node.setStyle("border", border);
  847. Object.each(styles, function(value, key){
  848. var reg = /^border\w*/ig;
  849. if (!key.test(reg)){
  850. node.setStyle(key, value);
  851. }
  852. }.bind(this));
  853. },
  854. setCustomStyles: function(){
  855. var border = this.node.getStyle("border");
  856. this.node.clearStyles();
  857. this.node.setStyles(this.css.moduleNode);
  858. if (this.initialStyles) this.node.setStyles(this.initialStyles);
  859. this.node.setStyle("border", border);
  860. if (this.json.styles) Object.each(this.json.styles, function(value, key){
  861. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1)){
  862. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  863. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  864. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  865. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  866. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  867. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  868. }
  869. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  870. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  871. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  872. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  873. }
  874. }
  875. var reg = /^border\w*/ig;
  876. if (!key.test(reg)){
  877. if (key){
  878. if (key.toString().toLowerCase()==="display"){
  879. if (value.toString().toLowerCase()==="none"){
  880. this.node.setStyle("opacity", 0.3);
  881. }else{
  882. this.node.setStyle("opacity", 1);
  883. this.node.setStyle(key, value);
  884. }
  885. }else{
  886. this.node.setStyle(key, value);
  887. }
  888. }
  889. }
  890. //this.node.setStyle(key, value);
  891. }.bind(this));
  892. // Object.each(this.json.styles, function(value, key){
  893. // var reg = /^border\w*/ig;
  894. // if (!key.test(reg)){
  895. // if (key){
  896. // if (key.toString().toLowerCase()==="display"){
  897. // if (value.toString().toLowerCase()==="none"){
  898. // this.node.setStyle("opacity", 0.3);
  899. // }else{
  900. // this.node.setStyle("opacity", 1);
  901. // }
  902. // }else{
  903. // this.node.setStyle(key, value);
  904. // }
  905. // }
  906. // }
  907. // }.bind(this));
  908. },
  909. _setEditStyle: function(name, obj, oldValue){
  910. var title = "";
  911. var text = "";
  912. if (name==="name"){
  913. title = this.json.name || this.json.id;
  914. if (this.json.type==="Common"){
  915. text = text = this.json.tagName+"(Common)";
  916. }else{
  917. text = this.json.type.substr(this.json.type.lastIndexOf("$")+1, this.json.type.length);
  918. }
  919. if (this.treeNode.setText) this.treeNode.setText("<"+text+"> "+title);
  920. }
  921. if (name==="id"){
  922. title = this.json.name || this.json.id;
  923. if (!this.json.name){
  924. if (this.json.type==="Common"){
  925. text = text = this.json.tagName+"(Common)";
  926. }else{
  927. text = this.json.type.substr(this.json.type.lastIndexOf("$")+1, this.json.type.length);
  928. }
  929. if (this.treeNode.setText) this.treeNode.setText("<"+text+"> "+this.json.id);
  930. }
  931. if (this.treeNode.setTitle) this.treeNode.setTitle(this.json.id);
  932. this.node.set("id", this.json.id);
  933. }
  934. this._setEditStyle_custom(name, obj, oldValue);
  935. },
  936. reloadMaplist: function(){
  937. if (this.property) Object.each(this.property.maplists, function(map, name){ map.reload(this.json[name]);}.bind(this));
  938. },
  939. _setEditStyle_custom: function(name, obj, oldValue){
  940. },
  941. getHtml: function(){
  942. var copy = this.node.clone(true, true);
  943. copy.clearStyles(true);
  944. this.form._clearNoId(copy);
  945. var html = copy.outerHTML;
  946. copy.destroy();
  947. return html;
  948. },
  949. _getSubModuleJson: function(node, moduleJsons){
  950. var subNode = node.getFirst();
  951. while (subNode){
  952. var module = subNode.retrieve("module");
  953. if (module) {
  954. moduleJsons[module.json.id] = Object.clone(module.json);
  955. }
  956. this._getSubModuleJson(subNode, moduleJsons);
  957. subNode = subNode.getNext();
  958. }
  959. },
  960. getJson: function(){
  961. var json = Object.clone(this.json);
  962. var o = {};
  963. o[json.id] = json;
  964. this._getSubModuleJson(this.node, o);
  965. return o;
  966. }
  967. // dragInElement: function(dragging, inObj, module){
  968. // this.containerNode = module.containerNode;
  969. //
  970. // // var border = this.containerNode.retrieve("thisborder", null);
  971. // // if (!border){
  972. // var top = this.containerNode.getStyle("border-top");
  973. // var left = this.containerNode.getStyle("border-left");
  974. // var bottom = this.containerNode.getStyle("border-bottom");
  975. // var right = this.containerNode.getStyle("border-right");
  976. //
  977. // this.containerNode.store("thisborder", {"top": top, "left": left, "bottom": bottom, "right": right});
  978. // // }
  979. // this.containerNode.setStyles({"border": "1px solid #ffa200"});
  980. //
  981. // if (!this.copyNode) this.createCopyNode(dragging, inObj);
  982. // this.copyNode.inject(inObj, "before");
  983. // },
  984. // dragInContainer: function(dragging, inObj){
  985. // // var border = inObj.retrieve("thisborder", null);
  986. // // if (!border){
  987. // var top = inObj.getStyle("border-top");
  988. // var left = inObj.getStyle("border-left");
  989. // var bottom = inObj.getStyle("border-bottom");
  990. // var right = inObj.getStyle("border-right");
  991. // inObj.store("thisborder", {"top": top, "left": left, "bottom": bottom, "right": right});
  992. // // }
  993. //
  994. // inObj.setStyles({"border": "1px solid #ffa200"});
  995. //
  996. // if (!this.copyNode) this.createCopyNode(dragging, inObj);
  997. //
  998. // this.copyNode.inject(inObj);
  999. //
  1000. // this.containerNode = inObj;
  1001. // },
  1002. //
  1003. //
  1004. // dragOutElement: function(dragging, inObj){
  1005. // var border = this.containerNode.retrieve("thisborder");
  1006. // if (border) {
  1007. // this.containerNode.setStyles({
  1008. // "border-top": border.top,
  1009. // "border-left": border.left,
  1010. // "border-bottom": border.bottom,
  1011. // "border-right": border.right
  1012. // });
  1013. // }
  1014. // this.containerNode = null;
  1015. // },
  1016. // dragOutContainer: function(dragging, inObj){
  1017. // var border = inObj.retrieve("thisborder");
  1018. // if (border) {
  1019. // inObj.setStyles({
  1020. // "border-top": border.top,
  1021. // "border-left": border.left,
  1022. // "border-bottom": border.bottom,
  1023. // "border-right": border.right
  1024. // });
  1025. // // inObj.setStyles({"border": border});
  1026. // }
  1027. // if (!this.node){
  1028. // if (this.copyNode){
  1029. // this.copyNode.destroy();
  1030. // this.copyNode = null;
  1031. // }
  1032. // }
  1033. // this.containerNode = null;
  1034. // },
  1035. //
  1036. //
  1037. //
  1038. //
  1039. // dragCancel: function(dragging){
  1040. // if (this.node){
  1041. // var thisDisplay = this.node.retrieve("thisDisplay");
  1042. // if (thisDisplay){
  1043. // this.node.setStyle("display", thisDisplay);
  1044. // }
  1045. // this.selected();
  1046. // }else{
  1047. // this.data = null;
  1048. // if (this.form.recordCurrentSelectedModule) this.form.recordCurrentSelectedModule.selected();
  1049. // }
  1050. // if (dragging) dragging.destroy();
  1051. // if (this.copyNode) this.copyNode.destroy();
  1052. // this.copyNode = null;
  1053. // this.moveNode = null;
  1054. // this.form.moveModule = null;
  1055. // }
  1056. });