Main.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  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. this.propertyDomArea = this.designerStatementArea;
  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.propertyContentArea = this.designerContentArea;
  289. this.loadDesignerStatementResize();
  290. //this.setPropertyContent();
  291. this.designerNode.addEvent("keydown", function(e){e.stopPropagation();});
  292. },
  293. loadDesignerResize: function(){
  294. this.designerResize = new Drag(this.designerResizeBar,{
  295. "snap": 1,
  296. "onStart": function(el, e){
  297. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  298. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  299. el.store("position", {"x": x, "y": y});
  300. var size = this.designerNode.getSize();
  301. el.store("initialWidth", size.x);
  302. }.bind(this),
  303. "onDrag": function(el, e){
  304. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  305. // var y = e.event.y;
  306. var bodySize = this.content.getSize();
  307. var position = el.retrieve("position");
  308. var initialWidth = el.retrieve("initialWidth").toFloat();
  309. var dx = position.x.toFloat()-x.toFloat();
  310. var width = initialWidth+dx;
  311. if (width> bodySize.x/2) width = bodySize.x/2;
  312. if (width<40) width = 40;
  313. var nodeSize = this.node.getSize();
  314. var scale = width/nodeSize.x;
  315. var scale = scale*100;
  316. this.contentNode.setStyle("margin-right", scale+"%");
  317. this.designerNode.setStyle("width", scale+"%");
  318. }.bind(this)
  319. });
  320. },
  321. loadDesignerStatementResize: function(){
  322. this.designerContentResize = new Drag(this.designerContentResizeNode, {
  323. "snap": 1,
  324. "onStart": function(el, e){
  325. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  326. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  327. el.store("position", {"x": x, "y": y});
  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. // var x = e.event.x;
  334. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  335. var position = el.retrieve("position");
  336. var dy = y.toFloat()-position.y.toFloat();
  337. var initialHeight = el.retrieve("initialHeight").toFloat();
  338. var height = initialHeight+dy;
  339. if (height<40) height = 40;
  340. if (height> size.y-40) height = size.y-40;
  341. this.designerStatementPercent = height/size.y;
  342. this.setDesignerStatementResize();
  343. }.bind(this)
  344. });
  345. },
  346. setDesignerStatementResize: function(){
  347. var size = this.designerContentNode.getSize();
  348. //var resizeNodeSize = this.designerContentResizeNode.getSize();
  349. //var height = size.y-resizeNodeSize.y;
  350. var height = size.y
  351. // var domHeight = this.designerStatementPercent*height;
  352. // var contentHeight = height-domHeight;
  353. //this.designerStatementArea.setStyle("height", ""+domHeight+"px");
  354. this.designerContentArea.setStyle("height", ""+height+"px");
  355. },
  356. //resizeNode------------------------------------------------
  357. resizeNode: function(){
  358. var nodeSize = this.node.getSize();
  359. this.contentNode.setStyle("height", ""+nodeSize.y+"px");
  360. this.designerNode.setStyle("height", ""+nodeSize.y+"px");
  361. var contentToolbarMarginTop = this.contentToolbarNode.getStyle("margin-top").toFloat();
  362. var contentToolbarMarginBottom = this.contentToolbarNode.getStyle("margin-bottom").toFloat();
  363. var allContentToolberSize = this.contentToolbarNode.getComputedSize();
  364. var y = nodeSize.y - allContentToolberSize.totalHeight - contentToolbarMarginTop - contentToolbarMarginBottom;
  365. this.editContentNode.setStyle("height", ""+y+"px");
  366. if (this.designNode){
  367. var designMarginTop = this.designNode.getStyle("margin-top").toFloat();
  368. var designMarginBottom = this.designNode.getStyle("margin-bottom").toFloat();
  369. y = nodeSize.y - allContentToolberSize.totalHeight - contentToolbarMarginTop - contentToolbarMarginBottom - designMarginTop - designMarginBottom;
  370. this.designNode.setStyle("height", ""+y+"px");
  371. }
  372. titleSize = this.designerTitleNode.getSize();
  373. titleMarginTop = this.designerTitleNode.getStyle("margin-top").toFloat();
  374. titleMarginBottom = this.designerTitleNode.getStyle("margin-bottom").toFloat();
  375. titlePaddingTop = this.designerTitleNode.getStyle("padding-top").toFloat();
  376. titlePaddingBottom = this.designerTitleNode.getStyle("padding-bottom").toFloat();
  377. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  378. y = nodeSize.y-y;
  379. this.designerContentNode.setStyle("height", ""+y+"px");
  380. this.designerResizeBar.setStyle("height", ""+y+"px");
  381. this.setDesignerStatementResize();
  382. titleSize = this.statementListTitleNode.getSize();
  383. titleMarginTop = this.statementListTitleNode.getStyle("margin-top").toFloat();
  384. titleMarginBottom = this.statementListTitleNode.getStyle("margin-bottom").toFloat();
  385. titlePaddingTop = this.statementListTitleNode.getStyle("padding-top").toFloat();
  386. titlePaddingBottom = this.statementListTitleNode.getStyle("padding-bottom").toFloat();
  387. nodeMarginTop = this.statementListAreaSccrollNode.getStyle("margin-top").toFloat();
  388. nodeMarginBottom = this.statementListAreaSccrollNode.getStyle("margin-bottom").toFloat();
  389. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom+nodeMarginTop+nodeMarginBottom;
  390. y = nodeSize.y-y;
  391. this.statementListAreaSccrollNode.setStyle("height", ""+y+"px");
  392. this.statementListResizeNode.setStyle("height", ""+y+"px");
  393. },
  394. //loadStatement------------------------------------------
  395. loadStatement: function(){
  396. debugger;
  397. this.getStatementData(this.options.id, function(vdata){
  398. this.setTitle(this.options.appTitle + "-"+vdata.name);
  399. this.taskitem.setText(this.options.appTitle + "-"+vdata.name);
  400. this.options.appTitle = this.options.appTitle + "-"+vdata.name;
  401. this.statement = new MWF.xApplication.query.StatementDesigner.Statement(this, vdata);
  402. this.statement.load();
  403. }.bind(this));
  404. },
  405. getStatementData: function(id, callback){
  406. if (!this.options.id){
  407. this.loadNewStatementData(callback);
  408. }else{
  409. this.loadStatementData(id, callback);
  410. }
  411. },
  412. loadNewStatementData: function(callback){
  413. var url = "../x_component_query_StatementDesigner/$Statement/statement.json";
  414. MWF.getJSON(url, {
  415. "onSuccess": function(obj){
  416. this.actions.getUUID(function(id){
  417. obj.id=id;
  418. obj.isNewStatement = true;
  419. obj.application = this.application.id;
  420. this.createListStatementItem(obj, true);
  421. if (callback) callback(obj);
  422. }.bind(this));
  423. }.bind(this),
  424. "onerror": function(text){
  425. this.notice(text, "error");
  426. }.bind(this),
  427. "onRequestFailure": function(xhr){
  428. this.notice(xhr.responseText, "error");
  429. }.bind(this)
  430. });
  431. },
  432. loadStatementData: function(id, callback){
  433. this.actions.getStatement(id, function(json){
  434. if (json){
  435. var data = json.data;
  436. if (!this.application){
  437. this.actions.getApplication(data.query, function(json){
  438. this.application = {"name": json.data.name, "id": json.data.id};
  439. if (callback) callback(data);
  440. }.bind(this));
  441. }else{
  442. if (callback) callback(data);
  443. }
  444. }
  445. }.bind(this));
  446. },
  447. preview : function(){
  448. this.statement.preview();
  449. },
  450. saveStatement: function(){
  451. this.statement.save(function(){
  452. var name = this.statement.data.name;
  453. this.setTitle(MWF.APPDSMD.LP.title + "-"+name);
  454. this.options.desktopReload = true;
  455. this.options.id = this.statement.data.id;
  456. }.bind(this));
  457. },
  458. statementHelp: function(){
  459. var content = new Element("div", {"styles": {"margin": "20px"}});
  460. content.set("html", this.lp.tableHelp);
  461. o2.DL.open({
  462. "title": "table help",
  463. "content": content,
  464. "width": 500,
  465. "height": 300,
  466. "buttonList": [
  467. {
  468. "text": "ok",
  469. "action": function(){this.close();}
  470. }
  471. ]
  472. });
  473. },
  474. recordStatus: function(){
  475. //if (this.tab){
  476. var openViews = [];
  477. openViews.push(this.statement.data.id);
  478. var currentId = this.statement.data.id;
  479. return {
  480. "id": this.options.id,
  481. "application": this.application,
  482. "openViews": openViews,
  483. "currentId": currentId
  484. };
  485. //}
  486. //return {"id": this.options.id, "application": this.application};
  487. }
  488. // dictionaryExplode: function(){
  489. // this.view.explode();
  490. // },
  491. // dictionaryImplode: function(){
  492. // this.view.implode();
  493. // }
  494. //recordStatus: function(){
  495. // return {"id": this.options.id};
  496. //},
  497. });