View.js 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672
  1. MWF.xApplication = MWF.xApplication || {};
  2. MWF.xApplication.cms = MWF.xApplication.cms || {};
  3. MWF.xApplication.cms.ViewDesigner = MWF.xApplication.cms.ViewDesigner || {};
  4. MWF.CMSVD = MWF.xApplication.cms.ViewDesigner;
  5. MWF.require("MWF.widget.Common", null, false);
  6. MWF.xDesktop.requireApp("cms.ViewDesigner", "lp."+MWF.language, null, false);
  7. MWF.xApplication.cms.ViewDesigner.View = new Class({
  8. Extends: MWF.widget.Common,
  9. Implements: [Options, Events],
  10. options: {
  11. "style": "default",
  12. "showTab": true
  13. },
  14. initialize: function(designer, data, options){
  15. this.setOptions(options);
  16. this.path = "/x_component_cms_ViewDesigner/$View/";
  17. this.cssPath = "/x_component_cms_ViewDesigner/$View/"+this.options.style+"/css.wcss";
  18. this._loadCss();
  19. this.designer = designer;
  20. this.documentFields =designer.documentFields;
  21. this.formFields=designer.formFields;
  22. this.relativeForm = data.content.relativeForm;
  23. this.actions = designer.actions;
  24. this.application = designer.application;
  25. this.lp = this.designer.lp;
  26. this.node = this.designer.designNode;
  27. this.tab = this.designer.tab;
  28. this.areaNode = new Element("div.areaNode", {"styles": {"overflow": "hidden"}});
  29. //this.propertyListNode = this.designer.propertyDomArea;
  30. //this.propertyNode = this.designer.propertyContentArea;
  31. this.data = data.content;
  32. this.isNewView = this.data.isNew;
  33. this.columns = [];
  34. this.columnsRemoved = [];
  35. this.autoSave();
  36. this.designer.addEvent("queryClose", function(){
  37. if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  38. }.bind(this));
  39. },
  40. autoSave: function(){
  41. this.autoSaveTimerID = window.setInterval(function(){
  42. if (!this.autoSaveCheckNode) this.autoSaveCheckNode = this.designer.contentToolbarNode.getElement("#MWFViewAutoSaveCheck");
  43. if (this.autoSaveCheckNode){
  44. if (this.autoSaveCheckNode.get("checked")){
  45. this.save();
  46. }
  47. }
  48. }.bind(this), 60000);
  49. },
  50. load : function(){
  51. this.setAreaNodeSize();
  52. this.designer.addEvent("resize", function(){
  53. this.setAreaNodeSize();
  54. this.setPropertyContentResize();
  55. this.setViewNodeWidth();
  56. }.bind(this));
  57. this.page = this.tab.addTab(this.areaNode, this.data.name || this.designer.lp.newView, (!this.data.isNew && this.data.id!=this.designer.options.id));
  58. this.page.view = this;
  59. this.page.addEvent("show", function(){
  60. this.designer.viewListAreaNode.getChildren().each(function(node){
  61. var view = node.retrieve("view");
  62. if (view.id==this.data.id || (view.content.isNew && this.isNewView) ){
  63. if (this.designer.currentListViewItem){
  64. this.designer.currentListViewItem.setStyles(this.designer.css.listViewItem);
  65. }
  66. node.setStyles(this.designer.css.listViewItem_current);
  67. this.designer.currentListViewItem = node;
  68. this.lisNode = node;
  69. }
  70. }.bind(this));
  71. if(!this.propertyNode)this.loadProperty();
  72. }.bind(this));
  73. this.page.addEvent("queryClose", function(){
  74. if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  75. this.saveSilence();
  76. if (this.lisNode) this.lisNode.setStyles(this.designer.css.listScriptItem);
  77. }.bind(this));
  78. this.page.tabNode.addEvent("dblclick", this.designer.maxOrReturnEditor.bind(this.designer));
  79. this.createViewNode();
  80. if (this.options.showTab) this.page.showTabIm();
  81. this.setPropertyContentResize();
  82. },
  83. saveSilence: function(callback){
  84. this._save(callback);
  85. },
  86. save: function(callback){
  87. //if (this.designer.tab.showPage==this.page){
  88. //
  89. //}
  90. this._save( callback, true );
  91. },
  92. _save : function(callback, isNotice ){
  93. var _self = this;
  94. if (!this.data.name || this.data.name==""){
  95. this.designer.notice(this.lp.notice.inputName, "error");
  96. return false;
  97. }
  98. //var flag = true;
  99. //if( flag ){
  100. // this.columns.each(function(column){
  101. // flag = column.save();
  102. // })
  103. //}
  104. //if(!flag)return false;
  105. //this.columnsRemoved.each(function(column){
  106. // column.delete(function(){
  107. // _self.columnsRemoved.erase(this);
  108. // }.bind(column));
  109. //})
  110. var data = {};
  111. data.isNew = this.isNewView; //this.data.isNew;
  112. data.id = this.data.id;
  113. data.name = this.data.name;
  114. data.alias = this.data.alias;
  115. data.description = this.data.description;
  116. data.appId = this.data.application;
  117. data.formId = this.data.relativeForm.id;
  118. data.orderType = this.data.sortType;
  119. data.orderField = this.data.sortField;
  120. data.orderFieldType = this.data.sortFieldType;
  121. this.data.isNew = false;
  122. this.data.columns = this.getColumnsData();
  123. data.fields = this.getColumnsItemData();
  124. data.content = JSON.stringify(this.data);
  125. this.designer.actions.saveView(data, function(json){
  126. this.data.id = json.data.id;
  127. if( isNotice ){
  128. this.designer.notice(this.designer.lp.notice.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  129. }
  130. if (this.lisNode) {
  131. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  132. if( this.isNewView ){
  133. this.lisNode.eliminate("view");
  134. this.lisNode.store("view",json.data);
  135. }
  136. }
  137. this.data.isNew = false;
  138. this.isNewView = false;
  139. this.page.textNode.set("text", this.data.name);
  140. if (callback) callback();
  141. }.bind(this));
  142. },
  143. saveAs: function(){
  144. var form = new MWF.xApplication.cms.ViewDesigner.View.NewName(this, {
  145. name : this.data.name + "_副本"
  146. }, {
  147. onSave : function( data, callback ){
  148. this._saveAs( data.name , callback);
  149. }.bind(this)
  150. }, {
  151. app: this.designer
  152. });
  153. form.edit()
  154. },
  155. clone : function( obj ){
  156. if (null == obj || "object" != typeof obj) return obj;
  157. if ( typeof obj.length==='number'){ //数组
  158. //print( "array" );
  159. var copy = [];
  160. for (var i = 0, len = obj.length; i < len; ++i) {
  161. copy[i] = this.clone(obj[i]);
  162. }
  163. return copy;
  164. }else{
  165. var copy = {};
  166. for (var attr in obj) {
  167. copy[attr] = this.clone(obj[attr]);
  168. }
  169. return copy;
  170. }
  171. },
  172. _saveAs : function( name , callback){
  173. var _self = this;
  174. var d = this.clone( this.data );
  175. d.name = name;
  176. d.alias = "";
  177. var data = {};
  178. data.isNew = true; //this.data.isNew;
  179. data.id = this.designer.actions.getUUID();
  180. data.name = name;
  181. data.alias = "";
  182. data.description = d.description;
  183. data.appId = d.application;
  184. data.formId = d.relativeForm.id;
  185. data.orderType = d.sortType;
  186. data.orderField = d.sortField;
  187. data.orderFieldType = d.sortFieldType;
  188. d.isNew = false;
  189. var columnsData = this.clone( this.getColumnsData() );
  190. var fieldData = this.clone( this.getColumnsItemData() );
  191. columnsData.each( function( column, i ){
  192. var field = fieldData[i];
  193. var id = this.designer.actions.getUUID();
  194. column.id = id;
  195. column.isNew = false;
  196. column.viewId = data.id;
  197. field.id = id;
  198. field.isNew = true;
  199. field.viewId = data.id;
  200. }.bind(this));
  201. d.columns = columnsData;
  202. data.fields = fieldData;
  203. data.content = JSON.stringify(d);
  204. this.designer.actions.saveView(data, function(json){
  205. this.designer.notice(this.designer.lp.notice.saveAs_success, "success", this.node, {"x": "left", "y": "bottom"});
  206. if (callback) callback();
  207. }.bind(this));
  208. },
  209. explode: function(){},
  210. implode: function(){},
  211. setAreaNodeSize: function(){
  212. var size = this.node.getSize();
  213. var tabSize = this.tab.tabNodeContainer.getSize();
  214. var y = parseInt(size.y - tabSize.y);
  215. this.areaNode.setStyle("height", ""+y+"px");
  216. },
  217. setViewNodeWidth: function(){
  218. this.columnWidth = this.getColumnsWidth();
  219. var cWidth = this.columnWidth + ( this.columns.length * 2 ) + 300;
  220. if( this.node.getSize().x - 10 > cWidth ){
  221. this.viewNode.setStyle( "width", this.node.getSize().x - 10 + "px");
  222. }else{
  223. this.viewNode.setStyle( "width" , cWidth + "px" );
  224. }
  225. },
  226. createViewNode: function() {
  227. this.viewAreaNode = new Element("div.viewAreaNode", { styles : { "overflow-x" : "scroll", "overflow-y" : "hidden" } }).inject( this.areaNode );
  228. this.viewAreaNode.addEvent("scroll", function() {
  229. if (this.currentColumn)this.currentColumn._hideActions();
  230. }.bind(this));
  231. //MWF.require("MWF.widget.ScrollBar", function(){
  232. // new MWF.widget.ScrollBar(this.viewAreaNode, {"distance": 100});
  233. //}.bind(this));
  234. this.setViewAreaNodeSize();
  235. this.viewAreaNode.addEvent( "click", function(){
  236. if(this.currentColumn) {
  237. this.currentColumn.cancelCurrent();
  238. this.currentColumn.hideProperty();
  239. }
  240. this.showPropertyContent();
  241. }.bind(this));
  242. this.viewNode = new Element("div.viewNode", { "styles": this.css.viewNode }).inject( this.viewAreaNode );
  243. this.headBar = new MWF.xApplication.cms.ViewDesigner.View.HeadBar(this);
  244. if( this.data.columns && this.data.columns.length > 0 ){
  245. for(var i=0;i<this.data.columns.length;i++){
  246. var c = this.data.columns[i];
  247. this.addColumn( i, c );
  248. }
  249. }else {
  250. this.addColumn(0);
  251. }
  252. this.setViewNodeWidth();
  253. },
  254. setViewAreaNodeSize: function(){
  255. var size = this.node.getSize();
  256. var tabSize = this.tab.tabNodeContainer.getSize();
  257. var y = parseInt((size.y - tabSize.y)/3);
  258. this.viewAreaNode.setStyle("height", ""+y+"px");
  259. },
  260. getTemplateData: function( callback){
  261. if (this.dataTemplate){
  262. if (callback) callback(this.dataTemplate);
  263. }else{
  264. var templateUrl = this.path +this.options.style+"/columnTemplate.json";
  265. MWF.getJSON(templateUrl, function(responseJSON, responseText){
  266. this.dataTemplate = responseJSON;
  267. if (callback) callback(responseJSON);
  268. }.bind(this), false );
  269. }
  270. },
  271. addColumn : function( index , data ){
  272. if( !data ){
  273. this.getTemplateData();
  274. data = Object.clone( this.dataTemplate );
  275. data.isNew = true;
  276. data.id = this.actions.getUUID();
  277. }
  278. index = index || 0;
  279. if( this.columns.length <= index ){
  280. index = this.columns.length;
  281. }
  282. var column = new MWF.xApplication.cms.ViewDesigner.View.Column(this, data , index );
  283. if( this.columns.length == index ){
  284. this.columns.push( column );
  285. }else{
  286. var tmpColumns = this.columns.splice( index, this.columns.length - index , column );
  287. tmpColumns.each(function(c){
  288. c.data.index = c.data.index + 1;
  289. c.node.set("index", c.data.index);
  290. });
  291. this.columns = this.columns.concat( tmpColumns );
  292. }
  293. this.setEachColumnWidth();
  294. this.setViewNodeWidth();
  295. },
  296. moveColumn : function(fromIndex, toIndex){
  297. if( fromIndex == toIndex )return;
  298. var tmpColumns = [];
  299. for(var i=0; i<this.columns.length; i++){
  300. if( i != fromIndex ){
  301. if( i == toIndex && toIndex != this.columns.length ) {
  302. tmpColumns.push( this.columns[fromIndex] );
  303. }
  304. tmpColumns.push( this.columns[i] );
  305. if( i == this.columns.length-1 && toIndex == this.columns.length ) {
  306. tmpColumns.push( this.columns[fromIndex] );
  307. }
  308. }
  309. }
  310. this.columns = tmpColumns;
  311. for(var i=0; i<this.columns.length; i++){
  312. c = this.columns[i];
  313. c.data.index = i;
  314. c.node.set("index",i);
  315. }
  316. this.setViewNodeWidth();
  317. },
  318. removeColumn : function( index ){
  319. if( this.columns.length <= 1 ){
  320. this.designer.notice(this.designer.lp.notice.noRemoveOnlyColumn, "error");
  321. return;
  322. }
  323. for( var i=index+1; i<this.columns.length;i++ ){
  324. c = this.columns[i];
  325. c.data.index = c.data.index - 1;
  326. //c.contentNode.set("text",c.index);
  327. c.node.set("index", c.data.index);
  328. }
  329. this.showPropertyContent();
  330. var column = this.columns.splice(index, 1);
  331. if( !column[0].data.isNew ){
  332. this.columnsRemoved.push(column[0]);
  333. }
  334. column[0].removeNode();
  335. this.setEachColumnWidth();
  336. this.setViewNodeWidth();
  337. },
  338. getColumnNodes : function(){
  339. var columnNodes = [];
  340. this.columns.each(function(column){
  341. columnNodes.push(column.node);
  342. });
  343. return columnNodes;
  344. },
  345. getColumnsWidth : function(){
  346. var width = 0;
  347. this.columns.each(function(column){
  348. width = width + column.data.width;
  349. });
  350. return width;
  351. },
  352. setEachColumnWidth : function(){
  353. var totalWidth = this.getColumnsWidth();
  354. this.columns.each(function(column){
  355. if( column.property ){
  356. var per = Math.round( (column.data.width/totalWidth) * 100 );
  357. column.property.columnPercentageWidthNode.set("text", per );
  358. column.data.widthPer = per;
  359. }
  360. })
  361. },
  362. getColumnsData : function(){
  363. var data = [];
  364. this.columns.each(function(column){
  365. data.push(column.data);
  366. });
  367. return data;
  368. },
  369. getColumnsItemData: function( ignoreNew ){
  370. var data = [];
  371. this.columns.each(function(column){
  372. data.push(column.getData());
  373. if(!ignoreNew)column.data.isNew = false;
  374. });
  375. return data;
  376. },
  377. //loadProperty------------------------
  378. loadProperty: function(){
  379. this.propertyNode = new Element("div", {
  380. "styles": this.css.propertyNode
  381. }).inject(this.areaNode);
  382. this.propertyContentNode = new Element("div.propertyContentNode", {
  383. "styles": this.css.propertyContentNode
  384. }).inject(this.propertyNode);
  385. this.viewAreaPercent = 0.3;
  386. this.propertyContentResizeNode = new Element("div", {
  387. "styles": this.css.propertyContentResizeNode
  388. }).inject(this.propertyContentNode);
  389. this.propertyTitleNode = new Element("div.propertyTitleNode", {
  390. "styles": this.css.propertyTitleNode,
  391. "text": this.lp.viewProperty
  392. }).inject(this.propertyContentNode);
  393. this.propertyContentArea = new Element("div.propertyContentArea", {
  394. "styles": this.css.propertyContentArea
  395. }).inject(this.propertyContentNode);
  396. this.loadPropertyContentResize();
  397. this.setPropertyContent();
  398. this.propertyNode.addEvent("keydown", function(e){e.stopPropagation();});
  399. },
  400. setPropertyContent: function(){
  401. this.propertyContentContainArea = new Element("div.propertyContentContainArea").inject(this.propertyContentArea);
  402. this.viewPropertyNode = new Element("div.viewPropertyNode", {"styles": this.css.viewPropertyNode});
  403. //this.eventsNode = new Element("div.eventsNode", {"styles": this.css.eventsNode});
  404. MWF.require("MWF.widget.Tab", function(){
  405. this.propertyTab = new MWF.widget.Tab(this.propertyContentContainArea, {"style": "moduleList"});
  406. this.propertyTab.load();
  407. var page = this.propertyTab.addTab(this.viewPropertyNode, this.lp.base, false);
  408. page.contentNodeArea.set("class","viewContentNodeArea");
  409. this.setScrollBar(page.contentNodeArea, "small", null, null);
  410. //page = this.propertyTab.addTab(this.eventsNode, this.lp.events, false);
  411. //page.contentNodeArea.set("class","eventsContentNodeArea");
  412. //this.setScrollBar(page.contentNodeArea, "small", null, null);
  413. this.propertyTab.pages[0].showTab();
  414. }.bind(this));
  415. var table = new Element("table", { "width" : "100%", "border" : "0", "cellpadding" : "5", "cellspacing" : "0", "styles" : this.css.editTable, "class" : "editTable"}).inject( this.viewPropertyNode );
  416. var tr = new Element("tr").inject(table);
  417. var td = new Element("td", { "class" : "editTableTitle", "styles" : this.css.editTableTitle, "text" : this.lp.id }).inject(tr);
  418. var td = this.propertyIdNode = new Element("td", { "class" : "editTableValue", "styles" : this.css.editTableValue , "text": this.data.id ? this.data.id : "" }).inject(tr);
  419. var tr = new Element("tr").inject(table);
  420. var td = new Element("td", { "class" : "editTableTitle", "styles" : this.css.editTableTitle, "text" : this.lp.relativeForm }).inject(tr);
  421. var td = new Element("td", { "class" : "editTableValue", "styles" : this.css.editTableValue , "text": this.relativeForm.name }).inject(tr);
  422. var tr = new Element("tr").inject(table);
  423. var td = new Element("td", { "class" : "editTableTitle", "styles" : this.css.editTableTitle, "text" : this.lp.name }).inject(tr);
  424. var td = new Element("td", { "class" : "editTableValue", "styles" : this.css.editTableValue }).inject(tr);
  425. this.propertyNameNode = new Element("input", {"styles": this.css.editTableInput}).inject(td);
  426. this.propertyNameNode.addEvent("change",function(){
  427. this.data.name = this.propertyNameNode.get("value");
  428. }.bind(this));
  429. var tr = new Element("tr").inject(table);
  430. var td = new Element("td", { "class" : "editTableTitle", "styles" : this.css.editTableTitle, "text" : this.lp.alias }).inject(tr);
  431. var td = new Element("td", { "class" : "editTableValue", "styles" : this.css.editTableValue }).inject(tr);
  432. this.propertyAliasNode = new Element("input", {"styles": this.css.editTableInput}).inject(td);
  433. this.propertyAliasNode.addEvent("change",function(){
  434. this.data.alias = this.propertyAliasNode.get("value");
  435. }.bind(this));
  436. var tr = new Element("tr").inject(table);
  437. var td = new Element("td", { "class" : "editTableTitle", "styles" : this.css.editTableTitle, "text" : this.lp.sortColumn }).inject(tr);
  438. var td = new Element("td", { "class" : "editTableValue", "styles" : this.css.editTableValue }).inject(tr);
  439. this.propertySortFieldNode = this.getFieldsSelectElement();
  440. this.propertySortFieldNode.inject(td);
  441. this.propertySortFieldNode.addEvent("change",function(){
  442. this.data.sortField = this.getSelectText(this.propertySortFieldNode);
  443. this.data.sortFieldType = this.getSelectValue(this.propertySortFieldNode);
  444. }.bind(this));
  445. this.propertySortTypeNode = this.getSortSelectElement();
  446. this.propertySortTypeNode.inject(td);
  447. this.propertySortTypeNode.addEvent("change",function(){
  448. this.data.sortType = this.getSelectValue(this.propertySortTypeNode);
  449. }.bind(this));
  450. var tr = new Element("tr").inject(table);
  451. var td = new Element("td", { "class" : "editTableTitle", "styles" : this.css.editTableTitle, "text" : this.lp.description }).inject(tr);
  452. var td = new Element("td", { "class" : "editTableValue", "styles" : this.css.editTableValue }).inject(tr);
  453. this.propertyDescriptionNode = new Element("textarea", {"styles": this.css.editTableTextarea}).inject(td);
  454. this.propertyDescriptionNode.addEvent("change",function(){
  455. this.data.description = this.propertyDescriptionNode.get("text");
  456. }.bind(this));
  457. //var tr = new Element("tr").inject(table);
  458. //var td = new Element("td", { "class" : "editTableTitle", "styles" : this.css.editTableTitle, "text" : "JS Header" }).inject(tr);
  459. //this.jsHeaderContainer = new Element("td", { "class" : "editTableValue", "styles" : this.css.editTableValue }).inject(tr);
  460. this.setPropertyValue();
  461. },
  462. hidePropertyContent : function(){
  463. this.propertyContentContainArea.setStyle("display", "none");
  464. },
  465. showPropertyContent : function(){
  466. if(this.currentColumn) {
  467. this.currentColumn.hideProperty();
  468. }
  469. this.propertyTitleNode.set("text",this.lp.viewProperty);
  470. this.propertyContentContainArea.setStyle("display", "block");
  471. },
  472. getFormSelectElement : function(formName, formId ){
  473. var obj = new Element("select", { "styles" : this.css.propertyFormNode });
  474. this.actions.listForm(this.application.id, function(json){
  475. json.data.each(function( form ){
  476. var opt = new Element("option", {
  477. "value":form.id,
  478. "text":form.name
  479. }).inject(obj);
  480. if( formId == form.id ){
  481. opt.selected = true;
  482. }
  483. })
  484. }.bind(this), null, false);
  485. return obj;
  486. },
  487. getFieldsSelectElement : function(){
  488. var obj = new Element("select");
  489. new Element("option", {
  490. "value":"",
  491. "text":""
  492. }).inject(obj);
  493. this.documentFields.concat(this.formFields).each(function( field ){
  494. var opt = new Element("option", {
  495. "value":field.type,
  496. "text":field.name
  497. }).inject(obj);
  498. if( this.data.sortField == field.name ){
  499. opt.selected = true;
  500. }
  501. }.bind(this));
  502. return obj;
  503. },
  504. getSortSelectElement : function(){
  505. var obj = new Element("select", {"styles":{"margin-left":"5px"}});
  506. var opt = new Element("option", {
  507. "value":"ASC",
  508. "text":this.lp.asc
  509. }).inject(obj);
  510. if( this.data.sortType == "ASC" ){
  511. opt.selected = true;
  512. }
  513. var opt = new Element("option", {
  514. "value":"DESC",
  515. "text":this.lp.desc
  516. }).inject(obj);
  517. if( this.data.sortType == "DESC" ){
  518. opt.selected = true;
  519. }
  520. return obj;
  521. },
  522. getSelectValue : function( el ){
  523. var value;
  524. el.getElements("option").each(function(opt){
  525. if(opt.selected){
  526. value = opt.value;
  527. }
  528. });
  529. return value;
  530. },
  531. getSelectText : function( el ){
  532. var text;
  533. el.getElements("option").each(function(opt){
  534. if(opt.selected){
  535. text = opt.text;
  536. }
  537. });
  538. return text;
  539. },
  540. loadPropertyContentResize: function(){
  541. this.propertyContentResize = new Drag(this.propertyContentResizeNode, {
  542. "snap": 1,
  543. "onStart": function(el, e){
  544. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  545. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  546. el.store("position", {"x": x, "y": y});
  547. var size = this.viewAreaNode.getSize();
  548. el.store("initialHeight", size.y);
  549. }.bind(this),
  550. "onDrag": function(el, e){
  551. var size = this.areaNode.getSize();
  552. // var x = e.event.x;
  553. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  554. var position = el.retrieve("position");
  555. var dy = y.toFloat()-position.y.toFloat();
  556. var initialHeight = el.retrieve("initialHeight").toFloat();
  557. var height = initialHeight+dy;
  558. if (height<60) height = 60;
  559. if (height> size.y-60) height = size.y-60;
  560. this.viewAreaPercent = height/size.y;
  561. this.setPropertyContentResize();
  562. }.bind(this)
  563. });
  564. },
  565. setPropertyContentResize: function(){
  566. var size = this.areaNode.getSize();
  567. var resizeNodeSize = this.propertyContentResizeNode.getSize();
  568. var height = size.y-resizeNodeSize.y-27;
  569. var domHeight = this.viewAreaPercent*height;
  570. var contentHeight = height-domHeight;
  571. this.viewAreaNode.setStyle("height", ""+domHeight+"px");
  572. this.propertyContentNode.setStyle("height", ""+contentHeight+"px");
  573. var tabSize = this.propertyTab.tabNodeContainer.getSize();
  574. var titleSize = this.propertyTitleNode.getSize();
  575. var areaHeight = this.propertyPageHeight = contentHeight-tabSize.y-titleSize.y-20;
  576. this.propertyTab.pages.each(function( page ){
  577. page.contentNodeArea.setStyle("height",""+ areaHeight +"px" );
  578. });
  579. if( this.currentColumn && this.currentColumn.property ){
  580. this.currentColumn.property.propertyTab.pages.each(function( page ){
  581. page.contentNodeArea.setStyle("height",""+ areaHeight +"px" );
  582. })
  583. }
  584. },
  585. setPropertyValue: function(){
  586. this.propertyIdNode.set("text", this.data.id);
  587. this.propertyNameNode.set("value", this.data.name);
  588. this.propertyAliasNode.set("value", this.data.alias);
  589. this.propertyDescriptionNode.set("value", this.data.description);
  590. //this.loadScriptEditor( this.jsHeaderContainer, "jsheader", "JS Header" );
  591. //if( !this.data.events ){
  592. // this.getViewEventsData();
  593. //}
  594. //this.loadEventsEditor( this.eventsNode, this.data.events );
  595. },
  596. loadEventsEditor: function( eventsNode, eventsData ){
  597. MWF.xDesktop.requireApp("cms.FormDesigner", "widget.EventsEditor", function(){
  598. var eventsEditor = new MWF.xApplication.cms.FormDesigner.widget.EventsEditor( eventsNode, this.designer, {
  599. "helpStyle" : "cmsView",
  600. "maxObj": this.node
  601. });
  602. eventsEditor.load( eventsData );
  603. }.bind(this));
  604. },
  605. loadScriptEditor: function(node, name, title, style){
  606. var scriptContent = this.data[name];
  607. MWF.require("MWF.widget.ScriptArea", function(){
  608. var scriptArea = this.scriptArea = new MWF.widget.ScriptArea(node, {
  609. "title": title,
  610. "maxObj": this.node,
  611. "onChange": function(){
  612. this.data[name] = scriptArea.toJson();
  613. }.bind(this),
  614. "onSave": function(){
  615. this.save();
  616. }.bind(this),
  617. "style": style || "default",
  618. "helpStyle" : "cmsView"
  619. });
  620. scriptArea.load(scriptContent);
  621. }.bind(this));
  622. },
  623. getViewEventsData: function( callback){
  624. var templateUrl = this.path +this.options.style+"/viewEventsTemplate.json";
  625. MWF.getJSON(templateUrl, function(responseJSON, responseText){
  626. this.data.events = responseJSON;
  627. if (callback) callback(responseJSON);
  628. }.bind(this), false );
  629. },
  630. getOperationConfig: function( callback){
  631. if (this.operationConfig){
  632. if (callback) callback(this.operationConfig);
  633. }else{
  634. var templateUrl = this.path +this.options.style+"/operation.json";
  635. MWF.getJSON(templateUrl, function(responseJSON, responseText){
  636. this.operationConfig = responseJSON;
  637. if (callback) callback(responseJSON);
  638. }.bind(this), false );
  639. }
  640. return this.operationConfig;
  641. }
  642. });
  643. MWF.xApplication.cms.ViewDesigner.View.Column = new Class({
  644. Implements: [Options, Events],
  645. options: {
  646. "style": "default",
  647. //"propertyPath": "/x_component_process_FormDesigner/Module/Table$Td/table$td.html",
  648. "actions": [
  649. {
  650. "name": "insertColLeft",
  651. "icon": "insertColLeft.png",
  652. "event": "click",
  653. "action": "insertColLeft",
  654. "title": MWF.xApplication.cms.ViewDesigner.LP.insertColLeft
  655. },
  656. {
  657. "name": "insertColRight",
  658. "icon": "insertColRight.png",
  659. "event": "click",
  660. "action": "insertColRight",
  661. "title": MWF.xApplication.cms.ViewDesigner.LP.insertColRight
  662. },
  663. {
  664. "name": "deleteCol",
  665. "icon": "deleteCol1.png",
  666. "event": "click",
  667. "action": "deleteCol",
  668. "title": MWF.xApplication.cms.ViewDesigner.LP.deleteCol
  669. },
  670. {
  671. "name": "moveCol",
  672. "icon": "move1.png",
  673. "event": "click",
  674. "action": "moveCol",
  675. "title": MWF.xApplication.cms.ViewDesigner.LP.moveCol
  676. }
  677. ],
  678. "actionNodeStyles": {
  679. "width": "16px",
  680. "height": "16px",
  681. "margin-left": "2px",
  682. "margin-right": "2px",
  683. "float": "left",
  684. "border": "1px solid #F1F1F1",
  685. "cursor": "pointer"
  686. }
  687. },
  688. initialize: function(view, data, index ){
  689. this.view = view;
  690. this.css = view.css;
  691. this.designer = view.designer;
  692. this.data = data;
  693. this.container = view.viewNode;
  694. this.data.index = index;
  695. this.isCurrent = false;
  696. this.load();
  697. },
  698. load: function(){
  699. this.createNodes();
  700. this.createIconAction();
  701. this.setEvent();
  702. },
  703. createNodes : function(){
  704. this.node = new Element("div.column", {"styles": this.view.css.columnNode , "index" : this.data.index } );
  705. this.node.store("column", this);
  706. var tmpNode = this.container.getFirst("div.column[index="+this.data.index+"]");
  707. if( !tmpNode ){
  708. this.node.inject(this.container)
  709. }else{
  710. this.node.inject(tmpNode,"before");
  711. }
  712. this.contentNode = new Element("div", {"styles": this.view.css.columnContentNode } ).inject(this.node);
  713. this.contentTitleNode = new Element("div.columnContentTitleNode", {"styles": this.view.css.columnContentTitleNode } ).inject(this.contentNode);
  714. if( this.data.title ){
  715. this.contentTitleNode.set("text",this.data.title);
  716. }else{
  717. this.contentTitleNode.set("text", this.view.lp.noTitle );
  718. }
  719. if( this.data.width ){
  720. this.contentNode.setStyle("width",this.data.width);
  721. }else{
  722. this.contentNode.setStyle("width","150px");
  723. this.data.width = 150;
  724. }
  725. if( this.data.align ){
  726. //this.contentNode.setStyle("text-align", this.data.align );
  727. this.setAlignIcon();
  728. }
  729. this.resizeNode = new Element("div",{"styles":this.view.css.columnResizeNode}).inject(this.node);
  730. this.loadResize();
  731. if( this.data.operation ){
  732. for(var o in this.data.operation){
  733. op = this.data.operation[o];
  734. this.setOperation(op.name,op.text,op.icon,op.iconOver, op.action);
  735. }
  736. }
  737. if( this.data.sortByClickTitle == "yes" ){
  738. this.setSortIcon();
  739. }
  740. },
  741. setEvent:function(){
  742. this.node.addEvents({
  743. "click":function(e){
  744. if( !this.view.isOnDragging ){
  745. this.setCurrent();
  746. }
  747. e.stopPropagation();
  748. }.bind(this),
  749. "mouseover" : function(e){
  750. if(!this.isCurrent)this.contentNode.setStyles( this.view.css.columnContentNode_over );
  751. }.bind(this),
  752. "mouseout" : function(e){
  753. if(!this.isCurrent)this.contentNode.setStyles( this.view.css.columnContentNode );
  754. }.bind(this)
  755. })
  756. },
  757. _showActions: function(){
  758. if (this.actionArea){
  759. if (this.options.actions.length){
  760. this._setActionAreaPosition();
  761. this.actionArea.setStyle("display", "block");
  762. }
  763. }
  764. },
  765. _hideActions: function(){
  766. if (this.actionArea) this.actionArea.setStyle("display", "none");
  767. },
  768. createIconAction: function(){
  769. this.actionNodes = this.actionNodes || {};
  770. if (!this.actionArea){
  771. this.actionArea = new Element("div", {
  772. styles: {
  773. "display": "none",
  774. // "width": 18*this.options.actions.length,
  775. "position": "absolute",
  776. "background-color": "#F1F1F1",
  777. "padding": "1px",
  778. "padding-right": "0px",
  779. "border": "1px solid #AAA",
  780. "box-shadow": "0px 2px 5px #999",
  781. "opacity": 1,
  782. "z-index": 100
  783. }
  784. }).inject(this.container, "after");
  785. this.options.actions.each(function(action){
  786. var actionNode = this.actionNodes[action.name] = new Element("div", {
  787. "styles": this.options.actionNodeStyles,
  788. "title": action.title
  789. }).inject(this.actionArea);
  790. actionNode.setStyle("background", "url("+this.view.path+this.options.style+"/icon/"+action.icon+") no-repeat left center");
  791. actionNode.addEvent(action.event, function(e){
  792. this[action.action](e);
  793. e.stopPropagation();
  794. }.bind(this));
  795. actionNode.addEvents({
  796. "mouseover": function(e){
  797. e.target.setStyle("border", "1px solid #999");
  798. }.bind(this),
  799. "mouseout": function(e){
  800. e.target.setStyle("border", "1px solid #F1F1F1");
  801. }.bind(this)
  802. });
  803. }.bind(this));
  804. }
  805. },
  806. _setActionAreaPosition: function(){
  807. var p = this.node.getPosition(this.designer.designNode.getOffsetParent());
  808. var y = p.y-25;
  809. var x = p.x;
  810. this.actionArea.setPosition({"x": x, "y": y});
  811. },
  812. insertColLeft : function(){
  813. var index = this.data.index;
  814. this.view.addColumn( index );
  815. this.view.columns[index].setCurrent();
  816. },
  817. insertColRight : function(){
  818. var index = this.data.index + 1;
  819. this.view.addColumn( index );
  820. this.view.columns[index].setCurrent();
  821. },
  822. deleteCol : function(){
  823. var _self = this;
  824. this.designer.confirm("warn", this.actionNodes.deleteCol, MWF.xApplication.cms.ViewDesigner.LP.deleteColConfirmTitle, MWF.xApplication.cms.ViewDesigner.LP.deleteColConfirm, 300, 120, function(){
  825. _self.view.removeColumn(_self.data.index);
  826. this.close();
  827. }, function(){
  828. this.close();
  829. });
  830. },
  831. removeNode : function(){
  832. if(this.actionArea)this.actionArea.destroy();
  833. this.node.destroy();
  834. },
  835. cancelCurrent : function(){
  836. this.isCurrent = false;
  837. this.contentNode.setStyles(this.view.css.columnContentNode);
  838. this._hideActions()
  839. },
  840. setCurrent : function(){
  841. if(this.view.currentColumn) {
  842. if( this.view.currentColumn.currentTimeout ){
  843. clearTimeout( this.view.currentColumn.currentTimeout );
  844. }
  845. this.view.currentColumn.cancelCurrent();
  846. this.view.currentColumn.hideProperty();
  847. }
  848. this.contentNode.setStyles( this.view.css.columnContentNode_current );
  849. this.isCurrent = true;
  850. this.setNodeScroll();
  851. this.currentTimeout = setTimeout( function(){
  852. this._showActions();
  853. this.showProperty();
  854. if( this.view.propertyPageHeight ){
  855. this.property.propertyTab.pages.each(function( page ){
  856. page.contentNodeArea.setStyle("height",""+ this.view.propertyPageHeight +"px" );
  857. }.bind(this))
  858. }
  859. this.view.currentColumn = this;
  860. this.currentTimeout = null;
  861. }.bind(this), 100 );
  862. },
  863. setNodeScroll : function(){
  864. var viewAreaNode = this.view.viewAreaNode;
  865. var viewNode = this.view.viewNode;
  866. var viewAreaCrd = viewAreaNode.getCoordinates();
  867. var leftPoint = viewAreaCrd.left;
  868. var rightPoint = leftPoint + viewAreaCrd.width;
  869. var nodeCrd = this.node.getCoordinates();
  870. if( rightPoint - nodeCrd.left < 100 ){
  871. var d = nodeCrd.left + 100 - rightPoint;
  872. if( viewAreaNode.getScroll().x + d < viewNode.getSize().x ){
  873. viewAreaNode.scrollTo(viewAreaNode.getScroll().x + d, 0);
  874. }else{
  875. viewAreaNode.scrollTo( viewNode.getSize().x, 0);
  876. }
  877. }else if( leftPoint > nodeCrd.left ){
  878. var d = viewAreaNode.getScroll().x - (leftPoint - nodeCrd.left) - 10;
  879. if( d > 0 ){
  880. viewAreaNode.scrollTo( d, 0);
  881. }else{
  882. viewAreaNode.scrollTo(0, 0);
  883. }
  884. }
  885. },
  886. loadResize: function(){
  887. // var size = this.propertyNode.getSize();
  888. // var position = this.propertyResizeBar.getPosition();
  889. this.resize = new Drag(this.resizeNode,{
  890. "snap": 1,
  891. "onStart": function(el, e){
  892. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  893. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  894. el.store("position", {"x": x, "y": y});
  895. var size = this.contentNode.getSize();
  896. el.store("initialWidth", size.x);
  897. }.bind(this),
  898. "onDrag": function(el, e){
  899. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  900. // var y = e.event.y;
  901. var bodySize = this.view.viewNode.getSize();
  902. var position = el.retrieve("position");
  903. var initialWidth = el.retrieve("initialWidth").toFloat();
  904. var dx = position.x.toFloat()-x.toFloat();
  905. var width = initialWidth-dx;
  906. if (width> bodySize.x/2) width = bodySize.x/2;
  907. if (width<40) width = 40;
  908. //this.contentNode.setStyle("margin-right", width+1);
  909. this.contentNode.setStyle("width", width);
  910. this.data.width = width+10;
  911. if( this.property ){
  912. this.property.columnWidthNode.set("value",Math.round(width)+10);
  913. }
  914. this.view.setEachColumnWidth();
  915. this.view.setViewNodeWidth();
  916. }.bind(this)
  917. });
  918. },
  919. moveCol: function(e){
  920. this._createMoveNode();
  921. this._setNodeMove(e);
  922. this._hideActions();
  923. },
  924. _createMoveNode: function(){
  925. this.moveNode = new Element("div", {
  926. "MWFType": "label",
  927. "styles": this.view.css.moduleNodeMove,
  928. "text": this.node.get("text"),
  929. "events": {
  930. "selectstart": function(){
  931. return false;
  932. }
  933. }
  934. }).inject(this.container);
  935. },
  936. _setNodeMove: function(e){
  937. this._setMoveNodePosition(e);
  938. var droppables = this.view.getColumnNodes(); //[this.container].concat(this.view.node, this.view.areaNode,this.view.columns);
  939. droppables.push( this.view.headBar.node );
  940. //debugger;
  941. var nodeDrag = new Drag.Move(this.moveNode, {
  942. "droppables": droppables,
  943. "onEnter": function(dragging, inObj){
  944. var column = inObj.retrieve("column");
  945. if (column) column._dragIn(this);
  946. }.bind(this),
  947. "onLeave": function(dragging, inObj){
  948. var column = inObj.retrieve("column");
  949. if (column) column._dragOut(this);
  950. }.bind(this),
  951. "onDrag": function(e){
  952. this.view.isOnDragging = true;
  953. this._setScroll();
  954. //this._nodeDrag(e, nodeDrag);
  955. }.bind(this),
  956. "onDrop": function(dragging, inObj, e){
  957. if (inObj){
  958. var column = inObj.retrieve("column");
  959. if (column){
  960. if( column.isHeadBar ){
  961. if( this.data.index==0 ){
  962. this._dragCancel(dragging);
  963. }else{
  964. this._dragComplete( column.node );
  965. this.view.moveColumn( this.data.index, 0 );
  966. }
  967. }else{
  968. if( column.data.index+1 == this.data.index || column.data.index==this.data.index ){
  969. this._dragCancel(dragging);
  970. }else{
  971. this._dragComplete( column.node );
  972. this.view.moveColumn( this.data.index, column.data.index+1 );
  973. }
  974. }
  975. column._dragDrop(this);
  976. }else{
  977. this._dragCancel(dragging);
  978. }
  979. }else{
  980. this._dragCancel(dragging);
  981. }
  982. if( this.dragColInterval ){
  983. clearInterval( this.dragColInterval );
  984. this.dragColInterval = null;
  985. }
  986. setTimeout( function(){
  987. this.view.isOnDragging = false;
  988. }.bind(this), 100 );
  989. e.stopPropagation();
  990. }.bind(this),
  991. "onCancel": function(dragging){
  992. if( this.dragColInterval ){
  993. clearInterval( this.dragColInterval );
  994. this.dragColInterval = null;
  995. }
  996. setTimeout( function(){
  997. this.view.isOnDragging = false;
  998. }.bind(this), 100 )
  999. }.bind(this)
  1000. });
  1001. nodeDrag.start(e);
  1002. // this.form.moveModule = this;
  1003. //this.form.recordCurrentSelectedModule = this.form.currentSelectedModule;
  1004. //this.form.selected();
  1005. },
  1006. _setScroll : function(){
  1007. var viewAreaNode = this.view.viewAreaNode;
  1008. var viewAreaCrd = viewAreaNode.getCoordinates();
  1009. var leftPoint = viewAreaCrd.left;
  1010. var rightPoint = leftPoint + viewAreaCrd.width;
  1011. var viewNode = this.view.viewNode;
  1012. var coordinates = this.moveNode.getCoordinates();
  1013. if( coordinates.left + coordinates.width > rightPoint ) {
  1014. if (!this.dragColInterval) {
  1015. this.dragColInterval = setInterval(function () {
  1016. if( viewAreaNode.getScroll().x + 15 < viewNode.getSize().x ){
  1017. viewAreaNode.scrollTo(viewAreaNode.getScroll().x + 15, 0);
  1018. }else{
  1019. viewAreaNode.scrollTo( viewNode.getSize().x, 0);
  1020. }
  1021. }.bind(this), 100)
  1022. }
  1023. }else if( coordinates.left < leftPoint ){
  1024. if (!this.dragColInterval) {
  1025. this.dragColInterval = setInterval(function () {
  1026. if( viewAreaNode.getScroll().x - 15 > 0 ){
  1027. viewAreaNode.scrollTo(viewAreaNode.getScroll().x - 15, 0);
  1028. }else{
  1029. viewAreaNode.scrollTo(0, 0);
  1030. }
  1031. }.bind(this), 100)
  1032. }
  1033. }else{
  1034. if( this.dragColInterval ){
  1035. clearInterval( this.dragColInterval );
  1036. this.dragColInterval = null;
  1037. }
  1038. }
  1039. },
  1040. _dragIn : function(){ //移动时鼠标进入
  1041. this.resizeNode.setStyles( this.view.css.columnResizeNode_dragIn );
  1042. },
  1043. _dragOut : function(){ //移动时鼠标移出
  1044. this.resizeNode.setStyles( this.view.css.columnResizeNode );
  1045. },
  1046. _dragDrop : function(){ //移动到该对象时鼠标松开
  1047. this.resizeNode.setStyles( this.view.css.columnResizeNode );
  1048. },
  1049. _dragComplete: function( toNode ){ //拖拽完成
  1050. this.node.inject(toNode,"after");
  1051. this.setCurrent();
  1052. if (this.moveNode) this.moveNode.destroy();
  1053. this.moveNode = null;
  1054. },
  1055. _dragCancel: function(){ //拖拽取消
  1056. if (this.moveNode) this.moveNode.destroy();
  1057. this.moveNode = null;
  1058. },
  1059. _setMoveNodePosition: function(e){
  1060. var x = e.page.x+2;
  1061. var y = e.page.y+2;
  1062. this.moveNode.positionTo(x, y);
  1063. },
  1064. showProperty: function(){
  1065. this.view.hidePropertyContent();
  1066. this.view.propertyTitleNode.set("text", this.view.lp.columnProperty);
  1067. if (!this.property){
  1068. this.property = new MWF.xApplication.cms.ViewDesigner.View.ColumnProperty(this, this.view.propertyContentArea, this.designer, {
  1069. "onPostLoad": function(){
  1070. this.property.show();
  1071. }.bind(this)
  1072. });
  1073. this.property.load();
  1074. }else{
  1075. this.property.show();
  1076. }
  1077. },
  1078. hideProperty: function(){
  1079. if (this.property) this.property.hide();
  1080. },
  1081. setPropertiesOrStyles: function(name){
  1082. if (name=="styles"){
  1083. this.setCustomStyles();
  1084. }
  1085. if (name=="properties"){
  1086. this.node.setProperties(this.data.properties);
  1087. }
  1088. },
  1089. setCustomStyles: function(){
  1090. var border = this.node.getStyle("border");
  1091. this.node.clearStyles();
  1092. this.node.setStyles(this.css.moduleNode);
  1093. if (this.initialStyles) this.node.setStyles(this.initialStyles);
  1094. this.node.setStyle("border", border);
  1095. Object.each(this.data.styles, function(value, key){
  1096. var reg = /^border\w*/ig;
  1097. if (!key.test(reg)){
  1098. this.node.setStyle(key, value);
  1099. }
  1100. }.bind(this));
  1101. },
  1102. setSortIcon : function(){
  1103. if( this.sortIconNode ){
  1104. this.sortIconNode.setStyle("display","inline");
  1105. }else{
  1106. this.sortIconNode = new Element("div",{"styles":this.css.sortIconNode}).inject( this.contentTitleNode, "before" );
  1107. }
  1108. },
  1109. cancelSortIcon : function(){
  1110. this.sortIconNode.setStyle("display","none");
  1111. },
  1112. setAlignIcon: function(){
  1113. if( this.alignIconNode )this.alignIconNode.destroy();
  1114. if( this.data.align == "left" ){
  1115. this.alignIconNode = new Element("div",{"styles":this.css.alignleftNode}).inject( this.contentTitleNode, "after" );
  1116. }else if( this.data.align == "right" ){
  1117. this.alignIconNode = new Element("div",{"styles":this.css.alignrightNode}).inject( this.contentTitleNode, "after" );
  1118. }
  1119. },
  1120. setOperation : function(name, title, image, imageOver, action){
  1121. this.optionNodes = this.optionNodes || {};
  1122. var _self = this;
  1123. var path = this.view.path +this.view.options.style+"/operationIcon/";
  1124. if( !this.optionNodes[name] ){
  1125. if( this.contentTitleNode.get("text") == this.view.lp.noTitle ){
  1126. this.contentTitleNode.set("text","");
  1127. }
  1128. var node = this.optionNodes[name] = new Element("div", {"styles": this.view.css.operationNode, "title": title }).inject(this.contentNode, "bottom" );
  1129. node.setStyle("background-image","url("+path+image+")");
  1130. }
  1131. },
  1132. deleteOperation : function( name ) {
  1133. if (this.optionNodes && this.optionNodes[name]) {
  1134. this.optionNodes[name].destroy();
  1135. this.optionNodes[name] = null;
  1136. delete this.optionNodes[name];
  1137. }
  1138. flag = false;
  1139. for (var op in this.optionNodes) {
  1140. flag = true;
  1141. }
  1142. if (!flag) {
  1143. if (this.contentTitleNode.get("text") == "") {
  1144. this.contentTitleNode.set("text", this.view.lp.noTitle );
  1145. }
  1146. }
  1147. },
  1148. delete : function(callback){
  1149. if( !this.data.isNew && this.data.id ){
  1150. this.view.actions.deleteViewColumn( this.data.id, function(json){
  1151. if(callback)callback();
  1152. }.bind(this));
  1153. }
  1154. },
  1155. getData: function(){
  1156. var data = {};
  1157. data.id = this.data.id;
  1158. data.isNew = this.data.isNew;
  1159. data.viewId = this.view.data.id;
  1160. data.fieldTitle = this.data.title;
  1161. data.fieldName = this.data.value;
  1162. data.xshowSequence = this.view.data.relativeForm.id;
  1163. return data;
  1164. },
  1165. save : function(callback){
  1166. var flag = true;
  1167. if( this.data.value && this.data.value!="" ){
  1168. var data = {};
  1169. data.id = this.data.id;
  1170. data.isNew = this.data.isNew;
  1171. data.viewId = this.view.data.id;
  1172. data.fieldTitle = this.data.title;
  1173. data.fieldName = this.data.value;
  1174. data.xshowSequence = this.view.data.relativeForm.id;
  1175. this.view.actions.saveViewColumn( data, function(json){
  1176. //this.data.id = json.data.id;
  1177. this.data.isNew = false;
  1178. if(callback)callback();
  1179. }.bind(this), function(){
  1180. flag = false;
  1181. }.bind(this), false );
  1182. }else{ //如果字段为空,且已经保存过,则删除
  1183. if( !this.data.isNew ){
  1184. this["delete"]( callback );
  1185. this.data.isNew = true;
  1186. }
  1187. }
  1188. return flag;
  1189. }
  1190. });
  1191. MWF.xApplication.cms.ViewDesigner.View.HeadBar = new Class({
  1192. initialize: function(view){
  1193. this.view = view;
  1194. this.designer = view.designer;
  1195. this.container = view.viewNode;
  1196. this.isHeadBar = true;
  1197. this.load();
  1198. },
  1199. load: function(){
  1200. this.createNodes();
  1201. },
  1202. createNodes : function(){
  1203. this.node = new Element("div.column", {"styles": this.view.css.headBarNode } );
  1204. this.node.store("column", this);
  1205. this.node.inject(this.container);
  1206. this.headBarContentNode = new Element("div", {"styles": this.view.css.headBarContentNode } ).inject(this.node);
  1207. this.resizeNode = new Element("div",{"styles":this.view.css.headBarResizeNode}).inject(this.node);
  1208. },
  1209. _dragIn : function(){ //移动时鼠标进入
  1210. this.resizeNode.setStyles( this.view.css.headBarResizeNode_dragIn );
  1211. },
  1212. _dragOut : function(){ //移动时鼠标移出
  1213. this.resizeNode.setStyles( this.view.css.headBarResizeNode );
  1214. },
  1215. _dragDrop : function(){ //移动到该对象时鼠标松开
  1216. this.resizeNode.setStyles( this.view.css.headBarResizeNode );
  1217. }
  1218. });
  1219. MWF.xApplication.cms.ViewDesigner.View.ColumnProperty = new Class({
  1220. Extends: MWF.widget.Common,
  1221. Implements: [Options, Events],
  1222. options: {
  1223. "style": "default"
  1224. },
  1225. initialize: function(column, propertyNode, designer, options){
  1226. this.setOptions(options);
  1227. this.column = column;
  1228. this.data = column.data;
  1229. this.css = column.css;
  1230. this.lp = column.view.lp;
  1231. this.designer = designer;
  1232. this.propertyNode = propertyNode;
  1233. },
  1234. load: function(){
  1235. this.fireEvent( "queryLoad" );
  1236. this.fireEvent( "postLoad" );
  1237. },
  1238. editProperty: function(td){
  1239. },
  1240. show: function(){
  1241. if (!this.propertyContent){
  1242. this.createNode();
  1243. //this.loadEventsEditor( this.eventsNode, this.data.events );
  1244. }else{
  1245. this.propertyContent.setStyle("display", "block");
  1246. }
  1247. },
  1248. hide: function(){
  1249. //this.JsonTemplate = null;
  1250. //this.propertyNode.set("html", "");
  1251. if (this.propertyContent) this.propertyContent.setStyle("display", "none");
  1252. },
  1253. createNode : function(){
  1254. var _self = this;
  1255. this.propertyContent = new Element("div", {"styles": this.css.columnPropertyContent }).inject(this.propertyNode);
  1256. this.basePropertyNode = new Element("div" );
  1257. //this.eventsNode = new Element("div");
  1258. MWF.require("MWF.widget.Tab", function(){
  1259. this.propertyTab = new MWF.widget.Tab(this.propertyContent, {"style": "moduleList"});
  1260. this.propertyTab.load();
  1261. var page = this.propertyTab.addTab(this.basePropertyNode, this.lp.base, false);
  1262. this.setScrollBar(page.contentNodeArea, "small", null, null);
  1263. //page = this.propertyTab.addTab(this.eventsNode, this.lp.events, false);
  1264. //this.setScrollBar(page.contentNodeArea, "small", null, null);
  1265. this.propertyTab.pages[0].showTab();
  1266. }.bind(this));
  1267. var table = new Element("table", { "width" : "100%", "border" : "0", "cellpadding" : "5", "cellspacing" : "0", "styles" : this.css.editTable, "class" : "editTable"}).inject( this.basePropertyNode );
  1268. var tr = new Element("tr").inject(table);
  1269. var td = new Element("td", { "class" : "editTableTitle", "styles" : this.css.editTableTitle, "text" : this.lp.columnTitle }).inject(tr);
  1270. var td = new Element("td", { "class" : "editTableValue", "styles" : this.css.editTableValue }).inject(tr);
  1271. this.columnTitleNode = new Element("input", {
  1272. "type" : "text",
  1273. "class" : "editTableInput",
  1274. "styles" : this.css.editTableInput,
  1275. "value" : this.data.title
  1276. }).inject(td);
  1277. this.columnTitleNode.addEvents({
  1278. "change" : function(){
  1279. var val = this.columnTitleNode.get("value");
  1280. this.data.title = val;
  1281. this.column.contentTitleNode.set("text",val);
  1282. }.bind(this)
  1283. });
  1284. var tr = new Element("tr").inject(table);
  1285. var td = new Element("td", { "class" : "editTableTitle", "styles" : this.css.editTableTitle }).inject(tr);
  1286. var td = new Element("td", { "class" : "editTableValue", "styles" : this.css.editTableValue }).inject(tr);
  1287. this.loadSort(td);
  1288. var tr = new Element("tr").inject(table);
  1289. var td = new Element("td", { "class" : "editTableTitle", "styles" : this.css.editTableTitle, "text" : this.lp.columnValue }).inject(tr);
  1290. var td = new Element("td", { "class" : "editTableValue", "styles" : this.css.editTableValue }).inject(tr);
  1291. this.columnValueNode = this.getFieldSelectElement();
  1292. this.columnValueNode.inject(td);
  1293. this.columnValueNode.addEvent("change",function(){
  1294. this.data.value = this.column.view.getSelectValue(this.columnValueNode);
  1295. }.bind(this));
  1296. var tr = new Element("tr").inject(table);
  1297. var td = new Element("td", { "class" : "editTableTitle", "styles" : this.css.editTableTitle, "text" : this.lp.columnWidth }).inject(tr);
  1298. var td = new Element("td", { "class" : "editTableValue", "styles" : this.css.editTableValue }).inject(tr);
  1299. if( this.data.widthPer ){
  1300. this.columnPercentageWidthNode = new Element("span",{"text": this.data.widthPer }).inject(td);
  1301. }else{
  1302. this.columnPercentageWidthNode = new Element("span",{"text": Math.round( this.data.width/this.column.view.getColumnsWidth() * 100) }).inject(td);
  1303. }
  1304. if( this.data.widthType == "px" ){
  1305. this.columnPercentageWidthNode.setStyle("display","none");
  1306. }
  1307. this.columnWidthNode = new Element("input", {
  1308. "type" : "text",
  1309. "class" : "editTableInput",
  1310. "styles" : this.css.editTableInputNoWidth,
  1311. "value" : this.data.width
  1312. }).inject(td);
  1313. this.columnWidthNode.setStyles({"width":"50px"});
  1314. if( this.data.widthType != "px" ){
  1315. this.columnWidthNode.setStyle("display","none");
  1316. }
  1317. this.columnWidthNode.addEvents({
  1318. "change" : function(){
  1319. var width = Math.round(this.value);
  1320. if( !isNaN( width ) ){
  1321. if( width > 10 ){
  1322. _self.column.node.setStyle("width",width);
  1323. _self.column.contentNode.setStyle("width",width-10);
  1324. _self.data.width = width;
  1325. _self.column.view.setViewNodeWidth();
  1326. }
  1327. }
  1328. }
  1329. });
  1330. this.columnWidthTypeNode = new Element("select").inject( td );
  1331. new Element("option" , {"value": "percentage", "text":this.lp.percentage }).inject(this.columnWidthTypeNode);
  1332. var option = new Element("option" , {"value": "px", "text":this.lp.px }).inject(this.columnWidthTypeNode);
  1333. if( this.data.widthType == "px" )option.selected = true;
  1334. this.columnWidthTypeNode.addEvents({
  1335. "change" : function(){
  1336. for(var i=0; i<this.options.length;i++){
  1337. option = this.options[i];
  1338. if(option.selected){
  1339. _self.data.widthType = option.value;
  1340. if( option.value == "percentage" ){
  1341. _self.widthType = "percentage";
  1342. _self.columnWidthNode.setStyle("display","none");
  1343. _self.columnPercentageWidthNode.setStyle("display","inline");
  1344. var per = Math.round(_self.column.node.getSize().x / _self.column.view.getColumnsWidth() * 100);
  1345. _self.columnPercentageWidthNode.set("text", per );
  1346. _self.data.widthPer = per;
  1347. _self.column.view.setViewNodeWidth();
  1348. }else{
  1349. _self.widthType = "px";
  1350. _self.columnWidthNode.setStyle("display","inline");
  1351. var width = _self.column.node.getSize().x;
  1352. _self.columnWidthNode.set("value",width);
  1353. _self.data.width = width;
  1354. _self.columnPercentageWidthNode.setStyle("display","none");
  1355. _self.column.view.setViewNodeWidth();
  1356. }
  1357. }
  1358. }
  1359. }
  1360. });
  1361. var tr = new Element("tr").inject(table);
  1362. var td = new Element("td", { "class" : "editTableTitle", "styles" : this.css.editTableTitle, "text" : this.lp.columnAlign }).inject(tr);
  1363. var td = new Element("td", { "class" : "editTableValue", "styles" : this.css.editTableValue }).inject(tr);
  1364. this.columnAlignNode = this.loadAlign(td);
  1365. this.columnAlignNode.addEvent("change",function(){
  1366. this.data.align = this.column.view.getSelectValue(this.columnAlignNode);
  1367. this.column.setAlignIcon();
  1368. }.bind(this));
  1369. var tr = new Element("tr").inject(table);
  1370. var td = new Element("td", { "class" : "editTableTitle", "styles" : this.css.editTableTitle, "text" : this.lp.action }).inject(tr);
  1371. var td = new Element("td", { "class" : "editTableValue", "styles" : this.css.editTableValue }).inject(tr);
  1372. this.loadOperation(td);
  1373. },
  1374. loadSort : function( container ){
  1375. var _self = this;
  1376. var node = new Element("span", {"styles":this.css.propertyCheckBox } ).inject( container );
  1377. var input = new Element("input",{
  1378. "type" : "checkbox",
  1379. "value" : "yes"
  1380. }).inject( node );
  1381. if( this.data.sortByClickTitle == "yes" )input.checked = true;
  1382. new Element("span" , { "text" : this.lp.sortByClickTitle } ).inject( node );
  1383. input.addEvents({
  1384. "click" : function(el){
  1385. if( this.checked ){
  1386. _self.data.sortByClickTitle = "yes";
  1387. _self.column.setSortIcon()
  1388. }else{
  1389. _self.data.sortByClickTitle = "no";
  1390. _self.column.cancelSortIcon()
  1391. }
  1392. }
  1393. })
  1394. },
  1395. getFieldSelectElement : function(){
  1396. var obj = new Element("select");
  1397. new Element("option", {
  1398. "value":"",
  1399. "text":""
  1400. }).inject(obj);
  1401. this.column.view.documentFields.concat(this.column.view.formFields).each(function( field ){
  1402. var opt = new Element("option", {
  1403. "value":field.name,
  1404. "text":field.name
  1405. }).inject(obj);
  1406. if( this.data.value == field.name ){
  1407. opt.selected = true;
  1408. }
  1409. }.bind(this));
  1410. return obj;
  1411. },
  1412. loadEventsEditor: function( eventsNode, eventsObj ){
  1413. MWF.xDesktop.requireApp("cms.FormDesigner", "widget.EventsEditor", function(){
  1414. var eventsEditor = new MWF.xApplication.cms.FormDesigner.widget.EventsEditor( eventsNode, this.designer, {
  1415. "helpStyle" : "cmsViewColumn",
  1416. "maxObj": this.column.view.node
  1417. });
  1418. eventsEditor.load( eventsObj );
  1419. }.bind(this));
  1420. },
  1421. loadAlign : function( container ){
  1422. var obj = new Element("select").inject(container);
  1423. var columnAlignValues = this.lp.columnAlignValue.split(",");
  1424. var columnAlignTexts = this.lp.columnAlignText.split(",");
  1425. columnAlignValues.each(function( v, i ){
  1426. var opt = new Element("option", {
  1427. "value":v,
  1428. "text":columnAlignTexts[i]
  1429. }).inject(obj);
  1430. if( this.data.align == v ){
  1431. opt.selected = true;
  1432. }
  1433. }.bind(this));
  1434. return obj;
  1435. },
  1436. loadOperation : function( container ){
  1437. var _self = this;
  1438. this.data.operation = this.data.operation || {};
  1439. var config = this.column.view.getOperationConfig();
  1440. if( config.default ){
  1441. for( var name in config.default ){
  1442. var op = config.default[name];
  1443. op.name = name;
  1444. op.text = _self.lp[op.title] ? _self.lp[op.title] : op.title;
  1445. var node = new Element("span", {"styles":this.css.propertyCheckBox } ).inject( container );
  1446. var input = new Element("input",{
  1447. "type" : "checkbox",
  1448. "value" : op.name
  1449. }).inject( node );
  1450. if( this.data.operation[name] )input.checked = true;
  1451. new Element("span" , { "text" : op.text} ).inject( node );
  1452. input.store("op", op );
  1453. input.addEvents({
  1454. "click" : function(el){
  1455. var op = this.retrieve("op");
  1456. if( this.checked ){
  1457. _self.data.operation[op.name] = op;
  1458. _self.column.setOperation( op.name,op.text,op.icon,op.iconOver, op.action )
  1459. }else{
  1460. if( _self.data.operation[op.name] ){
  1461. delete _self.data.operation[op.name];
  1462. }
  1463. _self.column.deleteOperation(op.name)
  1464. }
  1465. }
  1466. })
  1467. }
  1468. }
  1469. }
  1470. });
  1471. MWF.xApplication.cms.ViewDesigner.View.NewName = new Class({
  1472. Extends: MPopupForm,
  1473. Implements: [Options, Events],
  1474. options: {
  1475. "style": "blue",
  1476. "width": 700,
  1477. //"height": 300,
  1478. "height": "220",
  1479. "hasTop": true,
  1480. "hasIcon": false,
  1481. "draggable": true,
  1482. "title" : "新列表名称"
  1483. },
  1484. _createTableContent: function () {
  1485. var html = "<table width='80%' bordr='0' cellpadding='7' cellspacing='0' styles='formTable' style='margin: 20px auto 0px auto; '>" +
  1486. "<tr><td styles='formTableTitle' lable='name' width='25%'></td>" +
  1487. " <td styles='formTableValue' item='name' colspan='3'></td></tr>" +
  1488. "</table>";
  1489. this.formTableArea.set("html", html);
  1490. MWF.xDesktop.requireApp("Template", "MForm", function () {
  1491. this.form = new MForm(this.formTableArea, this.data || {}, {
  1492. isEdited: true,
  1493. style : "cms",
  1494. hasColon : true,
  1495. itemTemplate: {
  1496. name: { text : "名称", notEmpty : true }
  1497. }
  1498. }, this.app);
  1499. this.form.load();
  1500. }.bind(this), null, true)
  1501. },
  1502. ok: function(){
  1503. var data = this.form.getResult(true,null,true,false,true);
  1504. if( data ){
  1505. this.fireEvent("save", [data, function(){
  1506. this.close();
  1507. }.bind(this)])
  1508. }
  1509. }
  1510. });