Main.js 35 KB

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