Main.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. MWF.APPDSMD = MWF.xApplication.query.StatementDesigner;
  2. MWF.APPDSMD.options = {
  3. "multitask": true,
  4. "executable": false
  5. };
  6. MWF.xDesktop.requireApp("query.StatementDesigner", "Statement", null, false);
  7. MWF.xApplication.query.StatementDesigner.Main = new Class({
  8. Extends: MWF.xApplication.Common.Main,
  9. Implements: [Options, Events],
  10. options: {
  11. "style": "default",
  12. "name": "query.StatementDesigner",
  13. "icon": "icon.png",
  14. "title": MWF.APPDSMD.LP.title,
  15. "appTitle": MWF.APPDSMD.LP.title,
  16. "id": "",
  17. "tooltip": {
  18. "unCategory": MWF.APPDSMD.LP.unCategory
  19. },
  20. "actions": null,
  21. "category": null,
  22. "processData": null,
  23. "sortKeys": ['name', 'alias', 'createTime', 'updateTime'],
  24. "sortKey": '',
  25. "listToolbarExpanded": false
  26. },
  27. onQueryLoad: function(){
  28. this.shortcut = true;
  29. if (this.status){
  30. this.options.application = this.status.applicationId;
  31. this.application = this.status.application;
  32. this.options.id = this.status.id;
  33. }
  34. if( !this.application && this.options.application ){
  35. this.application = this.options.application;
  36. }
  37. if (!this.options.id){
  38. this.options.desktopReload = false;
  39. this.options.title = this.options.title + "-"+MWF.APPDSMD.LP.newStatement;
  40. }
  41. if (!this.actions) this.actions = MWF.Actions.get("x_query_assemble_designer");
  42. this.lp = MWF.xApplication.query.StatementDesigner.LP;
  43. this.addEvent("queryClose", function(e){
  44. if (this.explorer){
  45. this.explorer.reload();
  46. }
  47. }.bind(this));
  48. },
  49. loadApplication: function(callback){
  50. this.createNode();
  51. if (!this.options.isRefresh){
  52. this.maxSize(function(){
  53. this.openStatement(function(){
  54. if (callback) callback();
  55. });
  56. }.bind(this));
  57. }else{
  58. this.openStatement(function(){
  59. if (callback) callback();
  60. });
  61. }
  62. if (!this.options.readMode) this.addKeyboardEvents();
  63. },
  64. createNode: function(){
  65. this.content.setStyle("overflow", "hidden");
  66. this.node = new Element("div", {
  67. "styles": {"width": "100%", "height": "100%", "overflow": "hidden"}
  68. }).inject(this.content);
  69. },
  70. addKeyboardEvents: function(){
  71. this.addEvent("keySave", function(e){
  72. this.keySave(e);
  73. }.bind(this));
  74. },
  75. keySave: function(e){
  76. if (this.shortcut) {
  77. this.view.save();
  78. e.preventDefault();
  79. }
  80. },
  81. getApplication:function(callback){
  82. if (!this.application){
  83. this.actions.getApplication(this.options.application, function(json){
  84. this.application = {"name": json.data.name, "id": json.data.id};
  85. if (callback) callback();
  86. }.bind(this));
  87. }else{
  88. if (callback) callback();
  89. }
  90. },
  91. openStatement: function(callback){
  92. this.getApplication(function(){
  93. this.getUd(function (){
  94. this.loadNodes();
  95. this.loadStatementListNodes();
  96. // this.loadToolbar();
  97. this.loadContentNode();
  98. this.loadProperty();
  99. // this.loadTools();
  100. this.resizeNode();
  101. this.addEvent("resize", this.resizeNode.bind(this));
  102. this.loadStatement(function(){
  103. if (callback) callback();
  104. }.bind(this));
  105. this.setScrollBar(this.designerStatementArea, null, {
  106. "V": {"x": 0, "y": 0},
  107. "H": {"x": 0, "y": 0}
  108. });
  109. }.bind(this))
  110. }.bind(this));
  111. },
  112. loadNodes: function(){
  113. this.statementListNode = new Element("div", {
  114. "styles": this.css.statementListNode
  115. }).inject(this.node);
  116. this.designerNode = new Element("div", {
  117. "styles": this.css.designerNode
  118. }).inject(this.node);
  119. this.contentNode = new Element("div", {
  120. "styles": this.css.contentNode
  121. }).inject(this.node);
  122. this.formContentNode = this.contentNode;
  123. },
  124. loadStatementListNodes: function(){
  125. this.statementListTitleNode = new Element("div", {
  126. "styles": this.css.statementListTitleNode,
  127. "text": this.lp.statement
  128. }).inject(this.statementListNode);
  129. this.statementListResizeNode = new Element("div", {"styles": this.css.statementListResizeNode}).inject(this.statementListNode);
  130. this.createListTitleNodes();
  131. this.statementListAreaSccrollNode = new Element("div", {"styles": this.css.statementListAreaSccrollNode}).inject(this.statementListNode);
  132. this.statementListAreaNode = new Element("div", {"styles": this.css.statementListAreaNode}).inject(this.statementListAreaSccrollNode);
  133. this.loadStatementListResize();
  134. this.loadStatementList();
  135. },
  136. createListTitleNodes: function (){
  137. this.statementListTitleNode.setStyle("display", 'flex');
  138. this.titleActionArea = new Element("div", {
  139. styles: this.css.titleActionArea
  140. }).inject(this.statementListTitleNode);
  141. this.moreAction = new Element("div", {
  142. styles: this.css.moreAction,
  143. title: this.lp.searchAndSort
  144. }).inject(this.titleActionArea);
  145. this.moreAction.addEvent("click", function(){
  146. var isHidden = this.toolbarNode.getStyle("display") === "none";
  147. this.toolbarNode.setStyle("display", isHidden ? "" : "none" );
  148. this.resizeNode();
  149. this.options.listToolbarExpanded = isHidden;
  150. this.setUd();
  151. }.bind(this));
  152. this.toolbarNode = new Element("div", {
  153. styles: this.css.toolbarNode
  154. }).inject(this.statementListNode);
  155. if( this.options.listToolbarExpanded )this.toolbarNode.show();
  156. this.createSortNode();
  157. this.createSearchNode();
  158. },
  159. getUd: function ( callback ){
  160. MWF.UD.getDataJson(this.options.name + "_" + this.application.id, function (data){
  161. if( data ){
  162. this.options.sortKey = data.sortKey;
  163. this.options.listToolbarExpanded = data.listToolbarExpanded || false;
  164. }
  165. callback();
  166. }.bind(this));
  167. },
  168. setUd: function (){
  169. var data = {
  170. sortKey: this.options.sortKey,
  171. listToolbarExpanded: this.options.listToolbarExpanded
  172. };
  173. MWF.UD.putData(this.options.name + "_" + this.application.id, data);
  174. },
  175. openApp: function (){
  176. layout.openApplication(null, 'query.QueryManager', {
  177. application: this.application,
  178. appId: 'query.QueryManager'+this.application.id
  179. }, {
  180. "navi":3
  181. });
  182. },
  183. createElement: function(){
  184. var options = {
  185. "application":{
  186. id: this.application.id,
  187. name: this.application.name
  188. }
  189. };
  190. layout.openApplication(null, this.options.name, options);
  191. },
  192. createSortNode: function(){
  193. this.itemSortArea = new Element("div.itemSortArea", {
  194. styles: this.css.itemSortArea
  195. }).inject(this.toolbarNode);
  196. this.itemSortSelect = new Element('select.itemSortSelect', {
  197. styles: this.css.itemSortSelect,
  198. events: {
  199. change: function(){
  200. this.options.sortKey = this.itemSortSelect[ this.itemSortSelect.selectedIndex ].value;
  201. this.setUd();
  202. this.loadStatementList();
  203. }.bind(this)
  204. }
  205. }).inject(this.itemSortArea);
  206. new Element('option',{ 'text': this.lp.sorkKeyNote, 'value': "" }).inject(this.itemSortSelect);
  207. this.options.sortKeys.each(function (key){
  208. var opt = new Element('option',{ 'text': this.lp[key] + " " + this.lp.asc, 'value': key+"-asc" }).inject(this.itemSortSelect);
  209. if( this.options.sortKey === opt.get('value') )opt.set('selected', true);
  210. opt = new Element('option',{ 'text': this.lp[key] + " " + this.lp.desc, 'value': key+"-desc" }).inject(this.itemSortSelect);
  211. if( this.options.sortKey === opt.get('value') )opt.set('selected', true);
  212. }.bind(this));
  213. },
  214. createSearchNode: function (){
  215. this.searchNode = new Element("div.searchNode", {
  216. "styles": this.css.searchArea
  217. }).inject(this.toolbarNode);
  218. this.searchInput = new Element("input.searchInput", {
  219. "styles": this.css.searchInput,
  220. "placeholder": this.lp.searchPlacholder,
  221. "value": this.options.searchKey || ""
  222. }).inject(this.searchNode);
  223. this.searchButton = new Element("i", {
  224. "styles": this.css.searchButton
  225. }).inject(this.searchNode);
  226. this.searchCancelButton = new Element("i", {
  227. "styles": this.css.searchCancelButton
  228. }).inject(this.searchNode);
  229. this.searchInput.addEvents({
  230. focus: function(){
  231. this.searchNode.addClass("mainColor_border");
  232. this.searchButton.addClass("mainColor_color");
  233. }.bind(this),
  234. blur: function () {
  235. this.searchNode.removeClass("mainColor_border");
  236. this.searchButton.removeClass("mainColor_color");
  237. }.bind(this),
  238. keydown: function (e) {
  239. if( (e.keyCode || e.code) === 13 ){
  240. this.search();
  241. }
  242. }.bind(this),
  243. keyup: function (e){
  244. this.searchCancelButton.setStyle('display', this.searchInput.get('value') ? '' : 'none');
  245. }.bind(this)
  246. });
  247. this.searchCancelButton.addEvent("click", function (e) {
  248. this.searchInput.set("value", "");
  249. this.searchCancelButton.hide();
  250. this.search();
  251. }.bind(this));
  252. this.searchButton.addEvent("click", function (e) {
  253. this.search();
  254. }.bind(this));
  255. },
  256. checkSort: function (data){
  257. if( !!this.options.sortKey ){
  258. var sortKey = this.options.sortKey.split("-");
  259. var key = sortKey[0], isDesc = sortKey[1] === 'desc';
  260. data.sort(function (a, b){
  261. var av = a[key];
  262. var bv = b[key];
  263. if( typeOf(av) === 'string' && typeOf(bv) === 'string' ){
  264. var isLetterA = /^[a-zA-Z0-9]/.test(av);
  265. var isLetterB = /^[a-zA-Z0-9]/.test(bv);
  266. if (isLetterA && !isLetterB) return isDesc ? 1 : -1; // a是字母,b不是,a排在前面
  267. if (!isLetterA && isLetterB) return isDesc ? -1 : 1; // a不是字母,b是,b排在前面
  268. return isDesc ? bv.localeCompare(av) : av.localeCompare(bv);
  269. }
  270. return isDesc ? (bv - av) : (av - bv);
  271. }.bind(this));
  272. }
  273. },
  274. checkShow: function (i){
  275. if( this.options.searchKey ){
  276. var v = this.options.searchKey;
  277. if( i.data.name.contains(v) || (i.data.alias || "").contains(v) || i.data.id.contains(v) ){
  278. //i.node.setStyle("display", "");
  279. }else{
  280. i.node.setStyle("display", "none");
  281. }
  282. }
  283. },
  284. search: function (){
  285. var v = this.searchInput.get("value");
  286. this.options.searchKey = v;
  287. this.itemArray.each(function (i){
  288. if( !v ){
  289. i.node.setStyle("display", "");
  290. }else if( i.data.name.contains(v) || (i.data.alias || "").contains(v) || i.data.id.contains(v) ){
  291. i.node.setStyle("display", "");
  292. }else{
  293. i.node.setStyle("display", "none");
  294. }
  295. }.bind(this));
  296. },
  297. loadStatementListResize: function(){
  298. this.statementListResize = new Drag(this.statementListResizeNode,{
  299. "snap": 1,
  300. "onStart": function(el, e){
  301. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  302. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  303. el.store("position", {"x": x, "y": y});
  304. var size = this.statementListAreaSccrollNode.getSize();
  305. el.store("initialWidth", size.x);
  306. }.bind(this),
  307. "onDrag": function(el, e){
  308. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  309. var bodySize = this.content.getSize();
  310. var position = el.retrieve("position");
  311. var initialWidth = el.retrieve("initialWidth").toFloat();
  312. var dx = x.toFloat() - position.x.toFloat();
  313. var width = initialWidth+dx;
  314. if (width> bodySize.x/2) width = bodySize.x/2;
  315. if (width<40) width = 40;
  316. this.contentNode.setStyle("margin-left", width+1);
  317. this.statementListNode.setStyle("width", width);
  318. }.bind(this)
  319. });
  320. this.statementListResizeNode.addEvents({
  321. "touchstart": function(e){
  322. el = e.target;
  323. var x = (Browser.name=="firefox") ? e.page.clientX : e.page.x;
  324. var y = (Browser.name=="firefox") ? e.page.clientY : e.page.y;
  325. el.store("position", {"x": x, "y": y});
  326. var size = this.statementListAreaSccrollNode.getSize();
  327. el.store("initialWidth", size.x);
  328. }.bind(this),
  329. "touchmove": function(e){
  330. el = e.target;
  331. var x = (Browser.name=="firefox") ? e.page.clientX : e.page.x;
  332. var bodySize = this.content.getSize();
  333. var position = el.retrieve("position");
  334. var initialWidth = el.retrieve("initialWidth").toFloat();
  335. var dx = x.toFloat() - position.x.toFloat();
  336. var width = initialWidth+dx;
  337. if (width> bodySize.x/2) width = bodySize.x/2;
  338. if (width<40) width = 40;
  339. this.contentNode.setStyle("margin-left", width+1);
  340. this.statementListNode.setStyle("width", width);
  341. }.bind(this)
  342. });
  343. },
  344. loadStatementList: function(){
  345. if( this.itemArray && this.itemArray.length ){
  346. this.itemArray.each(function(i){
  347. if(!i.data.isNewStatement)i.node.destroy();
  348. });
  349. }
  350. this.itemArray = [];
  351. this.actions.listStatement(this.application.id, {},function (json) {
  352. this.checkSort(json.data);
  353. json.data.each(function(statement){
  354. this.createListStatementItem(statement);
  355. }.bind(this));
  356. }.bind(this), null, false);
  357. },
  358. //列示所有查询配置列表
  359. createListStatementItem: function(statement, isNew){
  360. var _self = this;
  361. var listStatementItem = new Element("div", {"styles": this.css.listStatementItem}).inject(this.statementListAreaNode, (isNew) ? "top": "bottom");
  362. var listStatementItemIcon = new Element("div", {"styles": this.css.listStatementItemIcon}).inject(listStatementItem);
  363. var listStatementItemText = new Element("div", {"styles": this.css.listStatementItemText, "text": (statement.name) ? statement.name+" ("+statement.alias+")" : this.lp.newStatement}).inject(listStatementItem);
  364. listStatementItem.store("statement", statement);
  365. listStatementItem.addEvents({
  366. "click": function(e){_self.loadStatementByData(this, e);},
  367. "mouseover": function(){if (_self.currentListStatementItem!=this) this.setStyles(_self.css.listStatementItem_over);},
  368. "mouseout": function(){if (_self.currentListStatementItem!=this) this.setStyles(_self.css.listStatementItem);}
  369. });
  370. if( statement.id === this.options.id ){
  371. listStatementItem.setStyles(this.css.listStatementItem_current);
  372. this.currentListStatementItem = listStatementItem;
  373. }
  374. var itemObj = {
  375. node: listStatementItem,
  376. data: statement
  377. };
  378. this.itemArray.push(itemObj);
  379. this.checkShow(itemObj);
  380. },
  381. //打开查询配置
  382. loadStatementByData: function(node, e){
  383. var statement = node.retrieve("statement");
  384. if (!statement.isNewStatement){
  385. var _self = this;
  386. var options = {
  387. "appId": "query.StatementDesigner"+statement.id,
  388. "id" : statement.id,
  389. // "application": _self.application.id,
  390. "application": {
  391. "name": _self.application.name,
  392. "id": _self.application.id,
  393. },
  394. "onQueryLoad": function(){
  395. this.actions = _self.actions;
  396. this.category = _self;
  397. this.options.id = statement.id;
  398. this.application = _self.application;
  399. this.explorer = _self.explorer;
  400. }
  401. };
  402. this.desktop.openApplication(e, "query.StatementDesigner", options);
  403. }
  404. },
  405. //loadContentNode-------------------------------------------
  406. loadContentNode: function(){
  407. this.contentToolbarNode = new Element("div", {
  408. "styles": this.css.contentToolbarNode
  409. }).inject(this.contentNode);
  410. if (!this.options.readMode) this.loadContentToolbar();
  411. this.editContentNode = new Element("div", {
  412. "styles": this.css.editContentNode
  413. }).inject(this.contentNode);
  414. this.loadEditContent();
  415. // this.loadEditContent(function(){
  416. // // if (this.designDcoument) this.designDcoument.body.setStyles(this.css.designBody);
  417. // // if (this.designNode) this.designNode.setStyles(this.css.designNode);
  418. // }.bind(this));
  419. },
  420. loadContentToolbar: function(callback){
  421. this.getFormToolbarHTML(function(toolbarNode){
  422. var spans = toolbarNode.getElements("span");
  423. spans.each(function(item, idx){
  424. var img = item.get("MWFButtonImage");
  425. if (img){
  426. item.set("MWFButtonImage", this.path+""+this.options.style+"/toolbar/"+img);
  427. }
  428. }.bind(this));
  429. $(toolbarNode).inject(this.contentToolbarNode);
  430. MWF.require("MWF.widget.Toolbar", function(){
  431. this.toolbar = new MWF.widget.Toolbar(toolbarNode, {"style": "ProcessCategory"}, this);
  432. this.toolbar.load();
  433. if (this.statement) if (this.statement.checkToolbars) this.statement.checkToolbars();
  434. if (callback) callback();
  435. }.bind(this));
  436. }.bind(this));
  437. },
  438. getFormToolbarHTML: function(callback){
  439. var toolbarUrl = this.path+this.options.style+"/toolbars.html";
  440. MWF.getRequestText(toolbarUrl, function(responseText, responseXML){
  441. var htmlString = responseText;
  442. htmlString = o2.bindJson(htmlString, {"lp": this.lp.formToolbar});
  443. var temp = new Element('div').set('html', htmlString);
  444. if (callback) callback( temp.childNodes[0] );
  445. }.bind(this));
  446. },
  447. loadEditContent: function(callback){
  448. this.designNode = new Element("div.designNode", {
  449. "styles": this.css.designNode
  450. }).inject(this.editContentNode);
  451. },
  452. //loadProperty--------------------------------------
  453. loadProperty: function(){
  454. this.designerTitleNode = new Element("div", {
  455. "styles": this.css.designerTitleNode,
  456. "text": this.lp.property
  457. }).inject(this.designerNode);
  458. this.designerResizeBar = new Element("div", {
  459. "styles": this.css.designerResizeBar
  460. }).inject(this.designerNode);
  461. this.loadDesignerResize();
  462. this.designerContentNode = new Element("div.designerContentNode", {
  463. "styles": this.css.designerContentNode
  464. }).inject(this.designerNode);
  465. this.designerStatementArea = new Element("div.designerStatementArea", {
  466. "styles": this.css.designerStatementArea
  467. }).inject(this.designerContentNode);
  468. this.propertyDomArea = this.designerStatementArea;
  469. this.designerStatementPercent = 0.3;
  470. this.designerContentResizeNode = new Element("div.designerContentResizeNode", {
  471. "styles": this.css.designerContentResizeNode
  472. }).inject(this.designerContentNode);
  473. this.designerContentArea = new Element("div.designerContentArea", {
  474. "styles": this.css.designerContentArea
  475. }).inject(this.designerContentNode);
  476. this.propertyContentArea = this.designerContentArea;
  477. this.loadDesignerStatementResize();
  478. //this.setPropertyContent();
  479. this.designerNode.addEvent("keydown", function(e){e.stopPropagation();});
  480. },
  481. loadDesignerResize: function(){
  482. this.designerResize = new Drag(this.designerResizeBar,{
  483. "snap": 1,
  484. "onStart": function(el, e){
  485. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  486. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  487. el.store("position", {"x": x, "y": y});
  488. var size = this.designerNode.getSize();
  489. el.store("initialWidth", size.x);
  490. }.bind(this),
  491. "onDrag": function(el, e){
  492. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  493. // var y = e.event.y;
  494. var bodySize = this.content.getSize();
  495. var position = el.retrieve("position");
  496. var initialWidth = el.retrieve("initialWidth").toFloat();
  497. var dx = position.x.toFloat()-x.toFloat();
  498. var width = initialWidth+dx;
  499. if (width> bodySize.x/2) width = bodySize.x/2;
  500. if (width<40) width = 40;
  501. var nodeSize = this.node.getSize();
  502. var scale = width/nodeSize.x;
  503. var scale = scale*100;
  504. this.contentNode.setStyle("margin-right", scale+"%");
  505. this.designerNode.setStyle("width", scale+"%");
  506. }.bind(this)
  507. });
  508. },
  509. loadDesignerStatementResize: function(){
  510. this.designerContentResize = new Drag(this.designerContentResizeNode, {
  511. "snap": 1,
  512. "onStart": function(el, e){
  513. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  514. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  515. el.store("position", {"x": x, "y": y});
  516. var size = this.designerStatementArea.getSize();
  517. el.store("initialHeight", size.y);
  518. }.bind(this),
  519. "onDrag": function(el, e){
  520. var size = this.designerContentNode.getSize();
  521. // var x = e.event.x;
  522. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  523. var position = el.retrieve("position");
  524. var dy = y.toFloat()-position.y.toFloat();
  525. var initialHeight = el.retrieve("initialHeight").toFloat();
  526. var height = initialHeight+dy;
  527. if (height<40) height = 40;
  528. if (height> size.y-40) height = size.y-40;
  529. this.designerStatementPercent = height/size.y;
  530. this.setDesignerStatementResize();
  531. }.bind(this)
  532. });
  533. },
  534. setDesignerStatementResize: function(){
  535. var size = this.designerContentNode.getSize();
  536. var contentHeight;
  537. debugger;
  538. if( this.statement && this.statement.selectMode && this.statement.selectMode.contains("view") ){
  539. this.designerContentResizeNode.show();
  540. this.designerStatementArea.show();
  541. var resizeNodeSize = this.designerContentResizeNode.getSize();
  542. var height = size.y-resizeNodeSize.y;
  543. var domHeight = this.designerStatementPercent*height;
  544. contentHeight = height-domHeight;
  545. this.designerStatementArea.setStyle("height", ""+domHeight+"px");
  546. this.designerContentArea.setStyle("height", ""+contentHeight+"px");
  547. }else{
  548. contentHeight = size.y;
  549. this.designerContentResizeNode.hide();
  550. this.designerStatementArea.hide();
  551. this.designerContentArea.setStyle("height", ""+contentHeight+"px");
  552. }
  553. if (this.statement){
  554. if (this.statement.currentSelectedModule){
  555. if (this.statement.currentSelectedModule.property){
  556. var tab = this.statement.currentSelectedModule.property.propertyTab;
  557. if (tab){
  558. var tabTitleSize = tab.tabNodeContainer.getSize();
  559. tab.pages.each(function(page){
  560. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  561. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  562. var tabContentNodeAreaHeight = contentHeight - topMargin - bottomMargin - tabTitleSize.y.toFloat()-15;
  563. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  564. }.bind(this));
  565. }
  566. }
  567. }
  568. }
  569. },
  570. //resizeNode------------------------------------------------
  571. resizeNode: function(){
  572. var nodeSize = this.node.getSize();
  573. this.contentNode.setStyle("height", ""+nodeSize.y+"px");
  574. this.designerNode.setStyle("height", ""+nodeSize.y+"px");
  575. var contentToolbarMarginTop = this.contentToolbarNode.getStyle("margin-top").toFloat();
  576. var contentToolbarMarginBottom = this.contentToolbarNode.getStyle("margin-bottom").toFloat();
  577. var allContentToolberSize = this.contentToolbarNode.getComputedSize();
  578. var y = nodeSize.y - allContentToolberSize.totalHeight - contentToolbarMarginTop - contentToolbarMarginBottom;
  579. this.editContentNode.setStyle("height", ""+y+"px");
  580. if (this.designNode){
  581. var designMarginTop = this.designNode.getStyle("margin-top").toFloat();
  582. var designMarginBottom = this.designNode.getStyle("margin-bottom").toFloat();
  583. y = nodeSize.y - allContentToolberSize.totalHeight - contentToolbarMarginTop - contentToolbarMarginBottom - designMarginTop - designMarginBottom;
  584. this.designNode.setStyle("height", ""+y+"px");
  585. }
  586. titleSize = this.designerTitleNode.getSize();
  587. titleMarginTop = this.designerTitleNode.getStyle("margin-top").toFloat();
  588. titleMarginBottom = this.designerTitleNode.getStyle("margin-bottom").toFloat();
  589. titlePaddingTop = this.designerTitleNode.getStyle("padding-top").toFloat();
  590. titlePaddingBottom = this.designerTitleNode.getStyle("padding-bottom").toFloat();
  591. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  592. y = nodeSize.y-y;
  593. this.designerContentNode.setStyle("height", ""+y+"px");
  594. this.designerResizeBar.setStyle("height", ""+y+"px");
  595. this.setDesignerStatementResize();
  596. titleSize = this.statementListTitleNode.getSize();
  597. titleMarginTop = this.statementListTitleNode.getStyle("margin-top").toFloat();
  598. titleMarginBottom = this.statementListTitleNode.getStyle("margin-bottom").toFloat();
  599. titlePaddingTop = this.statementListTitleNode.getStyle("padding-top").toFloat();
  600. titlePaddingBottom = this.statementListTitleNode.getStyle("padding-bottom").toFloat();
  601. nodeMarginTop = this.statementListAreaSccrollNode.getStyle("margin-top").toFloat();
  602. nodeMarginBottom = this.statementListAreaSccrollNode.getStyle("margin-bottom").toFloat();
  603. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom+nodeMarginTop+nodeMarginBottom;
  604. y = nodeSize.y-y;
  605. var leftToolbarSize = this.toolbarNode ? this.toolbarNode.getSize() : {x:0,y:0};
  606. this.statementListAreaSccrollNode.setStyle("height", ""+(y-leftToolbarSize.y)+"px");
  607. this.statementListResizeNode.setStyle("height", ""+y+"px");
  608. },
  609. //loadStatement------------------------------------------
  610. loadStatement: function(callback){
  611. debugger;
  612. this.getStatementData(this.options.id, function(vdata){
  613. this.setTitle(this.options.appTitle + "-"+vdata.name);
  614. if(this.taskitem)this.taskitem.setText(this.options.appTitle + "-"+vdata.name);
  615. this.options.appTitle = this.options.appTitle + "-"+vdata.name;
  616. this.statement = new MWF.xApplication.query.StatementDesigner.Statement(this, vdata);
  617. this.statement.load();
  618. if(callback)callback()
  619. }.bind(this));
  620. },
  621. getStatementData: function(id, callback){
  622. if (!this.options.id){
  623. this.loadNewStatementData(callback);
  624. }else{
  625. this.loadStatementData(id, callback);
  626. }
  627. },
  628. loadNewStatementData: function(callback){
  629. var url = "../x_component_query_StatementDesigner/$Statement/statement.json";
  630. MWF.getJSON(url, {
  631. "onSuccess": function(obj){
  632. this.actions.getUUID(function(id){
  633. obj.id=id;
  634. obj.isNewStatement = true;
  635. obj.application = this.application.id;
  636. this.createListStatementItem(obj, true);
  637. if (callback) callback(obj);
  638. }.bind(this));
  639. }.bind(this),
  640. "onerror": function(text){
  641. this.notice(text, "error");
  642. }.bind(this),
  643. "onRequestFailure": function(xhr){
  644. this.notice(xhr.responseText, "error");
  645. }.bind(this)
  646. });
  647. },
  648. loadStatementData: function(id, callback){
  649. this.actions.getStatement(id, function(json){
  650. if (json){
  651. var data = json.data;
  652. if (!this.application){
  653. this.actions.getApplication(data.query, function(json){
  654. this.application = {"name": json.data.name, "id": json.data.id};
  655. if (callback) callback(data);
  656. }.bind(this));
  657. }else{
  658. if (callback) callback(data);
  659. }
  660. }
  661. }.bind(this));
  662. },
  663. preview : function(){
  664. this.statement.preview();
  665. },
  666. saveStatement: function(){
  667. this.statement.save(function(){
  668. var name = this.statement.data.name;
  669. this.setTitle(MWF.APPDSMD.LP.title + "-"+name);
  670. this.options.desktopReload = true;
  671. this.options.id = this.statement.data.id;
  672. }.bind(this));
  673. },
  674. saveView: function(){
  675. this.saveStatement();
  676. },
  677. saveForm: function(){
  678. this.saveStatement();
  679. },
  680. statementHelp: function(){
  681. window.open("../x_component_query_StatementDesigner/$Statement/tutorial/tutorial-statement.html", "o2statement")
  682. // var content = new Element("div", {"styles": {"margin": "20px"}});
  683. // content.set("html", this.lp.tableHelp);
  684. // o2.DL.open({
  685. // "title": "table help",
  686. // "content": content,
  687. // "width": 500,
  688. // "height": 300,
  689. // "buttonList": [
  690. // {
  691. // "text": "ok",
  692. // "action": function(){this.close();}
  693. // }
  694. // ]
  695. // });
  696. },
  697. recordStatus: function(){
  698. //if (this.tab){
  699. var openViews = [];
  700. openViews.push(this.statement.data.id);
  701. var currentId = this.statement.data.id;
  702. var application = o2.typeOf(this.application) === "object" ? {
  703. name: this.application.name,
  704. id: this.application.id
  705. } : this.application;
  706. return {
  707. "id": this.options.id,
  708. "application": application,
  709. "openViews": openViews,
  710. "currentId": currentId
  711. };
  712. //}
  713. //return {"id": this.options.id, "application": this.application};
  714. }
  715. // dictionaryExplode: function(){
  716. // this.view.explode();
  717. // },
  718. // dictionaryImplode: function(){
  719. // this.view.implode();
  720. // }
  721. //recordStatus: function(){
  722. // return {"id": this.options.id};
  723. //},
  724. });