View.js 90 KB

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