Main.js 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049
  1. MWF.xApplication.cms = MWF.xApplication.cms || {};
  2. MWF.CMSE = MWF.xApplication.cms.Module = MWF.xApplication.cms.Module ||{};
  3. MWF.require("MWF.widget.O2Identity", null,false);
  4. //MWF.xDesktop.requireApp("cms.Module", "Actions.RestActions", null, false);
  5. MWF.xApplication.cms.Module.options = {
  6. multitask: false,
  7. executable: true
  8. };
  9. MWF.xApplication.cms.Module.Main = new Class({
  10. Extends: MWF.xApplication.Common.Main,
  11. Implements: [Options, Events],
  12. options: {
  13. "style": "default",
  14. "name": "cms.Module",
  15. "icon": "icon.png",
  16. "width": "1200",
  17. "height": "700",
  18. "isResize": true,
  19. "isMax": true,
  20. "isCategory" : false,
  21. "searchKey" : "",
  22. "title": MWF.xApplication.cms.Module.LP.title
  23. },
  24. onQueryLoad: function(){
  25. this.lp = MWF.xApplication.cms.Module.LP;
  26. },
  27. onQueryClose : function(){
  28. if (window.clipboardData){
  29. if (this.keyCopyItemsFun)this.removeEvent("copy", this.keyCopyItemsFun);
  30. if (this.keyPasteItemsFun)this.removeEvent("paste", this.keyPasteItemsFun);
  31. }else{
  32. if (this.keyCopyItemsFun) document.removeEventListener('copy', this.keyCopyItemsFun);
  33. if (this.keyPasteItemsFun) document.removeEventListener('paste', this.keyPasteItemsFun);
  34. }
  35. },
  36. loadApplication: function(callback){
  37. //this.controllers = [];
  38. this.isAdmin = false;
  39. this.restActions = MWF.Actions.get("x_cms_assemble_control"); //new MWF.xApplication.cms.Module.Actions.RestActions();
  40. this.createNode();
  41. this.loadApplicationContent();
  42. },
  43. createNode: function(){
  44. this.content.setStyle("overflow", "hidden");
  45. this.node = new Element("div", {
  46. "styles": this.css.node
  47. }).inject(this.content);
  48. this.naviContainerNode = new Element("div.naviContainerNode", {
  49. "styles": this.css.naviContainerNode
  50. }).inject(this.node);
  51. this.leftTitleNode = new Element("div.leftTitleNode", {
  52. "styles": this.css.leftTitleNode
  53. }).inject(this.naviContainerNode);
  54. this.rightContentNode = new Element("div", {
  55. "styles":this.css.rightContentNode
  56. }).inject(this.node);
  57. this.titleBar = new Element("div", {
  58. "styles": this.css.titleBar
  59. }).inject(this.rightContentNode );
  60. },
  61. loadApplicationContent: function(){
  62. if( this.options.columnData ){
  63. this.setTitle(this.options.columnData.appName);
  64. this.loadController(function(){
  65. this.loadTitle(function(){
  66. this.loadMenu();
  67. }.bind(this));
  68. }.bind(this))
  69. }else if( (this.status && this.status.columnId) || this.options.columnId ){
  70. var columnId = this.options.columnId || this.status.columnId;
  71. this.loadColumnData( columnId, function(){
  72. this.loadController(function(){
  73. this.loadTitle(function(){
  74. this.loadMenu();
  75. }.bind(this));
  76. }.bind(this))
  77. }.bind(this))
  78. }else if( this.options.columnAlias ){
  79. this.restActions.getColumnByAlias( this.options.columnAlias, function( json ){
  80. this.options.columnData = json.data;
  81. this.setTitle(this.options.columnData.appName);
  82. this.loadController(function(){
  83. this.loadTitle(function(){
  84. this.loadMenu();
  85. }.bind(this));
  86. }.bind(this))
  87. }.bind(this))
  88. }
  89. },
  90. loadColumnData : function(columnId, callback){
  91. this.restActions.getColumn( columnId, function( json ){
  92. this.options.columnData = json.data;
  93. this.setTitle(this.options.columnData.appName);
  94. if(callback)callback()
  95. }.bind(this))
  96. },
  97. loadController: function(callback){
  98. //this.restActions.listColumnController(this.options.columnData.id, function( json ){
  99. // json.data = json.data || [];
  100. // json.data.each(function(item){
  101. // this.controllers.push(item.adminUid)
  102. // }.bind(this));
  103. // this.isAdmin = MWF.AC.isCMSManager() || this.controllers.contains(layout.desktop.session.user.distinguishedName);
  104. // if(callback)callback(json);
  105. //}.bind(this));
  106. this.restActions.isAppInfoManager( this.options.columnData.id, function( json ){
  107. this.isAdmin = MWF.AC.isCMSManager() || json.data.value;
  108. if(callback)callback(json);
  109. }.bind(this))
  110. },
  111. loadTitle : function(callback){
  112. if( this.isAdmin ){
  113. this.loadImportActionNode();
  114. this.loadExportActionNode();
  115. }
  116. this.loadCreateDocumentActionNode(
  117. function(){
  118. this.loadTitleIconNode();
  119. this.loadTitleContentNode();
  120. this.loadCopyActionNode();
  121. this.loadPastEvent();
  122. this.loadSearchNode();
  123. if(callback)callback();
  124. }.bind(this)
  125. );
  126. },
  127. loadCreateDocumentActionNode: function( callback ) {
  128. this.restActions.listCategoryByPublisher( this.options.columnData.id, function( json ){
  129. if( json.data && json.data.length ){
  130. this.createDocumentAction = new Element("div", {
  131. "styles": this.css.createDocumentAction,
  132. "text" : this.lp.start
  133. }).inject(this.titleBar);
  134. this.createDocumentAction.addEvents({
  135. "click": function(e){
  136. MWF.xDesktop.requireApp("cms.Index", "Newer", null, false);
  137. this.creater = new MWF.xApplication.cms.Index.Newer( this.options.columnData, null, this, this.view, {
  138. restrictToColumn : true
  139. });
  140. this.creater.load();
  141. }.bind(this),
  142. "mouseover" : function(e){
  143. this.createDocumentAction.setStyles( this.css.createDocumentAction_over )
  144. }.bind(this),
  145. "mouseout" : function(e){
  146. this.createDocumentAction.setStyles( this.css.createDocumentAction )
  147. }.bind(this)
  148. });
  149. }
  150. if(callback)callback();
  151. }.bind(this));
  152. },
  153. loadPastEvent : function(){
  154. if( !this.isAdmin )return;
  155. this.keyPasteItemsFun = this.keyPasteItems.bind(this);
  156. if (window.clipboardData){
  157. this.addEvent("paste", this.keyPasteItemsFun);
  158. }else{
  159. document.addEventListener('paste', this.keyPasteItemsFun);
  160. //this.addEvent("queryClose", function(){
  161. // if (this.keyPasteItemsFun) document.removeEventListener('paste', this.keyPasteItemsFun);
  162. //}.bind(this));
  163. }
  164. },
  165. loadCopyActionNode : function(){
  166. if( !this.isAdmin )return;
  167. this.copyAction = new Element("div", {
  168. "styles": this.css.createDocumentAction,
  169. "text" : this.lp.copy
  170. }).inject(this.titleBar);
  171. this.copyAction.addEvents({
  172. "click": function(e){
  173. if( this.view ){
  174. if( this.view.selectEnable ){
  175. this.view.disableSelectMode();
  176. if (window.clipboardData){
  177. if (this.keyCopyItemsFun)this.removeEvent("copy", this.keyCopyItemsFun);
  178. }else{
  179. if (this.keyCopyItemsFun) document.removeEventListener('copy', this.keyCopyItemsFun);
  180. }
  181. this.keyCopyItemsFun = null;
  182. }else{
  183. this.view.selectMode();
  184. this.keyCopyItemsFun = this.keyCopyItems.bind(this);
  185. if (window.clipboardData){
  186. this.addEvent("copy", this.keyCopyItemsFun);
  187. }else{
  188. document.addEventListener('copy', this.keyCopyItemsFun);
  189. //this.addEvent("queryClose", function(){
  190. // if (this.keyCopyItemsFun) document.removeEventListener('copy', this.keyCopyItemsFun);
  191. //}.bind(this));
  192. }
  193. this.notice( this.lp.copyInfor );
  194. }
  195. }
  196. }.bind(this),
  197. "mouseover" : function(e){
  198. this.copyAction.setStyles( this.css.createDocumentAction_over )
  199. }.bind(this),
  200. "mouseout" : function(e){
  201. this.copyAction.setStyles( this.css.createDocumentAction )
  202. }.bind(this)
  203. });
  204. },
  205. keyCopyItems: function(e){
  206. var itemIds = this.view.getSelectedIds();
  207. if (itemIds.length){
  208. var items = [];
  209. var i = 0;
  210. var checkItems = function(e){
  211. if (i>= itemIds.length){
  212. if (items.length){
  213. var str = JSON.encode(items);
  214. if (e && e.clipboardData){
  215. e.clipboardData.setData('text/plain', str);
  216. }else {
  217. window.clipboardData.setData("Text", str);
  218. }
  219. this.notice(this.lp.copyed, "success");
  220. }
  221. }
  222. }.bind(this);
  223. itemIds.each(function(id){
  224. this.restActions.getDocument( id, function(json){
  225. json.data.elementType = "cmsDocument";
  226. items.push(json.data);
  227. i++;
  228. checkItems(e);
  229. }.bind(this), null, false)
  230. }.bind(this));
  231. }
  232. },
  233. keyPasteItems: function(e){
  234. var dataStr = "";
  235. if (e && e.clipboardData){
  236. dataStr = e.clipboardData.getData('text/plain');
  237. }else{
  238. dataStr = window.clipboardData.getData("Text");
  239. }
  240. var data = JSON.decode(dataStr);
  241. this.pasteItem(data, 0);
  242. },
  243. pasteItem: function(data, i){
  244. if (i<data.length){
  245. var item = data[i];
  246. if (item.elementType==="cmsDocument"){
  247. this.saveItemAs(item, function(){
  248. i++;
  249. this.pasteItem(data, i);
  250. }.bind(this), function(){
  251. i++;
  252. this.pasteItem(data, i);
  253. }.bind(this), function(){
  254. this.view.reload();
  255. }.bind(this));
  256. }else{
  257. i++;
  258. this.pasteItem(data, i);
  259. }
  260. }else{
  261. this.view.reload();
  262. }
  263. },
  264. saveItemAs: function(data, success, failure, cancel){
  265. this.restActions.getDocument(data.document.id, function(dJson){
  266. var someItem = dJson.data;
  267. if (someItem){
  268. var lp = this.lp;
  269. var _self = this;
  270. var d1 = new Date().parse(data.document.publishTime);
  271. var d2 = new Date().parse(someItem.document.publishTime);
  272. var html = "<div>"+lp.copyConfirmInfor+"</div>";
  273. html += "<div style='overflow: hidden; margin: 10px 0px; padding: 5px 10px; background-color: #ffffff; border-radius: 6px;'><div style='font-weight: bold; font-size:14px;'>"+lp.copySource+" "+someItem.document.title+"</div>";
  274. html += "<div style='font-size:12px; color: #666666; float: left'>"+someItem.document.publishTime+"</div>" +
  275. "<div style='font-size:12px; color: #666666; float: left; margin-left: 20px;'>"+MWF.name.cn(someItem.document.creatorPersonShort)+"</div>" +
  276. "<div style='color: red; float: right;'>"+((d1>=d2) ? "": lp.copynew)+"</div></div>";
  277. html += "<div style='overflow: hidden; margin: 10px 0px; padding: 5px 10px; background-color: #ffffff; border-radius: 6px;'><div style='clear: both;font-weight: bold; font-size:14px;'>"+lp.copyTarget+" "+data.document.title+"</div>";
  278. html += "<div style='font-size:12px; color: #666666; float: left;'>"+data.document.publishTime+"</div>" +
  279. "<div style='font-size:12px; color: #666666; float: left; margin-left: 20px;'>"+MWF.name.cn(data.document.creatorPersonShort)+"</div>" +
  280. "<div style='color: red; float: right;'>"+((d1<=d2) ? "": lp.copynew)+"</div></div>";
  281. // html += "<>"
  282. this.dlg("inofr", null, lp.copyConfirmTitle, {"html": html}, 500, 290, [
  283. {
  284. "text": lp.copyConfirm_overwrite,
  285. "action": function(){_self.saveItemAsUpdate(someItem, data, success, failure);this.close();}
  286. },
  287. {
  288. "text": lp.copyConfirm_new,
  289. "action": function(){_self.saveItemAsNew( data, success, failure, true );this.close();}
  290. },
  291. {
  292. "text": lp.copyConfirm_skip,
  293. "action": function(){/*nothing*/ this.close(); if (success) success();}
  294. },
  295. {
  296. "text": lp.copyConfirm_cancel,
  297. "action": function(){this.close(); if (cancel) cancel();}
  298. }
  299. ]);
  300. }
  301. }.bind(this), function(){
  302. //if (failure) failure();
  303. this.saveItemAsNew(data, success, failure)
  304. }.bind(this));
  305. },
  306. saveItemAsUpdate: function(someItem, data, success, failure){
  307. var doc = data.document;
  308. doc.id = someItem.document.id;
  309. doc.isNewDocument = false;
  310. doc.appId = someItem.document.appId;
  311. doc.appName = someItem.document.appName;
  312. doc.categoryId = someItem.document.categoryId;
  313. doc.categoryName = someItem.document.categoryName;
  314. doc.categoryAlias = someItem.document.categoryAlias;
  315. doc.form = someItem.document.form;
  316. doc.formName = someItem.document.formName;
  317. doc.readFormId = someItem.document.readFormId;
  318. doc.readFormName = someItem.document.readFormName;
  319. doc.docData = data.data;
  320. this.restActions.saveDocument(doc, function(){
  321. if (success) success();
  322. }.bind(this), function(){
  323. if (failure) failure();
  324. }.bind(this));
  325. },
  326. saveItemAsNew: function(data, success, failure, clearId){
  327. var columnData = this.options.columnData;
  328. var doc = data.document;
  329. if( clearId ){
  330. delete doc.id
  331. }
  332. doc.appId = columnData.id;
  333. doc.docData = data.data;
  334. delete doc.docData.$document;
  335. var callback = function(data){
  336. this.restActions.publishDocumentComplex(data, function(){
  337. if (success) success();
  338. }.bind(this), function(){
  339. if (failure) failure();
  340. }.bind(this));
  341. }.bind(this);
  342. this.restActions.getCategory( data.document.categoryId, function( json ){
  343. if( json.data.appId === columnData.id ){
  344. doc.categoryId = data.document.categoryId;
  345. callback( doc );
  346. }else{
  347. this.loadSelectCategoryDialog( "选择"+ data.document.title + "的分类",function(id){
  348. doc.categoryId = id;
  349. callback( doc );
  350. }.bind(this))
  351. }
  352. }.bind(this), function(){
  353. this.loadSelectCategoryDialog( "选择"+ data.document.title + "的分类",function(id){
  354. doc.categoryId = id;
  355. callback( doc );
  356. }.bind(this))
  357. }.bind(this))
  358. },
  359. loadSelectCategoryDialog : function(title, callback){
  360. if( !this.categoryList ){
  361. this.categoryList = [];
  362. this.restActions.listCategory( this.options.columnData.id, function( json ){
  363. json.data.each( function(d){
  364. this.categoryList.push( {
  365. name : d.categoryName,
  366. id : d.id
  367. })
  368. }.bind(this))
  369. }.bind(this), null, false)
  370. }
  371. MWF.xDesktop.requireApp("Template", "Selector.Custom", null, false);
  372. var opt = {
  373. "count": 1,
  374. "title": "选择分类",
  375. "selectableItems" : this.categoryList,
  376. "values": [],
  377. "onComplete": function( array ){
  378. if( !array || array.length == 0 )return;
  379. var id = array[0].data.id;
  380. callback( id )
  381. }.bind(this)
  382. };
  383. var selector = new MWF.xApplication.Template.Selector.Custom(this.content, opt );
  384. selector.load();
  385. },
  386. loadImportActionNode : function(){
  387. this.importAction = new Element("div", {
  388. "styles": this.css.importAction,
  389. "text" : this.lp.import
  390. }).inject(this.titleBar);
  391. this.importAction.setStyle("display","none");
  392. this.importAction.addEvents({
  393. "click": function(e){
  394. MWF.xDesktop.requireApp("cms.Module", "ExcelForm", null, false);
  395. var categoryData = this.navi.currentObject.isCategory ? this.navi.currentObject.data : this.navi.currentObject.category.data ;
  396. this.import = new MWF.xApplication.cms.Module.ImportForm( { app : this }, categoryData, {} );
  397. this.import.edit();
  398. }.bind(this),
  399. "mouseover" : function(e){
  400. this.importAction.setStyles( this.css.importAction_over )
  401. }.bind(this),
  402. "mouseout" : function(e){
  403. this.importAction.setStyles( this.css.importAction )
  404. }.bind(this)
  405. });
  406. },
  407. loadExportActionNode : function(){
  408. this.exportAction = new Element("div", {
  409. "styles": this.css.exportAction,
  410. "text" : this.lp.export
  411. }).inject(this.titleBar);
  412. this.exportAction.setStyle("display","none");
  413. this.exportAction.addEvents({
  414. "click": function(e){
  415. MWF.xDesktop.requireApp("cms.Module", "ExcelForm", null, false);
  416. var categoryData = this.navi.currentObject.isCategory ? this.navi.currentObject.data : this.navi.currentObject.category.data ;
  417. this.export = new MWF.xApplication.cms.Module.ExportForm ( { app : this }, categoryData, {} );
  418. this.export.edit();
  419. }.bind(this),
  420. "mouseover" : function(e){
  421. this.exportAction.setStyles( this.css.exportAction_over )
  422. }.bind(this),
  423. "mouseout" : function(e){
  424. this.exportAction.setStyles( this.css.exportAction )
  425. }.bind(this)
  426. });
  427. },
  428. loadTitleIconNode : function(){
  429. this.defaultColumnIcon = "/x_component_cms_Index/$Main/"+this.options.style+"/icon/column.png";
  430. var iconAreaNode = this.iconAreaNode = new Element("div",{
  431. "styles" : this.css.titleIconAreaNode
  432. }).inject(this.leftTitleNode);
  433. var iconNode = this.iconNode = new Element("img",{
  434. "styles" : this.css.titleIconNode
  435. }).inject(iconAreaNode);
  436. if (this.options.columnData.appIcon){
  437. this.iconNode.set("src", "data:image/png;base64,"+this.options.columnData.appIcon+"");
  438. }else{
  439. this.iconNode.set("src", this.defaultColumnIcon)
  440. }
  441. iconNode.makeLnk({
  442. "par": this._getLnkPar()
  443. });
  444. },
  445. _getLnkPar: function(){
  446. var lnkIcon = this.defaultColumnIcon;
  447. if (this.options.columnData.appIcon) lnkIcon = "data:image/png;base64,"+this.options.columnData.appIcon;
  448. var appId = "cms.Module"+this.options.columnData.id;
  449. return {
  450. "icon": lnkIcon,
  451. "title": this.options.columnData.appName,
  452. "par": "cms.Module#{\"columnId\": \""+this.options.columnData.id+"\", \"appId\": \""+appId+"\"}"
  453. };
  454. },
  455. loadTitleContentNode: function(){
  456. this.titleContentNode = new Element("div.titleContentNode", {
  457. "styles": this.css.titleContentNode
  458. }).inject(this.leftTitleNode);
  459. this.titleTextNode = new Element("div.titleTextNode", {
  460. "styles": this.css.titleTextNode,
  461. "text": this.options.columnData.appName,
  462. "title": this.options.columnData.appName
  463. }).inject(this.titleContentNode);
  464. this.titleDescriptionNode = new Element("div.titleDescriptionNode", {
  465. "styles": this.css.titleDescriptionNode,
  466. "text": this.options.columnData.description ? this.options.columnData.description : this.lp.noDescription,
  467. "title": this.options.columnData.description ? this.options.columnData.description : this.lp.noDescription
  468. }).inject(this.titleContentNode);
  469. },
  470. loadSearchNode : function(){
  471. this.searchNode = new Element("div").inject( this.titleBar );
  472. },
  473. loadMenu: function(callback){
  474. this.naviNode = new Element("div.naviNode", {
  475. "styles": this.css.naviNode
  476. }).inject(this.naviContainerNode);
  477. //this.setScrollBar(this.naviNode,{"where": "before"});
  478. MWF.require("MWF.widget.ScrollBar", function(){
  479. new MWF.widget.ScrollBar(this.naviContainerNode, {
  480. "style":"xApp_ProcessManager_StartMenu", "distance": 100, "friction": 4, "axis": {"x": false, "y": true}
  481. });
  482. }.bind(this));
  483. this.addEvent("resize", function(){this.setNaviSize();}.bind(this));
  484. //MWF.require("MWF.widget.ScrollBar", function(){
  485. // new MWF.widget.ScrollBar(this.menuNode, {
  486. // "style":"xApp_CMSModule_StartMenu", "distance": 100, "friction": 4, "axis": {"x": false, "y": true}
  487. // });
  488. //}.bind(this));
  489. if( this.options.categoryId == "all" ){
  490. this.options.categoryId = "whole";
  491. }
  492. if( this.status && this.status.categoryId ){
  493. this._loadMenu( this.status );
  494. }else if( this.options.categoryId && this.options.categoryId != "" ){
  495. if( this.options.viewId && this.options.viewId!="" ){
  496. this._loadMenu( { "categoryId" :this.options.categoryId , "viewId" : this.options.viewId } )
  497. }else{
  498. //this.getCategoryDefaultList(this.options.categoryId , function(viewId){
  499. // if( viewId ){
  500. // this._loadMenu( { "categoryId" :this.options.categoryId , "viewId" : viewId, "isCategory" : this.options.isCategory } );
  501. // }else{
  502. // this._loadMenu( { "categoryId" :this.options.categoryId , "isCategory" : this.options.isCategory, "naviIndex" : (this.options.naviIndex || 0) } );
  503. // }
  504. //}.bind(this))
  505. this._loadMenu( { "categoryId" :this.options.categoryId , "isCategory" : this.options.isCategory, "naviIndex" : (this.options.naviIndex || 0) } );
  506. }
  507. }else if( this.options.categoryAlias && this.options.categoryAlias != "" ){
  508. this.restActions.getCategoryByAlias( this.options.categoryAlias, function( json ){
  509. this.options.categoryId = json.data.id;
  510. if( this.options.viewId && this.options.viewId!="" ){
  511. this._loadMenu( { "categoryId" :this.options.categoryId , "viewId" : this.options.viewId } )
  512. }else{
  513. this._loadMenu( { "categoryId" :this.options.categoryId , "isCategory" : this.options.isCategory, "naviIndex" : (this.options.naviIndex || 0) } );
  514. }
  515. }.bind(this))
  516. }else{
  517. this._loadMenu( { "categoryId" :"whole" } )
  518. }
  519. },
  520. _loadMenu : function( options ){
  521. this.navi = new MWF.xApplication.cms.Module.Navi(this, this.naviNode, this.options.columnData, options );
  522. this.setNaviSize();
  523. },
  524. clearContent: function(){
  525. //debugger;
  526. if (this.moduleContent){
  527. if (this.view) delete this.view;
  528. this.moduleContent.destroy();
  529. this.searchNode.empty();
  530. this.moduleContent = null;
  531. }
  532. },
  533. openView : function(el, categoryData, revealData, searchKey, navi){
  534. if( revealData && revealData.type == "queryview" ){
  535. this.loadQueryView(el, categoryData, revealData, searchKey, navi);
  536. }else{
  537. this.loadList(el, categoryData, revealData, searchKey, navi);
  538. }
  539. },
  540. loadQueryView : function(el, categoryData, revealData, searchKey, navi){
  541. MWF.xDesktop.requireApp("cms.Module", "ViewExplorer", function(){
  542. this.clearContent();
  543. this.moduleContent = new Element("div", {
  544. "styles": this.css.moduleContent
  545. }).inject(this.rightContentNode);
  546. this.view = new MWF.xApplication.cms.Module.ViewExplorer(
  547. this.moduleContent,
  548. this,
  549. this.options.columnData,
  550. categoryData,
  551. revealData,
  552. {"isAdmin": this.isAdmin, "searchKey" : searchKey },
  553. this.searchNode
  554. );
  555. this.view.load();
  556. }.bind(this))
  557. },
  558. loadList : function(el, categoryData, revealData, searchKey, navi){
  559. MWF.xDesktop.requireApp("cms.Module", "ListExplorer", function(){
  560. this.clearContent();
  561. this.moduleContent = new Element("div", {
  562. "styles": this.css.moduleContent
  563. }).inject(this.rightContentNode);
  564. if (!this.restActions) this.restActions = MWF.Actions.get("x_cms_assemble_control"); //new MWF.xApplication.cms.Module.Actions.RestActions();
  565. this.view = new MWF.xApplication.cms.Module.ListExplorer(
  566. this.moduleContent,
  567. this.restActions,
  568. this.options.columnData,
  569. categoryData,
  570. revealData,
  571. {"isAdmin": this.isAdmin, "searchKey" : searchKey },
  572. this.searchNode
  573. );
  574. this.view.app = this;
  575. this.view.load();
  576. }.bind(this));
  577. },
  578. recordStatus: function(){
  579. var currentObject = this.navi.currentObject;
  580. if( currentObject ){
  581. var categoryId = currentObject.getCategoryId();
  582. if (categoryId){
  583. return {
  584. "columnId" : this.options.columnData.id,
  585. "categoryId" :categoryId,
  586. "isCategory" : currentObject.isCategory,
  587. "viewId" : currentObject.data.id
  588. };
  589. }else{
  590. return { "columnId" : this.options.columnData.id , "categoryId" : "whole"}
  591. }
  592. }else{
  593. return { "columnId" : this.options.columnData.id , "categoryId" : "whole" }
  594. }
  595. },
  596. setNaviSize: function(){
  597. //var titlebarSize = this.titleBar ? this.titleBar.getSize() : {"x":0,"y":0};
  598. var nodeSize = this.node.getSize();
  599. //var pt = this.naviContainerNode.getStyle("padding-top").toFloat();
  600. //var pb = this.naviContainerNode.getStyle("padding-bottom").toFloat();
  601. //var height = nodeSize.y-pt-pb-titlebarSize.y;
  602. this.naviContainerNode.setStyle("height", ""+nodeSize.y+"px");
  603. }
  604. });
  605. MWF.xApplication.cms.Module.Navi = new Class({
  606. Implements: [Options, Events],
  607. options : {
  608. "categoryId" :"" ,
  609. "viewId" : "",
  610. "isCategory" : false,
  611. "navi" : -1
  612. },
  613. initialize: function(app, node, columnData, options){
  614. this.setOptions(options);
  615. this.app = app;
  616. this.node = $(node);
  617. this.columnData = columnData;
  618. this.categoryList = [];
  619. this.css = this.app.css;
  620. this.load();
  621. },
  622. load: function(){
  623. var self = this;
  624. this.allView = new MWF.xApplication.cms.Module.NaviAllView( this, this.node, {} );
  625. new Element("div",{
  626. "styles" : this.css.viewNaviBottom
  627. }).inject(this.node);
  628. this.app.restActions.listCategory( this.columnData.id, function( json ) {
  629. json.data.each(function (d) {
  630. var isCurrent = false;
  631. var category = new MWF.xApplication.cms.Module.NaviCategory(this, this.node,d, {} );
  632. this.categoryList.push( category );
  633. this.fireEvent("postLoad");
  634. }.bind(this))
  635. }.bind(this))
  636. }
  637. });
  638. MWF.xApplication.cms.Module.NaviCategory = new Class({
  639. Implements: [Options, Events],
  640. options: {
  641. "style": "default"
  642. },
  643. initialize: function ( navi, container, data, options) {
  644. this.setOptions(options);
  645. this.navi = navi;
  646. this.app = navi.app;
  647. this.container = $(container);
  648. this.data = data;
  649. this.css = this.app.css;
  650. this.load();
  651. },
  652. load: function () {
  653. var _self = this;
  654. this.isCategory = true;
  655. this.isCurrent = false;
  656. this.isExpended = false;
  657. this.hasSub = false;
  658. this.naviViewList = [];
  659. if( this.navi.options.categoryId == this.data.id && this.navi.options.isCategory ){
  660. this.isCurrent = true;
  661. }
  662. this.reveal = this.getRevealData();
  663. this.node = new Element("div.categoryNaviNode", {
  664. "styles": this.css.categoryNaviNode
  665. }).inject(this.container);
  666. this.expendNode = new Element("div.expendNode").inject(this.node);
  667. this.setExpendNodeStyle();
  668. if( this.hasSub ){
  669. this.expendNode.addEvent( "click" , function(ev){
  670. this.triggerExpend();
  671. ev.stopPropagation();
  672. }.bind(this));
  673. }
  674. this.textNode = new Element("div.categoryNaviTextNode",{
  675. "styles": this.css.categoryNaviTextNode,
  676. "text": this.data.name //this.defaultRevealData.id == "defaultList" ? this.data.name : this.defaultRevealData.showName
  677. }).inject(this.node);
  678. this.node.addEvents({
  679. "mouseover": function(){ if ( !_self.isCurrent )this.setStyles(_self.app.css.categoryNaviNode_over) },
  680. "mouseout": function(){ if ( !_self.isCurrent )this.setStyles( _self.app.css.categoryNaviNode ) },
  681. click : function(){ _self.setCurrent(this);}
  682. });
  683. this.listNode = new Element("div.viewNaviListNode",{
  684. "styles" : this.css.viewNaviListNode
  685. }).inject(this.container);
  686. this.loadListContent();
  687. if( this.isCurrent ){
  688. this.setCurrent();
  689. }
  690. },
  691. getRevealData: function(){
  692. var j = this.data.extContent;
  693. if( j ){
  694. this.extContent = JSON.parse( j );
  695. }
  696. if( !this.extContent || !this.extContent.reveal || this.extContent.reveal.length == 0 ){ //兼容以前的设置
  697. this.extContent = { reveal : [] };
  698. this.app.restActions.listViewByCategory( this.data.id, function(json){
  699. ( json.data || [] ).each( function(d){
  700. var itemData = {
  701. "type" : "list",
  702. "name" : d.name,
  703. "showName" : d.name,
  704. "id" : d.id,
  705. "alias" : d.alias,
  706. "appId" : d.appId,
  707. "formId" : d.formId,
  708. "formName" : d.formName
  709. };
  710. this.extContent.reveal.push( itemData );
  711. }.bind(this));
  712. }.bind(this), null, false );
  713. }
  714. this.extContent.reveal.each( function( r ){
  715. if(this.data.defaultViewName && r.id == this.data.defaultViewName ){
  716. this.defaultRevealData = r;
  717. }else{
  718. this.isExpended = true;
  719. this.hasSub = true;
  720. }
  721. }.bind(this));
  722. if( !this.extContent || !this.extContent.reveal || this.extContent.reveal.length == 0 ){
  723. this.extContent = { reveal : [{
  724. id : "defaultList",
  725. showName : "系统列表",
  726. name : "系统列表"
  727. }] };
  728. }
  729. this.revealData = this.extContent.reveal;
  730. if( !this.defaultRevealData ){
  731. this.defaultRevealData = {
  732. id : "defaultList",
  733. showName : "系统列表",
  734. name : "系统列表"
  735. }
  736. }
  737. },
  738. setExpendNodeStyle : function(){
  739. var style;
  740. if( this.hasSub ){
  741. if( this.isExpended ){
  742. if( this.isCurrent ){
  743. style = this.css.categoryExpendNode_selected;
  744. }else{
  745. style = this.css.categoryExpendNode;
  746. }
  747. }else{
  748. if( this.isCurrent ){
  749. style = this.css.categoryCollapseNode_selected;
  750. }else{
  751. style = this.css.categoryCollapseNode;
  752. }
  753. }
  754. }else{
  755. style = this.css.emptyExpendNode;
  756. }
  757. this.expendNode.setStyles( style );
  758. },
  759. triggerExpend : function(){
  760. if( this.hasSub ){
  761. if( this.isExpended ){
  762. this.isExpended = false;
  763. this.listNode.setStyle("display","none")
  764. }else{
  765. this.isExpended = true;
  766. this.listNode.setStyle("display","")
  767. }
  768. this.setExpendNodeStyle();
  769. }
  770. },
  771. setCurrent : function(){
  772. if( this.navi.currentObject ){
  773. this.navi.currentObject.cancelCurrent();
  774. }
  775. this.node.setStyles( this.css.categoryNaviNode_selected );
  776. if( this.hasSub ){
  777. if( this.isExpended ){
  778. this.expendNode.setStyles( this.css.categoryExpendNode_selected );
  779. }else{
  780. this.expendNode.setStyles( this.css.categoryCollapseNode_selected );
  781. }
  782. }
  783. this.isCurrent = true;
  784. this.navi.currentObject = this;
  785. var action = this.app.importAction;
  786. if( action ){
  787. action.setStyle("display", (this.data.importViewId && this.app.isAdmin) ? "" : "none");
  788. }
  789. action = this.app.exportAction;
  790. if( action ){
  791. action.setStyle("display", (this.data.importViewId && this.app.isAdmin) ? "" : "none");
  792. }
  793. this.loadView();
  794. },
  795. cancelCurrent : function(){
  796. this.isCurrent = false;
  797. this.node.setStyles( this.css.categoryNaviNode );
  798. if( this.hasSub ){
  799. if( this.isExpended ){
  800. this.expendNode.setStyles( this.css.categoryExpendNode );
  801. }else{
  802. this.expendNode.setStyles( this.css.categoryCollapseNode );
  803. }
  804. }
  805. },
  806. loadView: function( searchkey ){
  807. this.app.openView( this, this.data, this.viewData || this.defaultRevealData, searchkey || "", this );
  808. },
  809. loadListContent : function(){
  810. this.revealData.each( function( d , i){
  811. if( d.id != this.defaultRevealData.id ){
  812. var naviView = new MWF.xApplication.cms.Module.NaviView(this.navi, this, this.listNode, d, {
  813. "style": this.options.style,
  814. "index" : i
  815. });
  816. this.naviViewList.push( naviView );
  817. }
  818. }.bind(this));
  819. new Element("div", {
  820. "styles": this.css.viewNaviSepartorNode
  821. }).inject( this.listNode );
  822. },
  823. getCategoryId : function(){
  824. return this.data.id;
  825. }
  826. });
  827. MWF.xApplication.cms.Module.NaviView = new Class({
  828. Implements: [Options, Events],
  829. options: {
  830. "style": "default",
  831. "index" : 0
  832. },
  833. initialize: function ( navi, category, container, data, options) {
  834. this.setOptions(options);
  835. this.navi = navi;
  836. this.category = category;
  837. this.app = navi.app;
  838. this.data = data;
  839. this.container = $(container);
  840. this.css = this.app.css;
  841. this.load();
  842. },
  843. load: function(){
  844. this.isDefault = this.data.id == "defaultList";
  845. this.isCurrent = false;
  846. this.isCategory = false;
  847. if( this.navi.options.categoryId == this.category.data.id && !this.navi.options.isCategory ){
  848. if( this.navi.options.viewId == "defaultList" && this.isDefault ){
  849. this.isCurrent = true;
  850. }else if( this.navi.options.viewId == this.data.id ){
  851. this.isCurrent = true;
  852. }else if( this.navi.options.naviIndex == this.options.index ){
  853. this.isCurrent = true;
  854. }
  855. }
  856. var _self = this;
  857. this.node = new Element("div.viewNaviNode", {
  858. "styles": this.css.viewNaviNode,
  859. "text" : this.isDefault ? this.app.lp.defaultView : this.data.showName
  860. }).inject(this.container);
  861. this.node.addEvents({
  862. "mouseover": function(){ if (!_self.isCurrent)this.setStyles(_self.css.viewNaviNode_over) },
  863. "mouseout": function(){ if (!_self.isCurrent)this.setStyles( _self.css.viewNaviNode ) },
  864. "click": function (el) {
  865. _self.setCurrent();
  866. }
  867. });
  868. if( this.isCurrent ){
  869. this.setCurrent()
  870. }
  871. },
  872. setCurrent : function(){
  873. if( this.navi.currentObject ){
  874. this.navi.currentObject.cancelCurrent();
  875. }
  876. this.node.setStyles( this.css.viewNaviNode_selected );
  877. this.isCurrent = true;
  878. this.navi.currentObject = this;
  879. var action = this.app.importAction;
  880. if( action ){
  881. action.setStyle("display", (this.category.data.importViewId && this.app.isAdmin) ? "" : "none");
  882. }
  883. action = this.app.exportAction;
  884. if( action ){
  885. action.setStyle("display", (this.category.data.importViewId && this.app.isAdmin) ? "" : "none");
  886. }
  887. this.loadView();
  888. },
  889. cancelCurrent : function(){
  890. this.isCurrent = false;
  891. this.node.setStyles( this.css.viewNaviNode );
  892. },
  893. getCategoryId : function(){
  894. return this.category.data.id;
  895. },
  896. loadView : function( searchKey ){
  897. this.app.openView( this, this.category.data, this.data, searchKey || "", this );
  898. }
  899. });
  900. MWF.xApplication.cms.Module.NaviAllView = new Class({
  901. Implements: [Options, Events],
  902. options: {
  903. "style": "default"
  904. },
  905. initialize: function ( navi, container, options) {
  906. this.setOptions(options);
  907. this.navi = navi;
  908. this.app = navi.app;
  909. this.container = $(container);
  910. this.css = this.app.css;
  911. this.data = {
  912. "isAll" : true,
  913. "id" : "defaultList"
  914. };
  915. this.load();
  916. },
  917. load: function(){
  918. var _self = this;
  919. this.isDefault = true;
  920. this.isAll = true;
  921. this.isCurrent = false;
  922. this.isCategory = false;
  923. if( this.navi.options.categoryId == "whole" ){
  924. this.isCurrent = true;
  925. }
  926. this.listNode = new Element("div.viewNaviListNode_all",{
  927. "styles" : this.css.viewNaviListNode_all
  928. }).inject(this.container);
  929. this.node = new Element("div.viewNaviNode_all", {
  930. "styles": this.css.viewNaviNode_all,
  931. "text" : this.app.lp.allDocument
  932. }).inject(this.listNode);
  933. this.node.addEvents({
  934. "mouseover": function(){ if ( !_self.isCurrent )this.setStyles(_self.css.viewNaviNode_all_over) },
  935. "mouseout": function(){ if ( !_self.isCurrent )this.setStyles( _self.css.viewNaviNode_all ) },
  936. "click": function (el) {
  937. _self.setCurrent();
  938. }
  939. });
  940. new Element("div", {
  941. "styles": this.css.viewNaviSepartorNode
  942. }).inject(this.listNode);
  943. if( this.isCurrent ){
  944. this.setCurrent()
  945. }
  946. },
  947. setCurrent : function(){
  948. if( this.navi.currentObject ){
  949. this.navi.currentObject.cancelCurrent();
  950. }
  951. this.node.setStyles( this.css.viewNaviNode_all_selected );
  952. this.isCurrent = true;
  953. this.navi.currentObject = this;
  954. var action = this.app.importAction;
  955. if( action ){
  956. action.setStyle("display","none");
  957. }
  958. var action = this.app.exportAction;
  959. if( action ){
  960. action.setStyle("display","none");
  961. }
  962. this.loadView();
  963. },
  964. cancelCurrent : function(){
  965. this.isCurrent = false;
  966. this.node.setStyles( this.css.viewNaviNode_all );
  967. },
  968. getCategoryId : function(){
  969. return null;
  970. },
  971. loadView : function( searchKey ){
  972. this.app.openView( this, null, this.data, searchKey || "", this );
  973. }
  974. });