Main.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. MWF.CMSVD = MWF.xApplication.cms.ViewDesigner;
  2. MWF.CMSVD.options = {
  3. "multitask": true,
  4. "executable": false
  5. };
  6. //MWF.xDesktop.requireApp("cms.ColumnManager", "Actions.RestActions", null, false);
  7. MWF.xDesktop.requireApp("cms.ViewDesigner", "View", null, false);
  8. MWF.xApplication.cms.ViewDesigner.Main = new Class({
  9. Extends: MWF.xApplication.Common.Main,
  10. Implements: [Options, Events],
  11. options: {
  12. "style": "default",
  13. "name": "cms.ViewDesigner",
  14. "icon": "icon.png",
  15. "title": MWF.CMSVD.LP.title,
  16. "appTitle": MWF.CMSVD.LP.title,
  17. "id": "",
  18. "actions": null,
  19. "category": null,
  20. "processData": null
  21. },
  22. onQueryLoad: function(){
  23. debugger;
  24. this.shortcut = true;
  25. if (!this.options.id && this.status){
  26. this.options.id = this.status.id;
  27. // this.options.application = this.status.applicationId;
  28. }else if( this.options.id && this.options.id.toLowerCase().indexOf("viewdesigner") > -1 ){
  29. if( this.status && this.status.id ){
  30. this.options.id = this.status.id;
  31. }else{
  32. this.options.id = "";
  33. }
  34. }
  35. if( !this.options.formId && this.status && this.status.formId ){
  36. this.options.formId = this.status.formId;
  37. }
  38. if( !this.application && this.status && this.status.applicationId ){
  39. this.application = {
  40. id : this.status.applicationId,
  41. appName : this.status.applicationName
  42. }
  43. }
  44. if (!this.options.id){
  45. this.options.desktopReload = false;
  46. this.options.title = this.options.title + "-"+MWF.CMSVD.LP.newView;
  47. }
  48. this.actions = MWF.Actions.get("x_cms_assemble_control"); //new MWF.xApplication.cms.ColumnManager.Actions.RestActions();
  49. this.path = "/x_component_cms_ViewDesigner/$Main/";
  50. this.lp = MWF.xApplication.cms.ViewDesigner.LP;
  51. // this.cmsData = this.options.processData;
  52. },
  53. loadApplication: function(callback){
  54. this.createNode();
  55. if (!this.options.isRefresh){
  56. this.maxSize(function(){
  57. this.openForm();
  58. }.bind(this));
  59. }else{
  60. this.openForm();
  61. }
  62. if (callback) callback();
  63. },
  64. createNode: function(){
  65. this.content.setStyle("overflow", "hidden");
  66. this.node = new Element("div", {
  67. "styles": {"width": "100%", "height": "100%", "overflow": "hidden"}
  68. }).inject(this.content);
  69. },
  70. openForm: function(){
  71. this.loadNodes();
  72. this.loadViewListNodes();
  73. // this.loadToolbar();
  74. this.loadContentNode();
  75. // this.loadProperty();
  76. // this.loadTools();
  77. this.resizeNode();
  78. this.addEvent("resize", this.resizeNode.bind(this));
  79. this.loadView();
  80. if (this.toolbarContentNode){
  81. this.setScrollBar(this.toolbarContentNode, null, {
  82. "V": {"x": 0, "y": 0},
  83. "H": {"x": 0, "y": 0}
  84. });
  85. //this.setScrollBar(this.propertyDomArea, null, {
  86. // "V": {"x": 0, "y": 0},
  87. // "H": {"x": 0, "y": 0}
  88. //});
  89. }
  90. },
  91. initOptions: function(){
  92. //this.toolsData = null;
  93. //this.toolbarMode = "all";
  94. //this.tools = [];
  95. //this.toolbarDecrease = 0;
  96. //
  97. //this.designNode = null;
  98. //this.form = null;
  99. },
  100. loadNodes: function(){
  101. this.viewListNode = new Element("div", {
  102. "styles": this.css.viewListNode
  103. }).inject(this.node);
  104. this.contentNode = new Element("div", {
  105. "styles": this.css.contentNode
  106. }).inject(this.node);
  107. },
  108. //loadViewListNodes-------------------------------
  109. loadViewListNodes: function(){
  110. this.viewListTitleNode = new Element("div", {
  111. "styles": this.css.viewListTitleNode,
  112. "text": MWF.CMSVD.LP.view
  113. }).inject(this.viewListNode);
  114. this.viewListResizeNode = new Element("div", {"styles": this.css.viewListResizeNode}).inject(this.viewListNode);
  115. this.viewListAreaSccrollNode = new Element("div", {"styles": this.css.viewListAreaSccrollNode}).inject(this.viewListNode);
  116. this.viewListAreaNode = new Element("div", {"styles": this.css.viewListAreaNode}).inject(this.viewListAreaSccrollNode);
  117. this.loadViewListResize();
  118. this.loadViewList();
  119. },
  120. loadViewListResize: function(){
  121. this.viewListResize = new Drag(this.viewListResizeNode,{
  122. "snap": 1,
  123. "onStart": function(el, e){
  124. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  125. var y = (Browser.name=="firefox") ? e.event.clientY : e.event.y;
  126. el.store("position", {"x": x, "y": y});
  127. var size = this.viewListAreaSccrollNode.getSize();
  128. el.store("initialWidth", size.x);
  129. }.bind(this),
  130. "onDrag": function(el, e){
  131. var x = (Browser.name=="firefox") ? e.event.clientX : e.event.x;
  132. // var y = e.event.y;
  133. var bodySize = this.content.getSize();
  134. var position = el.retrieve("position");
  135. var initialWidth = el.retrieve("initialWidth").toFloat();
  136. var dx = x.toFloat() - position.x.toFloat();
  137. var width = initialWidth+dx;
  138. if (width> bodySize.x/2) width = bodySize.x/2;
  139. if (width<40) width = 40;
  140. this.contentNode.setStyle("margin-left", width+1);
  141. this.viewListNode.setStyle("width", width);
  142. }.bind(this)
  143. });
  144. },
  145. loadViewList: function(){
  146. this.actions.listView(this.application.id, function (json) {
  147. ( json.data || [] ).each(function(view){
  148. this.createListViewItem(view);
  149. }.bind(this));
  150. }.bind(this), null, false);
  151. },
  152. createListViewItem: function(view, isNew){
  153. var _self = this;
  154. var listViewItem = new Element("div", {"styles": this.css.listViewItem}).inject(this.viewListAreaNode, (isNew) ? "top": "bottom");
  155. var listViewItemIcon = new Element("div", {"styles": this.css.listViewItemIcon}).inject(listViewItem);
  156. var listViewItemText = new Element("div", {"styles": this.css.listViewItemText, "text": (view.name) ? view.name+" ("+view.alias+")" : this.lp.newView}).inject(listViewItem);
  157. listViewItem.store("view", view);
  158. listViewItem.addEvents({
  159. "dblclick": function(e){_self.loadViewByData(this, e);},
  160. "mouseover": function(){if (_self.currentListViewItem!=this) this.setStyles(_self.css.listViewItem_over);},
  161. "mouseout": function(){if (_self.currentListViewItem!=this) this.setStyles(_self.css.listViewItem);}
  162. });
  163. },
  164. loadViewByData: function(node, e){
  165. var view = node.retrieve("view");
  166. var openNew = true;
  167. for (var i = 0; i<this.tab.pages.length; i++){
  168. if (view.id==this.tab.pages[i].view.data.id){
  169. this.tab.pages[i].showTabIm();
  170. openNew = false;
  171. break;
  172. }
  173. }
  174. if (openNew){
  175. this.loadViewData(view.id, function(data){
  176. var view = new MWF.xApplication.cms.ViewDesigner.View(this, data);
  177. view.load();
  178. }.bind(this), true);
  179. }
  180. },
  181. loadRelativeForm : function( formId, callback ){
  182. this.actions.getForm(formId, function(json){
  183. debugger;
  184. this.relativeFormData = (json.data.data) ? JSON.decode(MWF.decodeJsonString(json.data.data)): null;
  185. if( !this.relativeForm ){
  186. this.relativeForm = {
  187. id : this.relativeFormData.json.id,
  188. name : this.relativeFormData.json.name
  189. }
  190. }
  191. this.getFields( callback );
  192. }.bind(this));
  193. },
  194. getFields : function(callback){
  195. var url = this.path+"fieldConfig.json";
  196. MWF.getJSON(url, function(json){
  197. this.documentFields = json.documentFields;
  198. var formFileldTypeName = [];
  199. json.formFileldType.each(function( ft ){
  200. formFileldTypeName.push( ft.name );
  201. });
  202. this.formFields =[];
  203. Object.each(this.relativeFormData.json.moduleList, function(v, key){
  204. var idx = formFileldTypeName.indexOf( v.type.toLowerCase() );
  205. if( idx > -1 ){
  206. this.formFields.push( {
  207. "name" : key,
  208. "type" : json.formFileldType[idx].type
  209. });
  210. }
  211. }.bind(this));
  212. if(callback)callback();
  213. }.bind(this))
  214. },
  215. //loadContentNode------------------------------
  216. loadContentNode: function(){
  217. this.contentToolbarNode = new Element("div#contentToolbarNode", {
  218. "styles": this.css.contentToolbarNode
  219. }).inject(this.contentNode);
  220. if (!this.options.readMode) this.loadContentToolbar();
  221. this.editContentNode = new Element("div.editContentNode", {
  222. "styles": this.css.editContentNode
  223. }).inject(this.contentNode);
  224. this.loadEditContent(function(){
  225. // if (this.designDcoument) this.designDcoument.body.setStyles(this.css.designBody);
  226. if (this.designNode) this.designNode.setStyles(this.css.designNode);
  227. }.bind(this));
  228. },
  229. loadContentToolbar: function(callback){
  230. this.getFormToolbarHTML(function(toolbarNode){
  231. var spans = toolbarNode.getElements("span");
  232. spans.each(function(item, idx){
  233. var img = item.get("MWFButtonImage");
  234. if (img){
  235. item.set("MWFButtonImage", this.path+""+this.options.style+"/toolbar/"+img);
  236. }
  237. }.bind(this));
  238. $(toolbarNode).inject(this.contentToolbarNode);
  239. MWF.require("MWF.widget.Toolbar", function(){
  240. this.toolbar = new MWF.widget.Toolbar(toolbarNode, {"style": "ProcessCategory"}, this);
  241. this.toolbar.load();
  242. if (callback) callback();
  243. }.bind(this));
  244. }.bind(this));
  245. },
  246. getFormToolbarHTML: function(callback){
  247. var toolbarUrl = this.path+this.options.style+"/toolbars.html";
  248. var r = new Request.HTML({
  249. url: toolbarUrl,
  250. method: "get",
  251. onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
  252. var toolbarNode = responseTree[0];
  253. if (callback) callback(toolbarNode);
  254. }.bind(this),
  255. onFailure: function(xhr){
  256. this.notice("request cmsToolbars error: "+xhr.responseText, "error");
  257. }.bind(this)
  258. });
  259. r.send();
  260. },
  261. maxOrReturnEditor: function(){
  262. if (!this.isMax){
  263. this.designNode.inject(this.node);
  264. this.designNode.setStyles({
  265. "position": "absolute",
  266. "width": "100%",
  267. "height": "100%",
  268. "top": "0px",
  269. "margin": "0px",
  270. "left": "0px"
  271. });
  272. this.tab.pages.each(function(page){
  273. page.view.setAreaNodeSize();
  274. });
  275. this.isMax = true;
  276. }else{
  277. this.isMax = false;
  278. this.designNode.inject(this.editContentNode);
  279. this.designNode.setStyles(this.css.designNode);
  280. this.designNode.setStyles({
  281. "position": "static"
  282. });
  283. this.resizeNode();
  284. this.tab.pages.each(function(page){
  285. page.view.setAreaNodeSize();
  286. });
  287. }
  288. },
  289. loadEditContent: function(callback){
  290. this.designNode = new Element("div.designNode", {
  291. "styles": this.css.designNode
  292. }).inject(this.editContentNode);
  293. MWF.require("MWF.widget.Tab", function(){
  294. this.tab = new MWF.widget.Tab(this.designNode, {"style": "dictionary"});
  295. this.tab.load();
  296. }.bind(this), false);
  297. // MWF.require("MWF.widget.ScrollBar", function(){
  298. // new MWF.widget.ScrollBar(this.designNode, {"distance": 100});
  299. // }.bind(this));
  300. },
  301. //resizeNode------------------------------------------------
  302. resizeNode: function(){
  303. var nodeSize = this.node.getSize();
  304. this.contentNode.setStyle("height", ""+nodeSize.y+"px");
  305. var contentToolbarMarginTop = this.contentToolbarNode.getStyle("margin-top").toFloat();
  306. var contentToolbarMarginBottom = this.contentToolbarNode.getStyle("margin-bottom").toFloat();
  307. var allContentToolberSize = this.contentToolbarNode.getComputedSize();
  308. var y = nodeSize.y - allContentToolberSize.totalHeight - contentToolbarMarginTop - contentToolbarMarginBottom;
  309. this.editContentNode.setStyle("height", ""+y+"px");
  310. if (this.designNode){
  311. var designMarginTop = this.designNode.getStyle("margin-top").toFloat();
  312. var designMarginBottom = this.designNode.getStyle("margin-bottom").toFloat();
  313. y = nodeSize.y - allContentToolberSize.totalHeight - contentToolbarMarginTop - contentToolbarMarginBottom - designMarginTop - designMarginBottom;
  314. this.designNode.setStyle("height", ""+y+"px");
  315. }
  316. //titleSize = this.propertyTitleNode.getSize();
  317. //titleMarginTop = this.propertyTitleNode.getStyle("margin-top").toFloat();
  318. //titleMarginBottom = this.propertyTitleNode.getStyle("margin-bottom").toFloat();
  319. //titlePaddingTop = this.propertyTitleNode.getStyle("padding-top").toFloat();
  320. //titlePaddingBottom = this.propertyTitleNode.getStyle("padding-bottom").toFloat();
  321. //
  322. //y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  323. //y = nodeSize.y-y;
  324. //this.propertyContentNode.setStyle("height", ""+y+"px");
  325. //
  326. //
  327. //this.setPropertyContentResize();
  328. titleSize = this.viewListTitleNode.getSize();
  329. titleMarginTop = this.viewListTitleNode.getStyle("margin-top").toFloat();
  330. titleMarginBottom = this.viewListTitleNode.getStyle("margin-bottom").toFloat();
  331. titlePaddingTop = this.viewListTitleNode.getStyle("padding-top").toFloat();
  332. titlePaddingBottom = this.viewListTitleNode.getStyle("padding-bottom").toFloat();
  333. nodeMarginTop = this.viewListAreaSccrollNode.getStyle("margin-top").toFloat();
  334. nodeMarginBottom = this.viewListAreaSccrollNode.getStyle("margin-bottom").toFloat();
  335. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom+nodeMarginTop+nodeMarginBottom;
  336. y = nodeSize.y-y;
  337. this.viewListAreaSccrollNode.setStyle("height", ""+y+"px");
  338. this.viewListResizeNode.setStyle("height", ""+y+"px");
  339. },
  340. //loadForm------------------------------------------
  341. loadView: function(){
  342. this.getViewData(this.options.id, function(vdata){
  343. var name = vdata.name || "";
  344. this.setTitle(this.options.appTitle + "-"+ name);
  345. this.taskitem.setText(this.options.appTitle + "-"+name);
  346. this.options.appTitle = this.options.appTitle + "-"+name;
  347. this.view = new MWF.xApplication.cms.ViewDesigner.View(this, vdata);
  348. this.view.load();
  349. if (this.status){
  350. if (this.status.openViews){
  351. this.status.openViews.each(function(id){
  352. this.loadViewData(id, function(data){
  353. var showTab = true;
  354. if (this.status.currentId){
  355. if (this.status.currentId!=data.id) showTab = false;
  356. }
  357. var view = new MWF.xApplication.cms.ViewDesigner.View(this, data, {"showTab": showTab});
  358. view.load();
  359. }.bind(this), true);
  360. }.bind(this));
  361. }
  362. }
  363. }.bind(this));
  364. },
  365. getViewData: function(id, callback){
  366. if (!id){
  367. this.loadNewViewData(callback);
  368. }else{
  369. this.loadViewData(id, callback);
  370. }
  371. },
  372. loadNewViewData: function(callback){
  373. this.loadRelativeForm( this.options.formId || this.relativeForm.id, function(){
  374. var data = {
  375. "content": {
  376. "isNew" : true,
  377. "name": "",
  378. "id": this.actions.getUUID(),
  379. "application": this.application.id,
  380. "applicationName" : this.application.appName,
  381. "alias": "",
  382. "description": "",
  383. "relativeForm" : this.relativeForm,
  384. "events" : null,
  385. "columns" :[],
  386. "jsheader" : null,
  387. "sortType" : "DESC"
  388. }
  389. };
  390. this.createListViewItem(data, true);
  391. if (callback) callback(data);
  392. }.bind(this))
  393. },
  394. loadViewData: function(id, callback){
  395. this.actions.getView(id, function(data){
  396. if (data){
  397. data.data.content = JSON.parse(data.data.content);
  398. if( data.data.content.id != id )data.data.content.id = id;
  399. if (!this.application){
  400. this.actions.getColumn( data.appId, function(json){
  401. this.application = {"name": json.data.name, "id": json.data.id};
  402. this.loadRelativeForm( data.data.content.relativeForm.id, function(){
  403. if (callback) callback(data.data);
  404. })
  405. }.bind(this));
  406. }else{
  407. this.loadRelativeForm( data.data.content.relativeForm.id, function(){
  408. if (callback) callback(data.data);
  409. })
  410. }
  411. }
  412. }.bind(this));
  413. },
  414. saveView: function(){
  415. if (this.tab.showPage){
  416. var view = this.tab.showPage.view;
  417. view.save(function(){
  418. if (view==this.view){
  419. var name = view.data.name || "";
  420. this.setTitle(MWF.CMSVD.LP.title + "-"+name);
  421. this.options.desktopReload = true;
  422. this.options.id = view.data.id;
  423. }
  424. this.fireAppEvent("postSave");
  425. }.bind(this));
  426. }
  427. },
  428. saveViewAs: function(){
  429. this.view.saveAs();
  430. },
  431. viewExplode: function(){
  432. this.view.explode();
  433. },
  434. viewImplode: function(){
  435. this.view.implode();
  436. },
  437. //recordStatus: function(){
  438. // return {"id": this.options.id};
  439. //},
  440. recordStatus: function(){
  441. if (this.tab){
  442. var openViews = [];
  443. this.tab.pages.each(function(page){
  444. if (page.view.data.id!=this.options.id) openViews.push(page.view.data.id);
  445. }.bind(this));
  446. var currentId = this.tab.showPage.view.data.id;
  447. var status = {
  448. "id": this.options.id,
  449. "applicationId": this.application.id,
  450. "applicationName" : this.application.appName,
  451. "formId" : this.options.formId || this.relativeForm.id,
  452. "openViews": openViews,
  453. "currentId": currentId
  454. };
  455. return status;
  456. }
  457. return {
  458. "id": this.options.id,
  459. "applicationId": this.application.id,
  460. "applicationName" : this.application.appName,
  461. "formId" : this.options.formId || this.relativeForm.id
  462. };
  463. }
  464. });