View.js 60 KB

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