$Module.js 41 KB

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