View.js 64 KB

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