Main.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  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. },
  24. onQueryLoad: function(){
  25. this.shortcut = true;
  26. if (this.status){
  27. this.options.application = this.status.applicationId;
  28. this.application = this.status.application;
  29. this.options.id = this.status.id;
  30. }
  31. if (!this.options.id){
  32. this.options.desktopReload = false;
  33. this.options.title = this.options.title + "-"+MWF.APPDSMD.LP.newStatement;
  34. }
  35. if (!this.actions) this.actions = MWF.Actions.get("x_query_assemble_designer");
  36. this.lp = MWF.xApplication.query.StatementDesigner.LP;
  37. this.addEvent("queryClose", function(e){
  38. if (this.explorer){
  39. this.explorer.reload();
  40. }
  41. }.bind(this));
  42. },
  43. loadApplication: function(callback){
  44. this.createNode();
  45. if (!this.options.isRefresh){
  46. this.maxSize(function(){
  47. this.openStatement(function(){
  48. if (callback) callback();
  49. });
  50. }.bind(this));
  51. }else{
  52. this.openStatement(function(){
  53. if (callback) callback();
  54. });
  55. }
  56. if (!this.options.readMode) this.addKeyboardEvents();
  57. },
  58. createNode: function(){
  59. this.content.setStyle("overflow", "hidden");
  60. this.node = new Element("div", {
  61. "styles": {"width": "100%", "height": "100%", "overflow": "hidden"}
  62. }).inject(this.content);
  63. },
  64. addKeyboardEvents: function(){
  65. this.addEvent("keySave", function(e){
  66. this.keySave(e);
  67. }.bind(this));
  68. },
  69. keySave: function(e){
  70. if (this.shortcut) {
  71. this.view.save();
  72. e.preventDefault();
  73. }
  74. },
  75. getApplication:function(callback){
  76. if (!this.application){
  77. this.actions.getApplication(this.options.application, function(json){
  78. this.application = {"name": json.data.name, "id": json.data.id};
  79. if (callback) callback();
  80. }.bind(this));
  81. }else{
  82. if (callback) callback();
  83. }
  84. },
  85. openStatement: function(callback){
  86. this.getApplication(function(){
  87. this.loadNodes();
  88. this.loadStatementListNodes();
  89. // this.loadToolbar();
  90. this.loadContentNode();
  91. this.loadProperty();
  92. // this.loadTools();
  93. this.resizeNode();
  94. this.addEvent("resize", this.resizeNode.bind(this));
  95. this.loadStatement(function(){
  96. if (callback) callback();
  97. });
  98. // this.setScrollBar(this.designerStatementArea, null, {
  99. // "V": {"x": 0, "y": 0},
  100. // "H": {"x": 0, "y": 0}
  101. // });
  102. }.bind(this));
  103. },
  104. loadNodes: function(){
  105. this.statementListNode = new Element("div", {
  106. "styles": this.css.statementListNode
  107. }).inject(this.node);
  108. this.designerNode = new Element("div", {
  109. "styles": this.css.designerNode
  110. }).inject(this.node);
  111. this.contentNode = new Element("div", {
  112. "styles": this.css.contentNode
  113. }).inject(this.node);
  114. },
  115. loadStatementListNodes: function(){
  116. this.statementListTitleNode = new Element("div", {
  117. "styles": this.css.statementListTitleNode,
  118. "text": this.lp.statement
  119. }).inject(this.statementListNode);
  120. this.statementListResizeNode = new Element("div", {"styles": this.css.statementListResizeNode}).inject(this.statementListNode);
  121. this.statementListAreaSccrollNode = new Element("div", {"styles": this.css.statementListAreaSccrollNode}).inject(this.statementListNode);
  122. this.statementListAreaNode = new Element("div", {"styles": this.css.statementListAreaNode}).inject(this.statementListAreaSccrollNode);
  123. this.loadStatementListResize();
  124. this.loadStatementList();
  125. },
  126. loadStatementListResize: function(){
  127. this.statementListResize = new Drag(this.statementListResizeNode,{
  128. "snap": 1,
  129. "onStart": function(el, e){
  130. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  131. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  132. el.store("position", {"x": x, "y": y});
  133. var size = this.statementListAreaSccrollNode.getSize();
  134. el.store("initialWidth", size.x);
  135. }.bind(this),
  136. "onDrag": function(el, e){
  137. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  138. var bodySize = this.content.getSize();
  139. var position = el.retrieve("position");
  140. var initialWidth = el.retrieve("initialWidth").toFloat();
  141. var dx = x.toFloat() - position.x.toFloat();
  142. var width = initialWidth+dx;
  143. if (width> bodySize.x/2) width = bodySize.x/2;
  144. if (width<40) width = 40;
  145. this.contentNode.setStyle("margin-left", width+1);
  146. this.statementListNode.setStyle("width", width);
  147. }.bind(this)
  148. });
  149. this.statementListResizeNode.addEvents({
  150. "touchstart": function(e){
  151. el = e.target;
  152. var x = (Browser.name=="firefox") ? e.page.clientX : e.page.x;
  153. var y = (Browser.name=="firefox") ? e.page.clientY : e.page.y;
  154. el.store("position", {"x": x, "y": y});
  155. var size = this.statementListAreaSccrollNode.getSize();
  156. el.store("initialWidth", size.x);
  157. }.bind(this),
  158. "touchmove": function(e){
  159. el = e.target;
  160. var x = (Browser.name=="firefox") ? e.page.clientX : e.page.x;
  161. var bodySize = this.content.getSize();
  162. var position = el.retrieve("position");
  163. var initialWidth = el.retrieve("initialWidth").toFloat();
  164. var dx = x.toFloat() - position.x.toFloat();
  165. var width = initialWidth+dx;
  166. if (width> bodySize.x/2) width = bodySize.x/2;
  167. if (width<40) width = 40;
  168. this.contentNode.setStyle("margin-left", width+1);
  169. this.statementListNode.setStyle("width", width);
  170. }.bind(this)
  171. });
  172. },
  173. loadStatementList: function(){
  174. this.actions.listStatement(this.application.id, function (json) {
  175. json.data.each(function(statement){
  176. this.createListStatementItem(statement);
  177. }.bind(this));
  178. }.bind(this), null, false);
  179. },
  180. //列示所有查询配置列表
  181. createListStatementItem: function(statement, isNew){
  182. var _self = this;
  183. var listStatementItem = new Element("div", {"styles": this.css.listStatementItem}).inject(this.statementListAreaNode, (isNew) ? "top": "bottom");
  184. var listStatementItemIcon = new Element("div", {"styles": this.css.listStatementItemIcon}).inject(listStatementItem);
  185. var listStatementItemText = new Element("div", {"styles": this.css.listStatementItemText, "text": (statement.name) ? statement.name+" ("+statement.alias+")" : this.lp.newStatement}).inject(listStatementItem);
  186. listStatementItem.store("statement", statement);
  187. listStatementItem.addEvents({
  188. "dblclick": function(e){_self.loadStatementByData(this, e);},
  189. "mouseover": function(){if (_self.currentListStatementItem!=this) this.setStyles(_self.css.listStatementItem_over);},
  190. "mouseout": function(){if (_self.currentListStatementItem!=this) this.setStyles(_self.css.listStatementItem);}
  191. });
  192. },
  193. //打开查询配置
  194. loadStatementByData: function(node, e){
  195. var statement = node.retrieve("statement");
  196. if (!statement.isNewStatement){
  197. var _self = this;
  198. var options = {
  199. "appId": "query.StatementDesigner"+statement.id,
  200. "onQueryLoad": function(){
  201. this.actions = _self.actions;
  202. this.category = _self;
  203. this.options.id = statement.id;
  204. this.application = _self.application;
  205. this.explorer = _self.explorer;
  206. }
  207. };
  208. this.desktop.openApplication(e, "query.StatementDesigner", options);
  209. }
  210. },
  211. //loadContentNode-------------------------------------------
  212. loadContentNode: function(){
  213. this.contentToolbarNode = new Element("div", {
  214. "styles": this.css.contentToolbarNode
  215. }).inject(this.contentNode);
  216. if (!this.options.readMode) this.loadContentToolbar();
  217. this.editContentNode = new Element("div", {
  218. "styles": this.css.editContentNode
  219. }).inject(this.contentNode);
  220. this.loadEditContent();
  221. // this.loadEditContent(function(){
  222. // // if (this.designDcoument) this.designDcoument.body.setStyles(this.css.designBody);
  223. // // if (this.designNode) this.designNode.setStyles(this.css.designNode);
  224. // }.bind(this));
  225. },
  226. loadContentToolbar: function(callback){
  227. this.getFormToolbarHTML(function(toolbarNode){
  228. var spans = toolbarNode.getElements("span");
  229. spans.each(function(item, idx){
  230. var img = item.get("MWFButtonImage");
  231. if (img){
  232. item.set("MWFButtonImage", this.path+""+this.options.style+"/toolbar/"+img);
  233. }
  234. }.bind(this));
  235. $(toolbarNode).inject(this.contentToolbarNode);
  236. MWF.require("MWF.widget.Toolbar", function(){
  237. this.toolbar = new MWF.widget.Toolbar(toolbarNode, {"style": "ProcessCategory"}, this);
  238. this.toolbar.load();
  239. if (this.statement) if (this.statement.checkToolbars) this.statement.checkToolbars();
  240. if (callback) callback();
  241. }.bind(this));
  242. }.bind(this));
  243. },
  244. getFormToolbarHTML: function(callback){
  245. var toolbarUrl = this.path+this.options.style+"/toolbars.html";
  246. var r = new Request.HTML({
  247. url: toolbarUrl,
  248. method: "get",
  249. onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
  250. var toolbarNode = responseTree[0];
  251. if (callback) callback(toolbarNode);
  252. }.bind(this),
  253. onFailure: function(xhr){
  254. this.notice("request processToolbars error: "+xhr.responseText, "error");
  255. }.bind(this)
  256. });
  257. r.send();
  258. },
  259. loadEditContent: function(callback){
  260. this.designNode = new Element("div", {
  261. "styles": this.css.designNode
  262. }).inject(this.editContentNode);
  263. },
  264. //loadProperty--------------------------------------
  265. loadProperty: function(){
  266. this.designerTitleNode = new Element("div", {
  267. "styles": this.css.designerTitleNode,
  268. "text": this.lp.property
  269. }).inject(this.designerNode);
  270. this.designerResizeBar = new Element("div", {
  271. "styles": this.css.designerResizeBar
  272. }).inject(this.designerNode);
  273. this.loadDesignerResize();
  274. this.designerContentNode = new Element("div", {
  275. "styles": this.css.designerContentNode
  276. }).inject(this.designerNode);
  277. // this.designerStatementArea = new Element("div", {
  278. // "styles": this.css.designerStatementArea
  279. // }).inject(this.designerContentNode);
  280. //
  281. // this.designerStatementPercent = 0.6;
  282. // this.designerContentResizeNode = new Element("div", {
  283. // "styles": this.css.designerContentResizeNode
  284. // }).inject(this.designerContentNode);
  285. this.designerContentArea = new Element("div", {
  286. "styles": this.css.designerContentArea
  287. }).inject(this.designerContentNode);
  288. //this.loadDesignerStatementResize();
  289. //this.setPropertyContent();
  290. this.designerNode.addEvent("keydown", function(e){e.stopPropagation();});
  291. },
  292. loadDesignerResize: function(){
  293. this.designerResize = new Drag(this.designerResizeBar,{
  294. "snap": 1,
  295. "onStart": function(el, e){
  296. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  297. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  298. el.store("position", {"x": x, "y": y});
  299. var size = this.designerNode.getSize();
  300. el.store("initialWidth", size.x);
  301. }.bind(this),
  302. "onDrag": function(el, e){
  303. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  304. // var y = e.event.y;
  305. var bodySize = this.content.getSize();
  306. var position = el.retrieve("position");
  307. var initialWidth = el.retrieve("initialWidth").toFloat();
  308. var dx = position.x.toFloat()-x.toFloat();
  309. var width = initialWidth+dx;
  310. if (width> bodySize.x/2) width = bodySize.x/2;
  311. if (width<40) width = 40;
  312. var nodeSize = this.node.getSize();
  313. var scale = width/nodeSize.x;
  314. var scale = scale*100;
  315. this.contentNode.setStyle("margin-right", scale+"%");
  316. this.designerNode.setStyle("width", scale+"%");
  317. }.bind(this)
  318. });
  319. },
  320. // loadDesignerStatementResize: function(){
  321. // this.designerContentResize = new Drag(this.designerContentResizeNode, {
  322. // "snap": 1,
  323. // "onStart": function(el, e){
  324. // var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  325. // var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  326. // el.store("position", {"x": x, "y": y});
  327. //
  328. // var size = this.designerStatementArea.getSize();
  329. // el.store("initialHeight", size.y);
  330. // }.bind(this),
  331. // "onDrag": function(el, e){
  332. // var size = this.designerContentNode.getSize();
  333. //
  334. // // var x = e.event.x;
  335. // var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  336. // var position = el.retrieve("position");
  337. // var dy = y.toFloat()-position.y.toFloat();
  338. //
  339. // var initialHeight = el.retrieve("initialHeight").toFloat();
  340. // var height = initialHeight+dy;
  341. // if (height<40) height = 40;
  342. // if (height> size.y-40) height = size.y-40;
  343. //
  344. // this.designerStatementPercent = height/size.y;
  345. //
  346. // this.setDesignerStatementResize();
  347. //
  348. // }.bind(this)
  349. // });
  350. // },
  351. setDesignerStatementResize: function(){
  352. var size = this.designerContentNode.getSize();
  353. //var resizeNodeSize = this.designerContentResizeNode.getSize();
  354. //var height = size.y-resizeNodeSize.y;
  355. var height = size.y
  356. // var domHeight = this.designerStatementPercent*height;
  357. // var contentHeight = height-domHeight;
  358. //this.designerStatementArea.setStyle("height", ""+domHeight+"px");
  359. this.designerContentArea.setStyle("height", ""+height+"px");
  360. },
  361. //resizeNode------------------------------------------------
  362. resizeNode: function(){
  363. var nodeSize = this.node.getSize();
  364. this.contentNode.setStyle("height", ""+nodeSize.y+"px");
  365. this.designerNode.setStyle("height", ""+nodeSize.y+"px");
  366. var contentToolbarMarginTop = this.contentToolbarNode.getStyle("margin-top").toFloat();
  367. var contentToolbarMarginBottom = this.contentToolbarNode.getStyle("margin-bottom").toFloat();
  368. var allContentToolberSize = this.contentToolbarNode.getComputedSize();
  369. var y = nodeSize.y - allContentToolberSize.totalHeight - contentToolbarMarginTop - contentToolbarMarginBottom;
  370. this.editContentNode.setStyle("height", ""+y+"px");
  371. if (this.designNode){
  372. var designMarginTop = this.designNode.getStyle("margin-top").toFloat();
  373. var designMarginBottom = this.designNode.getStyle("margin-bottom").toFloat();
  374. y = nodeSize.y - allContentToolberSize.totalHeight - contentToolbarMarginTop - contentToolbarMarginBottom - designMarginTop - designMarginBottom;
  375. this.designNode.setStyle("height", ""+y+"px");
  376. }
  377. titleSize = this.designerTitleNode.getSize();
  378. titleMarginTop = this.designerTitleNode.getStyle("margin-top").toFloat();
  379. titleMarginBottom = this.designerTitleNode.getStyle("margin-bottom").toFloat();
  380. titlePaddingTop = this.designerTitleNode.getStyle("padding-top").toFloat();
  381. titlePaddingBottom = this.designerTitleNode.getStyle("padding-bottom").toFloat();
  382. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  383. y = nodeSize.y-y;
  384. this.designerContentNode.setStyle("height", ""+y+"px");
  385. this.designerResizeBar.setStyle("height", ""+y+"px");
  386. this.setDesignerStatementResize();
  387. titleSize = this.statementListTitleNode.getSize();
  388. titleMarginTop = this.statementListTitleNode.getStyle("margin-top").toFloat();
  389. titleMarginBottom = this.statementListTitleNode.getStyle("margin-bottom").toFloat();
  390. titlePaddingTop = this.statementListTitleNode.getStyle("padding-top").toFloat();
  391. titlePaddingBottom = this.statementListTitleNode.getStyle("padding-bottom").toFloat();
  392. nodeMarginTop = this.statementListAreaSccrollNode.getStyle("margin-top").toFloat();
  393. nodeMarginBottom = this.statementListAreaSccrollNode.getStyle("margin-bottom").toFloat();
  394. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom+nodeMarginTop+nodeMarginBottom;
  395. y = nodeSize.y-y;
  396. this.statementListAreaSccrollNode.setStyle("height", ""+y+"px");
  397. this.statementListResizeNode.setStyle("height", ""+y+"px");
  398. },
  399. //loadStatement------------------------------------------
  400. loadStatement: function(){
  401. debugger;
  402. this.getStatementData(this.options.id, function(vdata){
  403. this.setTitle(this.options.appTitle + "-"+vdata.name);
  404. this.taskitem.setText(this.options.appTitle + "-"+vdata.name);
  405. this.options.appTitle = this.options.appTitle + "-"+vdata.name;
  406. this.statement = new MWF.xApplication.query.StatementDesigner.Statement(this, vdata);
  407. this.statement.load();
  408. }.bind(this));
  409. },
  410. getStatementData: function(id, callback){
  411. if (!this.options.id){
  412. this.loadNewStatementData(callback);
  413. }else{
  414. this.loadStatementData(id, callback);
  415. }
  416. },
  417. loadNewStatementData: function(callback){
  418. var url = "../x_component_query_StatementDesigner/$Statement/statement.json";
  419. MWF.getJSON(url, {
  420. "onSuccess": function(obj){
  421. this.actions.getUUID(function(id){
  422. obj.id=id;
  423. obj.isNewStatement = true;
  424. obj.application = this.application.id;
  425. this.createListStatementItem(obj, true);
  426. if (callback) callback(obj);
  427. }.bind(this));
  428. }.bind(this),
  429. "onerror": function(text){
  430. this.notice(text, "error");
  431. }.bind(this),
  432. "onRequestFailure": function(xhr){
  433. this.notice(xhr.responseText, "error");
  434. }.bind(this)
  435. });
  436. },
  437. loadStatementData: function(id, callback){
  438. this.actions.getStatement(id, function(json){
  439. if (json){
  440. var data = json.data;
  441. if (!this.application){
  442. this.actions.getApplication(data.query, function(json){
  443. this.application = {"name": json.data.name, "id": json.data.id};
  444. if (callback) callback(data);
  445. }.bind(this));
  446. }else{
  447. if (callback) callback(data);
  448. }
  449. }
  450. }.bind(this));
  451. },
  452. saveStatement: function(){
  453. this.statement.save(function(){
  454. var name = this.statement.data.name;
  455. this.setTitle(MWF.APPDSMD.LP.title + "-"+name);
  456. this.options.desktopReload = true;
  457. this.options.id = this.statement.data.id;
  458. }.bind(this));
  459. },
  460. statementHelp: function(){
  461. var content = new Element("div", {"styles": {"margin": "20px"}});
  462. content.set("html", this.lp.tableHelp);
  463. o2.DL.open({
  464. "title": "table help",
  465. "content": content,
  466. "width": 500,
  467. "height": 300,
  468. "buttonList": [
  469. {
  470. "text": "ok",
  471. "action": function(){this.close();}
  472. }
  473. ]
  474. });
  475. },
  476. recordStatus: function(){
  477. //if (this.tab){
  478. var openViews = [];
  479. openViews.push(this.statement.data.id);
  480. var currentId = this.statement.data.id;
  481. return {
  482. "id": this.options.id,
  483. "application": this.application,
  484. "openViews": openViews,
  485. "currentId": currentId
  486. };
  487. //}
  488. //return {"id": this.options.id, "application": this.application};
  489. }
  490. // dictionaryExplode: function(){
  491. // this.view.explode();
  492. // },
  493. // dictionaryImplode: function(){
  494. // this.view.implode();
  495. // }
  496. //recordStatus: function(){
  497. // return {"id": this.options.id};
  498. //},
  499. });