Main.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888
  1. MWF.xApplication.query.ViewDesigner =MWF.xApplication.query.ViewDesigner || {};
  2. MWF.APPDVD = MWF.xApplication.query.ViewDesigner;
  3. MWF.APPDVD.options = {
  4. "multitask": true,
  5. "executable": false
  6. };
  7. MWF.xDesktop.requireApp("query.ViewDesigner", "View", null, false);
  8. MWF.xApplication.query.ViewDesigner.Main = new Class({
  9. Extends: MWF.xApplication.Common.Main,
  10. Implements: [Options, Events],
  11. options: {
  12. "style": "default",
  13. "name": "query.ViewDesigner",
  14. "icon": "icon.png",
  15. "title": MWF.APPDVD.LP.title,
  16. "appTitle": MWF.APPDVD.LP.title,
  17. "id": "",
  18. "tooltip": {
  19. "unCategory": MWF.APPDVD.LP.unCategory
  20. },
  21. "actions": null,
  22. "category": null,
  23. "processData": null
  24. },
  25. onQueryLoad: function(){
  26. this.shortcut = true;
  27. if (this.status){
  28. this.options.application = this.status.applicationId;
  29. this.application = this.status.application;
  30. this.options.id = this.status.id;
  31. }
  32. if( !this.application && this.options.application ){
  33. this.application = this.options.application;
  34. }
  35. if (!this.options.id){
  36. this.options.desktopReload = false;
  37. this.options.title = this.options.title + "-"+MWF.APPDVD.LP.newView;
  38. }
  39. if (!this.actions) this.actions = MWF.Actions.get("x_query_assemble_designer");
  40. this.lp = MWF.xApplication.query.ViewDesigner.LP;
  41. this.addEvent("queryClose", function(e){
  42. if (this.explorer){
  43. this.explorer.reload();
  44. }
  45. }.bind(this));
  46. this.addEvent("postLoadWindowMax", function(e){
  47. this.loadWindowOk = true;
  48. if (this.loadApplicationOk && this.loadWindowOk){
  49. //if (this.tab.showPage) {
  50. // var view = this.tab.showPage.view;
  51. // if (view) {
  52. this.view.setViewWidth();
  53. // }
  54. //}
  55. }
  56. }.bind(this));
  57. this.addEvent("postLoadApplication", function(e){
  58. this.loadApplicationOk = true;
  59. if (this.loadApplicationOk && this.loadWindowOk){
  60. //if (this.tab.showPage) {
  61. // var view = this.tab.showPage.view;
  62. // if (view) {
  63. this.view.setViewWidth();
  64. // }
  65. //}
  66. }
  67. }.bind(this));
  68. },
  69. loadApplication: function(callback){
  70. this.createNode();
  71. if (!this.options.isRefresh){
  72. this.maxSize(function(){
  73. this.openView(function(){
  74. if (callback) callback();
  75. });
  76. }.bind(this));
  77. }else{
  78. this.openView(function(){
  79. if (callback) callback();
  80. });
  81. }
  82. if (!this.options.readMode) this.addKeyboardEvents();
  83. },
  84. addKeyboardEvents: function(){
  85. this.addEvent("copy", function(){
  86. this.copyModule();
  87. }.bind(this));
  88. this.addEvent("paste", function(){
  89. this.pasteModule();
  90. }.bind(this));
  91. this.addEvent("cut", function(){
  92. this.cutModule();
  93. }.bind(this));
  94. this.addEvent("keySave", function(e){
  95. this.keySave(e);
  96. }.bind(this));
  97. this.addEvent("keyDelete", function(e){
  98. this.keyDelete(e);
  99. }.bind(this));
  100. },
  101. keySave: function(e){
  102. if (this.shortcut) {
  103. //if (this.tab.showPage) {
  104. // var view = this.tab.showPage.view;
  105. // if (view) {
  106. this.view.save();
  107. e.preventDefault();
  108. // }
  109. //}
  110. }
  111. },
  112. keyDelete: function(){
  113. if (this.shortcut) {
  114. //if (this.tab.showPage) {
  115. //var view = this.tab.showPage.view;
  116. //if (view) {
  117. if (this.view.currentSelectedModule) {
  118. var item = this.view.currentSelectedModule;
  119. item["delete"]();
  120. }
  121. //}
  122. //}
  123. }
  124. },
  125. copyModule: function(){
  126. if (this.shortcut) {
  127. //if (this.tab.showPage) {
  128. //var view = this.tab.showPage.view;
  129. //if (view) {
  130. if (this.view.currentSelectedModule) {
  131. var item = this.view.currentSelectedModule;
  132. MWF.clipboard.data = {
  133. "type": "view",
  134. "data": item.json
  135. };
  136. }
  137. //}
  138. //}
  139. }
  140. },
  141. cutModule: function(){
  142. if (this.shortcut) {
  143. //if (this.tab.showPage) {
  144. //var view = this.tab.showPage.view;
  145. //if (view) {
  146. if (this.view.currentSelectedModule) {
  147. this.copyModule();
  148. var item = this.view.currentSelectedModule;
  149. item.destroy();
  150. }
  151. //}
  152. //}
  153. }
  154. },
  155. pasteModule: function(){
  156. if (this.shortcut) {
  157. if (MWF.clipboard.data) {
  158. if (MWF.clipboard.data.type == "view") {
  159. //if (this.tab.showPage) {
  160. //var view = this.tab.showPage.view;
  161. //if (view) {
  162. if (this.view.currentSelectedModule) {
  163. var item = this.view.currentSelectedModule;
  164. var data = MWF.clipboard.data.data;
  165. item.addColumn(null, data);
  166. }
  167. //}
  168. //}
  169. }
  170. }
  171. }
  172. },
  173. createNode: function(){
  174. this.content.setStyle("overflow", "hidden");
  175. this.node = new Element("div", {
  176. "styles": {"width": "100%", "height": "100%", "overflow": "hidden"}
  177. }).inject(this.content);
  178. },
  179. getApplication:function(callback){
  180. if (!this.application){
  181. var app = typeOf(this.options.application) === "string" ? this.options.application : this.options.application.id;
  182. this.actions.getApplication((app), function(json){
  183. this.application = {"name": json.data.name, "id": json.data.id};
  184. if (callback) callback();
  185. }.bind(this));
  186. }else{
  187. if (callback) callback();
  188. }
  189. },
  190. openView: function(callback){
  191. this.getApplication(function(){
  192. this.initOptions();
  193. this.loadNodes();
  194. this.loadViewListNodes();
  195. // this.loadToolbar();
  196. this.loadContentNode();
  197. this.loadProperty();
  198. // this.loadTools();
  199. this.resizeNode();
  200. this.addEvent("resize", this.resizeNode.bind(this));
  201. this.loadView(function(){
  202. if (callback) callback();
  203. });
  204. this.setScrollBar(this.propertyDomArea, null, {
  205. "V": {"x": 0, "y": 0},
  206. "H": {"x": 0, "y": 0}
  207. });
  208. }.bind(this));
  209. },
  210. initOptions: function(){
  211. //this.toolsData = null;
  212. //this.toolbarMode = "all";
  213. //this.tools = [];
  214. //this.toolbarDecrease = 0;
  215. //
  216. //this.designNode = null;
  217. //this.form = null;
  218. },
  219. loadNodes: function(){
  220. this.viewListNode = new Element("div", {
  221. "styles": this.css.viewListNode
  222. }).inject(this.node);
  223. this.propertyNode = new Element("div", {
  224. "styles": this.css.propertyNode
  225. }).inject(this.node);
  226. this.contentNode = new Element("div", {
  227. "styles": this.css.contentNode
  228. }).inject(this.node);
  229. this.formContentNode = this.contentNode;
  230. },
  231. //loadViewListNodes-------------------------------
  232. loadViewListNodes: function(){
  233. this.viewListTitleNode = new Element("div", {
  234. "styles": this.css.viewListTitleNode,
  235. "text": MWF.APPDVD.LP.view
  236. }).inject(this.viewListNode);
  237. this.viewListResizeNode = new Element("div", {"styles": this.css.viewListResizeNode}).inject(this.viewListNode);
  238. this.viewListAreaSccrollNode = new Element("div", {"styles": this.css.viewListAreaSccrollNode}).inject(this.viewListNode);
  239. this.viewListAreaNode = new Element("div", {"styles": this.css.viewListAreaNode}).inject(this.viewListAreaSccrollNode);
  240. this.loadViewListResize();
  241. this.loadViewList();
  242. },
  243. loadViewListResize: function(){
  244. this.viewListResize = new Drag(this.viewListResizeNode,{
  245. "snap": 1,
  246. "onStart": function(el, e){
  247. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  248. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  249. el.store("position", {"x": x, "y": y});
  250. var size = this.viewListAreaSccrollNode.getSize();
  251. el.store("initialWidth", size.x);
  252. }.bind(this),
  253. "onDrag": function(el, e){
  254. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  255. // var y = e.event.y;
  256. var bodySize = this.content.getSize();
  257. var position = el.retrieve("position");
  258. var initialWidth = el.retrieve("initialWidth").toFloat();
  259. var dx = x.toFloat() - position.x.toFloat();
  260. var width = initialWidth+dx;
  261. if (width> bodySize.x/2) width = bodySize.x/2;
  262. if (width<40) width = 40;
  263. this.contentNode.setStyle("margin-left", width+1);
  264. this.viewListNode.setStyle("width", width);
  265. //this.tab.pages.each(function(page){
  266. (this.view || this.table).setViewWidth();
  267. //});
  268. }.bind(this)
  269. });
  270. this.viewListResizeNode.addEvents({
  271. "touchstart": function(e){
  272. el = e.target;
  273. var x = (Browser.name=="firefox") ? e.page.clientX : e.page.x;
  274. var y = (Browser.name=="firefox") ? e.page.clientY : e.page.y;
  275. el.store("position", {"x": x, "y": y});
  276. var size = this.viewListAreaSccrollNode.getSize();
  277. el.store("initialWidth", size.x);
  278. }.bind(this),
  279. "touchmove": function(e){
  280. //Object.each(e, function(v, k){
  281. // alert(k+": "+ v);
  282. //});
  283. el = e.target;
  284. var x = (Browser.name=="firefox") ? e.page.clientX : e.page.x;
  285. // var y = e.event.y;
  286. var bodySize = this.content.getSize();
  287. var position = el.retrieve("position");
  288. var initialWidth = el.retrieve("initialWidth").toFloat();
  289. var dx = x.toFloat() - position.x.toFloat();
  290. var width = initialWidth+dx;
  291. if (width> bodySize.x/2) width = bodySize.x/2;
  292. if (width<40) width = 40;
  293. this.contentNode.setStyle("margin-left", width+1);
  294. this.viewListNode.setStyle("width", width);
  295. //this.tab.pages.each(function(page){
  296. (this.view || this.table).setViewWidth();
  297. //});
  298. }.bind(this)
  299. });
  300. },
  301. loadViewList: function(){
  302. this.actions.listView(this.application.id, function (json) {
  303. json.data.each(function(view){
  304. this.createListViewItem(view);
  305. }.bind(this));
  306. }.bind(this), null, false);
  307. },
  308. //列示所有视图列表
  309. createListViewItem: function(view, isNew){
  310. var _self = this;
  311. var listViewItem = new Element("div", {"styles": this.css.listViewItem}).inject(this.viewListAreaNode, (isNew) ? "top": "bottom");
  312. var listViewItemIcon = new Element("div", {"styles": this.css.listViewItemIcon}).inject(listViewItem);
  313. var listViewItemText = new Element("div", {"styles": this.css.listViewItemText, "text": (view.name) ? view.name+" ("+view.alias+")" : this.lp.newView}).inject(listViewItem);
  314. listViewItem.store("view", view);
  315. listViewItem.addEvents({
  316. "click": function(e){_self.loadViewByData(this, e);},
  317. "mouseover": function(){if (_self.currentListViewItem!=this) this.setStyles(_self.css.listViewItem_over);},
  318. "mouseout": function(){if (_self.currentListViewItem!=this) this.setStyles(_self.css.listViewItem);}
  319. });
  320. },
  321. //打开视图
  322. loadViewByData: function(node, e){
  323. var view = node.retrieve("view");
  324. if (!view.isNewView){
  325. var openNew = true;
  326. //for (var i = 0; i<this.tab.pages.length; i++){
  327. // if (view.id==this.tab.pages[i].view.data.id){
  328. // this.tab.pages[i].showTabIm();
  329. // openNew = false;
  330. // break;
  331. // }
  332. //}
  333. if (openNew){
  334. //this.loadViewData(view.id, function(vdata){
  335. // var view = new MWF.xApplication.process.ViewDesigner.View(this, vdata);
  336. // view.load();
  337. //}.bind(this));
  338. var _self = this;
  339. var options = {
  340. "appId": "query.ViewDesigner"+view.id,
  341. "id": view.id,
  342. // "application": _self.application.id,
  343. "application": {
  344. "name": _self.application.name,
  345. "id": _self.application.id,
  346. },
  347. "onQueryLoad": function(){
  348. this.actions = _self.actions;
  349. this.category = _self;
  350. this.options.id = view.id;
  351. this.application = _self.application;
  352. this.explorer = _self.explorer;
  353. }
  354. };
  355. this.desktop.openApplication(e, "query.ViewDesigner", options);
  356. }
  357. }
  358. },
  359. //loadContentNode------------------------------
  360. loadContentNode: function(){
  361. this.contentToolbarNode = new Element("div", {
  362. "styles": this.css.contentToolbarNode
  363. }).inject(this.contentNode);
  364. if (!this.options.readMode) this.loadContentToolbar();
  365. this.editContentNode = new Element("div", {
  366. "styles": this.css.editContentNode
  367. }).inject(this.contentNode);
  368. this.loadEditContent(function(){
  369. // if (this.designDcoument) this.designDcoument.body.setStyles(this.css.designBody);
  370. if (this.designNode) this.designNode.setStyles(this.css.designNode);
  371. }.bind(this));
  372. },
  373. loadContentToolbar: function(callback){
  374. this.getFormToolbarHTML(function(toolbarNode){
  375. var spans = toolbarNode.getElements("span");
  376. spans.each(function(item, idx){
  377. var img = item.get("MWFButtonImage");
  378. if (img){
  379. item.set("MWFButtonImage", this.path+""+this.options.style+"/toolbar/"+img);
  380. }
  381. }.bind(this));
  382. $(toolbarNode).inject(this.contentToolbarNode);
  383. MWF.require("MWF.widget.Toolbar", function(){
  384. this.toolbar = new MWF.widget.Toolbar(toolbarNode, {"style": "ProcessCategory"}, this);
  385. this.toolbar.load();
  386. if (this.table) if (this.table.checkToolbars) this.table.checkToolbars();
  387. if (callback) callback();
  388. }.bind(this));
  389. }.bind(this));
  390. },
  391. getFormToolbarHTML: function(callback){
  392. var toolbarUrl = this.path+this.options.style+"/toolbars.html";
  393. MWF.getRequestText(toolbarUrl, function(responseText, responseXML){
  394. var htmlString = responseText;
  395. htmlString = o2.bindJson(htmlString, {"lp": this.lp.formToolbar});
  396. var temp = new Element('div').set('html', htmlString);
  397. if (callback) callback( temp.childNodes[0] );
  398. }.bind(this));
  399. },
  400. maxOrReturnEditor: function(){
  401. if (!this.isMax){
  402. this.designNode.inject(this.node);
  403. this.designNode.setStyles({
  404. "position": "absolute",
  405. "width": "100%",
  406. "height": "100%",
  407. "top": "0px",
  408. "margin": "0px",
  409. "left": "0px"
  410. });
  411. //this.tab.pages.each(function(page){
  412. this.view.setAreaNodeSize();
  413. //});
  414. this.isMax = true;
  415. }else{
  416. this.isMax = false;
  417. this.designNode.inject(this.editContentNode);
  418. this.designNode.setStyles(this.css.designNode);
  419. this.designNode.setStyles({
  420. "position": "static"
  421. });
  422. this.resizeNode();
  423. //this.tab.pages.each(function(page){
  424. this.view.setAreaNodeSize();
  425. //});
  426. }
  427. },
  428. loadEditContent: function(callback){
  429. this.designNode = new Element("div", {
  430. "styles": this.css.designNode
  431. }).inject(this.editContentNode);
  432. //MWF.require("MWF.widget.Tab", function(){
  433. // this.tab = new MWF.widget.Tab(this.designNode, {"style": "dictionary"});
  434. // this.tab.load();
  435. //}.bind(this), false);
  436. // MWF.require("MWF.widget.ScrollBar", function(){
  437. // new MWF.widget.ScrollBar(this.designNode, {"distance": 100});
  438. // }.bind(this));
  439. },
  440. //loadProperty------------------------
  441. loadProperty: function(){
  442. this.propertyTitleNode = new Element("div", {
  443. "styles": this.css.propertyTitleNode,
  444. "text": MWF.APPDVD.LP.property
  445. }).inject(this.propertyNode);
  446. this.propertyResizeBar = new Element("div", {
  447. "styles": this.css.propertyResizeBar
  448. }).inject(this.propertyNode);
  449. this.loadPropertyResize();
  450. this.propertyContentNode = new Element("div", {
  451. "styles": this.css.propertyContentNode
  452. }).inject(this.propertyNode);
  453. this.propertyDomArea = new Element("div", {
  454. "styles": this.css.propertyDomArea
  455. }).inject(this.propertyContentNode);
  456. this.propertyDomPercent = 0.3;
  457. this.propertyContentResizeNode = new Element("div", {
  458. "styles": this.css.propertyContentResizeNode
  459. }).inject(this.propertyContentNode);
  460. this.propertyContentArea = new Element("div", {
  461. "styles": this.css.propertyContentArea
  462. }).inject(this.propertyContentNode);
  463. this.loadPropertyContentResize();
  464. //this.setPropertyContent();
  465. this.propertyNode.addEvent("keydown", function(e){e.stopPropagation();});
  466. },
  467. //setPropertyContent: function(){
  468. // this.dictionaryPropertyNode = new Element("div", {"styles": this.css.dictionaryPropertyNode});
  469. // this.jsonDomNode = new Element("div", {"styles": this.css.jsonDomNode});
  470. // this.jsonTextNode = new Element("div", {"styles": this.css.jsonTextNode});
  471. // this.jsonTextAreaNode = new Element("textarea", {"styles": this.css.jsonTextAreaNode}).inject(this.jsonTextNode);
  472. //
  473. // MWF.require("MWF.widget.Tab", function(){
  474. // var tab = new MWF.widget.Tab(this.propertyContentArea, {"style": "moduleList"});
  475. // tab.load();
  476. // tab.addTab(this.dictionaryPropertyNode, this.lp.property, false);
  477. // tab.addTab(this.jsonDomNode, "JSON", false);
  478. // tab.addTab(this.jsonTextNode, "TEXT", false);
  479. // tab.pages[0].showTab();
  480. // }.bind(this));
  481. //
  482. // var node = new Element("div", {"styles": this.css.propertyTitleNode, "text": this.lp.id+":"}).inject(this.dictionaryPropertyNode);
  483. // this.propertyIdNode = new Element("div", {"styles": this.css.propertyTextNode}).inject(this.dictionaryPropertyNode);
  484. //
  485. // node = new Element("div", {"styles": this.css.propertyTitleNode, "text": this.lp.name+":"}).inject(this.dictionaryPropertyNode);
  486. // this.propertyNameNode = new Element("input", {"styles": this.css.propertyInputNode}).inject(this.dictionaryPropertyNode);
  487. // if (this.options.noModifyName || this.options.readMode){
  488. // this.propertyNameNode.set("readonly", true);
  489. // this.propertyNameNode.addEvent("keydown", function(){
  490. // this.notice(this.lp.notice.noModifyName, "error");
  491. // }.bind(this));
  492. // }
  493. //
  494. // node = new Element("div", {"styles": this.css.propertyTitleNode, "text": this.lp.alias+":"}).inject(this.dictionaryPropertyNode);
  495. // this.propertyAliasNode = new Element("input", {"styles": this.css.propertyInputNode}).inject(this.dictionaryPropertyNode);
  496. // if (this.options.noModifyName || this.options.readMode){
  497. // this.propertyAliasNode.set("readonly", true);
  498. // this.propertyAliasNode.addEvent("keydown", function(){
  499. // this.notice(this.lp.notice.noModifyName, "error");
  500. // }.bind(this));
  501. // }
  502. //
  503. // node = new Element("div", {"styles": this.css.propertyTitleNode, "text": this.lp.description+":"}).inject(this.dictionaryPropertyNode);
  504. // this.propertyDescriptionNode = new Element("textarea", {"styles": this.css.propertyInputAreaNode}).inject(this.dictionaryPropertyNode);
  505. // if (this.options.noModifyName || this.options.readMode){
  506. // this.propertyDescriptionNode.set("readonly", true);
  507. // }
  508. //},
  509. loadPropertyResize: function(){
  510. // var size = this.propertyNode.getSize();
  511. // var position = this.propertyResizeBar.getPosition();
  512. this.propertyResize = new Drag(this.propertyResizeBar,{
  513. "snap": 1,
  514. "onStart": function(el, e){
  515. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  516. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  517. el.store("position", {"x": x, "y": y});
  518. var size = this.propertyNode.getSize();
  519. el.store("initialWidth", size.x);
  520. }.bind(this),
  521. "onDrag": function(el, e){
  522. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  523. // var y = e.event.y;
  524. var bodySize = this.content.getSize();
  525. var position = el.retrieve("position");
  526. var initialWidth = el.retrieve("initialWidth").toFloat();
  527. var dx = position.x.toFloat()-x.toFloat();
  528. var width = initialWidth+dx;
  529. if (width> bodySize.x/2) width = bodySize.x/2;
  530. if (width<40) width = 40;
  531. this.contentNode.setStyle("margin-right", width+1);
  532. this.propertyNode.setStyle("width", width);
  533. //this.tab.pages.each(function(page){
  534. (this.view || this.table).setViewWidth();
  535. //});
  536. }.bind(this)
  537. });
  538. },
  539. loadPropertyContentResize: function(){
  540. this.propertyContentResize = new Drag(this.propertyContentResizeNode, {
  541. "snap": 1,
  542. "onStart": function(el, e){
  543. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  544. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  545. el.store("position", {"x": x, "y": y});
  546. var size = this.propertyDomArea.getSize();
  547. el.store("initialHeight", size.y);
  548. }.bind(this),
  549. "onDrag": function(el, e){
  550. var size = this.propertyContentNode.getSize();
  551. // var x = e.event.x;
  552. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  553. var position = el.retrieve("position");
  554. var dy = y.toFloat()-position.y.toFloat();
  555. var initialHeight = el.retrieve("initialHeight").toFloat();
  556. var height = initialHeight+dy;
  557. if (height<40) height = 40;
  558. if (height> size.y-40) height = size.y-40;
  559. this.propertyDomPercent = height/size.y;
  560. this.setPropertyContentResize();
  561. }.bind(this)
  562. });
  563. },
  564. setPropertyContentResize: function(){
  565. var size = this.propertyContentNode.getSize();
  566. var resizeNodeSize = this.propertyContentResizeNode.getSize();
  567. var height = size.y-resizeNodeSize.y;
  568. var domHeight = this.propertyDomPercent*height;
  569. var contentHeight = height-domHeight;
  570. this.propertyDomArea.setStyle("height", ""+domHeight+"px");
  571. this.propertyContentArea.setStyle("height", ""+contentHeight+"px");
  572. if (this.table) this.view = this.table;
  573. if (this.view){
  574. if (this.view.currentSelectedModule){
  575. if (this.view.currentSelectedModule.property){
  576. var tab = this.view.currentSelectedModule.property.propertyTab;
  577. if (tab){
  578. var tabTitleSize = tab.tabNodeContainer.getSize();
  579. tab.pages.each(function(page){
  580. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  581. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  582. var tabContentNodeAreaHeight = contentHeight - topMargin - bottomMargin - tabTitleSize.y.toFloat()-15;
  583. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  584. }.bind(this));
  585. }
  586. }
  587. }
  588. }
  589. },
  590. //resizeNode------------------------------------------------
  591. resizeNode: function(){
  592. var nodeSize = this.node.getSize();
  593. this.contentNode.setStyle("height", ""+nodeSize.y+"px");
  594. this.propertyNode.setStyle("height", ""+nodeSize.y+"px");
  595. var contentToolbarMarginTop = this.contentToolbarNode.getStyle("margin-top").toFloat();
  596. var contentToolbarMarginBottom = this.contentToolbarNode.getStyle("margin-bottom").toFloat();
  597. var allContentToolberSize = this.contentToolbarNode.getComputedSize();
  598. var y = nodeSize.y - allContentToolberSize.totalHeight - contentToolbarMarginTop - contentToolbarMarginBottom;
  599. this.editContentNode.setStyle("height", ""+y+"px");
  600. if (this.designNode){
  601. var designMarginTop = this.designNode.getStyle("margin-top").toFloat();
  602. var designMarginBottom = this.designNode.getStyle("margin-bottom").toFloat();
  603. y = nodeSize.y - allContentToolberSize.totalHeight - contentToolbarMarginTop - contentToolbarMarginBottom - designMarginTop - designMarginBottom;
  604. this.designNode.setStyle("height", ""+y+"px");
  605. }
  606. titleSize = this.propertyTitleNode.getSize();
  607. titleMarginTop = this.propertyTitleNode.getStyle("margin-top").toFloat();
  608. titleMarginBottom = this.propertyTitleNode.getStyle("margin-bottom").toFloat();
  609. titlePaddingTop = this.propertyTitleNode.getStyle("padding-top").toFloat();
  610. titlePaddingBottom = this.propertyTitleNode.getStyle("padding-bottom").toFloat();
  611. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  612. y = nodeSize.y-y;
  613. this.propertyContentNode.setStyle("height", ""+y+"px");
  614. this.propertyResizeBar.setStyle("height", ""+y+"px");
  615. this.setPropertyContentResize();
  616. titleSize = this.viewListTitleNode.getSize();
  617. titleMarginTop = this.viewListTitleNode.getStyle("margin-top").toFloat();
  618. titleMarginBottom = this.viewListTitleNode.getStyle("margin-bottom").toFloat();
  619. titlePaddingTop = this.viewListTitleNode.getStyle("padding-top").toFloat();
  620. titlePaddingBottom = this.viewListTitleNode.getStyle("padding-bottom").toFloat();
  621. nodeMarginTop = this.viewListAreaSccrollNode.getStyle("margin-top").toFloat();
  622. nodeMarginBottom = this.viewListAreaSccrollNode.getStyle("margin-bottom").toFloat();
  623. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom+nodeMarginTop+nodeMarginBottom;
  624. y = nodeSize.y-y;
  625. this.viewListAreaSccrollNode.setStyle("height", ""+y+"px");
  626. this.viewListResizeNode.setStyle("height", ""+y+"px");
  627. },
  628. //loadView------------------------------------------
  629. loadView: function(callback){
  630. this.getViewData(this.options.id, function(vdata){
  631. this.setTitle(this.options.appTitle + "-"+vdata.name);
  632. if(this.taskitem)this.taskitem.setText(this.options.appTitle + "-"+vdata.name);
  633. this.options.appTitle = this.options.appTitle + "-"+vdata.name;
  634. //if (this.options.readMode){
  635. // this.view = new MWF.xApplication.process.DictionaryDesigner.DictionaryReader(this, ddata);
  636. //}else{
  637. this.view = new MWF.xApplication.query.ViewDesigner.View(this, vdata, {
  638. "onPostLoad": function(){
  639. this.fireEvent("onPostViewLoad");
  640. }.bind(this)
  641. });
  642. //}
  643. this.view.load();
  644. if (callback) callback();
  645. //if (this.status){
  646. // if (this.status.openViews){
  647. // this.status.openViews.each(function(id){
  648. // this.loadViewData(id, function(data){
  649. // var showTab = true;
  650. // if (this.status.currentId){
  651. // if (this.status.currentId!=data.id) showTab = false;
  652. // }
  653. // //if (this.options.readMode){
  654. // // var view = new MWF.xApplication.process.DictionaryDesigner.DictionaryReader(this, data, {"showTab": showTab});
  655. // //}else{
  656. // var view = new MWF.xApplication.process.DictionaryDesigner.View(this, data, {"showTab": showTab});
  657. // //}
  658. //
  659. // view.load();
  660. // }.bind(this), true);
  661. // }.bind(this));
  662. // }
  663. //}
  664. }.bind(this));
  665. },
  666. getViewData: function(id, callback){
  667. if (!this.options.id){
  668. this.loadNewViewData(callback);
  669. }else{
  670. this.loadViewData(id, callback);
  671. }
  672. },
  673. loadNewViewData: function(callback){
  674. var url = "../x_component_query_ViewDesigner/$View/view.json";
  675. MWF.getJSON(url, {
  676. "onSuccess": function(obj){
  677. this.actions.getUUID(function(id){
  678. obj.id=id;
  679. obj.isNewView = true;
  680. obj.application = this.application.id;
  681. this.createListViewItem(obj, true);
  682. if (callback) callback(obj);
  683. }.bind(this));
  684. }.bind(this),
  685. "onerror": function(text){
  686. this.notice(text, "error");
  687. }.bind(this),
  688. "onRequestFailure": function(xhr){
  689. this.notice(xhr.responseText, "error");
  690. }.bind(this)
  691. });
  692. },
  693. loadViewData: function(id, callback){
  694. this.actions.getView(id, function(json){
  695. if (json){
  696. var data = json.data;
  697. var dataJson = JSON.decode(data.data);
  698. data.data = dataJson;
  699. if (!this.application){
  700. this.actions.getApplication(data.application, function(json){
  701. this.application = {"name": json.data.name, "id": json.data.id};
  702. if (callback) callback(data);
  703. }.bind(this));
  704. }else{
  705. if (callback) callback(data);
  706. }
  707. }
  708. }.bind(this));
  709. },
  710. saveView: function(){
  711. this.view.save(function(){
  712. var name = this.view.data.name;
  713. this.setTitle(MWF.APPDVD.LP.title + "-"+name);
  714. this.options.desktopReload = true;
  715. this.options.id = this.view.data.id;
  716. }.bind(this));
  717. },
  718. saveForm: function(){
  719. this.saveView();
  720. },
  721. preview : function(){
  722. this.view.preview();
  723. },
  724. saveViewAs: function(){
  725. this.view.saveAs();
  726. },
  727. dictionaryExplode: function(){
  728. this.view.explode();
  729. },
  730. dictionaryImplode: function(){
  731. this.view.implode();
  732. },
  733. //recordStatus: function(){
  734. // return {"id": this.options.id};
  735. //},
  736. recordStatus: function(){
  737. //if (this.tab){
  738. var openViews = [];
  739. openViews.push(this.view.data.id);
  740. var currentId = this.view.data.id;
  741. var application = o2.typeOf(this.application) === "object" ? {
  742. name: this.application.name,
  743. id: this.application.id
  744. } : this.application;
  745. return {
  746. "id": this.options.id,
  747. "application": application,
  748. "openViews": openViews,
  749. "currentId": currentId
  750. };
  751. //}
  752. //return {"id": this.options.id, "application": this.application};
  753. }
  754. });
  755. MWF.xDesktop.requireApp("Template", "MPopupForm", null, false);
  756. MWF.xApplication.query.ViewDesigner.View.NewNameForm = new Class({
  757. Extends: MPopupForm,
  758. Implements: [Options, Events],
  759. options: {
  760. "style": "design",
  761. "width": 700,
  762. //"height": 300,
  763. "height": "260",
  764. "hasTop": true,
  765. "hasIcon": false,
  766. "draggable": true,
  767. "title" : MWF.xApplication.query.ViewDesigner.LP.newView
  768. },
  769. _createTableContent: function () {
  770. var html = "<table width='80%' bordr='0' cellpadding='7' cellspacing='0' styles='formTable' style='margin: 20px auto 0px auto; '>" +
  771. "<tr><td styles='formTableTitle' lable='selectQuery' width='25%'></td>" +
  772. " <td styles='formTableValue' item='selectQuery' colspan='3' width='75%'></td></tr>" +
  773. "<tr><td styles='formTableTitle' lable='name'></td>" +
  774. " <td styles='formTableValue' item='name' colspan='3'></td></tr>" +
  775. "</table>";
  776. this.formTableArea.set("html", html);
  777. MWF.xDesktop.requireApp("Template", "MForm", function () {
  778. this.form = new MForm(this.formTableArea, this.data || {}, {
  779. isEdited: true,
  780. style: "cms",
  781. hasColon: true,
  782. itemTemplate: {
  783. selectQuery : { text: MWF.xApplication.query.ViewDesigner.LP.application , type : "org", orgType : "Query", defaultValue : this.data.queryName, orgWidgetOptions : {
  784. "canRemove" : false
  785. }},
  786. name: {text: MWF.xApplication.query.ViewDesigner.LP.name, notEmpty: true}
  787. }
  788. }, this.app);
  789. this.form.load();
  790. }.bind(this),null, true)
  791. },
  792. ok: function(){
  793. var data = this.form.getResult(true,null,true,false,true);
  794. if( data ){
  795. var selectQuery = this.form.getItem("selectQuery").orgObject;
  796. if( selectQuery && selectQuery.length > 0 ){
  797. var queryData = selectQuery[0].data;
  798. data.query = queryData.id;
  799. data.queryName = queryData.name;
  800. }else{
  801. //data.query 和 data.queryName 还是传进来的值
  802. }
  803. this.fireEvent("save", [data , function(){
  804. this.close();
  805. }.bind(this)])
  806. }
  807. }
  808. });