Main.js 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069
  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. var dateTimeStamp = Date.parse(publishTime.replace(/-/gi, "/"));
  415. var minute = 1000 * 60;
  416. var hour = minute * 60;
  417. var day = hour * 24;
  418. var halfamonth = day * 15;
  419. var month = day * 30;
  420. var year = month * 12;
  421. var now = new Date().getTime();
  422. var diffValue = now - dateTimeStamp;
  423. if (diffValue < 0) {
  424. //若日期不符则弹出窗口告之
  425. //alert("结束日期不能小于开始日期!");
  426. }
  427. var yesterday = new Date().decrement('day', 1);
  428. var beforYesterday = new Date().decrement('day', 2);
  429. var yearC = diffValue / year;
  430. var monthC = diffValue / month;
  431. var weekC = diffValue / (7 * day);
  432. var dayC = diffValue / day;
  433. var hourC = diffValue / hour;
  434. var minC = diffValue / minute;
  435. if (yesterday.getFullYear() == dateTimeStamp.getFullYear() && yesterday.getMonth() == dateTimeStamp.getMonth() && yesterday.getDate() == dateTimeStamp.getDate()) {
  436. result = "昨天 " + dateTimeStamp.getHours() + ":" + dateTimeStamp.getMinutes();
  437. } else if (beforYesterday.getFullYear() == dateTimeStamp.getFullYear() && beforYesterday.getMonth() == dateTimeStamp.getMonth() && beforYesterday.getDate() == dateTimeStamp.getDate()) {
  438. result = "前天 " + dateTimeStamp.getHours() + ":" + dateTimeStamp.getMinutes();
  439. } else if (yearC > 1) {
  440. result = dateTimeStamp.getFullYear() + "年" + (dateTimeStamp.getMonth() + 1) + "月" + dateTimeStamp.getDate() + "日";
  441. } else if (monthC >= 1) {
  442. //result= parseInt(monthC) + "个月前";
  443. // s.getFullYear()+"年";
  444. result = (dateTimeStamp.getMonth() + 1) + "月" + dateTimeStamp.getDate() + "日";
  445. } else if (weekC >= 1) {
  446. result = parseInt(weekC) + "周前";
  447. } else if (dayC >= 1) {
  448. result = parseInt(dayC) + "天前";
  449. } else if (hourC >= 1) {
  450. result = parseInt(hourC) + "小时前";
  451. } else if (minC >= 1) {
  452. result = parseInt(minC) + "分钟前";
  453. } else
  454. result = "刚刚发表";
  455. return result;
  456. },
  457. openPerson : function( userName ){
  458. if( !userName || userName == "" ){
  459. }else{
  460. var appId = "ForumPerson"+userName;
  461. if (this.desktop.apps[userName]){
  462. this.desktop.apps[userName].setCurrent();
  463. }else {
  464. this.desktop.openApplication(null, "ForumPerson", {
  465. "personName" : userName,
  466. "appId": appId
  467. });
  468. }
  469. }
  470. },
  471. createPersonNode : function( container, personName ){
  472. var persons = personName.split(",");
  473. persons.each( function(userName, i){
  474. var span = new Element("span", {
  475. "text" : userName,
  476. "styles" : this.css.person
  477. }).inject(container);
  478. span.addEvents( {
  479. mouseover : function(){ this.node.setStyles( this.obj.css.person_over )}.bind( {node:span, obj:this} ),
  480. mouseout : function(){ this.node.setStyles( this.obj.css.person )}.bind( {node:span, obj:this} ),
  481. click : function(){ this.obj.openPerson( this.userName ) }.bind( {userName:userName, obj:this} )
  482. })
  483. if( i != persons.length - 1 ){
  484. new Element("span", {
  485. "text" : ",",
  486. }).inject(container);
  487. }
  488. }.bind(this))
  489. },
  490. clearContent: function () {
  491. if (this.explorer)this.explorer.destroy();
  492. if(this.setContentSizeFun)this.removeEvent("resize", this.setContentSizeFun );
  493. if(this.scrollBar && this.scrollBar.scrollVAreaNode)this.scrollBar.scrollVAreaNode.destroy();
  494. if( this.scrollBar )delete this.scrollBar;
  495. if (this.contentContainerNode) {
  496. this.contentContainerNode.destroy();
  497. //this.middleNode.destroy();
  498. //this.contentNode.destroy();
  499. }
  500. },
  501. });
  502. MWF.xApplication.ForumSection.Explorer = new Class({
  503. Extends: MWF.widget.Common,
  504. Implements: [Options, Events],
  505. options: {
  506. "style": "default",
  507. "viewPageNum" : 1
  508. },
  509. initialize: function (container, app, parent, options) {
  510. this.setOptions( options );
  511. this.container = container;
  512. this.parent = parent;
  513. this.app = app;
  514. this.css = this.parent.css;
  515. this.lp = this.app.lp;
  516. },
  517. load: function () {
  518. this.container.empty();
  519. this.loadToolbar();
  520. this.viewContainerTop = Element("div",{
  521. "styles" : this.css.viewContainerTop
  522. }).inject(this.container);
  523. this.viewContainer = Element("div",{
  524. "styles" : this.css.viewContainer
  525. }).inject(this.container);
  526. this.viewContainerPrime = Element("div",{
  527. "styles" : this.css.viewContainer
  528. }).inject(this.container);
  529. this.loadToolbar();
  530. //this.loadTopView();
  531. this.loadView();
  532. },
  533. destroy : function(){
  534. if(this.resizeWindowFun)this.app.removeEvent("resize",this.resizeWindowFun)
  535. this.view.destroy();
  536. if( this.view.refreshInterval ){
  537. clearInterval( this.view.refreshInterval );
  538. }
  539. },
  540. loadToolbar: function(){
  541. var toolbar = new Element("div",{
  542. styles : this.css.toolbar
  543. }).inject(this.container)
  544. if( this.toolbarTop ){
  545. this.toolbarBottom = toolbar;
  546. }else{
  547. this.toolbarTop = toolbar;
  548. }
  549. //if( this.parent.access.isSubjectPublisher( this.parent.sectionData ) ){
  550. if( this.app.sectionPermission.subjectPublishAble ){
  551. var createActionNode = new Element("div",{
  552. styles : this.css.toolbarActionNode,
  553. text: this.lp.createSubject
  554. }).inject(toolbar);
  555. createActionNode.addEvents(
  556. {
  557. "mouseover": function () {
  558. this.node.setStyles(this.obj.css.toolbarActionNode_over);
  559. }.bind({obj: this, node: createActionNode}),
  560. "mouseout": function () {
  561. this.node.setStyles(this.obj.css.toolbarActionNode);
  562. }.bind({obj: this, node: createActionNode}),
  563. "click": function () {
  564. if( this.app.access.isAnonymousDynamic() ){
  565. this.app.openLoginForm(
  566. function(){ this.createSubject(); }.bind(this)
  567. );
  568. }else{
  569. this.createSubject();
  570. }
  571. }.bind(this)
  572. }
  573. )
  574. }
  575. var fileterNode = new Element("div",{
  576. styles : this.css.fileterNode
  577. }).inject(toolbar);
  578. var pagingBar = new Element("div",{
  579. styles : this.css.fileterNode
  580. }).inject(toolbar);
  581. if( this.pagingBarTop ){
  582. this.pagingBarBottom = pagingBar;
  583. }else{
  584. this.pagingBarTop = pagingBar;
  585. }
  586. },
  587. loadTopView : function(){
  588. this.viewTop = new MWF.xApplication.ForumSection.TopView( this.viewContainerTop, this.app, this, {
  589. templateUrl : this.parent.path+"listItemTop.json"
  590. } )
  591. //this.viewTop.filterData = { sectionId : this.app.sectionData.id };
  592. this.viewTop.load();
  593. },
  594. loadView : function(){
  595. //this.resizeWindow();
  596. //this.resizeWindowFun = this.resizeWindow.bind(this)
  597. //this.app.addEvent("resize", this.resizeWindowFun );
  598. this.view = new MWF.xApplication.ForumSection.View( this.viewContainer, this.app, this, {
  599. templateUrl : this.parent.path+"listItem.json",
  600. pagingEnable : true,
  601. pagingPar : {
  602. currentPage : this.options.viewPageNum,
  603. countPerPage : 30,
  604. onPostLoad : function( pagingBar ){
  605. if(pagingBar.nextPageNode){
  606. pagingBar.nextPageNode.inject( this.toolbarBottom, "before" );
  607. }
  608. }.bind(this),
  609. onPageReturn : function( pagingBar ){
  610. var appId = "Forum";
  611. if (this.app.desktop.apps[appId]){
  612. this.app.desktop.apps[appId].setCurrent();
  613. }else {
  614. this.app.desktop.openApplication(null, "Forum", { "appId": appId });
  615. }
  616. this.app.close();
  617. }.bind(this)
  618. }
  619. } )
  620. this.view.filterData = { sectionId : this.app.sectionData.id , withTopSubject : true };
  621. this.view.pagingContainerTop = this.pagingBarTop;
  622. this.view.pagingContainerBottom = this.pagingBarBottom;
  623. this.view.load();
  624. },
  625. reloadView : function() {
  626. if( this.viewPrime )this.viewPrime.destroy();
  627. this.viewContainer.setStyle("display","");
  628. this.viewContainerTop.setStyle("display","");
  629. this.viewContainerPrime.setStyle("display","none");
  630. this.loadTopView();
  631. this.loadView();
  632. },
  633. loadPrimeView : function(){
  634. if( this.view )this.view.destroy();
  635. if( this.viewTop )this.viewTop.destroy();
  636. this.viewContainer.setStyle("display","none");
  637. this.viewContainerTop.setStyle("display","none");
  638. this.viewContainerPrime.setStyle("display","");
  639. this.viewPrime = new MWF.xApplication.ForumSection.PrimeView( this.viewContainerPrime, this.app, this, {
  640. templateUrl : this.parent.path+"listItemPrime.json",
  641. pagingEnable : true,
  642. pagingPar : {
  643. currentPage : 1,
  644. countPerPage : 30,
  645. onPostLoad : function( pagingBar ){
  646. if(pagingBar.nextPageNode){
  647. pagingBar.nextPageNode.inject( this.toolbarBottom, "before" );
  648. }
  649. }.bind(this),
  650. onPageReturn : function( pagingBar ){
  651. var appId = "Forum";
  652. if (this.app.desktop.apps[appId]){
  653. this.app.desktop.apps[appId].setCurrent();
  654. }else {
  655. this.app.desktop.openApplication(null, "Forum", { "appId": appId });
  656. }
  657. this.app.close();
  658. }.bind(this)
  659. }
  660. } )
  661. this.viewPrime.filterData = { sectionId : this.app.sectionData.id };
  662. this.viewPrime.pagingContainerTop = this.pagingBarTop;
  663. this.viewPrime.pagingContainerBottom = this.pagingBarBottom;
  664. this.viewPrime.load();
  665. },
  666. resizeWindow: function(){
  667. var size = this.app.content.getSize();
  668. this.viewContainer.setStyles({"height":(size.y-121)+"px"});
  669. },
  670. createSubject: function(){
  671. var _self = this;
  672. var appId = "ForumDocument";
  673. if (_self.app.desktop.apps[appId]){
  674. _self.app.desktop.apps[appId].setCurrent();
  675. }else {
  676. this.app.desktop.openApplication(null, "ForumDocument", {
  677. "sectionId": this.app.sectionData.id,
  678. "appId": appId,
  679. "onPostPublish" : function(){
  680. //this.view.reload();
  681. }.bind(this)
  682. });
  683. }
  684. }
  685. })
  686. MWF.xApplication.ForumSection.TopView = new Class({
  687. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  688. _createDocument: function(data, index){
  689. return new MWF.xApplication.ForumSection.TopDocument(this.viewNode, data, this.explorer, this, null, index);
  690. },
  691. _getCurrentPageData: function(callback, count){
  692. if (!count)count = 30;
  693. //var id = (this.items.length) ? this.items[this.items.length - 1].data.id : "(0)";
  694. var filter = this.filterData || {};
  695. //page, count, filterData, success,failure, async
  696. if( !this.page ){
  697. this.page = 1;
  698. }else{
  699. this.page ++;
  700. }
  701. this.actions.listTopSubject( this.app.sectionData.id, function (json) {
  702. if( !json.data )json.data = [];
  703. if (callback)callback(json);
  704. }.bind(this))
  705. },
  706. _removeDocument: function(documentData, all){
  707. this.actions.deleteSubject(documentData.id, function(json){
  708. this.reload();
  709. this.app.reloadAllParents()
  710. this.app.notice(this.app.lp.deleteDocumentOK, "success");
  711. }.bind(this));
  712. },
  713. _create: function(){
  714. },
  715. _openDocument: function( documentData,index ){
  716. var appId = "ForumDocument"+documentData.id;
  717. if (this.app.desktop.apps[appId]){
  718. this.app.desktop.apps[appId].setCurrent();
  719. }else {
  720. this.app.desktop.openApplication(null, "ForumDocument", {
  721. "sectionId" : documentData.sectionId,
  722. "id" : documentData.id,
  723. "appId": appId,
  724. "isEdited" : false,
  725. "isNew" : false,
  726. "index" : index
  727. });
  728. }
  729. },
  730. _queryCreateViewNode: function(){
  731. },
  732. _postCreateViewNode: function( viewNode ){
  733. },
  734. _queryCreateViewHead:function(){
  735. },
  736. _postCreateViewHead: function( headNode ){
  737. //this.allSubjectNode = headNode.getElements("[lable='allSubject']")[0];
  738. var primeNode = headNode.getElements("[lable='prime']")[0];
  739. primeNode.addEvent( "click", function(){
  740. this.explorer.loadPrimeView();
  741. }.bind(this))
  742. }
  743. })
  744. MWF.xApplication.ForumSection.TopDocument = new Class({
  745. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  746. _queryCreateDocumentNode:function( itemData ){
  747. },
  748. _postCreateDocumentNode: function( itemNode, itemData ){
  749. },
  750. open: function (e) {
  751. this.view._openDocument(this.data, this.index);
  752. },
  753. edit : function(){
  754. var appId = "ForumDocument"+this.data.id;
  755. if (this.app.desktop.apps[appId]){
  756. this.app.desktop.apps[appId].setCurrent();
  757. }else {
  758. this.app.desktop.openApplication(null, "ForumDocument", {
  759. "sectionId" : this.data.sectionId,
  760. "id" : this.data.id,
  761. "appId": appId,
  762. "isEdited" : true,
  763. "isNew" : false,
  764. "index" : this.index
  765. });
  766. }
  767. }
  768. })
  769. MWF.xApplication.ForumSection.View = new Class({
  770. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  771. refreshNewSubject : function(){
  772. if (this.refreshTr)this.refreshTr.destroy();
  773. if( this.refreshInterval ){
  774. clearInterval( this.refreshInterval );
  775. }
  776. this.refreshInterval = setInterval( function(){
  777. this.actions.listSubjectFilterPage( 1, 1, this.filterData || {}, function(json){
  778. if( !json.count )json.count=0;
  779. var count = this.laterRefreshCount || this.dataCount;
  780. if( json.count > count ) {
  781. this.laterRefreshCount = json.count;
  782. this.createRefreshTr( json.count );
  783. }
  784. }.bind(this))
  785. }.bind(this), 10 * 60 * 1000 )
  786. },
  787. createRefreshTr : function( newCount ){
  788. if (this.refreshTr)this.refreshTr.destroy();
  789. var refreshTr = this.refreshTr = new Element( "tr.refreshTrNode" , {
  790. styles : this.css.refreshTrNode
  791. }).inject( this.headNode, "after" );
  792. var td = this.refreshTd = new Element( "td.refreshTdNode", {
  793. width : "60%",
  794. styles : this.css.refreshTdNode
  795. }).inject( refreshTr )
  796. var refreshNode = new Element("div" , {
  797. styles : this.css.refreshNode,
  798. text : this.lp.newSubjectPublishedText.replace( "{count}", newCount - this.dataCount )
  799. }).inject(td)
  800. refreshNode.addEvent("click", function(){
  801. this.gotoPage(1)
  802. }.bind(this))
  803. var td = new Element( "td.refreshTdNode", {
  804. styles : this.css.refreshTdNode,
  805. width : "12%"
  806. }).inject( refreshTr )
  807. var td = new Element( "td.refreshTdNode", {
  808. styles : this.css.refreshTdNode,
  809. width : "7%"
  810. }).inject( refreshTr )
  811. var td = new Element( "td.refreshTdNode", {
  812. styles : this.css.refreshTdNode,
  813. width : "7%"
  814. }).inject( refreshTr )
  815. var td = new Element( "td.refreshTdNode", {
  816. styles : this.css.refreshTdNode,
  817. width : "14%"
  818. }).inject( refreshTr )
  819. },
  820. _createDocument: function(data, index){
  821. return new MWF.xApplication.ForumSection.Document(this.viewNode, data, this.explorer, this, null, index);
  822. },
  823. _getCurrentPageData: function(callback, count, pageNum){
  824. this.clearBody();
  825. if(!count)count=30;
  826. if(!pageNum)pageNum = 1;
  827. //if( pageNum == 1 ){
  828. // this.explorer.viewContainerTop.setStyle("display","block");
  829. // this.headNode.setStyle("display","none");
  830. //}else{
  831. // this.explorer.viewContainerTop.setStyle("display","none");
  832. // this.headNode.setStyle("display","");
  833. //}
  834. if( this.topSepTr )this.topSepTr.destroy();
  835. var filter = this.filterData || {};
  836. //filter.withTopSubject = false;
  837. this.actions.listSubjectFilterPage( pageNum, count, filter, function(json){
  838. if( !json.data )json.data = [];
  839. if( !json.count )json.count=0;
  840. this.refreshNewSubject();
  841. if( callback )callback(json);
  842. }.bind(this))
  843. },
  844. _removeDocument: function(documentData, all){
  845. this.actions.deleteSubject(documentData.id, function(json){
  846. this.reload();
  847. this.app.reloadAllParents()
  848. this.app.notice(this.app.lp.deleteDocumentOK, "success");
  849. }.bind(this));
  850. },
  851. _create: function(){
  852. },
  853. _openDocument: function( documentData,index ){
  854. var appId = "ForumDocument"+documentData.id;
  855. if (this.app.desktop.apps[appId]){
  856. this.app.desktop.apps[appId].setCurrent();
  857. }else {
  858. this.app.desktop.openApplication(null, "ForumDocument", {
  859. "sectionId" : documentData.sectionId,
  860. "id" : documentData.id,
  861. "appId": appId,
  862. "isEdited" : false,
  863. "isNew" : false,
  864. "index" : index
  865. });
  866. }
  867. },
  868. _queryCreateViewNode: function(){
  869. },
  870. _postCreateViewNode: function( viewNode ){
  871. },
  872. _queryCreateViewHead:function(){
  873. },
  874. _postCreateViewHead: function( headNode ){
  875. var primeNode = headNode.getElements("[lable='prime']")[0];
  876. primeNode.addEvent( "click", function(){
  877. this.explorer.loadPrimeView();
  878. }.bind(this))
  879. }
  880. })
  881. MWF.xApplication.ForumSection.Document = new Class({
  882. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  883. _queryCreateDocumentNode:function( itemData ){
  884. },
  885. _postCreateDocumentNode: function( itemNode, itemData ){
  886. //置顶帖和一般帖之间添加分割线
  887. if( this.index != 1 && !itemData.isTopSubject ){
  888. var prev = this.view.items[this.index-1];
  889. if( prev && prev.data.isTopSubject ){
  890. var tr = this.view.topSepTr = new Element( "tr").inject( itemNode, "before" );
  891. new Element( "td", {colspan:5}).inject( tr )
  892. }
  893. }
  894. },
  895. open: function (e) {
  896. this.view._openDocument(this.data, this.index);
  897. },
  898. edit : function(){
  899. var appId = "ForumDocument"+this.data.id;
  900. if (this.app.desktop.apps[appId]){
  901. this.app.desktop.apps[appId].setCurrent();
  902. }else {
  903. this.app.desktop.openApplication(null, "ForumDocument", {
  904. "sectionId" : this.data.sectionId,
  905. "id" : this.data.id,
  906. "appId": appId,
  907. "isEdited" : true,
  908. "isNew" : false,
  909. "index" : this.index
  910. });
  911. }
  912. }
  913. })
  914. MWF.xApplication.ForumSection.PrimeView = new Class({
  915. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  916. _createDocument: function(data, index){
  917. return new MWF.xApplication.ForumSection.PrimeDocument(this.viewNode, data, this.explorer, this, null, index);
  918. },
  919. _getCurrentPageData: function(callback, count, pageNum){
  920. this.clearBody();
  921. if(!count)count=30;
  922. if(!pageNum)pageNum = 1;
  923. var filter = this.filterData || {};
  924. this.actions.listCreamSubjectFilterPage( pageNum, count, filter, function(json){
  925. if( !json.data )json.data = [];
  926. if( !json.count )json.count=0;
  927. if( callback )callback(json);
  928. }.bind(this))
  929. },
  930. _removeDocument: function(documentData, all){
  931. this.actions.deleteSubject(documentData.id, function(json){
  932. this.reload();
  933. this.app.reloadAllParents()
  934. this.app.notice(this.app.lp.deleteDocumentOK, "success");
  935. }.bind(this));
  936. },
  937. _create: function(){
  938. },
  939. _openDocument: function( documentData,index ){
  940. var appId = "ForumDocument"+documentData.id;
  941. if (this.app.desktop.apps[appId]){
  942. this.app.desktop.apps[appId].setCurrent();
  943. }else {
  944. this.app.desktop.openApplication(null, "ForumDocument", {
  945. "sectionId" : documentData.sectionId,
  946. "id" : documentData.id,
  947. "appId": appId,
  948. "isEdited" : false,
  949. "isNew" : false,
  950. "index" : index
  951. });
  952. }
  953. },
  954. _queryCreateViewNode: function(){
  955. },
  956. _postCreateViewNode: function( viewNode ){
  957. },
  958. _queryCreateViewHead:function(){
  959. },
  960. _postCreateViewHead: function( headNode ){
  961. var allSubjectNode = headNode.getElements("[lable='allSubject']")[0];
  962. allSubjectNode.addEvent( "click", function(){
  963. this.explorer.reloadView();
  964. }.bind(this))
  965. }
  966. })
  967. MWF.xApplication.ForumSection.PrimeDocument = new Class({
  968. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  969. _queryCreateDocumentNode:function( itemData ){
  970. },
  971. _postCreateDocumentNode: function( itemNode, itemData ){
  972. },
  973. open: function (e) {
  974. this.view._openDocument(this.data, this.index);
  975. },
  976. edit : function(){
  977. var appId = "ForumDocument"+this.data.id;
  978. if (this.app.desktop.apps[appId]){
  979. this.app.desktop.apps[appId].setCurrent();
  980. }else {
  981. this.app.desktop.openApplication(null, "ForumDocument", {
  982. "sectionId" : this.data.sectionId,
  983. "id" : this.data.id,
  984. "appId": appId,
  985. "isEdited" : true,
  986. "isNew" : false,
  987. "index" : this.index
  988. });
  989. }
  990. }
  991. })