Main.js 19 KB

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