$Module.js 32 KB

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