History.js 46 KB

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