Main.js 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570
  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. this.titleActionBar = new Element("div", {
  61. "styles": this.css.titleActionBar
  62. }).inject(this.titleBar );
  63. },
  64. loadApplicationContent: function(){
  65. if( this.options.columnData ){
  66. this.setColumnDataConfig();
  67. this.setTitle(this.options.columnData.appName);
  68. this.loadController(function(){
  69. this.loadTitle(function(){
  70. this.loadMenu();
  71. }.bind(this));
  72. }.bind(this))
  73. }else if( (this.status && this.status.columnId) || this.options.columnId ){
  74. var columnId = this.options.columnId || this.status.columnId;
  75. this.loadColumnData( columnId, function(){
  76. this.loadController(function(){
  77. this.loadTitle(function(){
  78. this.loadMenu();
  79. }.bind(this));
  80. }.bind(this))
  81. }.bind(this))
  82. }else if( this.options.columnAlias ){
  83. this.restActions.getColumnByAlias( this.options.columnAlias, function( json ){
  84. this.options.columnData = json.data;
  85. this.setColumnDataConfig();
  86. this.setTitle(this.options.columnData.appName);
  87. this.loadController(function(){
  88. this.loadTitle(function(){
  89. this.loadMenu();
  90. }.bind(this));
  91. }.bind(this))
  92. }.bind(this))
  93. }
  94. },
  95. setColumnDataConfig : function(){
  96. if( !this.options.columnData.config ){
  97. this.options.columnData.config = {};
  98. }else if( typeOf(this.options.columnData.config) === "string" ){
  99. this.options.columnData.config = JSON.parse( this.options.columnData.config || {} );
  100. }
  101. },
  102. loadColumnData : function(columnId, callback){
  103. this.restActions.getColumn( columnId, function( json ){
  104. this.options.columnData = json.data;
  105. this.setTitle(this.options.columnData.appName);
  106. this.setColumnDataConfig();
  107. //MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  108. //MWF.require("o2.xScript.Macro", null, false);
  109. //var scriptAction = new MWF.xScript.Actions.CMSScriptActions();
  110. //scriptAction.getScriptByName( this.options.columnData.id, "_config", [], function(json){
  111. // if (json.data){
  112. // try{
  113. // this.options.columnData = Object.merge(this.options.columnData,JSON.parse(json.data.text));
  114. // }catch(e){
  115. // }
  116. // }
  117. //}.bind(this), null, false);
  118. if(callback)callback()
  119. }.bind(this))
  120. },
  121. loadController: function(callback){
  122. //this.restActions.listColumnController(this.options.columnData.id, function( json ){
  123. // json.data = json.data || [];
  124. // json.data.each(function(item){
  125. // this.controllers.push(item.adminUid)
  126. // }.bind(this));
  127. // this.isAdmin = MWF.AC.isCMSManager() || this.controllers.contains(layout.desktop.session.user.distinguishedName);
  128. // if(callback)callback(json);
  129. //}.bind(this));
  130. this.restActions.isAppInfoManager( this.options.columnData.id, function( json ){
  131. this.isAdmin = MWF.AC.isCMSManager() || json.data.value;
  132. if(callback)callback(json);
  133. }.bind(this))
  134. },
  135. loadTitle : function(callback){
  136. if( this.isAdmin ){
  137. //this.loadImportActionNode();
  138. //this.loadExportActionNode();
  139. }
  140. this.loadCreateDocumentActionNode(
  141. function(){
  142. this.loadTitleIconNode();
  143. this.loadTitleContentNode();
  144. this.loadBatchAction();
  145. this.loadPastEvent();
  146. this.loadSearchNode();
  147. if(callback)callback();
  148. }.bind(this)
  149. );
  150. },
  151. loadBatchAction: function(){
  152. if( !this.isAdmin )return;
  153. this.batchAction = new Element("div", {
  154. "styles": this.css.batchAction,
  155. "text" : "选择"
  156. }).inject(this.titleActionBar);
  157. this.batchAction.addEvents({
  158. "click": function(e){
  159. if( this.view ){
  160. if( this.view.selectEnable ){
  161. this.selectEnable = false;
  162. this.batchAction.setStyles( this.css.batchAction );
  163. this.batchAction.set("text","选择");
  164. this.view.disableSelectMode();
  165. this.cancelBatchRemoveAction();
  166. this.cancelChangeCategoryAction();
  167. this.cancelCopyActionNode();
  168. }else{
  169. this.selectEnable = true;
  170. this.batchAction.setStyles( this.css.batchAction_over );
  171. this.batchAction.set("text","取消选择");
  172. this.view.selectMode();
  173. this.loadCopyActionNode();
  174. this.loadChangeCategoryAction();
  175. this.loadBatchRemoveAction();
  176. }
  177. }
  178. }.bind(this),
  179. "mouseover" : function(e){
  180. if( this.view.selectEnable )return;
  181. this.batchAction.setStyles( this.css.batchAction_over )
  182. }.bind(this),
  183. "mouseout" : function(e){
  184. if( this.view.selectEnable )return;
  185. this.batchAction.setStyles( this.css.batchAction )
  186. }.bind(this)
  187. });
  188. },
  189. getSearchBarSize : function(){
  190. var x_action = this.titleActionBar.getSize().x;
  191. var x_titlebar = this.titleBar.getSize().x;
  192. return x_titlebar - x_action;
  193. },
  194. loadPastEvent : function(){
  195. if( !this.isAdmin )return;
  196. this.keyPasteItemsFun = this.keyPasteItems.bind(this);
  197. if (window.clipboardData){
  198. this.addEvent("paste", this.keyPasteItemsFun);
  199. }else{
  200. document.addEventListener('paste', this.keyPasteItemsFun);
  201. //this.addEvent("queryClose", function(){
  202. // if (this.keyPasteItemsFun) document.removeEventListener('paste', this.keyPasteItemsFun);
  203. //}.bind(this));
  204. }
  205. },
  206. loadCreateDocumentActionNode: function( callback ){
  207. this.restActions.listCategoryByPublisher( this.options.columnData.id, function( json ){
  208. if( json.data && json.data.length ){
  209. this.createDocumentAction = new Element("div", {
  210. "styles": this.css.createDocumentAction,
  211. "text" : this.lp.start
  212. }).inject(this.titleActionBar);
  213. this.createDocumentAction.addEvents({
  214. "click": function(e){
  215. MWF.xDesktop.requireApp("cms.Index", "Newer", null, false);
  216. //if(this.options.columnData.latest===undefined) this.options.columnData.latest = true;
  217. //if(this.options.columnData.ignoreTitle===undefined) this.options.columnData.ignoreTitle = false;
  218. this.creater = new MWF.xApplication.cms.Index.Newer( this.options.columnData, null, this, this.view, {
  219. restrictToColumn : true
  220. //ignoreTitle : this.options.columnData.ignoreTitle,
  221. //latest : this.options.columnData.latest
  222. });
  223. this.creater.load();
  224. }.bind(this),
  225. "mouseover" : function(e){
  226. this.createDocumentAction.setStyles( this.css.createDocumentAction_over )
  227. }.bind(this),
  228. "mouseout" : function(e){
  229. this.createDocumentAction.setStyles( this.css.createDocumentAction )
  230. }.bind(this)
  231. });
  232. }
  233. if(callback)callback();
  234. }.bind(this));
  235. },
  236. cancelChangeCategoryAction : function(){
  237. if(this.moveAction)this.moveAction.destroy();
  238. this.moveAction = null;
  239. },
  240. loadChangeCategoryAction : function(){
  241. if( !this.isAdmin )return;
  242. this.moveAction = new Element("div", {
  243. "styles": this.css.moveDocumentAction,
  244. "text" : "移动"
  245. }).inject(this.titleActionBar);
  246. this.moveAction.addEvents({
  247. "click": function(e){
  248. var _self = this;
  249. if( this.view ){
  250. var itemIds = this.view.getSelectedIds();
  251. if (!itemIds.length) {
  252. this.notice("请先选择文档","error");
  253. return;
  254. }
  255. this.loadSelectColumnDialog( function( data ){
  256. if( data && data.id ){
  257. var text = "移动后将在本分类删除,确定要移动选中的"+itemIds.length+"个文档到"+data.categoryName+"?";
  258. this.confirm("warn", e, "移动确认", text, 350, 120, function(){
  259. _self.restActions.moveDocumentToCategory({
  260. ids : itemIds,
  261. categoryId : data.id
  262. }, function(){
  263. _self.notice("移动成功", "success");
  264. _self.view.reload();
  265. this.close();
  266. }.bind(this))
  267. }, function(){
  268. this.close();
  269. });
  270. }
  271. }.bind(this))
  272. }
  273. }.bind(this),
  274. "mouseover" : function(e){
  275. this.moveAction.setStyles( this.css.moveDocumentAction_over )
  276. }.bind(this),
  277. "mouseout" : function(e){
  278. this.moveAction.setStyles( this.css.moveDocumentAction )
  279. }.bind(this)
  280. });
  281. },
  282. cancelBatchRemoveAction : function(){
  283. if(this.batchRemoveAction)this.batchRemoveAction.destroy();
  284. this.batchRemoveAction = null;
  285. },
  286. loadBatchRemoveAction : function(){
  287. if( !this.isAdmin )return;
  288. var _self = this;
  289. this.batchRemoveAction = new Element("div", {
  290. "styles": this.css.batchRemoveDocumentAction,
  291. "text" : this.lp.batchRemove
  292. }).inject(this.titleActionBar);
  293. this.batchRemoveAction.addEvents({
  294. "click": function(e){
  295. if( this.view ){
  296. var itemIds = this.view.getSelectedIds();
  297. if (itemIds.length) {
  298. _self.readyRemove = true;
  299. var text = "删除后无法恢复,确定要删除选中的"+itemIds.length+"个文档?";
  300. this.confirm("warn", e, "清除确认", text, 350, 120, function(){
  301. _self.removeDocumentList(itemIds);
  302. this.close();
  303. }, function(){
  304. _self.readyRemove = false;
  305. this.close();
  306. });
  307. }else{
  308. this.notice("请先选择文档","error")
  309. }
  310. }
  311. }.bind(this),
  312. "mouseover" : function(e){
  313. this.batchRemoveAction.setStyles( this.css.batchRemoveDocumentAction_over )
  314. }.bind(this),
  315. "mouseout" : function(e){
  316. this.batchRemoveAction.setStyles( this.css.batchRemoveDocumentAction )
  317. }.bind(this)
  318. });
  319. },
  320. //loadBatchRemoveAction : function(){
  321. // if( !this.isAdmin )return;
  322. //
  323. // this.batchRemoveAction = new Element("div", {
  324. // "styles": this.css.batchRemoveDocumentAction,
  325. // "text" : this.lp.batchRemove
  326. // }).inject(this.titleBar);
  327. // this.batchRemoveAction.addEvents({
  328. // "click": function(e){
  329. // if( this.view ){
  330. // if( this.view.selectEnable ){
  331. // this.view.disableSelectMode();
  332. // this.batchRemoveConfirmAction.setStyle("display","none");
  333. // //this.batchRemoveAction.set("text",this.lp.batchRemove);
  334. // }else{
  335. // this.view.selectMode();
  336. // this.batchRemoveConfirmAction.setStyle("display","");
  337. // //this.batchRemoveAction.set("text",this.lp.cancel);
  338. // }
  339. // }
  340. // }.bind(this),
  341. // "mouseover" : function(e){
  342. // this.batchRemoveAction.setStyles( this.css.batchRemoveDocumentAction_over )
  343. // }.bind(this),
  344. // "mouseout" : function(e){
  345. // this.batchRemoveAction.setStyles( this.css.batchRemoveDocumentAction )
  346. // }.bind(this)
  347. // });
  348. //
  349. //
  350. // this.batchRemoveConfirmAction = new Element("div", {
  351. // "styles": this.css.batchRemoveConfirmDocumentAction,
  352. // "text" : this.lp.batchRemoveConfirm
  353. // }).inject(this.titleBar);
  354. // var _self = this;
  355. // this.batchRemoveConfirmAction.addEvents({
  356. // "click": function (e) {
  357. // var itemIds = this.view.getSelectedIds();
  358. // if (itemIds.length) {
  359. // _self.readyRemove = true;
  360. // var text = "删除后无法恢复,确定要删除选中的"+itemIds.length+"个文档?";
  361. // this.confirm("warn", e, "清除确认", text, 350, 120, function(){
  362. //
  363. // _self.removeDocumentList(itemIds);
  364. //
  365. // this.close();
  366. //
  367. // }, function(){
  368. // _self.readyRemove = false;
  369. // this.close();
  370. // });
  371. // }else{
  372. // this.notice("请先选择文档","error")
  373. // }
  374. // }.bind(this)
  375. // });
  376. // this.batchRemoveConfirmAction.setStyle("display","none");
  377. //},
  378. removeDocumentList : function( itemIds ){
  379. var count = 0;
  380. itemIds.each( function(id){
  381. this.restActions.removeDocument(id, function(json){
  382. count++;
  383. if( count === itemIds.length ){
  384. this.notice("清除成功", "success");
  385. //this.view.disableSelectMode();
  386. this.view.reload();
  387. }
  388. }.bind(this));
  389. }.bind(this))
  390. },
  391. cancelCopyActionNode : function(){
  392. if (window.clipboardData){
  393. if (this.keyCopyItemsFun)this.removeEvent("copy", this.keyCopyItemsFun);
  394. }else{
  395. if (this.keyCopyItemsFun) document.removeEventListener('copy', this.keyCopyItemsFun);
  396. }
  397. this.keyCopyItemsFun = null;
  398. if(this.copyAction)this.copyAction.destroy();
  399. this.copyAction = null;
  400. },
  401. loadCopyActionNode : function(){
  402. if( !this.isAdmin )return;
  403. this.copyAction = new Element("div", {
  404. "styles": this.css.copyDocumentAction,
  405. "text" : "启用复制"
  406. }).inject(this.titleActionBar);
  407. this.copyAction.addEvents({
  408. "click": function(e){
  409. if( this.view ){
  410. if( this.keyCopyItemsFun )return;
  411. this.keyCopyItemsFun = this.keyCopyItems.bind(this);
  412. if (window.clipboardData){
  413. this.addEvent("copy", this.keyCopyItemsFun);
  414. }else{
  415. document.addEventListener('copy', this.keyCopyItemsFun);
  416. //this.addEvent("queryClose", function(){
  417. // if (this.keyCopyItemsFun) document.removeEventListener('copy', this.keyCopyItemsFun);
  418. //}.bind(this));
  419. }
  420. this.notice( this.lp.copyInfor );
  421. }
  422. }.bind(this),
  423. "mouseover" : function(e){
  424. this.copyAction.setStyles( this.css.copyDocumentAction_over )
  425. }.bind(this),
  426. "mouseout" : function(e){
  427. this.copyAction.setStyles( this.css.copyDocumentAction )
  428. }.bind(this)
  429. });
  430. },
  431. //loadCopyActionNode : function(){
  432. // if( !this.isAdmin )return;
  433. // this.copyAction = new Element("div", {
  434. // "styles": this.css.copyDocumentAction,
  435. // "text" : this.lp.copy
  436. // }).inject(this.titleBar);
  437. // this.copyAction.addEvents({
  438. // "click": function(e){
  439. // if( this.view ){
  440. // if( this.view.selectEnable ){
  441. // this.view.disableSelectMode();
  442. // if (window.clipboardData){
  443. // if (this.keyCopyItemsFun)this.removeEvent("copy", this.keyCopyItemsFun);
  444. // }else{
  445. // if (this.keyCopyItemsFun) document.removeEventListener('copy', this.keyCopyItemsFun);
  446. // }
  447. // this.keyCopyItemsFun = null;
  448. // }else{
  449. // this.view.selectMode();
  450. // this.keyCopyItemsFun = this.keyCopyItems.bind(this);
  451. // if (window.clipboardData){
  452. // this.addEvent("copy", this.keyCopyItemsFun);
  453. // }else{
  454. // document.addEventListener('copy', this.keyCopyItemsFun);
  455. // //this.addEvent("queryClose", function(){
  456. // // if (this.keyCopyItemsFun) document.removeEventListener('copy', this.keyCopyItemsFun);
  457. // //}.bind(this));
  458. // }
  459. // this.notice( this.lp.copyInfor );
  460. // }
  461. // }
  462. // }.bind(this),
  463. // "mouseover" : function(e){
  464. // this.copyAction.setStyles( this.css.copyDocumentAction_over )
  465. // }.bind(this),
  466. // "mouseout" : function(e){
  467. // this.copyAction.setStyles( this.css.copyDocumentAction )
  468. // }.bind(this)
  469. // });
  470. //},
  471. keyCopyItems: function(e){
  472. if (layout.desktop.currentApp && layout.desktop.currentApp.appId===this.appId) {
  473. var itemIds = this.view.getSelectedIds();
  474. if (itemIds.length) {
  475. var items = [];
  476. var i = 0;
  477. var checkItems = function (e) {
  478. if (i >= itemIds.length) {
  479. if (items.length) {
  480. var str = JSON.encode(items);
  481. if (e && e.clipboardData) {
  482. e.clipboardData.setData('text/plain', str);
  483. e.preventDefault();
  484. } else {
  485. window.clipboardData.setData("Text", str);
  486. }
  487. this.notice(this.lp.copyed, "success");
  488. }
  489. }
  490. }.bind(this);
  491. itemIds.each(function (id) {
  492. this.restActions.getDocument(id, function (json) {
  493. json.data.elementType = "cmsDocument";
  494. items.push(json.data);
  495. i++;
  496. checkItems(e);
  497. }.bind(this), null, false)
  498. }.bind(this));
  499. }
  500. }
  501. },
  502. keyPasteItems: function(e){
  503. if (layout.desktop.currentApp && layout.desktop.currentApp.appId===this.appId) {
  504. var dataStr = "";
  505. if (e && e.clipboardData) {
  506. dataStr = e.clipboardData.getData('text/plain');
  507. } else {
  508. dataStr = window.clipboardData.getData("Text");
  509. }
  510. var data = JSON.decode(dataStr);
  511. this.listPublishableCategoryInfo(function(){
  512. this.pasteItem(data, 0);
  513. }.bind(this))
  514. }
  515. },
  516. listPublishableCategoryInfo : function( callback ){
  517. this.publishableCategoryInfoObject_id = {};
  518. this.publishableCategoryInfoObject_alias = {};
  519. this.publishableCategoryInfoObject_name = {};
  520. this.categoryTransformMap = {};
  521. this.categoryRadioHtml = "";
  522. o2.Actions.load("x_cms_assemble_control").CategoryInfoAction.listPublishableCategoryInfo( this.options.columnData.id, function(json){
  523. ( json.data || [] ).each( function(c){
  524. this.publishableCategoryInfoObject_id[c.id] = c;
  525. this.publishableCategoryInfoObject_alias[c.categoryAlias] = c;
  526. this.publishableCategoryInfoObject_name[c.categoryName] = c;
  527. this.categoryRadioHtml += "<div><input type='radio' name='categoryRadio' value='"+ c.id+"'/>" + c.categoryName + "(" + c.categoryAlias +")</div>"
  528. }.bind(this));
  529. this.categoryRadioHtml = "<div style='overflow: hidden; margin: 10px 0px; padding: 5px 10px; background-color: #ffffff; border-radius: 6px;'>" +
  530. this.categoryRadioHtml + "</div>"
  531. if(callback)callback();
  532. }.bind(this));
  533. },
  534. pasteItem: function(data, i){
  535. if (i<data.length){
  536. var item = data[i];
  537. if (item.elementType==="cmsDocument"){
  538. this.saveItemAs(item, function(){
  539. i++;
  540. this.pasteItem(data, i);
  541. }.bind(this), function(){
  542. i++;
  543. this.pasteItem(data, i);
  544. }.bind(this), function(){
  545. this.view.reload();
  546. }.bind(this));
  547. }else{
  548. i++;
  549. this.pasteItem(data, i);
  550. }
  551. }else{
  552. this.view.reload();
  553. }
  554. },
  555. saveItemAs: function(data, success, failure, cancel){
  556. var lp = this.lp;
  557. var _self = this;
  558. if( this.publishableCategoryInfoObject_id[ data.document.categoryId ] ){
  559. this._saveItemAs(data, success, failure, cancel );
  560. }else if( this.categoryTransformMap[ data.document.categoryId ] ){
  561. this._saveItemAs(data, success, failure, cancel, this.categoryTransformMap[ data.document.categoryId ] );
  562. }else{
  563. var text;
  564. if( this.publishableCategoryInfoObject_alias[ data.document.categoryAlias ] ){
  565. text = lp.copyConfirmCategoryInfor_hasSameAlias + "。<br/>" + lp.copyConfirmCateogyrInfor_withChoice
  566. }else if( this.publishableCategoryInfoObject_name[ data.document.categoryName ] ){
  567. text = lp.copyConfirmCategoryInfor_hasSameName + "。<br/>" + lp.copyConfirmCateogyrInfor_withChoice
  568. }else{
  569. text = lp.copyConfirmCategoryInfor_noCategory + ":"
  570. }
  571. text = text.replace("{alias}", "(<span style='color:red;'>" + data.document.categoryAlias + "</span>)" );
  572. text = text.replace("{name}", "(<span style='color:red;'>" + data.document.categoryName + "</span>)" );
  573. var html = "<div style='overflow-y:auto;height:300px'>";
  574. html += "<div style='overflow: hidden; margin: 10px 0px; padding: 5px 10px; background-color: #ffffff; border-radius: 6px;'>";
  575. html += " <div style='clear: both;font-weight: bold; font-size:14px;'>"+lp.copyTarget+" "+data.document.title+"</div>";
  576. html += " <div style='font-size:12px; color: #666666; float: left;'>"+data.document.publishTime+"</div>";
  577. html += " <div style='font-size:12px; color: #666666; float: left; margin-left: 20px;'>"+MWF.name.cn(data.document.creatorPersonShort)+"</div>";
  578. html += "</div>";
  579. html += "<div>" + text + "</div>" + this.categoryRadioHtml;
  580. html += "<div><input type='checkbox' value='true' name='useSameChoice'>"+lp.copyConfirm_SameCategory+"</div>";
  581. html += "</div>";
  582. // html += "<>"
  583. this.dlg("inofr", null, lp.copyConfirmCategoryTitle, {"html": html}, 500, 360, [
  584. {
  585. "text": lp.copy,
  586. "action": function(){
  587. var categoryRadio = this.node.getElements("[name='categoryRadio']");
  588. var checkbox = this.node.getElement("[name='useSameChoice']");
  589. var newCategory;
  590. for( var i=0; i<categoryRadio.length; i++ ){
  591. if( categoryRadio[i].checked ){
  592. newCategory = _self.publishableCategoryInfoObject_id[ categoryRadio[i].get("value") ];
  593. }
  594. }
  595. if( !newCategory ){
  596. if( _self.publishableCategoryInfoObject_alias[ data.document.categoryAlias ] ){
  597. newCategory = _self.publishableCategoryInfoObject_alias[ data.document.categoryAlias ];
  598. }else if( _self.publishableCategoryInfoObject_name[ data.document.categoryName ] ){
  599. newCategory = _self.publishableCategoryInfoObject_name[ data.document.categoryName ];
  600. }
  601. }
  602. if( newCategory ){
  603. if( checkbox.checked )_self.categoryTransformMap[ data.document.categoryId ] = newCategory;
  604. this.close();
  605. _self._saveItemAs(data, success, failure, cancel, newCategory );
  606. }else{
  607. _self.notice( lp.notSelectCategory, "error" )
  608. }
  609. //_self.saveItemAsUpdate(someItem, data, success, failure);
  610. }
  611. },
  612. {
  613. "text": lp.copyConfirm_skip,
  614. "action": function(){/*nothing*/ this.close(); if (success) success();}
  615. },
  616. {
  617. "text": lp.copyConfirm_cancel,
  618. "action": function(){this.close(); if (cancel) cancel();}
  619. }
  620. ]);
  621. }
  622. },
  623. _saveItemAs: function(data, success, failure, cancel, newCategory ){
  624. this.restActions.getDocument(data.document.id, function(dJson){
  625. var someItem = dJson.data;
  626. var flag = false;
  627. if (someItem){
  628. if( newCategory ){
  629. if( newCategory.id !== someItem.document.categoryId ){ //如果已有文档的分类和新分类不一样,直接新建
  630. this.saveItemAsNew(data, success, failure, true, newCategory)
  631. }else{ //如果已有文档的分类和新分类一样,需要询问
  632. flag = true;
  633. }
  634. }else{ //如果使用原有分类,需要询问
  635. flag = true;
  636. }
  637. if( flag ){
  638. var lp = this.lp;
  639. var _self = this;
  640. var d1 = new Date().parse(data.document.publishTime);
  641. var d2 = new Date().parse(someItem.document.publishTime);
  642. var html = "<div>"+lp.copyConfirmInfor+"</div>";
  643. 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>";
  644. html += "<div style='font-size:12px; color: #666666; float: left'>"+someItem.document.publishTime+"</div>" +
  645. "<div style='font-size:12px; color: #666666; float: left; margin-left: 20px;'>"+MWF.name.cn(someItem.document.creatorPersonShort)+"</div>" +
  646. "<div style='color: red; float: right;'>"+((d1>=d2) ? "": lp.copynew)+"</div></div>";
  647. 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>";
  648. html += "<div style='font-size:12px; color: #666666; float: left;'>"+data.document.publishTime+"</div>" +
  649. "<div style='font-size:12px; color: #666666; float: left; margin-left: 20px;'>"+MWF.name.cn(data.document.creatorPersonShort)+"</div>" +
  650. "<div style='color: red; float: right;'>"+((d1<=d2) ? "": lp.copynew)+"</div></div>";
  651. // html += "<>"
  652. this.dlg("inofr", null, lp.copyConfirmTitle, {"html": html}, 500, 290, [
  653. {
  654. "text": lp.copyConfirm_overwrite,
  655. "action": function(){_self.saveItemAsUpdate(someItem, data, success, failure);this.close();}
  656. },
  657. {
  658. "text": lp.copyConfirm_new,
  659. "action": function(){_self.saveItemAsNew( data, success, failure, true, newCategory );this.close();}
  660. },
  661. {
  662. "text": lp.copyConfirm_skip,
  663. "action": function(){/*nothing*/ this.close(); if (success) success();}
  664. },
  665. {
  666. "text": lp.copyConfirm_cancel,
  667. "action": function(){this.close(); if (cancel) cancel();}
  668. }
  669. ]);
  670. }
  671. }
  672. }.bind(this), function(){
  673. //if (failure) failure();
  674. this.saveItemAsNew(data, success, failure, false, newCategory)
  675. }.bind(this));
  676. },
  677. saveItemAsUpdate: function(someItem, data, success, failure){
  678. var doc = data.document;
  679. doc.id = someItem.document.id;
  680. doc.isNewDocument = false;
  681. doc.appId = someItem.document.appId;
  682. doc.appName = someItem.document.appName;
  683. doc.categoryId = someItem.document.categoryId;
  684. doc.categoryName = someItem.document.categoryName;
  685. doc.categoryAlias = someItem.document.categoryAlias;
  686. doc.form = someItem.document.form;
  687. doc.formName = someItem.document.formName;
  688. doc.readFormId = someItem.document.readFormId;
  689. doc.readFormName = someItem.document.readFormName;
  690. doc.docData = data.data;
  691. this.restActions.saveDocument(doc, function(){
  692. if (success) success();
  693. }.bind(this), function(){
  694. if (failure) failure();
  695. }.bind(this));
  696. },
  697. saveItemAsNew: function(data, success, failure, clearId, newCategory){
  698. var columnData = this.options.columnData;
  699. var doc = data.document;
  700. if( clearId ){
  701. delete doc.id;
  702. }
  703. delete doc.documentType;
  704. delete doc.appId;
  705. delete doc.appName;
  706. delete doc.appAlias;
  707. delete doc.categoryId;
  708. delete doc.categoryName;
  709. delete doc.categoryAlias;
  710. delete doc.form;
  711. delete doc.formName;
  712. delete doc.readFormId;
  713. delete doc.readFormName;
  714. doc.appId = columnData.id;
  715. doc.docData = data.data;
  716. delete doc.docData.$document;
  717. var callback = function(data){
  718. this.restActions.publishDocumentComplex(data, function(){
  719. if (success) success();
  720. }.bind(this), function(){
  721. if (failure) failure();
  722. }.bind(this));
  723. }.bind(this);
  724. if( newCategory ){
  725. doc.categoryId = newCategory.id;
  726. callback( doc );
  727. }else{
  728. this.restActions.getCategory( data.document.categoryId, function( json ){
  729. if( json.data.appId === columnData.id ){
  730. doc.categoryId = data.document.categoryId;
  731. callback( doc );
  732. }else{
  733. this.loadSelectCategoryDialog( "选择"+ data.document.title + "的分类",function(id){
  734. doc.categoryId = id;
  735. callback( doc );
  736. }.bind(this))
  737. }
  738. }.bind(this), function(){
  739. this.loadSelectCategoryDialog( "选择"+ data.document.title + "的分类",function(id){
  740. doc.categoryId = id;
  741. callback( doc );
  742. }.bind(this))
  743. }.bind(this))
  744. }
  745. },
  746. loadSelectColumnDialog : function( callback){
  747. MWF.xDesktop.requireApp("Selector", "package", null, false);
  748. var options = {
  749. "type": "CMSCategory",
  750. "count": 1,
  751. "onComplete": function(items){
  752. items.each(function(item){
  753. if( callback )callback( item.data );
  754. }.bind(this));
  755. }.bind(this)
  756. };
  757. var selector = new MWF.O2Selector(this.content, options);
  758. },
  759. loadSelectCategoryDialog : function(title, callback){
  760. if( !this.categoryList ){
  761. this.categoryList = [];
  762. this.restActions.listCategory( this.options.columnData.id, function( json ){
  763. json.data.each( function(d){
  764. this.categoryList.push( {
  765. name : d.categoryName,
  766. id : d.id
  767. })
  768. }.bind(this))
  769. }.bind(this), null, false)
  770. }
  771. MWF.xDesktop.requireApp("Template", "Selector.Custom", null, false);
  772. var opt = {
  773. "count": 1,
  774. "title": "选择分类",
  775. "selectableItems" : this.categoryList,
  776. "values": [],
  777. "onComplete": function( array ){
  778. if( !array || array.length == 0 )return;
  779. var id = array[0].data.id;
  780. callback( id )
  781. }.bind(this)
  782. };
  783. var selector = new MWF.xApplication.Template.Selector.Custom(this.content, opt );
  784. selector.load();
  785. },
  786. loadImportActionNode : function(){
  787. this.importAction = new Element("div", {
  788. "styles": this.css.importAction,
  789. "text" : this.lp.import
  790. }).inject(this.titleActionBar);
  791. this.importAction.setStyle("display","none");
  792. this.importAction.addEvents({
  793. "click": function(e){
  794. MWF.xDesktop.requireApp("cms.Module", "ExcelForm", null, false);
  795. var categoryData = this.navi.currentObject.isCategory ? this.navi.currentObject.data : this.navi.currentObject.category.data ;
  796. this.import = new MWF.xApplication.cms.Module.ImportForm( { app : this }, categoryData, {} );
  797. this.import.edit();
  798. }.bind(this),
  799. "mouseover" : function(e){
  800. this.importAction.setStyles( this.css.importAction_over )
  801. }.bind(this),
  802. "mouseout" : function(e){
  803. this.importAction.setStyles( this.css.importAction )
  804. }.bind(this)
  805. });
  806. },
  807. loadExportActionNode : function(){
  808. this.exportAction = new Element("div", {
  809. "styles": this.css.exportAction,
  810. "text" : this.lp.export
  811. }).inject(this.titleActionBar);
  812. this.exportAction.setStyle("display","none");
  813. this.exportAction.addEvents({
  814. "click": function(e){
  815. MWF.xDesktop.requireApp("cms.Module", "ExcelForm", null, false);
  816. var categoryData = this.navi.currentObject.isCategory ? this.navi.currentObject.data : this.navi.currentObject.category.data ;
  817. this.export = new MWF.xApplication.cms.Module.ExportForm ( { app : this }, categoryData, {} );
  818. this.export.edit();
  819. }.bind(this),
  820. "mouseover" : function(e){
  821. this.exportAction.setStyles( this.css.exportAction_over )
  822. }.bind(this),
  823. "mouseout" : function(e){
  824. this.exportAction.setStyles( this.css.exportAction )
  825. }.bind(this)
  826. });
  827. },
  828. loadTitleIconNode : function(){
  829. this.defaultColumnIcon = "/x_component_cms_Index/$Main/"+this.options.style+"/icon/column.png";
  830. var iconAreaNode = this.iconAreaNode = new Element("div",{
  831. "styles" : this.css.titleIconAreaNode
  832. }).inject(this.leftTitleNode);
  833. var iconNode = this.iconNode = new Element("img",{
  834. "styles" : this.css.titleIconNode
  835. }).inject(iconAreaNode);
  836. if (this.options.columnData.appIcon){
  837. this.iconNode.set("src", "data:image/png;base64,"+this.options.columnData.appIcon+"");
  838. }else{
  839. this.iconNode.set("src", this.defaultColumnIcon)
  840. }
  841. iconNode.makeLnk({
  842. "par": this._getLnkPar()
  843. });
  844. },
  845. _getLnkPar: function(){
  846. var lnkIcon = this.defaultColumnIcon;
  847. if (this.options.columnData.appIcon) lnkIcon = "data:image/png;base64,"+this.options.columnData.appIcon;
  848. var appId = "cms.Module"+this.options.columnData.id;
  849. return {
  850. "icon": lnkIcon,
  851. "title": this.options.columnData.appName,
  852. "par": "cms.Module#{\"columnId\": \""+this.options.columnData.id+"\", \"appId\": \""+appId+"\"}"
  853. };
  854. },
  855. loadTitleContentNode: function(){
  856. this.titleContentNode = new Element("div.titleContentNode", {
  857. "styles": this.css.titleContentNode
  858. }).inject(this.leftTitleNode);
  859. this.titleTextNode = new Element("div.titleTextNode", {
  860. "styles": this.css.titleTextNode,
  861. "text": this.options.columnData.appName,
  862. "title": this.options.columnData.appName
  863. }).inject(this.titleContentNode);
  864. this.titleDescriptionNode = new Element("div.titleDescriptionNode", {
  865. "styles": this.css.titleDescriptionNode,
  866. "text": this.options.columnData.description ? this.options.columnData.description : this.lp.noDescription,
  867. "title": this.options.columnData.description ? this.options.columnData.description : this.lp.noDescription
  868. }).inject(this.titleContentNode);
  869. },
  870. loadSearchNode : function(){
  871. this.searchNode = new Element("div").inject( this.titleBar );
  872. },
  873. loadMenu: function(callback){
  874. this.naviNode = new Element("div.naviNode", {
  875. "styles": this.css.naviNode
  876. }).inject(this.naviContainerNode);
  877. //this.setScrollBar(this.naviNode,{"where": "before"});
  878. MWF.require("MWF.widget.ScrollBar", function(){
  879. new MWF.widget.ScrollBar(this.naviContainerNode, {
  880. "style":"xApp_ProcessManager_StartMenu", "distance": 100, "friction": 4, "axis": {"x": false, "y": true}
  881. });
  882. }.bind(this));
  883. this.addEvent("resize", function(){this.setNaviSize();}.bind(this));
  884. //MWF.require("MWF.widget.ScrollBar", function(){
  885. // new MWF.widget.ScrollBar(this.menuNode, {
  886. // "style":"xApp_CMSModule_StartMenu", "distance": 100, "friction": 4, "axis": {"x": false, "y": true}
  887. // });
  888. //}.bind(this));
  889. if( this.options.categoryId == "all" ){
  890. this.options.categoryId = "whole";
  891. }
  892. if( this.status && this.status.categoryId ){
  893. this._loadMenu( this.status );
  894. }else if( this.options.categoryId && this.options.categoryId != "" ){
  895. if( this.options.viewId && this.options.viewId!="" ){
  896. this._loadMenu( { "categoryId" :this.options.categoryId , "viewId" : this.options.viewId } )
  897. }else{
  898. //this.getCategoryDefaultList(this.options.categoryId , function(viewId){
  899. // if( viewId ){
  900. // this._loadMenu( { "categoryId" :this.options.categoryId , "viewId" : viewId, "isCategory" : this.options.isCategory } );
  901. // }else{
  902. // this._loadMenu( { "categoryId" :this.options.categoryId , "isCategory" : this.options.isCategory, "naviIndex" : (this.options.naviIndex || 0) } );
  903. // }
  904. //}.bind(this))
  905. this._loadMenu( { "categoryId" :this.options.categoryId , "isCategory" : true, "naviIndex" : (this.options.naviIndex || 0) } ); //this.options.isCategory
  906. }
  907. }else if( this.options.categoryAlias && this.options.categoryAlias != "" ){
  908. this.restActions.getCategoryByAlias( this.options.categoryAlias, function( json ){
  909. this.options.categoryId = json.data.id;
  910. if( this.options.viewId && this.options.viewId!="" ){
  911. this._loadMenu( { "categoryId" :this.options.categoryId , "viewId" : this.options.viewId } )
  912. }else{
  913. this._loadMenu( { "categoryId" :this.options.categoryId , "isCategory" : true, "naviIndex" : (this.options.naviIndex || 0) } ); //this.options.isCategory
  914. }
  915. }.bind(this))
  916. }else{
  917. this._loadMenu( { "categoryId" :"whole" } )
  918. }
  919. },
  920. _loadMenu : function( options ){
  921. this.navi = new MWF.xApplication.cms.Module.Navi(this, this.naviNode, this.options.columnData, options );
  922. this.setNaviSize();
  923. },
  924. clearContent: function(){
  925. //debugger;
  926. if (this.moduleContent){
  927. if (this.view) delete this.view;
  928. this.moduleContent.destroy();
  929. this.searchNode.empty();
  930. this.moduleContent = null;
  931. }
  932. },
  933. openView : function(el, categoryData, revealData, searchKey, navi){
  934. if( revealData && revealData.type == "queryview" ){
  935. this.loadQueryView(el, categoryData, revealData, searchKey, navi);
  936. }else{
  937. this.loadList(el, categoryData, revealData, searchKey, navi);
  938. }
  939. },
  940. loadQueryView : function(el, categoryData, revealData, searchKey, navi){
  941. MWF.xDesktop.requireApp("cms.Module", "ViewExplorer", function(){
  942. this.clearContent();
  943. this.moduleContent = new Element("div", {
  944. "styles": this.css.moduleContent
  945. }).inject(this.rightContentNode);
  946. this.view = new MWF.xApplication.cms.Module.ViewExplorer(
  947. this.moduleContent,
  948. this,
  949. this.options.columnData,
  950. categoryData,
  951. revealData,
  952. {"isAdmin": this.isAdmin, "searchKey" : searchKey },
  953. this.searchNode
  954. );
  955. this.view.selectEnable = this.selectEnable;
  956. this.view.load();
  957. }.bind(this))
  958. },
  959. loadList : function(el, categoryData, revealData, searchKey, navi){
  960. MWF.xDesktop.requireApp("cms.Module", "ListExplorer", function(){
  961. this.clearContent();
  962. this.moduleContent = new Element("div", {
  963. "styles": this.css.moduleContent
  964. }).inject(this.rightContentNode);
  965. if (!this.restActions) this.restActions = MWF.Actions.get("x_cms_assemble_control"); //new MWF.xApplication.cms.Module.Actions.RestActions();
  966. this.view = new MWF.xApplication.cms.Module.ListExplorer(
  967. this.moduleContent,
  968. this.restActions,
  969. this.options.columnData,
  970. categoryData,
  971. revealData,
  972. {"isAdmin": this.isAdmin, "searchKey" : searchKey },
  973. this.searchNode
  974. );
  975. this.view.app = this;
  976. this.view.selectEnable = this.selectEnable;
  977. this.view.load();
  978. }.bind(this));
  979. },
  980. recordStatus: function(){
  981. var currentObject = this.navi.currentObject;
  982. if( currentObject ){
  983. var categoryId = currentObject.getCategoryId();
  984. if (categoryId){
  985. return {
  986. "columnId" : this.options.columnData.id,
  987. "categoryId" :categoryId,
  988. "isCategory" : currentObject.isCategory,
  989. "viewId" : currentObject.data.id
  990. };
  991. }else{
  992. return { "columnId" : this.options.columnData.id , "categoryId" : "whole"}
  993. }
  994. }else{
  995. return { "columnId" : this.options.columnData.id , "categoryId" : "whole" }
  996. }
  997. },
  998. setNaviSize: function(){
  999. //var titlebarSize = this.titleBar ? this.titleBar.getSize() : {"x":0,"y":0};
  1000. var nodeSize = this.node.getSize();
  1001. //var pt = this.naviContainerNode.getStyle("padding-top").toFloat();
  1002. //var pb = this.naviContainerNode.getStyle("padding-bottom").toFloat();
  1003. //var height = nodeSize.y-pt-pb-titlebarSize.y;
  1004. this.naviContainerNode.setStyle("height", ""+nodeSize.y+"px");
  1005. }
  1006. });
  1007. MWF.xApplication.cms.Module.Navi = new Class({
  1008. Implements: [Options, Events],
  1009. options : {
  1010. "categoryId" :"" ,
  1011. "viewId" : "",
  1012. "isCategory" : false,
  1013. "navi" : -1
  1014. },
  1015. initialize: function(app, node, columnData, options){
  1016. this.setOptions(options);
  1017. this.app = app;
  1018. this.node = $(node);
  1019. this.columnData = columnData;
  1020. this.categoryList = [];
  1021. this.css = this.app.css;
  1022. this.load();
  1023. },
  1024. load: function(){
  1025. var self = this;
  1026. var showAll = (typeOf(this.columnData.showAllDocuments) === "boolean" ? this.columnData.showAllDocuments : true).toString();
  1027. if( showAll !== "false" ){
  1028. this.allView = new MWF.xApplication.cms.Module.NaviAllView( this, this.node, {} );
  1029. }
  1030. if( this.columnData.config.latest === false ){
  1031. this.draftView = new MWF.xApplication.cms.Module.NaviDraftView( this, this.node, {} );
  1032. }
  1033. new Element("div",{
  1034. "styles" : this.css.viewNaviBottom
  1035. }).inject(this.node);
  1036. this.app.restActions.listCategory( this.columnData.id, function( json ) {
  1037. json.data.each(function (d, idx) {
  1038. var isCurrent = false;
  1039. var category = new MWF.xApplication.cms.Module.NaviCategory(this, this.node,d, {} );
  1040. this.categoryList.push( category );
  1041. if( showAll == "false" && idx === 0 ){
  1042. category.setCurrent();
  1043. }
  1044. this.fireEvent("postLoad");
  1045. }.bind(this))
  1046. }.bind(this))
  1047. }
  1048. });
  1049. MWF.xApplication.cms.Module.NaviCategory = new Class({
  1050. Implements: [Options, Events],
  1051. options: {
  1052. "style": "default"
  1053. },
  1054. initialize: function ( navi, container, data, options) {
  1055. this.setOptions(options);
  1056. this.navi = navi;
  1057. this.app = navi.app;
  1058. this.container = $(container);
  1059. this.data = data;
  1060. this.css = this.app.css;
  1061. this.load();
  1062. },
  1063. load: function () {
  1064. var _self = this;
  1065. this.isCategory = true;
  1066. this.isCurrent = false;
  1067. this.isExpended = false;
  1068. this.hasSub = false;
  1069. this.naviViewList = [];
  1070. if( this.navi.options.categoryId == this.data.id && this.navi.options.isCategory ){
  1071. this.isCurrent = true;
  1072. }
  1073. this.reveal = this.getRevealData();
  1074. this.node = new Element("div.categoryNaviNode", {
  1075. "styles": this.css.categoryNaviNode
  1076. }).inject(this.container);
  1077. this.expendNode = new Element("div.expendNode").inject(this.node);
  1078. this.setExpendNodeStyle();
  1079. if( this.hasSub ){
  1080. this.expendNode.addEvent( "click" , function(ev){
  1081. this.triggerExpend();
  1082. ev.stopPropagation();
  1083. }.bind(this));
  1084. }
  1085. this.textNode = new Element("div.categoryNaviTextNode",{
  1086. "styles": this.css.categoryNaviTextNode,
  1087. "text": this.data.name //this.defaultRevealData.id == "defaultList" ? this.data.name : this.defaultRevealData.showName
  1088. }).inject(this.node);
  1089. this.node.addEvents({
  1090. "mouseover": function(){ if ( !_self.isCurrent )this.setStyles(_self.app.css.categoryNaviNode_over) },
  1091. "mouseout": function(){ if ( !_self.isCurrent )this.setStyles( _self.app.css.categoryNaviNode ) },
  1092. click : function(){ _self.setCurrent(this);}
  1093. });
  1094. this.listNode = new Element("div.viewNaviListNode",{
  1095. "styles" : this.css.viewNaviListNode
  1096. }).inject(this.container);
  1097. this.loadListContent();
  1098. if( this.isCurrent ){
  1099. this.setCurrent();
  1100. }
  1101. },
  1102. getRevealData: function(){
  1103. debugger;
  1104. var j = this.data.extContent;
  1105. if( j ){
  1106. this.extContent = JSON.parse( j );
  1107. }
  1108. if( !this.extContent || !this.extContent.reveal || this.extContent.reveal.length == 0 ){ //兼容以前的设置
  1109. this.extContent = { reveal : [] };
  1110. this.app.restActions.listViewByCategory( this.data.id, function(json){
  1111. ( json.data || [] ).each( function(d){
  1112. var itemData = {
  1113. "type" : "list",
  1114. "name" : d.name,
  1115. "showName" : d.name,
  1116. "id" : d.id,
  1117. "alias" : d.alias,
  1118. "appId" : d.appId,
  1119. "formId" : d.formId,
  1120. "formName" : d.formName
  1121. };
  1122. this.extContent.reveal.push( itemData );
  1123. }.bind(this));
  1124. }.bind(this), null, false );
  1125. }
  1126. this.extContent.reveal.each( function( r, i ){
  1127. if(this.data.defaultViewName && r.id == this.data.defaultViewName ){
  1128. this.defaultRevealData = r;
  1129. }else if( i>0 ){
  1130. this.isExpended = true;
  1131. this.hasSub = true;
  1132. }
  1133. }.bind(this));
  1134. if( !this.extContent || !this.extContent.reveal || this.extContent.reveal.length == 0 ){
  1135. this.extContent = { reveal : [{
  1136. id : "defaultList",
  1137. showName : "系统列表",
  1138. name : "系统列表"
  1139. }] };
  1140. }
  1141. this.revealData = this.extContent.reveal;
  1142. if( !this.defaultRevealData ){
  1143. this.defaultRevealData = {
  1144. id : "defaultList",
  1145. showName : "系统列表",
  1146. name : "系统列表"
  1147. }
  1148. }
  1149. },
  1150. setExpendNodeStyle : function(){
  1151. var style;
  1152. if( this.hasSub ){
  1153. if( this.isExpended ){
  1154. if( this.isCurrent ){
  1155. style = this.css.categoryExpendNode_selected;
  1156. }else{
  1157. style = this.css.categoryExpendNode;
  1158. }
  1159. }else{
  1160. if( this.isCurrent ){
  1161. style = this.css.categoryCollapseNode_selected;
  1162. }else{
  1163. style = this.css.categoryCollapseNode;
  1164. }
  1165. }
  1166. }else{
  1167. style = this.css.emptyExpendNode;
  1168. }
  1169. this.expendNode.setStyles( style );
  1170. },
  1171. triggerExpend : function(){
  1172. if( this.hasSub ){
  1173. if( this.isExpended ){
  1174. this.isExpended = false;
  1175. this.listNode.setStyle("display","none")
  1176. }else{
  1177. this.isExpended = true;
  1178. this.listNode.setStyle("display","")
  1179. }
  1180. this.setExpendNodeStyle();
  1181. }
  1182. },
  1183. setCurrent : function(){
  1184. if( this.navi.currentObject ){
  1185. this.navi.currentObject.cancelCurrent();
  1186. }
  1187. this.node.setStyles( this.css.categoryNaviNode_selected );
  1188. if( this.hasSub ){
  1189. if( this.isExpended ){
  1190. this.expendNode.setStyles( this.css.categoryExpendNode_selected );
  1191. }else{
  1192. this.expendNode.setStyles( this.css.categoryCollapseNode_selected );
  1193. }
  1194. }
  1195. this.isCurrent = true;
  1196. this.navi.currentObject = this;
  1197. var action = this.app.importAction;
  1198. if( action ){
  1199. action.setStyle("display", (this.data.importViewId && this.app.isAdmin) ? "" : "none");
  1200. }
  1201. action = this.app.exportAction;
  1202. if( action ){
  1203. action.setStyle("display", (this.data.importViewId && this.app.isAdmin) ? "" : "none");
  1204. }
  1205. this.loadView();
  1206. },
  1207. cancelCurrent : function(){
  1208. this.isCurrent = false;
  1209. this.node.setStyles( this.css.categoryNaviNode );
  1210. if( this.hasSub ){
  1211. if( this.isExpended ){
  1212. this.expendNode.setStyles( this.css.categoryExpendNode );
  1213. }else{
  1214. this.expendNode.setStyles( this.css.categoryCollapseNode );
  1215. }
  1216. }
  1217. },
  1218. loadView: function( searchkey ){
  1219. this.app.openView( this, this.data, this.viewData || this.defaultRevealData, searchkey || "", this );
  1220. },
  1221. loadListContent : function(){
  1222. this.revealData.each( function( d , i){
  1223. if( d.id != this.defaultRevealData.id ){
  1224. var naviView = new MWF.xApplication.cms.Module.NaviView(this.navi, this, this.listNode, d, {
  1225. "style": this.options.style,
  1226. "index" : i
  1227. });
  1228. this.naviViewList.push( naviView );
  1229. }
  1230. }.bind(this));
  1231. new Element("div", {
  1232. "styles": this.css.viewNaviSepartorNode
  1233. }).inject( this.listNode );
  1234. },
  1235. getCategoryId : function(){
  1236. return this.data.id;
  1237. }
  1238. });
  1239. MWF.xApplication.cms.Module.NaviView = new Class({
  1240. Implements: [Options, Events],
  1241. options: {
  1242. "style": "default",
  1243. "index" : 0
  1244. },
  1245. initialize: function ( navi, category, container, data, options) {
  1246. this.setOptions(options);
  1247. this.navi = navi;
  1248. this.category = category;
  1249. this.app = navi.app;
  1250. this.data = data;
  1251. this.container = $(container);
  1252. this.css = this.app.css;
  1253. this.load();
  1254. },
  1255. load: function(){
  1256. this.isDefault = this.data.id == "defaultList";
  1257. this.isCurrent = false;
  1258. this.isCategory = false;
  1259. if( this.navi.options.categoryId == this.category.data.id && !this.navi.options.isCategory ){
  1260. if( this.navi.options.viewId == "defaultList" && this.isDefault ){
  1261. this.isCurrent = true;
  1262. }else if( this.navi.options.viewId == this.data.id ){
  1263. this.isCurrent = true;
  1264. }else if( this.navi.options.naviIndex == this.options.index ){
  1265. this.isCurrent = true;
  1266. }
  1267. }
  1268. var _self = this;
  1269. this.node = new Element("div.viewNaviNode", {
  1270. "styles": this.css.viewNaviNode,
  1271. "text" : (this.isDefault && !this.data.showName) ? this.app.lp.defaultView : this.data.showName
  1272. }).inject(this.container);
  1273. this.node.addEvents({
  1274. "mouseover": function(){ if (!_self.isCurrent)this.setStyles(_self.css.viewNaviNode_over) },
  1275. "mouseout": function(){ if (!_self.isCurrent)this.setStyles( _self.css.viewNaviNode ) },
  1276. "click": function (el) {
  1277. _self.setCurrent();
  1278. }
  1279. });
  1280. if( this.isCurrent ){
  1281. this.setCurrent()
  1282. }
  1283. },
  1284. setCurrent : function(){
  1285. if( this.navi.currentObject ){
  1286. this.navi.currentObject.cancelCurrent();
  1287. }
  1288. this.node.setStyles( this.css.viewNaviNode_selected );
  1289. this.isCurrent = true;
  1290. this.navi.currentObject = this;
  1291. var action = this.app.importAction;
  1292. if( action ){
  1293. action.setStyle("display", (this.category.data.importViewId && this.app.isAdmin) ? "" : "none");
  1294. }
  1295. action = this.app.exportAction;
  1296. if( action ){
  1297. action.setStyle("display", (this.category.data.importViewId && this.app.isAdmin) ? "" : "none");
  1298. }
  1299. this.loadView();
  1300. },
  1301. cancelCurrent : function(){
  1302. this.isCurrent = false;
  1303. this.node.setStyles( this.css.viewNaviNode );
  1304. },
  1305. getCategoryId : function(){
  1306. return this.category.data.id;
  1307. },
  1308. loadView : function( searchKey ){
  1309. this.app.openView( this, this.category.data, this.data, searchKey || "", this );
  1310. }
  1311. });
  1312. MWF.xApplication.cms.Module.NaviAllView = new Class({
  1313. Implements: [Options, Events],
  1314. options: {
  1315. "style": "default"
  1316. },
  1317. initialize: function ( navi, container, options) {
  1318. this.setOptions(options);
  1319. this.navi = navi;
  1320. this.app = navi.app;
  1321. this.container = $(container);
  1322. this.css = this.app.css;
  1323. this.data = {
  1324. "isAll" : true,
  1325. "id" : "defaultList"
  1326. };
  1327. this.load();
  1328. },
  1329. load: function(){
  1330. var _self = this;
  1331. this.isDefault = true;
  1332. this.isAll = true;
  1333. this.isCurrent = false;
  1334. this.isCategory = false;
  1335. if( this.navi.options.categoryId == "whole" ){
  1336. this.isCurrent = true;
  1337. }
  1338. this.listNode = new Element("div.viewNaviListNode_all",{
  1339. "styles" : this.css.viewNaviListNode_all
  1340. }).inject(this.container);
  1341. this.node = new Element("div.viewNaviNode_all", {
  1342. "styles": this.css.viewNaviNode_all,
  1343. "text" : this.app.lp.allDocument
  1344. }).inject(this.listNode);
  1345. this.node.addEvents({
  1346. "mouseover": function(){ if ( !_self.isCurrent )this.setStyles(_self.css.viewNaviNode_all_over) },
  1347. "mouseout": function(){ if ( !_self.isCurrent )this.setStyles( _self.css.viewNaviNode_all ) },
  1348. "click": function (el) {
  1349. _self.setCurrent();
  1350. }
  1351. });
  1352. new Element("div", {
  1353. "styles": this.css.viewNaviSepartorNode
  1354. }).inject(this.listNode);
  1355. if( this.isCurrent ){
  1356. this.setCurrent()
  1357. }
  1358. },
  1359. setCurrent : function(){
  1360. if( this.navi.currentObject ){
  1361. this.navi.currentObject.cancelCurrent();
  1362. }
  1363. this.node.setStyles( this.css.viewNaviNode_all_selected );
  1364. this.isCurrent = true;
  1365. this.navi.currentObject = this;
  1366. var action = this.app.importAction;
  1367. if( action ){
  1368. action.setStyle("display","none");
  1369. }
  1370. var action = this.app.exportAction;
  1371. if( action ){
  1372. action.setStyle("display","none");
  1373. }
  1374. this.loadView();
  1375. },
  1376. cancelCurrent : function(){
  1377. this.isCurrent = false;
  1378. this.node.setStyles( this.css.viewNaviNode_all );
  1379. },
  1380. getCategoryId : function(){
  1381. return null;
  1382. },
  1383. loadView : function( searchKey ){
  1384. this.app.openView( this, null, this.data, searchKey || "", this );
  1385. }
  1386. });
  1387. MWF.xApplication.cms.Module.NaviDraftView = new Class({
  1388. Implements: [Options, Events],
  1389. options: {
  1390. "style": "default"
  1391. },
  1392. initialize: function ( navi, container, options) {
  1393. this.setOptions(options);
  1394. this.navi = navi;
  1395. this.app = navi.app;
  1396. this.container = $(container);
  1397. this.css = this.app.css;
  1398. this.data = {
  1399. "isDraft" : true,
  1400. "id" : "defaultList"
  1401. };
  1402. this.load();
  1403. },
  1404. load: function(){
  1405. var _self = this;
  1406. this.isDefault = true;
  1407. this.isAll = true;
  1408. this.isCurrent = false;
  1409. this.isCategory = false;
  1410. this.listNode = new Element("div.viewNaviListNode_all",{
  1411. "styles" : this.css.viewNaviListNode_all
  1412. }).inject(this.container);
  1413. this.node = new Element("div.viewNaviNode_all", {
  1414. "styles": this.css.viewNaviNode_all,
  1415. "text" : this.app.lp.draftStatus
  1416. }).inject(this.listNode);
  1417. this.node.addEvents({
  1418. "mouseover": function(){ if ( !_self.isCurrent )this.setStyles(_self.css.viewNaviNode_all_over) },
  1419. "mouseout": function(){ if ( !_self.isCurrent )this.setStyles( _self.css.viewNaviNode_all ) },
  1420. "click": function (el) {
  1421. _self.setCurrent();
  1422. }
  1423. });
  1424. new Element("div", {
  1425. "styles": this.css.viewNaviSepartorNode
  1426. }).inject(this.listNode);
  1427. if( this.isCurrent ){
  1428. this.setCurrent()
  1429. }
  1430. },
  1431. setCurrent : function(){
  1432. if( this.navi.currentObject ){
  1433. this.navi.currentObject.cancelCurrent();
  1434. }
  1435. this.node.setStyles( this.css.viewNaviNode_all_selected );
  1436. this.isCurrent = true;
  1437. this.navi.currentObject = this;
  1438. var action = this.app.importAction;
  1439. if( action ){
  1440. action.setStyle("display","none");
  1441. }
  1442. var action = this.app.exportAction;
  1443. if( action ){
  1444. action.setStyle("display","none");
  1445. }
  1446. this.loadView();
  1447. },
  1448. cancelCurrent : function(){
  1449. this.isCurrent = false;
  1450. this.node.setStyles( this.css.viewNaviNode_all );
  1451. },
  1452. getCategoryId : function(){
  1453. return null;
  1454. },
  1455. loadView : function( searchKey ){
  1456. this.app.openView( this, null, this.data, searchKey || "", this );
  1457. }
  1458. });