$Module.js 34 KB

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