Main.js 17 KB

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