Main.js 31 KB

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