Statement.js 103 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443
  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.countMethod){
  45. if( this.json.countData || this.json.countScriptText ){
  46. this.json.countMethod = "assign";
  47. }else{
  48. this.json.countMethod = "auto";
  49. }
  50. }
  51. if (!this.json.entityClassName) this.json.entityClassName = ""; //"com.x.processplatform.core.entity.content.Task";
  52. },
  53. autoSave: function () {
  54. this.autoSaveTimerID = window.setInterval(function () {
  55. if (!this.autoSaveCheckNode) this.autoSaveCheckNode = this.designer.contentToolbarNode.getElement("#MWFAutoSaveCheck");
  56. if (this.autoSaveCheckNode) {
  57. if (this.autoSaveCheckNode.get("checked")) {
  58. this.save();
  59. }
  60. }
  61. }.bind(this), 60000);
  62. },
  63. getDefaultEditorData: function(){
  64. return {
  65. "javascriptEditor": {
  66. "monaco_theme": "vs",
  67. "fontSize" : "12px",
  68. "editor": "monaco"
  69. }
  70. };
  71. // return {
  72. // "javascriptEditor": {
  73. // "theme": "tomorrow",
  74. // "fontSize" : "12px",
  75. // "editor": "ace"
  76. // }
  77. // };
  78. },
  79. getEditorTheme: function(callback){
  80. if (!o2.editorData){
  81. o2.UD.getData("editor", function(json){
  82. if (json.data){
  83. o2.editorData = JSON.decode(json.data);
  84. }else{
  85. o2.editorData = this.getDefaultEditorData();
  86. }
  87. if (callback) callback();
  88. }.bind(this));
  89. }else{
  90. if (callback) callback();
  91. }
  92. },
  93. load : function(){
  94. this.getEditorTheme( function () {
  95. this._load();
  96. }.bind(this))
  97. },
  98. _load: function () {
  99. // this.setAreaNodeSize();
  100. // this.designer.addEvent("resize", this.setAreaNodeSize.bind(this));
  101. this.areaNode.inject(this.node);
  102. this.designer.statementListAreaNode.getChildren().each(function (node) {
  103. var statement = node.retrieve("statement");
  104. if (statement.id == this.data.id) {
  105. if (this.designer.currentListStatementItem) {
  106. this.designer.currentListStatementItem.setStyles(this.designer.css.listStatementItem);
  107. }
  108. node.setStyles(this.designer.css.listStatementItem_current);
  109. this.designer.currentListStatementItem = node;
  110. this.lisNode = node;
  111. }
  112. }.bind(this));
  113. this.loadStatement();
  114. // this.showProperty();
  115. this.selected();
  116. },
  117. selected: function () {
  118. if (this.currentSelectedModule) {
  119. if (this.currentSelectedModule == this) {
  120. return true;
  121. } else {
  122. this.currentSelectedModule.unSelected();
  123. }
  124. }
  125. if (this.view && this.view.domListNode) {
  126. this.view.domListNode.hide();
  127. }
  128. this.selectMode = "statement";
  129. this.currentSelectedModule = this;
  130. this.isSelected = true;
  131. this.showProperty();
  132. this.designer.setDesignerStatementResize();
  133. },
  134. unSelected: function () {
  135. this.currentSelectedModule = null;
  136. this.isSelected = false;
  137. this.hideProperty();
  138. },
  139. showProperty: function () {
  140. if (!this.property) {
  141. this.property = new MWF.xApplication.query.StatementDesigner.Property(this, this.designer.designerContentArea, this.designer, {
  142. "path": this.options.propertyPath,
  143. "onPostLoad": function () {
  144. this.property.show();
  145. }.bind(this)
  146. });
  147. this.property.load();
  148. } else {
  149. this.property.show();
  150. }
  151. },
  152. hideProperty: function () {
  153. if (this.property) this.property.hide();
  154. },
  155. loadStatementTab: function (callback) {
  156. var _self = this;
  157. MWF.require("MWF.widget.Tab", null, false);
  158. this.statementTab = new MWF.widget.Tab(this.statementTabNode, {"style": "script"});
  159. this.statementTab.load();
  160. this.tabQueryNode = Element("div");
  161. this.queryTabPageNode.inject(this.tabQueryNode);
  162. this.queryPage = this.statementTab.addTab(this.tabQueryNode, this.designer.lp.queryStatement);
  163. this.queryPage.addEvent("postShow", function(){
  164. switch (this.json.format) {
  165. case "script":
  166. if( this.jpqlScriptEditor ){
  167. this.jpqlScriptEditor.container.setStyle("height", ""+this.getEditorHeight()+"px");
  168. this.jpqlScriptEditor.resizeContentNodeSize();
  169. }
  170. break;
  171. case "sql":
  172. if(this.sqlEditor)this.sqlEditor.resize();
  173. break;
  174. case "sqlScript":
  175. if( this.sqlScriptEditor ){
  176. this.sqlScriptEditor.container.setStyle("height", ""+this.getEditorHeight()+"px");
  177. this.sqlScriptEditor.resizeContentNodeSize();
  178. }
  179. break;
  180. default:
  181. if(this.jpqlEditor)this.jpqlEditor.resize();
  182. }
  183. }.bind(this))
  184. this.tabCountNode = Element("div");
  185. this.countTabPageNode.inject(this.tabCountNode);
  186. this.countPage = this.statementTab.addTab(this.tabCountNode, this.designer.lp.countStatement);
  187. this.countPage.addEvent("postShow", function(){
  188. switch (this.json.format) {
  189. case "script":
  190. if( this.jpqlCountScriptEditor ){
  191. this.jpqlCountScriptEditor.container.setStyle("height", ""+this.getEditorHeight()+"px");
  192. this.jpqlCountScriptEditor.resizeContentNodeSize();
  193. }
  194. break;
  195. case "sql":
  196. if( this.sqlCountEditor )this.sqlCountEditor.resize();
  197. break;
  198. case "sqlScript":
  199. if( this.sqlCountScriptEditor ){
  200. this.sqlCountScriptEditor.container.setStyle("height", ""+this.getEditorHeight()+"px");
  201. this.sqlCountScriptEditor.resizeContentNodeSize();
  202. }
  203. break;
  204. default:
  205. if( this.jpqlCountEditor )this.jpqlCountEditor.resize();
  206. }
  207. }.bind(this))
  208. // this.tabSqlNode = Element("div");
  209. // this.sqlTabPageNode.inject(this.tabSqlNode);
  210. //
  211. // this.tabCountSqlNode = Element("div");
  212. // this.countSqlTabPageNode.inject(this.tabCountSqlNode);
  213. this.queryPage.showTabIm();
  214. if( ["auto", "ignore"].contains(this.json.countMethod) ){
  215. this.countPage.disableTab();
  216. }
  217. // this.queryPage.addEvent("postShow", function(){
  218. // if( this.view ){
  219. // this.view.setContentHeight();
  220. // this.view.selected();
  221. // }
  222. // }.bind(this));
  223. // this.countPage.addEvent("postShow", function(){
  224. // this.selected();
  225. // }.bind(this));
  226. },
  227. loadTab: function (callback) {
  228. var _self = this;
  229. MWF.require("MWF.widget.Tab", null, false);
  230. this.tab = new MWF.widget.Tab(this.tabNode, {"style": "script"});
  231. this.tab.load();
  232. this.tabRunNode = Element("div");
  233. this.pageRunNode = new Element("div", {
  234. "styles": {
  235. "overflow": "auto",
  236. "background-color": "#fff"
  237. }
  238. }).inject(this.tabRunNode);
  239. this.runArea.inject(this.pageRunNode);
  240. this.tabViewNode = Element("div", {"styles": {"height": "100%"}});
  241. this.pageViewNode = new Element("div.pageViewNode").inject(this.tabViewNode);
  242. this.viewArea.inject(this.pageViewNode);
  243. this.runPage = this.tab.addTab(this.tabRunNode, this.designer.lp.runTest);
  244. this.viewPage = this.tab.addTab(this.tabViewNode, this.designer.lp.view);
  245. this.runPage.showTabIm();
  246. this.viewPage.addEvent("postShow", function () {
  247. if (this.view) {
  248. this.view.setContentHeight();
  249. this.view.selected();
  250. }
  251. }.bind(this));
  252. this.runPage.addEvent("postShow", function () {
  253. this.selected();
  254. }.bind(this));
  255. if( this.options.viewEnable === false ){
  256. this.viewPage.disableTab();
  257. }
  258. },
  259. loadStatement: function () {
  260. //this.statementDesignerNode = new Element("div", {"styles": this.css.statementDesignerNode}).inject(this.areaNode);
  261. this.loadStatementHtml(function () {
  262. this.designerArea = this.areaNode.getElement(".o2_statement_statementDesignerNode");
  263. this.statementTabNode = this.areaNode.getElement(".o2_statement_statementTabNode");
  264. this.queryTabPageNode = this.areaNode.getElement(".o2_statement_statementQueryTabPageNode");
  265. this.jpqlArea = this.areaNode.getElement(".o2_statement_statementDesignerJpql");
  266. this.jpqlScriptArea = this.areaNode.getElement(".o2_statement_statementDesignerScript");
  267. this.jpqlEditorNode = this.areaNode.getElement(".o2_statement_statementDesignerJpqlLine");
  268. this.sqlArea = this.areaNode.getElement(".o2_statement_statementDesignerSql");
  269. this.sqlScriptArea = this.areaNode.getElement(".o2_statement_statementDesignerSqlScript");
  270. this.sqlEditorNode = this.areaNode.getElement(".o2_statement_statementDesignerSqlLine");
  271. this.countTabPageNode = this.areaNode.getElement(".o2_statement_statementCountTabPageNode");
  272. this.jpqlCountArea = this.areaNode.getElement(".o2_statement_statementDesignerCountJpql");
  273. this.jpqlCountScriptArea = this.areaNode.getElement(".o2_statement_statementDesignerCountScript");
  274. this.jpqlCountEditorNode = this.areaNode.getElement(".o2_statement_statementDesignerCountJpqlLine");
  275. this.sqlCountArea = this.areaNode.getElement(".o2_statement_statementDesignerCountSql");
  276. this.sqlCountScriptArea = this.areaNode.getElement(".o2_statement_statementDesignerCountSqlScript");
  277. this.sqlCountEditorNode = this.areaNode.getElement(".o2_statement_statementDesignerCountSqlLine");
  278. this.formatTypeArea = this.areaNode.getElement(".o2_statement_statementDesignerFormatContent");
  279. this.formatTypeArea.getElements("input").each(function (input) {
  280. input.set("name", input.get("name") + "_" +this.json.id);
  281. }.bind(this));
  282. this.entityCategorySelect = this.areaNode.getElement(".o2_statement_statementDesignerCategoryContent").getElement("select");
  283. this.dynamicTableArea = this.areaNode.getElement(".o2_statement_statementDesignerTableArea_dynamic");
  284. this.officialTableArea = this.areaNode.getElement(".o2_statement_statementDesignerTableArea_official");
  285. this.jpqlOfficalTable = this.areaNode.getElement(".o2_statement_statementDesignerOfficialTable_JPQL");
  286. this.sqlOfficalTable = this.areaNode.getElement(".o2_statement_statementDesignerOfficialTable_SQL");
  287. this.customTableArea = this.areaNode.getElement(".o2_statement_statementDesignerTableArea_custom");
  288. this.dynamicTableSelect = this.areaNode.getElement(".o2_statement_statementDesignerSelectTable");
  289. this.officialTableSelectJPQL = this.jpqlOfficalTable.getElement("select");
  290. this.officialTableSelectSQL = this.sqlOfficalTable.getElement("select");
  291. this.fieldSelect = this.areaNode.getElement(".o2_statement_statementDesignerTableArea_field").getElement("select");
  292. this.dynamicTableContent = this.areaNode.getElement(".o2_statement_statementDesignerTableContent");
  293. // this.statementTypeSelect = this.areaNode.getElement(".o2_statement_statementDesignerTypeContent").getElement("select");
  294. // this.loadStatementTypeSelect();
  295. this.countMethodSelect = this.areaNode.getElement(".o2_statement_statementDesignerCountMethodContent").getElement("select");
  296. this.loadCountMethodSelect();
  297. // this.jpqlSelectEditor = this.areaNode.getElement(".o2_statement_statementDesignerJpql_select");
  298. // this.jpqlUpdateEditor = this.areaNode.getElement(".o2_statement_statementDesignerJpql_update");
  299. // this.jpqlDeleteEditor = this.areaNode.getElement(".o2_statement_statementDesignerJpql_sdelete");
  300. // this.jpqlSelectEditor_selectContent= this.jpqlSelectEditor.getElement(".o2_statement_statementDesignerJpql_jpql_selectContent");
  301. // this.jpqlSelectEditor_fromContent= this.jpqlSelectEditor.getElement(".o2_statement_statementDesignerJpql_jpql_fromContent");
  302. // this.jpqlSelectEditor_whereContent= this.jpqlSelectEditor.getElement(".o2_statement_statementDesignerJpql_jpql_whereContent");
  303. this.loadStatementTab();
  304. this.resizeNode = this.areaNode.getElement(".o2_statement_resizeNode");
  305. this.tabNode = this.areaNode.getElement(".o2_statement_tabNode");
  306. this.runArea = this.areaNode.getElement(".o2_statement_statementRunNode");
  307. // this.runTitleNode = this.areaNode.getElement(".o2_statement_statementRunTitleNode");
  308. this.runContentNode = this.areaNode.getElement(".o2_statement_statementRunContentNode");
  309. this.runJsonNode = this.runContentNode.getElement(".o2_statement_statementRunJsonNode");
  310. this.runFilterNode = this.runContentNode.getElement(".o2_statement_statementRunFilterNode");
  311. this.runPageNoInput = this.runContentNode.getElement(".o2_statement_statementRunPageNoInput");
  312. this.runPageSizeInput = this.runContentNode.getElement(".o2_statement_statementRunPageSizeInput");
  313. this.runActionNode = this.runContentNode.getElement(".o2_statement_statementRunActionNode");
  314. this.runResultNode = this.runContentNode.getElement(".o2_statement_statementRunResultNode");
  315. // this.runDefaultNode = this.runContentNode.getElement(".o2_statement_statementRunDefaultContent");
  316. this.setRunnerSize();
  317. this.designer.addEvent("resize", this.setRunnerSize.bind(this));
  318. debugger;
  319. this.loadFieldSelect();
  320. switch (this.json.format) {
  321. case "script":
  322. this.jpqlOfficalTable.show();
  323. this.sqlOfficalTable.hide();
  324. this.loadJpqlScriptEditor();
  325. this.loadJpqlCountScriptEditor();
  326. break;
  327. case "sql":
  328. this.jpqlOfficalTable.hide();
  329. this.sqlOfficalTable.show();
  330. this.loadSqlEditor();
  331. this.loadSqlCountEditor();
  332. break;
  333. case "sqlScript":
  334. this.jpqlOfficalTable.hide();
  335. this.sqlOfficalTable.show();
  336. this.loadSqlScriptEditor();
  337. this.loadSqlCountScriptEditor();
  338. break;
  339. default:
  340. this.jpqlOfficalTable.show();
  341. this.sqlOfficalTable.hide();
  342. this.loadJpqlEditor();
  343. this.loadJpqlCountEditor();
  344. }
  345. // this.loadDefaultCondition();
  346. this.loadStatementRunner();
  347. this.viewArea = this.areaNode.getElement(".o2_statement_viewNode");
  348. this.loadView();
  349. this.loadTab();
  350. if( this.json.table ){
  351. o2.Actions.load("x_query_assemble_designer").TableAction.get( this.json.table, function(json){
  352. this.json.tableObj = json.data;
  353. this.setDynamicTableName();
  354. }.bind(this), function(){
  355. return true;
  356. });
  357. }
  358. this.setEvent();
  359. this.loadVerticalResize();
  360. }.bind(this));
  361. },
  362. // loadDefaultCondition: function(){
  363. // var lp = ["currentPerson","currentIdentity","currentPersonDirectUnit","currentPersonAllUnit","currentPersonGroupList","currentPersonRoleList"];
  364. // ["person","identityList","unitList","unitAllList","groupList","roleList"].each(function (key, i) {
  365. // var div = new Element("div", {
  366. // style: "float:left;margin-right:10px;"
  367. // }).inject(this.runDefaultNode);
  368. // new Element("input", {
  369. // type: "checkbox",
  370. // value: "@"+key,
  371. // name: this.json.id + "defaultConditoin",
  372. // id: this.json.id + "defaultConditoin" + key
  373. // }).inject(div);
  374. // new Element("label", {
  375. // for: this.json.id + "defaultConditoin" + key,
  376. // text: this.designer.lp[lp[i]]
  377. // }).inject(div);
  378. // }.bind(this));
  379. // },
  380. loadCountMethodSelect: function(){
  381. this.countMethodSelect.getElements("option").each(function(o){
  382. if( this.json.countMethod === o.value ){
  383. o.selected = true;
  384. }
  385. }.bind(this));
  386. },
  387. // loadStatementTypeSelect : function(){
  388. // this.statementTypeSelect.empty();
  389. // var optionList = [{text:"SELECT", value:"select"}];
  390. // if( this.data.entityCategory === "dynamic" || (this.data.description && this.data.description.indexOf("update")>-1)){
  391. // optionList = optionList.concat([
  392. // {text:"UPDATE", value:"update"},
  393. // {text:"DELETE", value:"delete"}
  394. // ])
  395. // }
  396. //
  397. // var flag = true;
  398. // optionList.each( function ( field ) {
  399. // var option = new Element("option", {
  400. // "text": field.text,
  401. // "value": field.value
  402. // }).inject(this.statementTypeSelect);
  403. // if( this.json.type === field.value ){
  404. // flag = false;
  405. // option.selected = true;
  406. // }
  407. // }.bind(this));
  408. // if( flag ){
  409. // this.statementTypeSelect.options[0].selected = true;
  410. // this.json.type = this.statementTypeSelect.options[0].value;
  411. // }
  412. // },
  413. loadFieldSelect : function(){
  414. this.fieldSelect.empty();
  415. var d = this.data;
  416. var className = d.entityCategory === "dynamic" ? d.table : d.entityClassName;
  417. if( !className )return;
  418. var pre = ["sql", "sqlScript"].contains(d.format) ? "x" : "";
  419. o2.Actions.load("x_query_assemble_designer").QueryAction.getEntityProperties(
  420. className,
  421. d.entityCategory,
  422. function(json){
  423. json = Object.clone(json);
  424. var option = new Element("option", { "text": this.designer.lp.fileldSelectNote, "value": "" }).inject(this.fieldSelect);
  425. option.store("type", d.entityCategory);
  426. option.store("tableName", className );
  427. (json.data||[]).each( function ( field ) {
  428. if( pre )field.name = pre + field.name;
  429. var option = new Element("option", {
  430. "text": field.name + ( field.description ? ("-" + field.description) : "" ),
  431. "value": field.name
  432. }).inject(this.fieldSelect);
  433. option.store("field", field);
  434. option.store("type", d.entityCategory );
  435. option.store("tableName", className );
  436. }.bind(this));
  437. }.bind(this)
  438. )
  439. },
  440. loadVerticalResize: function(){
  441. this.verticalResize = new Drag(this.resizeNode, {
  442. "snap": 10,
  443. "onStart": function(el, e){
  444. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  445. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  446. el.store("position", {"x": x, "y": y});
  447. var size = this.designerArea.getSize(); //designerArea
  448. el.store("initialHeight", size.y);
  449. var allSize = this.areaNode.getSize();
  450. el.store("initialAllHeight", allSize.y);
  451. }.bind(this),
  452. "onDrag": function(el, e){
  453. var allHeight = el.retrieve("initialAllHeight").toFloat(); //this.areaNode.getSize();
  454. // var x = e.event.x;
  455. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  456. var position = el.retrieve("position");
  457. var dy = y.toFloat()-position.y.toFloat();
  458. var initialHeight = el.retrieve("initialHeight").toFloat();
  459. var height = initialHeight+dy;
  460. if (height < 180) height = 180;
  461. if (height > allHeight-180) height = allHeight-180;
  462. this.designerAreaPercent = height/allHeight;
  463. this.setVerticalResize();
  464. }.bind(this)
  465. });
  466. },
  467. setVerticalResize: function(){
  468. var size = this.areaNode.getSize();
  469. var height = size.y;
  470. var designAreaHeight = this.designerAreaPercent*height - 52;
  471. // var runAreaHeight = height-designAreaHeight;
  472. this.designerArea.setStyle("height", ""+designAreaHeight+"px");
  473. var editorHeight = designAreaHeight - 98;
  474. if(this.jpqlEditorNode)this.jpqlEditorNode.setStyle( "height", ""+editorHeight+"px" );
  475. if(this.jpqlCountEditorNode)this.jpqlCountEditorNode.setStyle( "height", ""+editorHeight+"px" );
  476. if(this.jpqlScriptArea)this.jpqlScriptArea.setStyle( "height", ""+editorHeight+"px" );
  477. if(this.jpqlCountScriptArea)this.jpqlCountScriptArea.setStyle( "height", ""+editorHeight+"px" );
  478. if(this.sqlEditorNode)this.sqlEditorNode.setStyle( "height", ""+editorHeight+"px" );
  479. if(this.sqlCountEditorNode)this.sqlCountEditorNode.setStyle( "height", ""+editorHeight+"px" );
  480. if(this.sqlScriptArea)this.sqlScriptArea.setStyle( "height", ""+editorHeight+"px" );
  481. if(this.sqlCountScriptArea)this.sqlCountScriptArea.setStyle( "height", ""+editorHeight+"px" );
  482. if( this.jpqlEditor )this.jpqlEditor.resize();
  483. if( this.jpqlCountEditor )this.jpqlCountEditor.resize();
  484. if( this.jpqlScriptEditor ){
  485. this.jpqlScriptEditor.container.setStyle("height", ""+editorHeight+"px");
  486. this.jpqlScriptEditor.resizeContentNodeSize();
  487. }
  488. if( this.jpqlCountScriptEditor ){
  489. this.jpqlCountScriptEditor.container.setStyle("height", ""+editorHeight+"px");
  490. this.jpqlCountScriptEditor.resizeContentNodeSize();
  491. }
  492. if( this.sqlEditor )this.sqlEditor.resize();
  493. if( this.sqlCountEditor )this.sqlCountEditor.resize();
  494. if( this.sqlScriptEditor ){
  495. this.sqlScriptEditor.container.setStyle("height", ""+editorHeight+"px");
  496. this.sqlScriptEditor.resizeContentNodeSize();
  497. }
  498. if( this.sqlCountScriptEditor ){
  499. this.sqlCountScriptEditor.container.setStyle("height", ""+editorHeight+"px");
  500. this.sqlCountScriptEditor.resizeContentNodeSize();
  501. }
  502. // this.tabNode.setStyle("height", ""+runAreaHeight+"px");
  503. this.setRunnerSize();
  504. if( this.view ){
  505. this.setViewSize();
  506. this.view.setContentHeight()
  507. }
  508. },
  509. getEditorHeight: function(){
  510. var size = this.areaNode.getSize();
  511. var height = size.y;
  512. var designAreaHeight = this.designerAreaPercent*height - 52;
  513. return designAreaHeight - 98;
  514. },
  515. setRunnerSize: function () {
  516. debugger;
  517. var size = this.areaNode.getSize();
  518. var designerSize = this.designerArea.getComputedSize();
  519. var reizeNodeSize = this.resizeNode.getComputedSize();
  520. var y = size.y - designerSize.totalHeight - reizeNodeSize.totalHeight;
  521. var mTop = this.runArea.getStyle("margin-top").toInt();
  522. var mBottom = this.runArea.getStyle("margin-bottom").toInt();
  523. var pTop = this.runArea.getStyle("padding-top").toInt();
  524. var pBottom = this.runArea.getStyle("padding-bottom").toInt();
  525. y = y - mTop - mBottom - pTop - pBottom - 5;
  526. var tabSize = this.tabNode.getComputedSize();
  527. y = y - tabSize.totalHeight;
  528. this.runArea.setStyle("height", "" + y + "px");
  529. // var titleSize = this.runTitleNode.getComputedSize();
  530. // y = y - titleSize.totalHeight;
  531. this.runContentNode.setStyle("height", "" + y + "px");
  532. },
  533. loadJpqlEditor: function () {
  534. if (!this.jpqlEditor) {
  535. var value;
  536. if( !this.json.data ){
  537. var table = "table";
  538. // switch (this.json.type) {
  539. // case "update":
  540. // value = "UPDATE " + table + " o SET ";
  541. // break;
  542. // case "delete":
  543. // value = "DELETE " + table + " o WHERE ";
  544. // break;
  545. // default:
  546. value = "SELECT o FROM " + table + " o";
  547. // }
  548. this.json.data = value;
  549. }
  550. if( this.jpqlEditorNode.offsetParent === null && o2.editorData.javascriptEditor.editor === "monaco" ){
  551. var postShowFun = function() {
  552. this._loadJpqlEditor();
  553. this.queryPage.removeEvent("postShow", postShowFun);
  554. }.bind(this);
  555. this.queryPage.addEvent("postShow", postShowFun);
  556. }else{
  557. this._loadJpqlEditor();
  558. }
  559. }else{
  560. this.jpqlEditor.resize();
  561. }
  562. },
  563. _loadJpqlEditor: function () {
  564. if (!this.jpqlEditor) {
  565. o2.require("o2.widget.JavascriptEditor", function () {
  566. this.jpqlEditor = new o2.widget.JavascriptEditor(this.jpqlEditorNode, {
  567. "title": "JPQL",
  568. "option": {"mode": "sql"}
  569. });
  570. this.jpqlEditor.load(function () {
  571. this.jpqlEditor.editor.setValue(this.json.data);
  572. this.jpqlEditor.addEditorEvent("change", function () {
  573. this.data.data = this.jpqlEditor.getValue();
  574. // this.checkStatementType();
  575. }.bind(this));
  576. }.bind(this));
  577. }.bind(this), false);
  578. }
  579. },
  580. loadJpqlCountEditor: function () {
  581. if (!this.jpqlCountEditor) {
  582. if( !this.json.countData )this.json.countData = "SELECT count(o.id) FROM table o";
  583. if( this.jpqlCountEditorNode.offsetParent === null && o2.editorData.javascriptEditor.editor === "monaco" ){
  584. var postShowFun = function() {
  585. this._loadJpqlCountEditor();
  586. this.countPage.removeEvent("postShow", postShowFun);
  587. }.bind(this);
  588. this.countPage.addEvent("postShow", postShowFun);
  589. }else{
  590. this._loadJpqlCountEditor();
  591. }
  592. }else{
  593. this.jpqlCountEditor.resize();
  594. }
  595. },
  596. _loadJpqlCountEditor : function(){
  597. o2.require("o2.widget.JavascriptEditor", function () {
  598. this.jpqlCountEditor = new o2.widget.JavascriptEditor(this.jpqlCountEditorNode, {
  599. "title": "JPQL",
  600. "option": {"mode": "sql"}
  601. });
  602. this.jpqlCountEditor.load(function () {
  603. this.jpqlCountEditor.editor.setValue(this.json.countData);
  604. this.jpqlCountEditor.addEditorEvent("change", function () {
  605. this.data.countData = this.jpqlCountEditor.getValue();
  606. }.bind(this));
  607. }.bind(this));
  608. }.bind(this), false);
  609. },
  610. loadSqlEditor: function () {
  611. if (!this.sqlEditor) {
  612. var value;
  613. if( !this.json.sql ){
  614. var table = "table";
  615. // switch (this.json.type) {
  616. // case "update":
  617. // value = "UPDATE " + table + " SET ";
  618. // break;
  619. // case "delete":
  620. // value = "DELETE FROM " + table + " WHERE ";
  621. // break;
  622. // default:
  623. value = "SELECT * FROM " + table + "";
  624. // }
  625. this.json.sql = value;
  626. }
  627. if( this.sqlEditorNode.offsetParent === null && o2.editorData.javascriptEditor.editor === "monaco" ){
  628. var postShowFun = function() {
  629. this._loadSqlEditor();
  630. this.queryPage.removeEvent("postShow", postShowFun);
  631. }.bind(this);
  632. this.queryPage.addEvent("postShow", postShowFun);
  633. }else{
  634. this._loadSqlEditor();
  635. }
  636. }else{
  637. this.sqlEditor.resize();
  638. }
  639. },
  640. _loadSqlEditor: function () {
  641. if (!this.sqlEditor) {
  642. o2.require("o2.widget.JavascriptEditor", function () {
  643. this.sqlEditor = new o2.widget.JavascriptEditor(this.sqlEditorNode, {
  644. "title": "SQL",
  645. "option": {"mode": "sql"}
  646. });
  647. this.sqlEditor.load(function () {
  648. this.sqlEditor.editor.setValue(this.json.sql);
  649. this.sqlEditor.addEditorEvent("change", function () {
  650. this.data.sql = this.sqlEditor.getValue();
  651. // this.checkStatementType();
  652. }.bind(this));
  653. }.bind(this));
  654. }.bind(this), false);
  655. }
  656. },
  657. loadSqlCountEditor: function () {
  658. if (!this.sqlCountEditor) {
  659. if( !this.json.sqlCount )this.json.sqlCount = "SELECT count(id) FROM table";
  660. if( this.sqlCountEditorNode.offsetParent === null && o2.editorData.javascriptEditor.editor === "monaco" ){
  661. var postShowFun = function() {
  662. this._loadSqlCountEditor();
  663. this.countPage.removeEvent("postShow", postShowFun);
  664. }.bind(this);
  665. this.countPage.addEvent("postShow", postShowFun);
  666. }else{
  667. this._loadSqlCountEditor();
  668. }
  669. }else{
  670. // this.sqlCountEditorNode.setStyle( "height", ""+editorHeight+"px" );
  671. this.sqlCountEditor.resize();
  672. }
  673. },
  674. _loadSqlCountEditor : function(){
  675. o2.require("o2.widget.JavascriptEditor", function () {
  676. this.sqlCountEditor = new o2.widget.JavascriptEditor(this.sqlCountEditorNode, {
  677. "title": "SQL",
  678. "option": {"mode": "sql"}
  679. });
  680. this.sqlCountEditor.load(function () {
  681. this.sqlCountEditor.editor.setValue(this.json.sqlCount);
  682. this.sqlCountEditor.addEditorEvent("change", function () {
  683. this.data.sqlCount = this.sqlCountEditor.getValue();
  684. }.bind(this));
  685. }.bind(this));
  686. }.bind(this), false);
  687. },
  688. loadJpqlScriptEditor: function () {
  689. if (!this.jpqlScriptEditor) {
  690. debugger;
  691. o2.require("o2.widget.ScriptArea", function () {
  692. this.jpqlScriptEditor = new o2.widget.ScriptArea(this.jpqlScriptArea, {
  693. "isbind": false,
  694. "api": "../api/server.service.module_parameters.html#server.service.module_parameters",
  695. "maxObj": this.designer.designNode,
  696. "title": this.designer.lp.scriptTitle,
  697. "type": "service",
  698. "onChange": function () {
  699. this.json.scriptText = this.jpqlScriptEditor.toJson().code;
  700. }.bind(this)
  701. });
  702. this.jpqlScriptEditor.load({"code": this.json.scriptText})
  703. }.bind(this), false);
  704. }
  705. },
  706. loadJpqlCountScriptEditor: function () {
  707. if (!this.jpqlCountScriptEditor) {
  708. debugger;
  709. o2.require("o2.widget.ScriptArea", function () {
  710. this.jpqlCountScriptEditor = new o2.widget.ScriptArea(this.jpqlCountScriptArea, {
  711. "isbind": false,
  712. "maxObj": this.designer.designNode,
  713. "title": this.designer.lp.scriptTitle,
  714. "onChange": function () {
  715. this.json.countScriptText = this.jpqlCountScriptEditor.toJson().code;
  716. }.bind(this)
  717. });
  718. this.jpqlCountScriptEditor.load({"code": this.json.countScriptText})
  719. }.bind(this), false);
  720. }
  721. },
  722. loadSqlScriptEditor: function () {
  723. if (!this.sqlScriptEditor) {
  724. debugger;
  725. o2.require("o2.widget.ScriptArea", function () {
  726. this.sqlScriptEditor = new o2.widget.ScriptArea(this.sqlScriptArea, {
  727. "isbind": false,
  728. "api": "../api/server.service.module_parameters.html#server.service.module_parameters",
  729. "maxObj": this.designer.designNode,
  730. "title": this.designer.lp.sqlScriptTitle,
  731. "type": "service",
  732. "onChange": function () {
  733. this.json.sqlScriptText = this.sqlScriptEditor.toJson().code;
  734. }.bind(this)
  735. });
  736. this.sqlScriptEditor.load({"code": this.json.sqlScriptText})
  737. }.bind(this), false);
  738. }
  739. },
  740. loadSqlCountScriptEditor: function () {
  741. if (!this.sqlCountScriptEditor) {
  742. o2.require("o2.widget.ScriptArea", function () {
  743. this.sqlCountScriptEditor = new o2.widget.ScriptArea(this.sqlCountScriptArea, {
  744. "isbind": false,
  745. "maxObj": this.designer.designNode,
  746. "title": this.designer.lp.sqlScriptTitle,
  747. "onChange": function () {
  748. this.json.sqlCountScriptText = this.sqlCountScriptEditor.toJson().code;
  749. }.bind(this)
  750. });
  751. this.sqlCountScriptEditor.load({"code": this.json.sqlCountScriptText})
  752. }.bind(this), false);
  753. }
  754. },
  755. // setSatementTable: function () {
  756. // if (!this.json.type) this.json.type = "select";
  757. // this.changeType(this.json.type, true);
  758. // },
  759. // checkStatementType: function () {
  760. // var str = this.json.data;
  761. // this.json.data = str;
  762. // var jpql_select = /^select/i;
  763. // var jpql_update = /^update/i;
  764. // var jpql_delete = /^delete/i;
  765. // if (jpql_select.test(str)) return this.changeType("select");
  766. // if (jpql_update.test(str)) return this.changeType("update");
  767. // if (jpql_delete.test(str)) return this.changeType("delete");
  768. // },
  769. // changeType: function (type, force) {
  770. // if (this.json.type != type) this.json.type = type;
  771. // if (type != this.statementTypeSelect.options[this.statementTypeSelect.selectedIndex].value || force) {
  772. // for (var i = 0; i < this.statementTypeSelect.options.length; i++) {
  773. // if (this.statementTypeSelect.options[i].value == type) {
  774. // this.statementTypeSelect.options[i].set("selected", true);
  775. // break;
  776. // }
  777. // }
  778. // }
  779. // },
  780. loadStatementHtml: function (callback) {
  781. this.areaNode.loadAll({
  782. "css": this.path + this.options.style + "/statement.css",
  783. "html": this.path + "statementDesigner.html"
  784. }, {
  785. "bind": {"lp": this.designer.lp, "data": this.data},
  786. "module": this
  787. }, function () {
  788. if (callback) callback();
  789. }.bind(this));
  790. },
  791. addFilterSample: function(){
  792. var filterList = this.filterListEditor.editor.getValue();
  793. filterList = JSON.parse( filterList );
  794. filterList.push({
  795. "path": ["sql", "sqlScript"].contains(this.json.format) ? "xtitle" : "o.title",
  796. "comparison":"like",
  797. "value": ["sql", "sqlScript"].contains(this.json.format) ? "xtitle" : "o_title",
  798. "formatType":"textValue"
  799. });
  800. this.filterListEditor.editor.setValue( JSON.stringify(filterList, null, 4) );
  801. var parameter = this.jsonEditor.editor.getValue();
  802. parameter = JSON.parse( parameter );
  803. parameter[ ["sql", "sqlScript"].contains(this.json.format) ? "xtitle" : "o_title" ] = "%关于%";
  804. this.jsonEditor.editor.setValue( JSON.stringify(parameter, null, 4) );
  805. },
  806. loadStatementRunner: function () {
  807. o2.require("o2.widget.JavascriptEditor", function () {
  808. this.jsonEditor = new o2.widget.JavascriptEditor(this.runJsonNode, {
  809. "title": "parameter",
  810. "option": {"mode": "json"}
  811. });
  812. this.jsonEditor.load(function () {
  813. debugger;
  814. var json = JSON.parse( this.data.testParameters || "{}" );
  815. if( json.parameter )json = json.parameter;
  816. this.jsonEditor.editor.setValue( JSON.stringify(json, null, 4) );
  817. }.bind(this));
  818. this.filterListEditor = new o2.widget.JavascriptEditor(this.runFilterNode, {
  819. "title": "filterList",
  820. "option": {"mode": "json"}
  821. });
  822. this.filterListEditor.load(function () {
  823. var json = JSON.parse( this.data.testParameters || "{}" );
  824. json = json.filterList || [];
  825. this.filterListEditor.editor.setValue( JSON.stringify(json, null, 4) );
  826. }.bind(this));
  827. }.bind(this), false);
  828. },
  829. getSQLTableByEntity: function(entityClassName){
  830. switch (entityClassName) {
  831. case "com.x.processplatform.core.entity.content.Task":
  832. return "PP_C_TASK";
  833. case "com.x.processplatform.core.entity.content.TaskCompleted":
  834. return "PP_C_TASKCOMPLETED";
  835. case "com.x.processplatform.core.entity.content.Read":
  836. return "PP_C_READ";
  837. case "com.x.processplatform.core.entity.content.ReadCompleted":
  838. return "PP_C_READCOMPLETED";
  839. case "com.x.processplatform.core.entity.content.Work":
  840. return "PP_C_WORK";
  841. case "com.x.processplatform.core.entity.content.WorkCompleted":
  842. return "PP_C_WORKCOMPLETED";
  843. case "com.x.processplatform.core.entity.content.Review":
  844. return "PP_C_REVIEW";
  845. case "com.x.cms.core.entity.Document":
  846. return "CMS_DOCUMENT";
  847. }
  848. },
  849. setDynamicTableName: function(){
  850. var name = this.json.tableObj && this.json.tableObj.name;
  851. if( name ){
  852. if( ["sql", "sqlScript"].contains(this.json.format) ){
  853. name = "QRY_DYN_" + name.toUpperCase();
  854. }
  855. this.dynamicTableContent.set("text", name);
  856. }else{
  857. this.dynamicTableContent.set("text", "");
  858. }
  859. },
  860. setEvent: function () {
  861. this.designerArea.addEvent("click", function (e) {
  862. this.selected();
  863. e.stopPropagation();
  864. }.bind(this));
  865. this.formatTypeArea.getElements("input").addEvent("click", function (e) {
  866. debugger;
  867. if (e.target.checked) {
  868. var v = e.target.get("value");
  869. switch (v) {
  870. case "sql":
  871. this.jpqlOfficalTable.hide();
  872. this.sqlOfficalTable.show();
  873. this.jpqlArea.hide();
  874. this.jpqlScriptArea.hide();
  875. this.sqlArea.show();
  876. this.sqlScriptArea.hide();
  877. this.loadSqlEditor();
  878. this.jpqlCountArea.hide();
  879. this.jpqlCountScriptArea.hide();
  880. this.sqlCountArea.show();
  881. this.sqlCountScriptArea.hide();
  882. this.loadSqlCountEditor();
  883. break;
  884. case "sqlScript":
  885. this.jpqlOfficalTable.hide();
  886. this.sqlOfficalTable.show();
  887. this.jpqlArea.hide();
  888. this.jpqlScriptArea.hide();
  889. this.sqlArea.hide();
  890. this.sqlScriptArea.show();
  891. this.loadSqlScriptEditor();
  892. this.jpqlCountArea.hide();
  893. this.jpqlCountScriptArea.hide();
  894. this.sqlCountArea.hide();
  895. this.sqlCountScriptArea.show();
  896. this.loadSqlCountScriptEditor();
  897. break;
  898. case "script":
  899. this.jpqlOfficalTable.show();
  900. this.sqlOfficalTable.hide();
  901. this.jpqlArea.hide();
  902. this.jpqlScriptArea.show();
  903. this.sqlArea.hide();
  904. this.sqlScriptArea.hide();
  905. this.loadJpqlScriptEditor();
  906. this.jpqlCountArea.hide();
  907. this.jpqlCountScriptArea.show();
  908. this.sqlCountArea.hide();
  909. this.sqlCountScriptArea.hide();
  910. this.loadJpqlCountScriptEditor();
  911. break;
  912. default:
  913. this.jpqlOfficalTable.show();
  914. this.sqlOfficalTable.hide();
  915. this.jpqlArea.show();
  916. this.jpqlScriptArea.hide();
  917. this.sqlArea.hide();
  918. this.sqlScriptArea.hide();
  919. this.loadJpqlEditor();
  920. this.jpqlCountArea.show();
  921. this.jpqlCountScriptArea.hide();
  922. this.sqlCountArea.hide();
  923. this.sqlCountScriptArea.hide();
  924. this.loadJpqlCountEditor();
  925. }
  926. this.json.format = v;
  927. this.setDynamicTableName();
  928. }
  929. this.loadFieldSelect();
  930. if(this.view && this.view.property && this.view.property.viewFilter)this.view.property.viewFilter.changeStatementType();
  931. this.checkViewFilter();
  932. }.bind(this));
  933. this.entityCategorySelect.addEvent("change", function (e) {
  934. var entityCategory = e.target.options[e.target.selectedIndex].value;
  935. switch (entityCategory) {
  936. case "dynamic":
  937. this.officialTableArea.hide();
  938. this.dynamicTableArea.show();
  939. this.customTableArea.hide();
  940. break;
  941. case "custom":
  942. this.officialTableArea.hide();
  943. this.dynamicTableArea.hide();
  944. this.customTableArea.show();
  945. break;
  946. default:
  947. this.officialTableArea.show();
  948. this.dynamicTableArea.hide();
  949. this.customTableArea.hide();
  950. break;
  951. }
  952. this.json.entityCategory = entityCategory;
  953. // this.loadStatementTypeSelect();
  954. this.loadFieldSelect();
  955. if(this.view && this.view.property && this.view.property.viewFilter)this.view.property.viewFilter.setPathInputSelectOptions();
  956. }.bind(this));
  957. //@todo change table
  958. this.officialTableSelectJPQL.addEvent("change", function (e) {
  959. debugger;
  960. var entityClassName = e.target.options[e.target.selectedIndex].value;
  961. this.json.entityClassName = entityClassName;
  962. if( entityClassName ){
  963. this.changeEditorEntityClassName( entityClassName.split(".").getLast() );
  964. }
  965. this.loadFieldSelect();
  966. this.json.table = "";
  967. this.json.tableObj = null;
  968. if(this.view && this.view.property && this.view.property.viewFilter)this.view.property.viewFilter.setPathInputSelectOptions();
  969. }.bind(this));
  970. this.officialTableSelectSQL.addEvent("change", function (e) {
  971. debugger;
  972. var entityClassName = e.target.options[e.target.selectedIndex].value;
  973. this.json.entityClassName = entityClassName;
  974. if( entityClassName ){
  975. this.changeEditorEntityClassName( this.getSQLTableByEntity(entityClassName) );
  976. }
  977. this.loadFieldSelect();
  978. this.json.table = "";
  979. this.json.tableObj = null;
  980. if(this.view && this.view.property && this.view.property.viewFilter)this.view.property.viewFilter.setPathInputSelectOptions();
  981. }.bind(this));
  982. this.runActionNode.getFirst().addEvent("click", this.runStatement.bind(this));
  983. this.dynamicTableSelect.addEvent("click", this.selectTable.bind(this));
  984. // this.statementTypeSelect.addEvent("change", function () {
  985. // var t = this.statementTypeSelect.options[this.statementTypeSelect.selectedIndex].value;
  986. // if (t != this.json.type) {
  987. // this.json.type = t;
  988. // }
  989. // if (t !== "select") {
  990. // this.queryPage.showTabIm();
  991. // this.countPage.disableTab();
  992. //
  993. // this.runPage.showTabIm();
  994. // this.viewPage.disableTab();
  995. // } else {
  996. // if( this.json.countMethod === "assign" )this.countPage.enableTab(true);
  997. // this.viewPage.enableTab(true);
  998. // }
  999. // }.bind(this));
  1000. this.countMethodSelect.addEvent("change", function () {
  1001. this.json.countMethod = this.countMethodSelect.options[this.countMethodSelect.selectedIndex].value;
  1002. switch (this.json.countMethod) {
  1003. case "auto":
  1004. case "ignore":
  1005. // if (this.json.type === "select") {
  1006. this.queryPage.showTabIm();
  1007. this.countPage.disableTab();
  1008. // }
  1009. break;
  1010. // case "assign":
  1011. // break;
  1012. default:
  1013. // if (this.json.type === "select") {
  1014. this.countPage.enableTab();
  1015. // }
  1016. break;
  1017. }
  1018. }.bind(this));
  1019. this.fieldSelect.addEvent("change", function (ev) {
  1020. var option = ev.target.options[ev.target.selectedIndex];
  1021. var type = option.retrieve("type");
  1022. var field = option.retrieve("field");
  1023. if( !field )return;
  1024. var text = field.name;
  1025. if( this.countPage && this.countPage.isShow && !this.countPage.disabled ) {
  1026. if (this.data.format === "script" && this.jpqlCountScriptEditor.jsEditor) {
  1027. this.jpqlCountScriptEditor.jsEditor.insertValue(text);
  1028. } else if (this.data.format === "sqlScript" && this.sqlCountScriptEditor.jsEditor) {
  1029. this.sqlCountScriptEditor.jsEditor.insertValue(text);
  1030. } else if (this.data.format === "sql" && this.sqlCountEditor) {
  1031. this.sqlCountEditor.insertValue(text);
  1032. } else if (this.jpqlCountEditor) {
  1033. this.jpqlCountEditor.insertValue(text);
  1034. }
  1035. }else{
  1036. if( this.data.format === "script" && this.jpqlScriptEditor.jsEditor ){
  1037. this.jpqlScriptEditor.jsEditor.insertValue( text );
  1038. }else if( this.data.format === "sqlScript" && this.sqlScriptEditor.jsEditor ){
  1039. this.sqlScriptEditor.jsEditor.insertValue( text );
  1040. }else if( this.data.format === "sql" && this.sqlEditor ){
  1041. this.sqlEditor.insertValue( text );
  1042. }else if( this.jpqlEditor ) {
  1043. this.jpqlEditor.insertValue(text);
  1044. }
  1045. }
  1046. }.bind(this));
  1047. },
  1048. changeEditorEntityClassName : function( entityClassName ){
  1049. debugger;
  1050. var re, v, replaceClassName;
  1051. if (this.json.format === "jpql") {
  1052. replaceClassName = function (re, v) {
  1053. if( !re )re = /(.*from\s*)/ig;
  1054. //var re2 = /(\s+)/ig;
  1055. var arr = re.exec(v);
  1056. if (arr && arr[0]) {
  1057. var left = arr[0];
  1058. v = v.substring(left.length, v.length);
  1059. //var ar = re2.exec(v);
  1060. var right = v.substring(v.indexOf(" "), v.length);
  1061. return left + entityClassName + right;
  1062. }
  1063. return "";
  1064. };
  1065. if (this.jpqlEditor) {
  1066. // if (this.json.type === "update") re = /(.*update\s*)/ig;
  1067. v = replaceClassName( re, this.json.data);
  1068. if (v) {
  1069. this.json.data = v;
  1070. this.jpqlEditor.editor.setValue(this.json.data);
  1071. }
  1072. }
  1073. if( this.jpqlCountEditor ){
  1074. v = replaceClassName( re, this.json.countData);
  1075. if (v) {
  1076. this.json.countData = v;
  1077. this.jpqlCountEditor.editor.setValue(this.json.countData);
  1078. }
  1079. }
  1080. }else if (this.json.format === "sql") {
  1081. replaceClassName = function (re, v) {
  1082. if( !re )re = /(.*from\s*)/ig;
  1083. //var re2 = /(\s+)/ig;
  1084. var arr = re.exec(v);
  1085. if (arr && arr[0]) {
  1086. var left = arr[0];
  1087. v = v.substring(left.length, v.length);
  1088. //var ar = re2.exec(v);
  1089. var right;
  1090. if( v.indexOf(" ") > -1 ){
  1091. right = v.substring(v.indexOf(" "), v.length);
  1092. }else{
  1093. right = "";
  1094. }
  1095. return left + entityClassName + right;
  1096. }
  1097. return "";
  1098. };
  1099. if (this.sqlEditor) {
  1100. // if (this.json.type === "update") re = /(.*update\s*)/ig;
  1101. v = replaceClassName( re, this.json.sql);
  1102. if (v) {
  1103. this.json.sql = v;
  1104. this.sqlEditor.editor.setValue(this.json.sql);
  1105. }
  1106. }
  1107. if( this.sqlCountEditor ){
  1108. v = replaceClassName( re, this.json.sqlCount);
  1109. if (v) {
  1110. this.json.sqlCount = v;
  1111. this.sqlCountEditor.editor.setValue(this.json.sqlCount);
  1112. }
  1113. }
  1114. }
  1115. },
  1116. selectTable: function () {
  1117. new MWF.O2Selector(this.designer.content, {
  1118. "type": "queryTable",
  1119. "count": 1,
  1120. "values": (this.json.table) ? [this.json.table] : [],
  1121. "title": this.designer.lp.selectTable,
  1122. "onComplete": function (items) {
  1123. if (items.length) {
  1124. var id = items[0].data.id;
  1125. var name = items[0].data.name;
  1126. this.json.table = name;
  1127. this.json.tableObj = items[0].data;
  1128. if( name ){
  1129. this.json.tableObj.nativeTableName = "QRY_DYN_" + name.toUpperCase();
  1130. }
  1131. this.officialTableSelectJPQL.options[0].set("selected", true);
  1132. this.officialTableSelectSQL.options[0].set("selected", true);
  1133. this.json.entityClassName = "";
  1134. if( name && ["sql", "sqlScript"].contains(this.json.format) ){
  1135. name = "QRY_DYN_" + name.toUpperCase();
  1136. }
  1137. this.dynamicTableContent.set("text", name);
  1138. this.changeEditorEntityClassName( name );
  1139. this.loadFieldSelect();
  1140. if(this.view && this.view.property && this.view.property.viewFilter)this.view.property.viewFilter.setPathInputSelectOptions();
  1141. } else {
  1142. this.dynamicTableContent.set("text", "");
  1143. this.json.table = "";
  1144. this.loadFieldSelect();
  1145. if(this.view && this.view.property && this.view.property.viewFilter)this.view.property.viewFilter.setPathInputSelectOptions();
  1146. }
  1147. }.bind(this)
  1148. });
  1149. },
  1150. runStatement: function () {
  1151. // if (!this.json.data){
  1152. // this.designer.notice(this.designer.lp.inputStatementData, "error");
  1153. // return false;
  1154. // }
  1155. // o2.require("o2.widget.Mask", null, false);
  1156. // this.runMask = new o2.widget.Mask();
  1157. // this.runMask.loadNode(this.node);
  1158. this.saveSilence(function () {
  1159. this.execute(function (json) {
  1160. this.executeData = json;
  1161. o2.require("o2.widget.JsonParse", function () {
  1162. this.runResultNode.empty();
  1163. var jsonResult = new o2.widget.JsonParse(json, this.runResultNode);
  1164. jsonResult.load();
  1165. }.bind(this));
  1166. if (this.view) {
  1167. var flag = true;
  1168. // if (this.data.type !== "select") flag = false;
  1169. if( this.data.viewEnable === false )flag = false;
  1170. if (this.data.format === "script" && !this.data.scriptText) flag = false;
  1171. if (this.data.format === "jpql" && !this.data.data) flag = false;
  1172. if (this.data.format === "sql" && !this.data.sql) flag = false;
  1173. if (this.data.format === "sqlScript" && !this.data.sqlScriptText) flag = false;
  1174. if (flag) this.view.loadViewData();
  1175. }
  1176. this.setColumnDataPath(json);
  1177. // this.runMask.hide();
  1178. }.bind(this), function () {
  1179. // if (this.runMask) this.runMask.hide();
  1180. }.bind(this));
  1181. }.bind(this));
  1182. },
  1183. setColumnDataPath: function (json) {
  1184. // if (this.data.type !== "select") return;
  1185. if (this.data.format === "script" && !this.data.scriptText) return;
  1186. if (this.data.format === "jpql" && !this.data.data) return;
  1187. if (this.data.format === "sql" && !this.data.sql) return;
  1188. if (this.data.format === "sqlScript" && !this.data.sqlScriptText) return;
  1189. this.columnDataPathList = [];
  1190. debugger;
  1191. var addPath = function (value, key) {
  1192. if (typeOf(value) === "array") {
  1193. Array.each(value, function (v, idx) {
  1194. var path = (key || typeOf(key) === "number") ? (key + "." + idx) : idx.toString();
  1195. if (!this.columnDataPathList.contains(path)) this.columnDataPathList.push(path);
  1196. if (typeOf(v) === "array" || typeOf(v) === "object") addPath(v, path);
  1197. }.bind(this))
  1198. } else if (typeOf(value) === "object") {
  1199. Object.each(value, function (v, k) {
  1200. var path = (key || typeOf(key) === "number") ? (key + "." + k) : k;
  1201. if (!this.columnDataPathList.contains(path)) this.columnDataPathList.push(path);
  1202. if (typeOf(v) === "array" || typeOf(v) === "object") addPath(v, path);
  1203. addPath(v, path);
  1204. }.bind(this))
  1205. } else {
  1206. // if( key && !this.columnDataPathList.indexOf(key) )this.columnDataPathList.push(key);
  1207. }
  1208. }.bind(this);
  1209. for (var i = 0; i < json.data.length && i < 10; i++) {
  1210. var d = json.data[i];
  1211. addPath(d);
  1212. }
  1213. this.columnDataPathList.sort();
  1214. if (this.view && this.view.items) {
  1215. this.view.items.each(function (column) {
  1216. column.refreshColumnPathData()
  1217. })
  1218. }
  1219. },
  1220. getColumnDataPath: function () {
  1221. return this.columnDataPathList || [];
  1222. },
  1223. checkViewFilter: function(){
  1224. if( this.json.viewEnable === false )return true;
  1225. var noteFlag = false;
  1226. if (typeOf(this.viewJson) === "object" && this.viewJson.data && this.viewJson.data.customFilterList) {
  1227. this.viewJson.data.customFilterList.each(function (item) {
  1228. if (item.path) {
  1229. if (["sql", "sqlScript"].contains(this.data.format) && item.path.contains(".")) {
  1230. noteFlag = true;
  1231. }
  1232. if (!["sql", "sqlScript"].contains(this.data.format) && !item.path.contains(".")) {
  1233. noteFlag = true;
  1234. }
  1235. }
  1236. }.bind(this));
  1237. if (noteFlag) this.designer.notice(MWF.xApplication.query.StatementDesigner.LP.modifyViewFilterNote, "info");
  1238. }
  1239. return !noteFlag;
  1240. },
  1241. execute: function (success, failure) {
  1242. var json = this.jsonEditor.editor.getValue() || "{}";
  1243. var parameter = JSON.parse(json);
  1244. var filter = this.filterListEditor.editor.getValue() || "[]";
  1245. var filterList = JSON.parse(filter);
  1246. var pageNo = this.runPageNoInput.get("value").toInt();
  1247. var pageSize = this.runPageSizeInput.get("value").toInt();
  1248. var mode = "data";
  1249. // if (this.data.type === "select") {
  1250. var getMode = function (queryName, countName) {
  1251. switch (this.data.countMethod) {
  1252. case "ignore":
  1253. return this.data[queryName] ? "data" : false;
  1254. case "auto":
  1255. return this.data[queryName] ? "all" : false;
  1256. default:
  1257. if (this.data[queryName] && this.data[countName]) {
  1258. return "all";
  1259. } else if (this.data[queryName] && !this.data[countName]) {
  1260. return "data";
  1261. } else if (!this.data[queryName] && this.data[countName]) {
  1262. return "count";
  1263. } else {
  1264. return false;
  1265. }
  1266. }
  1267. }.bind(this);
  1268. switch (this.data.format) {
  1269. case "script":
  1270. mode = getMode("scriptText", "countScriptText");
  1271. break;
  1272. case "sqlScript":
  1273. mode = getMode("sqlScriptText", "sqlCountScriptText");
  1274. break;
  1275. case "sql":
  1276. mode = getMode("sql", "sqlCount");
  1277. break;
  1278. default:
  1279. mode = getMode("data", "countData");
  1280. break;
  1281. // }
  1282. if( !mode ){
  1283. this.designer.notice(this.designer.lp.inputStatementData, "error");
  1284. return false;
  1285. }
  1286. }
  1287. o2.Actions.load("x_query_assemble_designer").StatementAction.executeV2(this.json.id, mode, pageNo || 1, pageSize || 50, {
  1288. parameter: parameter,
  1289. filterList: filterList
  1290. }, function (json) {
  1291. if (success) success(json)
  1292. }.bind(this), function (xhr, text, error) {
  1293. if (failure) failure();
  1294. var errorText = error;
  1295. if (xhr) {
  1296. var json = JSON.decode(xhr.responseText);
  1297. if (json) {
  1298. errorText = json.message.trim() || "request json error";
  1299. } else {
  1300. errorText = "request json error: " + xhr.responseText;
  1301. }
  1302. }
  1303. errorText = errorText.replace(/\</g, "&lt;");
  1304. errorText = errorText.replace(/\</g, "&gt;");
  1305. MWF.xDesktop.notice("error", {x: "right", y: "top"}, errorText);
  1306. }.bind(this))
  1307. },
  1308. save: function (callback) {
  1309. if (!this.data.name) {
  1310. this.designer.notice(this.designer.lp.inputStatementName, "error");
  1311. return false;
  1312. }
  1313. if( !this.checkViewFilter() ){
  1314. return false;
  1315. }
  1316. if (typeOf(this.viewJson) === "object") {
  1317. if(this.viewJson.data && !this.viewJson.data.group)this.viewJson.data.group = {};
  1318. if(!this.viewJson.pageSize)this.viewJson.pageSize = "20";
  1319. this.data.view = JSON.stringify(this.viewJson);
  1320. }
  1321. // if (this.jpqlEditor) this.data.data = this.jpqlEditor.editor.getValue();
  1322. // if (this.jpqlScriptEditor) this.data.scriptText = this.jpqlScriptEditor.toJson().code;
  1323. var textJson = {};
  1324. if (this.jsonEditor) textJson.parameter = JSON.parse(this.jsonEditor.editor.getValue() || "{}");
  1325. if (this.filterListEditor) textJson.filterList = JSON.parse(this.filterListEditor.editor.getValue() || "[]");
  1326. this.data.testParameters = JSON.stringify(textJson);
  1327. this.designer.actions.saveStatement(this.data, function (json) {
  1328. this.designer.notice(this.designer.lp.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  1329. this.data.id = json.data.id;
  1330. if (this.lisNode) {
  1331. this.lisNode.getLast().set("text", this.data.name + "(" + this.data.alias + ")");
  1332. }
  1333. if (callback) callback();
  1334. }.bind(this));
  1335. },
  1336. _setEditStyle: function (name, input, oldValue) {
  1337. if( name === "viewEnable" && this.viewPage ){
  1338. if (this.data.viewEnable === false ) {
  1339. this.viewPage.disableTab();
  1340. } else {
  1341. this.viewPage.enableTab(true);
  1342. }
  1343. }
  1344. },
  1345. saveSilence: function (callback) {
  1346. if (!this.data.name) {
  1347. this.designer.notice(this.designer.lp.inputStatementName, "error");
  1348. return false;
  1349. }
  1350. if (typeOf(this.viewJson) === "object") {
  1351. if(this.viewJson.data && !this.viewJson.data.group)this.viewJson.data.group = {};
  1352. if( !this.viewJson.pageSize )this.viewJson.pageSize = "20";
  1353. this.data.view = JSON.stringify(this.viewJson);
  1354. }
  1355. // if (this.jpqlEditor) this.data.data = this.jpqlEditor.editor.getValue();
  1356. // if (this.jpqlScriptEditor) this.data.scriptText = this.jpqlScriptEditor.toJson().code;
  1357. // if (this.jsonEditor) this.data.testParameters = this.jsonEditor.editor.getValue();
  1358. var textJson = {};
  1359. if (this.jsonEditor) textJson.parameter = JSON.parse(this.jsonEditor.editor.getValue() || "{}");
  1360. if (this.filterListEditor) textJson.filterList = JSON.parse(this.filterListEditor.editor.getValue() || "[]");
  1361. this.data.testParameters = JSON.stringify(textJson);
  1362. this.designer.actions.saveStatement(this.data, function (json) {
  1363. //this.designer.notice(this.designer.lp.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  1364. this.data.id = json.data.id;
  1365. if (this.lisNode) {
  1366. this.lisNode.getLast().set("text", this.data.name + "(" + this.data.alias + ")");
  1367. }
  1368. if (callback) callback();
  1369. }.bind(this));
  1370. },
  1371. loadView: function (callback) {
  1372. this.setViewSize();
  1373. this.designer.addEvent("resize", this.setViewSize.bind(this));
  1374. if (!this.data.view) {
  1375. this.viewJson = {};
  1376. } else {
  1377. this.viewJson = JSON.parse(this.data.view)
  1378. }
  1379. this.view = new MWF.xApplication.query.StatementDesigner.View(this.designer, this, this.viewJson, {});
  1380. this.view.load(function () {
  1381. this.view.setContentHeight();
  1382. }.bind(this));
  1383. },
  1384. setViewSize: function () {
  1385. var size = this.areaNode.getSize();
  1386. var designerSize = this.designerArea.getComputedSize();
  1387. var reizeNodeSize = this.resizeNode.getComputedSize();
  1388. var y = size.y - designerSize.totalHeight - reizeNodeSize.totalHeight;
  1389. var mTop = this.viewArea.getStyle("margin-top").toInt();
  1390. var mBottom = this.viewArea.getStyle("margin-bottom").toInt();
  1391. var pTop = this.viewArea.getStyle("padding-top").toInt();
  1392. var pBottom = this.viewArea.getStyle("padding-bottom").toInt();
  1393. y = y - mTop - mBottom - pTop - pBottom - 1;
  1394. var tabSize = this.tabNode.getComputedSize();
  1395. y = y - tabSize.totalHeight;
  1396. this.viewArea.setStyle("height", "" + y + "px");
  1397. // var titleSize = this.runTitleNode.getComputedSize();
  1398. // y = y - titleSize.totalHeight;
  1399. // this.runContentNode.setStyle("height", ""+y+"px");
  1400. },
  1401. preview: function () {
  1402. if( this.json.viewEnable === false ){
  1403. this.designer.notice(this.designer.lp.cannotDisabledViewNotice, "error");
  1404. return;
  1405. }
  1406. if (this.isNewStatement) {
  1407. this.designer.notice(this.designer.lp.saveStatementNotice, "error");
  1408. return;
  1409. }
  1410. // if (this.data.type !== "select") {
  1411. // this.designer.notice(this.designer.lp.previewNotSelectStatementNotice, "error");
  1412. // return;
  1413. // }
  1414. if (!this.data.view) {
  1415. this.designer.notice(this.designer.lp.noViewNotice, "error");
  1416. }
  1417. this.saveSilence(function () {
  1418. var url = "../x_desktop/app.html?app=query.Query&status=";
  1419. url += JSON.stringify({
  1420. id: this.data.application,
  1421. statementId: this.data.id
  1422. });
  1423. window.open(o2.filterUrl(url), "_blank");
  1424. }.bind(this));
  1425. }
  1426. });
  1427. MWF.xApplication.query.StatementDesigner.View = new Class({
  1428. Extends: MWF.xApplication.query.ViewDesigner.View,
  1429. Implements: [Options, Events],
  1430. options: {
  1431. "style": "default",
  1432. "isView": false,
  1433. "showTab": true,
  1434. "propertyPath": "../x_component_query_StatementDesigner/$Statement/view.html"
  1435. },
  1436. initialize: function (designer, statement, data, options) {
  1437. this.setOptions(options);
  1438. this.path = "../x_component_query_ViewDesigner/$View/";
  1439. this.cssPath = "../x_component_query_ViewDesigner/$View/" + this.options.style + "/css.wcss";
  1440. this._loadCss();
  1441. this.statement = statement;
  1442. this.designer = designer;
  1443. this.data = data;
  1444. this.data.id = this.statement.data.id + "_view";
  1445. // if (!this.data.data) this.data.data = {};
  1446. this.parseData();
  1447. this.node = this.statement.viewArea;
  1448. //this.tab = this.designer.tab;
  1449. this.areaNode = new Element("div", {"styles": {"height": "calc(100% - 2px)", "overflow": "auto"}});
  1450. this.areaNode.setStyles(this.css.areaNode);
  1451. //MWF.require("MWF.widget.ScrollBar", function(){
  1452. // new MWF.widget.ScrollBar(this.areaNode, {"distance": 100});
  1453. //}.bind(this));
  1454. // this.propertyListNode = this.designer.propertyDomArea;
  1455. //this.propertyNode = this.designer.propertyContentArea;
  1456. // if(this.designer.application) this.data.applicationName = this.designer.application.name;
  1457. // if(this.designer.application) this.data.application = this.designer.application.id;
  1458. // this.isNewView = (this.data.name) ? false : true;
  1459. this.items = [];
  1460. this.view = this;
  1461. // this.autoSave();
  1462. // this.designer.addEvent("queryClose", function(){
  1463. // if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  1464. // }.bind(this));
  1465. },
  1466. load: function (callback) {
  1467. this.setAreaNodeSize();
  1468. this.designer.addEvent("resize", this.setAreaNodeSize.bind(this));
  1469. this.areaNode.inject(this.node);
  1470. this.domListNode = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.designer.propertyDomArea);
  1471. this.loadTemplateStyle(function () {
  1472. this.loadActionbar();
  1473. this.loadView();
  1474. this.loadPaging();
  1475. // this.selected();
  1476. this.setEvent();
  1477. //if (this.options.showTab) this.page.showTabIm();
  1478. this.setViewWidth();
  1479. this.designer.addEvent("resize", this.setViewWidth.bind(this));
  1480. if (callback) callback();
  1481. }.bind(this))
  1482. },
  1483. parseData: function () {
  1484. this.json = this.data;
  1485. if (!this.json.id) {
  1486. this.json.id = (new o2.widget.UUID).id;
  1487. }
  1488. if (!this.json.data || !this.json.data.events) {
  1489. var url = "../x_component_query_StatementDesigner/$Statement/view.json";
  1490. MWF.getJSON(url, {
  1491. "onSuccess": function (obj) {
  1492. if (!this.json.data) this.json.data = obj.data;
  1493. if (!this.json.data.events) this.json.data.events = obj.data.events;
  1494. }.bind(this),
  1495. "onerror": function (text) {
  1496. this.notice(text, "error");
  1497. }.bind(this),
  1498. "onRequestFailure": function (xhr) {
  1499. this.notice(xhr.responseText, "error");
  1500. }.bind(this)
  1501. }, false);
  1502. }
  1503. },
  1504. setEvent: function () {
  1505. this.areaNode.addEvents({
  1506. "click": function (e) {
  1507. this.selected();
  1508. e.stopPropagation();
  1509. }.bind(this),
  1510. "mouseover": function () {
  1511. if (!this.isSelected) this.areaNode.setStyles(this.css.areaNode_over)
  1512. }.bind(this),
  1513. "mouseout": function () {
  1514. if (!this.isSelected) this.areaNode.setStyles(this.css.areaNode)
  1515. }.bind(this)
  1516. });
  1517. this.refreshNode.addEvent("click", function (e) {
  1518. this.statement.runStatement();
  1519. e.stopPropagation();
  1520. }.bind(this));
  1521. this.addColumnNode.addEvent("click", function (e) {
  1522. this.addColumn();
  1523. e.stopPropagation();
  1524. }.bind(this));
  1525. },
  1526. selected: function () {
  1527. if (this.statement.currentSelectedModule) {
  1528. if (this.statement.currentSelectedModule == this) {
  1529. return true;
  1530. } else {
  1531. this.statement.currentSelectedModule.unSelected();
  1532. }
  1533. }
  1534. this.areaNode.setStyles(this.css.areaNode_selected);
  1535. this.statement.currentSelectedModule = this;
  1536. this.statement.selectMode = "view";
  1537. this.domListNode.show();
  1538. this.isSelected = true;
  1539. this.showProperty();
  1540. this.statement.designer.setDesignerStatementResize();
  1541. },
  1542. unSelected: function () {
  1543. this.statement.currentSelectedModule = null;
  1544. this.isSelected = false;
  1545. this.areaNode.setStyles(this.css.areaNode);
  1546. this.hideProperty();
  1547. },
  1548. showProperty: function () {
  1549. if (!this.property) {
  1550. this.property = new MWF.xApplication.query.StatementDesigner.Property(this, this.designer.propertyContentArea, this.designer, {
  1551. "path": this.options.propertyPath,
  1552. "onPostLoad": function () {
  1553. this.property.show();
  1554. }.bind(this)
  1555. });
  1556. this.property.load();
  1557. } else {
  1558. this.property.show();
  1559. }
  1560. },
  1561. hideProperty: function () {
  1562. if (this.property) this.property.hide();
  1563. },
  1564. loadViewData: function () {
  1565. if (this.data.id) {
  1566. // this.statement.saveSilence(function () {
  1567. this.viewContentBodyNode.empty();
  1568. this.viewContentTableNode = new Element("table", {
  1569. "styles": this.css.viewContentTableNode,
  1570. "border": "0px",
  1571. "cellPadding": "0",
  1572. "cellSpacing": "0"
  1573. }).inject(this.viewContentBodyNode);
  1574. // this.statement.execute( function (json) {
  1575. // this.statement.setColumnDataPath( json );
  1576. var entries = {};
  1577. this.json.data.selectList.each(function (entry) {
  1578. entries[entry.column] = entry;
  1579. }.bind(this));
  1580. if (this.statement.executeData && this.statement.executeData.data && this.statement.executeData.data.length) {
  1581. this.statement.executeData.data.each(function (line, idx) {
  1582. var tr = new Element("tr", {
  1583. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTr"] : this.css.viewContentTrNode
  1584. }).inject(this.viewContentTableNode);
  1585. //this.createViewCheckboxTd( tr );
  1586. Object.each(entries, function (c, k) {
  1587. debugger;
  1588. var path = c.path, code = c.code, obj = line;
  1589. if( path ){
  1590. var pathList = path.split(".");
  1591. for( var i=0; i<pathList.length; i++ ){
  1592. var p = pathList[i];
  1593. if( (/(^[1-9]\d*$)/.test(p)) )p = p.toInt();
  1594. if( obj[ p ] ){
  1595. obj = obj[ p ];
  1596. }else if(obj[p] === undefined || obj[p] === null) {
  1597. obj = "";
  1598. break;
  1599. } else {
  1600. obj = obj[p];
  1601. break;
  1602. }
  1603. }
  1604. }
  1605. if( code && code.trim())obj = MWF.Macro.exec( code, { "target" : {"value": obj, "data": line, "entry": c} });
  1606. var toName = function (value) {
  1607. if(typeOf(value) === "array"){
  1608. Array.each( value, function (v, idx) {
  1609. value[idx] = toName(v)
  1610. })
  1611. }else if( typeOf(value) === "object" ){
  1612. Object.each( value, function (v, key) {
  1613. value[key] = toName(v);
  1614. })
  1615. }else if( typeOf( value ) === "string" ){
  1616. value = o2.name.cn( value )
  1617. }
  1618. return value;
  1619. };
  1620. var d;
  1621. if( obj!= undefined && obj!= null ){
  1622. if( typeOf(obj) === "array" ) {
  1623. d = c.isName ? JSON.stringify(toName(Array.clone(obj))) : JSON.stringify(obj);
  1624. }else if( typeOf(obj) === "object" ){
  1625. d = c.isName ? JSON.stringify(toName(Object.clone(obj))) : JSON.stringify(obj);
  1626. }else{
  1627. d = c.isName ? o2.name.cn( obj.toString() ) : obj;
  1628. }
  1629. }
  1630. if (d != undefined && d != null ) {
  1631. var td = new Element("td", {
  1632. "styles": this.json.data.viewStyles ? this.json.data.viewStyles["contentTd"] : this.css.viewContentTdNode
  1633. }).inject(tr);
  1634. if (c.isHtml) {
  1635. td.set("html", d);
  1636. } else {
  1637. td.set("text", d);
  1638. }
  1639. }
  1640. }.bind(this));
  1641. }.bind(this));
  1642. this.setContentColumnWidth();
  1643. this.setContentHeight();
  1644. } else if (this.json.data.noDataText) {
  1645. var noDataTextNodeStyle = this.css.noDataTextNode;
  1646. if (this.json.data.viewStyles) {
  1647. if (this.json.data.viewStyles["noDataTextNode"]) {
  1648. noDataTextNodeStyle = this.json.data.viewStyles["noDataTextNode"]
  1649. } else {
  1650. this.json.data.viewStyles["noDataTextNode"] = this.css.noDataTextNode
  1651. }
  1652. }
  1653. this.noDataTextNode = new Element("div", {
  1654. "styles": noDataTextNodeStyle,
  1655. "text": this.json.data.noDataText
  1656. }).inject(this.viewContentBodyNode);
  1657. }
  1658. // }.bind(this));
  1659. // }.bind(this));
  1660. }
  1661. },
  1662. addColumn: function () {
  1663. MWF.require("MWF.widget.UUID", function () {
  1664. var id = (new MWF.widget.UUID).id;
  1665. var json = {
  1666. "id": id,
  1667. "column": id,
  1668. "displayName": this.designer.lp.unnamed,
  1669. "orderType": "original"
  1670. };
  1671. if (!this.json.data.selectList) this.json.data.selectList = [];
  1672. this.json.data.selectList.push(json);
  1673. var column = new MWF.xApplication.query.StatementDesigner.View.Column(json, this);
  1674. this.items.push(column);
  1675. column.selected();
  1676. if (this.viewContentTableNode) {
  1677. var trs = this.viewContentTableNode.getElements("tr");
  1678. trs.each(function (tr) {
  1679. new Element("td", {"styles": this.css.viewContentTdNode}).inject(tr)
  1680. }.bind(this));
  1681. //this.setContentColumnWidth();
  1682. }
  1683. this.setViewWidth();
  1684. this.addColumnNode.scrollIntoView(false);
  1685. }.bind(this));
  1686. //new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 0}).toRight();
  1687. },
  1688. setContentHeight: function () {
  1689. var size = this.areaNode.getSize();
  1690. var titleSize = this.viewTitleNode.getSize();
  1691. var actionbarSize = this.actionbarNode ? this.actionbarNode.getSize() : {x: 0, y: 0};
  1692. var pagingSize = this.pagingNode ? this.pagingNode.getSize() : {x: 0, y: 0};
  1693. var height = size.y - titleSize.y - actionbarSize.y - pagingSize.y - 4;
  1694. this.viewContentScrollNode.setStyle("height", height);
  1695. var contentSize = this.viewContentBodyNode.getSize();
  1696. if (height < contentSize.y) height = contentSize.y + 10;
  1697. this.viewContentNode.setStyle("height", height);
  1698. this.contentLeftNode.setStyle("height", height);
  1699. this.contentRightNode.setStyle("height", height);
  1700. //this.viewContentBodyNode.setStyle("min-height", height);
  1701. },
  1702. loadViewColumns: function () {
  1703. // for (var i=0; i<10; i++){
  1704. if (this.json.data.selectList) {
  1705. this.json.data.selectList.each(function (json) {
  1706. this.items.push(new MWF.xApplication.query.StatementDesigner.View.Column(json, this));
  1707. }.bind(this));
  1708. }
  1709. // }
  1710. },
  1711. showActionbar: function (noSetHeight) {
  1712. this.actionbarNode.show();
  1713. if (!this.json.data.actionbarList) this.json.data.actionbarList = [];
  1714. if (!this.actionbarList || this.actionbarList.length == 0) {
  1715. if (this.json.data.actionbarList.length) {
  1716. this.json.data.actionbarList.each(function (json) {
  1717. this.actionbarList.push(new MWF.xApplication.query.StatementDesigner.View.Actionbar(json, this.json.data.actionbarList, this))
  1718. }.bind(this));
  1719. } else {
  1720. this.actionbarList.push(new MWF.xApplication.query.StatementDesigner.View.Actionbar(null, this.json.data.actionbarList, this))
  1721. }
  1722. }
  1723. if (!noSetHeight) this.setContentHeight();
  1724. },
  1725. showPagingbar: function (noSetHeight) {
  1726. this.pagingNode.show();
  1727. if (!this.json.data.pagingList) this.json.data.pagingList = [];
  1728. if (!this.pagingList || this.pagingList.length == 0) {
  1729. if (this.json.data.pagingList.length) {
  1730. this.json.data.pagingList.each(function (json) {
  1731. this.pagingList.push(new MWF.xApplication.query.StatementDesigner.View.Paging(json, this.json.data.pagingList, this))
  1732. }.bind(this));
  1733. } else {
  1734. this.pagingList.push(new MWF.xApplication.query.StatementDesigner.View.Paging(null, this.json.data.pagingList, this))
  1735. }
  1736. }
  1737. if( !noSetHeight )this.setContentHeight();
  1738. },
  1739. setViewWidth: function () {
  1740. if (!this.viewAreaNode) return;
  1741. this.viewAreaNode.setStyle("width", "auto");
  1742. this.viewTitleNode.setStyle("width", "auto");
  1743. var s1 = this.viewTitleTableNode.getSize();
  1744. var s2 = this.refreshNode.getSize();
  1745. var s3 = this.addColumnNode.getSize();
  1746. var width = s1.x + s2.x + s2.x;
  1747. var size = this.areaNode.getSize();
  1748. if (width > size.x) {
  1749. this.viewTitleNode.setStyle("width", "" + (width - 2) + "px");
  1750. this.viewAreaNode.setStyle("width", "" + (width - 2) + "px");
  1751. } else {
  1752. this.viewTitleNode.setStyle("width", "" + (size.x - 2) + "px");
  1753. this.viewAreaNode.setStyle("width", "" + (size.x - 2) + "px");
  1754. }
  1755. this.setContentColumnWidth();
  1756. this.setContentHeight();
  1757. },
  1758. _setEditStyle: function (name, input, oldValue) {
  1759. if (name == "data.actionbarHidden") {
  1760. if (this.json.data.actionbarHidden) {
  1761. this.hideActionbar()
  1762. } else {
  1763. this.showActionbar()
  1764. }
  1765. }
  1766. if (name == "data.pagingbarHidden") {
  1767. if (this.json.data.pagingbarHidden) {
  1768. this.hidePagingbar()
  1769. } else {
  1770. this.showPagingbar()
  1771. }
  1772. }
  1773. if (name == "data.selectAllEnable") {
  1774. if (this.json.data.selectAllEnable) {
  1775. this.viewTitleTrNode.getElement(".viewTitleCheckboxTd").setStyle("display", "table-cell");
  1776. this.viewContentTableNode.getElements(".viewContentCheckboxTd").setStyle("display", "table-cell");
  1777. } else {
  1778. this.viewTitleTrNode.getElement(".viewTitleCheckboxTd").setStyle("display", "none");
  1779. this.viewContentTableNode.getElements(".viewContentCheckboxTd").setStyle("display", "none");
  1780. }
  1781. }
  1782. if (name == "data.viewStyleType") {
  1783. var file = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType].file : null;
  1784. var extendFile = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType].extendFile : null;
  1785. this.loadTemplateStyles(file, extendFile, function (templateStyles) {
  1786. this.templateStyles = templateStyles;
  1787. var oldFile, oldExtendFile;
  1788. if (oldValue && this.stylesList[oldValue]) {
  1789. oldFile = this.stylesList[oldValue].file;
  1790. oldExtendFile = this.stylesList[oldValue].extendFile;
  1791. }
  1792. this.loadTemplateStyles(oldFile, oldExtendFile, function (oldTemplateStyles) {
  1793. this.json.data.styleConfig = (this.stylesList && this.json.data.viewStyleType) ? this.stylesList[this.json.data.viewStyleType] : null;
  1794. if (oldTemplateStyles["view"]) this.clearTemplateStyles(oldTemplateStyles["view"]);
  1795. if (this.templateStyles["view"]) this.setTemplateStyles(this.templateStyles["view"]);
  1796. this.setAllStyles();
  1797. this.actionbarList.each(function (module) {
  1798. if (oldTemplateStyles["actionbar"]) {
  1799. module.clearTemplateStyles(oldTemplateStyles["actionbar"]);
  1800. }
  1801. module.setStyleTemplate();
  1802. module.setAllStyles();
  1803. })
  1804. this.pagingList.each(function (module) {
  1805. if (oldTemplateStyles["paging"]) {
  1806. module.clearTemplateStyles(oldTemplateStyles["paging"]);
  1807. }
  1808. module.setStyleTemplate();
  1809. module.setAllStyles();
  1810. });
  1811. // this.moduleList.each(function(module){
  1812. // if (oldTemplateStyles[module.moduleName]){
  1813. // module.clearTemplateStyles(oldTemplateStyles[module.moduleName]);
  1814. // }
  1815. // module.setStyleTemplate();
  1816. // module.setAllStyles();
  1817. // }.bind(this));
  1818. }.bind(this))
  1819. }.bind(this))
  1820. }
  1821. if (name == "data.viewStyles") {
  1822. this.setCustomStyles();
  1823. }
  1824. },
  1825. loadTemplateStyle: function (callback) {
  1826. this.loadStylesList(function () {
  1827. var oldStyleValue = "";
  1828. if ((!this.json.data.viewStyleType) || !this.stylesList[this.json.data.viewStyleType]) this.json.data.viewStyleType = "default";
  1829. this.loadTemplateStyles(this.stylesList[this.json.data.viewStyleType].file, this.stylesList[this.json.data.viewStyleType].extendFile,
  1830. function (templateStyles) {
  1831. this.templateStyles = templateStyles;
  1832. if (!this.json.data.viewStyleType) this.json.data.viewStyleType = "default";
  1833. if (this.templateStyles && this.templateStyles["view"]) {
  1834. var viewStyles = Object.clone(this.templateStyles["view"]);
  1835. if (viewStyles.contentGroupTd) delete viewStyles.contentGroupTd;
  1836. if (viewStyles.groupCollapseNode) delete viewStyles.groupCollapseNode;
  1837. if (viewStyles.groupExpandNode) delete viewStyles.groupExpandNode;
  1838. if (!this.json.data.viewStyles) {
  1839. this.json.data.viewStyles = viewStyles;
  1840. } else {
  1841. this.setTemplateStyles(viewStyles);
  1842. }
  1843. }
  1844. this.setCustomStyles();
  1845. if (callback) callback();
  1846. }.bind(this)
  1847. );
  1848. }.bind(this));
  1849. },
  1850. clearTemplateStyles: function (styles) {
  1851. if (styles) {
  1852. if (styles.container) this.removeStyles(styles.container, "container");
  1853. if (styles.table) this.removeStyles(styles.table, "table");
  1854. if (styles.titleTr) this.removeStyles(styles.titleTr, "titleTr");
  1855. if (styles.titleTd) this.removeStyles(styles.titleTd, "titleTd");
  1856. if (styles.contentTr) this.removeStyles(styles.contentTr, "contentTr");
  1857. if (styles.contentSelectedTr) this.removeStyles(styles.contentSelectedTr, "contentSelectedTr");
  1858. if (styles.contentTd) this.removeStyles(styles.contentTd, "contentTd");
  1859. // if (styles.contentGroupTd) this.removeStyles(styles.contentGroupTd, "contentGroupTd");
  1860. // if (styles.groupCollapseNode) this.removeStyles(styles.groupCollapseNode, "groupCollapseNode");
  1861. // if (styles.groupExpandNode) this.removeStyles(styles.groupExpandNode, "groupExpandNode");
  1862. if (styles.checkboxNode) this.removeStyles(styles.checkboxNode, "checkboxNode");
  1863. if (styles.checkedCheckboxNode) this.removeStyles(styles.checkedCheckboxNode, "checkedCheckboxNode");
  1864. if (styles.radioNode) this.removeStyles(styles.radioNode, "radioNode");
  1865. if (styles.checkedRadioNode) this.removeStyles(styles.checkedRadioNode, "checkedRadioNode");
  1866. if (styles.tableProperties) this.removeStyles(styles.tableProperties, "tableProperties");
  1867. }
  1868. },
  1869. setTemplateStyles: function (styles) {
  1870. if (styles.container) this.copyStyles(styles.container, "container");
  1871. if (styles.table) this.copyStyles(styles.table, "table");
  1872. if (styles.titleTr) this.copyStyles(styles.titleTr, "titleTr");
  1873. if (styles.titleTd) this.copyStyles(styles.titleTd, "titleTd");
  1874. if (styles.contentTr) this.copyStyles(styles.contentTr, "contentTr");
  1875. if (styles.contentSelectedTr) this.copyStyles(styles.contentSelectedTr, "contentSelectedTr");
  1876. if (styles.contentTd) this.copyStyles(styles.contentTd, "contentTd");
  1877. // if (styles.contentGroupTd) this.copyStyles(styles.contentGroupTd, "contentGroupTd");
  1878. // if (styles.groupCollapseNode) this.copyStyles(styles.groupCollapseNode, "groupCollapseNode");
  1879. // if (styles.groupExpandNode) this.copyStyles(styles.groupExpandNode, "groupExpandNode");
  1880. if (styles.checkboxNode) this.copyStyles(styles.checkboxNode, "checkboxNode");
  1881. if (styles.checkedCheckboxNode) this.copyStyles(styles.checkedCheckboxNode, "checkedCheckboxNode");
  1882. if (styles.radioNode) this.copyStyles(styles.radioNode, "radioNode");
  1883. if (styles.checkedRadioNode) this.copyStyles(styles.checkedRadioNode, "checkedRadioNode");
  1884. if (styles.tableProperties) this.copyStyles(styles.tableProperties, "tableProperties");
  1885. },
  1886. removeStyles: function (from, to) {
  1887. if (this.json.data.viewStyles[to]) {
  1888. Object.each(from, function (style, key) {
  1889. if (this.json.data.viewStyles[to][key] && this.json.data.viewStyles[to][key] == style) {
  1890. delete this.json.data.viewStyles[to][key];
  1891. }
  1892. }.bind(this));
  1893. }
  1894. },
  1895. copyStyles: function (from, to) {
  1896. if (!this.json.data.viewStyles[to]) this.json.data.viewStyles[to] = {};
  1897. Object.each(from, function (style, key) {
  1898. if (!this.json.data.viewStyles[to][key]) this.json.data.viewStyles[to][key] = style;
  1899. }.bind(this));
  1900. }
  1901. // preview: function(){
  1902. // if( this.isNewView ){
  1903. // this.designer.notice( this.designer.lp.saveViewNotice, "error" );
  1904. // return;
  1905. // }
  1906. // this.saveSilence( function () {
  1907. // var url = "../x_desktop/app.html?app=query.Query&status=";
  1908. // url += JSON.stringify({
  1909. // id : this.data.application,
  1910. // viewId : this.data.id
  1911. // });
  1912. // window.open(o2.filterUrl(url),"_blank");
  1913. // }.bind(this));
  1914. // },
  1915. // saveSilence: function(callback){
  1916. // if (!this.data.name){
  1917. // this.designer.notice(this.designer.lp.notice.inputName, "error");
  1918. // return false;
  1919. // }
  1920. //
  1921. // this.designer.actions.saveView(this.data, function(json){
  1922. // this.data.id = json.data.id;
  1923. // this.isNewView = false;
  1924. // //this.page.textNode.set("text", this.data.name);
  1925. // if (this.lisNode) {
  1926. // this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  1927. // }
  1928. // if (callback) callback();
  1929. // }.bind(this));
  1930. // },
  1931. // save: function(callback){
  1932. // //if (this.designer.tab.showPage==this.page){
  1933. // if (!this.data.name){
  1934. // this.designer.notice(this.designer.lp.notice.inputName, "error");
  1935. // return false;
  1936. // }
  1937. // //}
  1938. // this.designer.actions.saveView(this.data, function(json){
  1939. // this.designer.notice(this.designer.lp.notice.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  1940. // this.isNewView = false;
  1941. // this.data.id = json.data.id;
  1942. // //this.page.textNode.set("text", this.data.name);
  1943. // if (this.lisNode) {
  1944. // this.lisNode.getLast().set("text", this.data.name+"("+this.data.alias+")");
  1945. // }
  1946. // if (callback) callback();
  1947. // }.bind(this));
  1948. // },
  1949. // saveAs: function(){
  1950. // var form = new MWF.xApplication.query.StatementDesigner.View.NewNameForm(this, {
  1951. // name : this.data.name + "_" + MWF.xApplication.query.StatementDesigner.LP.copy,
  1952. // query : this.data.query || this.data.application,
  1953. // queryName : this.data.queryName || this.data.applicationName
  1954. // }, {
  1955. // onSave : function( data, callback ){
  1956. // this._saveAs( data, callback );
  1957. // }.bind(this)
  1958. // }, {
  1959. // app: this.designer
  1960. // });
  1961. // form.edit()
  1962. // },
  1963. // _saveAs : function( data , callback){
  1964. // var _self = this;
  1965. //
  1966. // var d = this.cloneObject( this.data );
  1967. //
  1968. // d.isNewView = true;
  1969. // d.id = this.designer.actions.getUUID();
  1970. // d.name = data.name;
  1971. // d.alias = "";
  1972. // d.query = data.query;
  1973. // d.queryName = data.queryName;
  1974. // d.application = data.query;
  1975. // d.applicationName = data.queryName;
  1976. // d.pid = d.id + d.id;
  1977. //
  1978. // delete d[this.data.id+"viewFilterType"];
  1979. // d[d.id+"viewFilterType"]="custom";
  1980. //
  1981. // d.data.selectList.each( function( entry ){
  1982. // entry.id = (new MWF.widget.UUID).id;
  1983. // }.bind(this));
  1984. //
  1985. // this.designer.actions.saveView(d, function(json){
  1986. // this.designer.notice(this.designer.lp.notice.saveAs_success, "success", this.node, {"x": "left", "y": "bottom"});
  1987. // if (callback) callback();
  1988. // }.bind(this));
  1989. // }
  1990. });
  1991. MWF.xApplication.query.StatementDesigner.View.Column = new Class({
  1992. Extends: MWF.xApplication.query.ViewDesigner.View.Column,
  1993. initialize: function (json, view, next) {
  1994. this.propertyPath = "../x_component_query_StatementDesigner/$Statement/column.html";
  1995. this.view = view;
  1996. this.json = json;
  1997. this.next = next;
  1998. this.css = this.view.css;
  1999. this.content = this.view.viewTitleTrNode;
  2000. this.domListNode = this.view.domListNode;
  2001. this.load();
  2002. },
  2003. refreshColumnPathData: function () {
  2004. if (this.property) {
  2005. this.property.loadDataPathSelect();
  2006. }
  2007. },
  2008. getColumnDataPath: function () {
  2009. return this.view.statement.getColumnDataPath();
  2010. },
  2011. showProperty: function () {
  2012. if (!this.property) {
  2013. this.property = new MWF.xApplication.query.StatementDesigner.Property(this, this.view.designer.propertyContentArea, this.view.designer, {
  2014. "path": this.propertyPath,
  2015. "onPostLoad": function () {
  2016. this.property.show();
  2017. var processDiv = this.property.propertyContent.getElements("#" + this.json.id + "dataPathSelectedProcessArea");
  2018. var cmsDiv = this.property.propertyContent.getElements("#" + this.json.id + "dataPathSelectedCMSArea");
  2019. if (this.view.json.type == "cms") {
  2020. processDiv.setStyle("display", "none");
  2021. cmsDiv.setStyle("display", "block");
  2022. } else {
  2023. processDiv.setStyle("display", "block");
  2024. cmsDiv.setStyle("display", "none");
  2025. }
  2026. }.bind(this)
  2027. });
  2028. this.property.load();
  2029. } else {
  2030. this.property.show();
  2031. }
  2032. },
  2033. selected: function () {
  2034. if (this.view.statement.currentSelectedModule) {
  2035. if (this.view.statement.currentSelectedModule == this) {
  2036. return true;
  2037. } else {
  2038. this.view.statement.currentSelectedModule.unSelected();
  2039. }
  2040. }
  2041. this.view.domListNode.show();
  2042. this.node.setStyles(this.css.viewTitleColumnNode_selected);
  2043. this.listNode.setStyles(this.css.cloumnListNode_selected);
  2044. // new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  2045. // new Fx.Scroll(this.view.designer.propertyDomArea, {
  2046. // "wheelStops": false,
  2047. // "duration": 100
  2048. // }).toElement(this.listNode);
  2049. try{
  2050. this.node.scrollIntoView(false);
  2051. this.listNode.scrollIntoView(false);
  2052. }catch (e) {
  2053. }
  2054. this.view.statement.selectMode = "viewColumn";
  2055. this.view.statement.currentSelectedModule = this;
  2056. this.isSelected = true;
  2057. this._showActions();
  2058. this.showProperty();
  2059. this.view.statement.designer.setDesignerStatementResize();
  2060. },
  2061. unSelected: function () {
  2062. this.view.statement.currentSelectedModule = null;
  2063. //this.node.setStyles(this.css.viewTitleColumnNode);
  2064. if (this.isError) {
  2065. this.node.setStyles(this.css.viewTitleColumnNode_error)
  2066. } else {
  2067. this.node.setStyles(this.css.viewTitleColumnNode)
  2068. }
  2069. this.listNode.setStyles(this.css.cloumnListNode);
  2070. this.isSelected = false;
  2071. this._hideActions();
  2072. this.hideProperty();
  2073. },
  2074. addColumn: function(e, data){
  2075. MWF.require("MWF.widget.UUID", function(){
  2076. var json;
  2077. if (data){
  2078. json = Object.clone(data);
  2079. json.id = (new MWF.widget.UUID).id;
  2080. json.column = (new MWF.widget.UUID).id;
  2081. }else{
  2082. var id = (new MWF.widget.UUID).id;
  2083. json = {
  2084. "id": id,
  2085. "column": id,
  2086. "displayName": this.view.designer.lp.unnamed,
  2087. "orderType": "original"
  2088. };
  2089. }
  2090. var idx = this.view.json.data.selectList.indexOf(this.json);
  2091. this.view.json.data.selectList.splice(idx, 0, json);
  2092. var column = new MWF.xApplication.query.StatementDesigner.View.Column(json, this.view, this);
  2093. this.view.items.splice(idx, 0, column);
  2094. column.selected();
  2095. if (this.view.viewContentTableNode){
  2096. var trs = this.view.viewContentTableNode.getElements("tr");
  2097. trs.each(function(tr){
  2098. var td = tr.insertCell(idx);
  2099. td.setStyles(this.css.viewContentTdNode);
  2100. }.bind(this));
  2101. }
  2102. this.view.setViewWidth();
  2103. }.bind(this));
  2104. }
  2105. });
  2106. MWF.xApplication.query.StatementDesigner.View.Actionbar = new Class({
  2107. Extends: MWF.xApplication.query.ViewDesigner.View.Actionbar,
  2108. initialize: function (json, jsonList, view, options) {
  2109. this.setOptions(options);
  2110. this.propertyPath = "../x_component_query_StatementDesigner/$Statement/actionbar.html";
  2111. this.path = "../x_component_query_ViewDesigner/$View/";
  2112. this.imagePath_default = "../x_component_query_ViewDesigner/$View/";
  2113. this.imagePath_custom = "../x_component_process_FormDesigner/Module/Actionbar/";
  2114. this.cssPath = "../x_component_query_ViewDesigner/$View/" + this.options.style + "/actionbar.wcss";
  2115. this.view = view;
  2116. this.json = json;
  2117. this.jsonList = jsonList;
  2118. this.css = this.view.css;
  2119. this.container = this.view.actionbarNode;
  2120. this.moduleName = "actionbar";
  2121. this.load();
  2122. },
  2123. getJsonPath: function () {
  2124. return "../x_component_query_StatementDesigner/$Statement/toolbars.json";
  2125. },
  2126. selected: function () {
  2127. if (this.view.statement.currentSelectedModule) {
  2128. if (this.view.statement.currentSelectedModule == this) {
  2129. return true;
  2130. } else {
  2131. this.view.statement.currentSelectedModule.unSelected();
  2132. }
  2133. }
  2134. this.view.domListNode.show();
  2135. this.node.setStyles(this.css.toolbarWarpNode_selected);
  2136. // new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  2137. try {
  2138. this.node.scrollIntoView(false);
  2139. }catch (e) {
  2140. }
  2141. this.view.statement.selectMode = "viewActionbar";
  2142. this.view.statement.currentSelectedModule = this;
  2143. this.isSelected = true;
  2144. //this._showActions();
  2145. this.showProperty();
  2146. this.view.statement.designer.setDesignerStatementResize();
  2147. },
  2148. unSelected: function () {
  2149. this.view.statement.currentSelectedModule = null;
  2150. this.node.setStyles(this.css.toolbarWarpNode);
  2151. //this.listNode.setStyles(this.css.cloumnListNode);
  2152. this.isSelected = false;
  2153. //this._hideActions();
  2154. this.hideProperty();
  2155. },
  2156. showProperty: function(){
  2157. if (!this.property){
  2158. this.property = new MWF.xApplication.query.StatementDesigner.Property(this, this.view.designer.propertyContentArea, this.view.designer, {
  2159. "path": this.propertyPath,
  2160. "onPostLoad": function(){
  2161. this.property.show();
  2162. }.bind(this)
  2163. });
  2164. this.property.load();
  2165. }else{
  2166. this.property.show();
  2167. }
  2168. }
  2169. });
  2170. MWF.xApplication.query.StatementDesigner.View.Paging = new Class({
  2171. Extends: MWF.xApplication.query.ViewDesigner.View.Paging,
  2172. selected: function () {
  2173. if (this.view.statement.currentSelectedModule) {
  2174. if (this.view.statement.currentSelectedModule == this) {
  2175. return true;
  2176. } else {
  2177. this.view.statement.currentSelectedModule.unSelected();
  2178. }
  2179. }
  2180. this.view.domListNode.show();
  2181. this.node.setStyles(this.css.pagingWarpNode_selected);
  2182. // new Fx.Scroll(this.view.areaNode, {"wheelStops": false, "duration": 100}).toElementEdge(this.node);
  2183. try {
  2184. this.node.scrollIntoView(false);
  2185. }catch (e) {
  2186. }
  2187. this.view.statement.selectMode = "viewPaging";
  2188. this.view.statement.currentSelectedModule = this;
  2189. this.isSelected = true;
  2190. this.showProperty();
  2191. this.view.statement.designer.setDesignerStatementResize();
  2192. },
  2193. unSelected: function () {
  2194. this.view.statement.currentSelectedModule = null;
  2195. this.node.setStyles(this.css.pagingWarpNode);
  2196. this.isSelected = false;
  2197. this.hideProperty();
  2198. }
  2199. });