$Module.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455
  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": "selectParent",
  33. "icon": "selectParent.png",
  34. "event": "click",
  35. "action": "selectParent",
  36. "title": MWF.APPFD.LP.formAction["selectParent"]
  37. }
  38. // {
  39. // "name": "styleBrush",
  40. // "icon": "styleBrush.png",
  41. // "event": "click",
  42. // "action": "styleBrush",
  43. // "title": MWF.APPFD.LP.formAction["styleBrush"]
  44. // }
  45. ],
  46. "actionNodeStyles": {
  47. "width": "16px",
  48. "height": "16px",
  49. "margin-left": "2px",
  50. "margin-right": "2px",
  51. "float": "left",
  52. "border": "1px solid #F1F1F1",
  53. "cursor": "pointer"
  54. },
  55. "injectActions" : [
  56. {
  57. "name" : "before",
  58. "styles" : "injectActionBefore",
  59. "event" : "click",
  60. "action" : "injectBefore",
  61. "title": MWF.APPFD.LP.formAction["insertBefore"]
  62. },
  63. {
  64. "name" : "after",
  65. "styles" : "injectActionAfter",
  66. "event" : "click",
  67. "action" : "injectAfter",
  68. "title": MWF.APPFD.LP.formAction["insertAfter"]
  69. }
  70. ],
  71. "propertyPath": "../x_component_process_FormDesigner/Module/Label/label.html"
  72. },
  73. _getNewId: function(prefix, moduleName){
  74. var p = "";
  75. if (prefix){
  76. p = prefix+"_";
  77. }
  78. if (!moduleName) moduleName = this.moduleName;
  79. var idx = 1;
  80. var id = p+moduleName;
  81. var type = (this.json) ? this.json.type : this.moduleName.capitalize();
  82. while (this.form.checkModuleId(id, type).elementConflict || this.form.json.moduleList[id]){
  83. //while (this.form.json.moduleList[id]){
  84. id = p+moduleName+"_"+idx;
  85. idx++;
  86. }
  87. return id;
  88. },
  89. _getCopyId: function( oid ){
  90. var id = oid;
  91. var idx = 1;
  92. while (this.form.json.moduleList[id]) {
  93. id = oid + "_" + idx;
  94. idx++;
  95. }
  96. return id;
  97. },
  98. load : function(json, node, parent){
  99. this.json = json;
  100. this.node= node;
  101. this.node.store("module", this);
  102. this.node.setStyles(this.css.moduleNode);
  103. this._loadNodeStyles();
  104. this._loadTreeNode(parent);
  105. this.parentContainer = this.treeNode.parentNode.module;
  106. this._initModule();
  107. this._setEditStyle_custom("id");
  108. this.json.moduleName = this.moduleName;
  109. },
  110. _loadNodeStyles: function(){
  111. },
  112. _loadNodeCustomStyles: function(){
  113. this.setCustomStyles();
  114. },
  115. _loadTreeNode: function(parent){
  116. var title = this.json.name || this.json.id;
  117. var text = "";
  118. if (this.json.type==="Common"){
  119. text = this.json.tagName+"(Common)";
  120. }else{
  121. text = this.json.type.substr(this.json.type.lastIndexOf("$")+1, this.json.type.length);
  122. }
  123. var o = {
  124. "expand": true,
  125. "title": this.json.id,
  126. "text": "<"+text+"> "+title,
  127. "icon": ""
  128. };
  129. o.action = function(){
  130. if (this.module) this.module.selected();
  131. };
  132. if (this.nextModule){
  133. this.treeNode = this.nextModule.treeNode.insertChild(o);
  134. }else{
  135. this.treeNode = parent.treeNode.appendChild(o);
  136. }
  137. this.treeNode.module = this;
  138. },
  139. copyStyles: function(from, to){
  140. if( this.form.isForceClearCustomStyle() ){
  141. this.json[to] = {};
  142. }else{
  143. if (!this.json[to]) this.json[to] = {};
  144. }
  145. Object.each(from, function(style, key){
  146. //if (!this.json[to][key])
  147. this.json[to][key] = style;
  148. }.bind(this));
  149. },
  150. removeStyles: function(from, to){
  151. if( this.form.isForceClearCustomStyle() ){
  152. this.json[to] = {};
  153. }else{
  154. if (this.json[to]){
  155. Object.each(from, function(style, key){
  156. if (this.json[to][key] && this.json[to][key]==style){
  157. delete this.json[to][key];
  158. }
  159. }.bind(this));
  160. }
  161. }
  162. },
  163. setTemplateStyles: function(styles){
  164. if (styles.styles) this.copyStyles(styles.styles, "styles");
  165. if (styles.properties) this.copyStyles(styles.properties, "properties");
  166. },
  167. clearTemplateStyles: function(styles){
  168. if (styles){
  169. if (styles.styles) this.removeStyles(styles.styles, "styles");
  170. if (styles.properties) this.removeStyles(styles.properties, "properties");
  171. }
  172. },
  173. setStyleTemplate: function(){
  174. //if (this.form.stylesList){
  175. // if (this.form.json.formStyleType){
  176. // if (this.form.stylesList[this.form.json.formStyleType]){
  177. // if (this.form.stylesList[this.form.json.formStyleType][this.moduleName]){
  178. // this.setTemplateStyles(this.form.stylesList[this.form.json.formStyleType][this.moduleName]);
  179. // }
  180. // }
  181. // }
  182. //}
  183. if( this.form.templateStyles && this.form.templateStyles[this.moduleName] ){
  184. this.setTemplateStyles(this.form.templateStyles[this.moduleName]);
  185. }
  186. },
  187. setAllStyles: function(){
  188. this.setPropertiesOrStyles("styles");
  189. this.setPropertiesOrStyles("inputStyles");
  190. this.setPropertiesOrStyles("properties");
  191. this.reloadMaplist();
  192. },
  193. _initModule: function(){
  194. if (!this.json.isSaved) this.setStyleTemplate();
  195. this._resetModuleDomNode();
  196. this.setPropertiesOrStyles("styles");
  197. this.setPropertiesOrStyles("inputStyles");
  198. this.setPropertiesOrStyles("properties");
  199. this._setNodeProperty();
  200. if (!this.form.isSubform) this._createIconAction();
  201. this._setNodeEvent();
  202. this.json.isSaved = true;
  203. },
  204. _resetModuleDomNode: function(){},
  205. _setNodeProperty: function(){},
  206. _createIconAction: function(){
  207. if (!this.actionArea){
  208. this.actionArea = new Element("div", {
  209. styles: {
  210. "display": "none",
  211. // "width": 18*this.options.actions.length,
  212. "position": "absolute",
  213. "background-color": "#F1F1F1",
  214. "padding": "1px",
  215. "padding-right": "0px",
  216. "border": "1px solid #AAA",
  217. "box-shadow": "0px 2px 5px #999",
  218. "opacity": 1,
  219. "z-index": 100
  220. }
  221. }).inject(this.form.container, "after");
  222. this.options.actions.each(function(action){
  223. var actionNode = new Element("div", {
  224. "styles": this.options.actionNodeStyles,
  225. "title": action.title
  226. }).inject(this.actionArea);
  227. if( action.name === "selectParent" ){
  228. actionNode.setStyle("background", "url(../x_component_process_FormDesigner/Module/Form/default/icon/selectParent.png) no-repeat left center");
  229. }else{
  230. actionNode.setStyle("background", "url("+this.path+this.options.style+"/icon/"+action.icon+") no-repeat left center");
  231. }
  232. actionNode.addEvent(action.event, function(e){
  233. this[action.action](e);
  234. }.bind(this));
  235. actionNode.addEvents({
  236. "mouseover": function(e){
  237. e.target.setStyle("border", "1px solid #999");
  238. }.bind(this),
  239. "mouseout": function(e){
  240. e.target.setStyle("border", "1px solid #F1F1F1");
  241. }.bind(this)
  242. });
  243. }.bind(this));
  244. this._createCustomIconAction();
  245. }
  246. },
  247. _createCustomIconAction: function(){},
  248. _setActionAreaPosition: function(){
  249. var p = this.node.getPosition(this.form.node.getOffsetParent());
  250. var y = p.y-25;
  251. var x = p.x;
  252. this.actionArea.setPosition({"x": x, "y": y});
  253. },
  254. _moveTo: function(container){
  255. this.parentContainer = container;
  256. if (!this.node){
  257. this._createNode();
  258. }
  259. this._resetTreeNode();
  260. this.node.inject(container.node);
  261. },
  262. move: function(e, operation){
  263. this._createMoveNode();
  264. var thisDisplay = this.node.getStyle("display");
  265. this.node.store("thisDisplay", thisDisplay);
  266. this.node.setStyle("display", "none");
  267. this._setNodeMove(e, operation || "move");
  268. },
  269. copy: function(e){
  270. this.copyTo().move(e, "copy");
  271. },
  272. copyTo: function(node){
  273. if (!node) node = this.form;
  274. var newNode = this.node.clone(true, true);
  275. var newModuleJson = Object.clone(this.json);
  276. newNode.inject(node.node);
  277. var className = this.moduleName.capitalize();
  278. var prefix = (this.form.moduleType=="page") ? "PC" : "FC";
  279. if( this.form.designer.options.name.contains("cms.") ){
  280. prefix = "CMSFC";
  281. }
  282. var newTool = new MWF[prefix+className](this.form);
  283. var oldId = newModuleJson.id;
  284. newTool.json = newModuleJson;
  285. newModuleJson.id = newTool._getNewId();
  286. newNode.set("id", newModuleJson.id);
  287. if( this.form.copyedModule && this.form.copyedModule.checkCopySubModule){
  288. this.form.copyedModule.checkCopySubModule(newModuleJson, oldId);
  289. }
  290. this.form.json.moduleList[newModuleJson.id] = newModuleJson;
  291. if (this.form.scriptDesigner) this.form.scriptDesigner.createModuleScript(newModuleJson);
  292. newTool.load(newModuleJson, newNode, node);
  293. return newTool;
  294. },
  295. "delete": function(e){
  296. var module = this;
  297. this.form.designer.shortcut = false;
  298. this.form.designer.confirm("warn", module.node, MWF.APPFD.LP.notice.deleteElementTitle, MWF.APPFD.LP.notice.deleteElement, 300, 120, function(){
  299. module.form.selected();
  300. module.form.designer.shortcut = true;
  301. module.addHistoryLog("delete");
  302. module.destroy();
  303. this.close();
  304. }, function(){
  305. module.form.designer.shortcut = true;
  306. this.close();
  307. }, null);
  308. },
  309. selectedContainer: function(){
  310. if (this.parentContainer) this.parentContainer.selected();
  311. },
  312. styleBrush: function(){
  313. //@todo
  314. this.form.styleBrushContent = Object.clone(this.json.styles);
  315. if (this.json.inputStyles) this.form.inputStyleBrushContent = Object.clone(this.json.inputStyles);
  316. },
  317. selectParent: function(){
  318. var parentModule = this.getParentModule();
  319. if(parentModule){
  320. parentModule.selected();
  321. if( parentModule.actionArea ){
  322. }
  323. }
  324. },
  325. getParentModule: function(){
  326. var module;
  327. var parent = this.node.getParent();
  328. while(parent) {
  329. var MWFtype = parent.get("MWFtype");
  330. if( MWFtype ){
  331. module = parent.retrieve("module");
  332. if( module )return module;
  333. }else{
  334. parent = parent.getParent();
  335. }
  336. }
  337. return null;
  338. },
  339. _setNodeEvent: function(){
  340. if (this.form.moduleType!="subform" && this.form.moduleType!="widget" && this.form.moduleType!="subpage"){
  341. if (!this.isSetEvents){
  342. this.node.addEvent("click", function(e){
  343. if (!this.form.noSelected) this.selected();
  344. this.form.noSelected = false;
  345. e.stopPropagation();
  346. }.bind(this));
  347. this.node.addEvent("mouseover", function(e){
  348. this.over();
  349. e.stopPropagation();
  350. }.bind(this));
  351. this.node.addEvent("mouseout", function(e){
  352. this.unOver();
  353. e.stopPropagation();
  354. }.bind(this));
  355. this.node.addEvent("copy", function(e){
  356. this.copyModule(e);
  357. });
  358. this._setOtherNodeEvent();
  359. this.isSetEvents = true;
  360. }
  361. }
  362. },
  363. copyModule: function(e){
  364. },
  365. _setOtherNodeEvent: function(){},
  366. over: function(){
  367. if (!this.form.moveModule) if (this.form.currentSelectedModule!=this){
  368. this.node.store("normalBorder", this.node.getBorder());
  369. this.node.setStyles({
  370. "border-width": "1px",
  371. "border-color": "#4e73ff"
  372. });
  373. }
  374. },
  375. unOver: function(){
  376. if (!this.form.moveModule) if (this.form.currentSelectedModule!=this){
  377. this.node.setStyles({
  378. "border-width": "1px",
  379. "border-color": "#333"
  380. });
  381. var border = this.node.retrieve("normalBorder");
  382. this.node.setStyles(border);
  383. }
  384. },
  385. _showActions: function(){
  386. if (this.actionArea){
  387. if (this.options.actions.length){
  388. this._setActionAreaPosition();
  389. this.actionArea.setStyle("display", "block");
  390. }
  391. }
  392. },
  393. _hideActions: function(){
  394. if (this.actionArea) this.actionArea.setStyle("display", "none");
  395. },
  396. selected: function(force){
  397. if (this.form && this.form.node)this.form.node.focus();
  398. if (this.form.currentSelectedModule){
  399. if (!force && this.form.currentSelectedModule==this){
  400. return true;
  401. }else{
  402. this.form.currentSelectedModule.unSelected();
  403. }
  404. }
  405. if (this.form.propertyMultiTd){
  406. this.form.propertyMultiTd.hide();
  407. this.form.propertyMultiTd = null;
  408. }
  409. this.form.unSelectedMulti();
  410. this.node.setStyles({
  411. "border-width": "1.5px",
  412. "border-color": "red"
  413. });
  414. this._showActions();
  415. this.form.currentSelectedModule = this;
  416. if (this.treeNode){
  417. this.treeNode.selectNode();
  418. (new Fx.Scroll(this.form.designer.propertyDomScrollArea)).toElement(this.treeNode.node);
  419. // this.treeNode.node.scrollIntoView();
  420. }
  421. var historyLog;
  422. if( this.form.brushStyle || this.form.brushInputStyle ){
  423. historyLog = this.createHistoryLog();
  424. }
  425. if (this.form.brushStyle){
  426. this.json.styles = Object.clone(this.form.brushStyle);
  427. this.setPropertiesOrStyles("styles");
  428. // if (this.property) this.property.loadMaplist();
  429. }
  430. if (this.form.brushInputStyle){
  431. this.json.inputStyles = Object.clone(this.form.brushInputStyle);
  432. this.setPropertiesOrStyles("inputStyles");
  433. // if (this.property) this.property.loadMaplist();
  434. }
  435. if( this.form.brushStyle || this.form.brushInputStyle ){
  436. if (this.property) this.property.loadMaplist();
  437. this.addHistoryLog("styleBrush", null, historyLog);
  438. }
  439. this.showProperty();
  440. },
  441. unSelected: function(){
  442. this.node.setStyles({
  443. "border-width": "1px",
  444. "border-color": "#333"
  445. });
  446. var border = this.node.retrieve("normalBorder");
  447. this.node.setStyles(border);
  448. this._hideActions();
  449. this.form.currentSelectedModule = null;
  450. this.hideProperty();
  451. },
  452. selectedMulti: function(){
  453. if (this.form.selectedModules.indexOf(this)==-1){
  454. this.form.selectedModules.push(this);
  455. this.node.setStyle("border-color", "red");
  456. }
  457. },
  458. unSelectedMulti: function(){
  459. if (this.form.selectedModules.indexOf(this)!=-1){
  460. this.form.selectedModules.erase(this);
  461. this.node.setStyle("border-color", "#333");
  462. }
  463. },
  464. showProperty: function(callback){
  465. if (!this.property){
  466. this.property = new MWF.xApplication.process.FormDesigner.Property(this, this.form.designer.propertyContentArea, this.form.designer, {
  467. "path": this.options.propertyPath,
  468. "onPostLoad": function(){
  469. this.property.show();
  470. this.isPropertyLoaded = true;
  471. if (callback) callback();
  472. }.bind(this),
  473. "onPostShow": function () {
  474. // if( this.form.history )this.originalJson = Object.clone(this.json);
  475. }.bind(this)
  476. });
  477. this.property.load();
  478. }else{
  479. this.property.show();
  480. if (callback) callback();
  481. }
  482. },
  483. hideProperty: function(){
  484. if (this.property) this.property.hide();
  485. },
  486. setBrushStyle: function( json ){
  487. this.json.styles = Object.clone(json.styles || {});
  488. this.setPropertiesOrStyles("styles");
  489. this.json.inputStyles = Object.clone(json.inputStyles || {});
  490. this.setPropertiesOrStyles("inputStyles");
  491. if (this.property) this.property.loadMaplist();
  492. },
  493. create: function(data, e, group){
  494. data.moduleGroup = group;
  495. this.json = data;
  496. this.json.id = this._getNewId();
  497. if (this.json.id){
  498. this._createMoveNode();
  499. this._setNodeMove(e, "create");
  500. }
  501. },
  502. createImmediately: function(data, relativeNode, position, selectDisabled){
  503. this.json = data;
  504. this.json.id = this._getNewId();
  505. this._createMoveNode();
  506. this._dragComplete( relativeNode, position, selectDisabled );
  507. },
  508. _createMoveNode: function(){
  509. this.moveNode = new Element("div", {
  510. "MWFType": "label",
  511. "styles": this.css.moduleNodeMove,
  512. "text": "Text",
  513. "events": {
  514. "selectstart": function(){
  515. return false;
  516. }
  517. }
  518. }).inject(this.form.container);
  519. },
  520. _onEnterOther: function(dragging, inObj){
  521. },
  522. _onLeaveOther: function(dragging, inObj){
  523. if (this.copyNode) this.copyNode.destroy();
  524. this.copyNode = null;
  525. },
  526. _onMoveEnter: function(dragging, inObj){
  527. var module = inObj.retrieve("module");
  528. if (module) module._dragIn(this);
  529. this._onEnterOther(dragging, inObj);
  530. },
  531. _getDroppableNodes: function(){
  532. return [this.form.node].concat(this.form.moduleElementNodeList, this.form.moduleContainerNodeList, this.form.moduleComponentNodeList);
  533. },
  534. _setNodeMove: function(e, operation){
  535. this._setMoveNodePosition(e);
  536. this.form.node.focus();
  537. var droppables = this._getDroppableNodes();
  538. this.operation = operation;
  539. if( this.form.history && operation === "move" ){
  540. this.fromLog = { path: this.form.history.getPath( this.node ) };
  541. }
  542. var nodeDrag = new Drag.Move(this.moveNode, {
  543. "droppables": droppables,
  544. "onEnter": function(dragging, inObj){
  545. this._onMoveEnter(dragging, inObj);
  546. }.bind(this),
  547. "onLeave": function(dragging, inObj){
  548. var module = inObj.retrieve("module");
  549. if (module) module._dragOut(this);
  550. this._onLeaveOther(dragging, inObj);
  551. }.bind(this),
  552. "onDrag": function(e){
  553. this._nodeDrag(e, nodeDrag);
  554. }.bind(this),
  555. "onDrop": function(dragging, inObj){
  556. if (inObj){
  557. var module = inObj.retrieve("module");
  558. if (module) module._dragDrop(this);
  559. this._nodeDrop( module );
  560. }else{
  561. this._dragCancel(dragging);
  562. }
  563. }.bind(this),
  564. "onCancel": function(dragging){
  565. this._dragCancel(dragging);
  566. }.bind(this)
  567. });
  568. nodeDrag.start(e);
  569. this.form.moveModule = this;
  570. this.form.recordCurrentSelectedModule = this.form.currentSelectedModule;
  571. // var d = (new Date()).getTime();
  572. this.form.selected();
  573. //var d1 = (new Date()).getTime();
  574. //alert((d1-d))
  575. },
  576. _setMoveNodePosition: function(e){
  577. // var x = e.event.clientX+2;
  578. // var y = e.event.clientY+2;
  579. var x = e.page.x+2;
  580. var y = e.page.y+2;
  581. this.moveNode.positionTo(x, y);
  582. // this.moveNode.setStyles({
  583. // "top": y,
  584. // "left": x
  585. // });
  586. },
  587. _getCopyNode: function(module){
  588. if (!this.copyNode) this._createCopyNode();
  589. this.copyNode.setStyles(this.css.moduleNodeShow);
  590. this.copyNode.empty();
  591. if (module){
  592. try{
  593. var display = module.node.getStyle("display").toString().toLowerCase();
  594. this.copyNode.setStyle("display", display);
  595. if (display==="inline" || display==="inline-block"){
  596. var h = module.node.getSize().y-2;
  597. this.copyNode.setStyle("height", ""+h+"px");
  598. //this.copyNode.setStyle("display", "inline");
  599. }
  600. }catch(e){}
  601. }
  602. // this.copyNode.setStyle("display", "block");
  603. return this.copyNode;
  604. },
  605. _positionCopyNode: function(copyNode, isIn){
  606. var display = this.node.getStyle("display");
  607. copyNode.setStyle("margin", "0");
  608. if (display.indexOf("inline") !==-1){
  609. var size = this.node.getComputedSize();
  610. copyNode.setStyle("position", "absolute");
  611. copyNode.setStyle("width", "1px");
  612. copyNode.setStyle("min-width", "0");
  613. copyNode.setStyle("height", size.height+"px");
  614. copyNode.position({
  615. relativeTo: this.node,
  616. position: 'leftTop',
  617. edge: 'rightTop'
  618. })
  619. }else{
  620. var w = copyNode.getStyle("width").toFloat();
  621. if (!w) w = copyNode.getSize().x;
  622. copyNode.setStyle("position", "absolute");
  623. copyNode.setStyle("width", ""+w+"px");
  624. copyNode.position({
  625. relativeTo: this.node,
  626. position: (!!isIn) ? 'leftBottom': 'leftTop',
  627. edge: 'leftBottom'
  628. })
  629. }
  630. },
  631. _createCopyNode: function(){
  632. this.copyNode = this.moveNode.clone();
  633. this.copyNode.setStyles(this.css.moduleNodeShow);
  634. this.copyNode.addEvent("selectstart", function(){
  635. return false;
  636. });
  637. },
  638. _showInjectAction : function( module ){
  639. if ( module.moveNode ){
  640. module.moveNode.setStyle("display","none");
  641. }
  642. this.draggingModule = module;
  643. //if( !this.node.getFirst() ){
  644. // this.inject( "top" );
  645. // return;
  646. //}
  647. if( !this.injectActionArea )this._createInjectAction();
  648. this.injectActionArea.setStyle("display","block");
  649. this._setInjectActionAreaPosition();
  650. this.injectActionEffect = new Fx.Morph(this.injectActionArea, {
  651. duration: 200,
  652. transition: Fx.Transitions.Sine.easeOut
  653. });
  654. this.injectActionEffect.start(this.form.css.injectActionArea_to);
  655. },
  656. _hideInjectAction : function(){
  657. this.draggingModule = null;
  658. if( this.injectActionArea ){
  659. this.injectActionArea.setStyle("display","none");
  660. // if (!this.injectActionEffect){
  661. // this.injectActionEffect = new Fx.Morph(this.injectActionArea, {
  662. // duration: 200,
  663. // transition: Fx.Transitions.Sine.easeOut
  664. // });
  665. // }
  666. //
  667. // var y = this.form.css.injectActionArea_to.top.toInt();
  668. // var x = this.form.css.injectActionArea_to.left.toInt();
  669. // y = y+60;
  670. // x = x+60;
  671. // // this.form.css.injectActionArea.top = ""+y+"px";
  672. // // this.form.css.injectActionArea.left = ""+x+"px";
  673. // this.injectActionEffect.start({
  674. // "width": "0px",
  675. // "height": "0px",
  676. // "top": ""+y+"px",
  677. // "left": ""+x+"px"
  678. // }).chain(function(){
  679. // this.injectActionArea.setStyle("display","none");
  680. // }.bind(this));
  681. }
  682. },
  683. _createInjectAction : function(){
  684. var css = this.form.css;
  685. if( !this.injectActionArea ){
  686. this.injectActionArea = new Element("div", { styles: css.injectActionArea }).inject(this.form.container, "after");
  687. this.injectActionTopBGNode = new Element("div", { styles : css.injectActionTopBGNode }).inject( this.injectActionArea );
  688. this.injectActionLeftBGNode = new Element("div", { styles : css.injectActionLeftBGNode }).inject( this.injectActionArea );
  689. this.injectActionRightBGNode = new Element("div", { styles : css.injectActionRightBGNode }).inject( this.injectActionArea );
  690. this.injectActionBottomBGNode = new Element("div", { styles : css.injectActionBottomBGNode }).inject( this.injectActionArea );
  691. var injectActions = {};
  692. this.options.injectActions.each( function( action ){
  693. injectActions[ action.name ] = action;
  694. });
  695. if( injectActions.before )this._createInjectActionNode( injectActions.before, this.injectActionTopBGNode );
  696. if( injectActions.top )this._createInjectActionNode( injectActions.top, this.injectActionLeftBGNode );
  697. if( injectActions.bottom )this._createInjectActionNode( injectActions.bottom, this.injectActionRightBGNode );
  698. if( injectActions.after )this._createInjectActionNode( injectActions.after, this.injectActionBottomBGNode );
  699. new Element("div", {
  700. styles : css.injectActionCancelNode,
  701. events : {
  702. click : function(){
  703. this.draggingModule._dragCancel();
  704. this._dragDrop( this.node, true );
  705. this._hideInjectAction();
  706. }.bind(this),
  707. mouseover : function(){
  708. this.setStyles( css.injectActionCancelNode_over )
  709. },
  710. mouseout : function(){
  711. this.setStyles( css.injectActionCancelNode )
  712. }
  713. }
  714. }).inject(this.injectActionArea);
  715. }
  716. },
  717. _createInjectActionNode : function( action, relativeNode ){
  718. var actionNode = new Element("div", {
  719. "styles": this.form.css[action.styles],
  720. "title": action.title
  721. }).inject( this.injectActionArea );
  722. actionNode.addEvent(action.event, function(e){
  723. this[action.action](e);
  724. }.bind(this));
  725. actionNode.addEvents({
  726. "mouseover": function(e){
  727. relativeNode.setStyle("background", "#ddd");
  728. this.draggingModule.copyNode.setStyle("display","");
  729. this.draggingModule.copyNode.inject( this.node, action.name );
  730. }.bind(this),
  731. "mouseout": function(e){
  732. relativeNode.setStyle("background", "transparent");
  733. }.bind(this)
  734. });
  735. relativeNode.set("title",action.title);
  736. relativeNode.addEvent(action.event, function(e){
  737. this[action.action](e);
  738. }.bind(this));
  739. relativeNode.setStyle("cursor","pointer");
  740. relativeNode.addEvents({
  741. "mouseover": function(e){
  742. relativeNode.setStyle("background", "#ddd");
  743. this.draggingModule.copyNode.setStyle("display","");
  744. this.draggingModule.copyNode.inject( this.node, action.name );
  745. }.bind(this),
  746. "mouseout": function(e){
  747. relativeNode.setStyle("background", "transparent");
  748. //this.draggingModule.copyNode.setStyle("display","none");
  749. }.bind(this)
  750. });
  751. },
  752. _setInjectActionAreaPosition: function(){
  753. var e = window.event || {};
  754. var formOffset = this.form.node.getOffsetParent().getPosition();
  755. //var p = this.node.getPosition(this.form.node.getOffsetParent());
  756. var y = e.pageY - formOffset.y;
  757. var x = e.pageX - formOffset.x;
  758. this.injectActionArea.setPosition({"x": x, "y": y});
  759. y = y-60;
  760. x = x-60;
  761. this.form.css.injectActionArea_to.top = ""+y+"px";
  762. this.form.css.injectActionArea_to.left = ""+x+"px";
  763. },
  764. injectBefore : function( e ){
  765. this.inject( "before" )
  766. },
  767. injectAfter : function( e ){
  768. this.inject( "after" )
  769. },
  770. injectTop : function( e ){
  771. this.inject( "top" )
  772. },
  773. injectBottom : function( e ){
  774. this.inject( "bottom" )
  775. },
  776. inject : function( position ){
  777. if ( this.draggingModule.moveNode ){
  778. this.draggingModule.moveNode.setStyle("display","");
  779. }
  780. this.draggingModule._dragComplete( this.node, position );
  781. this._dragDrop( this.node, true );
  782. this._hideInjectAction();
  783. },
  784. _nodeDrop: function( module ){
  785. if( this.dragTimeout ){
  786. window.clearTimeout( this.dragTimeout );
  787. this.dragTimeout = null;
  788. }
  789. if (this.parentContainer){
  790. var available = true;
  791. if( !this.options.injectActions )available = false;
  792. // if( module && module.moduleName === "datagrid$Data" )available = false;
  793. // if( module.parentContainer && module.parentContainer.moduleName == "datagrid$Data" )available = false;
  794. if( module && ["datagrid$Data"].contains(module.moduleName) )available = false;
  795. if( module.parentContainer && ["datagrid$Data"].contains(module.parentContainer.moduleName) )available = false;
  796. if( module.moduleName === "datatable$Data" && !module.options.allowModules.contains( this.moduleName ) )available = false;
  797. if( module.parentContainer && module.parentContainer.moduleName === "datatable$Data" &&
  798. !module.parentContainer.options.allowModules.contains( this.moduleName ) )available = false;
  799. var e = window.event || {};
  800. if( available && e.ctrlKey ){
  801. if( this.copyNode )this.copyNode.setStyle("display","none");
  802. module._showInjectAction( this );
  803. }else{
  804. this._dragComplete();
  805. }
  806. }else{
  807. this._dragCancel();
  808. }
  809. },
  810. _dragComplete: function( relativeNode, position, selectDisabled ){
  811. this.setStyleTemplate();
  812. if( this.injectNoticeNode )this.injectNoticeNode.destroy();
  813. if(this.moveNode){
  814. var overflow = this.moveNode.retrieve("overflow");
  815. if( overflow ){
  816. this.moveNode.setStyle("overflow",overflow);
  817. this.moveNode.eliminate("overflow");
  818. }
  819. }
  820. if (!this.node){
  821. this._createNode();
  822. }
  823. this._resetTreeNode();
  824. if( relativeNode && position ){
  825. this.node.inject( relativeNode, position );
  826. }else{
  827. this.node.inject(this.copyNode, "before");
  828. }
  829. this._initModule();
  830. var thisDisplay = this.node.retrieve("thisDisplay");
  831. if (thisDisplay){
  832. this.node.setStyle("display", thisDisplay);
  833. }
  834. if (this.copyNode) this.copyNode.destroy();
  835. if (this.moveNode) this.moveNode.destroy();
  836. this.moveNode = null;
  837. this.copyNode = null;
  838. this.nextModule = null;
  839. this.form.moveModule = null;
  840. this.form.json.moduleList[this.json.id] = this.json;
  841. if (this.form.scriptDesigner) this.form.scriptDesigner.createModuleScript(this.json);
  842. if( !selectDisabled )this.selected();
  843. if( this.operation && !this.historyAddDelay ){
  844. this.addHistoryLog( this.operation, null, this.fromLog );
  845. }
  846. if( !this.historyAddDelay ){
  847. this.operation = null;
  848. this.fromLog = null;
  849. }
  850. },
  851. _resetTreeNode: function(){
  852. if (this.parentContainer){
  853. if (this.treeNode){
  854. if (this.treeNode.parentNode){
  855. var originalModule = this.treeNode.parentNode.module;
  856. // if (originalModule == this.parentContainer){
  857. // if (!this.nextModule) return true;
  858. // };
  859. }
  860. this.treeNode.destroy();
  861. }
  862. this._loadTreeNode(this.parentContainer);
  863. if (this.treeNode.parentNode){
  864. if (!this.treeNode.parentNode.options.expand) this.treeNode.parentNode.expandOrCollapse();
  865. }
  866. this._resetSubTreeNode(this.node)
  867. }
  868. },
  869. _resetSubTreeNode: function(node){
  870. var subNode = node.getFirst();
  871. while (subNode){
  872. var module = subNode.retrieve("module");
  873. if (module) module._resetTreeNode();
  874. this._resetSubTreeNode(subNode);
  875. subNode = subNode.getNext();
  876. }
  877. },
  878. _createNode: function(){
  879. this.node = this.moveNode.clone(true, true);
  880. this.node.clearStyles(false);
  881. this.node.setStyles(this.css.moduleNode);
  882. this.node.set("id", this.json.id);
  883. this.node.addEvent("selectstart", function(){
  884. return false;
  885. });
  886. },
  887. _dragCancel: function(){
  888. if( this.dragTimeout ){
  889. window.clearTimeout( this.dragTimeout );
  890. this.dragTimeout = null;
  891. }
  892. if (this.node){
  893. var thisDisplay = this.node.retrieve("thisDisplay");
  894. if (thisDisplay){
  895. this.node.setStyle("display", thisDisplay);
  896. }
  897. this.selected();
  898. }else{
  899. this.data = null;
  900. if (this.form.recordCurrentSelectedModule) this.form.recordCurrentSelectedModule.selected();
  901. }
  902. this._hideInjectAction();
  903. if (this.moveNode) this.moveNode.destroy();
  904. if (this.copyNode) this.copyNode.destroy();
  905. this.copyNode = null;
  906. this.moveNode = null;
  907. this.form.moveModule = null;
  908. this.operation = null;
  909. this.fromLog = null;
  910. },
  911. _nodeDrag: function(e, drag){
  912. if( !this.dragTimeout ){
  913. this.dragTimeout = window.setTimeout(function(){
  914. var overflow = this.moveNode.getStyle("overflow");
  915. if( overflow && overflow !== "visible" ){
  916. this.moveNode.store("overflow",overflow);
  917. this.moveNode.setStyle("overflow","visible");
  918. }
  919. this.injectNoticeNode = new Element("div", {
  920. styles : this.form.css.injectNoticeNode,
  921. text : MWF.APPFD.LP.formAction.injectNotice
  922. }).inject( this.moveNode );
  923. //if (this.copyNode) this.copyNode.destroy();
  924. }.bind(this), 5000);
  925. }
  926. if (this.inContainer){
  927. var p = this.inContainer.node.getCoordinates();
  928. var now = drag.mouse.now;
  929. var height = p.height*0.4;
  930. if (p.height>200) height = 100;
  931. var y = p.top.toFloat()+height.toFloat();
  932. if (this.inContainer == this.parentContainer){
  933. if (this.parentContainer!=this.form){
  934. if (now.x > p.left && now.x < p.right && now.y < y && now.y > p.top){
  935. this.parentContainer.node.setStyles(this.parentContainer.css.moduleNode);
  936. this.parentContainer.node.setStyles(this.parentContainer.json.styles);
  937. if(e.control ){
  938. this.inContainer._dragIn(this);
  939. }else{
  940. this.parentContainer._dragInLikeElement(this);
  941. }
  942. }
  943. }
  944. }else{
  945. if (now.x > p.left && now.x < p.right && now.y < p.bottom && now.y > y){
  946. this.parentContainer.node.setStyles(this.parentContainer.css.moduleNode);
  947. this.parentContainer.node.setStyles(this.parentContainer.json.styles);
  948. this.inContainer._dragIn(this);
  949. }
  950. }
  951. }
  952. },
  953. _setControlMode: function(flag){
  954. if (this.controlMode!=flag){
  955. this.controlMode = flag;
  956. this._setControlModeNode();
  957. }
  958. },
  959. deletePropertiesOrStyles: function(name, key){
  960. if (name=="properties"){
  961. try{
  962. this.node.removeProperty(key);
  963. }catch(e){}
  964. }
  965. },
  966. setPropertiesOrStyles: function(name){
  967. if (name=="styles"){
  968. try{
  969. this.setCustomStyles();
  970. }catch(e){}
  971. }
  972. if (name=="properties"){
  973. try{
  974. this.setCustomProperties();
  975. }catch(e){}
  976. }
  977. },
  978. setCustomProperties: function(){
  979. this.node.setProperties(this.json.properties);
  980. },
  981. setCustomNodeStyles: function(node, styles){
  982. var border = node.getStyle("border");
  983. node.clearStyles();
  984. //node.setStyles(styles);
  985. node.setStyle("border", border);
  986. Object.each(styles, function(value, key){
  987. var reg = /^border\w*/ig;
  988. if (!key.test(reg)){
  989. node.setStyle(key, value);
  990. }
  991. }.bind(this));
  992. },
  993. _preprocessingModuleData: function(){
  994. this.node.clearStyles();
  995. //if (this.initialStyles) this.node.setStyles(this.initialStyles);
  996. this.json.recoveryStyles = Object.clone(this.json.styles);
  997. if (this.json.recoveryStyles) Object.each(this.json.recoveryStyles, function(value, key){
  998. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1)){
  999. //需要运行时处理
  1000. }else{
  1001. this.node.setStyle(key, value);
  1002. delete this.json.styles[key];
  1003. }
  1004. }.bind(this));
  1005. this.json.preprocessing = "y";
  1006. },
  1007. _recoveryModuleData: function(){
  1008. if (this.json.recoveryStyles) this.json.styles = this.json.recoveryStyles;
  1009. this.json.recoveryStyles = null;
  1010. },
  1011. setCustomStyles: function(){
  1012. this._recoveryModuleData();
  1013. var border = this.node.getStyle("border");
  1014. this.node.clearStyles();
  1015. this.node.setStyles(this.css.moduleNode);
  1016. if (this.initialStyles) this.node.setStyles(this.initialStyles);
  1017. this.node.setStyle("border", border);
  1018. this.parseStyles( this.node, this.json.styles );
  1019. // Object.each(this.json.styles, function(value, key){
  1020. // var reg = /^border\w*/ig;
  1021. // if (!key.test(reg)){
  1022. // if (key){
  1023. // if (key.toString().toLowerCase()==="display"){
  1024. // if (value.toString().toLowerCase()==="none"){
  1025. // this.node.setStyle("opacity", 0.3);
  1026. // }else{
  1027. // this.node.setStyle("opacity", 1);
  1028. // }
  1029. // }else{
  1030. // this.node.setStyle(key, value);
  1031. // }
  1032. // }
  1033. // }
  1034. // }.bind(this));
  1035. },
  1036. parseStyles: function(node, styles){
  1037. if (styles) Object.each(styles, function(value, key){
  1038. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1)){
  1039. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  1040. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  1041. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  1042. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  1043. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  1044. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  1045. }
  1046. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  1047. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  1048. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  1049. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  1050. }
  1051. value = o2.filterUrl(value);
  1052. }
  1053. var reg = /^border\w*/ig;
  1054. if (!key.test(reg)){
  1055. if (key){
  1056. if (key.toString().toLowerCase()==="display"){
  1057. if (value.toString().toLowerCase()==="none"){
  1058. node.setStyle("opacity", 0.3);
  1059. }else{
  1060. node.setStyle("opacity", 1);
  1061. node.setStyle(key, value);
  1062. }
  1063. }else{
  1064. node.setStyle(key, value);
  1065. }
  1066. }
  1067. }
  1068. //this.node.setStyle(key, value);
  1069. }.bind(this));
  1070. },
  1071. _setEditStyle: function(name, obj, oldValue){
  1072. var title = "";
  1073. var text = "";
  1074. if (name==="name"){
  1075. title = this.json.name || this.json.id;
  1076. if (this.json.type==="Common"){
  1077. text = text = this.json.tagName+"(Common)";
  1078. }else{
  1079. text = this.json.type.substr(this.json.type.lastIndexOf("$")+1, this.json.type.length);
  1080. }
  1081. if (this.treeNode.setText) this.treeNode.setText("<"+text+"> "+title);
  1082. }
  1083. if (name==="id"){
  1084. title = this.json.name || this.json.id;
  1085. if (!this.json.name){
  1086. if (this.json.type==="Common"){
  1087. text = text = this.json.tagName+"(Common)";
  1088. }else{
  1089. text = this.json.type.substr(this.json.type.lastIndexOf("$")+1, this.json.type.length);
  1090. }
  1091. if (this.treeNode.setText) this.treeNode.setText("<"+text+"> "+this.json.id);
  1092. }
  1093. if (this.treeNode.setTitle) this.treeNode.setTitle(this.json.id);
  1094. this.node.set("id", this.json.id);
  1095. }
  1096. this._setEditStyle_custom(name, obj, oldValue);
  1097. },
  1098. reloadMaplist: function(){
  1099. if (this.property) Object.each(this.property.maplists, function(map, name){ map.reload(this.json[name]);}.bind(this));
  1100. },
  1101. _setEditStyle_custom: function(name, obj, oldValue){
  1102. },
  1103. getHtml: function(){
  1104. var copy = this.node.clone(true, true);
  1105. copy.clearStyles(true);
  1106. this.form._clearNoId(copy);
  1107. var html = copy.outerHTML;
  1108. copy.destroy();
  1109. return html;
  1110. },
  1111. _getSubModuleJson: function(node, moduleJsons){
  1112. var subNode = node.getFirst();
  1113. while (subNode){
  1114. var module = subNode.retrieve("module");
  1115. if (module) {
  1116. moduleJsons[module.json.id] = Object.clone(module.json);
  1117. }
  1118. this._getSubModuleJson(subNode, moduleJsons);
  1119. subNode = subNode.getNext();
  1120. }
  1121. },
  1122. getJson: function(){
  1123. var json = Object.clone(this.json);
  1124. var o = {};
  1125. o[json.id] = json;
  1126. this._getSubModuleJson(this.node, o);
  1127. return o;
  1128. },
  1129. getJsonData: function(name){
  1130. var d = this.json;
  1131. Array.each(name.split("."), function (n) {
  1132. if (d) d = d[n];
  1133. });
  1134. return d;
  1135. },
  1136. checkPropertyHistory: function(name, oldValue, newValue, notSetEditStyle, compareName, force){
  1137. if( !this.form.history )return null;
  1138. var log = {
  1139. "type": "property",
  1140. "force": force,
  1141. "moduleId": this.json.id,
  1142. "moduleType": this.json.type,
  1143. "notSetEditStyle": notSetEditStyle,
  1144. "changeList": []
  1145. };
  1146. if( typeOf(name) === "array" ){
  1147. name.each(function (n, i) {
  1148. log.changeList.push({
  1149. "name": n,
  1150. "fromValue": oldValue[i],
  1151. "toValue": newValue[i] || this.getJsonData(n)
  1152. });
  1153. }.bind(this));
  1154. }else{
  1155. log.changeList.push({
  1156. "name": name,
  1157. "compareName": compareName,
  1158. "fromValue": oldValue,
  1159. "toValue": newValue || this.getJsonData(name)
  1160. });
  1161. }
  1162. this.form.history.checkProperty(log, this);
  1163. },
  1164. // createHistoryPropertyLogList: function( moduleList ){
  1165. // if( !this.form.history )return null;
  1166. // var logList = [];
  1167. // if(moduleList){
  1168. // var list = o2.typeOf(moduleList) === "array" ? moduleList : [moduleList];
  1169. // list.each(function (module) {
  1170. // logList.push( module.createHistoryPropertyLog() );
  1171. // }.bind(this));
  1172. // }
  1173. // return logList;
  1174. // },
  1175. // createHistoryPropertyLog: function ( module ) {
  1176. // if( !this.form.history )return null;
  1177. // if( !module )module = this;
  1178. // var obj = {
  1179. // "path": module.form.history.getPath(module.node),
  1180. // "from": module.originalJson,
  1181. // "to": module.json
  1182. // };
  1183. // return obj;
  1184. // },
  1185. addHistoryLog: function(operation, toModuleList, fromList, moduleId, moduleType, html ){
  1186. if( !this.form.history )return null;
  1187. var log = {
  1188. "operation": operation,
  1189. "type": "module",
  1190. "moduleType": moduleType || this.json.type,
  1191. "moduleId": moduleId || this.json.id
  1192. };
  1193. if( toModuleList ){
  1194. log.toList = this.createHistoryLogList( toModuleList );
  1195. }else{
  1196. var to = {
  1197. "json": Object.clone(this.json),
  1198. "path": this.form.history.getPath(this.node)
  1199. };
  1200. if( operation !== "move" ){
  1201. to.jsonObject = this.getJson();
  1202. to.html = html || this.node.outerHTML;
  1203. }
  1204. log.toList = [ to ];
  1205. }
  1206. if( fromList ){
  1207. log.fromList = o2.typeOf(fromList) === "array" ? fromList : [fromList];
  1208. }
  1209. this.form.history.add( log, this);
  1210. },
  1211. createHistoryLogList: function( moduleList ){
  1212. if( !this.form.history )return null;
  1213. var logList = [];
  1214. if(moduleList){
  1215. var list = o2.typeOf(moduleList) === "array" ? moduleList : [moduleList];
  1216. list.each(function (module) {
  1217. logList.push( module.createHistoryLog() );
  1218. }.bind(this));
  1219. }
  1220. return logList;
  1221. },
  1222. createHistoryLog: function ( module ) {
  1223. if( !this.form.history )return null;
  1224. if( !module )module = this;
  1225. var obj = {
  1226. "json": Object.clone(module.json),
  1227. "path": module.form.history.getPath(module.node),
  1228. "jsonObject": module.getJson(),
  1229. "html": module.node.outerHTML
  1230. };
  1231. return obj;
  1232. },
  1233. //脚本附签上的脚本编辑器
  1234. addScriptJsEditor: function (propertyName, jsEditor) {
  1235. if( !this.scriptJsEditors )this.scriptJsEditors = {};
  1236. this.scriptJsEditors[propertyName] = jsEditor;
  1237. },
  1238. getScriptJsEditor: function (propertyName) {
  1239. if( !this.scriptJsEditors ){
  1240. return null;
  1241. }else{
  1242. return this.scriptJsEditors[propertyName];
  1243. }
  1244. }
  1245. // dragInElement: function(dragging, inObj, module){
  1246. // this.containerNode = module.containerNode;
  1247. //
  1248. // // var border = this.containerNode.retrieve("thisborder", null);
  1249. // // if (!border){
  1250. // var top = this.containerNode.getStyle("border-top");
  1251. // var left = this.containerNode.getStyle("border-left");
  1252. // var bottom = this.containerNode.getStyle("border-bottom");
  1253. // var right = this.containerNode.getStyle("border-right");
  1254. //
  1255. // this.containerNode.store("thisborder", {"top": top, "left": left, "bottom": bottom, "right": right});
  1256. // // }
  1257. // this.containerNode.setStyles({"border": "1px solid #ffa200"});
  1258. //
  1259. // if (!this.copyNode) this.createCopyNode(dragging, inObj);
  1260. // this.copyNode.inject(inObj, "before");
  1261. // },
  1262. // dragInContainer: function(dragging, inObj){
  1263. // // var border = inObj.retrieve("thisborder", null);
  1264. // // if (!border){
  1265. // var top = inObj.getStyle("border-top");
  1266. // var left = inObj.getStyle("border-left");
  1267. // var bottom = inObj.getStyle("border-bottom");
  1268. // var right = inObj.getStyle("border-right");
  1269. // inObj.store("thisborder", {"top": top, "left": left, "bottom": bottom, "right": right});
  1270. // // }
  1271. //
  1272. // inObj.setStyles({"border": "1px solid #ffa200"});
  1273. //
  1274. // if (!this.copyNode) this.createCopyNode(dragging, inObj);
  1275. //
  1276. // this.copyNode.inject(inObj);
  1277. //
  1278. // this.containerNode = inObj;
  1279. // },
  1280. //
  1281. //
  1282. // dragOutElement: function(dragging, inObj){
  1283. // var border = this.containerNode.retrieve("thisborder");
  1284. // if (border) {
  1285. // this.containerNode.setStyles({
  1286. // "border-top": border.top,
  1287. // "border-left": border.left,
  1288. // "border-bottom": border.bottom,
  1289. // "border-right": border.right
  1290. // });
  1291. // }
  1292. // this.containerNode = null;
  1293. // },
  1294. // dragOutContainer: function(dragging, inObj){
  1295. // var border = inObj.retrieve("thisborder");
  1296. // if (border) {
  1297. // inObj.setStyles({
  1298. // "border-top": border.top,
  1299. // "border-left": border.left,
  1300. // "border-bottom": border.bottom,
  1301. // "border-right": border.right
  1302. // });
  1303. // // inObj.setStyles({"border": border});
  1304. // }
  1305. // if (!this.node){
  1306. // if (this.copyNode){
  1307. // this.copyNode.destroy();
  1308. // this.copyNode = null;
  1309. // }
  1310. // }
  1311. // this.containerNode = null;
  1312. // },
  1313. //
  1314. //
  1315. //
  1316. //
  1317. // dragCancel: function(dragging){
  1318. // if (this.node){
  1319. // var thisDisplay = this.node.retrieve("thisDisplay");
  1320. // if (thisDisplay){
  1321. // this.node.setStyle("display", thisDisplay);
  1322. // }
  1323. // this.selected();
  1324. // }else{
  1325. // this.data = null;
  1326. // if (this.form.recordCurrentSelectedModule) this.form.recordCurrentSelectedModule.selected();
  1327. // }
  1328. // if (dragging) dragging.destroy();
  1329. // if (this.copyNode) this.copyNode.destroy();
  1330. // this.copyNode = null;
  1331. // this.moveNode = null;
  1332. // this.form.moveModule = null;
  1333. // }
  1334. });