View.js 88 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163
  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.id) ? 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. this.viewAreaNode.setStyle("width", "auto");
  465. this.viewTitleNode.setStyle("width", "auto");
  466. var s1 = this.viewTitleTableNode.getSize();
  467. var s2 = this.refreshNode.getSize();
  468. var s3 = this.addColumnNode.getSize();
  469. var width = s1.x+s2.x+s2.x;
  470. var size = this.areaNode.getSize();
  471. if (width>size.x){
  472. this.viewTitleNode.setStyle("width", ""+width+"px");
  473. this.viewAreaNode.setStyle("width", ""+width+"px");
  474. }else{
  475. this.viewTitleNode.setStyle("width", ""+size.x+"px");
  476. this.viewAreaNode.setStyle("width", ""+size.x+"px");
  477. }
  478. this.setContentColumnWidth();
  479. this.setContentHeight();
  480. },
  481. //setPropertyContent: function(){
  482. // this.designer.propertyIdNode.set("text", this.data.id);
  483. // this.designer.propertyNameNode.set("value", this.data.name);
  484. // this.designer.propertyAliasNode.set("value", this.data.alias);
  485. // this.designer.propertyDescriptionNode.set("value", this.data.description);
  486. //
  487. // this.designer.jsonDomNode.empty();
  488. // MWF.require("MWF.widget.JsonParse", function(){
  489. // this.jsonParse = new MWF.widget.JsonParse(this.data.data, this.designer.jsonDomNode, this.designer.jsonTextAreaNode);
  490. // window.setTimeout(function(){
  491. // this.jsonParse.load();
  492. // }.bind(this), 1);
  493. // }.bind(this));
  494. //},
  495. setAreaNodeSize: function(){
  496. //var size = this.node.getSize();
  497. ////var tabSize = this.tab.tabNodeContainer.getSize();
  498. //var tabSize = this.node.getSize();
  499. //var y = size.y - tabSize.y;
  500. //this.areaNode.setStyle("height", ""+y+"px");
  501. //if (this.editor) if (this.editor.editor) this.editor.editor.resize();
  502. },
  503. // createRootItem: function() {
  504. // this.items.push(new MWF.xApplication.process.DictionaryDesigner.Dictionary.item("ROOT", this.data.data, null, 0, this, true));
  505. // },
  506. saveSilence: function(callback){
  507. if (!this.data.name){
  508. this.designer.notice(this.designer.lp.notice.inputName, "error");
  509. return false;
  510. }
  511. this.designer.actions.saveView(this.data, function(json){
  512. this.data.id = json.data.id;
  513. //this.page.textNode.set("text", this.data.name);
  514. if (this.lisNode) {
  515. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  516. }
  517. if (callback) callback();
  518. }.bind(this));
  519. },
  520. save: function(callback){
  521. //if (this.designer.tab.showPage==this.page){
  522. if (!this.data.name){
  523. this.designer.notice(this.designer.lp.notice.inputName, "error");
  524. return false;
  525. }
  526. //}
  527. this.designer.actions.saveView(this.data, function(json){
  528. this.designer.notice(this.designer.lp.notice.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  529. this.data.id = json.data.id;
  530. //this.page.textNode.set("text", this.data.name);
  531. if (this.lisNode) {
  532. this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  533. }
  534. if (callback) callback();
  535. }.bind(this));
  536. },
  537. explode: function(){},
  538. implode: function(){},
  539. _setEditStyle: function(name, input, oldValue){
  540. if (name=="type"){
  541. this.items.each(function(item){
  542. if (item.property){
  543. var processDiv = item.property.propertyContent.getElements("#"+item.json.id+"dataPathSelectedProcessArea");
  544. var cmsDiv = item.property.propertyContent.getElements("#"+item.json.id+"dataPathSelectedCMSArea");
  545. if (this.json[name]=="cms"){
  546. cmsDiv.setStyle("display", "block");
  547. processDiv.setStyle("display", "none");
  548. }else{
  549. cmsDiv.setStyle("display", "none");
  550. processDiv.setStyle("display", "block");
  551. }
  552. }
  553. }.bind(this));
  554. }
  555. if( name=="data.actionbarHidden" ){
  556. if( this.json.data.actionbarHidden ){
  557. this.hideActionbar()
  558. }else{
  559. this.showActionbar()
  560. }
  561. }
  562. if( name=="data.selectAllEnable" ){
  563. if( this.json.data.selectAllEnable ){
  564. this.viewTitleTrNode.getElement(".viewTitleCheckboxTd").setStyle("display","table-cell");
  565. this.viewContentTableNode.getElements(".viewContentCheckboxTd").setStyle("display","table-cell");
  566. }else{
  567. this.viewTitleTrNode.getElement(".viewTitleCheckboxTd").setStyle("display","none");
  568. this.viewContentTableNode.getElements(".viewContentCheckboxTd").setStyle("display","none");
  569. }
  570. }
  571. if (name=="data.viewStyleType"){
  572. var file = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType].file : null;
  573. var extendFile = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType].extendFile : null;
  574. this.loadTemplateStyles( file, extendFile, function( templateStyles ){
  575. this.templateStyles = templateStyles;
  576. var oldFile, oldExtendFile;
  577. if( oldValue && this.stylesList[oldValue] ){
  578. oldFile = this.stylesList[oldValue].file;
  579. oldExtendFile = this.stylesList[oldValue].extendFile;
  580. }
  581. this.loadTemplateStyles( oldFile, oldExtendFile, function( oldTemplateStyles ){
  582. this.json.data.styleConfig = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType] : null;
  583. if (oldTemplateStyles["form"]) this.clearTemplateStyles(oldTemplateStyles["form"]);
  584. if (this.templateStyles["form"]) this.setTemplateStyles(this.templateStyles["form"]);
  585. // this.setAllStyles();
  586. // this.moduleList.each(function(module){
  587. // if (oldTemplateStyles[module.moduleName]){
  588. // module.clearTemplateStyles(oldTemplateStyles[module.moduleName]);
  589. // }
  590. // module.setStyleTemplate();
  591. // module.setAllStyles();
  592. // }.bind(this));
  593. }.bind(this))
  594. }.bind(this))
  595. }
  596. },
  597. saveAs: function(){
  598. var form = new MWF.xApplication.query.ViewDesigner.View.NewNameForm(this, {
  599. name : this.data.name + "_" + MWF.xApplication.query.ViewDesigner.LP.copy,
  600. query : this.data.query || this.data.application,
  601. queryName : this.data.queryName || this.data.applicationName
  602. }, {
  603. onSave : function( data, callback ){
  604. this._saveAs( data, callback );
  605. }.bind(this)
  606. }, {
  607. app: this.designer
  608. });
  609. form.edit()
  610. },
  611. cloneObject : function( obj ){
  612. if (null == obj || "object" != typeof obj) return obj;
  613. if ( typeof obj.length==='number'){ //数组
  614. //print( "array" );
  615. var copy = [];
  616. for (var i = 0, len = obj.length; i < len; ++i) {
  617. copy[i] = this.cloneObject(obj[i]);
  618. }
  619. return copy;
  620. }else{
  621. var copy = {};
  622. for (var attr in obj) {
  623. copy[attr] = this.cloneObject(obj[attr]);
  624. }
  625. return copy;
  626. }
  627. },
  628. _saveAs : function( data , callback){
  629. var _self = this;
  630. var d = this.cloneObject( this.data );
  631. d.isNewView = true;
  632. d.id = this.designer.actions.getUUID();
  633. d.name = data.name;
  634. d.alias = "";
  635. d.query = data.query;
  636. d.queryName = data.queryName;
  637. d.application = data.query;
  638. d.applicationName = data.queryName;
  639. d.pid = d.id + d.id;
  640. delete d[this.data.id+"viewFilterType"];
  641. d[d.id+"viewFilterType"]="custom";
  642. d.data.selectList.each( function( entry ){
  643. entry.id = (new MWF.widget.UUID).id;
  644. }.bind(this));
  645. this.designer.actions.saveView(d, function(json){
  646. this.designer.notice(this.designer.lp.notice.saveAs_success, "success", this.node, {"x": "left", "y": "bottom"});
  647. if (callback) callback();
  648. }.bind(this));
  649. },
  650. loadTemplateStyle : function( callback ){
  651. this.loadStylesList(function(){
  652. var oldStyleValue = "";
  653. if ((!this.json.data.viewStyleType) || !this.stylesList[this.json.data.viewStyleType]) this.json.data.viewStyleType="default";
  654. // if (this.options.mode=="Mobile"){
  655. // if (this.json.viewStyleType != "defaultMobile"){
  656. // var styles = this.stylesList[this.json.viewStyleType];
  657. // if( !styles || typeOf(styles.mode)!=="array" || !styles.mode.contains( "mobile" ) ){
  658. // oldStyleValue = this.json.viewStyleType;
  659. // this.json.viewStyleType = "defaultMobile";
  660. // }
  661. // }
  662. // }
  663. this.loadTemplateStyles( this.stylesList[this.json.data.viewStyleType].file, this.stylesList[this.json.data.viewStyleType].extendFile,
  664. function( templateStyles ){
  665. this.templateStyles = templateStyles;
  666. // this.loadDomModules();
  667. if (this.json.data.viewStyleType && this.templateStyles && this.templateStyles["form"]){
  668. this.setTemplateStyles(this.templateStyles["form"]);
  669. }
  670. // this.setCustomStyles();
  671. this.node.setProperties(this.json.data.properties);
  672. if(callback)callback();
  673. // this.setNodeEvents();
  674. // if (this.options.mode=="Mobile"){
  675. // if (oldStyleValue) this._setEditStyle("viewStyleType", null, oldStyleValue);
  676. // }
  677. }.bind(this)
  678. );
  679. }.bind(this));
  680. },
  681. removeStyles: function(from, to){
  682. if (this.json.data[to]){
  683. Object.each(from, function(style, key){
  684. if (this.json.data[to][key] && this.json.data[to][key]==style){
  685. delete this.json.data[to][key];
  686. }
  687. }.bind(this));
  688. }
  689. },
  690. copyStyles: function(from, to){
  691. if (!this.json.data[to]) this.json.data[to] = {};
  692. Object.each(from, function(style, key){
  693. if (!this.json.data[to][key]) this.json.data[to][key] = style;
  694. }.bind(this));
  695. },
  696. clearTemplateStyles: function(styles){
  697. if (styles){
  698. if (styles.styles) this.removeStyles(styles.styles, "styles");
  699. if (styles.properties) this.removeStyles(styles.properties, "properties");
  700. }
  701. },
  702. setTemplateStyles: function(styles){
  703. if (styles.styles) this.copyStyles(styles.styles, "styles");
  704. if (styles.properties) this.copyStyles(styles.properties, "properties");
  705. },
  706. loadTemplateStyles : function( file, extendFile, callback ){
  707. if( !file ){
  708. if (callback) callback({});
  709. return;
  710. }
  711. this.templateStylesList = this.templateStylesList || {};
  712. if( this.templateStylesList[file] ){
  713. if (callback) callback(this.templateStylesList[file]);
  714. return;
  715. }
  716. this.loadTemplateStyleFile( file, function( json_file ){
  717. this.loadTemplateExtendStyleFile( extendFile, function( json_extend ){
  718. this.templateStylesList[file] = Object.merge( json_file, json_extend );
  719. if (callback) callback(this.templateStylesList[file]);
  720. }.bind(this))
  721. }.bind(this))
  722. },
  723. loadTemplateStyleFile : function(file, callback ){
  724. if( !file ){
  725. if (callback) callback({});
  726. return;
  727. }
  728. var stylesUrl = "/x_component_query_ViewDesigner/$View/skin/"+file;
  729. MWF.getJSON(stylesUrl,{
  730. "onSuccess": function(responseJSON){
  731. //this.templateStylesList[file] = responseJSON;
  732. if (callback) callback(responseJSON);
  733. }.bind(this),
  734. "onRequestFailure": function(){
  735. if (callback) callback({});
  736. }.bind(this),
  737. "onError": function(){
  738. if (callback) callback({});
  739. }.bind(this)
  740. }
  741. );
  742. },
  743. loadTemplateExtendStyleFile : function(extendFile, callback ){
  744. if( !extendFile ){
  745. if (callback) callback({});
  746. return;
  747. }
  748. var stylesUrl = "/x_component_query_ViewDesigner/$View/skin/"+extendFile;
  749. MWF.getJSON(stylesUrl,{
  750. "onSuccess": function(responseJSON){
  751. //this.templateStylesList[file] = responseJSON;
  752. if (callback) callback(responseJSON);
  753. }.bind(this),
  754. "onRequestFailure": function(){
  755. if (callback) callback({});
  756. }.bind(this),
  757. "onError": function(){
  758. if (callback) callback({});
  759. }.bind(this)
  760. }
  761. );
  762. },
  763. loadStylesList: function(callback){
  764. var configUrl = "/x_component_query_ViewDesigner/$View/skin/config.json";
  765. MWF.getJSON(configUrl,{
  766. "onSuccess": function(responseJSON){
  767. this.stylesList = responseJSON;
  768. if (callback) callback(this.stylesList);
  769. }.bind(this),
  770. "onRequestFailure": function(){
  771. this.stylesList = {};
  772. if (callback) callback(this.stylesList);
  773. }.bind(this),
  774. "onError": function(){
  775. this.stylesList = {};
  776. if (callback) callback(this.stylesList);
  777. }.bind(this)
  778. }
  779. );
  780. }
  781. });
  782. MWF.xApplication.query.ViewDesigner.View.Column = new Class({
  783. initialize: function(json, view, next){
  784. this.propertyPath = "/x_component_query_ViewDesigner/$View/column.html";
  785. this.view = view;
  786. this.json = json;
  787. this.next = next;
  788. this.css = this.view.css;
  789. this.content = this.view.viewTitleTrNode;
  790. this.domListNode = this.view.domListNode;
  791. this.load();
  792. },
  793. load: function(){
  794. this.areaNode = new Element("td", {"styles": this.css.viewTitleColumnAreaNode});
  795. this.areaNode.store("column", this);
  796. if (this.next){
  797. this.areaNode.inject(this.next.areaNode, "before");
  798. }else{
  799. this.areaNode.inject(this.content);
  800. }
  801. this.node = new Element("div", {
  802. "styles": this.css.viewTitleColumnNode
  803. }).inject(this.areaNode);
  804. this.textNode = new Element("div", {
  805. "styles": this.css.viewTitleColumnTextNode,
  806. "text": this.json.displayName
  807. }).inject(this.node);
  808. this.createDomListItem();
  809. this._createIconAction();
  810. //if (!this.json.export) this.hideMode();
  811. this.setEvent();
  812. },
  813. createDomListItem: function(){
  814. this.listNode = new Element("div", {"styles": this.css.cloumnListNode});
  815. if (this.next){
  816. this.listNode.inject(this.next.listNode, "before");
  817. }else{
  818. this.listNode.inject(this.domListNode);
  819. }
  820. var listIconNode = new Element("div", {"styles": this.css.cloumnListIconNode}).inject(this.listNode);
  821. var listTextNode = new Element("div", {"styles": this.css.cloumnListTextNode}).inject(this.listNode);
  822. this.resetTextNode();
  823. },
  824. setEvent: function(){
  825. this.node.addEvents({
  826. "click": function(e){this.selected(); e.stopPropagation();}.bind(this),
  827. "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css.viewTitleColumnNode_over)}.bind(this),
  828. "mouseout": function(){if (!this.isSelected) if (this.isError){
  829. this.node.setStyles(this.css.viewTitleColumnNode_error)
  830. }else{
  831. this.node.setStyles(this.css.viewTitleColumnNode)
  832. }}.bind(this)
  833. });
  834. this.listNode.addEvents({
  835. "click": function(e){this.selected(); e.stopPropagation();}.bind(this),
  836. "mouseover": function(){debugger; if (!this.isSelected) this.listNode.setStyles(this.css.cloumnListNode_over)}.bind(this),
  837. "mouseout": function(){if (!this.isSelected) this.listNode.setStyles(this.css.cloumnListNode)}.bind(this)
  838. });
  839. },
  840. _createIconAction: function(){
  841. if (!this.actionArea){
  842. this.actionArea = new Element("div", {"styles": this.css.actionAreaNode}).inject(this.view.areaNode, "after");
  843. this._createAction({
  844. "name": "move",
  845. "icon": "move1.png",
  846. "event": "mousedown",
  847. "action": "move",
  848. "title": MWF.APPDVD.LP.action.move
  849. });
  850. this._createAction({
  851. "name": "add",
  852. "icon": "add.png",
  853. "event": "click",
  854. "action": "addColumn",
  855. "title": MWF.APPDVD.LP.action.add
  856. });
  857. this._createAction({
  858. "name": "delete",
  859. "icon": "delete1.png",
  860. "event": "click",
  861. "action": "delete",
  862. "title": MWF.APPDVD.LP.action["delete"]
  863. });
  864. }
  865. },
  866. _createAction: function(action){
  867. var actionNode = new Element("div", {
  868. "styles": this.css.actionNodeStyles,
  869. "title": action.title
  870. }).inject(this.actionArea);
  871. actionNode.setStyle("background", "url("+this.view.path+this.view.options.style+"/action/"+action.icon+") no-repeat left center");
  872. actionNode.addEvent(action.event, function(e){
  873. this[action.action](e);
  874. }.bind(this));
  875. actionNode.addEvents({
  876. "mouseover": function(e){
  877. e.target.setStyle("border", "1px solid #999");
  878. }.bind(this),
  879. "mouseout": function(e){
  880. e.target.setStyle("border", "1px solid #F1F1F1");
  881. }.bind(this)
  882. });
  883. },
  884. _setActionAreaPosition: function(){
  885. var p = this.node.getPosition(this.view.areaNode.getOffsetParent());
  886. var y = p.y-25;
  887. var x = p.x;
  888. this.actionArea.setPosition({"x": x, "y": y});
  889. },
  890. _showActions: function(){
  891. if (this.actionArea){
  892. this._setActionAreaPosition();
  893. this.actionArea.setStyle("display", "block");
  894. }
  895. },
  896. _hideActions: function(){
  897. if (this.actionArea) this.actionArea.setStyle("display", "none");
  898. },
  899. selected: function(){
  900. if (this.view.currentSelectedModule){
  901. if (this.view.currentSelectedModule==this){
  902. return true;
  903. }else{
  904. this.view.currentSelectedModule.unSelected();
  905. }
  906. }
  907. this.node.setStyles(this.css.viewTitleColumnNode_selected);
  908. this.listNode.setStyles(this.css.cloumnListNode_selected);
  909. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  910. new Fx.Scroll(this.view.designer.propertyDomArea, {"wheelStops": false, "duration": 100}).toElement(this.listNode);
  911. this.view.currentSelectedModule = this;
  912. this.isSelected = true;
  913. this._showActions();
  914. this.showProperty();
  915. },
  916. unSelected: function(){
  917. this.view.currentSelectedModule = null;
  918. //this.node.setStyles(this.css.viewTitleColumnNode);
  919. if (this.isError){
  920. this.node.setStyles(this.css.viewTitleColumnNode_error)
  921. }else{
  922. this.node.setStyles(this.css.viewTitleColumnNode)
  923. }
  924. this.listNode.setStyles(this.css.cloumnListNode);
  925. this.isSelected = false;
  926. this._hideActions();
  927. this.hideProperty();
  928. },
  929. showProperty: function(){
  930. if (!this.property){
  931. this.property = new MWF.xApplication.query.ViewDesigner.Property(this, this.view.designer.propertyContentArea, this.view.designer, {
  932. "path": this.propertyPath,
  933. "onPostLoad": function(){
  934. this.property.show();
  935. var processDiv = this.property.propertyContent.getElements("#"+this.json.id+"dataPathSelectedProcessArea");
  936. var cmsDiv = this.property.propertyContent.getElements("#"+this.json.id+"dataPathSelectedCMSArea");
  937. if (this.view.json.type=="cms"){
  938. processDiv.setStyle("display", "none");
  939. cmsDiv.setStyle("display", "block");
  940. }else{
  941. processDiv.setStyle("display", "block");
  942. cmsDiv.setStyle("display", "none");
  943. }
  944. }.bind(this)
  945. });
  946. this.property.load();
  947. }else{
  948. this.property.show();
  949. }
  950. },
  951. hideProperty: function(){
  952. if (this.property) this.property.hide();
  953. },
  954. _setEditStyle: function(name, input, oldValue){
  955. if (name=="displayName") this.resetTextNode();
  956. if (name=="selectType") this.resetTextNode();
  957. if (name=="attribute") this.resetTextNode();
  958. if (name=="path") this.resetTextNode();
  959. if (name=="column"){
  960. this.view.json.data.orderList.each(function(order){
  961. if (order.column==oldValue) order.column = this.json.column
  962. }.bind(this));
  963. if (this.view.json.data.group.column == oldValue) this.view.json.data.group.column = this.json.column;
  964. }
  965. },
  966. resetTextNode: function(){
  967. var listText = (this.json.selectType=="attribute") ? (this.json.attribute || "") : (this.json.path || "");
  968. if (!listText) listText = "unnamed";
  969. this.textNode.set("text", this.json.displayName);
  970. this.listNode.getLast().set("text", this.json.displayName+"("+listText+")");
  971. },
  972. "delete": function(e){
  973. var _self = this;
  974. if (!e) e = this.node;
  975. this.view.designer.confirm("warn", e, MWF.APPDVD.LP.notice.deleteColumnTitle, MWF.APPDVD.LP.notice.deleteColumn, 300, 120, function(){
  976. _self.destroy();
  977. this.close();
  978. }, function(){
  979. this.close();
  980. }, null);
  981. },
  982. destroy: function(){
  983. if (this.view.currentSelectedModule==this) this.view.currentSelectedModule = null;
  984. if (this.actionArea) this.actionArea.destroy();
  985. if (this.listNode) this.listNode.destroy();
  986. if (this.property) this.property.propertyContent.destroy();
  987. var idx = this.view.items.indexOf(this);
  988. if (this.view.viewContentTableNode){
  989. var trs = this.view.viewContentTableNode.getElements("tr");
  990. trs.each(function(tr){
  991. tr.deleteCell(idx);
  992. }.bind(this));
  993. }
  994. if (this.view.json.data.selectList) this.view.json.data.selectList.erase(this.json);
  995. if (this.view.json.data.calculate) if (this.view.json.data.calculate.calculateList) this.view.json.data.calculate.calculateList.erase(this.json);
  996. this.view.items.erase(this);
  997. if (this.view.property) this.view.property.loadStatColumnSelect();
  998. this.areaNode.destroy();
  999. this.view.selected();
  1000. this.view.setViewWidth();
  1001. MWF.release(this);
  1002. delete this;
  1003. },
  1004. addColumn: function(e, data){
  1005. MWF.require("MWF.widget.UUID", function(){
  1006. var json;
  1007. if (data){
  1008. json = Object.clone(data);
  1009. json.id = (new MWF.widget.UUID).id;
  1010. json.column = (new MWF.widget.UUID).id;
  1011. }else{
  1012. var id = (new MWF.widget.UUID).id;
  1013. json = {
  1014. "id": id,
  1015. "column": id,
  1016. "displayName": this.view.designer.lp.unnamed,
  1017. "orderType": "original"
  1018. };
  1019. }
  1020. var idx = this.view.json.data.selectList.indexOf(this.json);
  1021. this.view.json.data.selectList.splice(idx, 0, json);
  1022. var column = new MWF.xApplication.query.ViewDesigner.View.Column(json, this.view, this);
  1023. this.view.items.splice(idx, 0, column);
  1024. column.selected();
  1025. if (this.view.viewContentTableNode){
  1026. var trs = this.view.viewContentTableNode.getElements("tr");
  1027. trs.each(function(tr){
  1028. var td = tr.insertCell(idx);
  1029. td.setStyles(this.css.viewContentTdNode);
  1030. }.bind(this));
  1031. }
  1032. this.view.setViewWidth();
  1033. }.bind(this));
  1034. },
  1035. move: function(e){
  1036. var columnNodes = [];
  1037. this.view.items.each(function(item){
  1038. if (item!=this){
  1039. columnNodes.push(item.areaNode);
  1040. }
  1041. }.bind(this));
  1042. this._createMoveNode();
  1043. this._setNodeMove(columnNodes, e);
  1044. },
  1045. _createMoveNode: function(){
  1046. this.moveNode = new Element("div", {"text": this.node.get("text")});
  1047. this.moveNode.inject(this.view.designer.content);
  1048. this.moveNode.setStyles({
  1049. "border": "2px dashed #ffa200",
  1050. "opacity": 0.7,
  1051. "height": "30px",
  1052. "line-height": "30px",
  1053. "padding": "0px 10px",
  1054. "position": "absolute"
  1055. });
  1056. },
  1057. _setMoveNodePosition: function(e){
  1058. var x = e.page.x+2;
  1059. var y = e.page.y+2;
  1060. this.moveNode.positionTo(x, y);
  1061. },
  1062. createMoveFlagNode: function(){
  1063. this.moveFlagNode = new Element("td", {"styles": this.css.moveFlagNode});
  1064. },
  1065. _setNodeMove: function(droppables, e){
  1066. this._setMoveNodePosition(e);
  1067. var movePosition = this.moveNode.getPosition();
  1068. var moveSize = this.moveNode.getSize();
  1069. var contentPosition = this.content.getPosition();
  1070. var contentSize = this.content.getSize();
  1071. var nodeDrag = new Drag.Move(this.moveNode, {
  1072. "droppables": droppables,
  1073. "limit": {
  1074. "x": [contentPosition.x, contentPosition.x+contentSize.x],
  1075. "y": [movePosition.y, movePosition.y+moveSize.y]
  1076. },
  1077. "onEnter": function(dragging, inObj){
  1078. if (!this.moveFlagNode) this.createMoveFlagNode();
  1079. this.moveFlagNode.inject(inObj, "before");
  1080. }.bind(this),
  1081. "onLeave": function(dragging, inObj){
  1082. if (this.moveFlagNode){
  1083. this.moveFlagNode.dispose();
  1084. }
  1085. }.bind(this),
  1086. "onDrop": function(dragging, inObj){
  1087. if (inObj){
  1088. this.areaNode.inject(inObj, "before");
  1089. var column = inObj.retrieve("column");
  1090. this.listNode.inject(column.listNode, "before");
  1091. var idx = this.view.json.data.selectList.indexOf(column.json);
  1092. this.view.json.data.selectList.erase(this.json);
  1093. this.view.items.erase(this);
  1094. this.view.json.data.selectList.splice(idx, 0, this.json);
  1095. this.view.items.splice(idx, 0, this);
  1096. if (this.moveNode) this.moveNode.destroy();
  1097. if (this.moveFlagNode) this.moveFlagNode.destroy();
  1098. this._setActionAreaPosition();
  1099. }else{
  1100. if (this.moveNode) this.moveNode.destroy();
  1101. if (this.moveFlagNode) this.moveFlagNode.destroy();
  1102. }
  1103. }.bind(this),
  1104. "onCancel": function(dragging){
  1105. if (this.moveNode) this.moveNode.destroy();
  1106. if (this.moveFlagNode) this.moveFlagNode.destroy();
  1107. }.bind(this)
  1108. });
  1109. nodeDrag.start(e);
  1110. }
  1111. //hideMode: function(){
  1112. // if (!this.columnHideFlagNode){
  1113. // this.columnHideFlagNode = new Element("div", {"styles": this.view.css.columnHideFlagNode}).inject(this.node);
  1114. // }
  1115. //},
  1116. //showMode: function(){
  1117. // if (this.columnHideFlagNode) this.columnHideFlagNode.destroy();
  1118. // this.columnHideFlagNode = null;
  1119. //}
  1120. });
  1121. MWF.require("MWF.widget.Toolbar", null, false);
  1122. MWF.xApplication.query.ViewDesigner.View.Actionbar = new Class({
  1123. Implements: [Options, Events],
  1124. options : {
  1125. "style" : "default",
  1126. "customImageStyle" : "default"
  1127. },
  1128. initialize: function(json, jsonList, view, options){
  1129. this.setOptions( options );
  1130. this.propertyPath = "/x_component_query_ViewDesigner/$View/actionbar.html";
  1131. this.path = "/x_component_query_ViewDesigner/$View/";
  1132. this.imagePath_default = "/x_component_query_ViewDesigner/$View/";
  1133. this.imagePath_custom = "/x_component_process_FormDesigner/Module/Actionbar/";
  1134. this.cssPath = "/x_component_query_ViewDesigner/$View/"+this.options.style+"/actionbar.wcss";
  1135. this.view = view;
  1136. this.json = json;
  1137. this.jsonList = jsonList;
  1138. this.css = this.view.css;
  1139. this.container = this.view.actionbarNode;
  1140. this.load();
  1141. },
  1142. load: function(){
  1143. this.systemTools = [];
  1144. this.customTools = [];
  1145. if( !this.json ){
  1146. this.loadDefaultJson(function(){
  1147. this._load()
  1148. }.bind(this));
  1149. }else{
  1150. this._load()
  1151. }
  1152. },
  1153. _load : function(){
  1154. this._createNode();
  1155. //this._createIconAction();
  1156. //if (!this.json.export) this.hideMode();
  1157. this.setEvent();
  1158. },
  1159. loadDefaultJson: function(callback){
  1160. var url = this.path+"actionbar.json";
  1161. MWF.getJSON(url, {
  1162. "onSuccess": function(obj){
  1163. this.view.designer.actions.getUUID(function(id){
  1164. obj.id=id;
  1165. //obj.isNewView = true;
  1166. //obj.application = this.view.designer.application.id;
  1167. this.json = obj;
  1168. this.jsonList.push( this.json );
  1169. if (callback) callback(obj);
  1170. }.bind(this));
  1171. }.bind(this),
  1172. "onerror": function(text){
  1173. this.view.designer.notice(text, "error");
  1174. }.bind(this),
  1175. "onRequestFailure": function(xhr){
  1176. this.view.designer.notice(xhr.responseText, "error");
  1177. }.bind(this)
  1178. });
  1179. },
  1180. setEvent: function(){
  1181. this.node.addEvents({
  1182. "click": function(e){this.selected(); e.stopPropagation();}.bind(this),
  1183. "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css.toolbarWarpNode_over)}.bind(this),
  1184. "mouseout": function(){if (!this.isSelected) this.node.setStyles(this.css.toolbarWarpNode) }.bind(this)
  1185. });
  1186. },
  1187. //_createIconAction: function(){
  1188. // if (!this.actionArea){
  1189. // this.actionArea = new Element("div", {"styles": this.css.actionAreaNode}).inject(this.container, "after");
  1190. //
  1191. // //this._createAction({
  1192. // // "name": "move",
  1193. // // "icon": "move1.png",
  1194. // // "event": "mousedown",
  1195. // // "action": "move",
  1196. // // "title": MWF.APPDVD.LP.action.move
  1197. // //});
  1198. // //this._createAction({
  1199. // // "name": "add",
  1200. // // "icon": "add.png",
  1201. // // "event": "click",
  1202. // // "action": "addColumn",
  1203. // // "title": MWF.APPDVD.LP.action.add
  1204. // //});
  1205. // this._createAction({
  1206. // "name": "delete",
  1207. // "icon": "delete1.png",
  1208. // "event": "click",
  1209. // "action": "delete",
  1210. // "title": MWF.APPDVD.LP.action["delete"]
  1211. // });
  1212. // }
  1213. //},
  1214. //_createAction: function(action){
  1215. // var actionNode = new Element("div", {
  1216. // "styles": this.css.actionNodeStyles,
  1217. // "title": action.title
  1218. // }).inject(this.actionArea);
  1219. // actionNode.setStyle("background", "url("+this.view.path+this.view.options.style+"/action/"+action.icon+") no-repeat left center");
  1220. // actionNode.addEvent(action.event, function(e){
  1221. // this[action.action](e);
  1222. // }.bind(this));
  1223. // actionNode.addEvents({
  1224. // "mouseover": function(e){
  1225. // e.target.setStyle("border", "1px solid #999");
  1226. // }.bind(this),
  1227. // "mouseout": function(e){
  1228. // e.target.setStyle("border", "1px solid #F1F1F1");
  1229. // }.bind(this)
  1230. // });
  1231. //},
  1232. //_setActionAreaPosition: function(){
  1233. // var p = this.node.getPosition(this.view.areaNode.getOffsetParent());
  1234. // var y = p.y-25;
  1235. // var x = p.x;
  1236. // this.actionArea.setPosition({"x": x, "y": y});
  1237. //},
  1238. //_showActions: function(){
  1239. // if (this.actionArea){
  1240. // this._setActionAreaPosition();
  1241. // this.actionArea.setStyle("display", "block");
  1242. // }
  1243. //},
  1244. //_hideActions: function(){
  1245. // if (this.actionArea) this.actionArea.setStyle("display", "none");
  1246. //},
  1247. selected: function(){
  1248. if (this.view.currentSelectedModule){
  1249. if (this.view.currentSelectedModule==this){
  1250. return true;
  1251. }else{
  1252. this.view.currentSelectedModule.unSelected();
  1253. }
  1254. }
  1255. this.node.setStyles(this.css.toolbarWarpNode_selected);
  1256. //this.listNode.setStyles(this.css.cloumnListNode_selected);
  1257. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  1258. //new Fx.Scroll(this.view.designer.propertyDomArea, {"wheelStops": false, "duration": 100}).toElement(this.listNode);
  1259. this.view.currentSelectedModule = this;
  1260. this.isSelected = true;
  1261. //this._showActions();
  1262. this.showProperty();
  1263. },
  1264. unSelected: function(){
  1265. this.view.currentSelectedModule = null;
  1266. this.node.setStyles(this.css.toolbarWarpNode)
  1267. //this.listNode.setStyles(this.css.cloumnListNode);
  1268. this.isSelected = false;
  1269. //this._hideActions();
  1270. this.hideProperty();
  1271. },
  1272. showProperty: function(){
  1273. if (!this.property){
  1274. this.property = new MWF.xApplication.query.ViewDesigner.Property(this, this.view.designer.propertyContentArea, this.view.designer, {
  1275. "path": this.propertyPath,
  1276. "onPostLoad": function(){
  1277. this.property.show();
  1278. //var processDiv = this.property.propertyContent.getElements("#"+this.json.id+"dataPathSelectedProcessArea");
  1279. //var cmsDiv = this.property.propertyContent.getElements("#"+this.json.id+"dataPathSelectedCMSArea");
  1280. //
  1281. //if (this.view.json.type=="cms"){
  1282. // processDiv.setStyle("display", "none");
  1283. // cmsDiv.setStyle("display", "block");
  1284. //}else{
  1285. // processDiv.setStyle("display", "block");
  1286. // cmsDiv.setStyle("display", "none");
  1287. //}
  1288. }.bind(this)
  1289. });
  1290. this.property.load();
  1291. }else{
  1292. this.property.show();
  1293. }
  1294. },
  1295. hideProperty: function(){
  1296. if (this.property) this.property.hide();
  1297. },
  1298. resetTextNode: function(){
  1299. var listText = (this.json.selectType=="attribute") ? (this.json.attribute || "") : (this.json.path || "");
  1300. if (!listText) listText = "unnamed";
  1301. this.textNode.set("text", this.json.displayName);
  1302. this.listNode.getLast().set("text", this.json.displayName+"("+listText+")");
  1303. },
  1304. //"delete": function(e){
  1305. // var _self = this;
  1306. // if (!e) e = this.node;
  1307. // this.view.designer.confirm("warn", e, MWF.APPDVD.LP.notice.deleteColumnTitle, MWF.APPDVD.LP.notice.deleteColumn, 300, 120, function(){
  1308. // _self.destroy();
  1309. //
  1310. // this.close();
  1311. // }, function(){
  1312. // this.close();
  1313. // }, null);
  1314. //},
  1315. //destroy: function(){
  1316. // if (this.view.currentSelectedModule==this) this.view.currentSelectedModule = null;
  1317. // if (this.actionArea) this.actionArea.destroy();
  1318. // if (this.listNode) this.listNode.destroy();
  1319. // if (this.property) this.property.propertyContent.destroy();
  1320. //
  1321. // var idx = this.view.items.indexOf(this);
  1322. //
  1323. // if (this.view.viewContentTableNode){
  1324. // var trs = this.view.viewContentTableNode.getElements("tr");
  1325. // trs.each(function(tr){
  1326. // tr.deleteCell(idx);
  1327. // }.bind(this));
  1328. // }
  1329. //
  1330. // if (this.view.json.data.selectList) this.view.json.data.selectList.erase(this.json);
  1331. // if (this.view.json.data.calculate) if (this.view.json.data.calculate.calculateList) this.view.json.data.calculate.calculateList.erase(this.json);
  1332. // this.view.items.erase(this);
  1333. // if (this.view.property) this.view.property.loadStatColumnSelect();
  1334. //
  1335. // this.areaNode.destroy();
  1336. // this.view.selected();
  1337. //
  1338. // this.view.setViewWidth();
  1339. //
  1340. // MWF.release(this);
  1341. // delete this;
  1342. //},
  1343. //move: function(e){
  1344. // this._createMoveNode();
  1345. //
  1346. // //this._setNodeMove(columnNodes, e);
  1347. //},
  1348. //_createMoveNode: function(){
  1349. // this.moveNode = new Element("div", {"text": this.node.get("text")});
  1350. // this.moveNode.inject(this.view.designer.content);
  1351. // this.moveNode.setStyles({
  1352. // "border": "2px dashed #ffa200",
  1353. // "opacity": 0.7,
  1354. // "height": "30px",
  1355. // "line-height": "30px",
  1356. // "padding": "0px 10px",
  1357. // "position": "absolute"
  1358. // });
  1359. //},
  1360. //_setMoveNodePosition: function(e){
  1361. // var x = e.page.x+2;
  1362. // var y = e.page.y+2;
  1363. // this.moveNode.positionTo(x, y);
  1364. //},
  1365. //createMoveFlagNode: function(){
  1366. // this.moveFlagNode = new Element("td", {"styles": this.css.moveFlagNode});
  1367. //},
  1368. //_setNodeMove: function(droppables, e){
  1369. // this._setMoveNodePosition(e);
  1370. // var movePosition = this.moveNode.getPosition();
  1371. // var moveSize = this.moveNode.getSize();
  1372. // var contentPosition = this.content.getPosition();
  1373. // var contentSize = this.content.getSize();
  1374. //
  1375. // var nodeDrag = new Drag.Move(this.moveNode, {
  1376. // "droppables": droppables,
  1377. // "limit": {
  1378. // "x": [contentPosition.x, contentPosition.x+contentSize.x],
  1379. // "y": [movePosition.y, movePosition.y+moveSize.y]
  1380. // },
  1381. // "onEnter": function(dragging, inObj){
  1382. // if (!this.moveFlagNode) this.createMoveFlagNode();
  1383. // this.moveFlagNode.inject(inObj, "before");
  1384. // }.bind(this),
  1385. // "onLeave": function(dragging, inObj){
  1386. // if (this.moveFlagNode){
  1387. // this.moveFlagNode.dispose();
  1388. // }
  1389. // }.bind(this),
  1390. // "onDrop": function(dragging, inObj){
  1391. // if (inObj){
  1392. // this.areaNode.inject(inObj, "before");
  1393. // var column = inObj.retrieve("column");
  1394. // this.listNode.inject(column.listNode, "before");
  1395. // var idx = this.view.json.data.selectList.indexOf(column.json);
  1396. //
  1397. // this.view.json.data.selectList.erase(this.json);
  1398. // this.view.items.erase(this);
  1399. //
  1400. // this.view.json.data.selectList.splice(idx, 0, this.json);
  1401. // this.view.items.splice(idx, 0, this);
  1402. //
  1403. // if (this.moveNode) this.moveNode.destroy();
  1404. // if (this.moveFlagNode) this.moveFlagNode.destroy();
  1405. // this._setActionAreaPosition();
  1406. // }else{
  1407. // if (this.moveNode) this.moveNode.destroy();
  1408. // if (this.moveFlagNode) this.moveFlagNode.destroy();
  1409. // }
  1410. // }.bind(this),
  1411. // "onCancel": function(dragging){
  1412. // if (this.moveNode) this.moveNode.destroy();
  1413. // if (this.moveFlagNode) this.moveFlagNode.destroy();
  1414. // }.bind(this)
  1415. // });
  1416. // nodeDrag.start(e);
  1417. //},
  1418. deletePropertiesOrStyles: function(name, key){
  1419. if (name=="properties"){
  1420. try{
  1421. this.node.removeProperty(key);
  1422. }catch(e){}
  1423. }
  1424. },
  1425. setPropertiesOrStyles: function(name){
  1426. if (name=="styles"){
  1427. try{
  1428. this.setCustomStyles();
  1429. }catch(e){}
  1430. }
  1431. if (name=="properties"){
  1432. try{
  1433. this.node.setProperties(this.json.properties);
  1434. }catch(e){}
  1435. }
  1436. },
  1437. setCustomNodeStyles: function(node, styles){
  1438. var border = node.getStyle("border");
  1439. node.clearStyles();
  1440. //node.setStyles(styles);
  1441. node.setStyle("border", border);
  1442. Object.each(styles, function(value, key){
  1443. var reg = /^border\w*/ig;
  1444. if (!key.test(reg)){
  1445. node.setStyle(key, value);
  1446. }
  1447. }.bind(this));
  1448. },
  1449. setCustomStyles: function(){
  1450. var border = this.node.getStyle("border");
  1451. this.node.clearStyles();
  1452. this.node.setStyles(this.css.moduleNode);
  1453. if (this.initialStyles) this.node.setStyles(this.initialStyles);
  1454. this.node.setStyle("border", border);
  1455. if (this.json.styles) Object.each(this.json.styles, function(value, key){
  1456. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1)){
  1457. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  1458. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  1459. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  1460. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  1461. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  1462. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  1463. }
  1464. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  1465. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  1466. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  1467. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  1468. }
  1469. }
  1470. var reg = /^border\w*/ig;
  1471. if (!key.test(reg)){
  1472. if (key){
  1473. if (key.toString().toLowerCase()==="display"){
  1474. if (value.toString().toLowerCase()==="none"){
  1475. this.node.setStyle("opacity", 0.3);
  1476. }else{
  1477. this.node.setStyle("opacity", 1);
  1478. this.node.setStyle(key, value);
  1479. }
  1480. }else{
  1481. this.node.setStyle(key, value);
  1482. }
  1483. }
  1484. }
  1485. //this.node.setStyle(key, value);
  1486. }.bind(this));
  1487. },
  1488. _setEditStyle: function(name, obj, oldValue){
  1489. var title = "";
  1490. var text = "";
  1491. if (name==="name"){
  1492. title = this.json.name || this.json.id;
  1493. text = this.json.type.substr(this.json.type.lastIndexOf("$")+1, this.json.type.length);
  1494. this.treeNode.setText("<"+text+"> "+title);
  1495. }
  1496. if (name==="id"){
  1497. title = this.json.name || this.json.id;
  1498. if (!this.json.name){
  1499. text = this.json.type.substr(this.json.type.lastIndexOf("$")+1, this.json.type.length);
  1500. this.treeNode.setText("<"+text+"> "+this.json.id);
  1501. }
  1502. this.treeNode.setTitle(this.json.id);
  1503. this.node.set("id", this.json.id);
  1504. }
  1505. this._setEditStyle_custom(name, obj, oldValue);
  1506. },
  1507. reloadMaplist: function(){
  1508. if (this.property) Object.each(this.property.maplists, function(map, name){ map.reload(this.json[name]);}.bind(this));
  1509. },
  1510. getHtml: function(){
  1511. var copy = this.node.clone(true, true);
  1512. copy.clearStyles(true);
  1513. var html = copy.outerHTML;
  1514. copy.destroy();
  1515. return html;
  1516. },
  1517. getJson: function(){
  1518. var json = Object.clone(this.json);
  1519. var o = {};
  1520. o[json.id] = json;
  1521. return o;
  1522. },
  1523. _createNode: function(callback){
  1524. this.node = new Element("div", {
  1525. "id": this.json.id,
  1526. "MWFType": "actionbar",
  1527. "styles": this.css.toolbarWarpNode,
  1528. "events": {
  1529. "selectstart": function(e){
  1530. e.preventDefault();
  1531. }
  1532. }
  1533. }).inject(this.container );
  1534. this.toolbarNode = new Element("div").inject(this.node);
  1535. this.toolbarWidget = new MWF.widget.Toolbar(this.toolbarNode, {"style": this.json.style}, this);
  1536. if (!this.json.actionStyles){
  1537. this.json.actionStyles = Object.clone(this.toolbarWidget.css);
  1538. }
  1539. //MWF.getJSON(this.path+"toolbars.json", function(json){
  1540. // this.json.defaultTools = json;
  1541. // this.setToolbars(json, this.toolbarNode);
  1542. // debugger;
  1543. // this.toolbarWidget.load();
  1544. //}.bind(this), false);
  1545. if (this.json.defaultTools){
  1546. var json = Array.clone(this.json.defaultTools);
  1547. //if (this.json.tools) json.append(this.json.tools);
  1548. this.setToolbars(json, this.toolbarNode);
  1549. if (this.json.tools){
  1550. this.setCustomToolbars(Array.clone(this.json.tools), this.toolbarNode);
  1551. }
  1552. this.toolbarWidget.load();
  1553. this._setEditStyle_custom("hideSystemTools");
  1554. //json = null;
  1555. }else{
  1556. MWF.getJSON(this.path+"toolbars.json", function(json){
  1557. this.json.defaultTools = json;
  1558. var json = Array.clone(this.json.defaultTools);
  1559. //if (this.json.tools) json.append(this.json.tools);
  1560. this.setToolbars(json, this.toolbarNode);
  1561. if (this.json.tools){
  1562. this.setCustomToolbars(Array.clone(this.json.tools), this.toolbarNode);
  1563. }
  1564. this.toolbarWidget.load();
  1565. this._setEditStyle_custom("hideSystemTools");
  1566. //json = null;
  1567. }.bind(this), false);
  1568. }
  1569. },
  1570. _refreshActionbar: function(){
  1571. //if (this.form.options.mode == "Mobile"){
  1572. // this.node.set("text", MWF.APPFD.LP.notice.notUseModuleInMobile+"("+this.moduleName+")");
  1573. // this.node.setStyles({"height": "24px", "line-height": "24px", "background-color": "#999"});
  1574. //}else{
  1575. this.toolbarNode = this.node.getFirst("div");
  1576. this.toolbarNode.empty();
  1577. this.toolbarWidget = new MWF.widget.Toolbar(this.toolbarNode, {"style": this.json.style}, this);
  1578. if (!this.json.actionStyles) this.json.actionStyles = Object.clone(this.toolbarWidget.css);
  1579. this.toolbarWidget.css = this.json.actionStyles;
  1580. if (this.json.defaultTools){
  1581. var json = Array.clone(this.json.defaultTools);
  1582. //if (this.json.tools) json.append(this.json.tools);
  1583. this.setToolbars(json, this.toolbarNode);
  1584. if (this.json.tools){
  1585. this.setCustomToolbars(Array.clone(this.json.tools), this.toolbarNode);
  1586. }
  1587. this.toolbarWidget.load();
  1588. //json = null;
  1589. }else{
  1590. MWF.getJSON(this.path+"toolbars.json", function(json){
  1591. this.json.defaultTools = json;
  1592. var json = Array.clone(this.json.defaultTools);
  1593. //if (this.json.tools) json.append(this.json.tools);
  1594. this.setToolbars(json, this.toolbarNode);
  1595. if (this.json.tools){
  1596. this.setCustomToolbars(Array.clone(this.json.tools), this.toolbarNode);
  1597. }
  1598. this.toolbarWidget.load();
  1599. //json = null;
  1600. }.bind(this), false);
  1601. }
  1602. //}
  1603. },
  1604. _resetActionbar: function(){
  1605. //if (this.form.options.mode == "Mobile"){
  1606. // this.node.set("text", MWF.APPFD.LP.notice.notUseModuleInMobile+"("+this.moduleName+")");
  1607. // this.node.setStyles({"height": "24px", "line-height": "24px", "background-color": "#999"});
  1608. //}else{
  1609. this.toolbarNode = this.node.getFirst("div");
  1610. this.toolbarNode.empty();
  1611. this.toolbarWidget = new MWF.widget.Toolbar(this.toolbarNode, {"style": this.json.style}, this);
  1612. if (!this.json.actionStyles){
  1613. this.json.actionStyles = Object.clone(this.toolbarWidget.css);
  1614. }else{
  1615. this.toolbarWidget.css = Object.merge( Object.clone(this.json.actionStyles), this.toolbarWidget.css );
  1616. this.json.actionStyles = Object.clone(this.toolbarWidget.css);
  1617. }
  1618. if (this.json.defaultTools){
  1619. var json = Array.clone(this.json.defaultTools);
  1620. //if (this.json.tools) json.append(this.json.tools);
  1621. this.setToolbars(json, this.toolbarNode);
  1622. if (this.json.tools){
  1623. this.setCustomToolbars(Array.clone(this.json.tools), this.toolbarNode);
  1624. }
  1625. this.toolbarWidget.load();
  1626. //json = null;
  1627. }else{
  1628. MWF.getJSON(this.path+"toolbars.json", function(json){
  1629. this.json.defaultTools = json;
  1630. var json = Array.clone(this.json.defaultTools);
  1631. //if (this.json.tools) json.append(this.json.tools);
  1632. this.setToolbars(json, this.toolbarNode);
  1633. if (this.json.tools){
  1634. this.setCustomToolbars(Array.clone(this.json.tools), this.toolbarNode);
  1635. }
  1636. this.toolbarWidget.load();
  1637. //json = null;
  1638. }.bind(this), false);
  1639. }
  1640. //}
  1641. },
  1642. setToolbars: function(tools, node){
  1643. tools.each(function(tool){
  1644. var actionNode = new Element("div", {
  1645. "MWFnodetype": tool.type,
  1646. "MWFButtonImage": this.imagePath_default+""+this.options.style+"/actionbar/"+tool.img,
  1647. "title": tool.title,
  1648. "MWFButtonAction": tool.action,
  1649. "MWFButtonText": tool.text
  1650. }).inject(node);
  1651. if( this.json.iconOverStyle ){
  1652. actionNode.set("MWFButtonImageOver" , this.imagePath_default+""+this.options.style+"/actionbar/"+this.json.iconOverStyle+"/"+tool.img );
  1653. }
  1654. this.systemTools.push(actionNode);
  1655. if (tool.sub){
  1656. var subNode = node.getLast();
  1657. this.setToolbars(tool.sub, subNode);
  1658. }
  1659. }.bind(this));
  1660. },
  1661. setCustomToolbars: function(tools, node){
  1662. //var style = (this.json.style || "default").indexOf("red") > -1 ? "red" : "blue";
  1663. var path = "";
  1664. if( this.json.customIconStyle ){
  1665. path = this.json.customIconStyle+ "/";
  1666. }
  1667. tools.each(function(tool){
  1668. var actionNode = new Element("div", {
  1669. "MWFnodetype": tool.type,
  1670. "MWFButtonImage": this.imagePath_custom+""+this.options.customImageStyle +"/custom/"+path+tool.img,
  1671. "title": tool.title,
  1672. "MWFButtonAction": tool.action,
  1673. "MWFButtonText": tool.text
  1674. }).inject(node);
  1675. if( this.json.customIconOverStyle ){
  1676. actionNode.set("MWFButtonImageOver" , this.imagePath_custom+""+this.options.customImageStyle +"/custom/"+this.json.customIconOverStyle+ "/" +tool.img );
  1677. }
  1678. this.customTools.push(actionNode);
  1679. if (tool.sub){
  1680. var subNode = node.getLast();
  1681. this.setToolbars(tool.sub, subNode);
  1682. }
  1683. }.bind(this));
  1684. },
  1685. _setEditStyle_custom: function(name){
  1686. if (name=="hideSystemTools"){
  1687. if (this.json.hideSystemTools){
  1688. this.systemTools.each(function(tool){
  1689. tool.setStyle("display", "none");
  1690. });
  1691. }else{
  1692. this.systemTools.each(function(tool){
  1693. tool.setStyle("display", "block");
  1694. });
  1695. }
  1696. }
  1697. if (name=="defaultTools" || name=="tools" || name==="actionStyles"){
  1698. this._refreshActionbar();
  1699. }
  1700. }
  1701. });
  1702. MWF.require("MWF.widget.Paging", null, false);
  1703. MWF.xApplication.query.ViewDesigner.View.Paging = new Class({
  1704. Implements: [Options, Events],
  1705. options : {
  1706. "style" : "default"
  1707. },
  1708. initialize: function(json, jsonList, view, options){
  1709. this.setOptions( options );
  1710. this.propertyPath = "/x_component_query_ViewDesigner/$View/paging.html";
  1711. this.view = view;
  1712. this.json = json;
  1713. this.jsonList = jsonList;
  1714. this.css = this.view.css;
  1715. this.container = this.view.pagingNode;
  1716. this.load();
  1717. },
  1718. load: function(){
  1719. this.systemTools = [];
  1720. this.customTools = [];
  1721. if( !this.json ){
  1722. this.loadDefaultJson(function(){
  1723. this._createNode();
  1724. this.setEvent();
  1725. }.bind(this));
  1726. }else{
  1727. this._createNode();
  1728. this.setEvent();
  1729. }
  1730. },
  1731. loadDefaultJson: function(callback){
  1732. var url = this.view.path+"paging.json";
  1733. MWF.getJSON(url, {
  1734. "onSuccess": function(obj){
  1735. this.view.designer.actions.getUUID(function(id){
  1736. obj.id=id;
  1737. this.json = obj;
  1738. this.jsonList.push( this.json );
  1739. if (callback) callback(obj);
  1740. }.bind(this));
  1741. }.bind(this),
  1742. "onerror": function(text){
  1743. this.view.designer.notice(text, "error");
  1744. }.bind(this),
  1745. "onRequestFailure": function(xhr){
  1746. this.view.designer.notice(xhr.responseText, "error");
  1747. }.bind(this)
  1748. });
  1749. },
  1750. setEvent: function(){
  1751. this.node.addEvents({
  1752. "click": function(e){this.selected(); e.stopPropagation();}.bind(this),
  1753. "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css.pagingWarpNode_over)}.bind(this),
  1754. "mouseout": function(){if (!this.isSelected) this.node.setStyles(this.css.pagingWarpNode) }.bind(this)
  1755. });
  1756. },
  1757. selected: function(){
  1758. if (this.view.currentSelectedModule){
  1759. if (this.view.currentSelectedModule==this){
  1760. return true;
  1761. }else{
  1762. this.view.currentSelectedModule.unSelected();
  1763. }
  1764. }
  1765. this.node.setStyles(this.css.pagingWarpNode_selected);
  1766. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  1767. this.view.currentSelectedModule = this;
  1768. this.isSelected = true;
  1769. this.showProperty();
  1770. },
  1771. unSelected: function(){
  1772. this.view.currentSelectedModule = null;
  1773. this.node.setStyles(this.css.pagingWarpNode);
  1774. this.isSelected = false;
  1775. this.hideProperty();
  1776. },
  1777. showProperty: function(){
  1778. if (!this.property){
  1779. this.property = new MWF.xApplication.query.ViewDesigner.Property(this, this.view.designer.propertyContentArea, this.view.designer, {
  1780. "path": this.propertyPath,
  1781. "onPostLoad": function(){
  1782. this.property.show();
  1783. }.bind(this)
  1784. });
  1785. this.property.load();
  1786. }else{
  1787. this.property.show();
  1788. }
  1789. },
  1790. hideProperty: function(){
  1791. if (this.property) this.property.hide();
  1792. },
  1793. resetTextNode: function(){
  1794. var listText = (this.json.selectType=="attribute") ? (this.json.attribute || "") : (this.json.path || "");
  1795. if (!listText) listText = "unnamed";
  1796. this.textNode.set("text", this.json.displayName);
  1797. this.listNode.getLast().set("text", this.json.displayName+"("+listText+")");
  1798. },
  1799. deletePropertiesOrStyles: function(name, key){
  1800. if (name=="properties"){
  1801. try{
  1802. this.node.removeProperty(key);
  1803. }catch(e){}
  1804. }
  1805. },
  1806. setPropertiesOrStyles: function(name){
  1807. if (name=="styles"){
  1808. try{
  1809. this.setCustomStyles();
  1810. }catch(e){}
  1811. }
  1812. if (name=="properties"){
  1813. try{
  1814. this.node.setProperties(this.json.properties);
  1815. }catch(e){}
  1816. }
  1817. },
  1818. setCustomNodeStyles: function(node, styles){
  1819. var border = node.getStyle("border");
  1820. node.clearStyles();
  1821. //node.setStyles(styles);
  1822. node.setStyle("border", border);
  1823. Object.each(styles, function(value, key){
  1824. var reg = /^border\w*/ig;
  1825. if (!key.test(reg)){
  1826. node.setStyle(key, value);
  1827. }
  1828. }.bind(this));
  1829. },
  1830. setCustomStyles: function(){
  1831. var border = this.node.getStyle("border");
  1832. this.node.clearStyles();
  1833. this.node.setStyles(this.css.moduleNode);
  1834. if (this.initialStyles) this.node.setStyles(this.initialStyles);
  1835. this.node.setStyle("border", border);
  1836. if (this.json.styles) Object.each(this.json.styles, function(value, key){
  1837. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1)){
  1838. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  1839. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  1840. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  1841. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  1842. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  1843. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  1844. }
  1845. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  1846. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  1847. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  1848. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  1849. }
  1850. }
  1851. var reg = /^border\w*/ig;
  1852. if (!key.test(reg)){
  1853. if (key){
  1854. if (key.toString().toLowerCase()==="display"){
  1855. if (value.toString().toLowerCase()==="none"){
  1856. this.node.setStyle("opacity", 0.3);
  1857. }else{
  1858. this.node.setStyle("opacity", 1);
  1859. this.node.setStyle(key, value);
  1860. }
  1861. }else{
  1862. this.node.setStyle(key, value);
  1863. }
  1864. }
  1865. }
  1866. //this.node.setStyle(key, value);
  1867. }.bind(this));
  1868. },
  1869. _setEditStyle: function(name, obj, oldValue){
  1870. var title = "";
  1871. var text = "";
  1872. if (name==="name"){
  1873. title = this.json.name || this.json.id;
  1874. text = this.json.type.substr(this.json.type.lastIndexOf("$")+1, this.json.type.length);
  1875. this.treeNode.setText("<"+text+"> "+title);
  1876. }
  1877. if (name==="id"){
  1878. title = this.json.name || this.json.id;
  1879. if (!this.json.name){
  1880. text = this.json.type.substr(this.json.type.lastIndexOf("$")+1, this.json.type.length);
  1881. this.treeNode.setText("<"+text+"> "+this.json.id);
  1882. }
  1883. this.treeNode.setTitle(this.json.id);
  1884. this.node.set("id", this.json.id);
  1885. }
  1886. this._setEditStyle_custom(name, obj, oldValue);
  1887. },
  1888. reloadMaplist: function(){
  1889. if (this.property) Object.each(this.property.maplists, function(map, name){ map.reload(this.json[name]);}.bind(this));
  1890. },
  1891. getHtml: function(){
  1892. var copy = this.node.clone(true, true);
  1893. copy.clearStyles(true);
  1894. var html = copy.outerHTML;
  1895. copy.destroy();
  1896. return html;
  1897. },
  1898. getJson: function(){
  1899. var json = Object.clone(this.json);
  1900. var o = {};
  1901. o[json.id] = json;
  1902. return o;
  1903. },
  1904. _createNode: function(callback){
  1905. this.node = new Element("div", {
  1906. "id": this.json.id,
  1907. "MWFType": "paging",
  1908. "styles": this.css.pagingWarpNode,
  1909. "events": {
  1910. "selectstart": function(e){
  1911. e.preventDefault();
  1912. }
  1913. }
  1914. }).inject(this.container );
  1915. this.pagingNode = new Element("div").inject(this.node);
  1916. this.loadWidget();
  1917. // this.pagingWidget = new MWF.widget.Paging(this.pagingNode, {"style": this.json.style}, this);
  1918. // if (!this.json.pagingStyles){
  1919. // this.json.pagingStyles = Object.clone(this.pagingWidget.css);
  1920. // }
  1921. // this.pagingWidget.load();
  1922. },
  1923. loadWidget : function(){
  1924. var visiblePages = this.json.visiblePages ? this.json.visiblePages.toInt() : 9;
  1925. this.pagingWidget = new o2.widget.Paging(this.pagingNode, {
  1926. style : this.json.style || "default",
  1927. countPerPage: 20, //this.json.pageSize || this.options.perPageCount,
  1928. visiblePages: visiblePages,
  1929. currentPage: 1,
  1930. itemSize: visiblePages * 20 * 2,
  1931. // pageSize: this.pages,
  1932. hasNextPage: typeOf( this.json.hasPreNextPage ) === "boolean" ? this.json.hasPreNextPage : true,
  1933. hasPrevPage: typeOf( this.json.hasPreNextPage ) === "boolean" ? this.json.hasPreNextPage : true,
  1934. hasTruningBar: typeOf( this.json.hasTruningBar ) === "boolean" ? this.json.hasTruningBar : true,
  1935. hasBatchTuring: typeOf( this.json.hasBatchTuring ) === "boolean" ? this.json.hasBatchTuring : true,
  1936. hasFirstPage: typeOf( this.json.hasFirstLastPage ) === "boolean" ? this.json.hasFirstLastPage : true,
  1937. hasLastPage: typeOf( this.json.hasFirstLastPage ) === "boolean" ? this.json.hasFirstLastPage : true,
  1938. hasJumper: typeOf( this.json.hasPageJumper ) === "boolean" ? this.json.hasPageJumper : true,
  1939. hiddenWithDisable: false,
  1940. // hiddenWithNoItem: true,
  1941. text: {
  1942. prePage: this.json.prePageText,
  1943. nextPage: this.json.nextPageText,
  1944. firstPage: this.json.firstPageText,
  1945. lastPage: this.json.lastPageText
  1946. },
  1947. onJumpingPage : function( pageNum, itemNum ){
  1948. }.bind(this),
  1949. onPostLoad : function () {
  1950. this.view.setContentHeight()
  1951. // if(this.setContentHeightFun)this.setContentHeightFun();
  1952. }.bind(this)
  1953. }, this.json.pagingStyles || {});
  1954. if (!this.json.pagingStyles){
  1955. this.json.pagingStyles = Object.clone(this.pagingWidget.css);
  1956. }
  1957. this.pagingWidget.load();
  1958. },
  1959. _refreshPaging: function(){
  1960. this.pagingNode.empty();
  1961. this.loadWidget();
  1962. },
  1963. _setEditStyle_custom: function(name, obj, oldValue){
  1964. debugger;
  1965. if ( ["hasTruningBar","visiblePages","hasBatchTuring",
  1966. "hasFirstLastPage","hasPreNextPage","hasPageJumper",
  1967. "firstPageText","lastPageText","prePageText","nextPageText",
  1968. "pagingStyles"].contains(name)){
  1969. this._refreshPaging();
  1970. }
  1971. }
  1972. });