Main.js 22 KB

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