View.js 60 KB

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