Main.js 41 KB

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