History.js 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315
  1. // MWF.xDesktop.requireApp("Template", "MTooltips", null, false);
  2. MWF.xApplication.process = MWF.xApplication.process || {};
  3. MWF.xApplication.process.FormDesigner = MWF.xApplication.process.FormDesigner || {};
  4. MWF.xApplication.process.FormDesigner.History = new Class({
  5. Implements: [Options, Events],
  6. Extends: MWF.widget.Common,
  7. options: {
  8. style: "default",
  9. maxLength: 20 //最大的item数,0表示不限制
  10. },
  11. initialize: function(form, container, options){
  12. this.setOptions(options);
  13. this.form = form;
  14. this.designer = form.designer;
  15. this.container = container;
  16. this.root = this.form.node;
  17. this.path = "../x_component_process_FormDesigner/$History/";
  18. this.iconPath = this.path+this.options.style+"/icon/";
  19. this.cssPath = this.path+this.options.style+"/css.wcss";
  20. this._loadCss();
  21. },
  22. load: function(data) {
  23. //存储当前表面状态数组-上一步
  24. this.preArray = [];
  25. //存储当前表面状态数组-下一步
  26. this.nextArray = [];
  27. this.node = new Element("div", {"style":"font-size:12px;"}).inject(this.container);
  28. this.add({
  29. "operation": "open", //操作 create, copy, move, delete
  30. "type": "form", //property
  31. "moduleId": (this.form.json.name || "form" )+ " ["+this.form.json.mode+"]"
  32. });
  33. // var _self = this;
  34. // this.tooltips = new MWF.FCWHistory.Tooltips(
  35. // this.form.designer.formNode,
  36. // this.actionNode,
  37. // this.form.designer,
  38. // null,
  39. // {
  40. // onPostCreate: function () {
  41. // _self.node.inject( this.contentNode );
  42. // _self.add({
  43. // "operation": "open", //操作 create, copy, move, delete
  44. // "type": "form", //property
  45. // "moduleId": "form"
  46. // });
  47. //
  48. // }
  49. // }
  50. // );
  51. // this.tooltips.load();
  52. },
  53. //获取domPath
  54. getPath: function (node) {
  55. var root = this.root;
  56. var path = [];
  57. var parent, childrens, nodeIndex;
  58. while (node && node !== root) {
  59. parent = node.parentElement;
  60. childrens = Array.from(parent.children);
  61. nodeIndex = childrens.indexOf(node);
  62. path.push(nodeIndex);
  63. node = parent;
  64. }
  65. return path.reverse();
  66. },
  67. add: function(log, module) {
  68. // var log = { //也有可能是对象数组
  69. // "operation": "create", //操作 create, copy, move, delete, cut, paste
  70. // "type": "module", //property 组件变化或属性变化
  71. // "moduleType": "", //模块类型
  72. // "moduleId": "", //模块id
  73. // "fromList": [{ //原始数据
  74. // "json": {}, //原始json
  75. // "jsonObject": {}, //本module所包含的子json
  76. // "html": "", //原始html
  77. // "path": [], //原始dom path
  78. // }],
  79. // "toList": [{ //结束数据
  80. // "json": {}, //最终json
  81. // "jsonObject": {}, //本module所包含的子json
  82. // "html": "", //最终html
  83. // "path": [], //最终dom path
  84. // }]
  85. // };
  86. var item;
  87. if( log.type === "module" ){
  88. switch (log.moduleType) {
  89. case "Table$Td":
  90. item = new MWF.FCWHistory.ModuleTableTdItem(this, log);
  91. break;
  92. case "Datatable$Title":
  93. case "Datatable$Data":
  94. item = new MWF.FCWHistory.ModuleDatatableTdItem(this, log);
  95. break;
  96. case "Tab$Page":
  97. item = new MWF.FCWHistory.ModuleTabpageItem(this, log);
  98. break;
  99. default:
  100. item = new MWF.FCWHistory.ModuleItem(this, log);
  101. }
  102. }else{
  103. item = new MWF.FCWHistory.Item(this, log);
  104. }
  105. debugger;
  106. item.load();
  107. this.addItem(item);
  108. },
  109. checkProperty: function(log, module){
  110. // var log = {
  111. // "type": "property",
  112. // "force": false,
  113. // "title": "",
  114. // "moduleId": this.json.id,
  115. // "moduleType": "",
  116. // "notSetEditStyle": false
  117. // "changeList": [
  118. // {
  119. // "name": name,
  120. // "compareName": compareName, //对比名称,value对应的是name, 但是对比名称和name不一样时可以传这个
  121. // "fromValue": oldValue,
  122. // "toValue": this.json[name]
  123. // }
  124. // ]
  125. // };
  126. var isModified = false;
  127. for( var i=0; i<log.changeList.length; i++ ){
  128. var c = log.changeList[i];
  129. if( !c.fromValue && !c.toValue )continue;
  130. if( this.compareObjects( c.fromValue, c.toValue ) )continue;
  131. isModified = true;
  132. break;
  133. }
  134. if( !isModified )return;
  135. // console.log( log );
  136. debugger;
  137. var flag = false;
  138. if( this.preArray.length ){
  139. var lastItem = this.preArray.getLast();
  140. var lastSubItem;
  141. if( lastItem.data.type === "property" ) {
  142. var change = log.changeList[0];
  143. if (lastItem.moduleIdList.contains(log.moduleId) || (change.name === "id" && lastItem.moduleIdList.contains(change.fromValue))) {
  144. if (change.name === "id") lastItem.moduleIdList.push(change.toValue);
  145. lastSubItem = lastItem.getLastSubItem();
  146. var it;
  147. while( this.nextArray.length ){
  148. it = this.nextArray.pop();
  149. it.destroy();
  150. }
  151. while( lastItem.nextArray && lastItem.nextArray.length ){
  152. it = lastItem.nextArray.pop();
  153. it.destroy();
  154. }
  155. var lastChangeList = lastSubItem.data.changeList;
  156. if ( log.force ) {
  157. lastItem.addSubItem(log);
  158. }else if( change.compareName ){
  159. if (lastChangeList.length === 1 && log.changeList.length === 1 && lastChangeList[0].compareName === change.compareName) {
  160. lastChangeList[0].toValue = change.toValue;
  161. }else{
  162. lastItem.addSubItem(log);
  163. }
  164. }else{
  165. if (lastChangeList.length === 1 && log.changeList.length === 1 && lastChangeList[0].name === change.name) {
  166. // if( lastSubItem.data.fromValue === change.toValue ){ //回到最初的值了
  167. // if( lastItem.preArray.length === 1 ){
  168. // this.destroyItem( lastItem );
  169. // }else{
  170. // lastItem.destroySubItem(lastSubItem);
  171. // }
  172. // }else{
  173. lastChangeList[0].toValue = change.toValue;
  174. // }
  175. } else {
  176. lastItem.addSubItem(log);
  177. }
  178. }
  179. flag = true;
  180. }
  181. }
  182. }
  183. if( !flag ){
  184. var item = new MWF.FCWHistory.PropertySingleItem(this, log);
  185. item.load( module );
  186. this.addItem(item);
  187. }
  188. },
  189. checkMultiProperty: function(log, modules){
  190. var flag = false;
  191. if( this.preArray.length ){
  192. var lastItem = this.preArray.getLast();
  193. if( lastItem.data.type === "multiProperty" ) {
  194. var change = log.changeList[0];
  195. var lastChangeList = lastItem.data.changeList;
  196. if (lastChangeList[0].name === change.name) {
  197. var moduleIdList = log.changeList.map(function (c) {
  198. return c.module.json.id;
  199. });
  200. if( this.compareObjects( lastItem.moduleIdList, moduleIdList ) ){
  201. var it;
  202. while( this.nextArray.length ){
  203. it = this.nextArray.pop();
  204. it.destroy();
  205. }
  206. lastItem.data.changeList.each(function ( c, i ) {
  207. c.toValue = log.changeList[i].toValue;
  208. });
  209. flag = true;
  210. }
  211. }
  212. }
  213. }
  214. if( !flag ) {
  215. //console.log(log);
  216. var item = new MWF.FCWHistory.PropertyMultiItem(this, log);
  217. item.load(modules);
  218. this.addItem(item);
  219. }
  220. },
  221. addItem: function(item){
  222. var it;
  223. while( this.nextArray.length ){
  224. it = this.nextArray.pop();
  225. it.destroy();
  226. }
  227. //删除上一个property的已经undo的subItem
  228. if( this.preArray.length ){
  229. it = this.preArray.getLast();
  230. if( it.data.type === "property" ){
  231. while( it.nextArray.length ){
  232. var subit = it.nextArray.pop();
  233. subit.destroy();
  234. }
  235. }
  236. }
  237. this.preArray.push(item);
  238. //大于最大条目数
  239. if( this.options.maxLength > 0 && this.preArray.length > this.options.maxLength ){
  240. this.destroyItem(this.preArray[0]);
  241. }
  242. },
  243. destroy: function(){
  244. var it;
  245. while( this.nextArray.length ){
  246. it = this.nextArray.pop();
  247. it.destroy();
  248. }
  249. while( this.preArray.length ){
  250. it = this.preArray.pop();
  251. it.destroy();
  252. }
  253. this.node.destroy();
  254. MWF.release(this);
  255. },
  256. destroyItem: function(item){
  257. this.preArray.erase(item);
  258. item.destroy();
  259. },
  260. goto: function(item, notRedoItem){
  261. var it;
  262. if( item.status === "pre" ){
  263. it = this.preArray.getLast();
  264. while (it && item !== it){
  265. it.undo();
  266. this.nextArray.unshift(it); //插入到灰显数组前面
  267. this.preArray.pop(); //删除preArray最后一个
  268. it = this.preArray.getLast();
  269. }
  270. item.selectModule("undo");
  271. }else if( item.status === "next" ){
  272. if( this.preArray.length ){ //上一个property的subItem要redo一下
  273. it = this.preArray.getLast();
  274. if( it.data.type === "property" )it.redo();
  275. }
  276. it = this.nextArray[0];
  277. while (it && item !== it){
  278. it.redo();
  279. this.preArray.push(it); //插入到preArray数组最后
  280. this.nextArray.shift();
  281. it = this.nextArray[0];
  282. }
  283. item.redo( notRedoItem );
  284. this.preArray.push(item); //插入到preArray数组最后
  285. this.nextArray.shift();
  286. item.selectModule("redo");
  287. }
  288. },
  289. compareObjects: function(o, p, deep){
  290. if( o === p )return true;
  291. return JSON.stringify(o) === JSON.stringify(p);
  292. }
  293. });
  294. MWF.FCWHistory = MWF.xApplication.process.FormDesigner.History;
  295. MWF.FCWHistory.Item = new Class({
  296. Implements: [Options, Events],
  297. options: {},
  298. initialize: function (history, log) {
  299. this.history = history;
  300. this.data = log;
  301. this.status = "pre";
  302. this.form = this.history.form;
  303. this.root = this.history.root;
  304. },
  305. load: function (module) {
  306. this.node = new Element("div", {
  307. styles : this._getItemStyle(),
  308. text: this._getText(),
  309. events: {
  310. click: this.comeHere.bind(this)
  311. }
  312. }).inject( this.history.node );
  313. this.node.setStyle("background-image", "url("+this.history.iconPath+ this.data.operation +".png)");
  314. this._afterLoad(module);
  315. },
  316. _afterLoad: function(){
  317. },
  318. _getItemStyle: function(){
  319. return this.history.css.itemNode;
  320. },
  321. _getText: function () {
  322. if( this.data.title )return this.data.title;
  323. var lp = MWF.xApplication.process.FormDesigner.LP.formAction;
  324. var type = this.getType();
  325. type = type ? (" <" + type + "> ") : " ";
  326. return ( lp[this.data.operation] || this.data.operation ) + type + this.data.moduleId;
  327. },
  328. getType: function(){
  329. var type = (this.data.type || "").toLowerCase();
  330. switch ( type ) {
  331. case "module": case "property":
  332. return (this.data.moduleType || "").capitalize();
  333. default:
  334. return type.capitalize();
  335. }
  336. },
  337. getTypeText: function(){
  338. var type = (this.data.type || "").toLowerCase();
  339. switch ( type ) {
  340. case "form": return this.history.designer.lp.propertyTemplate.form;
  341. case "page": return this.history.designer.lp.pageform;
  342. case "module":
  343. var moduleType = (this.data.moduleType || "").toLowerCase();
  344. var tool = this.history.designer.toolsData[moduleType] || this.history.designer.toolsData[moduleType.capitalize()];
  345. return (tool) ? tool.text : moduleType;
  346. default:
  347. return "";
  348. }
  349. },
  350. comeHere: function ( e, notRedoThis ) {
  351. debugger;
  352. this.history.goto(this, notRedoThis);
  353. },
  354. undo: function () { //回退
  355. this.status = "next";
  356. this.node.setStyles( this.history.css.itemNode_undo );
  357. this._undo();
  358. },
  359. redo: function(){ //重做
  360. this.status = "pre";
  361. this.node.setStyles(this.history.css.itemNode_redo);
  362. this._redo();
  363. },
  364. _undo: function(){
  365. },
  366. _redo: function(){
  367. },
  368. setBrushStyle: function( type ){
  369. var to = this.data.toList[0];
  370. var from = this.data.fromList[0];
  371. var dom = this.getDomByPath( to.path );
  372. if(dom){
  373. var module = dom.retrieve("module");
  374. if(module){
  375. var json = type === "undo" ? (from.json || {}) : (to.json || {});
  376. module.setBrushStyle( json );
  377. }
  378. }
  379. },
  380. destroy: function () {
  381. this.node.destroy();
  382. MWF.release(this);
  383. },
  384. unselectModule: function () {
  385. if(this.form.currentSelectedModule && this.form.currentSelectedModule.unSelected){
  386. this.form.currentSelectedModule.unSelected();
  387. }
  388. this.form.currentSelectedModule = null;
  389. if( this.form.selectedModules && this.form.selectedModules.length ){
  390. this.form.selectedModules = [];
  391. }
  392. },
  393. _selectModule: function (path) {
  394. var dom = this.getDomByPath(path);
  395. if(dom){
  396. var module = dom.retrieve("module");
  397. if(module)module.selected();
  398. }
  399. },
  400. deleteModuleList: function(){
  401. for( var i=this.data.toList.length-1; i>-1; i-- ){
  402. var to = this.data.toList[i];
  403. this._deleteModule( to.path );
  404. }
  405. },
  406. _deleteModule: function( path ){
  407. var module, dom = this.getDomByPath( path );
  408. if(dom)module = dom.retrieve("module");
  409. if(module)module.destroy();
  410. },
  411. loadModuleList: function(){
  412. for( var i=0; i<this.data.toList.length; i++ ) {
  413. var to = this.data.toList[i];
  414. this._loadModule(to.path, to.html, to.json, to.jsonObject);
  415. }
  416. },
  417. _loadModule: function( path, html, json, jsonObject ){
  418. var dom = this.injectHtmlByPath( path, html );
  419. this.addModulesJson(jsonObject);
  420. var parentModule = this.getParentModule(dom);
  421. var module = this.form.loadModule(json, dom, parentModule || this.form);
  422. module._setEditStyle_custom("id");
  423. },
  424. //根据路径顺序排序
  425. sortByPath: function( arr ){
  426. arr.sort(function (a, b) {
  427. var max = Math.max(a.path.length, b.path.length);
  428. for( var i=0; i< max; i++ ){
  429. if( a.path[i] && !b.path[i] && b.path[i]!==0 )return -1;
  430. if( b.path[i] && !a.path[i] && a.path[i]!==0 )return 1;
  431. if( a.path[i] !== b.path[i] )return a.path[i] - b.path[i];
  432. }
  433. return -1;
  434. });
  435. },
  436. //根据路径获取dom
  437. getDomByPath: function(path){
  438. var i, nodeIndex;
  439. var node = this.root;
  440. for( i=0; i<path.length; i++ ){
  441. nodeIndex = path[i];
  442. node = node.children[nodeIndex];
  443. }
  444. return node;
  445. },
  446. //插入到对应位置
  447. injectToByPath: function(path, dom){
  448. var i, nodeIndex;
  449. var node = this.root;
  450. for( i=0; i<path.length - 1; i++ ){
  451. nodeIndex = path[i];
  452. node = node.children[nodeIndex];
  453. }
  454. var last = path.getLast();
  455. if( last === 0 ){
  456. dom.inject( node, "top" );
  457. }else{
  458. var contains = false;
  459. for( i=0; i<last; i++ ){
  460. if( node.children[i] === dom ){ //如果位置包含当前dom
  461. contains = true;
  462. break;
  463. }
  464. }
  465. node = node.children[contains ? last : (last-1)];
  466. dom.inject(node, "after");
  467. }
  468. this.resetTreeNode( dom );
  469. },
  470. //插入HTML到对应位置
  471. injectHtmlByPath: function(path, html){
  472. var i, nodeIndex;
  473. var node = this.root;
  474. for( i=0; i<path.length - 1; i++ ){
  475. nodeIndex = path[i];
  476. node = node.children[nodeIndex];
  477. }
  478. var dom = new Element("div");
  479. var last = path.getLast();
  480. var parentNode = node;
  481. if( last === 0 ){
  482. dom.inject( node, "top" );
  483. }else{
  484. node = node.children[last-1];
  485. dom.inject(node, "after");
  486. }
  487. dom.outerHTML = html; //dom没了
  488. dom = parentNode.children[last];
  489. return dom;
  490. },
  491. resetTreeNode: function(node){
  492. var module = node.retrieve("module");
  493. if(module){
  494. module.parentContainer = this.getParentModule( node );
  495. module._resetTreeNode();
  496. }
  497. },
  498. addModulesJson: function( jsonObject ){
  499. if(jsonObject){
  500. for( var id in jsonObject ){
  501. this.form.json.moduleList[id] = jsonObject[id];
  502. }
  503. }
  504. },
  505. getParentModule: function (node) {
  506. var parent, parentNode = node.getParent();
  507. while( parentNode && !parent ){
  508. var mwftype = parentNode.get("mwftype");
  509. if( mwftype === "form") {
  510. parent = this.form;
  511. }else if( mwftype ){
  512. parent = parentNode.retrieve("module");
  513. }else{
  514. parentNode = parentNode.getParent();
  515. }
  516. }
  517. return parent;
  518. },
  519. getParentModuleByType: function( node, moduleType ){
  520. var parentNode = node;
  521. var module;
  522. while( parentNode && !module ){
  523. if( parentNode.get("mwftype") === moduleType )module = parentNode.retrieve("module");
  524. parentNode = parentNode.getParent();
  525. }
  526. return module;
  527. },
  528. selectModule: function(type){
  529. this.form.selected();
  530. },
  531. changeJsonDate: function(json, name, value){
  532. var key = name.split(".");
  533. var len = key.length-1;
  534. key.each(function(n, i){
  535. if (i<len) {
  536. if (!json.hasOwnProperty(n)) json[n] = {};
  537. json = json[n];
  538. }
  539. }.bind(this));
  540. if( typeOf(value) === "null" ){
  541. delete json[key[len]];
  542. }else{
  543. json[key[len]] = value;
  544. }
  545. }
  546. });
  547. MWF.FCWHistory.ModuleItem = new Class({
  548. Extends: MWF.FCWHistory.Item,
  549. _afterLoad: function () {
  550. if( this.data.toList && this.data.toList.length > 1 ){
  551. this.sortByPath(this.data.toList);
  552. }
  553. if( this.data.fromList && this.data.fromList.length > 1 ){
  554. this.sortByPath(this.data.fromList);
  555. }
  556. },
  557. _getText: function () {
  558. if( this.data.title )return this.data.title;
  559. var lp = MWF.xApplication.process.FormDesigner.LP.formAction;
  560. var type = this.getType();
  561. type = type ? (" <" + type + "> ") : " ";
  562. return ( lp[this.data.operation] || this.data.operation ) + type + this.data.moduleId;
  563. },
  564. _undo: function(){
  565. switch (this.data.operation) {
  566. case "create":
  567. this.deleteModuleList();
  568. break;
  569. case "copy":
  570. this.deleteModuleList();
  571. break;
  572. case "move":
  573. var to = this.data.toList[0];
  574. var from = this.data.fromList[0];
  575. var dom = this.getDomByPath( to.path );
  576. this.injectToByPath( from.path, dom );
  577. break;
  578. case "delete":
  579. this.loadModuleList();
  580. break;
  581. case "cut":
  582. this.loadModuleList();
  583. break;
  584. case "paste":
  585. this.deleteModuleList();
  586. break;
  587. case "styleBrush":
  588. this.setBrushStyle( "undo" );
  589. break;
  590. }
  591. this.unselectModule();
  592. },
  593. _redo: function(){
  594. switch (this.data.operation) {
  595. case "create":
  596. this.loadModuleList();
  597. break;
  598. case "copy":
  599. this.loadModuleList();
  600. break;
  601. case "move":
  602. var to = this.data.toList[0];
  603. var from = this.data.fromList[0];
  604. var dom = this.getDomByPath( from.path );
  605. this.injectToByPath( to.path, dom );
  606. break;
  607. case "delete":
  608. this.deleteModuleList();
  609. break;
  610. case "cut":
  611. this.deleteModuleList();
  612. break;
  613. case "paste":
  614. this.loadModuleList();
  615. break;
  616. case "styleBrush":
  617. this.setBrushStyle( "redo" );
  618. break;
  619. }
  620. this.unselectModule();
  621. },
  622. selectModule: function(type){
  623. if( ["delete","cut"].contains(this.data.operation) || this.data.toList.length > 1){
  624. this.form.selected();
  625. }else{
  626. this._selectModule(this.data.toList[0].path);
  627. }
  628. }
  629. });
  630. MWF.FCWHistory.ModuleTableTdItem = new Class({
  631. Extends: MWF.FCWHistory.ModuleItem,
  632. _getItemStyle: function(){
  633. return this.history.css.itemNode_table;
  634. },
  635. getTrPathList: function(){
  636. var trPathStrList = [];
  637. this.data.toList.each(function (log) {
  638. var path = Array.clone(log.path);
  639. path.pop();
  640. var str = path.join(",");
  641. if( trPathStrList.indexOf( str ) === -1 )trPathStrList.push(str);
  642. });
  643. return trPathStrList.map(function (str) {
  644. return str.split(",").map(function (path) {
  645. return path.toInt()
  646. });
  647. }.bind(this));
  648. },
  649. restoreRow: function(){
  650. this.getTrPathList().each(function (path) {
  651. this.injectHtmlByPath( path, "<tr></tr>" ); //创建tr
  652. }.bind(this));
  653. this.restoreTds();
  654. },
  655. restoreTds: function(){
  656. var log;
  657. for( var i=0; i<this.data.toList.length; i++ ){
  658. log = this.data.toList[i];
  659. this.restoreTd( log.path, log.html, log.json, log.jsonObject, i );
  660. }
  661. },
  662. restoreTd: function( path, html, json, jsonObject, i ){
  663. var tdNode = this.injectHtmlByPath( path, html );
  664. this.addModulesJson( jsonObject );
  665. var tableModule = this.getParentModuleByType(tdNode, "table");
  666. tableModule.loadExistedNodeTd(tdNode, json);
  667. },
  668. deleteRow: function(){
  669. this.deleteTds();
  670. this.getTrPathList().reverse().each(function (path) {
  671. var tr = this.getDomByPath( path );
  672. if(tr)tr.destroy();
  673. }.bind(this));
  674. },
  675. deleteTds: function(){
  676. var log, dom;
  677. for( var i=this.data.toList.length-1; i>-1; i-- ){
  678. log = this.data.toList[i];
  679. dom = this.getDomByPath( log.path );
  680. this.deleteTd( dom, i );
  681. }
  682. },
  683. deleteTd: function( dom, i ){
  684. var tableModule = this.getParentModuleByType(dom, "table");
  685. tableModule.deleteTdWithNode(dom);
  686. },
  687. _undo: function(){
  688. switch (this.data.operation) {
  689. case "insertRow": //td的操作,插入行
  690. this.deleteRow();
  691. break;
  692. case "insertCol": //td的操作,插入列
  693. this.deleteTds();
  694. break;
  695. case "deleteRow": //td的操作,删除行
  696. this.restoreRow();
  697. break;
  698. case "deleteCol": //td的操作,删除列
  699. this.restoreTds();
  700. break;
  701. case "splitCell": //拆分单元格
  702. this.deleteTds(); //先删除新建的单元格
  703. var fromLog = this.data.fromList[0]; //恢复原有的单元格
  704. this.restoreTd( fromLog.path, fromLog.html, fromLog.json, fromLog.jsonObject );
  705. break;
  706. case "mergeCell": //合并单元格
  707. //先删除新建的单元格
  708. var dom = this.getDomByPath( this.data.toList[0].path );
  709. this.deleteTd(dom);
  710. //恢复原来的单元格
  711. for( var i=0; i<this.data.fromList.length; i++ ){
  712. var log = this.data.fromList[i];
  713. this.restoreTd( log.path, log.html, log.json, log.jsonObject );
  714. }
  715. break;
  716. case "styleBrush":
  717. this.setBrushStyle( "undo" );
  718. break;
  719. }
  720. this.unselectModule();
  721. },
  722. _redo: function(){
  723. var dom, module, log;
  724. switch (this.data.operation) {
  725. case "insertRow": //td的操作,插入行
  726. this.restoreRow();
  727. break;
  728. case "insertCol": //td的操作,插入列
  729. this.restoreTds();
  730. break;
  731. case "deleteRow": //td的操作,插入列
  732. this.deleteRow();
  733. break;
  734. case "deleteCol": //td的操作,删除列
  735. this.deleteTds();
  736. break;
  737. case "splitCell": //拆分单元格
  738. dom = this.getDomByPath( this.data.fromList[0].path );
  739. this.deleteTd( dom );
  740. this.restoreTds();
  741. break;
  742. case "mergeCell": //合并单元格
  743. //删除原单元格
  744. for( var i=this.data.fromList.length-1; i>-1; i--){
  745. dom = this.getDomByPath( this.data.fromList[i].path );
  746. this.deleteTd(dom);
  747. }
  748. //恢复新的单元格
  749. var to = this.data.toList[0];
  750. this.restoreTd( to.path, to.html, to.json, to.jsonObject );
  751. break;
  752. case "styleBrush":
  753. this.setBrushStyle( "redo" );
  754. break;
  755. }
  756. this.unselectModule();
  757. },
  758. selectModule: function(type){
  759. if( ["mergeCell"].contains(this.data.operation) ){
  760. this._selectModule(this.data.toList[0].path);
  761. }else{
  762. this.selectTableModule();
  763. }
  764. },
  765. selectTableModule: function () {
  766. var log = this.data.toList[0] || this.data.fromList[0];
  767. var path = Array.clone(log.path);
  768. path.pop();
  769. path.pop();
  770. var dom = this.getDomByPath(path);
  771. var tableModule = this.getParentModuleByType(dom, "table");
  772. tableModule.selected();
  773. }
  774. });
  775. MWF.FCWHistory.ModuleDatatableTdItem = new Class({
  776. Extends: MWF.FCWHistory.ModuleTableTdItem,
  777. restoreTd: function (path, html, json, jsonObject, i) {
  778. var tdNode = this.injectHtmlByPath(path, html);
  779. this.addModulesJson(jsonObject);
  780. var tableModule = this.getParentModuleByType(tdNode, "datatable");
  781. if( tdNode.tagName === "TD"){
  782. tableModule.loadExistedNodeTd(tdNode, json);
  783. }else if( tdNode.tagName === "TH"){
  784. tableModule.loadExistedNodeTh(tdNode, json);
  785. }
  786. },
  787. deleteTd: function( dom, i ){
  788. var tableModule = this.getParentModuleByType(dom, "datatable");
  789. if( dom.tagName === "TD"){
  790. tableModule.deleteTdWithNode(dom);
  791. }else if( dom.tagName === "TH"){
  792. tableModule.deleteThWithNode(dom);
  793. }
  794. },
  795. _undo: function(){
  796. switch (this.data.operation) {
  797. case "insertCol": //td的操作,插入列
  798. this.deleteTds();
  799. break;
  800. case "deleteCol": //td的操作,删除列
  801. this.restoreTds();
  802. break;
  803. case "styleBrush":
  804. this.setBrushStyle( "undo" );
  805. break;
  806. }
  807. this.unselectModule();
  808. },
  809. _redo: function(){
  810. var dom, module, log;
  811. switch (this.data.operation) {
  812. case "insertCol": //td的操作,插入列
  813. this.restoreTds();
  814. break;
  815. case "deleteCol": //td的操作,删除列
  816. this.deleteTds();
  817. break;
  818. case "styleBrush":
  819. this.setBrushStyle( "redo" );
  820. break;
  821. }
  822. this.unselectModule();
  823. },
  824. selectModule: function(type){
  825. this.selectTableModule();
  826. },
  827. selectTableModule: function () {
  828. var log = this.data.toList[0] || this.data.fromList[0];
  829. var path = Array.clone(log.path);
  830. path.pop();
  831. path.pop();
  832. var dom = this.getDomByPath(path);
  833. var tableModule = this.getParentModuleByType(dom, "datatable");
  834. tableModule.selected();
  835. }
  836. });
  837. MWF.FCWHistory.ModuleTabpageItem = new Class({
  838. Extends: MWF.FCWHistory.ModuleItem,
  839. restoreTabage: function(){
  840. var to = this.data.toList[0];
  841. var contentNode = this.injectHtmlByPath( to.content.path, to.content.html );
  842. this.addModulesJson( to.content.jsonObject );
  843. var tabNode = this.injectHtmlByPath( to.path, to.html );
  844. this.addModulesJson( to.jsonObject );
  845. var tabModule = this.getParentModuleByType(tabNode, "tab");
  846. tabModule.loadExistedNodePage(tabNode, contentNode, to.json, to.content.json);
  847. },
  848. _undo: function(){
  849. var dom, module, to = this.data.toList[0];
  850. switch (this.data.operation) {
  851. case "add":
  852. dom = this.getDomByPath( to.path );
  853. if(dom)module = dom.retrieve("module");
  854. if(module)module._delete();
  855. break;
  856. case "copy":
  857. break;
  858. case "move":
  859. dom = this.getDomByPath( to.path );
  860. this.injectToByPath( this.data.fromList[0].path, dom );
  861. dom = this.getDomByPath( to.content.path );
  862. this.injectToByPath( this.data.fromList[0].content.path, dom );
  863. break;
  864. case "delete":
  865. this.restoreTabage();
  866. break;
  867. case "styleBrush":
  868. this.setBrushStyle( "undo" );
  869. break;
  870. }
  871. this.unselectModule();
  872. },
  873. _redo: function(){
  874. var dom, module, to = this.data.toList[0];
  875. switch (this.data.operation) {
  876. case "add":
  877. this.restoreTabage();
  878. break;
  879. case "copy":
  880. break;
  881. case "move":
  882. dom = this.getDomByPath( this.data.fromList[0].path );
  883. this.injectToByPath( to.path, dom );
  884. dom = this.getDomByPath( this.data.fromList[0].content.path );
  885. this.injectToByPath( to.content.path, dom );
  886. break;
  887. case "delete":
  888. dom = this.getDomByPath( to.path );
  889. if(dom)module = dom.retrieve("module");
  890. if(module)module._delete();
  891. break;
  892. case "styleBrush":
  893. this.setBrushStyle( "redo" );
  894. break;
  895. }
  896. this.unselectModule();
  897. },
  898. selectModule: function(type){
  899. if( ["delete"].contains(this.data.operation) || this.data.toList.length > 1){
  900. this.form.selected();
  901. }else{
  902. this._selectModule(this.data.toList[0].path);
  903. }
  904. }
  905. });
  906. MWF.FCWHistory.PropertySingleItem = new Class({
  907. Extends: MWF.FCWHistory.Item,
  908. load: function (module) {
  909. this.module = module;
  910. this.node = new Element("div", {
  911. styles : this._getItemStyle(),
  912. text: this._getText()
  913. // events: {
  914. // click: this.comeHere.bind(this)
  915. // }
  916. }).inject( this.history.node );
  917. this.node.setStyle("background-image", "url("+this.history.iconPath+ "property.png)");
  918. this._afterLoad(module);
  919. },
  920. _getItemStyle: function(){
  921. return this.history.css.itemNode_property;
  922. },
  923. _afterLoad: function ( module ) {
  924. this.moduleIdList = [ this.data.moduleId ];
  925. this.nextArray = [];
  926. this.preArray = [];
  927. this.path = this.data.path || this.history.getPath( module.node );
  928. this.addSubItem( this.data );
  929. },
  930. getModule: function(){
  931. var module, dom = this.getDomByPath( this.path );
  932. if(dom)module = dom.retrieve("module");
  933. if( !module && this.module && this.form.moduleList.contains(this.module) ){
  934. module = this.module;
  935. }
  936. return module;
  937. },
  938. _getText: function () {
  939. if( this.data.title )return this.data.title;
  940. var lp = MWF.xApplication.process.FormDesigner.LP.formAction;
  941. var type = this.getType();
  942. type = type ? (" <" + type + "> ") : " ";
  943. return lp.property + " " + type + this.data.moduleId;
  944. },
  945. destroy: function () {
  946. var si = this.preArray.pop();
  947. while (si){
  948. si.destroy();
  949. si = this.preArray.pop(); //删除preArray最后一个
  950. }
  951. si = this.nextArray.pop();
  952. while (si){
  953. si.destroy();
  954. si = this.nextArray.pop(); //删除nextArray最后一个
  955. }
  956. this.node.destroy();
  957. MWF.release(this);
  958. },
  959. undo: function () { //回退
  960. this.status = "next";
  961. this.node.setStyles( this.history.css.itemNode_property_undo );
  962. this._undo();
  963. },
  964. redo: function( notRedoItem ){ //重做
  965. this.status = "pre";
  966. this.node.setStyles(this.history.css.itemNode_property_redo);
  967. if( !notRedoItem )this._redo();
  968. },
  969. _undo: function () {
  970. // for( var i=this.subItemList.length-1; i > -1; i-- ){
  971. // var subItem = this.subItemList.length[i];
  972. // subItem.undo();
  973. // }
  974. var si = this.preArray.getLast();
  975. var flag = false;
  976. while (si){
  977. si.undo();
  978. flag = true;
  979. this.nextArray.unshift(si); //插入到灰显数组前面
  980. this.preArray.pop(); //删除preArray最后一个
  981. si = this.preArray.getLast();
  982. }
  983. if(flag){
  984. var module = this.getModule();
  985. if( module && module.property ){
  986. module.property.reset();
  987. }
  988. }
  989. },
  990. _redo: function () {
  991. // for( var i=0; i < this.subItemList.length; i++ ){
  992. // var subItem = this.subItemList.length[i];
  993. // subItem.redo();
  994. // }
  995. var si = this.nextArray[0];
  996. var flag = false;
  997. while (si){
  998. si.redo();
  999. flag = true;
  1000. this.preArray.push(si); //插入到preArray数组最后
  1001. this.nextArray.shift();
  1002. si = this.nextArray[0];
  1003. }
  1004. if(flag){
  1005. var module = this.getModule();
  1006. if( module && module.property ){
  1007. module.property.reset();
  1008. }
  1009. }
  1010. },
  1011. getLastSubItem: function(){
  1012. return this.preArray.getLast();
  1013. },
  1014. destroySubItem: function(subItem){
  1015. this.preArray.erase( subItem );
  1016. subItem.destroy();
  1017. },
  1018. addSubItem: function ( data ) {
  1019. var subItem = new MWF.FCWHistory.PropertySingleItem.SubItem(this, data);
  1020. subItem.load();
  1021. this._addSubItem(subItem);
  1022. },
  1023. _addSubItem: function(subItem){
  1024. var si;
  1025. while( this.nextArray.length ){
  1026. si = this.nextArray.pop();
  1027. si.destroy();
  1028. }
  1029. this.preArray.push(subItem);
  1030. },
  1031. getNext: function(subItem){
  1032. var index = this.nextArray.indexOf(subItem);
  1033. if( index < 0 )return null;
  1034. if( index === this.nextArray.length - 1 )return null;
  1035. return this.nextArray[ index + 1 ];
  1036. },
  1037. goto: function(subItem){
  1038. var si, si_next, notSetEditStyle = false;
  1039. if( subItem.status === "pre" ){
  1040. si = this.preArray.getLast();
  1041. while (si && subItem !== si){
  1042. //如果下一个subitem的名称和现在一样,不设置SetEditStyle
  1043. si_next = this.preArray.length>1 ? this.preArray[this.preArray.length-2] : null;
  1044. notSetEditStyle = si_next && (subItem !== si_next) && ( si_next.data.changeList[0].name === si.data.changeList[0].name );
  1045. si.undo( notSetEditStyle );
  1046. this.nextArray.unshift(si); //插入到灰显数组前面
  1047. this.preArray.pop(); //删除preArray最后一个
  1048. si = this.preArray.getLast();
  1049. }
  1050. }else if( subItem.status === "next" ){
  1051. var subItemNext = this.getNext(subItem);
  1052. si = this.nextArray[0];
  1053. while (si && subItem !== si){
  1054. //如果下一个subitem的名称和现在一样,不设置SetEditStyle
  1055. si_next = this.nextArray.length>1 ? this.nextArray[1] : null;
  1056. notSetEditStyle = si_next && (subItemNext !== si_next) && ( si_next.data.changeList[0].name === si.data.changeList[0].name );
  1057. si.redo( notSetEditStyle );
  1058. this.preArray.push(si); //插入到preArray数组最后
  1059. this.nextArray.shift();
  1060. si = this.nextArray[0];
  1061. }
  1062. subItem.redo();
  1063. this.preArray.push(subItem); //插入到preArray数组最后
  1064. this.nextArray.shift();
  1065. }
  1066. var module = this.getModule();
  1067. if( module && module.property ){
  1068. module.property.reset();
  1069. }
  1070. },
  1071. selectModule: function(){
  1072. this._selectModule(this.path);
  1073. }
  1074. });
  1075. MWF.FCWHistory.PropertySingleItem.SubItem = new Class({
  1076. Extends: MWF.FCWHistory.Item,
  1077. initialize: function (item, log) {
  1078. this.parentItem = item;
  1079. this.history = item.history;
  1080. this.data = log;
  1081. this.status = "pre";
  1082. this.form = this.history.form;
  1083. this.root = this.history.root;
  1084. },
  1085. load: function () {
  1086. this.node = new Element("div", {
  1087. styles: this.history.css.subItemNode,
  1088. text: this.getText(),
  1089. events: {
  1090. click: this.comeHere.bind(this)
  1091. }
  1092. }).inject(this.history.node);
  1093. },
  1094. getText: function () {
  1095. return this.data.changeList[0].compareName || this.data.changeList[0].name;
  1096. },
  1097. comeHere: function (e) {
  1098. debugger;
  1099. this.parentItem.comeHere( null, true );
  1100. this.parentItem.goto( this );
  1101. },
  1102. undo: function ( notSetEditStyle ) { //回退
  1103. this.status = "next";
  1104. this.node.setStyles( this.history.css.subItemNode_undo );
  1105. this._undo( notSetEditStyle );
  1106. },
  1107. redo: function( notSetEditStyle ){ //重做
  1108. this.status = "pre";
  1109. this.node.setStyles( this.history.css.subItemNode_redo );
  1110. this._redo( notSetEditStyle );
  1111. },
  1112. _undo: function ( notSetEditStyle ) {
  1113. //console.log( "_undo", this.data);
  1114. var module = this.parentItem.getModule();
  1115. if (module) {
  1116. var json = module.json;
  1117. for( var i=this.data.changeList.length-1; i>-1; i-- ){
  1118. var change = this.data.changeList[i];
  1119. if (change.name === "id") {
  1120. json.id = change.fromValue;
  1121. this.form.json.moduleList[change.fromValue] = json;
  1122. delete this.form.json.moduleList[change.toValue];
  1123. }else{
  1124. // json[change.name] = change.fromValue;
  1125. this.changeJsonDate(json, change.name, change.fromValue);
  1126. module.setPropertiesOrStyles(change.name, change.toValue);
  1127. this.setScriptJsEditor(module, change.name, change.fromValue);
  1128. }
  1129. if(!notSetEditStyle && !this.data.notSetEditStyle){
  1130. //console.log("change.name")
  1131. module._setEditStyle(change.name, null, change.toValue);
  1132. }
  1133. }
  1134. }
  1135. },
  1136. _redo: function (notSetEditStyle) {
  1137. //console.log( "_redo", this.data);
  1138. var module = this.parentItem.getModule();
  1139. if (module) {
  1140. var json = module.json;
  1141. for( var i=0; i<this.data.changeList.length; i++ ){
  1142. var change = this.data.changeList[i];
  1143. if( change.name === "id" ){
  1144. json.id = change.toValue;
  1145. this.form.json.moduleList[ change.toValue ] = json;
  1146. delete this.form.json.moduleList[ change.fromValue ];
  1147. }else{
  1148. // json[change.name] = change.toValue;
  1149. this.changeJsonDate(json, change.name, change.toValue);
  1150. module.setPropertiesOrStyles(change.name, change.fromValue);
  1151. this.setScriptJsEditor(module, change.name, change.toValue);
  1152. }
  1153. if(!notSetEditStyle && !this.data.notSetEditStyle){
  1154. module._setEditStyle(change.name, null, change.fromValue);
  1155. }
  1156. }
  1157. }
  1158. },
  1159. setScriptJsEditor: function (module, name, value) {
  1160. if( module )return;
  1161. var jsEditor = module.getScriptJsEditor(name);
  1162. if(jsEditor){
  1163. var v = "";
  1164. switch ( o2.typeOf(value)) {
  1165. case "object":
  1166. if( o2.typeOf(value.code) === "string" ){
  1167. v = value.code;
  1168. }else if( o2.typeOf(value.actionScript) === "string" ){
  1169. v = value.actionScript;
  1170. }
  1171. break;
  1172. case "string":
  1173. v = value;
  1174. break;
  1175. }
  1176. jsEditor.setValue( v, true );
  1177. }
  1178. }
  1179. });
  1180. MWF.FCWHistory.PropertyMultiItem = new Class({
  1181. Extends: MWF.FCWHistory.Item,
  1182. load: function () {
  1183. this.node = new Element("div", {
  1184. styles: this._getItemStyle(),
  1185. text: this._getText(),
  1186. events: {
  1187. click: this.comeHere.bind(this)
  1188. }
  1189. }).inject(this.history.node);
  1190. this.node.setStyle("background-image", "url(" + this.history.iconPath + "property.png)");
  1191. this.modules = [];
  1192. this.moduleIdList = [];
  1193. this.data.changeList.each(function (log) {
  1194. log.path = this.history.getPath(log.module.node);
  1195. this.modules.push( log.module );
  1196. this.moduleIdList.push( log.module.json.id );
  1197. }.bind(this))
  1198. },
  1199. _getItemStyle: function () {
  1200. return this.history.css.itemNode;
  1201. },
  1202. getModule: function ( log ) {
  1203. var module, dom = this.getDomByPath(log.path);
  1204. if (dom) module = dom.retrieve("module");
  1205. if( !module && log.module ){
  1206. module = log.module;
  1207. }
  1208. return module;
  1209. },
  1210. _getText: function () {
  1211. if (this.data.title) return this.data.title;
  1212. var lp = MWF.xApplication.process.FormDesigner.LP.formAction;
  1213. return lp.batchModify + this.data.changeList[0].name + lp.property;
  1214. },
  1215. _undo: function () {
  1216. //console.log( "_undo", this.data);
  1217. for( var i=this.data.changeList.length-1; i>-1; i-- ){
  1218. var change = this.data.changeList[i];
  1219. var module = this.getModule( change );
  1220. if( module ){
  1221. var json = module.json;
  1222. this.changeJsonDate(json, change.name, change.fromValue);
  1223. module.setPropertiesOrStyles(change.name, change.toValue);
  1224. module._setEditStyle(change.name, null, change.toValue);
  1225. if( module.property )module.property.reset();
  1226. }
  1227. }
  1228. },
  1229. _redo: function () {
  1230. //console.log( "_redo", this.data);
  1231. for( var i=0; i<this.data.changeList.length; i++ ){
  1232. var change = this.data.changeList[i];
  1233. var module = this.getModule( change );
  1234. if( module ) {
  1235. var json = module.json;
  1236. this.changeJsonDate(json, change.name, change.toValue);
  1237. module.setPropertiesOrStyles(change.name, change.fromValue);
  1238. module._setEditStyle(change.name, null, change.fromValue);
  1239. if( module.property )module.property.reset();
  1240. }
  1241. }
  1242. }
  1243. });
  1244. // MWF.FCWHistory.Tooltips = new Class({
  1245. // Extends: MTooltips,
  1246. // options : {
  1247. // style: "design",
  1248. // axis: "y", //箭头在x轴还是y轴上展现
  1249. // position : { //node 固定的位置
  1250. // x : "right", //x轴上left center right, auto 系统自动计算
  1251. // y : "bottom" //y 轴上top middle bottom, auto 系统自动计算
  1252. // },
  1253. // event : "click", //事件类型,有target 时有效, mouseenter对应mouseleave,click 对应 container 的 click
  1254. // isAutoHide: false,
  1255. // hiddenDelay : 200, //ms , 有target 且 事件类型为 mouseenter 时有效
  1256. // displayDelay : 0, //ms , 有target 且事件类型为 mouseenter 时有效
  1257. // hasArrow : false,
  1258. // hasCloseAction: true,
  1259. // hasMask: false,
  1260. // isParentOffset: true,
  1261. // nodeStyles: {
  1262. // padding: "0px",
  1263. // "min-height": "100px",
  1264. // "border-radius" : "0px"
  1265. // }
  1266. // },
  1267. // _customNode : function( node, contentNode ){
  1268. // new Element("div", {
  1269. // "style": "padding-left: 10px; background-color: rgb(242, 242, 242); color: #333333; height: 30px; line-height: 30px; ",
  1270. // "text": "历史记录"
  1271. // }).inject(contentNode, "before");
  1272. // },
  1273. // })