Main.js 50 KB

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