Main.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062
  1. MWF.xApplication.Forum = MWF.xApplication.Forum || {};
  2. MWF.xApplication.ForumSection = MWF.xApplication.ForumSection || {};
  3. MWF.require("MWF.widget.O2Identity", null,false);
  4. MWF.xDesktop.requireApp("Forum", "Common", null, false);
  5. //MWF.xDesktop.requireApp("Forum", "Actions.RestActions", null, false);
  6. MWF.xDesktop.requireApp("Forum", "lp."+MWF.language, null, false);
  7. MWF.xDesktop.requireApp("Template", "Explorer", null, false);
  8. MWF.xDesktop.requireApp("Forum", "Access", null, false);
  9. MWF.xDesktop.requireApp("Forum", "TopNode", null, false);
  10. MWF.xApplication.ForumSection.options = {
  11. multitask: true,
  12. executable: true
  13. };
  14. MWF.xApplication.ForumSection.Main = new Class({
  15. Extends: MWF.xApplication.Common.Main,
  16. Implements: [Options, Events],
  17. options: {
  18. "style": "default",
  19. "name": "ForumSection",
  20. "icon": "icon.png",
  21. "width": "1230",
  22. "height": "700",
  23. "isResize": true,
  24. "isMax": true,
  25. "title": MWF.xApplication.ForumSection.LP.title,
  26. "hasTop" : true,
  27. "naviMode" : false,
  28. "hasBreadCrumb" : true,
  29. "autoWidth" : false,
  30. "sectionId" : ""
  31. },
  32. onQueryLoad: function(){
  33. this.lp = MWF.xApplication.Forum.LP;
  34. },
  35. onQueryClose : function(){
  36. this.clearContent();
  37. },
  38. loadApplication: function(callback){
  39. this.userName = layout.desktop.session.user.distinguishedName;
  40. this.restActions = MWF.Actions.get("x_bbs_assemble_control"); //new MWF.xApplication.Forum.Actions.RestActions();
  41. this.path = "../x_component_ForumSection/$Main/"+this.options.style+"/";
  42. this.createNode();
  43. this.loadApplicationContent();
  44. },
  45. loadController: function(callback){
  46. this.access = new MWF.xApplication.Forum.Access( this.restActions, this.lp );
  47. if(callback)callback();
  48. },
  49. createNode: function(){
  50. this.content.setStyle("overflow", "hidden");
  51. this.node = new Element("div", {
  52. "styles": this.css.node
  53. }).inject(this.content);
  54. },
  55. clearContent: function(){
  56. this.node.empty();
  57. },
  58. loadApplicationContent: function(){
  59. if( !this.options.sectionId && this.status && this.status.sectionId ){
  60. this.options.sectionId = this.status.sectionId;
  61. }
  62. this.loadController(function(){
  63. this.access.login( function () {
  64. this.loadApplicationLayout();
  65. }.bind(this))
  66. }.bind(this))
  67. },
  68. reloadAllParents : function(){
  69. var aid = "Forum";
  70. if (this.desktop.apps[aid]){
  71. this.desktop.apps[aid].reload();
  72. }
  73. aid = "ForumCategory"+this.sectionData.forumId;
  74. if (this.desktop.apps[aid]){
  75. this.desktop.apps[aid].reload();
  76. }
  77. },
  78. reload : function(){
  79. this.status = {
  80. sectionId : this.options.sectionId,
  81. viewPageNum : this.explorer.view.getCurrentPageNum(),
  82. noteHidden : this.noteNodeHidden
  83. };
  84. this.clearContent();
  85. this.contentContainerNode = new Element("div.contentContainerNode", {
  86. "styles": this.options.autoWidth ? this.css.contentContainerNode_inContainer : this.css.contentContainerNode
  87. }).inject(this.node);
  88. this.createTopNode();
  89. this.createMiddleNode();
  90. },
  91. loadApplicationLayout : function(){
  92. this.contentContainerNode = new Element("div.contentContainerNode", {
  93. "styles": this.options.autoWidth ? this.css.contentContainerNode_inContainer : this.css.contentContainerNode
  94. }).inject(this.node);
  95. if( this.options.sectionId ){
  96. this.restActions.listSectionPermission( this.options.sectionId, function( permission ){
  97. this.sectionPermission = permission.data;
  98. this.isAdmin = this.sectionPermission.subjectManageAble;
  99. this.restActions.getSection( this.options.sectionId, function( json ){
  100. this.sectionData = json.data;
  101. //this.access.hasSectionAdminAuthority( this.sectionData, function( flag ){
  102. //this.isAdmin = flag;
  103. var tail = this.inBrowser ? (MWFForum.getSystemConfigValue( MWFForum.BBS_TITLE_TAIL ) || "") : "";
  104. this.setTitle( this.sectionData.sectionName + tail );
  105. this.createTopNode();
  106. this.createMiddleNode();
  107. //}.bind(this) );
  108. }.bind(this) )
  109. }.bind(this) )
  110. }else{
  111. this.close()
  112. }
  113. },
  114. loadTopObject : function(naviMode){
  115. if( this.options.hasTop ){
  116. var node = this.topObject = new MWF.xApplication.Forum.TopNode(this.contentContainerNode, this, this, {
  117. type: this.options.style,
  118. naviModeEnable : true,
  119. naviMode : naviMode
  120. });
  121. node.load();
  122. }
  123. },
  124. createTopNode: function(){
  125. this.loadTopObject( false );
  126. if( this.options.hasBreadCrumb ){
  127. var topNode = this.topNode = new Element("div.topNode", {
  128. "styles": this.options.autoWidth ? this.css.topNode_inContainer : this.css.topNode
  129. }).inject(this.contentContainerNode);
  130. //topNode.setStyle("border-bottom","1px solid "+forumColor);
  131. var topTitleMiddleNode = this.breadCrumbNode = new Element("div.topTitleMiddleNode", {
  132. "styles": this.css.topTitleMiddleNode
  133. }).inject(topNode);
  134. //topTitleMiddleNode.setStyle( "background-color" , forumColor )
  135. var topItemTitleNode = new Element("div.topItemTitleNode", {
  136. "styles": this.css.topItemTitleNode,
  137. "text": MWFForum.getBBSName() || MWF.xApplication.Forum.LP.title
  138. }).inject(topTitleMiddleNode);
  139. topItemTitleNode.addEvent("click", function(){
  140. if( this.options.naviMode && this.forumNavi ){
  141. this.forumNavi.goto( MWFForum.NaviType.main )
  142. }else{
  143. var appId = "Forum";
  144. if (this.desktop.apps[appId]){
  145. this.desktop.apps[appId].setCurrent();
  146. }else {
  147. this.desktop.openApplication(null, "Forum", { "appId": appId });
  148. }
  149. this.close();
  150. }
  151. }.bind(this));
  152. var topItemSepNode = new Element("div.topItemSepNode", {
  153. "styles": this.css.topItemSepNode,
  154. "text" : ">"
  155. }).inject(topTitleMiddleNode);
  156. var topItemTitleNode = new Element("div.topItemTitleNode", {
  157. "styles": this.css.topItemTitleNode,
  158. "text": this.sectionData.forumName
  159. }).inject(topTitleMiddleNode);
  160. topItemTitleNode.addEvent("click", function(){
  161. if( this.obj.options.naviMode && this.obj.forumNavi ){
  162. this.obj.forumNavi.goto( MWFForum.NaviType.category, this.forumId )
  163. }else{
  164. var appId = "ForumCategory"+this.forumId;
  165. if (this.obj.desktop.apps[appId]){
  166. this.obj.desktop.apps[appId].setCurrent();
  167. }else {
  168. this.obj.desktop.openApplication(null, "ForumCategory", { "categoryId" : this.forumId ,"appId": appId });
  169. }
  170. if( !this.obj.inBrowser ){
  171. this.obj.close();
  172. }
  173. }
  174. }.bind({ obj: this, forumId : this.sectionData.forumId }));
  175. topItemSepNode = new Element("div.topItemSepNode", {
  176. "styles": this.css.topItemSepNode,
  177. "text" : ">"
  178. }).inject(topTitleMiddleNode);
  179. topItemTitleNode = new Element("div.topItemTitleNode", {
  180. "styles": this.css.topItemTitleLastNode,
  181. "text": this.sectionData.sectionName
  182. }).inject(topTitleMiddleNode);
  183. }
  184. if( this.sectionData.sectionNotice ){
  185. var topRightNode = new Element("div", {
  186. "styles": this.css.topRightNode
  187. }).inject(topNode);
  188. topRightNode.addEvents({
  189. "click" :function(){
  190. if( !this.noteNodeHidden ){
  191. this.noteNode.setStyle("display","none");
  192. this.topRightIconNode.setStyles(this.css.topRightIconDownNode);
  193. this.noteNodeHidden = true;
  194. }else{
  195. this.noteNode.setStyle("display","");
  196. this.topRightIconNode.setStyles(this.css.topRightIconNode);
  197. this.noteNodeHidden = false;
  198. }
  199. }.bind(this)
  200. });
  201. var topRightIconNode = this.topRightIconNode = new Element("div", {
  202. "styles": this.css.topRightIconNode
  203. }).inject(topRightNode);
  204. if( this.status && this.status.noteHidden ){
  205. this.topRightIconNode.setStyles(this.css.topRightIconDownNode);
  206. this.noteNodeHidden = true;
  207. }
  208. }
  209. },
  210. createMiddleNode: function(){
  211. this.middleNode = new Element("div.middleNode", {
  212. "styles": this.options.autoWidth ? this.css.middleNode_inContainer : this.css.middleNode
  213. }).inject(this.contentContainerNode);
  214. this.createSectionNode();
  215. this.createNoteNode();
  216. this._createMiddleNode();
  217. if( !this.options.naviMode ){
  218. this.addEvent("resize", function () {
  219. this.setContentSize();
  220. }.bind(this));
  221. this.setContentSize();
  222. }
  223. //MWF.require("MWF.widget.ScrollBar", function () {
  224. // new MWF.widget.ScrollBar(this.contentContainerNode, {
  225. // "indent": false,
  226. // "style": "xApp_TaskList",
  227. // "where": "before",
  228. // "distance": 30,
  229. // "friction": 4,
  230. // "axis": {"x": false, "y": true},
  231. // "onScroll": function (y) {
  232. // }
  233. // });
  234. //}.bind(this));
  235. },
  236. openNavi: function () {
  237. MWF.xDesktop.requireApp("Forum", "NaviMode", null, false);
  238. this.clearContent();
  239. this.contentContainerNode = new Element("div.contentContainerNode", {
  240. "styles": this.css.contentContainerNode
  241. }).inject(this.node);
  242. this.loadTopObject( true );
  243. this.middleNode = new Element("div.middleNode", {
  244. "styles": this.css.middleNode
  245. }).inject(this.contentContainerNode);
  246. this.contentNode = new Element("div.contentNode", {
  247. "styles": this.css.contentNode
  248. }).inject(this.middleNode);
  249. this.navi = new MWF.xApplication.Forum.NaviMode(this, this.contentNode, {
  250. type : MWFForum.NaviType.section,
  251. id : this.sectionData.id
  252. });
  253. this.navi.load();
  254. },
  255. closeNavi : function(){
  256. if( this.navi )this.navi.close();
  257. },
  258. colorRgba : function( color, opacity ){ /*16进制颜色转为RGB格式*/
  259. var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
  260. var sColor = color.toLowerCase();
  261. if(sColor && reg.test(sColor)){
  262. if(sColor.length === 4){
  263. var sColorNew = "#";
  264. for(var i=1; i<4; i+=1){
  265. sColorNew += sColor.slice(i,i+1).concat(sColor.slice(i,i+1));
  266. }
  267. sColor = sColorNew;
  268. }
  269. //处理六位的颜色值
  270. var sColorChange = [];
  271. for(var i=1; i<7; i+=2){
  272. sColorChange.push(parseInt("0x"+sColor.slice(i,i+2)));
  273. }
  274. return "rgba(" + sColorChange.join(",") + "," + opacity + ")";
  275. }else{
  276. return sColor;
  277. }
  278. },
  279. createSectionNode: function(){
  280. var forumColor = MWF.xApplication.Forum.ForumSetting[this.sectionData.forumId].forumColor;
  281. var sectionNode = new Element("div.sectionNode", {
  282. "styles": this.options.autoWidth ? this.css.sectionNode_inContainer : this.css.sectionNode
  283. }).inject(this.middleNode);
  284. sectionNode.setStyle("background-color", this.colorRgba( forumColor, "0.05" ));
  285. var sectionLeftNode = new Element("div.sectionLeftNode", {
  286. "styles": this.css.sectionLeftNode
  287. }).inject(sectionNode);
  288. var sectionLeftIconNode = new Element("div.sectionLeftIconNode", {
  289. "styles": this.css.sectionLeftIconNode
  290. }).inject(sectionLeftNode);
  291. var sectionLeftIcon = new Element("img", {
  292. "styles": this.css.sectionLeftIcon,
  293. "src" : this.sectionData.icon ? ('data:image/png;base64,'+ this.sectionData.icon) : "../x_component_Forum/$Setting/default/sectionIcon/forum_icon.png"
  294. }).inject(sectionLeftIconNode);
  295. var sectionLeftContent = new Element("div.sectionLeftContent", {
  296. "styles": this.css.sectionLeftContent
  297. }).inject(sectionLeftNode);
  298. var sectionTopDiv = new Element("div.sectionTopDiv", {
  299. "styles": this.css.sectionTopDiv
  300. }).inject(sectionLeftContent);
  301. var sectionTopInfor= new Element("div.sectionTopInfor", {
  302. "styles": this.css.sectionTopInfor,
  303. "text" : this.lp.subject + ":" + this.sectionData.subjectTotal + "," + this.lp.replyCount + ":" + this.sectionData.replyTotal
  304. }).inject(sectionTopDiv);
  305. var sectionLeftDiv = new Element("div.sectionLeftDiv", {
  306. "styles": this.css.sectionLeftDiv
  307. }).inject(sectionLeftContent);
  308. var sectionLeftMemo = new Element("div.sectionLeftMemo", {
  309. "styles": this.css.sectionLeftMemo,
  310. "text" : this.sectionData.sectionDescription
  311. }).inject(sectionLeftDiv);
  312. sectionTopDiv = new Element("div.sectionTopDiv", {
  313. "styles": this.css.sectionTopDiv
  314. }).inject(sectionLeftContent);
  315. sectionTopInfor= new Element("div.sectionTopInfor", {
  316. "styles": this.css.sectionTopInfor,
  317. "text" : this.lp.moderatorNames + ":"
  318. }).inject(sectionTopDiv);
  319. sectionTopInfor= new Element("div.sectionTopInfor", {
  320. "styles": this.css.sectionTopInfor
  321. }).inject(sectionTopDiv);
  322. this.createPersonNode( sectionTopInfor, this.sectionData.moderatorNames );
  323. },
  324. createNoteNode : function(){
  325. if( !this.sectionData.sectionNotice || this.sectionData.sectionNotice.trim() =="" ){
  326. return;
  327. }
  328. var noteNode = this.noteNode = new Element("div.noteNode", {
  329. "styles": this.css.noteNode
  330. }).inject(this.middleNode);
  331. var noteTopNode = new Element("div.noteTopNode", {
  332. "styles": this.css.noteTopNode
  333. }).inject(noteNode);
  334. var noteTopContent = new Element("div.noteTopContent", {
  335. "styles": this.css.noteTopContent
  336. }).inject(noteTopNode);
  337. var noteIcon = new Element("div.noteIcon", {
  338. "styles": this.css.noteIcon
  339. }).inject(noteTopContent);
  340. var noteTopText = new Element("div.noteTopText", {
  341. "styles": this.css.noteTopText,
  342. "text" : this.lp.sectionNotice
  343. }).inject(noteTopContent);
  344. var noteContent = new Element("div.noteContent", {
  345. "styles": this.css.noteContent,
  346. "html" : this.sectionData.sectionNotice
  347. }).inject(noteNode);
  348. if( this.status && this.status.noteHidden ){
  349. noteNode.setStyle("display" , "none");
  350. }
  351. },
  352. _createMiddleNode : function(){
  353. this.contentDiv = new Element("div.contentDiv",{"styles":this.css.contentDiv}).inject(this.middleNode);
  354. if( this.contentDiv )this.contentDiv.empty();
  355. if( this.explorer ){
  356. this.explorer.destroy();
  357. delete this.explorer;
  358. }
  359. this.explorer = new MWF.xApplication.ForumSection.Explorer(this.contentDiv, this, this,{
  360. style:this.options.style,
  361. viewPageNum : ( this.status && this.status.viewPageNum ) ? this.status.viewPageNum : 1
  362. });
  363. this.explorer.load();
  364. },
  365. setContentSize: function () {
  366. //var topSize = this.topNode ? this.topNode.getSize() : {"x": 0, "y": 0};
  367. var topSize = {"x": 0, "y": 0};
  368. var nodeSize = this.content.getSize();
  369. var pt = this.contentContainerNode.getStyle("padding-top").toFloat();
  370. var pb = this.contentContainerNode.getStyle("padding-bottom").toFloat();
  371. var height = nodeSize.y - topSize.y - pt - pb;
  372. this.contentContainerNode.setStyle("height", "" + height + "px");
  373. },
  374. // openLoginForm : function(){
  375. // //MWF.xDesktop.requireApp("Forum", "Login", null, false);
  376. // //var login = new MWF.xApplication.Forum.Login(this, {
  377. // // onPostOk : function(){
  378. // // window.location.reload();
  379. // // }
  380. // //});
  381. // //login.openLoginForm();
  382. // MWF.require("MWF.xDesktop.Authentication", null, false);
  383. // var authentication = new MWF.xDesktop.Authentication({
  384. // style : "application",
  385. // onPostOk : function(){
  386. // window.location.reload();
  387. // }
  388. // },this);
  389. // authentication.openLoginForm({
  390. // hasMask : true
  391. // });
  392. // },
  393. // openSignUpForm : function(){
  394. // //MWF.xDesktop.requireApp("Forum", "Login", null, false);
  395. // //var login = new MWF.xApplication.Forum.Login(this, {});
  396. // //login.openSignUpForm();
  397. // MWF.require("MWF.xDesktop.Authentication", null, false);
  398. // var authentication = new MWF.xDesktop.Authentication( {
  399. // style : "application",
  400. // onPostOk : function(){
  401. // }
  402. // }, this);
  403. // authentication.openSignUpForm({
  404. // hasMask : true
  405. // });
  406. // },
  407. openLoginForm : function(){
  408. MWF.require("MWF.xDesktop.Authentication", null, false);
  409. var authentication = new MWF.xDesktop.Authentication({
  410. "style" : "flat",
  411. "popupStyle_password": "o2platformSignupFlat",
  412. onPostOk : function(){
  413. window.location.reload();
  414. }
  415. },this);
  416. authentication.popupOptions = {
  417. "draggable": true,
  418. "closeAction": true,
  419. "hasMask": true,
  420. "relativeToApp": true,
  421. "width": "420",
  422. "height": "640"
  423. };
  424. // authentication.loadLogin(this.app.content);
  425. authentication.openLoginForm();
  426. },
  427. openSignUpForm : function(){
  428. MWF.require("MWF.xDesktop.Authentication", null, false);
  429. var authentication = new MWF.xDesktop.Authentication( {
  430. style : "flat",
  431. "popupStyle_password": "o2platformSignupFlat",
  432. onPostOk : function(){
  433. }
  434. }, this);
  435. authentication.popupOptions = {
  436. "draggable": true,
  437. "closeAction": true,
  438. "hasMask": true,
  439. "relativeToApp": true,
  440. "width": "420",
  441. "height": "640"
  442. };
  443. authentication.openSignUpForm();
  444. },
  445. recordStatus: function(){
  446. return {
  447. sectionId : this.options.sectionId,
  448. viewPageNum : this.explorer.view.getCurrentPageNum(),
  449. noteHidden : this.noteNodeHidden
  450. };
  451. },
  452. openPerson : function( userName ){
  453. if( !userName || userName == "" ){
  454. }else{
  455. var appId = "ForumPerson"+userName;
  456. if (this.desktop.apps[userName]){
  457. this.desktop.apps[userName].setCurrent();
  458. }else {
  459. this.desktop.openApplication(null, "ForumPerson", {
  460. "personName" : userName,
  461. "appId": appId
  462. });
  463. }
  464. }
  465. },
  466. createPersonNode : function( container, personName ){
  467. var persons = typeOf( personName ) === "string" ? personName.split(",") : personName;
  468. persons.each( function(userName, i){
  469. if( !userName )return;
  470. var span = new Element("span", {
  471. "text" : userName.split("@")[0],
  472. "styles" : this.css.person
  473. }).inject(container);
  474. span.addEvents( {
  475. mouseover : function(){ this.node.setStyles( this.obj.css.person_over )}.bind( {node:span, obj:this} ),
  476. mouseout : function(){ this.node.setStyles( this.obj.css.person )}.bind( {node:span, obj:this} ),
  477. click : function(){ this.obj.openPerson( this.userName ) }.bind( {userName:userName, obj:this} )
  478. });
  479. if( i != persons.length - 1 ){
  480. new Element("span", {
  481. "text" : "、"
  482. }).inject(container);
  483. }
  484. }.bind(this))
  485. },
  486. destroy : function(){
  487. this.clearContent();
  488. },
  489. clearContent: function () {
  490. if (this.explorer)this.explorer.destroy();
  491. if(this.setContentSizeFun)this.removeEvent("resize", this.setContentSizeFun );
  492. if(this.scrollBar && this.scrollBar.scrollVAreaNode)this.scrollBar.scrollVAreaNode.destroy();
  493. if( this.scrollBar )delete this.scrollBar;
  494. if (this.contentContainerNode) {
  495. this.contentContainerNode.destroy();
  496. //this.middleNode.destroy();
  497. //this.contentNode.destroy();
  498. }
  499. }
  500. });
  501. MWF.xApplication.ForumSection.Explorer = new Class({
  502. Extends: MWF.widget.Common,
  503. Implements: [Options, Events],
  504. options: {
  505. "style": "default",
  506. "viewPageNum" : 1
  507. },
  508. initialize: function (container, app, parent, options) {
  509. this.setOptions( options );
  510. this.container = container;
  511. this.parent = parent;
  512. this.app = app;
  513. this.css = this.parent.css;
  514. this.lp = this.app.lp;
  515. },
  516. load: function () {
  517. this.container.empty();
  518. this.loadToolbar();
  519. this.viewContainerTop = Element("div",{
  520. "styles" : this.css.viewContainerTop
  521. }).inject(this.container);
  522. this.viewContainer = Element("div",{
  523. "styles" : this.css.viewContainer
  524. }).inject(this.container);
  525. this.viewContainerPrime = Element("div",{
  526. "styles" : this.css.viewContainer
  527. }).inject(this.container);
  528. this.loadToolbar();
  529. //this.loadTopView();
  530. this.loadView();
  531. },
  532. destroy : function(){
  533. if(this.resizeWindowFun)this.app.removeEvent("resize",this.resizeWindowFun);
  534. this.view.destroy();
  535. if( this.view.refreshInterval ){
  536. clearInterval( this.view.refreshInterval );
  537. }
  538. },
  539. loadToolbar: function(){
  540. var toolbar = new Element("div",{
  541. styles : this.css.toolbar
  542. }).inject(this.container);
  543. if( this.toolbarTop ){
  544. this.toolbarBottom = toolbar;
  545. }else{
  546. this.toolbarTop = toolbar;
  547. }
  548. //if( this.parent.access.isSubjectPublisher( this.parent.sectionData ) ){
  549. if( this.app.sectionPermission.subjectPublishAble ){
  550. var createActionNode = new Element("div",{
  551. styles : this.css.toolbarActionNode,
  552. text: this.lp.createSubject
  553. }).inject(toolbar);
  554. createActionNode.addEvents(
  555. {
  556. "mouseover": function () {
  557. this.node.setStyles(this.obj.css.toolbarActionNode_over);
  558. }.bind({obj: this, node: createActionNode}),
  559. "mouseout": function () {
  560. this.node.setStyles(this.obj.css.toolbarActionNode);
  561. }.bind({obj: this, node: createActionNode}),
  562. "click": function () {
  563. if( this.app.access.isAnonymousDynamic() ){
  564. this.app.openLoginForm(
  565. function(){ this.createSubject(); }.bind(this)
  566. );
  567. }else{
  568. this.createSubject();
  569. }
  570. }.bind(this)
  571. }
  572. )
  573. }
  574. var fileterNode = new Element("div",{
  575. styles : this.css.fileterNode
  576. }).inject(toolbar);
  577. var pagingBar = new Element("div",{
  578. styles : this.css.fileterNode
  579. }).inject(toolbar);
  580. if( this.pagingBarTop ){
  581. this.pagingBarBottom = pagingBar;
  582. }else{
  583. this.pagingBarTop = pagingBar;
  584. }
  585. },
  586. loadView : function(){
  587. //this.resizeWindow();
  588. //this.resizeWindowFun = this.resizeWindow.bind(this)
  589. //this.app.addEvent("resize", this.resizeWindowFun );
  590. this.view = new MWF.xApplication.ForumSection.View( this.viewContainer, this.app, this, {
  591. templateUrl : this.parent.path+"listItem.json",
  592. pagingEnable : true,
  593. onPostCreateViewBody : function(){
  594. this.app.fireEvent("postCreateViewBody");
  595. }.bind(this),
  596. pagingPar : {
  597. hasReturn : !this.app.naviMode,
  598. currentPage : this.options.viewPageNum,
  599. countPerPage : 30,
  600. onPostLoad : function( pagingBar ){
  601. if(pagingBar.nextPageNode){
  602. pagingBar.nextPageNode.inject( this.toolbarBottom, "before" );
  603. }
  604. }.bind(this),
  605. onPageReturn : function( pagingBar ){
  606. var appId = "Forum";
  607. if (this.app.desktop.apps[appId]){
  608. this.app.desktop.apps[appId].setCurrent();
  609. }else {
  610. this.app.desktop.openApplication(null, "Forum", { "appId": appId });
  611. }
  612. this.app.close();
  613. }.bind(this)
  614. }
  615. } );
  616. this.view.filterData = { sectionId : this.app.sectionData.id , withTopSubject : true };
  617. this.view.pagingContainerTop = this.pagingBarTop;
  618. this.view.pagingContainerBottom = this.pagingBarBottom;
  619. this.view.load();
  620. },
  621. reloadView : function() {
  622. if( this.viewPrime )this.viewPrime.destroy();
  623. this.viewContainer.setStyle("display","");
  624. this.viewContainerTop.setStyle("display","");
  625. this.viewContainerPrime.setStyle("display","none");
  626. //this.loadTopView();
  627. this.loadView();
  628. },
  629. loadPrimeView : function(){
  630. if( this.view )this.view.destroy();
  631. if( this.viewTop )this.viewTop.destroy();
  632. this.viewContainer.setStyle("display","none");
  633. this.viewContainerTop.setStyle("display","none");
  634. this.viewContainerPrime.setStyle("display","");
  635. this.viewPrime = new MWF.xApplication.ForumSection.PrimeView( this.viewContainerPrime, this.app, this, {
  636. templateUrl : this.parent.path+"listItemPrime.json",
  637. pagingEnable : true,
  638. pagingPar : {
  639. hasReturn : !this.app.naviMode,
  640. currentPage : 1,
  641. countPerPage : 30,
  642. onPostLoad : function( pagingBar ){
  643. if(pagingBar.nextPageNode){
  644. pagingBar.nextPageNode.inject( this.toolbarBottom, "before" );
  645. }
  646. }.bind(this),
  647. onPageReturn : function( pagingBar ){
  648. var appId = "Forum";
  649. if (this.app.desktop.apps[appId]){
  650. this.app.desktop.apps[appId].setCurrent();
  651. }else {
  652. this.app.desktop.openApplication(null, "Forum", { "appId": appId });
  653. }
  654. this.app.close();
  655. }.bind(this)
  656. }
  657. } );
  658. this.viewPrime.filterData = { sectionId : this.app.sectionData.id };
  659. this.viewPrime.pagingContainerTop = this.pagingBarTop;
  660. this.viewPrime.pagingContainerBottom = this.pagingBarBottom;
  661. this.viewPrime.load();
  662. },
  663. resizeWindow: function(){
  664. var size = this.app.content.getSize();
  665. this.viewContainer.setStyles({"height":(size.y-121)+"px"});
  666. },
  667. createSubject: function(){
  668. var _self = this;
  669. var appId = "ForumDocument"+this.app.sectionData.id;
  670. if (_self.app.desktop.apps[appId]){
  671. _self.app.desktop.apps[appId].setCurrent();
  672. }else {
  673. this.app.desktop.openApplication(null, "ForumDocument", {
  674. "sectionId": this.app.sectionData.id,
  675. "appId": appId,
  676. "isNew" : true,
  677. "isEdited" : true,
  678. "onPostPublish" : function(){
  679. //this.view.reload();
  680. }.bind(this)
  681. });
  682. }
  683. }
  684. });
  685. MWF.xApplication.ForumSection.TopView = new Class({
  686. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  687. _createDocument: function(data, index){
  688. return new MWF.xApplication.ForumSection.TopDocument(this.viewNode, data, this.explorer, this, null, index);
  689. },
  690. _getCurrentPageData: function(callback, count){
  691. if (!count)count = 30;
  692. //var id = (this.items.length) ? this.items[this.items.length - 1].data.id : "(0)";
  693. var filter = this.filterData || {};
  694. //page, count, filterData, success,failure, async
  695. if( !this.page ){
  696. this.page = 1;
  697. }else{
  698. this.page ++;
  699. }
  700. this.actions.listTopSubject( this.app.sectionData.id, function (json) {
  701. if( !json.data )json.data = [];
  702. if (callback)callback(json);
  703. }.bind(this))
  704. },
  705. _removeDocument: function(documentData, all){
  706. this.actions.deleteSubject(documentData.id, function(json){
  707. this.reload();
  708. this.app.reloadAllParents();
  709. this.app.notice(this.app.lp.deleteDocumentOK, "success");
  710. }.bind(this));
  711. },
  712. _create: function(){
  713. },
  714. _openDocument: function( documentData,index ){
  715. var appId = "ForumDocument"+documentData.id;
  716. if (this.app.desktop.apps[appId]){
  717. this.app.desktop.apps[appId].setCurrent();
  718. }else {
  719. this.app.desktop.openApplication(null, "ForumDocument", {
  720. "sectionId" : documentData.sectionId,
  721. "id" : documentData.id,
  722. "appId": appId,
  723. "isEdited" : false,
  724. "isNew" : false,
  725. "index" : index
  726. });
  727. }
  728. },
  729. _queryCreateViewNode: function(){
  730. },
  731. _postCreateViewNode: function( viewNode ){
  732. },
  733. _queryCreateViewHead:function(){
  734. },
  735. _postCreateViewHead: function( headNode ){
  736. //this.allSubjectNode = headNode.getElements("[lable='allSubject']")[0];
  737. var primeNode = headNode.getElements("[lable='prime']")[0];
  738. primeNode.addEvent( "click", function(){
  739. this.explorer.loadPrimeView();
  740. }.bind(this))
  741. }
  742. });
  743. MWF.xApplication.ForumSection.TopDocument = new Class({
  744. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  745. _queryCreateDocumentNode:function( itemData ){
  746. },
  747. _postCreateDocumentNode: function( itemNode, itemData ){
  748. },
  749. open: function (e) {
  750. this.view._openDocument(this.data, this.index);
  751. },
  752. edit : function(){
  753. var appId = "ForumDocument"+this.data.id;
  754. if (this.app.desktop.apps[appId]){
  755. this.app.desktop.apps[appId].setCurrent();
  756. }else {
  757. this.app.desktop.openApplication(null, "ForumDocument", {
  758. "sectionId" : this.data.sectionId,
  759. "id" : this.data.id,
  760. "appId": appId,
  761. "isEdited" : true,
  762. "isNew" : false,
  763. "index" : this.index
  764. });
  765. }
  766. }
  767. });
  768. MWF.xApplication.ForumSection.View = new Class({
  769. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  770. refreshNewSubject : function(){
  771. if (this.refreshTr)this.refreshTr.destroy();
  772. if( this.refreshInterval ){
  773. clearInterval( this.refreshInterval );
  774. }
  775. this.refreshInterval = setInterval( function(){
  776. this.actions.listSubjectFilterPage( 1, 1, this.filterData || {}, function(json){
  777. if( !json.count )json.count=0;
  778. var count = this.laterRefreshCount || this.dataCount;
  779. if( json.count > count ) {
  780. this.laterRefreshCount = json.count;
  781. this.createRefreshTr( json.count );
  782. }
  783. }.bind(this))
  784. }.bind(this), 10 * 60 * 1000 )
  785. },
  786. createRefreshTr : function( newCount ){
  787. if (this.refreshTr)this.refreshTr.destroy();
  788. var refreshTr = this.refreshTr = new Element( "tr.refreshTrNode" , {
  789. styles : this.css.refreshTrNode
  790. }).inject( this.headNode, "after" );
  791. var td = this.refreshTd = new Element( "td.refreshTdNode", {
  792. width : "60%",
  793. styles : this.css.refreshTdNode
  794. }).inject( refreshTr );
  795. var refreshNode = new Element("div" , {
  796. styles : this.css.refreshNode,
  797. text : this.lp.newSubjectPublishedText.replace( "{count}", newCount - this.dataCount )
  798. }).inject(td);
  799. refreshNode.addEvent("click", function(){
  800. this.gotoPage(1)
  801. }.bind(this));
  802. var td = new Element( "td.refreshTdNode", {
  803. styles : this.css.refreshTdNode,
  804. width : "12%"
  805. }).inject( refreshTr );
  806. var td = new Element( "td.refreshTdNode", {
  807. styles : this.css.refreshTdNode,
  808. width : "7%"
  809. }).inject( refreshTr );
  810. var td = new Element( "td.refreshTdNode", {
  811. styles : this.css.refreshTdNode,
  812. width : "7%"
  813. }).inject( refreshTr );
  814. var td = new Element( "td.refreshTdNode", {
  815. styles : this.css.refreshTdNode,
  816. width : "14%"
  817. }).inject( refreshTr )
  818. },
  819. _createDocument: function(data, index){
  820. return new MWF.xApplication.ForumSection.Document(this.viewNode, data, this.explorer, this, null, index);
  821. },
  822. _getCurrentPageData: function(callback, count, pageNum){
  823. this.clearBody();
  824. if(!count)count=30;
  825. if(!pageNum)pageNum = 1;
  826. //if( pageNum == 1 ){
  827. // this.explorer.viewContainerTop.setStyle("display","block");
  828. // this.headNode.setStyle("display","none");
  829. //}else{
  830. // this.explorer.viewContainerTop.setStyle("display","none");
  831. // this.headNode.setStyle("display","");
  832. //}
  833. if( this.topSepTr )this.topSepTr.destroy();
  834. var filter = this.filterData || {};
  835. //filter.withTopSubject = false;
  836. this.actions.listSubjectFilterPage( pageNum, count, filter, function(json){
  837. if( !json.data )json.data = [];
  838. if( !json.count )json.count=0;
  839. this.refreshNewSubject();
  840. if( callback )callback(json);
  841. }.bind(this))
  842. },
  843. _removeDocument: function(documentData, all){
  844. this.actions.deleteSubject(documentData.id, function(json){
  845. this.reload();
  846. this.app.reloadAllParents();
  847. this.app.notice(this.app.lp.deleteDocumentOK, "success");
  848. }.bind(this));
  849. },
  850. _create: function(){
  851. },
  852. _openDocument: function( documentData,index ){
  853. var appId = "ForumDocument"+documentData.id;
  854. if (this.app.desktop.apps[appId]){
  855. this.app.desktop.apps[appId].setCurrent();
  856. }else {
  857. this.app.desktop.openApplication(null, "ForumDocument", {
  858. "sectionId" : documentData.sectionId,
  859. "id" : documentData.id,
  860. "appId": appId,
  861. "isEdited" : false,
  862. "isNew" : false,
  863. "index" : index
  864. });
  865. }
  866. },
  867. _queryCreateViewNode: function(){
  868. },
  869. _postCreateViewNode: function( viewNode ){
  870. },
  871. _queryCreateViewHead:function(){
  872. },
  873. _postCreateViewHead: function( headNode ){
  874. var primeNode = headNode.getElements("[lable='prime']")[0];
  875. primeNode.addEvent( "click", function(){
  876. this.explorer.loadPrimeView();
  877. }.bind(this))
  878. }
  879. });
  880. MWF.xApplication.ForumSection.Document = new Class({
  881. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  882. _queryCreateDocumentNode:function( itemData ){
  883. },
  884. _postCreateDocumentNode: function( itemNode, itemData ){
  885. //置顶帖和一般帖之间添加分割线
  886. if( this.index != 1 && !itemData.isTopSubject ){
  887. var prev = this.view.items[this.index-1];
  888. if( prev && prev.data.isTopSubject ){
  889. var tr = this.view.topSepTr = new Element( "tr" , {styles: this.css.documentNode_empty } ).inject( itemNode, "before" );
  890. new Element( "td", {colspan:5}).inject( tr )
  891. }
  892. }
  893. },
  894. open: function (e) {
  895. this.view._openDocument(this.data, this.index);
  896. },
  897. edit : function(){
  898. var appId = "ForumDocument"+this.data.id;
  899. if (this.app.desktop.apps[appId]){
  900. this.app.desktop.apps[appId].setCurrent();
  901. }else {
  902. this.app.desktop.openApplication(null, "ForumDocument", {
  903. "sectionId" : this.data.sectionId,
  904. "id" : this.data.id,
  905. "appId": appId,
  906. "isEdited" : true,
  907. "isNew" : false,
  908. "index" : this.index
  909. });
  910. }
  911. }
  912. });
  913. MWF.xApplication.ForumSection.PrimeView = new Class({
  914. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  915. _createDocument: function(data, index){
  916. return new MWF.xApplication.ForumSection.PrimeDocument(this.viewNode, data, this.explorer, this, null, index);
  917. },
  918. _getCurrentPageData: function(callback, count, pageNum){
  919. this.clearBody();
  920. if(!count)count=30;
  921. if(!pageNum)pageNum = 1;
  922. var filter = this.filterData || {};
  923. this.actions.listCreamSubjectFilterPage( pageNum, count, filter, function(json){
  924. if( !json.data )json.data = [];
  925. if( !json.count )json.count=0;
  926. if( callback )callback(json);
  927. }.bind(this))
  928. },
  929. _removeDocument: function(documentData, all){
  930. this.actions.deleteSubject(documentData.id, function(json){
  931. this.reload();
  932. this.app.reloadAllParents();
  933. this.app.notice(this.app.lp.deleteDocumentOK, "success");
  934. }.bind(this));
  935. },
  936. _create: function(){
  937. },
  938. _openDocument: function( documentData,index ){
  939. var appId = "ForumDocument"+documentData.id;
  940. if (this.app.desktop.apps[appId]){
  941. this.app.desktop.apps[appId].setCurrent();
  942. }else {
  943. this.app.desktop.openApplication(null, "ForumDocument", {
  944. "sectionId" : documentData.sectionId,
  945. "id" : documentData.id,
  946. "appId": appId,
  947. "isEdited" : false,
  948. "isNew" : false,
  949. "index" : index
  950. });
  951. }
  952. },
  953. _queryCreateViewNode: function(){
  954. },
  955. _postCreateViewNode: function( viewNode ){
  956. },
  957. _queryCreateViewHead:function(){
  958. },
  959. _postCreateViewHead: function( headNode ){
  960. var allSubjectNode = headNode.getElements("[lable='allSubject']")[0];
  961. allSubjectNode.addEvent( "click", function(){
  962. this.explorer.reloadView();
  963. }.bind(this))
  964. }
  965. });
  966. MWF.xApplication.ForumSection.PrimeDocument = new Class({
  967. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  968. _queryCreateDocumentNode:function( itemData ){
  969. },
  970. _postCreateDocumentNode: function( itemNode, itemData ){
  971. },
  972. open: function (e) {
  973. this.view._openDocument(this.data, this.index);
  974. },
  975. edit : function(){
  976. var appId = "ForumDocument"+this.data.id;
  977. if (this.app.desktop.apps[appId]){
  978. this.app.desktop.apps[appId].setCurrent();
  979. }else {
  980. this.app.desktop.openApplication(null, "ForumDocument", {
  981. "sectionId" : this.data.sectionId,
  982. "id" : this.data.id,
  983. "appId": appId,
  984. "isEdited" : true,
  985. "isNew" : false,
  986. "index" : this.index
  987. });
  988. }
  989. }
  990. });