Main.js 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  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. onPostCreateViewBody : function(){
  554. this.app.fireEvent("postCreateViewBody");
  555. }.bind(this),
  556. pagingPar : {
  557. hasReturn : !this.app.naviMode,
  558. currentPage : this.options.viewPageNum,
  559. countPerPage : 30,
  560. onPostLoad : function( pagingBar ){
  561. if(pagingBar.nextPageNode){
  562. pagingBar.nextPageNode.inject( this.toolbarBottom, "before" );
  563. }
  564. }.bind(this),
  565. onPageReturn : function( pagingBar ){
  566. var appId = "Forum";
  567. if (this.app.desktop.apps[appId]){
  568. this.app.desktop.apps[appId].setCurrent();
  569. }else {
  570. this.app.desktop.openApplication(null, "Forum", { "appId": appId });
  571. }
  572. this.app.close();
  573. }.bind(this)
  574. }
  575. } );
  576. this.view.filterData = { sectionId : this.app.sectionData.id , withTopSubject : true };
  577. this.view.pagingContainerTop = this.pagingBarTop;
  578. this.view.pagingContainerBottom = this.pagingBarBottom;
  579. this.view.load();
  580. },
  581. reloadView : function() {
  582. if( this.viewPrime )this.viewPrime.destroy();
  583. this.viewContainer.setStyle("display","");
  584. this.viewContainerTop.setStyle("display","");
  585. this.viewContainerPrime.setStyle("display","none");
  586. //this.loadTopView();
  587. this.loadView();
  588. },
  589. loadPrimeView : function(){
  590. if( this.view )this.view.destroy();
  591. if( this.viewTop )this.viewTop.destroy();
  592. this.viewContainer.setStyle("display","none");
  593. this.viewContainerTop.setStyle("display","none");
  594. this.viewContainerPrime.setStyle("display","");
  595. this.viewPrime = new MWF.xApplication.ForumSection.PrimeView( this.viewContainerPrime, this.app, this, {
  596. templateUrl : this.parent.path+"listItemPrime.json",
  597. pagingEnable : true,
  598. pagingPar : {
  599. hasReturn : !this.app.naviMode,
  600. currentPage : 1,
  601. countPerPage : 30,
  602. onPostLoad : function( pagingBar ){
  603. if(pagingBar.nextPageNode){
  604. pagingBar.nextPageNode.inject( this.toolbarBottom, "before" );
  605. }
  606. }.bind(this),
  607. onPageReturn : function( pagingBar ){
  608. var appId = "Forum";
  609. if (this.app.desktop.apps[appId]){
  610. this.app.desktop.apps[appId].setCurrent();
  611. }else {
  612. this.app.desktop.openApplication(null, "Forum", { "appId": appId });
  613. }
  614. this.app.close();
  615. }.bind(this)
  616. }
  617. } );
  618. this.viewPrime.filterData = { sectionId : this.app.sectionData.id };
  619. this.viewPrime.pagingContainerTop = this.pagingBarTop;
  620. this.viewPrime.pagingContainerBottom = this.pagingBarBottom;
  621. this.viewPrime.load();
  622. },
  623. resizeWindow: function(){
  624. var size = this.app.content.getSize();
  625. this.viewContainer.setStyles({"height":(size.y-121)+"px"});
  626. },
  627. createSubject: function(){
  628. var _self = this;
  629. var appId = "ForumDocument"+this.app.sectionData.id;
  630. if (_self.app.desktop.apps[appId]){
  631. _self.app.desktop.apps[appId].setCurrent();
  632. }else {
  633. this.app.desktop.openApplication(null, "ForumDocument", {
  634. "sectionId": this.app.sectionData.id,
  635. "appId": appId,
  636. "isNew" : true,
  637. "isEdited" : true,
  638. "onPostPublish" : function(){
  639. //this.view.reload();
  640. }.bind(this)
  641. });
  642. }
  643. }
  644. });
  645. MWF.xApplication.ForumSection.TopView = new Class({
  646. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  647. _createDocument: function(data, index){
  648. return new MWF.xApplication.ForumSection.TopDocument(this.viewNode, data, this.explorer, this, null, index);
  649. },
  650. _getCurrentPageData: function(callback, count){
  651. if (!count)count = 30;
  652. //var id = (this.items.length) ? this.items[this.items.length - 1].data.id : "(0)";
  653. var filter = this.filterData || {};
  654. //page, count, filterData, success,failure, async
  655. if( !this.page ){
  656. this.page = 1;
  657. }else{
  658. this.page ++;
  659. }
  660. this.actions.listTopSubject( this.app.sectionData.id, function (json) {
  661. if( !json.data )json.data = [];
  662. if (callback)callback(json);
  663. }.bind(this))
  664. },
  665. _removeDocument: function(documentData, all){
  666. this.actions.deleteSubject(documentData.id, function(json){
  667. this.reload();
  668. this.app.reloadAllParents();
  669. this.app.notice(this.app.lp.deleteDocumentOK, "success");
  670. }.bind(this));
  671. },
  672. _create: function(){
  673. },
  674. _openDocument: function( documentData,index ){
  675. var appId = "ForumDocument"+documentData.id;
  676. if (this.app.desktop.apps[appId]){
  677. this.app.desktop.apps[appId].setCurrent();
  678. }else {
  679. this.app.desktop.openApplication(null, "ForumDocument", {
  680. "sectionId" : documentData.sectionId,
  681. "id" : documentData.id,
  682. "appId": appId,
  683. "isEdited" : false,
  684. "isNew" : false,
  685. "index" : index
  686. });
  687. }
  688. },
  689. _queryCreateViewNode: function(){
  690. },
  691. _postCreateViewNode: function( viewNode ){
  692. },
  693. _queryCreateViewHead:function(){
  694. },
  695. _postCreateViewHead: function( headNode ){
  696. //this.allSubjectNode = headNode.getElements("[lable='allSubject']")[0];
  697. var primeNode = headNode.getElements("[lable='prime']")[0];
  698. primeNode.addEvent( "click", function(){
  699. this.explorer.loadPrimeView();
  700. }.bind(this))
  701. }
  702. });
  703. MWF.xApplication.ForumSection.TopDocument = new Class({
  704. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  705. _queryCreateDocumentNode:function( itemData ){
  706. },
  707. _postCreateDocumentNode: function( itemNode, itemData ){
  708. },
  709. open: function (e) {
  710. this.view._openDocument(this.data, this.index);
  711. },
  712. edit : function(){
  713. var appId = "ForumDocument"+this.data.id;
  714. if (this.app.desktop.apps[appId]){
  715. this.app.desktop.apps[appId].setCurrent();
  716. }else {
  717. this.app.desktop.openApplication(null, "ForumDocument", {
  718. "sectionId" : this.data.sectionId,
  719. "id" : this.data.id,
  720. "appId": appId,
  721. "isEdited" : true,
  722. "isNew" : false,
  723. "index" : this.index
  724. });
  725. }
  726. }
  727. });
  728. MWF.xApplication.ForumSection.View = new Class({
  729. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  730. refreshNewSubject : function(){
  731. if (this.refreshTr)this.refreshTr.destroy();
  732. if( this.refreshInterval ){
  733. clearInterval( this.refreshInterval );
  734. }
  735. this.refreshInterval = setInterval( function(){
  736. this.actions.listSubjectFilterPage( 1, 1, this.filterData || {}, function(json){
  737. if( !json.count )json.count=0;
  738. var count = this.laterRefreshCount || this.dataCount;
  739. if( json.count > count ) {
  740. this.laterRefreshCount = json.count;
  741. this.createRefreshTr( json.count );
  742. }
  743. }.bind(this))
  744. }.bind(this), 10 * 60 * 1000 )
  745. },
  746. createRefreshTr : function( newCount ){
  747. if (this.refreshTr)this.refreshTr.destroy();
  748. var refreshTr = this.refreshTr = new Element( "tr.refreshTrNode" , {
  749. styles : this.css.refreshTrNode
  750. }).inject( this.headNode, "after" );
  751. var td = this.refreshTd = new Element( "td.refreshTdNode", {
  752. width : "60%",
  753. styles : this.css.refreshTdNode
  754. }).inject( refreshTr );
  755. var refreshNode = new Element("div" , {
  756. styles : this.css.refreshNode,
  757. text : this.lp.newSubjectPublishedText.replace( "{count}", newCount - this.dataCount )
  758. }).inject(td);
  759. refreshNode.addEvent("click", function(){
  760. this.gotoPage(1)
  761. }.bind(this));
  762. var td = new Element( "td.refreshTdNode", {
  763. styles : this.css.refreshTdNode,
  764. width : "12%"
  765. }).inject( refreshTr );
  766. var td = new Element( "td.refreshTdNode", {
  767. styles : this.css.refreshTdNode,
  768. width : "7%"
  769. }).inject( refreshTr );
  770. var td = new Element( "td.refreshTdNode", {
  771. styles : this.css.refreshTdNode,
  772. width : "7%"
  773. }).inject( refreshTr );
  774. var td = new Element( "td.refreshTdNode", {
  775. styles : this.css.refreshTdNode,
  776. width : "14%"
  777. }).inject( refreshTr )
  778. },
  779. _createDocument: function(data, index){
  780. return new MWF.xApplication.ForumSection.Document(this.viewNode, data, this.explorer, this, null, index);
  781. },
  782. _getCurrentPageData: function(callback, count, pageNum){
  783. this.clearBody();
  784. if(!count)count=30;
  785. if(!pageNum)pageNum = 1;
  786. //if( pageNum == 1 ){
  787. // this.explorer.viewContainerTop.setStyle("display","block");
  788. // this.headNode.setStyle("display","none");
  789. //}else{
  790. // this.explorer.viewContainerTop.setStyle("display","none");
  791. // this.headNode.setStyle("display","");
  792. //}
  793. if( this.topSepTr )this.topSepTr.destroy();
  794. var filter = this.filterData || {};
  795. //filter.withTopSubject = false;
  796. this.actions.listSubjectFilterPage( pageNum, count, filter, function(json){
  797. if( !json.data )json.data = [];
  798. if( !json.count )json.count=0;
  799. this.refreshNewSubject();
  800. if( callback )callback(json);
  801. }.bind(this))
  802. },
  803. _removeDocument: function(documentData, all){
  804. this.actions.deleteSubject(documentData.id, function(json){
  805. this.reload();
  806. this.app.reloadAllParents();
  807. this.app.notice(this.app.lp.deleteDocumentOK, "success");
  808. }.bind(this));
  809. },
  810. _create: function(){
  811. },
  812. _openDocument: function( documentData,index ){
  813. var appId = "ForumDocument"+documentData.id;
  814. if (this.app.desktop.apps[appId]){
  815. this.app.desktop.apps[appId].setCurrent();
  816. }else {
  817. this.app.desktop.openApplication(null, "ForumDocument", {
  818. "sectionId" : documentData.sectionId,
  819. "id" : documentData.id,
  820. "appId": appId,
  821. "isEdited" : false,
  822. "isNew" : false,
  823. "index" : index
  824. });
  825. }
  826. },
  827. _queryCreateViewNode: function(){
  828. },
  829. _postCreateViewNode: function( viewNode ){
  830. },
  831. _queryCreateViewHead:function(){
  832. },
  833. _postCreateViewHead: function( headNode ){
  834. var primeNode = headNode.getElements("[lable='prime']")[0];
  835. primeNode.addEvent( "click", function(){
  836. this.explorer.loadPrimeView();
  837. }.bind(this))
  838. }
  839. });
  840. MWF.xApplication.ForumSection.Document = new Class({
  841. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  842. _queryCreateDocumentNode:function( itemData ){
  843. },
  844. _postCreateDocumentNode: function( itemNode, itemData ){
  845. //置顶帖和一般帖之间添加分割线
  846. if( this.index != 1 && !itemData.isTopSubject ){
  847. var prev = this.view.items[this.index-1];
  848. if( prev && prev.data.isTopSubject ){
  849. var tr = this.view.topSepTr = new Element( "tr" , {styles: this.css.documentNode_empty } ).inject( itemNode, "before" );
  850. new Element( "td", {colspan:5}).inject( tr )
  851. }
  852. }
  853. },
  854. open: function (e) {
  855. this.view._openDocument(this.data, this.index);
  856. },
  857. edit : function(){
  858. var appId = "ForumDocument"+this.data.id;
  859. if (this.app.desktop.apps[appId]){
  860. this.app.desktop.apps[appId].setCurrent();
  861. }else {
  862. this.app.desktop.openApplication(null, "ForumDocument", {
  863. "sectionId" : this.data.sectionId,
  864. "id" : this.data.id,
  865. "appId": appId,
  866. "isEdited" : true,
  867. "isNew" : false,
  868. "index" : this.index
  869. });
  870. }
  871. }
  872. });
  873. MWF.xApplication.ForumSection.PrimeView = new Class({
  874. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  875. _createDocument: function(data, index){
  876. return new MWF.xApplication.ForumSection.PrimeDocument(this.viewNode, data, this.explorer, this, null, index);
  877. },
  878. _getCurrentPageData: function(callback, count, pageNum){
  879. this.clearBody();
  880. if(!count)count=30;
  881. if(!pageNum)pageNum = 1;
  882. var filter = this.filterData || {};
  883. this.actions.listCreamSubjectFilterPage( pageNum, count, filter, function(json){
  884. if( !json.data )json.data = [];
  885. if( !json.count )json.count=0;
  886. if( callback )callback(json);
  887. }.bind(this))
  888. },
  889. _removeDocument: function(documentData, all){
  890. this.actions.deleteSubject(documentData.id, function(json){
  891. this.reload();
  892. this.app.reloadAllParents();
  893. this.app.notice(this.app.lp.deleteDocumentOK, "success");
  894. }.bind(this));
  895. },
  896. _create: function(){
  897. },
  898. _openDocument: function( documentData,index ){
  899. var appId = "ForumDocument"+documentData.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" : documentData.sectionId,
  905. "id" : documentData.id,
  906. "appId": appId,
  907. "isEdited" : false,
  908. "isNew" : false,
  909. "index" : index
  910. });
  911. }
  912. },
  913. _queryCreateViewNode: function(){
  914. },
  915. _postCreateViewNode: function( viewNode ){
  916. },
  917. _queryCreateViewHead:function(){
  918. },
  919. _postCreateViewHead: function( headNode ){
  920. var allSubjectNode = headNode.getElements("[lable='allSubject']")[0];
  921. allSubjectNode.addEvent( "click", function(){
  922. this.explorer.reloadView();
  923. }.bind(this))
  924. }
  925. });
  926. MWF.xApplication.ForumSection.PrimeDocument = new Class({
  927. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  928. _queryCreateDocumentNode:function( itemData ){
  929. },
  930. _postCreateDocumentNode: function( itemNode, itemData ){
  931. },
  932. open: function (e) {
  933. this.view._openDocument(this.data, this.index);
  934. },
  935. edit : function(){
  936. var appId = "ForumDocument"+this.data.id;
  937. if (this.app.desktop.apps[appId]){
  938. this.app.desktop.apps[appId].setCurrent();
  939. }else {
  940. this.app.desktop.openApplication(null, "ForumDocument", {
  941. "sectionId" : this.data.sectionId,
  942. "id" : this.data.id,
  943. "appId": appId,
  944. "isEdited" : true,
  945. "isNew" : false,
  946. "index" : this.index
  947. });
  948. }
  949. }
  950. });