$Module.js 32 KB

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