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. this.setTitle( this.sectionData.sectionName );
  104. this.createTopNode();
  105. this.createMiddleNode();
  106. //}.bind(this) );
  107. }.bind(this) )
  108. }.bind(this) )
  109. }else{
  110. this.close()
  111. }
  112. },
  113. loadTopObject : function(naviMode){
  114. if( this.options.hasTop ){
  115. var node = this.topObject = new MWF.xApplication.Forum.TopNode(this.contentContainerNode, this, this, {
  116. type: this.options.style,
  117. naviModeEnable : true,
  118. naviMode : naviMode
  119. });
  120. node.load();
  121. }
  122. },
  123. createTopNode: function(){
  124. this.loadTopObject( false );
  125. if( this.options.hasBreadCrumb ){
  126. var topNode = this.topNode = new Element("div.topNode", {
  127. "styles": this.options.autoWidth ? this.css.topNode_inContainer : this.css.topNode
  128. }).inject(this.contentContainerNode);
  129. //topNode.setStyle("border-bottom","1px solid "+forumColor);
  130. var topTitleMiddleNode = this.breadCrumbNode = new Element("div.topTitleMiddleNode", {
  131. "styles": this.css.topTitleMiddleNode
  132. }).inject(topNode);
  133. //topTitleMiddleNode.setStyle( "background-color" , forumColor )
  134. var topItemTitleNode = new Element("div.topItemTitleNode", {
  135. "styles": this.css.topItemTitleNode,
  136. "text": this.lp.title
  137. }).inject(topTitleMiddleNode);
  138. topItemTitleNode.addEvent("click", function(){
  139. if( this.options.naviMode && this.forumNavi ){
  140. this.forumNavi.goto( MWFForum.NaviType.main )
  141. }else{
  142. var appId = "Forum";
  143. if (this.desktop.apps[appId]){
  144. this.desktop.apps[appId].setCurrent();
  145. }else {
  146. this.desktop.openApplication(null, "Forum", { "appId": appId });
  147. }
  148. this.close();
  149. }
  150. }.bind(this));
  151. var topItemSepNode = new Element("div.topItemSepNode", {
  152. "styles": this.css.topItemSepNode,
  153. "text" : ">"
  154. }).inject(topTitleMiddleNode);
  155. var topItemTitleNode = new Element("div.topItemTitleNode", {
  156. "styles": this.css.topItemTitleNode,
  157. "text": this.sectionData.forumName
  158. }).inject(topTitleMiddleNode);
  159. topItemTitleNode.addEvent("click", function(){
  160. if( this.obj.options.naviMode && this.obj.forumNavi ){
  161. this.obj.forumNavi.goto( MWFForum.NaviType.category, this.forumId )
  162. }else{
  163. var appId = "ForumCategory"+this.forumId;
  164. if (this.obj.desktop.apps[appId]){
  165. this.obj.desktop.apps[appId].setCurrent();
  166. }else {
  167. this.obj.desktop.openApplication(null, "ForumCategory", { "categoryId" : this.forumId ,"appId": appId });
  168. }
  169. if( !this.obj.inBrowser ){
  170. this.obj.close();
  171. }
  172. }
  173. }.bind({ obj: this, forumId : this.sectionData.forumId }));
  174. topItemSepNode = new Element("div.topItemSepNode", {
  175. "styles": this.css.topItemSepNode,
  176. "text" : ">"
  177. }).inject(topTitleMiddleNode);
  178. topItemTitleNode = new Element("div.topItemTitleNode", {
  179. "styles": this.css.topItemTitleLastNode,
  180. "text": this.sectionData.sectionName
  181. }).inject(topTitleMiddleNode);
  182. }
  183. if( this.sectionData.sectionNotice ){
  184. var topRightNode = new Element("div", {
  185. "styles": this.css.topRightNode
  186. }).inject(topNode);
  187. topRightNode.addEvents({
  188. "click" :function(){
  189. if( !this.noteNodeHidden ){
  190. this.noteNode.setStyle("display","none");
  191. this.topRightIconNode.setStyles(this.css.topRightIconDownNode);
  192. this.noteNodeHidden = true;
  193. }else{
  194. this.noteNode.setStyle("display","");
  195. this.topRightIconNode.setStyles(this.css.topRightIconNode);
  196. this.noteNodeHidden = false;
  197. }
  198. }.bind(this)
  199. });
  200. var topRightIconNode = this.topRightIconNode = new Element("div", {
  201. "styles": this.css.topRightIconNode
  202. }).inject(topRightNode);
  203. if( this.status && this.status.noteHidden ){
  204. this.topRightIconNode.setStyles(this.css.topRightIconDownNode);
  205. this.noteNodeHidden = true;
  206. }
  207. }
  208. },
  209. createMiddleNode: function(){
  210. this.middleNode = new Element("div.middleNode", {
  211. "styles": this.options.autoWidth ? this.css.middleNode_inContainer : this.css.middleNode
  212. }).inject(this.contentContainerNode);
  213. this.createSectionNode();
  214. this.createNoteNode();
  215. this._createMiddleNode();
  216. if( !this.options.naviMode ){
  217. this.addEvent("resize", function () {
  218. this.setContentSize();
  219. }.bind(this));
  220. this.setContentSize();
  221. }
  222. //MWF.require("MWF.widget.ScrollBar", function () {
  223. // new MWF.widget.ScrollBar(this.contentContainerNode, {
  224. // "indent": false,
  225. // "style": "xApp_TaskList",
  226. // "where": "before",
  227. // "distance": 30,
  228. // "friction": 4,
  229. // "axis": {"x": false, "y": true},
  230. // "onScroll": function (y) {
  231. // }
  232. // });
  233. //}.bind(this));
  234. },
  235. openNavi: function () {
  236. MWF.xDesktop.requireApp("Forum", "NaviMode", null, false);
  237. this.clearContent();
  238. this.contentContainerNode = new Element("div.contentContainerNode", {
  239. "styles": this.css.contentContainerNode
  240. }).inject(this.node);
  241. this.loadTopObject( true );
  242. this.middleNode = new Element("div.middleNode", {
  243. "styles": this.css.middleNode
  244. }).inject(this.contentContainerNode);
  245. this.contentNode = new Element("div.contentNode", {
  246. "styles": this.css.contentNode
  247. }).inject(this.middleNode);
  248. this.navi = new MWF.xApplication.Forum.NaviMode(this, this.contentNode, {
  249. type : MWFForum.NaviType.section,
  250. id : this.sectionData.id
  251. });
  252. this.navi.load();
  253. },
  254. closeNavi : function(){
  255. if( this.navi )this.navi.close();
  256. },
  257. colorRgba : function( color, opacity ){ /*16进制颜色转为RGB格式*/
  258. var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
  259. var sColor = color.toLowerCase();
  260. if(sColor && reg.test(sColor)){
  261. if(sColor.length === 4){
  262. var sColorNew = "#";
  263. for(var i=1; i<4; i+=1){
  264. sColorNew += sColor.slice(i,i+1).concat(sColor.slice(i,i+1));
  265. }
  266. sColor = sColorNew;
  267. }
  268. //处理六位的颜色值
  269. var sColorChange = [];
  270. for(var i=1; i<7; i+=2){
  271. sColorChange.push(parseInt("0x"+sColor.slice(i,i+2)));
  272. }
  273. return "rgba(" + sColorChange.join(",") + "," + opacity + ")";
  274. }else{
  275. return sColor;
  276. }
  277. },
  278. createSectionNode: function(){
  279. var forumColor = MWF.xApplication.Forum.ForumSetting[this.sectionData.forumId].forumColor;
  280. var sectionNode = new Element("div.sectionNode", {
  281. "styles": this.options.autoWidth ? this.css.sectionNode_inContainer : this.css.sectionNode
  282. }).inject(this.middleNode);
  283. sectionNode.setStyle("background-color", this.colorRgba( forumColor, "0.05" ));
  284. var sectionLeftNode = new Element("div.sectionLeftNode", {
  285. "styles": this.css.sectionLeftNode
  286. }).inject(sectionNode);
  287. var sectionLeftIconNode = new Element("div.sectionLeftIconNode", {
  288. "styles": this.css.sectionLeftIconNode
  289. }).inject(sectionLeftNode);
  290. var sectionLeftIcon = new Element("img", {
  291. "styles": this.css.sectionLeftIcon,
  292. "src" : this.sectionData.icon ? ('data:image/png;base64,'+ this.sectionData.icon) : "/x_component_Forum/$Setting/default/sectionIcon/forum_icon.png"
  293. }).inject(sectionLeftIconNode);
  294. var sectionLeftContent = new Element("div.sectionLeftContent", {
  295. "styles": this.css.sectionLeftContent
  296. }).inject(sectionLeftNode);
  297. var sectionTopDiv = new Element("div.sectionTopDiv", {
  298. "styles": this.css.sectionTopDiv
  299. }).inject(sectionLeftContent);
  300. var sectionTopInfor= new Element("div.sectionTopInfor", {
  301. "styles": this.css.sectionTopInfor,
  302. "text" : this.lp.subject + ":" + this.sectionData.subjectTotal + "," + this.lp.replyCount + ":" + this.sectionData.replyTotal
  303. }).inject(sectionTopDiv);
  304. var sectionLeftDiv = new Element("div.sectionLeftDiv", {
  305. "styles": this.css.sectionLeftDiv
  306. }).inject(sectionLeftContent);
  307. var sectionLeftMemo = new Element("div.sectionLeftMemo", {
  308. "styles": this.css.sectionLeftMemo,
  309. "text" : this.sectionData.sectionDescription
  310. }).inject(sectionLeftDiv);
  311. sectionTopDiv = new Element("div.sectionTopDiv", {
  312. "styles": this.css.sectionTopDiv
  313. }).inject(sectionLeftContent);
  314. sectionTopInfor= new Element("div.sectionTopInfor", {
  315. "styles": this.css.sectionTopInfor,
  316. "text" : this.lp.moderatorNames + ":"
  317. }).inject(sectionTopDiv);
  318. sectionTopInfor= new Element("div.sectionTopInfor", {
  319. "styles": this.css.sectionTopInfor
  320. }).inject(sectionTopDiv);
  321. this.createPersonNode( sectionTopInfor, this.sectionData.moderatorNames );
  322. },
  323. createNoteNode : function(){
  324. if( !this.sectionData.sectionNotice || this.sectionData.sectionNotice.trim() =="" ){
  325. return;
  326. }
  327. var noteNode = this.noteNode = new Element("div.noteNode", {
  328. "styles": this.css.noteNode
  329. }).inject(this.middleNode);
  330. var noteTopNode = new Element("div.noteTopNode", {
  331. "styles": this.css.noteTopNode
  332. }).inject(noteNode);
  333. var noteTopContent = new Element("div.noteTopContent", {
  334. "styles": this.css.noteTopContent
  335. }).inject(noteTopNode);
  336. var noteIcon = new Element("div.noteIcon", {
  337. "styles": this.css.noteIcon
  338. }).inject(noteTopContent);
  339. var noteTopText = new Element("div.noteTopText", {
  340. "styles": this.css.noteTopText,
  341. "text" : this.lp.sectionNotice
  342. }).inject(noteTopContent);
  343. var noteContent = new Element("div.noteContent", {
  344. "styles": this.css.noteContent,
  345. "html" : this.sectionData.sectionNotice
  346. }).inject(noteNode);
  347. if( this.status && this.status.noteHidden ){
  348. noteNode.setStyle("display" , "none");
  349. }
  350. },
  351. _createMiddleNode : function(){
  352. this.contentDiv = new Element("div.contentDiv",{"styles":this.css.contentDiv}).inject(this.middleNode);
  353. if( this.contentDiv )this.contentDiv.empty();
  354. if( this.explorer ){
  355. this.explorer.destroy();
  356. delete this.explorer;
  357. }
  358. this.explorer = new MWF.xApplication.ForumSection.Explorer(this.contentDiv, this, this,{
  359. style:this.options.style,
  360. viewPageNum : ( this.status && this.status.viewPageNum ) ? this.status.viewPageNum : 1
  361. });
  362. this.explorer.load();
  363. },
  364. setContentSize: function () {
  365. //var topSize = this.topNode ? this.topNode.getSize() : {"x": 0, "y": 0};
  366. var topSize = {"x": 0, "y": 0};
  367. var nodeSize = this.content.getSize();
  368. var pt = this.contentContainerNode.getStyle("padding-top").toFloat();
  369. var pb = this.contentContainerNode.getStyle("padding-bottom").toFloat();
  370. var height = nodeSize.y - topSize.y - pt - pb;
  371. this.contentContainerNode.setStyle("height", "" + height + "px");
  372. },
  373. openLoginForm : function(){
  374. //MWF.xDesktop.requireApp("Forum", "Login", null, false);
  375. //var login = new MWF.xApplication.Forum.Login(this, {
  376. // onPostOk : function(){
  377. // window.location.reload();
  378. // }
  379. //});
  380. //login.openLoginForm();
  381. MWF.require("MWF.xDesktop.Authentication", null, false);
  382. var authentication = new MWF.xDesktop.Authentication({
  383. style : "application",
  384. onPostOk : function(){
  385. window.location.reload();
  386. }
  387. },this);
  388. authentication.openLoginForm({
  389. hasMask : true
  390. });
  391. },
  392. openSignUpForm : function(){
  393. //MWF.xDesktop.requireApp("Forum", "Login", null, false);
  394. //var login = new MWF.xApplication.Forum.Login(this, {});
  395. //login.openSignUpForm();
  396. MWF.require("MWF.xDesktop.Authentication", null, false);
  397. var authentication = new MWF.xDesktop.Authentication( {
  398. style : "application",
  399. onPostOk : function(){
  400. }
  401. }, this);
  402. authentication.openSignUpForm({
  403. hasMask : true
  404. });
  405. },
  406. recordStatus: function(){
  407. return {
  408. sectionId : this.options.sectionId,
  409. viewPageNum : this.explorer.view.getCurrentPageNum(),
  410. noteHidden : this.noteNodeHidden
  411. };
  412. },
  413. openPerson : function( userName ){
  414. if( !userName || userName == "" ){
  415. }else{
  416. var appId = "ForumPerson"+userName;
  417. if (this.desktop.apps[userName]){
  418. this.desktop.apps[userName].setCurrent();
  419. }else {
  420. this.desktop.openApplication(null, "ForumPerson", {
  421. "personName" : userName,
  422. "appId": appId
  423. });
  424. }
  425. }
  426. },
  427. createPersonNode : function( container, personName ){
  428. var persons = personName.split(",");
  429. persons.each( function(userName, i){
  430. var span = new Element("span", {
  431. "text" : userName.split("@")[0],
  432. "styles" : this.css.person
  433. }).inject(container);
  434. span.addEvents( {
  435. mouseover : function(){ this.node.setStyles( this.obj.css.person_over )}.bind( {node:span, obj:this} ),
  436. mouseout : function(){ this.node.setStyles( this.obj.css.person )}.bind( {node:span, obj:this} ),
  437. click : function(){ this.obj.openPerson( this.userName ) }.bind( {userName:userName, obj:this} )
  438. });
  439. if( i != persons.length - 1 ){
  440. new Element("span", {
  441. "text" : "、"
  442. }).inject(container);
  443. }
  444. }.bind(this))
  445. },
  446. destroy : function(){
  447. this.clearContent();
  448. },
  449. clearContent: function () {
  450. if (this.explorer)this.explorer.destroy();
  451. if(this.setContentSizeFun)this.removeEvent("resize", this.setContentSizeFun );
  452. if(this.scrollBar && this.scrollBar.scrollVAreaNode)this.scrollBar.scrollVAreaNode.destroy();
  453. if( this.scrollBar )delete this.scrollBar;
  454. if (this.contentContainerNode) {
  455. this.contentContainerNode.destroy();
  456. //this.middleNode.destroy();
  457. //this.contentNode.destroy();
  458. }
  459. }
  460. });
  461. MWF.xApplication.ForumSection.Explorer = new Class({
  462. Extends: MWF.widget.Common,
  463. Implements: [Options, Events],
  464. options: {
  465. "style": "default",
  466. "viewPageNum" : 1
  467. },
  468. initialize: function (container, app, parent, options) {
  469. this.setOptions( options );
  470. this.container = container;
  471. this.parent = parent;
  472. this.app = app;
  473. this.css = this.parent.css;
  474. this.lp = this.app.lp;
  475. },
  476. load: function () {
  477. this.container.empty();
  478. this.loadToolbar();
  479. this.viewContainerTop = Element("div",{
  480. "styles" : this.css.viewContainerTop
  481. }).inject(this.container);
  482. this.viewContainer = Element("div",{
  483. "styles" : this.css.viewContainer
  484. }).inject(this.container);
  485. this.viewContainerPrime = Element("div",{
  486. "styles" : this.css.viewContainer
  487. }).inject(this.container);
  488. this.loadToolbar();
  489. //this.loadTopView();
  490. this.loadView();
  491. },
  492. destroy : function(){
  493. if(this.resizeWindowFun)this.app.removeEvent("resize",this.resizeWindowFun);
  494. this.view.destroy();
  495. if( this.view.refreshInterval ){
  496. clearInterval( this.view.refreshInterval );
  497. }
  498. },
  499. loadToolbar: function(){
  500. var toolbar = new Element("div",{
  501. styles : this.css.toolbar
  502. }).inject(this.container);
  503. if( this.toolbarTop ){
  504. this.toolbarBottom = toolbar;
  505. }else{
  506. this.toolbarTop = toolbar;
  507. }
  508. //if( this.parent.access.isSubjectPublisher( this.parent.sectionData ) ){
  509. if( this.app.sectionPermission.subjectPublishAble ){
  510. var createActionNode = new Element("div",{
  511. styles : this.css.toolbarActionNode,
  512. text: this.lp.createSubject
  513. }).inject(toolbar);
  514. createActionNode.addEvents(
  515. {
  516. "mouseover": function () {
  517. this.node.setStyles(this.obj.css.toolbarActionNode_over);
  518. }.bind({obj: this, node: createActionNode}),
  519. "mouseout": function () {
  520. this.node.setStyles(this.obj.css.toolbarActionNode);
  521. }.bind({obj: this, node: createActionNode}),
  522. "click": function () {
  523. if( this.app.access.isAnonymousDynamic() ){
  524. this.app.openLoginForm(
  525. function(){ this.createSubject(); }.bind(this)
  526. );
  527. }else{
  528. this.createSubject();
  529. }
  530. }.bind(this)
  531. }
  532. )
  533. }
  534. var fileterNode = new Element("div",{
  535. styles : this.css.fileterNode
  536. }).inject(toolbar);
  537. var pagingBar = new Element("div",{
  538. styles : this.css.fileterNode
  539. }).inject(toolbar);
  540. if( this.pagingBarTop ){
  541. this.pagingBarBottom = pagingBar;
  542. }else{
  543. this.pagingBarTop = pagingBar;
  544. }
  545. },
  546. loadView : function(){
  547. //this.resizeWindow();
  548. //this.resizeWindowFun = this.resizeWindow.bind(this)
  549. //this.app.addEvent("resize", this.resizeWindowFun );
  550. this.view = new MWF.xApplication.ForumSection.View( this.viewContainer, this.app, this, {
  551. templateUrl : this.parent.path+"listItem.json",
  552. pagingEnable : true,
  553. holdMouseDownStyles : true,
  554. onPostCreateViewBody : function(){
  555. this.app.fireEvent("postCreateViewBody");
  556. }.bind(this),
  557. pagingPar : {
  558. hasReturn : !this.app.naviMode,
  559. currentPage : this.options.viewPageNum,
  560. countPerPage : 30,
  561. onPostLoad : function( pagingBar ){
  562. if(pagingBar.nextPageNode){
  563. pagingBar.nextPageNode.inject( this.toolbarBottom, "before" );
  564. }
  565. }.bind(this),
  566. onPageReturn : function( pagingBar ){
  567. var appId = "Forum";
  568. if (this.app.desktop.apps[appId]){
  569. this.app.desktop.apps[appId].setCurrent();
  570. }else {
  571. this.app.desktop.openApplication(null, "Forum", { "appId": appId });
  572. }
  573. this.app.close();
  574. }.bind(this)
  575. }
  576. } );
  577. this.view.filterData = { sectionId : this.app.sectionData.id , withTopSubject : true };
  578. this.view.pagingContainerTop = this.pagingBarTop;
  579. this.view.pagingContainerBottom = this.pagingBarBottom;
  580. this.view.load();
  581. },
  582. reloadView : function() {
  583. if( this.viewPrime )this.viewPrime.destroy();
  584. this.viewContainer.setStyle("display","");
  585. this.viewContainerTop.setStyle("display","");
  586. this.viewContainerPrime.setStyle("display","none");
  587. //this.loadTopView();
  588. this.loadView();
  589. },
  590. loadPrimeView : function(){
  591. if( this.view )this.view.destroy();
  592. if( this.viewTop )this.viewTop.destroy();
  593. this.viewContainer.setStyle("display","none");
  594. this.viewContainerTop.setStyle("display","none");
  595. this.viewContainerPrime.setStyle("display","");
  596. this.viewPrime = new MWF.xApplication.ForumSection.PrimeView( this.viewContainerPrime, this.app, this, {
  597. templateUrl : this.parent.path+"listItemPrime.json",
  598. pagingEnable : true,
  599. holdMouseDownStyles : 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. });