Main.js 31 KB

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