View.js 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004
  1. MWF.xApplication = MWF.xApplication || {};
  2. MWF.xApplication.query = MWF.xApplication.query || {};
  3. MWF.xApplication.query.ViewDesigner = MWF.xApplication.query.ViewDesigner || {};
  4. MWF.APPDVD = MWF.xApplication.query.ViewDesigner;
  5. MWF.require("MWF.widget.Common", null, false);
  6. MWF.require("MWF.xScript.Macro", null, false);
  7. MWF.xDesktop.requireApp("query.ViewDesigner", "lp."+MWF.language, null, false);
  8. MWF.xDesktop.requireApp("query.ViewDesigner", "Property", null, false);
  9. MWF.xApplication.query.ViewDesigner.View = new Class({
  10. Extends: MWF.widget.Common,
  11. Implements: [Options, Events],
  12. options: {
  13. "style": "default",
  14. "isView": false,
  15. "showTab": true,
  16. "propertyPath": "/x_component_query_ViewDesigner/$View/view.html"
  17. },
  18. initialize: function(designer, data, options){
  19. this.setOptions(options);
  20. this.path = "/x_component_query_ViewDesigner/$View/";
  21. this.cssPath = "/x_component_query_ViewDesigner/$View/"+this.options.style+"/css.wcss";
  22. this._loadCss();
  23. this.designer = designer;
  24. this.data = data;
  25. if (!this.data.data) this.data.data = {};
  26. this.parseData();
  27. this.node = this.designer.designNode;
  28. //this.tab = this.designer.tab;
  29. this.areaNode = new Element("div", {"styles": {"height": "100%", "overflow": "auto"}});
  30. //MWF.require("MWF.widget.ScrollBar", function(){
  31. // new MWF.widget.ScrollBar(this.areaNode, {"distance": 100});
  32. //}.bind(this));
  33. this.propertyListNode = this.designer.propertyDomArea;
  34. //this.propertyNode = this.designer.propertyContentArea;
  35. if(this.designer.application) this.data.applicationName = this.designer.application.name;
  36. if(this.designer.application) this.data.application = this.designer.application.id;
  37. this.isNewView = (this.data.name) ? false : true;
  38. this.items = [];
  39. this.view = this;
  40. this.autoSave();
  41. this.designer.addEvent("queryClose", function(){
  42. if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  43. }.bind(this));
  44. },
  45. autoSave: function(){
  46. this.autoSaveTimerID = window.setInterval(function(){
  47. if (!this.autoSaveCheckNode) this.autoSaveCheckNode = this.designer.contentToolbarNode.getElement("#MWFDictionaryAutoSaveCheck");
  48. if (this.autoSaveCheckNode){
  49. if (this.autoSaveCheckNode.get("checked")){
  50. this.save();
  51. }
  52. }
  53. }.bind(this), 60000);
  54. },
  55. parseData: function(){
  56. this.json = this.data;
  57. if( !this.json.data.events ){
  58. var url = "/x_component_query_ViewDesigner/$View/view.json";
  59. MWF.getJSON(url, {
  60. "onSuccess": function(obj){
  61. this.json.data.events = obj.data.events;
  62. }.bind(this),
  63. "onerror": function(text){
  64. this.notice(text, "error");
  65. }.bind(this),
  66. "onRequestFailure": function(xhr){
  67. this.notice(xhr.responseText, "error");
  68. }.bind(this)
  69. },false);
  70. }
  71. },
  72. showProperty: function(){
  73. if (!this.property){
  74. this.property = new MWF.xApplication.query.ViewDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
  75. "path": this.options.propertyPath,
  76. "onPostLoad": function(){
  77. this.property.show();
  78. }.bind(this)
  79. });
  80. this.property.load();
  81. }else{
  82. this.property.show();
  83. }
  84. },
  85. hideProperty: function(){
  86. if (this.property) this.property.hide();
  87. },
  88. load : function(){
  89. this.setAreaNodeSize();
  90. this.designer.addEvent("resize", this.setAreaNodeSize.bind(this));
  91. this.areaNode.inject(this.node);
  92. this.designer.viewListAreaNode.getChildren().each(function(node){
  93. var view = node.retrieve("view");
  94. if (view.id==this.data.id){
  95. if (this.designer.currentListViewItem){
  96. this.designer.currentListViewItem.setStyles(this.designer.css.listViewItem);
  97. }
  98. node.setStyles(this.designer.css.listViewItem_current);
  99. this.designer.currentListViewItem = node;
  100. this.lisNode = node;
  101. }
  102. }.bind(this));
  103. this.domListNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.designer.propertyDomArea);
  104. this.loadTemplateStyle( function () {
  105. this.loadActionbar();
  106. this.loadView();
  107. this.loadPaging();
  108. this.selected();
  109. this.setEvent();
  110. //if (this.options.showTab) this.page.showTabIm();
  111. this.setViewWidth();
  112. this.designer.addEvent("resize", this.setViewWidth.bind(this));
  113. }.bind(this))
  114. },
  115. setEvent: function(){
  116. this.areaNode.addEvent("click", this.selected.bind(this));
  117. this.refreshNode.addEvent("click", function(e){
  118. this.loadViewData();
  119. e.stopPropagation();
  120. }.bind(this));
  121. this.addColumnNode.addEvent("click", function(e){
  122. this.addColumn();
  123. e.stopPropagation();
  124. }.bind(this));
  125. },
  126. loadViewData: function(){
  127. if (this.data.id){
  128. this.saveSilence(function(){
  129. this.viewContentBodyNode.empty();
  130. this.viewContentTableNode = new Element("table", {
  131. "styles": this.css.viewContentTableNode,
  132. "border": "0px",
  133. "cellPadding": "0",
  134. "cellSpacing": "0"
  135. }).inject(this.viewContentBodyNode);
  136. this.designer.actions.loadView(this.data.id, null,function(json){
  137. var entries = {};
  138. json.data.selectList.each(function(entry){entries[entry.column] = entry;}.bind(this));
  139. if (this.json.data.group.column){
  140. if (json.data.groupGrid.length){
  141. var groupColumn = null;
  142. for (var c = 0; c<json.data.selectList.length; c++){
  143. if (json.data.selectList[c].column === json.data.group.column){
  144. groupColumn = json.data.selectList[c];
  145. break;
  146. }
  147. }
  148. json.data.groupGrid.each(function(line, idx){
  149. var groupTr = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.viewContentTableNode);
  150. var colSpan = this.items.length ;
  151. var td = new Element("td", {"styles": this.css.viewContentGroupTdNode, "colSpan": colSpan}).inject(groupTr);
  152. var groupAreaNode = new Element("div", {"styles": this.css.viewContentTdGroupNode}).inject(td);
  153. var groupIconNode = new Element("div", {"styles": this.css.viewContentTdGroupIconNode}).inject(groupAreaNode);
  154. var groupTextNode = new Element("div", {"styles": this.css.viewContentTdGroupTextNode}).inject(groupAreaNode);
  155. if (groupColumn){
  156. //groupTextNode.set("text", (groupColumn.code) ? MWF.Macro.exec(groupColumn.code, {"value": line.group, "gridData": json.data.groupGrid, "data": json.data, "entry": line}) : line.group);
  157. groupTextNode.set("text", line.group);
  158. }else{
  159. groupTextNode.set("text", line.group);
  160. }
  161. var subtrs = [];
  162. line.list.each(function(entry){
  163. var tr = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.viewContentTableNode);
  164. tr.setStyle("display", "none");
  165. //this.createViewCheckboxTd( tr );
  166. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  167. Object.each(entries, function(c, k){
  168. var d = entry.data[k];
  169. if (d!=undefined){
  170. if (k!=this.json.data.group.column){
  171. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  172. //td.set("text", (entries[k].code) ? MWF.Macro.exec(entries[k].code, {"value": d, "gridData": json.data.groupGrid, "data": json.data, "entry": entry}) : d);
  173. if (c.isHtml){
  174. td.set("html", d);
  175. }else{
  176. td.set("text", d);
  177. }
  178. }
  179. }
  180. }.bind(this));
  181. // Object.each(entry.data, function(d, k){
  182. // if (k!=this.json.data.group.column){
  183. // var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  184. // td.set("text", (entries[k].code) ? MWF.Macro.exec(entries[k].code, {"value": d, "gridData": json.data.groupGrid, "data": json.data, "entry": entry}) : d);
  185. // }
  186. // }.bind(this));
  187. subtrs.push(tr)
  188. }.bind(this));
  189. groupAreaNode.store("subtrs", subtrs);
  190. var _self = this;
  191. groupAreaNode.addEvent("click", function(){
  192. var subtrs = this.retrieve("subtrs");
  193. var iconNode = groupAreaNode.getFirst("div");
  194. if (subtrs[0]){
  195. if (subtrs[0].getStyle("display")=="none"){
  196. subtrs.each(function(subtr){ subtr.setStyle("display", "table-row"); });
  197. iconNode.setStyle("background", "url("+"/x_component_process_ViewDesigner/$View/default/icon/down.png) center center no-repeat");
  198. }else{
  199. subtrs.each(function(subtr){ subtr.setStyle("display", "none"); });
  200. iconNode.setStyle("background", "url("+"/x_component_process_ViewDesigner/$View/default/icon/right.png) center center no-repeat");
  201. }
  202. }
  203. _self.setContentHeight();
  204. });
  205. }.bind(this));
  206. this.setContentColumnWidth();
  207. this.setContentHeight();
  208. }
  209. }else{
  210. if (json.data.grid.length){
  211. json.data.grid.each(function(line, idx){
  212. var tr = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.viewContentTableNode);
  213. //this.createViewCheckboxTd( tr );
  214. Object.each(entries, function(c, k){
  215. var d = line.data[k];
  216. if (d!=undefined){
  217. var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  218. //td.set("text", (entries[k].code) ? MWF.Macro.exec(entries[k].code, {"value": d, "gridData": json.data.grid, "data": json.data, "entry": line}) : d);
  219. if (c.isHtml){
  220. td.set("html", d);
  221. }else{
  222. td.set("text", d);
  223. }
  224. //td.set("text", d);
  225. }
  226. }.bind(this));
  227. // Object.each(line.data, function(d, k){
  228. // var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  229. // td.set("text", (entries[k].code) ? MWF.Macro.exec(entries[k].code, {"value": d, "gridData": json.data.grid, "data": json.data, "entry": line}) : d);
  230. // }.bind(this));
  231. }.bind(this));
  232. this.setContentColumnWidth();
  233. this.setContentHeight();
  234. }
  235. }
  236. }.bind(this));
  237. //this.getLookupAction(function(){
  238. // this.lookupAction.invoke({"name": "lookup","async": true, "parameter": {"id": this.data.id},"success": function(json){
  239. // if (json.data.length){
  240. // json.data.each(function(line, idx){
  241. // var tr = new Element("tr", {"styles": this.css.viewContentTrNode}).inject(this.viewContentTableNode);
  242. // line.each(function(cell, i){
  243. // var td = new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr);
  244. // td.set("text", cell);
  245. // }.bind(this));
  246. // }.bind(this));
  247. // this.setContentColumnWidth();
  248. // this.setContentHeight();
  249. // }
  250. // }.bind(this)});
  251. //}.bind(this));
  252. }.bind(this));
  253. }
  254. },
  255. setContentColumnWidth: function(){
  256. var titleTds = this.viewTitleTrNode.getElements("td");
  257. var widthList = [];
  258. titleTds.each(function(td){widthList.push(td.getSize().x);});
  259. var flag = false;
  260. if (this.viewContentTableNode){
  261. trs = this.viewContentTableNode.getElements("tr");
  262. for (var i=0; i<trs.length; i++){
  263. var tr = trs[i];
  264. var tds = tr.getElements("td");
  265. tds.each(function(contentTd, i){
  266. if (contentTd.get("colSpan")==1){
  267. contentTd.setStyle("width", ""+widthList[i]+"px");
  268. flag = true;
  269. }
  270. });
  271. if (flag) break;
  272. }
  273. //var tr = this.viewContentTableNode.getFirst("tr");
  274. //if (tr){
  275. // var tds = tr.getElements("td");
  276. // tds.each(function(contentTd, i){
  277. // if (!contentTd.get("colSpan")){
  278. // contentTd.setStyle("width", ""+widthList[i]+"px");
  279. // }
  280. // });
  281. //}
  282. }
  283. },
  284. //getLookupAction: function(callback){
  285. // if (!this.lookupAction){
  286. // MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  287. // this.lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_processplatform_assemble_surface_lookup", "");
  288. // this.lookupAction.getActions = function(actionCallback){
  289. //
  290. // this.actions = {"lookup": {"uri": "/jaxrs/view/{id}"}};
  291. // if (actionCallback) actionCallback();
  292. // }
  293. // if (callback) callback();
  294. // }.bind(this));
  295. // }else{
  296. // if (callback) callback();
  297. // }
  298. //},
  299. addColumn: function(){
  300. MWF.require("MWF.widget.UUID", function(){
  301. var id = (new MWF.widget.UUID).id;
  302. var json = {
  303. "id": id,
  304. "column": id,
  305. "displayName": this.designer.lp.unnamed,
  306. "orderType": "original"
  307. };
  308. if (!this.json.data.selectList) this.json.data.selectList = [];
  309. this.json.data.selectList.push(json);
  310. var column = new MWF.xApplication.query.ViewDesigner.View.Column(json, this);
  311. this.items.push(column);
  312. column.selected();
  313. if (this.viewContentTableNode){
  314. var trs = this.viewContentTableNode.getElements("tr");
  315. trs.each(function(tr){
  316. new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr)
  317. }.bind(this));
  318. //this.setContentColumnWidth();
  319. }
  320. this.setViewWidth();
  321. this.addColumnNode.scrollIntoView(true);
  322. }.bind(this));
  323. //new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 0}).toRight();
  324. },
  325. selected: function(){
  326. if (this.currentSelectedModule){
  327. if (this.currentSelectedModule==this){
  328. return true;
  329. }else{
  330. this.currentSelectedModule.unSelected();
  331. }
  332. }
  333. this.currentSelectedModule = this;
  334. this.showProperty();
  335. },
  336. unSelected: function(){
  337. this.currentSelectedModule = null;
  338. this.hideProperty();
  339. },
  340. loadViewNodes: function(){
  341. this.viewAreaNode = new Element("div#viewAreaNode", {"styles": this.css.viewAreaNode}).inject(this.areaNode);
  342. this.viewTitleNode = new Element("div#viewTitleNode", {"styles": this.css.viewTitleNode}).inject(this.viewAreaNode);
  343. this.refreshNode = new Element("div", {"styles": this.css.refreshNode}).inject(this.viewTitleNode);
  344. this.addColumnNode = new Element("div", {"styles": this.css.addColumnNode}).inject(this.viewTitleNode);
  345. this.viewTitleContentNode = new Element("div", {"styles": this.css.viewTitleContentNode}).inject(this.viewTitleNode);
  346. this.viewTitleTableNode = new Element("table", {
  347. "styles": this.css.viewTitleTableNode,
  348. "border": "0px",
  349. "cellPadding": "0",
  350. "cellSpacing": "0"
  351. }).inject(this.viewTitleContentNode);
  352. this.viewTitleTrNode = new Element("tr", {"styles": this.css.viewTitleTrNode}).inject(this.viewTitleTableNode);
  353. this.viewContentScrollNode = new Element("div", {"styles": this.css.viewContentScrollNode}).inject(this.viewAreaNode);
  354. this.viewContentNode = new Element("div", {"styles": this.css.viewContentNode}).inject(this.viewContentScrollNode);
  355. MWF.require("MWF.widget.ScrollBar", function(){
  356. new MWF.widget.ScrollBar(this.viewContentScrollNode, {"style": "view", "distance": 100, "indent": false});
  357. }.bind(this));
  358. this.contentLeftNode = new Element("div", {"styles": this.css.contentLeftNode}).inject(this.viewContentNode);
  359. this.contentRightNode = new Element("div", {"styles": this.css.contentRightNode}).inject(this.viewContentNode);
  360. this.viewContentBodyNode = new Element("div", {"styles": this.css.viewContentBodyNode}).inject(this.viewContentNode);
  361. this.viewContentTableNode = new Element("table", {
  362. "styles": this.css.viewContentTableNode,
  363. "border": "0px",
  364. "cellPadding": "0",
  365. "cellSpacing": "0"
  366. }).inject(this.viewContentBodyNode);
  367. },
  368. setContentHeight: function(){
  369. var size = this.areaNode.getSize();
  370. var titleSize = this.viewTitleNode.getSize();
  371. var actionbarSize = this.actionbarNode ? this.actionbarNode.getSize() : {x:0, y:0};
  372. var pagingSize = this.pagingNode ? this.pagingNode.getSize() : {x:0, y:0};
  373. var height = size.y-titleSize.y-actionbarSize.y-pagingSize.y-2;
  374. this.viewContentScrollNode.setStyle("height", height);
  375. var contentSize = this.viewContentBodyNode.getSize();
  376. if (height<contentSize.y) height = contentSize.y+10;
  377. this.viewContentNode.setStyle("height", height);
  378. this.contentLeftNode.setStyle("height", height);
  379. this.contentRightNode.setStyle("height", height);
  380. //this.viewContentBodyNode.setStyle("min-height", height);
  381. },
  382. loadViewColumns: function(){
  383. // for (var i=0; i<10; i++){
  384. if (this.json.data.selectList) {
  385. this.json.data.selectList.each(function (json) {
  386. this.items.push(new MWF.xApplication.query.ViewDesigner.View.Column(json, this));
  387. }.bind(this));
  388. }
  389. // }
  390. },
  391. loadViewSelectAllNode : function(){
  392. var _self = this;
  393. var td = new Element("td.viewTitleCheckboxTd",{ "styles": this.css.viewTitleColumnAreaNode }).inject( this.viewTitleTrNode );
  394. td.setStyles({
  395. "width":"30px", "text-align" : "center",
  396. "display" : this.json.data.selectAllEnable ? "table-cell" : "none"
  397. });
  398. new Element("input",{
  399. "type" : "checkbox",
  400. "events" : {
  401. "change" : function(){
  402. _self.viewContentTableNode.getElements(".viewContentCheckbox").set("checked", this.checked )
  403. }
  404. }
  405. }).inject(td);
  406. },
  407. createViewCheckboxTd : function( tr ){
  408. var td = new Element("td.viewContentCheckboxTd", {"styles": this.css.viewContentTdNode}).inject(tr, "top");
  409. td.setStyles({
  410. "width":"30px", "text-align" : "center",
  411. "display" : this.json.data.selectAllEnable ? "table-cell" : "none"
  412. });
  413. new Element("input.viewContentCheckbox",{
  414. "type" : "checkbox"
  415. }).inject(td);
  416. },
  417. loadView: function(){
  418. this.loadViewNodes();
  419. //this.loadViewSelectAllNode();
  420. this.loadViewColumns();
  421. // this.addTopItemNode.addEvent("click", this.addTopItem.bind(this));
  422. },
  423. loadActionbar: function(){
  424. this.actionbarNode = new Element("div#actionbarNode", {"styles": this.css.actionbarNode}).inject(this.areaNode);
  425. this.actionbarList = [];
  426. if( !this.json.data.actionbarHidden ){
  427. this.showActionbar( true );
  428. }
  429. },
  430. hideActionbar : function(){
  431. this.actionbarNode.hide();
  432. this.setContentHeight();
  433. },
  434. showActionbar : function( noSetHeight ){
  435. this.actionbarNode.show();
  436. if( !this.json.data.actionbarList )this.json.data.actionbarList = [];
  437. if( !this.actionbarList || this.actionbarList.length == 0 ){
  438. if( this.json.data.actionbarList.length ){
  439. this.json.data.actionbarList.each( function(json){
  440. this.actionbarList.push( new MWF.xApplication.query.ViewDesigner.View.Actionbar( json, this.json.data.actionbarList, this) )
  441. }.bind(this));
  442. }else{
  443. this.actionbarList.push( new MWF.xApplication.query.ViewDesigner.View.Actionbar( null, this.json.data.actionbarList, this) )
  444. }
  445. }
  446. if( !noSetHeight )this.setContentHeight();
  447. },
  448. loadPaging: function( noSetHeight ){
  449. this.pagingNode = new Element("div#pagingNode", {"styles": this.css.pagingNode}).inject(this.areaNode);
  450. this.pagingList = [];
  451. if( !this.json.data.pagingList )this.json.data.pagingList = [];
  452. if( !this.pagingList || this.pagingList.length == 0 ){
  453. if( this.json.data.pagingList.length ){
  454. this.json.data.pagingList.each( function(json){
  455. this.pagingList.push( new MWF.xApplication.query.ViewDesigner.View.Paging( json, this.json.data.pagingList, this) )
  456. }.bind(this));
  457. }else{
  458. this.pagingList.push( new MWF.xApplication.query.ViewDesigner.View.Paging( null, this.json.data.pagingList, this) )
  459. }
  460. }
  461. // if( !noSetHeight )this.setContentHeight();
  462. },
  463. setViewWidth: function(){
  464. if( !this.viewAreaNode )return;
  465. this.viewAreaNode.setStyle("width", "auto");
  466. this.viewTitleNode.setStyle("width", "auto");
  467. var s1 = this.viewTitleTableNode.getSize();
  468. var s2 = this.refreshNode.getSize();
  469. var s3 = this.addColumnNode.getSize();
  470. var width = s1.x+s2.x+s2.x;
  471. var size = this.areaNode.getSize();
  472. if (width>size.x){
  473. this.viewTitleNode.setStyle("width", ""+width+"px");
  474. this.viewAreaNode.setStyle("width", ""+width+"px");
  475. }else{
  476. this.viewTitleNode.setStyle("width", ""+size.x+"px");
  477. this.viewAreaNode.setStyle("width", ""+size.x+"px");
  478. }
  479. this.setContentColumnWidth();
  480. this.setContentHeight();
  481. },
  482. //setPropertyContent: function(){
  483. // this.designer.propertyIdNode.set("text", this.data.id);
  484. // this.designer.propertyNameNode.set("value", this.data.name);
  485. // this.designer.propertyAliasNode.set("value", this.data.alias);
  486. // this.designer.propertyDescriptionNode.set("value", this.data.description);
  487. //
  488. // this.designer.jsonDomNode.empty();
  489. // MWF.require("MWF.widget.JsonParse", function(){
  490. // this.jsonParse = new MWF.widget.JsonParse(this.data.data, this.designer.jsonDomNode, this.designer.jsonTextAreaNode);
  491. // window.setTimeout(function(){
  492. // this.jsonParse.load();
  493. // }.bind(this), 1);
  494. // }.bind(this));
  495. //},
  496. setAreaNodeSize: function(){
  497. //var size = this.node.getSize();
  498. ////var tabSize = this.tab.tabNodeContainer.getSize();
  499. //var tabSize = this.node.getSize();
  500. //var y = size.y - tabSize.y;
  501. //this.areaNode.setStyle("height", ""+y+"px");
  502. //if (this.editor) if (this.editor.editor) this.editor.editor.resize();
  503. },
  504. // createRootItem: function() {
  505. // this.items.push(new MWF.xApplication.process.DictionaryDesigner.Dictionary.item("ROOT", this.data.data, null, 0, this, true));
  506. // },
  507. preview: function(){
  508. if( this.isNewView ){
  509. this.designer.notice( this.designer.lp.saveViewNotice, "error" );
  510. return;
  511. }
  512. this.saveSilence( function () {
  513. var url = "/x_desktop/app.html?app=query.Query&status=";
  514. url += JSON.stringify({
  515. id : this.data.application,
  516. viewId : this.data.id
  517. });
  518. window.open(url,"_blank");
  519. }.bind(this));
  520. },
  521. saveSilence: function(callback){
  522. if (!this.data.name){
  523. this.designer.notice(this.designer.lp.notice.inputName, "error");
  524. return false;
  525. }
  526. this.designer.actions.saveView(this.data, function(json){
  527. this.data.id = json.data.id;
  528. this.isNewView = false;
  529. //this.page.textNode.set("text", this.data.name);
  530. if (this.lisNode) {
  531. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  532. }
  533. if (callback) callback();
  534. }.bind(this));
  535. },
  536. save: function(callback){
  537. //if (this.designer.tab.showPage==this.page){
  538. if (!this.data.name){
  539. this.designer.notice(this.designer.lp.notice.inputName, "error");
  540. return false;
  541. }
  542. //}
  543. this.designer.actions.saveView(this.data, function(json){
  544. this.designer.notice(this.designer.lp.notice.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  545. this.isNewView = false;
  546. this.data.id = json.data.id;
  547. //this.page.textNode.set("text", this.data.name);
  548. if (this.lisNode) {
  549. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  550. }
  551. if (callback) callback();
  552. }.bind(this));
  553. },
  554. explode: function(){},
  555. implode: function(){},
  556. _setEditStyle: function(name, input, oldValue){
  557. if (name=="type"){
  558. this.items.each(function(item){
  559. if (item.property){
  560. var processDiv = item.property.propertyContent.getElements("#"+item.json.id+"dataPathSelectedProcessArea");
  561. var cmsDiv = item.property.propertyContent.getElements("#"+item.json.id+"dataPathSelectedCMSArea");
  562. if (this.json[name]=="cms"){
  563. cmsDiv.setStyle("display", "block");
  564. processDiv.setStyle("display", "none");
  565. }else{
  566. cmsDiv.setStyle("display", "none");
  567. processDiv.setStyle("display", "block");
  568. }
  569. }
  570. }.bind(this));
  571. }
  572. if( name=="data.actionbarHidden" ){
  573. if( this.json.data.actionbarHidden ){
  574. this.hideActionbar()
  575. }else{
  576. this.showActionbar()
  577. }
  578. }
  579. if( name=="data.selectAllEnable" ){
  580. if( this.json.data.selectAllEnable ){
  581. this.viewTitleTrNode.getElement(".viewTitleCheckboxTd").setStyle("display","table-cell");
  582. this.viewContentTableNode.getElements(".viewContentCheckboxTd").setStyle("display","table-cell");
  583. }else{
  584. this.viewTitleTrNode.getElement(".viewTitleCheckboxTd").setStyle("display","none");
  585. this.viewContentTableNode.getElements(".viewContentCheckboxTd").setStyle("display","none");
  586. }
  587. }
  588. if (name=="data.viewStyleType"){
  589. debugger;
  590. var file = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType].file : null;
  591. var extendFile = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType].extendFile : null;
  592. this.loadTemplateStyles( file, extendFile, function( templateStyles ){
  593. this.templateStyles = templateStyles;
  594. var oldFile, oldExtendFile;
  595. if( oldValue && this.stylesList[oldValue] ){
  596. oldFile = this.stylesList[oldValue].file;
  597. oldExtendFile = this.stylesList[oldValue].extendFile;
  598. }
  599. this.loadTemplateStyles( oldFile, oldExtendFile, function( oldTemplateStyles ){
  600. this.json.data.styleConfig = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType] : null;
  601. if (oldTemplateStyles["table"]) this.clearTemplateStyles(oldTemplateStyles["table"]);
  602. if (this.templateStyles["table"]) this.setTemplateStyles(this.templateStyles["table"]);
  603. this.setAllStyles();
  604. this.actionbarList.each( function (module) {
  605. if (oldTemplateStyles["actionbar"]){
  606. module.clearTemplateStyles(oldTemplateStyles["actionbar"]);
  607. }
  608. module.setStyleTemplate();
  609. module.setAllStyles();
  610. })
  611. this.pagingList.each( function (module) {
  612. if (oldTemplateStyles["paging"]){
  613. module.clearTemplateStyles(oldTemplateStyles["paging"]);
  614. }
  615. module.setStyleTemplate();
  616. module.setAllStyles();
  617. });
  618. // this.moduleList.each(function(module){
  619. // if (oldTemplateStyles[module.moduleName]){
  620. // module.clearTemplateStyles(oldTemplateStyles[module.moduleName]);
  621. // }
  622. // module.setStyleTemplate();
  623. // module.setAllStyles();
  624. // }.bind(this));
  625. }.bind(this))
  626. }.bind(this))
  627. }
  628. },
  629. setAllStyles: function(){
  630. this.setPropertiesOrStyles("styles");
  631. this.setPropertiesOrStyles("properties");
  632. this.reloadMaplist();
  633. },
  634. reloadMaplist: function(){
  635. if (this.property) Object.each(this.property.maplists, function(map, name){ map.reload(this.json[name]);}.bind(this));
  636. },
  637. setPropertiesOrStyles: function(name){
  638. if (name=="styles"){
  639. this.setCustomStyles();
  640. }
  641. if (name=="properties"){
  642. this.node.setProperties(this.json.properties);
  643. }
  644. },
  645. setCustomStyles: function(){
  646. // var border = this.node.getStyle("border");
  647. // this.node.clearStyles();
  648. // this.node.setStyles((this.options.mode==="Mobile") ? this.css.formMobileNode : this.css.formNode);
  649. // var y = this.container.getStyle("height");
  650. // y = (y) ? y.toInt()-2 : this.container.getSize().y-2;
  651. // this.node.setStyle("min-height", ""+y+"px");
  652. //
  653. // if (this.initialStyles) this.node.setStyles(this.initialStyles);
  654. // this.node.setStyle("border", border);
  655. //
  656. // Object.each(this.json.styles, function(value, key){
  657. // var reg = /^border\w*/ig;
  658. // if (!key.test(reg)){
  659. // this.node.setStyle(key, value);
  660. // }
  661. // }.bind(this));
  662. },
  663. saveAs: function(){
  664. var form = new MWF.xApplication.query.ViewDesigner.View.NewNameForm(this, {
  665. name : this.data.name + "_" + MWF.xApplication.query.ViewDesigner.LP.copy,
  666. query : this.data.query || this.data.application,
  667. queryName : this.data.queryName || this.data.applicationName
  668. }, {
  669. onSave : function( data, callback ){
  670. this._saveAs( data, callback );
  671. }.bind(this)
  672. }, {
  673. app: this.designer
  674. });
  675. form.edit()
  676. },
  677. cloneObject : function( obj ){
  678. if (null == obj || "object" != typeof obj) return obj;
  679. if ( typeof obj.length==='number'){ //数组
  680. //print( "array" );
  681. var copy = [];
  682. for (var i = 0, len = obj.length; i < len; ++i) {
  683. copy[i] = this.cloneObject(obj[i]);
  684. }
  685. return copy;
  686. }else{
  687. var copy = {};
  688. for (var attr in obj) {
  689. copy[attr] = this.cloneObject(obj[attr]);
  690. }
  691. return copy;
  692. }
  693. },
  694. _saveAs : function( data , callback){
  695. var _self = this;
  696. var d = this.cloneObject( this.data );
  697. d.isNewView = true;
  698. d.id = this.designer.actions.getUUID();
  699. d.name = data.name;
  700. d.alias = "";
  701. d.query = data.query;
  702. d.queryName = data.queryName;
  703. d.application = data.query;
  704. d.applicationName = data.queryName;
  705. d.pid = d.id + d.id;
  706. delete d[this.data.id+"viewFilterType"];
  707. d[d.id+"viewFilterType"]="custom";
  708. d.data.selectList.each( function( entry ){
  709. entry.id = (new MWF.widget.UUID).id;
  710. }.bind(this));
  711. this.designer.actions.saveView(d, function(json){
  712. this.designer.notice(this.designer.lp.notice.saveAs_success, "success", this.node, {"x": "left", "y": "bottom"});
  713. if (callback) callback();
  714. }.bind(this));
  715. },
  716. loadTemplateStyle : function( callback ){
  717. this.loadStylesList(function(){
  718. var oldStyleValue = "";
  719. if ((!this.json.data.viewStyleType) || !this.stylesList[this.json.data.viewStyleType]) this.json.data.viewStyleType="default";
  720. // if (this.options.mode=="Mobile"){
  721. // if (this.json.viewStyleType != "defaultMobile"){
  722. // var styles = this.stylesList[this.json.viewStyleType];
  723. // if( !styles || typeOf(styles.mode)!=="array" || !styles.mode.contains( "mobile" ) ){
  724. // oldStyleValue = this.json.viewStyleType;
  725. // this.json.viewStyleType = "defaultMobile";
  726. // }
  727. // }
  728. // }
  729. this.loadTemplateStyles( this.stylesList[this.json.data.viewStyleType].file, this.stylesList[this.json.data.viewStyleType].extendFile,
  730. function( templateStyles ){
  731. this.templateStyles = templateStyles;
  732. // this.loadDomModules();
  733. if (this.json.data.viewStyleType && this.templateStyles && this.templateStyles["table"]){
  734. this.setTemplateStyles(this.templateStyles["table"]);
  735. }
  736. this.setCustomStyles();
  737. this.node.setProperties(this.json.data.properties);
  738. if(callback)callback();
  739. // this.setNodeEvents();
  740. // if (this.options.mode=="Mobile"){
  741. // if (oldStyleValue) this._setEditStyle("viewStyleType", null, oldStyleValue);
  742. // }
  743. }.bind(this)
  744. );
  745. }.bind(this));
  746. },
  747. removeStyles: function(from, to){
  748. if (this.json.data[to]){
  749. Object.each(from, function(style, key){
  750. if (this.json.data[to][key] && this.json.data[to][key]==style){
  751. delete this.json.data[to][key];
  752. }
  753. }.bind(this));
  754. }
  755. },
  756. copyStyles: function(from, to){
  757. if (!this.json.data[to]) this.json.data[to] = {};
  758. Object.each(from, function(style, key){
  759. if (!this.json.data[to][key]) this.json.data[to][key] = style;
  760. }.bind(this));
  761. },
  762. clearTemplateStyles: function(styles){
  763. if (styles){
  764. if (styles.styles) this.removeStyles(styles.styles, "styles");
  765. if (styles.properties) this.removeStyles(styles.properties, "properties");
  766. }
  767. },
  768. setTemplateStyles: function(styles){
  769. if (styles.styles) this.copyStyles(styles.styles, "styles");
  770. if (styles.properties) this.copyStyles(styles.properties, "properties");
  771. },
  772. loadTemplateStyles : function( file, extendFile, callback ){
  773. if( !file ){
  774. if (callback) callback({});
  775. return;
  776. }
  777. this.templateStylesList = this.templateStylesList || {};
  778. if( this.templateStylesList[file] ){
  779. if (callback) callback(this.templateStylesList[file]);
  780. return;
  781. }
  782. this.loadTemplateStyleFile( file, function( json_file ){
  783. this.loadTemplateExtendStyleFile( extendFile, function( json_extend ){
  784. this.templateStylesList[file] = Object.merge( json_file, json_extend );
  785. if (callback) callback(this.templateStylesList[file]);
  786. }.bind(this))
  787. }.bind(this))
  788. },
  789. loadTemplateStyleFile : function(file, callback ){
  790. if( !file ){
  791. if (callback) callback({});
  792. return;
  793. }
  794. var stylesUrl = "/x_component_query_ViewDesigner/$View/skin/"+file;
  795. MWF.getJSON(stylesUrl,{
  796. "onSuccess": function(responseJSON){
  797. //this.templateStylesList[file] = responseJSON;
  798. if (callback) callback(responseJSON);
  799. }.bind(this),
  800. "onRequestFailure": function(){
  801. if (callback) callback({});
  802. }.bind(this),
  803. "onError": function(){
  804. if (callback) callback({});
  805. }.bind(this)
  806. }
  807. );
  808. },
  809. loadTemplateExtendStyleFile : function(extendFile, callback ){
  810. if( !extendFile ){
  811. if (callback) callback({});
  812. return;
  813. }
  814. var stylesUrl = "/x_component_query_ViewDesigner/$View/skin/"+extendFile;
  815. MWF.getJSON(stylesUrl,{
  816. "onSuccess": function(responseJSON){
  817. //this.templateStylesList[file] = responseJSON;
  818. if (callback) callback(responseJSON);
  819. }.bind(this),
  820. "onRequestFailure": function(){
  821. if (callback) callback({});
  822. }.bind(this),
  823. "onError": function(){
  824. if (callback) callback({});
  825. }.bind(this)
  826. }
  827. );
  828. },
  829. loadStylesList: function(callback){
  830. var configUrl = "/x_component_query_ViewDesigner/$View/skin/config.json";
  831. MWF.getJSON(configUrl,{
  832. "onSuccess": function(responseJSON){
  833. this.stylesList = responseJSON;
  834. if (callback) callback(this.stylesList);
  835. }.bind(this),
  836. "onRequestFailure": function(){
  837. this.stylesList = {};
  838. if (callback) callback(this.stylesList);
  839. }.bind(this),
  840. "onError": function(){
  841. this.stylesList = {};
  842. if (callback) callback(this.stylesList);
  843. }.bind(this)
  844. }
  845. );
  846. }
  847. });
  848. MWF.xApplication.query.ViewDesigner.View.Column = new Class({
  849. initialize: function(json, view, next){
  850. this.propertyPath = "/x_component_query_ViewDesigner/$View/column.html";
  851. this.view = view;
  852. this.json = json;
  853. this.next = next;
  854. this.css = this.view.css;
  855. this.content = this.view.viewTitleTrNode;
  856. this.domListNode = this.view.domListNode;
  857. this.load();
  858. },
  859. load: function(){
  860. this.areaNode = new Element("td", {"styles": this.css.viewTitleColumnAreaNode});
  861. this.areaNode.store("column", this);
  862. if (this.next){
  863. this.areaNode.inject(this.next.areaNode, "before");
  864. }else{
  865. this.areaNode.inject(this.content);
  866. }
  867. this.node = new Element("div", {
  868. "styles": this.css.viewTitleColumnNode
  869. }).inject(this.areaNode);
  870. this.textNode = new Element("div", {
  871. "styles": this.css.viewTitleColumnTextNode,
  872. "text": this.json.displayName
  873. }).inject(this.node);
  874. this.createDomListItem();
  875. this._createIconAction();
  876. //if (!this.json.export) this.hideMode();
  877. this.setEvent();
  878. },
  879. createDomListItem: function(){
  880. this.listNode = new Element("div", {"styles": this.css.cloumnListNode});
  881. if (this.next){
  882. this.listNode.inject(this.next.listNode, "before");
  883. }else{
  884. this.listNode.inject(this.domListNode);
  885. }
  886. var listIconNode = new Element("div", {"styles": this.css.cloumnListIconNode}).inject(this.listNode);
  887. var listTextNode = new Element("div", {"styles": this.css.cloumnListTextNode}).inject(this.listNode);
  888. this.resetTextNode();
  889. },
  890. setEvent: function(){
  891. this.node.addEvents({
  892. "click": function(e){this.selected(); e.stopPropagation();}.bind(this),
  893. "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css.viewTitleColumnNode_over)}.bind(this),
  894. "mouseout": function(){if (!this.isSelected) if (this.isError){
  895. this.node.setStyles(this.css.viewTitleColumnNode_error)
  896. }else{
  897. this.node.setStyles(this.css.viewTitleColumnNode)
  898. }}.bind(this)
  899. });
  900. this.listNode.addEvents({
  901. "click": function(e){this.selected(); e.stopPropagation();}.bind(this),
  902. "mouseover": function(){debugger; if (!this.isSelected) this.listNode.setStyles(this.css.cloumnListNode_over)}.bind(this),
  903. "mouseout": function(){if (!this.isSelected) this.listNode.setStyles(this.css.cloumnListNode)}.bind(this)
  904. });
  905. },
  906. _createIconAction: function(){
  907. if (!this.actionArea){
  908. this.actionArea = new Element("div", {"styles": this.css.actionAreaNode}).inject(this.view.areaNode, "after");
  909. this._createAction({
  910. "name": "move",
  911. "icon": "move1.png",
  912. "event": "mousedown",
  913. "action": "move",
  914. "title": MWF.APPDVD.LP.action.move
  915. });
  916. this._createAction({
  917. "name": "add",
  918. "icon": "add.png",
  919. "event": "click",
  920. "action": "addColumn",
  921. "title": MWF.APPDVD.LP.action.add
  922. });
  923. this._createAction({
  924. "name": "delete",
  925. "icon": "delete1.png",
  926. "event": "click",
  927. "action": "delete",
  928. "title": MWF.APPDVD.LP.action["delete"]
  929. });
  930. }
  931. },
  932. _createAction: function(action){
  933. var actionNode = new Element("div", {
  934. "styles": this.css.actionNodeStyles,
  935. "title": action.title
  936. }).inject(this.actionArea);
  937. actionNode.setStyle("background", "url("+this.view.path+this.view.options.style+"/action/"+action.icon+") no-repeat left center");
  938. actionNode.addEvent(action.event, function(e){
  939. this[action.action](e);
  940. }.bind(this));
  941. actionNode.addEvents({
  942. "mouseover": function(e){
  943. e.target.setStyle("border", "1px solid #999");
  944. }.bind(this),
  945. "mouseout": function(e){
  946. e.target.setStyle("border", "1px solid #F1F1F1");
  947. }.bind(this)
  948. });
  949. },
  950. _setActionAreaPosition: function(){
  951. var p = this.node.getPosition(this.view.areaNode.getOffsetParent());
  952. var y = p.y-25;
  953. var x = p.x;
  954. this.actionArea.setPosition({"x": x, "y": y});
  955. },
  956. _showActions: function(){
  957. if (this.actionArea){
  958. this._setActionAreaPosition();
  959. this.actionArea.setStyle("display", "block");
  960. }
  961. },
  962. _hideActions: function(){
  963. if (this.actionArea) this.actionArea.setStyle("display", "none");
  964. },
  965. selected: function(){
  966. if (this.view.currentSelectedModule){
  967. if (this.view.currentSelectedModule==this){
  968. return true;
  969. }else{
  970. this.view.currentSelectedModule.unSelected();
  971. }
  972. }
  973. this.node.setStyles(this.css.viewTitleColumnNode_selected);
  974. this.listNode.setStyles(this.css.cloumnListNode_selected);
  975. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  976. new Fx.Scroll(this.view.designer.propertyDomArea, {"wheelStops": false, "duration": 100}).toElement(this.listNode);
  977. this.view.currentSelectedModule = this;
  978. this.isSelected = true;
  979. this._showActions();
  980. this.showProperty();
  981. },
  982. unSelected: function(){
  983. this.view.currentSelectedModule = null;
  984. //this.node.setStyles(this.css.viewTitleColumnNode);
  985. if (this.isError){
  986. this.node.setStyles(this.css.viewTitleColumnNode_error)
  987. }else{
  988. this.node.setStyles(this.css.viewTitleColumnNode)
  989. }
  990. this.listNode.setStyles(this.css.cloumnListNode);
  991. this.isSelected = false;
  992. this._hideActions();
  993. this.hideProperty();
  994. },
  995. showProperty: function(){
  996. if (!this.property){
  997. this.property = new MWF.xApplication.query.ViewDesigner.Property(this, this.view.designer.propertyContentArea, this.view.designer, {
  998. "path": this.propertyPath,
  999. "onPostLoad": function(){
  1000. this.property.show();
  1001. var processDiv = this.property.propertyContent.getElements("#"+this.json.id+"dataPathSelectedProcessArea");
  1002. var cmsDiv = this.property.propertyContent.getElements("#"+this.json.id+"dataPathSelectedCMSArea");
  1003. if (this.view.json.type=="cms"){
  1004. processDiv.setStyle("display", "none");
  1005. cmsDiv.setStyle("display", "block");
  1006. }else{
  1007. processDiv.setStyle("display", "block");
  1008. cmsDiv.setStyle("display", "none");
  1009. }
  1010. }.bind(this)
  1011. });
  1012. this.property.load();
  1013. }else{
  1014. this.property.show();
  1015. }
  1016. },
  1017. hideProperty: function(){
  1018. if (this.property) this.property.hide();
  1019. },
  1020. _setEditStyle: function(name, input, oldValue){
  1021. if (name=="displayName") this.resetTextNode();
  1022. if (name=="selectType") this.resetTextNode();
  1023. if (name=="attribute") this.resetTextNode();
  1024. if (name=="path") this.resetTextNode();
  1025. if (name=="column"){
  1026. this.view.json.data.orderList.each(function(order){
  1027. if (order.column==oldValue) order.column = this.json.column
  1028. }.bind(this));
  1029. if (this.view.json.data.group.column == oldValue) this.view.json.data.group.column = this.json.column;
  1030. }
  1031. },
  1032. resetTextNode: function(){
  1033. var listText = (this.json.selectType=="attribute") ? (this.json.attribute || "") : (this.json.path || "");
  1034. if (!listText) listText = "unnamed";
  1035. this.textNode.set("text", this.json.displayName);
  1036. this.listNode.getLast().set("text", this.json.displayName+"("+listText+")");
  1037. },
  1038. "delete": function(e){
  1039. var _self = this;
  1040. if (!e) e = this.node;
  1041. this.view.designer.confirm("warn", e, MWF.APPDVD.LP.notice.deleteColumnTitle, MWF.APPDVD.LP.notice.deleteColumn, 300, 120, function(){
  1042. _self.destroy();
  1043. this.close();
  1044. }, function(){
  1045. this.close();
  1046. }, null);
  1047. },
  1048. destroy: function(){
  1049. if (this.view.currentSelectedModule==this) this.view.currentSelectedModule = null;
  1050. if (this.actionArea) this.actionArea.destroy();
  1051. if (this.listNode) this.listNode.destroy();
  1052. if (this.property) this.property.propertyContent.destroy();
  1053. var idx = this.view.items.indexOf(this);
  1054. if (this.view.viewContentTableNode){
  1055. var trs = this.view.viewContentTableNode.getElements("tr");
  1056. trs.each(function(tr){
  1057. tr.deleteCell(idx);
  1058. }.bind(this));
  1059. }
  1060. if (this.view.json.data.selectList) this.view.json.data.selectList.erase(this.json);
  1061. if (this.view.json.data.calculate) if (this.view.json.data.calculate.calculateList) this.view.json.data.calculate.calculateList.erase(this.json);
  1062. this.view.items.erase(this);
  1063. if (this.view.property) this.view.property.loadStatColumnSelect();
  1064. this.areaNode.destroy();
  1065. this.view.selected();
  1066. this.view.setViewWidth();
  1067. MWF.release(this);
  1068. delete this;
  1069. },
  1070. addColumn: function(e, data){
  1071. MWF.require("MWF.widget.UUID", function(){
  1072. var json;
  1073. if (data){
  1074. json = Object.clone(data);
  1075. json.id = (new MWF.widget.UUID).id;
  1076. json.column = (new MWF.widget.UUID).id;
  1077. }else{
  1078. var id = (new MWF.widget.UUID).id;
  1079. json = {
  1080. "id": id,
  1081. "column": id,
  1082. "displayName": this.view.designer.lp.unnamed,
  1083. "orderType": "original"
  1084. };
  1085. }
  1086. var idx = this.view.json.data.selectList.indexOf(this.json);
  1087. this.view.json.data.selectList.splice(idx, 0, json);
  1088. var column = new MWF.xApplication.query.ViewDesigner.View.Column(json, this.view, this);
  1089. this.view.items.splice(idx, 0, column);
  1090. column.selected();
  1091. if (this.view.viewContentTableNode){
  1092. var trs = this.view.viewContentTableNode.getElements("tr");
  1093. trs.each(function(tr){
  1094. var td = tr.insertCell(idx);
  1095. td.setStyles(this.css.viewContentTdNode);
  1096. }.bind(this));
  1097. }
  1098. this.view.setViewWidth();
  1099. }.bind(this));
  1100. },
  1101. move: function(e){
  1102. var columnNodes = [];
  1103. this.view.items.each(function(item){
  1104. if (item!=this){
  1105. columnNodes.push(item.areaNode);
  1106. }
  1107. }.bind(this));
  1108. this._createMoveNode();
  1109. this._setNodeMove(columnNodes, e);
  1110. },
  1111. _createMoveNode: function(){
  1112. this.moveNode = new Element("div", {"text": this.node.get("text")});
  1113. this.moveNode.inject(this.view.designer.content);
  1114. this.moveNode.setStyles({
  1115. "border": "2px dashed #ffa200",
  1116. "opacity": 0.7,
  1117. "height": "30px",
  1118. "line-height": "30px",
  1119. "padding": "0px 10px",
  1120. "position": "absolute"
  1121. });
  1122. },
  1123. _setMoveNodePosition: function(e){
  1124. var x = e.page.x+2;
  1125. var y = e.page.y+2;
  1126. this.moveNode.positionTo(x, y);
  1127. },
  1128. createMoveFlagNode: function(){
  1129. this.moveFlagNode = new Element("td", {"styles": this.css.moveFlagNode});
  1130. },
  1131. _setNodeMove: function(droppables, e){
  1132. this._setMoveNodePosition(e);
  1133. var movePosition = this.moveNode.getPosition();
  1134. var moveSize = this.moveNode.getSize();
  1135. var contentPosition = this.content.getPosition();
  1136. var contentSize = this.content.getSize();
  1137. var nodeDrag = new Drag.Move(this.moveNode, {
  1138. "droppables": droppables,
  1139. "limit": {
  1140. "x": [contentPosition.x, contentPosition.x+contentSize.x],
  1141. "y": [movePosition.y, movePosition.y+moveSize.y]
  1142. },
  1143. "onEnter": function(dragging, inObj){
  1144. if (!this.moveFlagNode) this.createMoveFlagNode();
  1145. this.moveFlagNode.inject(inObj, "before");
  1146. }.bind(this),
  1147. "onLeave": function(dragging, inObj){
  1148. if (this.moveFlagNode){
  1149. this.moveFlagNode.dispose();
  1150. }
  1151. }.bind(this),
  1152. "onDrop": function(dragging, inObj){
  1153. if (inObj){
  1154. this.areaNode.inject(inObj, "before");
  1155. var column = inObj.retrieve("column");
  1156. this.listNode.inject(column.listNode, "before");
  1157. var idx = this.view.json.data.selectList.indexOf(column.json);
  1158. this.view.json.data.selectList.erase(this.json);
  1159. this.view.items.erase(this);
  1160. this.view.json.data.selectList.splice(idx, 0, this.json);
  1161. this.view.items.splice(idx, 0, this);
  1162. if (this.moveNode) this.moveNode.destroy();
  1163. if (this.moveFlagNode) this.moveFlagNode.destroy();
  1164. this._setActionAreaPosition();
  1165. }else{
  1166. if (this.moveNode) this.moveNode.destroy();
  1167. if (this.moveFlagNode) this.moveFlagNode.destroy();
  1168. }
  1169. }.bind(this),
  1170. "onCancel": function(dragging){
  1171. if (this.moveNode) this.moveNode.destroy();
  1172. if (this.moveFlagNode) this.moveFlagNode.destroy();
  1173. }.bind(this)
  1174. });
  1175. nodeDrag.start(e);
  1176. }
  1177. //hideMode: function(){
  1178. // if (!this.columnHideFlagNode){
  1179. // this.columnHideFlagNode = new Element("div", {"styles": this.view.css.columnHideFlagNode}).inject(this.node);
  1180. // }
  1181. //},
  1182. //showMode: function(){
  1183. // if (this.columnHideFlagNode) this.columnHideFlagNode.destroy();
  1184. // this.columnHideFlagNode = null;
  1185. //}
  1186. });
  1187. MWF.xApplication.query.ViewDesigner.View.$Module = MWF.QV$Module = new Class({
  1188. Extends: MWF.widget.Common,
  1189. Implements: [Options, Events],
  1190. copyStyles: function(from, to){
  1191. if (!this.json[to]) this.json[to] = {};
  1192. Object.each(from, function(style, key){
  1193. //if (!this.json[to][key])
  1194. this.json[to][key] = style;
  1195. }.bind(this));
  1196. },
  1197. removeStyles: function(from, to){
  1198. if (this.json[to]){
  1199. Object.each(from, function(style, key){
  1200. if (this.json[to][key] && this.json[to][key]==style){
  1201. delete this.json[to][key];
  1202. }
  1203. //if (this.json[from][key]){
  1204. // delete this.json[to][key];
  1205. //}
  1206. }.bind(this));
  1207. }
  1208. },
  1209. setTemplateStyles: function(styles){
  1210. if (styles.styles) this.copyStyles(styles.styles, "styles");
  1211. if (styles.properties) this.copyStyles(styles.properties, "properties");
  1212. },
  1213. clearTemplateStyles: function(styles){
  1214. if (styles){
  1215. if (styles.styles) this.removeStyles(styles.styles, "styles");
  1216. if (styles.properties) this.removeStyles(styles.properties, "properties");
  1217. }
  1218. },
  1219. setStyleTemplate: function(){
  1220. if( this.view.templateStyles && this.view.templateStyles[this.moduleName] ){
  1221. this.setTemplateStyles(this.view.templateStyles[this.moduleName]);
  1222. }
  1223. },
  1224. setAllStyles: function(){
  1225. this.setPropertiesOrStyles("styles");
  1226. this.setPropertiesOrStyles("inputStyles");
  1227. this.setPropertiesOrStyles("properties");
  1228. this.reloadMaplist();
  1229. },
  1230. showProperty: function(){
  1231. if (!this.property){
  1232. this.property = new MWF.xApplication.query.ViewDesigner.Property(this, this.view.designer.propertyContentArea, this.view.designer, {
  1233. "path": this.propertyPath,
  1234. "onPostLoad": function(){
  1235. this.property.show();
  1236. }.bind(this)
  1237. });
  1238. this.property.load();
  1239. }else{
  1240. this.property.show();
  1241. }
  1242. },
  1243. hideProperty: function(){
  1244. if (this.property) this.property.hide();
  1245. },
  1246. deletePropertiesOrStyles: function(name, key){
  1247. if (name=="properties"){
  1248. try{
  1249. this.node.removeProperty(key);
  1250. }catch(e){}
  1251. }
  1252. },
  1253. setPropertiesOrStyles: function(name){
  1254. if (name=="styles"){
  1255. try{
  1256. this.setCustomStyles();
  1257. }catch(e){}
  1258. }
  1259. if (name=="properties"){
  1260. try{
  1261. this.node.setProperties(this.json.properties);
  1262. }catch(e){}
  1263. }
  1264. },
  1265. setCustomNodeStyles: function(node, styles){
  1266. var border = node.getStyle("border");
  1267. node.clearStyles();
  1268. //node.setStyles(styles);
  1269. node.setStyle("border", border);
  1270. Object.each(styles, function(value, key){
  1271. var reg = /^border\w*/ig;
  1272. if (!key.test(reg)){
  1273. node.setStyle(key, value);
  1274. }
  1275. }.bind(this));
  1276. },
  1277. setCustomStyles: function(){
  1278. var border = this.node.getStyle("border");
  1279. this.node.clearStyles();
  1280. this.node.setStyles(this.css.moduleNode);
  1281. if (this.initialStyles) this.node.setStyles(this.initialStyles);
  1282. this.node.setStyle("border", border);
  1283. if (this.json.styles) Object.each(this.json.styles, function(value, key){
  1284. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1)){
  1285. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  1286. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  1287. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  1288. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  1289. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  1290. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  1291. }
  1292. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  1293. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  1294. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  1295. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  1296. }
  1297. }
  1298. var reg = /^border\w*/ig;
  1299. if (!key.test(reg)){
  1300. if (key){
  1301. if (key.toString().toLowerCase()==="display"){
  1302. if (value.toString().toLowerCase()==="none"){
  1303. this.node.setStyle("opacity", 0.3);
  1304. }else{
  1305. this.node.setStyle("opacity", 1);
  1306. this.node.setStyle(key, value);
  1307. }
  1308. }else{
  1309. this.node.setStyle(key, value);
  1310. }
  1311. }
  1312. }
  1313. //this.node.setStyle(key, value);
  1314. }.bind(this));
  1315. },
  1316. _setEditStyle: function(name, obj, oldValue){
  1317. var title = "";
  1318. var text = "";
  1319. if (name==="name"){
  1320. title = this.json.name || this.json.id;
  1321. text = this.json.type.substr(this.json.type.lastIndexOf("$")+1, this.json.type.length);
  1322. this.treeNode.setText("<"+text+"> "+title);
  1323. }
  1324. if (name==="id"){
  1325. title = this.json.name || this.json.id;
  1326. if (!this.json.name){
  1327. text = this.json.type.substr(this.json.type.lastIndexOf("$")+1, this.json.type.length);
  1328. this.treeNode.setText("<"+text+"> "+this.json.id);
  1329. }
  1330. this.treeNode.setTitle(this.json.id);
  1331. this.node.set("id", this.json.id);
  1332. }
  1333. this._setEditStyle_custom(name, obj, oldValue);
  1334. },
  1335. reloadMaplist: function(){
  1336. if (this.property) Object.each(this.property.maplists, function(map, name){ map.reload(this.json[name]);}.bind(this));
  1337. },
  1338. getHtml: function(){
  1339. var copy = this.node.clone(true, true);
  1340. copy.clearStyles(true);
  1341. var html = copy.outerHTML;
  1342. copy.destroy();
  1343. return html;
  1344. },
  1345. getJson: function(){
  1346. var json = Object.clone(this.json);
  1347. var o = {};
  1348. o[json.id] = json;
  1349. return o;
  1350. }
  1351. })
  1352. MWF.require("MWF.widget.Toolbar", null, false);
  1353. MWF.xApplication.query.ViewDesigner.View.Actionbar = new Class({
  1354. Extends: MWF.xApplication.query.ViewDesigner.View.$Module,
  1355. options : {
  1356. "style" : "default",
  1357. "customImageStyle" : "default"
  1358. },
  1359. initialize: function(json, jsonList, view, options){
  1360. this.setOptions( options );
  1361. this.propertyPath = "/x_component_query_ViewDesigner/$View/actionbar.html";
  1362. this.path = "/x_component_query_ViewDesigner/$View/";
  1363. this.imagePath_default = "/x_component_query_ViewDesigner/$View/";
  1364. this.imagePath_custom = "/x_component_process_FormDesigner/Module/Actionbar/";
  1365. this.cssPath = "/x_component_query_ViewDesigner/$View/"+this.options.style+"/actionbar.wcss";
  1366. this.view = view;
  1367. this.json = json;
  1368. this.jsonList = jsonList;
  1369. this.css = this.view.css;
  1370. this.container = this.view.actionbarNode;
  1371. this.moduleName = "actionbar";
  1372. this.load();
  1373. },
  1374. load: function(){
  1375. this.systemTools = [];
  1376. this.customTools = [];
  1377. if( !this.json ){
  1378. this.loadDefaultJson(function(){
  1379. this._load()
  1380. }.bind(this));
  1381. }else{
  1382. this._load()
  1383. }
  1384. },
  1385. _load : function(){
  1386. this.json.moduleName = this.moduleName;
  1387. this._createNode();
  1388. //this._createIconAction();
  1389. //if (!this.json.export) this.hideMode();
  1390. this.setEvent();
  1391. },
  1392. loadDefaultJson: function(callback){
  1393. var url = this.path+"actionbar.json";
  1394. MWF.getJSON(url, {
  1395. "onSuccess": function(obj){
  1396. this.view.designer.actions.getUUID(function(id){
  1397. obj.id=id;
  1398. //obj.isNewView = true;
  1399. //obj.application = this.view.designer.application.id;
  1400. this.json = obj;
  1401. this.jsonList.push( this.json );
  1402. if (callback) callback(obj);
  1403. }.bind(this));
  1404. }.bind(this),
  1405. "onerror": function(text){
  1406. this.view.designer.notice(text, "error");
  1407. }.bind(this),
  1408. "onRequestFailure": function(xhr){
  1409. this.view.designer.notice(xhr.responseText, "error");
  1410. }.bind(this)
  1411. });
  1412. },
  1413. setTemplateStyles: function(styles){
  1414. this.json.style = styles.style;
  1415. this.json.iconOverStyle = styles.iconOverStyle || "";
  1416. this.json.customIconStyle = styles.customIconStyle;
  1417. this.json.customIconOverStyle = styles.customIconOverStyle || "";
  1418. this.json.forceStyles = styles.forceStyles || "";
  1419. },
  1420. clearTemplateStyles: function(styles){
  1421. this.json.style = "form";
  1422. this.json.iconOverStyle = "";
  1423. this.json.customIconStyle = "";
  1424. this.json.customIconOverStyle = "";
  1425. this.json.forceStyles = "";
  1426. },
  1427. setAllStyles: function(){
  1428. this._resetActionbar();
  1429. },
  1430. setEvent: function(){
  1431. this.node.addEvents({
  1432. "click": function(e){this.selected(); e.stopPropagation();}.bind(this),
  1433. "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css.toolbarWarpNode_over)}.bind(this),
  1434. "mouseout": function(){if (!this.isSelected) this.node.setStyles(this.css.toolbarWarpNode) }.bind(this)
  1435. });
  1436. },
  1437. selected: function(){
  1438. if (this.view.currentSelectedModule){
  1439. if (this.view.currentSelectedModule==this){
  1440. return true;
  1441. }else{
  1442. this.view.currentSelectedModule.unSelected();
  1443. }
  1444. }
  1445. this.node.setStyles(this.css.toolbarWarpNode_selected);
  1446. //this.listNode.setStyles(this.css.cloumnListNode_selected);
  1447. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  1448. //new Fx.Scroll(this.view.designer.propertyDomArea, {"wheelStops": false, "duration": 100}).toElement(this.listNode);
  1449. this.view.currentSelectedModule = this;
  1450. this.isSelected = true;
  1451. //this._showActions();
  1452. this.showProperty();
  1453. },
  1454. unSelected: function(){
  1455. this.view.currentSelectedModule = null;
  1456. this.node.setStyles(this.css.toolbarWarpNode)
  1457. //this.listNode.setStyles(this.css.cloumnListNode);
  1458. this.isSelected = false;
  1459. //this._hideActions();
  1460. this.hideProperty();
  1461. },
  1462. resetTextNode: function(){
  1463. var listText = (this.json.selectType=="attribute") ? (this.json.attribute || "") : (this.json.path || "");
  1464. if (!listText) listText = "unnamed";
  1465. this.textNode.set("text", this.json.displayName);
  1466. this.listNode.getLast().set("text", this.json.displayName+"("+listText+")");
  1467. },
  1468. _createNode: function(callback){
  1469. this.node = new Element("div", {
  1470. "id": this.json.id,
  1471. "MWFType": "actionbar",
  1472. "styles": this.css.toolbarWarpNode,
  1473. "events": {
  1474. "selectstart": function(e){
  1475. e.preventDefault();
  1476. }
  1477. }
  1478. }).inject(this.container );
  1479. this.toolbarNode = new Element("div").inject(this.node);
  1480. this.toolbarWidget = new MWF.widget.Toolbar(this.toolbarNode, {"style": this.json.style}, this);
  1481. if (!this.json.actionStyles){
  1482. this.json.actionStyles = Object.clone(this.toolbarWidget.css);
  1483. }
  1484. //MWF.getJSON(this.path+"toolbars.json", function(json){
  1485. // this.json.defaultTools = json;
  1486. // this.setToolbars(json, this.toolbarNode);
  1487. // debugger;
  1488. // this.toolbarWidget.load();
  1489. //}.bind(this), false);
  1490. if (this.json.defaultTools){
  1491. var json = Array.clone(this.json.defaultTools);
  1492. //if (this.json.tools) json.append(this.json.tools);
  1493. this.setToolbars(json, this.toolbarNode);
  1494. if (this.json.tools){
  1495. this.setCustomToolbars(Array.clone(this.json.tools), this.toolbarNode);
  1496. }
  1497. this.toolbarWidget.load();
  1498. this._setEditStyle_custom("hideSystemTools");
  1499. //json = null;
  1500. }else{
  1501. MWF.getJSON(this.path+"toolbars.json", function(json){
  1502. this.json.defaultTools = json;
  1503. var json = Array.clone(this.json.defaultTools);
  1504. //if (this.json.tools) json.append(this.json.tools);
  1505. this.setToolbars(json, this.toolbarNode);
  1506. if (this.json.tools){
  1507. this.setCustomToolbars(Array.clone(this.json.tools), this.toolbarNode);
  1508. }
  1509. this.toolbarWidget.load();
  1510. this._setEditStyle_custom("hideSystemTools");
  1511. //json = null;
  1512. }.bind(this), false);
  1513. }
  1514. },
  1515. _refreshActionbar: function(){
  1516. //if (this.form.options.mode == "Mobile"){
  1517. // this.node.set("text", MWF.APPFD.LP.notice.notUseModuleInMobile+"("+this.moduleName+")");
  1518. // this.node.setStyles({"height": "24px", "line-height": "24px", "background-color": "#999"});
  1519. //}else{
  1520. this.toolbarNode = this.node.getFirst("div");
  1521. this.toolbarNode.empty();
  1522. this.toolbarWidget = new MWF.widget.Toolbar(this.toolbarNode, {"style": this.json.style}, this);
  1523. if (!this.json.actionStyles) this.json.actionStyles = Object.clone(this.toolbarWidget.css);
  1524. this.toolbarWidget.css = this.json.actionStyles;
  1525. if (this.json.defaultTools){
  1526. var json = Array.clone(this.json.defaultTools);
  1527. //if (this.json.tools) json.append(this.json.tools);
  1528. this.setToolbars(json, this.toolbarNode);
  1529. if (this.json.tools){
  1530. this.setCustomToolbars(Array.clone(this.json.tools), this.toolbarNode);
  1531. }
  1532. this.toolbarWidget.load();
  1533. //json = null;
  1534. }else{
  1535. MWF.getJSON(this.path+"toolbars.json", function(json){
  1536. this.json.defaultTools = json;
  1537. var json = Array.clone(this.json.defaultTools);
  1538. //if (this.json.tools) json.append(this.json.tools);
  1539. this.setToolbars(json, this.toolbarNode);
  1540. if (this.json.tools){
  1541. this.setCustomToolbars(Array.clone(this.json.tools), this.toolbarNode);
  1542. }
  1543. this.toolbarWidget.load();
  1544. //json = null;
  1545. }.bind(this), false);
  1546. }
  1547. //}
  1548. },
  1549. _resetActionbar: function(){
  1550. //if (this.form.options.mode == "Mobile"){
  1551. // this.node.set("text", MWF.APPFD.LP.notice.notUseModuleInMobile+"("+this.moduleName+")");
  1552. // this.node.setStyles({"height": "24px", "line-height": "24px", "background-color": "#999"});
  1553. //}else{
  1554. this.toolbarNode = this.node.getFirst("div");
  1555. this.toolbarNode.empty();
  1556. this.toolbarWidget = new MWF.widget.Toolbar(this.toolbarNode, {"style": this.json.style}, this);
  1557. if (!this.json.actionStyles){
  1558. this.json.actionStyles = Object.merge( Object.clone( this.toolbarWidget.css ), this.json.forceStyles || {} );
  1559. }else{
  1560. this.toolbarWidget.css = Object.merge( Object.clone( this.json.actionStyles ), this.toolbarWidget.css, this.json.forceStyles || {} );
  1561. this.json.actionStyles = Object.clone(this.toolbarWidget.css);
  1562. }
  1563. if (this.json.defaultTools){
  1564. var json = Array.clone(this.json.defaultTools);
  1565. //if (this.json.tools) json.append(this.json.tools);
  1566. this.setToolbars(json, this.toolbarNode);
  1567. if (this.json.tools){
  1568. this.setCustomToolbars(Array.clone(this.json.tools), this.toolbarNode);
  1569. }
  1570. this.toolbarWidget.load();
  1571. //json = null;
  1572. }else{
  1573. MWF.getJSON(this.path+"toolbars.json", function(json){
  1574. this.json.defaultTools = json;
  1575. var json = Array.clone(this.json.defaultTools);
  1576. //if (this.json.tools) json.append(this.json.tools);
  1577. this.setToolbars(json, this.toolbarNode);
  1578. if (this.json.tools){
  1579. this.setCustomToolbars(Array.clone(this.json.tools), this.toolbarNode);
  1580. }
  1581. this.toolbarWidget.load();
  1582. //json = null;
  1583. }.bind(this), false);
  1584. }
  1585. //}
  1586. },
  1587. setToolbars: function(tools, node){
  1588. tools.each(function(tool){
  1589. var actionNode = new Element("div", {
  1590. "MWFnodetype": tool.type,
  1591. "MWFButtonImage": this.imagePath_default+""+this.options.style+"/actionbar/"+tool.img,
  1592. "title": tool.title,
  1593. "MWFButtonAction": tool.action,
  1594. "MWFButtonText": tool.text
  1595. }).inject(node);
  1596. if( this.json.iconOverStyle ){
  1597. actionNode.set("MWFButtonImageOver" , this.imagePath_default+""+this.options.style+"/actionbar/"+this.json.iconOverStyle+"/"+tool.img );
  1598. }
  1599. this.systemTools.push(actionNode);
  1600. if (tool.sub){
  1601. var subNode = node.getLast();
  1602. this.setToolbars(tool.sub, subNode);
  1603. }
  1604. }.bind(this));
  1605. },
  1606. setCustomToolbars: function(tools, node){
  1607. //var style = (this.json.style || "default").indexOf("red") > -1 ? "red" : "blue";
  1608. var path = "";
  1609. if( this.json.customIconStyle ){
  1610. path = this.json.customIconStyle+ "/";
  1611. }
  1612. tools.each(function(tool){
  1613. var actionNode = new Element("div", {
  1614. "MWFnodetype": tool.type,
  1615. "MWFButtonImage": this.imagePath_custom+""+this.options.customImageStyle +"/custom/"+path+tool.img,
  1616. "title": tool.title,
  1617. "MWFButtonAction": tool.action,
  1618. "MWFButtonText": tool.text
  1619. }).inject(node);
  1620. if( this.json.customIconOverStyle ){
  1621. actionNode.set("MWFButtonImageOver" , this.imagePath_custom+""+this.options.customImageStyle +"/custom/"+this.json.customIconOverStyle+ "/" +tool.img );
  1622. }
  1623. this.customTools.push(actionNode);
  1624. if (tool.sub){
  1625. var subNode = node.getLast();
  1626. this.setToolbars(tool.sub, subNode);
  1627. }
  1628. }.bind(this));
  1629. },
  1630. _setEditStyle_custom: function(name){
  1631. if (name=="hideSystemTools"){
  1632. if (this.json.hideSystemTools){
  1633. this.systemTools.each(function(tool){
  1634. tool.setStyle("display", "none");
  1635. });
  1636. }else{
  1637. this.systemTools.each(function(tool){
  1638. tool.setStyle("display", "block");
  1639. });
  1640. }
  1641. }
  1642. if (name=="defaultTools" || name=="tools" || name==="actionStyles"){
  1643. this._refreshActionbar();
  1644. }
  1645. }
  1646. });
  1647. MWF.require("MWF.widget.Paging", null, false);
  1648. MWF.xApplication.query.ViewDesigner.View.Paging = new Class({
  1649. Extends: MWF.xApplication.query.ViewDesigner.View.$Module,
  1650. options : {
  1651. "style" : "default"
  1652. },
  1653. initialize: function(json, jsonList, view, options){
  1654. this.setOptions( options );
  1655. this.propertyPath = "/x_component_query_ViewDesigner/$View/paging.html";
  1656. this.view = view;
  1657. this.json = json;
  1658. this.jsonList = jsonList;
  1659. this.css = this.view.css;
  1660. this.container = this.view.pagingNode;
  1661. this.moduleName = "paging";
  1662. this.load();
  1663. },
  1664. load: function(){
  1665. this.systemTools = [];
  1666. this.customTools = [];
  1667. if( !this.json ){
  1668. this.loadDefaultJson(function(){
  1669. this._load();
  1670. }.bind(this));
  1671. }else{
  1672. this._load();
  1673. }
  1674. },
  1675. _load : function(){
  1676. this.json.moduleName = this.moduleName;
  1677. this._createNode();
  1678. this.setEvent();
  1679. },
  1680. loadDefaultJson: function(callback){
  1681. var url = this.view.path+"paging.json";
  1682. MWF.getJSON(url, {
  1683. "onSuccess": function(obj){
  1684. this.view.designer.actions.getUUID(function(id){
  1685. obj.id=id;
  1686. this.json = obj;
  1687. this.jsonList.push( this.json );
  1688. if (callback) callback(obj);
  1689. }.bind(this));
  1690. }.bind(this),
  1691. "onerror": function(text){
  1692. this.view.designer.notice(text, "error");
  1693. }.bind(this),
  1694. "onRequestFailure": function(xhr){
  1695. this.view.designer.notice(xhr.responseText, "error");
  1696. }.bind(this)
  1697. });
  1698. },
  1699. setTemplateStyles: function(styles){
  1700. this.json.style = styles.style;
  1701. this.json.forceStyles = styles.forceStyles || "";
  1702. },
  1703. clearTemplateStyles: function(styles){
  1704. this.json.style = "default";
  1705. this.json.forceStyles = "";
  1706. },
  1707. setAllStyles: function(){
  1708. this._resetPaging();
  1709. },
  1710. setEvent: function(){
  1711. this.node.addEvents({
  1712. "click": function(e){this.selected(); e.stopPropagation();}.bind(this),
  1713. "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css.pagingWarpNode_over)}.bind(this),
  1714. "mouseout": function(){if (!this.isSelected) this.node.setStyles(this.css.pagingWarpNode) }.bind(this)
  1715. });
  1716. },
  1717. selected: function(){
  1718. if (this.view.currentSelectedModule){
  1719. if (this.view.currentSelectedModule==this){
  1720. return true;
  1721. }else{
  1722. this.view.currentSelectedModule.unSelected();
  1723. }
  1724. }
  1725. this.node.setStyles(this.css.pagingWarpNode_selected);
  1726. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  1727. this.view.currentSelectedModule = this;
  1728. this.isSelected = true;
  1729. this.showProperty();
  1730. },
  1731. unSelected: function(){
  1732. this.view.currentSelectedModule = null;
  1733. this.node.setStyles(this.css.pagingWarpNode);
  1734. this.isSelected = false;
  1735. this.hideProperty();
  1736. },
  1737. resetTextNode: function(){
  1738. var listText = (this.json.selectType=="attribute") ? (this.json.attribute || "") : (this.json.path || "");
  1739. if (!listText) listText = "unnamed";
  1740. this.textNode.set("text", this.json.displayName);
  1741. this.listNode.getLast().set("text", this.json.displayName+"("+listText+")");
  1742. },
  1743. _createNode: function(callback){
  1744. this.node = new Element("div", {
  1745. "id": this.json.id,
  1746. "MWFType": "paging",
  1747. "styles": this.css.pagingWarpNode,
  1748. "events": {
  1749. "selectstart": function(e){
  1750. e.preventDefault();
  1751. }
  1752. }
  1753. }).inject(this.container );
  1754. this.pagingNode = new Element("div").inject(this.node);
  1755. this.loadWidget();
  1756. // this.pagingWidget = new MWF.widget.Paging(this.pagingNode, {"style": this.json.style}, this);
  1757. // if (!this.json.pagingStyles){
  1758. // this.json.pagingStyles = Object.clone(this.pagingWidget.css);
  1759. // }
  1760. // this.pagingWidget.load();
  1761. },
  1762. loadWidget : function( isReset ){
  1763. var visiblePages = this.json.visiblePages ? this.json.visiblePages.toInt() : 9;
  1764. this.pagingWidget = new o2.widget.Paging(this.pagingNode, {
  1765. style : this.json.style || "default",
  1766. countPerPage: 20, //this.json.pageSize || this.options.perPageCount,
  1767. visiblePages: visiblePages,
  1768. currentPage: 1,
  1769. itemSize: visiblePages * 20 * 3,
  1770. // pageSize: this.pages,
  1771. hasNextPage: typeOf( this.json.hasPreNextPage ) === "boolean" ? this.json.hasPreNextPage : true,
  1772. hasPrevPage: typeOf( this.json.hasPreNextPage ) === "boolean" ? this.json.hasPreNextPage : true,
  1773. hasTruningBar: typeOf( this.json.hasTruningBar ) === "boolean" ? this.json.hasTruningBar : true,
  1774. hasBatchTuring: typeOf( this.json.hasBatchTuring ) === "boolean" ? this.json.hasBatchTuring : true,
  1775. hasFirstPage: typeOf( this.json.hasFirstLastPage ) === "boolean" ? this.json.hasFirstLastPage : true,
  1776. hasLastPage: typeOf( this.json.hasFirstLastPage ) === "boolean" ? this.json.hasFirstLastPage : true,
  1777. hasJumper: typeOf( this.json.hasPageJumper ) === "boolean" ? this.json.hasPageJumper : true,
  1778. hiddenWithDisable: false,
  1779. // hiddenWithNoItem: true,
  1780. text: {
  1781. prePage: this.json.prePageText,
  1782. nextPage: this.json.nextPageText,
  1783. firstPage: this.json.firstPageText,
  1784. lastPage: this.json.lastPageText
  1785. },
  1786. onJumpingPage : function( pageNum, itemNum ){
  1787. }.bind(this),
  1788. onPostLoad : function () {
  1789. this.view.setContentHeight()
  1790. // if(this.setContentHeightFun)this.setContentHeightFun();
  1791. }.bind(this)
  1792. }, isReset ? {} : (this.json.pagingStyles || {}));
  1793. if( isReset ){
  1794. if (!this.json.pagingStyles){
  1795. this.json.pagingStyles = Object.merge( Object.clone( this.pagingWidget.css ), this.json.forceStyles || {} );
  1796. }else{
  1797. this.pagingWidget.css = Object.merge( Object.clone( this.json.pagingStyles ), this.pagingWidget.css, this.json.forceStyles || {} );
  1798. this.json.pagingStyles = Object.clone(this.pagingWidget.css);
  1799. }
  1800. }else{
  1801. if (!this.json.pagingStyles){
  1802. this.json.pagingStyles = Object.clone(this.pagingWidget.css);
  1803. }
  1804. }
  1805. this.pagingWidget.load();
  1806. },
  1807. _resetPaging : function(){
  1808. this.pagingNode.empty();
  1809. this.loadWidget( true );
  1810. },
  1811. _refreshPaging: function(){
  1812. this.pagingNode.empty();
  1813. this.loadWidget();
  1814. },
  1815. _setEditStyle_custom: function(name, obj, oldValue){
  1816. debugger;
  1817. if ( ["hasTruningBar","visiblePages","hasBatchTuring",
  1818. "hasFirstLastPage","hasPreNextPage","hasPageJumper",
  1819. "firstPageText","lastPageText","prePageText","nextPageText",
  1820. "pagingStyles"].contains(name)){
  1821. this._refreshPaging();
  1822. }
  1823. }
  1824. });