Main.js 33 KB

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