View.js 64 KB

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