Statement.js 111 KB

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