Statement.js 81 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928
  1. MWF.xApplication = MWF.xApplication || {};
  2. MWF.xApplication.query = MWF.xApplication.query || {};
  3. MWF.xApplication.query.StatementDesigner = MWF.xApplication.query.StatementDesigner || {};
  4. MWF.APPDSMD = MWF.xApplication.query.StatementDesigner;
  5. MWF.xDesktop.requireApp("query.StatementDesigner", "lp." + MWF.language, null, false);
  6. MWF.xDesktop.requireApp("query.StatementDesigner", "Property", null, false);
  7. MWF.xDesktop.requireApp("query.ViewDesigner", "View", null, false);
  8. o2.require("o2.widget.JavascriptEditor", null, false);
  9. o2.require("o2.widget.UUID", null, false);
  10. MWF.xApplication.query.StatementDesigner.Statement = new Class({
  11. Extends: MWF.widget.Common,
  12. Implements: [Options, Events],
  13. options: {
  14. "style": "default",
  15. "isView": false,
  16. "showTab": true,
  17. "propertyPath": "../x_component_query_StatementDesigner/$Statement/statement.html"
  18. },
  19. initialize: function (designer, data, options) {
  20. this.setOptions(options);
  21. this.path = "../x_component_query_StatementDesigner/$Statement/";
  22. this.cssPath = "../x_component_query_StatementDesigner/$Statement/" + this.options.style + "/css.wcss";
  23. this._loadCss();
  24. this.designer = designer;
  25. this.data = data;
  26. this.parseData();
  27. this.node = this.designer.designNode;
  28. this.areaNode = new Element("div", {"styles": {"height": "100%", "overflow": "auto"}});
  29. //this.statementRunNode = this.designer.designerStatementArea;
  30. if (this.designer.application) this.data.applicationName = this.designer.application.name;
  31. if (this.designer.application) this.data.application = this.designer.application.id;
  32. this.isNewStatement = (this.data.id) ? false : true;
  33. this.view = this;
  34. this.autoSave();
  35. this.designer.addEvent("queryClose", function () {
  36. if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  37. }.bind(this));
  38. },
  39. parseData: function () {
  40. this.json = this.data;
  41. if (!this.json.type) this.json.type = "select";
  42. if (!this.json.format) this.json.format = "jpql";
  43. if (!this.json.entityCategory) this.json.entityCategory = "official";
  44. if (!this.json.entityClassName) this.json.entityClassName = ""; //"com.x.processplatform.core.entity.content.Task";
  45. },
  46. autoSave: function () {
  47. this.autoSaveTimerID = window.setInterval(function () {
  48. if (!this.autoSaveCheckNode) this.autoSaveCheckNode = this.designer.contentToolbarNode.getElement("#MWFAutoSaveCheck");
  49. if (this.autoSaveCheckNode) {
  50. if (this.autoSaveCheckNode.get("checked")) {
  51. this.save();
  52. }
  53. }
  54. }.bind(this), 60000);
  55. },
  56. getEditorTheme: function(callback){
  57. if (!o2.editorData){
  58. o2.UD.getData("editor", function(json){
  59. if (json.data){
  60. o2.editorData = JSON.decode(json.data);
  61. }else{
  62. o2.editorData = this.getDefaultEditorData();
  63. }
  64. if (callback) callback();
  65. }.bind(this));
  66. }else{
  67. if (callback) callback();
  68. }
  69. },
  70. load : function(){
  71. this.getEditorTheme( function () {
  72. this._load();
  73. }.bind(this))
  74. },
  75. _load: function () {
  76. // this.setAreaNodeSize();
  77. // this.designer.addEvent("resize", this.setAreaNodeSize.bind(this));
  78. this.areaNode.inject(this.node);
  79. this.designer.statementListAreaNode.getChildren().each(function (node) {
  80. var statement = node.retrieve("statement");
  81. if (statement.id == this.data.id) {
  82. if (this.designer.currentListStatementItem) {
  83. this.designer.currentListStatementItem.setStyles(this.designer.css.listStatementItem);
  84. }
  85. node.setStyles(this.designer.css.listStatementItem_current);
  86. this.designer.currentListStatementItem = node;
  87. this.lisNode = node;
  88. }
  89. }.bind(this));
  90. this.loadStatement();
  91. // this.showProperty();
  92. this.selected();
  93. },
  94. selected: function () {
  95. if (this.currentSelectedModule) {
  96. if (this.currentSelectedModule == this) {
  97. return true;
  98. } else {
  99. this.currentSelectedModule.unSelected();
  100. }
  101. }
  102. if (this.view && this.view.domListNode) {
  103. this.view.domListNode.hide();
  104. }
  105. this.currentSelectedModule = this;
  106. this.isSelected = true;
  107. this.showProperty();
  108. },
  109. unSelected: function () {
  110. this.currentSelectedModule = null;
  111. this.isSelected = false;
  112. this.hideProperty();
  113. },
  114. showProperty: function () {
  115. if (!this.property) {
  116. this.property = new MWF.xApplication.query.StatementDesigner.Property(this, this.designer.designerContentArea, this.designer, {
  117. "path": this.options.propertyPath,
  118. "onPostLoad": function () {
  119. this.property.show();
  120. }.bind(this)
  121. });
  122. this.property.load();
  123. } else {
  124. this.property.show();
  125. }
  126. },
  127. hideProperty: function () {
  128. if (this.property) this.property.hide();
  129. },
  130. loadJpqlTab: function (callback) {
  131. var _self = this;
  132. MWF.require("MWF.widget.Tab", null, false);
  133. this.jpqlTab = new MWF.widget.Tab(this.jpqlTabNode, {"style": "script"});
  134. this.jpqlTab.load();
  135. this.tabJpqlNode = Element("div");
  136. this.jpqlTabPageNode.inject(this.tabJpqlNode);
  137. this.tabCountJpqlNode = Element("div");
  138. this.countJpqlTabPageNode.inject(this.tabCountJpqlNode);
  139. this.jpqlPage = this.jpqlTab.addTab(this.tabJpqlNode, this.designer.lp.queryStatement);
  140. this.countJpqlPage = this.jpqlTab.addTab(this.tabCountJpqlNode, this.designer.lp.countStatement);
  141. this.jpqlPage.showTabIm();
  142. // this.jpqlPage.addEvent("postShow", function(){
  143. // if( this.view ){
  144. // this.view.setContentHeight();
  145. // this.view.selected();
  146. // }
  147. // }.bind(this));
  148. // this.countJpqlPage.addEvent("postShow", function(){
  149. // this.selected();
  150. // }.bind(this));
  151. },
  152. loadTab: function (callback) {
  153. var _self = this;
  154. MWF.require("MWF.widget.Tab", null, false);
  155. this.tab = new MWF.widget.Tab(this.tabNode, {"style": "script"});
  156. this.tab.load();
  157. this.tabRunNode = Element("div");
  158. this.pageRunNode = new Element("div", {
  159. "styles": {
  160. "overflow": "auto",
  161. "background-color": "#fff"
  162. }
  163. }).inject(this.tabRunNode);
  164. this.runArea.inject(this.pageRunNode);
  165. this.tabViewNode = Element("div", {"styles": {"height": "100%"}});
  166. this.pageViewNode = new Element("div.pageViewNode").inject(this.tabViewNode);
  167. this.viewArea.inject(this.pageViewNode);
  168. this.runPage = this.tab.addTab(this.tabRunNode, this.designer.lp.runTest);
  169. this.viewPage = this.tab.addTab(this.tabViewNode, this.designer.lp.view);
  170. this.runPage.showTabIm();
  171. this.viewPage.addEvent("postShow", function () {
  172. if (this.view) {
  173. this.view.setContentHeight();
  174. this.view.selected();
  175. }
  176. }.bind(this));
  177. this.runPage.addEvent("postShow", function () {
  178. this.selected();
  179. }.bind(this));
  180. },
  181. loadStatement: function () {
  182. //this.statementDesignerNode = new Element("div", {"styles": this.css.statementDesignerNode}).inject(this.areaNode);
  183. this.loadStatementHtml(function () {
  184. this.designerArea = this.areaNode.getElement(".o2_statement_statementDesignerNode");
  185. this.jpqlTabPageNode = this.areaNode.getElement(".o2_statement_statementJpqlTabPageNode");
  186. this.jpqlArea = this.areaNode.getElement(".o2_statement_statementDesignerJpql");
  187. this.scriptArea = this.areaNode.getElement(".o2_statement_statementDesignerScript");
  188. this.formatTypeArea = this.areaNode.getElement(".o2_statement_statementDesignerFormatContent");
  189. this.entityCategorySelect = this.areaNode.getElement(".o2_statement_statementDesignerCategoryContent").getElement("select");
  190. this.dynamicTableArea = this.areaNode.getElement(".o2_statement_statementDesignerTableArea_dynamic");
  191. this.officialTableArea = this.areaNode.getElement(".o2_statement_statementDesignerTableArea_official");
  192. this.customTableArea = this.areaNode.getElement(".o2_statement_statementDesignerTableArea_custom");
  193. this.dynamicTableSelect = this.areaNode.getElement(".o2_statement_statementDesignerSelectTable");
  194. this.officialTableSelect = this.officialTableArea.getElement("select");
  195. this.fieldSelect = this.areaNode.getElement(".o2_statement_statementDesignerTableArea_field").getElement("select");
  196. this.loadFieldSelect();
  197. this.dynamicTableContent = this.areaNode.getElement(".o2_statement_statementDesignerTableContent");
  198. this.jpqlTabNode = this.areaNode.getElement(".o2_statement_statementJpqlTabNode");
  199. this.jpqlTypeSelect = this.areaNode.getElement(".o2_statement_statementDesignerTypeContent").getElement("select");
  200. this.loadJpqlTypeSelect();
  201. // this.jpqlSelectEditor = this.areaNode.getElement(".o2_statement_statementDesignerJpql_select");
  202. // this.jpqlUpdateEditor = this.areaNode.getElement(".o2_statement_statementDesignerJpql_update");
  203. // this.jpqlDeleteEditor = this.areaNode.getElement(".o2_statement_statementDesignerJpql_sdelete");
  204. // this.jpqlSelectEditor_selectContent= this.jpqlSelectEditor.getElement(".o2_statement_statementDesignerJpql_jpql_selectContent");
  205. // this.jpqlSelectEditor_fromContent= this.jpqlSelectEditor.getElement(".o2_statement_statementDesignerJpql_jpql_fromContent");
  206. // this.jpqlSelectEditor_whereContent= this.jpqlSelectEditor.getElement(".o2_statement_statementDesignerJpql_jpql_whereContent");
  207. this.jpqlEditorNode = this.areaNode.getElement(".o2_statement_statementDesignerJpqlLine");
  208. this.countJpqlTabPageNode = this.areaNode.getElement(".o2_statement_statementCountJpqlTabPageNode");
  209. this.countJpqlArea = this.areaNode.getElement(".o2_statement_statementDesignerCountJpql");
  210. this.countScriptArea = this.areaNode.getElement(".o2_statement_statementDesignerCountScript");
  211. this.countJpqlEditorNode = this.areaNode.getElement(".o2_statement_statementDesignerCountJpqlLine");
  212. this.loadJpqlTab();
  213. this.resizeNode = this.areaNode.getElement(".o2_statement_resizeNode");
  214. this.tabNode = this.areaNode.getElement(".o2_statement_tabNode");
  215. this.runArea = this.areaNode.getElement(".o2_statement_statementRunNode");
  216. // this.runTitleNode = this.areaNode.getElement(".o2_statement_statementRunTitleNode");
  217. this.runContentNode = this.areaNode.getElement(".o2_statement_statementRunContentNode");
  218. this.runJsonNode = this.runContentNode.getFirst();
  219. this.runActionNode = this.runJsonNode.getNext();
  220. this.runResultNode = this.runContentNode.getLast();
  221. this.setRunnerSize();
  222. this.designer.addEvent("resize", this.setRunnerSize.bind(this));
  223. if (this.json.format == "script") {
  224. this.loadStatementScriptEditor();
  225. this.loadStatementCountScriptEditor();
  226. } else {
  227. this.loadStatementEditor();
  228. this.loadStatementCountEditor();
  229. }
  230. this.loadStatementRunner();
  231. this.viewArea = this.areaNode.getElement(".o2_statement_viewNode");
  232. this.loadView();
  233. this.loadTab();
  234. this.setEvent();
  235. this.loadVerticalResize();
  236. }.bind(this));
  237. },
  238. loadJpqlTypeSelect : function(){
  239. this.jpqlTypeSelect.empty();
  240. var optionList = [{text:"SELECT", value:"select"}];
  241. if( this.data.entityCategory === "dynamic" || this.data.description.indexOf("update")>-1){
  242. optionList = optionList.concat([
  243. {text:"UPDATE", value:"update"},
  244. {text:"DELETE", value:"delete"}
  245. ])
  246. }
  247. var flag = true;
  248. optionList.each( function ( field ) {
  249. var option = new Element("option", {
  250. "text": field.text,
  251. "value": field.value
  252. }).inject(this.jpqlTypeSelect);
  253. if( this.json.type === field.value ){
  254. flag = false;
  255. option.selected = true;
  256. }
  257. }.bind(this));
  258. if( flag ){
  259. this.jpqlTypeSelect.options[0].selected = true;
  260. this.json.type = this.jpqlTypeSelect.options[0].value;
  261. this.jpqlTypeSelect.fireEvent("change");
  262. }
  263. },
  264. loadFieldSelect : function(){
  265. this.fieldSelect.empty();
  266. var d = this.data;
  267. var className = d.entityCategory === "dynamic" ? d.table : d.entityClassName;
  268. if( !className )return;
  269. o2.Actions.load("x_query_assemble_designer").QueryAction.getEntityProperties(
  270. className,
  271. d.entityCategory,
  272. function(json){
  273. var option = new Element("option", { "text": this.designer.lp.fileldSelectNote, "value": "" }).inject(this.fieldSelect);
  274. option.store("type", d.entityCategory);
  275. option.store("tableName", className );
  276. (json.data||[]).each( function ( field ) {
  277. var option = new Element("option", {
  278. "text": field.name + ( field.description ? ("-" + field.description) : "" ),
  279. "value": field.name
  280. }).inject(this.fieldSelect);
  281. option.store("field", field);
  282. option.store("type", d.entityCategory );
  283. option.store("tableName", className );
  284. }.bind(this))
  285. }.bind(this)
  286. )
  287. },
  288. loadVerticalResize: function(){
  289. this.verticalResize = new Drag(this.resizeNode, {
  290. "snap": 10,
  291. "onStart": function(el, e){
  292. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  293. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  294. el.store("position", {"x": x, "y": y});
  295. var size = this.designerArea.getSize(); //designerArea
  296. el.store("initialHeight", size.y);
  297. var allSize = this.areaNode.getSize();
  298. el.store("initialAllHeight", allSize.y);
  299. }.bind(this),
  300. "onDrag": function(el, e){
  301. var allHeight = el.retrieve("initialAllHeight").toFloat(); //this.areaNode.getSize();
  302. // var x = e.event.x;
  303. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  304. var position = el.retrieve("position");
  305. var dy = y.toFloat()-position.y.toFloat();
  306. var initialHeight = el.retrieve("initialHeight").toFloat();
  307. var height = initialHeight+dy;
  308. if (height < 180) height = 180;
  309. if (height > allHeight-180) height = allHeight-180;
  310. this.designerAreaPercent = height/allHeight;
  311. this.setVerticalResize();
  312. }.bind(this)
  313. });
  314. },
  315. setVerticalResize: function(){
  316. var size = this.areaNode.getSize();
  317. var height = size.y;
  318. var designAreaHeight = this.designerAreaPercent*height - 52;
  319. // var runAreaHeight = height-designAreaHeight;
  320. this.designerArea.setStyle("height", ""+designAreaHeight+"px");
  321. debugger;
  322. var editorHeight = designAreaHeight - 98;
  323. if(this.jpqlEditorNode)this.jpqlEditorNode.setStyle( "height", ""+editorHeight+"px" );
  324. if(this.countJpqlEditorNode)this.countJpqlEditorNode.setStyle( "height", ""+editorHeight+"px" );
  325. if(this.scriptArea)this.scriptArea.setStyle( "height", ""+editorHeight+"px" );
  326. if(this.countScriptArea)this.countScriptArea.setStyle( "height", ""+editorHeight+"px" );
  327. if( this.editor )this.editor.resize();
  328. if( this.countEditor )this.countEditor.resize();
  329. if( this.scriptEditor ){
  330. this.scriptEditor.container.setStyle("height", ""+editorHeight+"px");
  331. this.scriptEditor.resizeContentNodeSize();
  332. }
  333. if( this.countScriptEditor ){
  334. this.countScriptEditor.container.setStyle("height", ""+editorHeight+"px");
  335. this.countScriptEditor.resizeContentNodeSize();
  336. }
  337. // this.tabNode.setStyle("height", ""+runAreaHeight+"px");
  338. this.setRunnerSize();
  339. if( this.view ){
  340. this.setViewSize();
  341. this.view.setContentHeight()
  342. }
  343. },
  344. loadStatementScriptEditor: function () {
  345. if (!this.scriptEditor) {
  346. debugger;
  347. o2.require("o2.widget.ScriptArea", function () {
  348. this.scriptEditor = new o2.widget.ScriptArea(this.scriptArea, {
  349. "isbind": false,
  350. "maxObj": this.designer.designNode,
  351. "title": this.designer.lp.scriptTitle,
  352. "onChange": function () {
  353. this.json.scriptText = this.scriptEditor.toJson().code;
  354. }.bind(this)
  355. });
  356. this.scriptEditor.load({"code": this.json.scriptText})
  357. }.bind(this), false);
  358. }
  359. },
  360. loadStatementCountScriptEditor: function () {
  361. if (!this.countScriptEditor) {
  362. debugger;
  363. o2.require("o2.widget.ScriptArea", function () {
  364. this.countScriptEditor = new o2.widget.ScriptArea(this.countScriptArea, {
  365. "isbind": false,
  366. "maxObj": this.designer.designNode,
  367. "title": this.designer.lp.scriptTitle,
  368. "onChange": function () {
  369. this.json.countScriptText = this.countScriptEditor.toJson().code;
  370. }.bind(this)
  371. });
  372. this.countScriptEditor.load({"code": this.json.countScriptText})
  373. }.bind(this), false);
  374. }
  375. },
  376. setRunnerSize: function () {
  377. debugger;
  378. var size = this.areaNode.getSize();
  379. var designerSize = this.designerArea.getComputedSize();
  380. var reizeNodeSize = this.resizeNode.getComputedSize();
  381. var y = size.y - designerSize.totalHeight - reizeNodeSize.totalHeight;
  382. var mTop = this.runArea.getStyle("margin-top").toInt();
  383. var mBottom = this.runArea.getStyle("margin-bottom").toInt();
  384. var pTop = this.runArea.getStyle("padding-top").toInt();
  385. var pBottom = this.runArea.getStyle("padding-bottom").toInt();
  386. y = y - mTop - mBottom - pTop - pBottom - 5;
  387. var tabSize = this.tabNode.getComputedSize();
  388. y = y - tabSize.totalHeight;
  389. this.runArea.setStyle("height", "" + y + "px");
  390. // var titleSize = this.runTitleNode.getComputedSize();
  391. // y = y - titleSize.totalHeight;
  392. this.runContentNode.setStyle("height", "" + y + "px");
  393. },
  394. loadStatementEditor: function () {
  395. if (!this.editor) {
  396. var value;
  397. if( !this.json.data ){
  398. var table = "table";
  399. switch (this.json.type) {
  400. case "update":
  401. value = "UPDATE " + table + " o SET ";
  402. break;
  403. case "delete":
  404. value = "DELETE " + table + " o WHERE ";
  405. break;
  406. default:
  407. value = "SELECT o FROM " + table + " o";
  408. }
  409. this.json.data = value;
  410. }
  411. if( this.jpqlEditorNode.offsetParent === null && o2.editorData.javascriptEditor.editor === "monaco" ){
  412. var postShowFun = function() {
  413. this._loadStatementEditor();
  414. this.jpqlPage.removeEvent("postShow", postShowFun);
  415. }.bind(this);
  416. this.jpqlPage.addEvent("postShow", postShowFun);
  417. }else{
  418. this._loadStatementEditor();
  419. }
  420. }
  421. },
  422. _loadStatementEditor: function () {
  423. if (!this.editor) {
  424. o2.require("o2.widget.JavascriptEditor", function () {
  425. this.editor = new o2.widget.JavascriptEditor(this.jpqlEditorNode, {
  426. "title": "JPQL",
  427. "option": {"mode": "sql"}
  428. });
  429. this.editor.load(function () {
  430. // if (this.json.data) {
  431. this.editor.editor.setValue(this.json.data);
  432. // } else {
  433. // var table = "table";
  434. // switch (this.json.type) {
  435. // case "update":
  436. // this.editor.editor.setValue("UPDATE " + table + " o SET ");
  437. // break;
  438. // case "delete":
  439. // this.editor.editor.setValue("DELETE " + table + " o WHERE ");
  440. // break;
  441. // default:
  442. // this.editor.editor.setValue("SELECT o FROM " + table + " o");
  443. // }
  444. // }
  445. // this.json.data = this.editor.editor.getValue();
  446. this.editor.addEditorEvent("change", function () {
  447. debugger;
  448. this.data.data = this.editor.getValue();
  449. this.checkJpqlType();
  450. }.bind(this));
  451. // this.editor.editor.on("change", function(){
  452. // this.data.data = this.editor.getValue();
  453. // this.checkJpqlType();
  454. // }.bind(this));
  455. }.bind(this));
  456. }.bind(this), false);
  457. }
  458. },
  459. loadStatementCountEditor: function () {
  460. if (!this.countEditor) {
  461. if( !this.json.countData )this.json.countData = "SELECT count(o.id) FROM table o";
  462. if( this.countJpqlEditorNode.offsetParent === null && o2.editorData.javascriptEditor.editor === "monaco" ){
  463. var postShowFun = function() {
  464. this._loadStatementCountEditor();
  465. this.countJpqlPage.removeEvent("postShow", postShowFun);
  466. }.bind(this);
  467. this.countJpqlPage.addEvent("postShow", postShowFun);
  468. }else{
  469. this._loadStatementCountEditor();
  470. }
  471. }
  472. },
  473. _loadStatementCountEditor : function(){
  474. o2.require("o2.widget.JavascriptEditor", function () {
  475. this.countEditor = new o2.widget.JavascriptEditor(this.countJpqlEditorNode, {
  476. "title": "JPQL",
  477. "option": {"mode": "sql"}
  478. });
  479. this.countEditor.load(function () {
  480. // if (this.json.countData) {
  481. this.countEditor.editor.setValue(this.json.countData);
  482. // } else {
  483. // var table = "table";
  484. // this.countEditor.editor.setValue("SELECT count(o.id) FROM " + table + " o");
  485. // }
  486. // this.json.countData = this.countEditor.editor.getValue();
  487. this.countEditor.addEditorEvent("change", function () {
  488. this.data.countData = this.countEditor.getValue();
  489. }.bind(this));
  490. // this.editor.editor.on("change", function(){
  491. // this.data.data = this.editor.getValue();
  492. // this.checkJpqlType();
  493. // }.bind(this));
  494. }.bind(this));
  495. }.bind(this), false);
  496. },
  497. setSatementTable: function () {
  498. if (!this.json.type) this.json.type = "select";
  499. this.changeType(this.json.type, true);
  500. if( this.editor && this.editor.editor){
  501. if (this.json.data) {
  502. this.editor.editor.setValue(this.json.data);
  503. } else {
  504. var table = (this.json.tableObj) ? this.json.tableObj.name : "table";
  505. switch (this.json.type) {
  506. case "update":
  507. this.editor.editor.setValue("UPDATE " + table + " o SET ");
  508. break;
  509. case "delete":
  510. this.editor.editor.setValue("DELETE " + table + " o WHERE ");
  511. break;
  512. default:
  513. this.editor.editor.setValue("SELECT o FROM " + table + " o");
  514. }
  515. }
  516. }
  517. },
  518. checkJpqlType: function () {
  519. var str = this.json.data;
  520. this.json.data = str;
  521. var jpql_select = /^select/i;
  522. var jpql_update = /^update/i;
  523. var jpql_delete = /^delete/i;
  524. if (jpql_select.test(str)) return this.changeType("select");
  525. if (jpql_update.test(str)) return this.changeType("update");
  526. if (jpql_delete.test(str)) return this.changeType("delete");
  527. },
  528. changeType: function (type, force) {
  529. if (this.json.type != type) this.json.type = type;
  530. if (type != this.jpqlTypeSelect.options[this.jpqlTypeSelect.selectedIndex].value || force) {
  531. for (var i = 0; i < this.jpqlTypeSelect.options.length; i++) {
  532. if (this.jpqlTypeSelect.options[i].value == type) {
  533. this.jpqlTypeSelect.options[i].set("selected", true);
  534. break;
  535. }
  536. }
  537. }
  538. },
  539. loadStatementHtml: function (callback) {
  540. this.areaNode.loadAll({
  541. "css": this.path + this.options.style + "/statement.css",
  542. "html": this.path + "statementDesigner.html"
  543. }, {
  544. "bind": {"lp": this.designer.lp, "data": this.data}
  545. }, function () {
  546. if (callback) callback();
  547. }.bind(this));
  548. },
  549. loadStatementRunner: function () {
  550. o2.require("o2.widget.JavascriptEditor", function () {
  551. this.jsonEditor = new o2.widget.JavascriptEditor(this.runJsonNode, {
  552. "title": "JPQL",
  553. "option": {"mode": "json"}
  554. });
  555. this.jsonEditor.load(function () {
  556. this.jsonEditor.editor.setValue(this.data.testParameters || "{}");
  557. }.bind(this));
  558. }.bind(this), false);
  559. },
  560. setEvent: function () {
  561. this.designerArea.addEvent("click", function (e) {
  562. this.selected();
  563. e.stopPropagation();
  564. }.bind(this));
  565. this.formatTypeArea.getElements("input").addEvent("click", function (e) {
  566. if (e.target.checked) {
  567. var v = e.target.get("value");
  568. if (v === "script") {
  569. this.scriptArea.show();
  570. this.jpqlArea.hide();
  571. this.loadStatementScriptEditor();
  572. this.countScriptArea.show();
  573. this.countJpqlArea.hide();
  574. this.loadStatementCountScriptEditor();
  575. } else {
  576. this.scriptArea.hide();
  577. this.jpqlArea.show();
  578. this.loadStatementEditor();
  579. this.countScriptArea.hide();
  580. this.countJpqlArea.show();
  581. this.loadStatementCountEditor();
  582. }
  583. this.json.format = v;
  584. }
  585. }.bind(this));
  586. this.entityCategorySelect.addEvent("change", function (e) {
  587. var entityCategory = e.target.options[e.target.selectedIndex].value;
  588. switch (entityCategory) {
  589. case "dynamic":
  590. this.officialTableArea.hide();
  591. this.dynamicTableArea.show();
  592. this.customTableArea.hide();
  593. break;
  594. case "custom":
  595. this.officialTableArea.hide();
  596. this.dynamicTableArea.hide();
  597. this.customTableArea.show();
  598. break;
  599. default:
  600. this.officialTableArea.show();
  601. this.dynamicTableArea.hide();
  602. this.customTableArea.hide();
  603. break;
  604. }
  605. this.json.entityCategory = entityCategory;
  606. this.loadJpqlTypeSelect();
  607. this.loadFieldSelect();
  608. if(this.view && this.view.property && this.view.property.viewFilter)this.view.property.viewFilter.setPathInputSelectOptions();
  609. }.bind(this));
  610. //@todo change table
  611. this.officialTableSelect.addEvent("change", function (e) {
  612. debugger;
  613. var entityClassName = e.target.options[e.target.selectedIndex].value;
  614. this.json.entityClassName = entityClassName;
  615. if( entityClassName ){
  616. this.changeEditorEntityClassName( entityClassName.split(".").getLast() );
  617. }
  618. this.loadFieldSelect();
  619. this.json.table = "";
  620. this.json.tableObj = null;
  621. if(this.view && this.view.property && this.view.property.viewFilter)this.view.property.viewFilter.setPathInputSelectOptions();
  622. // var className = e.target.options[e.target.selectedIndex].value;
  623. // if (this.json.type=="select"){
  624. // this.json.data
  625. // /(select)*(where|)/g
  626. // }
  627. // }.bind(this));
  628. // this.jpqlTypeSelect.addEvent("change", function(){
  629. // var type = e.target.options[e.target.selectedIndex].value;
  630. // switch (entityCategory) {
  631. // case "update":
  632. // this.jpqlSelectEditor.hide();
  633. // this.jpqlUpdateEditor.show();
  634. // this.jpqlDeleteEditor.hide();
  635. // this.loadJpqlUpdateEditor();
  636. // break;
  637. // case "delete":
  638. // this.jpqlSelectEditor.hide();
  639. // this.jpqlUpdateEditor.hide();
  640. // this.jpqlDeleteEditor.show();
  641. // break;
  642. // default:
  643. // this.jpqlSelectEditor.show();
  644. // this.jpqlUpdateEditor.hide();
  645. // this.jpqlDeleteEditor.hide();
  646. // break;
  647. // }
  648. }.bind(this));
  649. this.runActionNode.getFirst().addEvent("click", this.runStatement.bind(this));
  650. this.dynamicTableSelect.addEvent("click", this.selectTable.bind(this));
  651. this.jpqlTypeSelect.addEvent("change", function () {
  652. var t = this.jpqlTypeSelect.options[this.jpqlTypeSelect.selectedIndex].value;
  653. if (t != this.json.type) {
  654. this.json.type = t;
  655. }
  656. if (t != "select") {
  657. this.jpqlPage.showTabIm();
  658. this.countJpqlPage.disableTab();
  659. this.runPage.showTabIm();
  660. this.viewPage.disableTab();
  661. } else {
  662. this.countJpqlPage.enableTab(true);
  663. this.viewPage.enableTab(true);
  664. }
  665. }.bind(this));
  666. this.fieldSelect.addEvent("change", function (ev) {
  667. var option = ev.target.options[ev.target.selectedIndex];
  668. var type = option.retrieve("type");
  669. var field = option.retrieve("field");
  670. if( !field )return;
  671. var text = field.name;
  672. if( this.countJpqlPage && this.countJpqlPage.isShow && !this.countJpqlPage.disabled ){
  673. if( this.data.format === "script" && this.countScriptEditor.jsEditor ){
  674. this.countScriptEditor.jsEditor.insertValue( text );
  675. }else if(this.countEditor){
  676. this.countEditor.insertValue( text );
  677. }
  678. }else{
  679. if( this.data.format === "script" && this.scriptEditor.jsEditor ){
  680. this.scriptEditor.jsEditor.insertValue( text );
  681. }else if( this.editor ){
  682. this.editor.insertValue( text );
  683. }
  684. }
  685. }.bind(this))
  686. },
  687. changeEditorEntityClassName : function( entityClassName ){
  688. if (this.json.format == "jpql") {
  689. if (this.editor) {
  690. var re = /(.*from\s*)/ig;
  691. if (this.json.type == "update") re = /(.*update\s*)/ig;
  692. //if (this.json.type=="select" && this.editor){
  693. var v = this.json.data;
  694. var re2 = /(\s+)/ig;
  695. var arr = re.exec(v);
  696. if (arr && arr[0]) {
  697. var left = arr[0]
  698. v = v.substring(left.length, v.length);
  699. //var ar = re2.exec(v);
  700. var right = v.substring(v.indexOf(" "), v.length);
  701. this.json.data = left + entityClassName + right;
  702. this.editor.editor.setValue(this.json.data);
  703. }
  704. //}
  705. }
  706. if( this.countEditor ){
  707. var re = /(.*from\s*)/ig;
  708. var v = this.json.countData;
  709. var re2 = /(\s+)/ig;
  710. var arr = re.exec(v);
  711. if (arr && arr[0]) {
  712. var left = arr[0]
  713. v = v.substring(left.length, v.length);
  714. //var ar = re2.exec(v);
  715. var right = v.substring(v.indexOf(" "), v.length);
  716. this.json.countData = left + entityClassName + right;
  717. this.countEditor.editor.setValue(this.json.countData);
  718. }
  719. }
  720. }
  721. },
  722. selectTable: function () {
  723. new MWF.O2Selector(this.designer.content, {
  724. "type": "queryTable",
  725. "count": 1,
  726. "values": (this.json.table) ? [this.json.table] : [],
  727. "title": this.designer.lp.selectTable,
  728. "onComplete": function (items) {
  729. if (items.length) {
  730. var id = items[0].data.id;
  731. var name = items[0].data.name;
  732. this.dynamicTableContent.set("text", name);
  733. this.json.table = name;
  734. this.json.tableObj = items[0].data;
  735. this.officialTableSelect.options[0].set("selected", true);
  736. this.json.entityClassName = "";
  737. this.changeEditorEntityClassName( name );
  738. this.loadFieldSelect();
  739. if(this.view && this.view.property && this.view.property.viewFilter)this.view.property.viewFilter.setPathInputSelectOptions();
  740. } else {
  741. this.dynamicTableContent.set("text", "");
  742. this.json.table = "";
  743. this.loadFieldSelect();
  744. if(this.view && this.view.property && this.view.property.viewFilter)this.view.property.viewFilter.setPathInputSelectOptions();
  745. }
  746. }.bind(this)
  747. });
  748. },
  749. runStatement: function () {
  750. debugger;
  751. // if (!this.json.data){
  752. // this.designer.notice(this.designer.lp.inputStatementData, "error");
  753. // return false;
  754. // }
  755. // o2.require("o2.widget.Mask", null, false);
  756. // this.runMask = new o2.widget.Mask();
  757. // this.runMask.loadNode(this.node);
  758. this.saveSilence(function () {
  759. debugger;
  760. this.execute(function (json) {
  761. this.executeData = json;
  762. o2.require("o2.widget.JsonParse", function () {
  763. this.runResultNode.empty();
  764. var jsonResult = new o2.widget.JsonParse(json, this.runResultNode);
  765. jsonResult.load();
  766. }.bind(this));
  767. if (this.view) {
  768. var flag = true;
  769. if (this.data.type !== "select") flag = false;
  770. if (this.data.format === "script" && !this.data.scriptText) flag = false;
  771. if (this.data.format !== "script" && !this.data.data) flag = false;
  772. if (flag) this.view.loadViewData();
  773. }
  774. this.setColumnDataPath(json);
  775. // this.runMask.hide();
  776. }.bind(this), function () {
  777. // if (this.runMask) this.runMask.hide();
  778. }.bind(this))
  779. // var json = this.jsonEditor.editor.getValue();
  780. // var o = JSON.parse(json);
  781. //
  782. // var mode = "data";
  783. // if( this.data.type === "select" ){
  784. // if( this.data.format === "script" ){
  785. // if( this.data.scriptText && this.data.countScriptText ){
  786. // mode = "all"
  787. // }else if( this.data.scriptText && !this.data.countScriptText ){
  788. // mode = "data"
  789. // }else if( !this.data.scriptText && this.data.countScriptText ){
  790. // mode = "count"
  791. // }else{
  792. // this.designer.notice(this.designer.lp.inputStatementData, "error");
  793. // return false;
  794. // }
  795. // }else{
  796. // if( this.data.data && this.data.countData ){
  797. // mode = "all"
  798. // }else if( this.data.data && !this.data.countData ){
  799. // mode = "data"
  800. // }else if( !this.data.data && this.data.countData ){
  801. // mode = "count"
  802. // }else{
  803. // this.designer.notice(this.designer.lp.inputStatementData, "error");
  804. // return false;
  805. // }
  806. // }
  807. // }
  808. // o2.Actions.load("x_query_assemble_designer").StatementAction.executeV2(this.json.id, mode, 1, 50 , o, function(json){
  809. // o2.require("o2.widget.JsonParse", function(){
  810. // this.runResultNode.empty();
  811. // var jsonResult = new o2.widget.JsonParse(json, this.runResultNode);
  812. // jsonResult.load();
  813. // }.bind(this));
  814. // this.runMask.hide();
  815. // }.bind(this), function(xhr, text, error){
  816. // debugger;
  817. // if (this.runMask) this.runMask.hide();
  818. // var errorText = error;
  819. // if (xhr){
  820. // var json = JSON.decode(xhr.responseText);
  821. // if (json){
  822. // errorText = json.message.trim() || "request json error";
  823. // }else{
  824. // errorText = "request json error: "+xhr.responseText;
  825. // }
  826. // }
  827. // errorText = errorText.replace(/\</g, "&lt;");
  828. // errorText = errorText.replace(/\</g, "&gt;");
  829. // MWF.xDesktop.notice("error", {x: "right", y:"top"}, errorText);
  830. // }.bind(this))
  831. }.bind(this));
  832. },
  833. setColumnDataPath: function (json) {
  834. if (this.data.type !== "select") return;
  835. if (this.data.format === "script" && !this.data.scriptText) return;
  836. if (this.data.format !== "script" && !this.data.data) return;
  837. this.columnDataPathList = [];
  838. debugger;
  839. var addPath = function (value, key) {
  840. if (typeOf(value) === "array") {
  841. Array.each(value, function (v, idx) {
  842. var path = (key || typeOf(key) === "number") ? (key + "." + idx) : idx.toString();
  843. if (!this.columnDataPathList.contains(path)) this.columnDataPathList.push(path);
  844. if (typeOf(v) === "array" || typeOf(v) === "object") addPath(v, path);
  845. }.bind(this))
  846. } else if (typeOf(value) === "object") {
  847. Object.each(value, function (v, k) {
  848. var path = (key || typeOf(key) === "number") ? (key + "." + k) : k;
  849. if (!this.columnDataPathList.contains(path)) this.columnDataPathList.push(path);
  850. if (typeOf(v) === "array" || typeOf(v) === "object") addPath(v, path);
  851. addPath(v, path);
  852. }.bind(this))
  853. } else {
  854. // if( key && !this.columnDataPathList.indexOf(key) )this.columnDataPathList.push(key);
  855. }
  856. }.bind(this);
  857. for (var i = 0; i < json.data.length && i < 10; i++) {
  858. var d = json.data[i];
  859. addPath(d);
  860. }
  861. this.columnDataPathList.sort();
  862. if (this.view && this.view.items) {
  863. this.view.items.each(function (column) {
  864. column.refreshColumnPathData()
  865. })
  866. }
  867. },
  868. getColumnDataPath: function () {
  869. return this.columnDataPathList || [];
  870. },
  871. execute: function (success, failure) {
  872. var json = this.jsonEditor.editor.getValue();
  873. var o = JSON.parse(json);
  874. var mode = "data";
  875. if (this.data.type === "select") {
  876. if (this.data.format === "script") {
  877. if (this.data.scriptText && this.data.countScriptText) {
  878. mode = "all"
  879. } else if (this.data.scriptText && !this.data.countScriptText) {
  880. mode = "data"
  881. } else if (!this.data.scriptText && this.data.countScriptText) {
  882. mode = "count"
  883. } else {
  884. this.designer.notice(this.designer.lp.inputStatementData, "error");
  885. return false;
  886. }
  887. } else {
  888. if (this.data.data && this.data.countData) {
  889. mode = "all"
  890. } else if (this.data.data && !this.data.countData) {
  891. mode = "data"
  892. } else if (!this.data.data && this.data.countData) {
  893. mode = "count"
  894. } else {
  895. this.designer.notice(this.designer.lp.inputStatementData, "error");
  896. return false;
  897. }
  898. }
  899. }
  900. o2.Actions.load("x_query_assemble_designer").StatementAction.executeV2(this.json.id, mode, 1, 50, o, function (json) {
  901. if (success) success(json)
  902. }.bind(this), function (xhr, text, error) {
  903. debugger;
  904. if (failure) failure();
  905. var errorText = error;
  906. if (xhr) {
  907. var json = JSON.decode(xhr.responseText);
  908. if (json) {
  909. errorText = json.message.trim() || "request json error";
  910. } else {
  911. errorText = "request json error: " + xhr.responseText;
  912. }
  913. }
  914. errorText = errorText.replace(/\</g, "&lt;");
  915. errorText = errorText.replace(/\</g, "&gt;");
  916. MWF.xDesktop.notice("error", {x: "right", y: "top"}, errorText);
  917. }.bind(this))
  918. },
  919. save: function (callback) {
  920. debugger;
  921. if (!this.data.name) {
  922. this.designer.notice(this.designer.lp.inputStatementName, "error");
  923. return false;
  924. }
  925. if (typeOf(this.viewJson) === "object") {
  926. if(this.viewJson.data && !this.viewJson.data.group)this.viewJson.data.group = {};
  927. if(!this.viewJson.pageSize)this.viewJson.pageSize = "20";
  928. this.data.view = JSON.stringify(this.viewJson);
  929. }
  930. //if( !this.data.tableType ){
  931. // this.data.tableType = "dynamic";
  932. //}
  933. if (this.editor) this.data.data = this.editor.editor.getValue();
  934. if (this.scriptEditor) this.data.scriptText = this.scriptEditor.toJson().code;
  935. if (this.jsonEditor) this.data.testParameters = this.jsonEditor.editor.getValue();
  936. this.designer.actions.saveStatement(this.data, function (json) {
  937. this.designer.notice(this.designer.lp.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  938. this.data.id = json.data.id;
  939. if (this.lisNode) {
  940. this.lisNode.getLast().set("text", this.data.name + "(" + this.data.alias + ")");
  941. }
  942. if (callback) callback();
  943. }.bind(this));
  944. },
  945. _setEditStyle: function () {
  946. },
  947. saveSilence: function (callback) {
  948. if (!this.data.name) {
  949. this.designer.notice(this.designer.lp.inputStatementName, "error");
  950. return false;
  951. }
  952. if (typeOf(this.viewJson) === "object") {
  953. if(this.viewJson.data && !this.viewJson.data.group)this.viewJson.data.group = {};
  954. if( !this.viewJson.pageSize )this.viewJson.pageSize = "20";
  955. this.data.view = JSON.stringify(this.viewJson);
  956. }
  957. if (this.editor) this.data.data = this.editor.editor.getValue();
  958. if (this.scriptEditor) this.data.scriptText = this.scriptEditor.toJson().code;
  959. if (this.jsonEditor) this.data.testParameters = this.jsonEditor.editor.getValue();
  960. this.designer.actions.saveStatement(this.data, function (json) {
  961. //this.designer.notice(this.designer.lp.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  962. this.data.id = json.data.id;
  963. if (this.lisNode) {
  964. this.lisNode.getLast().set("text", this.data.name + "(" + this.data.alias + ")");
  965. }
  966. if (callback) callback();
  967. }.bind(this));
  968. },
  969. loadView: function (callback) {
  970. this.setViewSize();
  971. this.designer.addEvent("resize", this.setViewSize.bind(this));
  972. if (!this.data.view) {
  973. this.viewJson = {};
  974. } else {
  975. this.viewJson = JSON.parse(this.data.view)
  976. }
  977. this.view = new MWF.xApplication.query.StatementDesigner.View(this.designer, this, this.viewJson, {});
  978. this.view.load(function () {
  979. this.view.setContentHeight();
  980. }.bind(this));
  981. },
  982. setViewSize: function () {
  983. debugger;
  984. var size = this.areaNode.getSize();
  985. var designerSize = this.designerArea.getComputedSize();
  986. var reizeNodeSize = this.resizeNode.getComputedSize();
  987. var y = size.y - designerSize.totalHeight - reizeNodeSize.totalHeight;
  988. var mTop = this.viewArea.getStyle("margin-top").toInt();
  989. var mBottom = this.viewArea.getStyle("margin-bottom").toInt();
  990. var pTop = this.viewArea.getStyle("padding-top").toInt();
  991. var pBottom = this.viewArea.getStyle("padding-bottom").toInt();
  992. y = y - mTop - mBottom - pTop - pBottom - 1;
  993. var tabSize = this.tabNode.getComputedSize();
  994. y = y - tabSize.totalHeight;
  995. this.viewArea.setStyle("height", "" + y + "px");
  996. // var titleSize = this.runTitleNode.getComputedSize();
  997. // y = y - titleSize.totalHeight;
  998. // this.runContentNode.setStyle("height", ""+y+"px");
  999. },
  1000. preview: function () {
  1001. if (this.isNewStatement) {
  1002. this.designer.notice(this.designer.lp.saveStatementNotice, "error");
  1003. return;
  1004. }
  1005. if (this.data.type !== "select") {
  1006. this.designer.notice(this.designer.lp.previewNotSelectStatementNotice, "error");
  1007. return;
  1008. }
  1009. if (!this.data.view) {
  1010. this.designer.notice(this.designer.lp.noViewNotice, "error");
  1011. }
  1012. this.saveSilence(function () {
  1013. var url = "../x_desktop/app.html?app=query.Query&status=";
  1014. url += JSON.stringify({
  1015. id: this.data.application,
  1016. statementId: this.data.id
  1017. });
  1018. window.open(o2.filterUrl(url), "_blank");
  1019. }.bind(this));
  1020. }
  1021. });
  1022. MWF.xApplication.query.StatementDesigner.View = new Class({
  1023. Extends: MWF.xApplication.query.ViewDesigner.View,
  1024. Implements: [Options, Events],
  1025. options: {
  1026. "style": "default",
  1027. "isView": false,
  1028. "showTab": true,
  1029. "propertyPath": "../x_component_query_StatementDesigner/$Statement/view.html"
  1030. },
  1031. initialize: function (designer, statement, data, options) {
  1032. this.setOptions(options);
  1033. this.path = "../x_component_query_ViewDesigner/$View/";
  1034. this.cssPath = "../x_component_query_ViewDesigner/$View/" + this.options.style + "/css.wcss";
  1035. this._loadCss();
  1036. this.statement = statement;
  1037. this.designer = designer;
  1038. this.data = data;
  1039. // if (!this.data.data) this.data.data = {};
  1040. this.parseData();
  1041. this.node = this.statement.viewArea;
  1042. //this.tab = this.designer.tab;
  1043. this.areaNode = new Element("div", {"styles": {"height": "calc(100% - 2px)", "overflow": "auto"}});
  1044. this.areaNode.setStyles(this.css.areaNode);
  1045. //MWF.require("MWF.widget.ScrollBar", function(){
  1046. // new MWF.widget.ScrollBar(this.areaNode, {"distance": 100});
  1047. //}.bind(this));
  1048. // this.propertyListNode = this.designer.propertyDomArea;
  1049. //this.propertyNode = this.designer.propertyContentArea;
  1050. // if(this.designer.application) this.data.applicationName = this.designer.application.name;
  1051. // if(this.designer.application) this.data.application = this.designer.application.id;
  1052. // this.isNewView = (this.data.name) ? false : true;
  1053. this.items = [];
  1054. this.view = this;
  1055. // this.autoSave();
  1056. // this.designer.addEvent("queryClose", function(){
  1057. // if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  1058. // }.bind(this));
  1059. },
  1060. load: function (callback) {
  1061. this.setAreaNodeSize();
  1062. this.designer.addEvent("resize", this.setAreaNodeSize.bind(this));
  1063. this.areaNode.inject(this.node);
  1064. this.domListNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.designer.propertyDomArea);
  1065. this.loadTemplateStyle(function () {
  1066. this.loadActionbar();
  1067. this.loadView();
  1068. this.loadPaging();
  1069. // this.selected();
  1070. this.setEvent();
  1071. //if (this.options.showTab) this.page.showTabIm();
  1072. this.setViewWidth();
  1073. this.designer.addEvent("resize", this.setViewWidth.bind(this));
  1074. if (callback) callback();
  1075. }.bind(this))
  1076. },
  1077. parseData: function () {
  1078. this.json = this.data;
  1079. if (!this.json.id) {
  1080. this.json.id = (new o2.widget.UUID).id;
  1081. }
  1082. if (!this.json.data || !this.json.data.events) {
  1083. var url = "../x_component_query_StatementDesigner/$Statement/view.json";
  1084. MWF.getJSON(url, {
  1085. "onSuccess": function (obj) {
  1086. if (!this.json.data) this.json.data = obj.data;
  1087. if (!this.json.data.events) this.json.data.events = obj.data.events;
  1088. }.bind(this),
  1089. "onerror": function (text) {
  1090. this.notice(text, "error");
  1091. }.bind(this),
  1092. "onRequestFailure": function (xhr) {
  1093. this.notice(xhr.responseText, "error");
  1094. }.bind(this)
  1095. }, false);
  1096. }
  1097. },
  1098. setEvent: function () {
  1099. this.areaNode.addEvents({
  1100. "click": function (e) {
  1101. this.selected();
  1102. e.stopPropagation();
  1103. }.bind(this),
  1104. "mouseover": function () {
  1105. if (!this.isSelected) this.areaNode.setStyles(this.css.areaNode_over)
  1106. }.bind(this),
  1107. "mouseout": function () {
  1108. if (!this.isSelected) this.areaNode.setStyles(this.css.areaNode)
  1109. }.bind(this)
  1110. });
  1111. this.refreshNode.addEvent("click", function (e) {
  1112. this.statement.runStatement();
  1113. e.stopPropagation();
  1114. }.bind(this));
  1115. this.addColumnNode.addEvent("click", function (e) {
  1116. this.addColumn();
  1117. e.stopPropagation();
  1118. }.bind(this));
  1119. },
  1120. selected: function () {
  1121. debugger;
  1122. if (this.statement.currentSelectedModule) {
  1123. if (this.statement.currentSelectedModule == this) {
  1124. return true;
  1125. } else {
  1126. this.statement.currentSelectedModule.unSelected();
  1127. }
  1128. }
  1129. this.areaNode.setStyles(this.css.areaNode_selected);
  1130. this.statement.currentSelectedModule = this;
  1131. this.domListNode.show();
  1132. this.isSelected = true;
  1133. this.showProperty();
  1134. },
  1135. unSelected: function () {
  1136. this.statement.currentSelectedModule = null;
  1137. this.isSelected = false;
  1138. this.areaNode.setStyles(this.css.areaNode);
  1139. this.hideProperty();
  1140. },
  1141. showProperty: function () {
  1142. if (!this.property) {
  1143. this.property = new MWF.xApplication.query.StatementDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
  1144. "path": this.options.propertyPath,
  1145. "onPostLoad": function () {
  1146. this.property.show();
  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. loadViewData: function () {
  1158. debugger;
  1159. if (this.data.id) {
  1160. // this.statement.saveSilence(function () {
  1161. this.viewContentBodyNode.empty();
  1162. this.viewContentTableNode = new Element("table", {
  1163. "styles": this.css.viewContentTableNode,
  1164. "border": "0px",
  1165. "cellPadding": "0",
  1166. "cellSpacing": "0"
  1167. }).inject(this.viewContentBodyNode);
  1168. // this.statement.execute( function (json) {
  1169. // this.statement.setColumnDataPath( json );
  1170. var entries = {};
  1171. this.json.data.selectList.each(function (entry) {
  1172. entries[entry.column] = entry;
  1173. }.bind(this));
  1174. if (this.statement.executeData && this.statement.executeData.data && this.statement.executeData.data.length) {
  1175. this.statement.executeData.data.each(function (line, idx) {
  1176. var tr = new Element("tr", {
  1177. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTr"] : this.css.viewContentTrNode
  1178. }).inject(this.viewContentTableNode);
  1179. //this.createViewCheckboxTd( tr );
  1180. Object.each(entries, function (c, k) {
  1181. debugger;
  1182. var path = c.path, code = c.code, obj = line;
  1183. if( path ){
  1184. var pathList = path.split(".");
  1185. for( var i=0; i<pathList.length; i++ ){
  1186. var p = pathList[i];
  1187. if( (/(^[1-9]\d*$)/.test(p)) )p = p.toInt();
  1188. if( obj[ p ] ){
  1189. obj = obj[ p ];
  1190. }else{
  1191. obj = "";
  1192. break;
  1193. }
  1194. }
  1195. }
  1196. if( code && code.trim())obj = MWF.Macro.exec( code, { "target" : {"value": obj, "data": line, "entry": c} });
  1197. var toName = function (value) {
  1198. if(typeOf(value) === "array"){
  1199. Array.each( value, function (v, idx) {
  1200. value[idx] = toName(v)
  1201. })
  1202. }else if( typeOf(value) === "object" ){
  1203. Object.each( value, function (v, key) {
  1204. value[key] = toName(v);
  1205. })
  1206. }else if( typeOf( value ) === "string" ){
  1207. value = o2.name.cn( value )
  1208. }
  1209. return value;
  1210. };
  1211. var d;
  1212. if( obj!= undefined && obj!= null ){
  1213. if( typeOf(obj) === "array" ) {
  1214. d = c.isName ? JSON.stringify(toName(Array.clone(obj))) : JSON.stringify(obj);
  1215. }else if( typeOf(obj) === "object" ){
  1216. d = c.isName ? JSON.stringify(toName(Object.clone(obj))) : JSON.stringify(obj);
  1217. }else{
  1218. d = c.isName ? o2.name.cn( obj.toString() ) : obj;
  1219. }
  1220. }
  1221. if (d != undefined && d != null ) {
  1222. var td = new Element("td", {
  1223. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTd"] : this.css.viewContentTdNode
  1224. }).inject(tr);
  1225. if (c.isHtml) {
  1226. td.set("html", d);
  1227. } else {
  1228. td.set("text", d);
  1229. }
  1230. }
  1231. }.bind(this));
  1232. }.bind(this));
  1233. this.setContentColumnWidth();
  1234. this.setContentHeight();
  1235. } else if (this.json.data.noDataText) {
  1236. var noDataTextNodeStyle = this.css.noDataTextNode;
  1237. if (this.json.data.viewStyles) {
  1238. if (this.json.data.viewStyles["noDataTextNode"]) {
  1239. noDataTextNodeStyle = this.json.data.viewStyles["noDataTextNode"]
  1240. } else {
  1241. this.json.data.viewStyles["noDataTextNode"] = this.css.noDataTextNode
  1242. }
  1243. }
  1244. this.noDataTextNode = new Element("div", {
  1245. "styles": noDataTextNodeStyle,
  1246. "text": this.json.data.noDataText
  1247. }).inject(this.viewContentBodyNode);
  1248. }
  1249. // }.bind(this));
  1250. // }.bind(this));
  1251. }
  1252. },
  1253. addColumn: function () {
  1254. debugger;
  1255. MWF.require("MWF.widget.UUID", function () {
  1256. var id = (new MWF.widget.UUID).id;
  1257. var json = {
  1258. "id": id,
  1259. "column": id,
  1260. "displayName": this.designer.lp.unnamed,
  1261. "orderType": "original"
  1262. };
  1263. if (!this.json.data.selectList) this.json.data.selectList = [];
  1264. this.json.data.selectList.push(json);
  1265. var column = new MWF.xApplication.query.StatementDesigner.View.Column(json, this);
  1266. this.items.push(column);
  1267. column.selected();
  1268. if (this.viewContentTableNode) {
  1269. var trs = this.viewContentTableNode.getElements("tr");
  1270. trs.each(function (tr) {
  1271. new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr)
  1272. }.bind(this));
  1273. //this.setContentColumnWidth();
  1274. }
  1275. this.setViewWidth();
  1276. this.addColumnNode.scrollIntoView(true);
  1277. }.bind(this));
  1278. //new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 0}).toRight();
  1279. },
  1280. setContentHeight: function () {
  1281. var size = this.areaNode.getSize();
  1282. var titleSize = this.viewTitleNode.getSize();
  1283. var actionbarSize = this.actionbarNode ? this.actionbarNode.getSize() : {x: 0, y: 0};
  1284. var pagingSize = this.pagingNode ? this.pagingNode.getSize() : {x: 0, y: 0};
  1285. var height = size.y - titleSize.y - actionbarSize.y - pagingSize.y - 4;
  1286. this.viewContentScrollNode.setStyle("height", height);
  1287. var contentSize = this.viewContentBodyNode.getSize();
  1288. if (height < contentSize.y) height = contentSize.y + 10;
  1289. this.viewContentNode.setStyle("height", height);
  1290. this.contentLeftNode.setStyle("height", height);
  1291. this.contentRightNode.setStyle("height", height);
  1292. //this.viewContentBodyNode.setStyle("min-height", height);
  1293. },
  1294. loadViewColumns: function () {
  1295. // for (var i=0; i<10; i++){
  1296. if (this.json.data.selectList) {
  1297. this.json.data.selectList.each(function (json) {
  1298. this.items.push(new MWF.xApplication.query.StatementDesigner.View.Column(json, this));
  1299. }.bind(this));
  1300. }
  1301. // }
  1302. },
  1303. showActionbar: function (noSetHeight) {
  1304. this.actionbarNode.show();
  1305. if (!this.json.data.actionbarList) this.json.data.actionbarList = [];
  1306. if (!this.actionbarList || this.actionbarList.length == 0) {
  1307. if (this.json.data.actionbarList.length) {
  1308. this.json.data.actionbarList.each(function (json) {
  1309. this.actionbarList.push(new MWF.xApplication.query.StatementDesigner.View.Actionbar(json, this.json.data.actionbarList, this))
  1310. }.bind(this));
  1311. } else {
  1312. this.actionbarList.push(new MWF.xApplication.query.StatementDesigner.View.Actionbar(null, this.json.data.actionbarList, this))
  1313. }
  1314. }
  1315. if (!noSetHeight) this.setContentHeight();
  1316. },
  1317. loadPaging: function (noSetHeight) {
  1318. this.pagingNode = new Element("div#pagingNode", {"styles": this.css.pagingNode}).inject(this.areaNode);
  1319. this.pagingList = [];
  1320. if (!this.json.data.pagingList) this.json.data.pagingList = [];
  1321. if (!this.pagingList || this.pagingList.length == 0) {
  1322. if (this.json.data.pagingList.length) {
  1323. this.json.data.pagingList.each(function (json) {
  1324. this.pagingList.push(new MWF.xApplication.query.StatementDesigner.View.Paging(json, this.json.data.pagingList, this))
  1325. }.bind(this));
  1326. } else {
  1327. this.pagingList.push(new MWF.xApplication.query.StatementDesigner.View.Paging(null, this.json.data.pagingList, this))
  1328. }
  1329. }
  1330. // if( !noSetHeight )this.setContentHeight();
  1331. },
  1332. setViewWidth: function () {
  1333. if (!this.viewAreaNode) return;
  1334. this.viewAreaNode.setStyle("width", "auto");
  1335. this.viewTitleNode.setStyle("width", "auto");
  1336. var s1 = this.viewTitleTableNode.getSize();
  1337. var s2 = this.refreshNode.getSize();
  1338. var s3 = this.addColumnNode.getSize();
  1339. var width = s1.x + s2.x + s2.x;
  1340. var size = this.areaNode.getSize();
  1341. if (width > size.x) {
  1342. this.viewTitleNode.setStyle("width", "" + (width - 2) + "px");
  1343. this.viewAreaNode.setStyle("width", "" + (width - 2) + "px");
  1344. } else {
  1345. this.viewTitleNode.setStyle("width", "" + (size.x - 2) + "px");
  1346. this.viewAreaNode.setStyle("width", "" + (size.x - 2) + "px");
  1347. }
  1348. this.setContentColumnWidth();
  1349. this.setContentHeight();
  1350. },
  1351. _setEditStyle: function (name, input, oldValue) {
  1352. if (name == "data.actionbarHidden") {
  1353. if (this.json.data.actionbarHidden) {
  1354. this.hideActionbar()
  1355. } else {
  1356. this.showActionbar()
  1357. }
  1358. }
  1359. if (name == "data.selectAllEnable") {
  1360. if (this.json.data.selectAllEnable) {
  1361. this.viewTitleTrNode.getElement(".viewTitleCheckboxTd").setStyle("display", "table-cell");
  1362. this.viewContentTableNode.getElements(".viewContentCheckboxTd").setStyle("display", "table-cell");
  1363. } else {
  1364. this.viewTitleTrNode.getElement(".viewTitleCheckboxTd").setStyle("display", "none");
  1365. this.viewContentTableNode.getElements(".viewContentCheckboxTd").setStyle("display", "none");
  1366. }
  1367. }
  1368. if (name == "data.viewStyleType") {
  1369. var file = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType].file : null;
  1370. var extendFile = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType].extendFile : null;
  1371. this.loadTemplateStyles(file, extendFile, function (templateStyles) {
  1372. this.templateStyles = templateStyles;
  1373. var oldFile, oldExtendFile;
  1374. if (oldValue && this.stylesList[oldValue]) {
  1375. oldFile = this.stylesList[oldValue].file;
  1376. oldExtendFile = this.stylesList[oldValue].extendFile;
  1377. }
  1378. this.loadTemplateStyles(oldFile, oldExtendFile, function (oldTemplateStyles) {
  1379. this.json.data.styleConfig = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType] : null;
  1380. if (oldTemplateStyles["view"]) this.clearTemplateStyles(oldTemplateStyles["view"]);
  1381. if (this.templateStyles["view"]) this.setTemplateStyles(this.templateStyles["view"]);
  1382. this.setAllStyles();
  1383. this.actionbarList.each(function (module) {
  1384. if (oldTemplateStyles["actionbar"]) {
  1385. module.clearTemplateStyles(oldTemplateStyles["actionbar"]);
  1386. }
  1387. module.setStyleTemplate();
  1388. module.setAllStyles();
  1389. })
  1390. this.pagingList.each(function (module) {
  1391. if (oldTemplateStyles["paging"]) {
  1392. module.clearTemplateStyles(oldTemplateStyles["paging"]);
  1393. }
  1394. module.setStyleTemplate();
  1395. module.setAllStyles();
  1396. });
  1397. // this.moduleList.each(function(module){
  1398. // if (oldTemplateStyles[module.moduleName]){
  1399. // module.clearTemplateStyles(oldTemplateStyles[module.moduleName]);
  1400. // }
  1401. // module.setStyleTemplate();
  1402. // module.setAllStyles();
  1403. // }.bind(this));
  1404. }.bind(this))
  1405. }.bind(this))
  1406. }
  1407. if (name == "data.viewStyles") {
  1408. this.setCustomStyles();
  1409. }
  1410. },
  1411. loadTemplateStyle: function (callback) {
  1412. this.loadStylesList(function () {
  1413. var oldStyleValue = "";
  1414. if ((!this.json.data.viewStyleType) || !this.stylesList[this.json.data.viewStyleType]) this.json.data.viewStyleType = "default";
  1415. this.loadTemplateStyles(this.stylesList[this.json.data.viewStyleType].file, this.stylesList[this.json.data.viewStyleType].extendFile,
  1416. function (templateStyles) {
  1417. this.templateStyles = templateStyles;
  1418. if (!this.json.data.viewStyleType) this.json.data.viewStyleType = "default";
  1419. if (this.templateStyles && this.templateStyles["view"]) {
  1420. var viewStyles = Object.clone(this.templateStyles["view"]);
  1421. if (viewStyles.contentGroupTd) delete viewStyles.contentGroupTd;
  1422. if (viewStyles.groupCollapseNode) delete viewStyles.groupCollapseNode;
  1423. if (viewStyles.groupExpandNode) delete viewStyles.groupExpandNode;
  1424. if (!this.json.data.viewStyles) {
  1425. this.json.data.viewStyles = viewStyles;
  1426. } else {
  1427. this.setTemplateStyles(viewStyles);
  1428. }
  1429. }
  1430. this.setCustomStyles();
  1431. if (callback) callback();
  1432. }.bind(this)
  1433. );
  1434. }.bind(this));
  1435. },
  1436. clearTemplateStyles: function (styles) {
  1437. if (styles) {
  1438. if (styles.container) this.removeStyles(styles.container, "container");
  1439. if (styles.table) this.removeStyles(styles.table, "table");
  1440. if (styles.titleTr) this.removeStyles(styles.titleTr, "titleTr");
  1441. if (styles.titleTd) this.removeStyles(styles.titleTd, "titleTd");
  1442. if (styles.contentTr) this.removeStyles(styles.contentTr, "contentTr");
  1443. if (styles.contentSelectedTr) this.removeStyles(styles.contentSelectedTr, "contentSelectedTr");
  1444. if (styles.contentTd) this.removeStyles(styles.contentTd, "contentTd");
  1445. // if (styles.contentGroupTd) this.removeStyles(styles.contentGroupTd, "contentGroupTd");
  1446. // if (styles.groupCollapseNode) this.removeStyles(styles.groupCollapseNode, "groupCollapseNode");
  1447. // if (styles.groupExpandNode) this.removeStyles(styles.groupExpandNode, "groupExpandNode");
  1448. if (styles.checkboxNode) this.removeStyles(styles.checkboxNode, "checkboxNode");
  1449. if (styles.checkedCheckboxNode) this.removeStyles(styles.checkedCheckboxNode, "checkedCheckboxNode");
  1450. if (styles.radioNode) this.removeStyles(styles.radioNode, "radioNode");
  1451. if (styles.checkedRadioNode) this.removeStyles(styles.checkedRadioNode, "checkedRadioNode");
  1452. if (styles.tableProperties) this.removeStyles(styles.tableProperties, "tableProperties");
  1453. }
  1454. },
  1455. setTemplateStyles: function (styles) {
  1456. if (styles.container) this.copyStyles(styles.container, "container");
  1457. if (styles.table) this.copyStyles(styles.table, "table");
  1458. if (styles.titleTr) this.copyStyles(styles.titleTr, "titleTr");
  1459. if (styles.titleTd) this.copyStyles(styles.titleTd, "titleTd");
  1460. if (styles.contentTr) this.copyStyles(styles.contentTr, "contentTr");
  1461. if (styles.contentSelectedTr) this.copyStyles(styles.contentSelectedTr, "contentSelectedTr");
  1462. if (styles.contentTd) this.copyStyles(styles.contentTd, "contentTd");
  1463. // if (styles.contentGroupTd) this.copyStyles(styles.contentGroupTd, "contentGroupTd");
  1464. // if (styles.groupCollapseNode) this.copyStyles(styles.groupCollapseNode, "groupCollapseNode");
  1465. // if (styles.groupExpandNode) this.copyStyles(styles.groupExpandNode, "groupExpandNode");
  1466. if (styles.checkboxNode) this.copyStyles(styles.checkboxNode, "checkboxNode");
  1467. if (styles.checkedCheckboxNode) this.copyStyles(styles.checkedCheckboxNode, "checkedCheckboxNode");
  1468. if (styles.radioNode) this.copyStyles(styles.radioNode, "radioNode");
  1469. if (styles.checkedRadioNode) this.copyStyles(styles.checkedRadioNode, "checkedRadioNode");
  1470. if (styles.tableProperties) this.copyStyles(styles.tableProperties, "tableProperties");
  1471. },
  1472. removeStyles: function (from, to) {
  1473. if (this.json.data.viewStyles[to]) {
  1474. Object.each(from, function (style, key) {
  1475. if (this.json.data.viewStyles[to][key] && this.json.data.viewStyles[to][key] == style) {
  1476. delete this.json.data.viewStyles[to][key];
  1477. }
  1478. }.bind(this));
  1479. }
  1480. },
  1481. copyStyles: function (from, to) {
  1482. if (!this.json.data.viewStyles[to]) this.json.data.viewStyles[to] = {};
  1483. Object.each(from, function (style, key) {
  1484. if (!this.json.data.viewStyles[to][key]) this.json.data.viewStyles[to][key] = style;
  1485. }.bind(this));
  1486. }
  1487. // preview: function(){
  1488. // if( this.isNewView ){
  1489. // this.designer.notice( this.designer.lp.saveViewNotice, "error" );
  1490. // return;
  1491. // }
  1492. // this.saveSilence( function () {
  1493. // var url = "../x_desktop/app.html?app=query.Query&status=";
  1494. // url += JSON.stringify({
  1495. // id : this.data.application,
  1496. // viewId : this.data.id
  1497. // });
  1498. // window.open(o2.filterUrl(url),"_blank");
  1499. // }.bind(this));
  1500. // },
  1501. // saveSilence: function(callback){
  1502. // if (!this.data.name){
  1503. // this.designer.notice(this.designer.lp.notice.inputName, "error");
  1504. // return false;
  1505. // }
  1506. //
  1507. // this.designer.actions.saveView(this.data, function(json){
  1508. // this.data.id = json.data.id;
  1509. // this.isNewView = false;
  1510. // //this.page.textNode.set("text", this.data.name);
  1511. // if (this.lisNode) {
  1512. // this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  1513. // }
  1514. // if (callback) callback();
  1515. // }.bind(this));
  1516. // },
  1517. // save: function(callback){
  1518. // //if (this.designer.tab.showPage==this.page){
  1519. // if (!this.data.name){
  1520. // this.designer.notice(this.designer.lp.notice.inputName, "error");
  1521. // return false;
  1522. // }
  1523. // //}
  1524. // this.designer.actions.saveView(this.data, function(json){
  1525. // this.designer.notice(this.designer.lp.notice.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  1526. // this.isNewView = false;
  1527. // this.data.id = json.data.id;
  1528. // //this.page.textNode.set("text", this.data.name);
  1529. // if (this.lisNode) {
  1530. // this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  1531. // }
  1532. // if (callback) callback();
  1533. // }.bind(this));
  1534. // },
  1535. // saveAs: function(){
  1536. // var form = new MWF.xApplication.query.StatementDesigner.View.NewNameForm(this, {
  1537. // name : this.data.name + "_" + MWF.xApplication.query.StatementDesigner.LP.copy,
  1538. // query : this.data.query || this.data.application,
  1539. // queryName : this.data.queryName || this.data.applicationName
  1540. // }, {
  1541. // onSave : function( data, callback ){
  1542. // this._saveAs( data, callback );
  1543. // }.bind(this)
  1544. // }, {
  1545. // app: this.designer
  1546. // });
  1547. // form.edit()
  1548. // },
  1549. // _saveAs : function( data , callback){
  1550. // var _self = this;
  1551. //
  1552. // var d = this.cloneObject( this.data );
  1553. //
  1554. // d.isNewView = true;
  1555. // d.id = this.designer.actions.getUUID();
  1556. // d.name = data.name;
  1557. // d.alias = "";
  1558. // d.query = data.query;
  1559. // d.queryName = data.queryName;
  1560. // d.application = data.query;
  1561. // d.applicationName = data.queryName;
  1562. // d.pid = d.id + d.id;
  1563. //
  1564. // delete d[this.data.id+"viewFilterType"];
  1565. // d[d.id+"viewFilterType"]="custom";
  1566. //
  1567. // d.data.selectList.each( function( entry ){
  1568. // entry.id = (new MWF.widget.UUID).id;
  1569. // }.bind(this));
  1570. //
  1571. // this.designer.actions.saveView(d, function(json){
  1572. // this.designer.notice(this.designer.lp.notice.saveAs_success, "success", this.node, {"x": "left", "y": "bottom"});
  1573. // if (callback) callback();
  1574. // }.bind(this));
  1575. // }
  1576. });
  1577. MWF.xApplication.query.StatementDesigner.View.Column = new Class({
  1578. Extends: MWF.xApplication.query.ViewDesigner.View.Column,
  1579. initialize: function (json, view, next) {
  1580. this.propertyPath = "../x_component_query_StatementDesigner/$Statement/column.html";
  1581. this.view = view;
  1582. this.json = json;
  1583. this.next = next;
  1584. this.css = this.view.css;
  1585. this.content = this.view.viewTitleTrNode;
  1586. this.domListNode = this.view.domListNode;
  1587. this.load();
  1588. },
  1589. refreshColumnPathData: function () {
  1590. if (this.property) {
  1591. this.property.loadDataPathSelect();
  1592. }
  1593. },
  1594. getColumnDataPath: function () {
  1595. return this.view.statement.getColumnDataPath();
  1596. },
  1597. showProperty: function () {
  1598. if (!this.property) {
  1599. this.property = new MWF.xApplication.query.StatementDesigner.Property(this, this.view.designer.propertyContentArea, this.view.designer, {
  1600. "path": this.propertyPath,
  1601. "onPostLoad": function () {
  1602. this.property.show();
  1603. var processDiv = this.property.propertyContent.getElements("#" + this.json.id + "dataPathSelectedProcessArea");
  1604. var cmsDiv = this.property.propertyContent.getElements("#" + this.json.id + "dataPathSelectedCMSArea");
  1605. if (this.view.json.type == "cms") {
  1606. processDiv.setStyle("display", "none");
  1607. cmsDiv.setStyle("display", "block");
  1608. } else {
  1609. processDiv.setStyle("display", "block");
  1610. cmsDiv.setStyle("display", "none");
  1611. }
  1612. }.bind(this)
  1613. });
  1614. this.property.load();
  1615. } else {
  1616. this.property.show();
  1617. }
  1618. },
  1619. selected: function () {
  1620. if (this.view.statement.currentSelectedModule) {
  1621. if (this.view.statement.currentSelectedModule == this) {
  1622. return true;
  1623. } else {
  1624. this.view.statement.currentSelectedModule.unSelected();
  1625. }
  1626. }
  1627. this.view.domListNode.show();
  1628. this.node.setStyles(this.css.viewTitleColumnNode_selected);
  1629. this.listNode.setStyles(this.css.cloumnListNode_selected);
  1630. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  1631. new Fx.Scroll(this.view.designer.propertyDomArea, {
  1632. "wheelStops": false,
  1633. "duration": 100
  1634. }).toElement(this.listNode);
  1635. this.view.statement.currentSelectedModule = this;
  1636. this.isSelected = true;
  1637. this._showActions();
  1638. this.showProperty();
  1639. },
  1640. unSelected: function () {
  1641. this.view.statement.currentSelectedModule = null;
  1642. //this.node.setStyles(this.css.viewTitleColumnNode);
  1643. if (this.isError) {
  1644. this.node.setStyles(this.css.viewTitleColumnNode_error)
  1645. } else {
  1646. this.node.setStyles(this.css.viewTitleColumnNode)
  1647. }
  1648. this.listNode.setStyles(this.css.cloumnListNode);
  1649. this.isSelected = false;
  1650. this._hideActions();
  1651. this.hideProperty();
  1652. }
  1653. });
  1654. MWF.xApplication.query.StatementDesigner.View.Actionbar = new Class({
  1655. Extends: MWF.xApplication.query.ViewDesigner.View.Actionbar,
  1656. initialize: function (json, jsonList, view, options) {
  1657. this.setOptions(options);
  1658. this.propertyPath = "../x_component_query_StatementDesigner/$Statement/actionbar.html";
  1659. this.path = "../x_component_query_ViewDesigner/$View/";
  1660. this.imagePath_default = "../x_component_query_ViewDesigner/$View/";
  1661. this.imagePath_custom = "../x_component_process_FormDesigner/Module/Actionbar/";
  1662. this.cssPath = "../x_component_query_ViewDesigner/$View/" + this.options.style + "/actionbar.wcss";
  1663. this.view = view;
  1664. this.json = json;
  1665. this.jsonList = jsonList;
  1666. this.css = this.view.css;
  1667. this.container = this.view.actionbarNode;
  1668. this.moduleName = "actionbar";
  1669. this.load();
  1670. },
  1671. getJsonPath: function () {
  1672. return "../x_component_query_StatementDesigner/$Statement/toolbars.json";
  1673. },
  1674. selected: function () {
  1675. if (this.view.statement.currentSelectedModule) {
  1676. if (this.view.statement.currentSelectedModule == this) {
  1677. return true;
  1678. } else {
  1679. this.view.statement.currentSelectedModule.unSelected();
  1680. }
  1681. }
  1682. this.view.domListNode.show();
  1683. this.node.setStyles(this.css.toolbarWarpNode_selected);
  1684. //this.listNode.setStyles(this.css.cloumnListNode_selected);
  1685. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  1686. //new Fx.Scroll(this.view.designer.propertyDomArea, {"wheelStops": false, "duration": 100}).toElement(this.listNode);
  1687. this.view.statement.currentSelectedModule = this;
  1688. this.isSelected = true;
  1689. //this._showActions();
  1690. this.showProperty();
  1691. },
  1692. unSelected: function () {
  1693. this.view.statement.currentSelectedModule = null;
  1694. this.node.setStyles(this.css.toolbarWarpNode);
  1695. //this.listNode.setStyles(this.css.cloumnListNode);
  1696. this.isSelected = false;
  1697. //this._hideActions();
  1698. this.hideProperty();
  1699. },
  1700. showProperty: function(){
  1701. if (!this.property){
  1702. this.property = new MWF.xApplication.query.StatementDesigner.Property(this, this.view.designer.propertyContentArea, this.view.designer, {
  1703. "path": this.propertyPath,
  1704. "onPostLoad": function(){
  1705. this.property.show();
  1706. }.bind(this)
  1707. });
  1708. this.property.load();
  1709. }else{
  1710. this.property.show();
  1711. }
  1712. }
  1713. });
  1714. MWF.xApplication.query.StatementDesigner.View.Paging = new Class({
  1715. Extends: MWF.xApplication.query.ViewDesigner.View.Paging,
  1716. selected: function () {
  1717. if (this.view.statement.currentSelectedModule) {
  1718. if (this.view.statement.currentSelectedModule == this) {
  1719. return true;
  1720. } else {
  1721. this.view.statement.currentSelectedModule.unSelected();
  1722. }
  1723. }
  1724. this.view.domListNode.show();
  1725. this.node.setStyles(this.css.pagingWarpNode_selected);
  1726. new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  1727. this.view.statement.currentSelectedModule = this;
  1728. this.isSelected = true;
  1729. this.showProperty();
  1730. },
  1731. unSelected: function () {
  1732. this.view.statement.currentSelectedModule = null;
  1733. this.node.setStyles(this.css.pagingWarpNode);
  1734. this.isSelected = false;
  1735. this.hideProperty();
  1736. }
  1737. });