Main.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. MWF.xApplication.Forum = MWF.xApplication.Forum || {};
  2. MWF.require("MWF.widget.O2Identity", null, false);
  3. //MWF.xDesktop.requireApp("Forum", "Actions.RestActions", null, false);
  4. MWF.xDesktop.requireApp("Forum", "Access", null, false);
  5. MWF.xDesktop.requireApp("Forum", "ColumnTemplate", null, false);
  6. MWF.xDesktop.requireApp("Forum", "TopNode", null, false);
  7. MWF.xDesktop.requireApp("Template", "Explorer", null, false);
  8. MWF.xApplication.Forum.options = {
  9. multitask: false,
  10. executable: true
  11. };
  12. MWF.xApplication.Forum.Main = new Class({
  13. Extends: MWF.xApplication.Common.Main,
  14. Implements: [Options, Events],
  15. options: {
  16. "style": "default",
  17. "name": "Forum",
  18. "icon": "icon.png",
  19. "width": "1230",
  20. "height": "700",
  21. "isResize": true,
  22. "isMax": true,
  23. "title": MWF.xApplication.Forum.LP.title
  24. },
  25. onQueryLoad: function () {
  26. this.lp = MWF.xApplication.Forum.LP;
  27. },
  28. loadApplication: function (callback) {
  29. this.userName = layout.desktop.session.user.distinguishedName;
  30. this.restActions = MWF.Actions.get("x_bbs_assemble_control"); //new MWF.xApplication.Forum.Actions.RestActions();
  31. this.path = "/x_component_Forum/$Main/" + this.options.style + "/";
  32. this.createNode();
  33. this.loadApplicationContent();
  34. },
  35. loadController: function (callback) {
  36. this.access = new MWF.xApplication.Forum.Access( this.restActions, this.lp );
  37. if (callback)callback();
  38. },
  39. reload : function(){
  40. this.clearContent();
  41. if( this.explorer ){
  42. this.openSetting( this.explorer.currentNaviItem.retrieve("index") )
  43. }else{
  44. this.loadApplicationLayout();
  45. }
  46. },
  47. isAdmin : function(){
  48. return this.access.isAdmin();
  49. },
  50. createNode: function () {
  51. this.content.setStyle("overflow", "hidden");
  52. this.node = new Element("div", {
  53. "styles": this.css.node
  54. }).inject(this.content);
  55. },
  56. loadApplicationContent: function () {
  57. this.loadController(function () {
  58. this.access.login( function(){
  59. if( this.status && this.status.setting ){
  60. this.openSetting( this.status.index )
  61. }else{
  62. this.loadApplicationLayout();
  63. }
  64. }.bind(this))
  65. }.bind(this))
  66. },
  67. loaNavi: function (callback) {
  68. this.naviNode = new Element("div.naviNode", {
  69. "styles": this.css.naviNode
  70. }).inject(this.node);
  71. var curNavi = {"id": ""};
  72. if (this.status) {
  73. curNavi.id = this.status.id;
  74. }
  75. this.navi = new MWF.xApplication.Forum.Navi(this, this.naviNode, curNavi);
  76. },
  77. loadApplicationLayout: function () {
  78. this.contentContainerNode = new Element("div.contentContainerNode", {
  79. "styles": this.css.contentContainerNode
  80. }).inject(this.node);
  81. this.createTopNode();
  82. this.createContainerNode();
  83. },
  84. createTopNode: function(){
  85. var node = new MWF.xApplication.Forum.TopNode(this.contentContainerNode, this, this, {
  86. type: this.options.style,
  87. settingEnable : true
  88. });
  89. node.load();
  90. },
  91. createContainerNode: function () {
  92. this.createContent();
  93. },
  94. createContent: function () {
  95. this.middleNode = new Element("div.middleNode", {
  96. "styles": this.css.middleNode
  97. }).inject(this.contentContainerNode);
  98. this.setContentSizeFun = this.setContentSize.bind(this);
  99. this.addEvent("resize", this.setContentSizeFun );
  100. this.setContentSize();
  101. //MWF.require("MWF.widget.ScrollBar", function () {
  102. // this.scrollBar = new MWF.widget.ScrollBar(this.contentContainerNode, {
  103. // "indent": false,
  104. // "style": "xApp_TaskList",
  105. // "where": "before",
  106. // "distance": 30,
  107. // "friction": 4,
  108. // "axis": {"x": false, "y": true},
  109. // "onScroll": function (y) {
  110. // }
  111. // });
  112. //}.bind(this));
  113. this.contentNode = new Element("div.contentNode", {
  114. "styles": this.css.contentNode
  115. }).inject(this.middleNode);
  116. this.createRecommand();
  117. this.restActions.listCategoryAll(function (json) {
  118. if( !json.data )json.data = [];
  119. json.data.each(function (d, idx) {
  120. if(d.forumStatus != this.lp.invalid ){
  121. this._createCategory(d, idx);
  122. }
  123. }.bind(this))
  124. }.bind(this))
  125. },
  126. setContentSize: function () {
  127. //var topSize = this.topNode ? this.topNode.getSize() : {"x": 0, "y": 0};
  128. var topSize = {"x": 0, "y": 0};
  129. var nodeSize = this.node.getSize();
  130. var pt = this.contentContainerNode.getStyle("padding-top").toFloat();
  131. var pb = this.contentContainerNode.getStyle("padding-bottom").toFloat();
  132. var height = nodeSize.y - topSize.y - pt - pb;
  133. this.contentContainerNode.setStyle("height", "" + height + "px");
  134. },
  135. createRecommand: function () {
  136. var recommandNode = new Element("div.recommandNode", {
  137. "styles": this.css.recommandNode
  138. }).inject(this.contentNode);
  139. var recommandTopNode = new Element("div.recommandTopNode", {
  140. "styles": this.css.recommandTopNode
  141. }).inject(recommandNode);
  142. //recommandTopNode.setStyle( "border-bottom" , "1px solid "+this.lp.defaultForumColor );
  143. var recommandTopTitleNode = new Element("div.recommandTopTitleNode", {
  144. "styles": this.css.recommandTopTitleNode,
  145. "text": this.lp.recommandSubject
  146. }).inject(recommandTopNode);
  147. //recommandTopTitleNode.setStyle( "background-color" , this.lp.defaultForumColor );
  148. //categoryTopTitleNode.addEvents({
  149. // click : function(el){ this.obj.openCategory( this.data ) }.bind({ obj : this, data : d })
  150. //})
  151. //var categoryTopRightNode = new Element("div.categoryTopRightNode", {
  152. // "styles": this.css.categoryTopRightNode,
  153. // "text": this.lp.recommandSubject
  154. //}).inject(categoryTopNode);
  155. var view = new MWF.xApplication.Forum.Main.RecommandView(recommandNode, this, this, {
  156. templateUrl: this.path + "listItemRecommand.json"
  157. }, {
  158. lp: this.lp
  159. });
  160. view.load();
  161. },
  162. _createCategory: function (d, idx) {
  163. var categoryNode = new Element("div.categoryNode", {
  164. "styles": this.css.categoryNode
  165. }).inject(this.contentNode);
  166. var categoryTopNode = new Element("div.categoryTopNode", {
  167. "styles": this.css.categoryTopNode
  168. }).inject(categoryNode);
  169. //categoryTopNode.setStyle( "border-bottom" , "1px solid "+ d.forumColor || this.lp.defaultForumColor );
  170. var categoryTopTitleNode = new Element("div.categoryTopTitleNode", {
  171. "styles": this.css.categoryTopTitleNode,
  172. "text": d.forumName
  173. }).inject(categoryTopNode);
  174. categoryTopTitleNode.addEvents({
  175. click : function(el){ this.obj.openCategory( this.data ) }.bind({ obj : this, data : d })
  176. });
  177. categoryTopTitleNode.setStyle( "color" , d.forumColor || this.lp.defaultForumColor );
  178. var categoryTopRightNode = new Element("div.categoryTopRightNode", {
  179. "styles": this.css.categoryTopRightNode2
  180. }).inject(categoryTopNode);
  181. this.createPersonNode(categoryTopRightNode,d.forumManagerName );
  182. new Element("div.categoryTopRightNode", {
  183. "styles": this.css.categoryTopRightNode,
  184. "text": this.lp.categoryManager + ":" //+ d.forumManagerName
  185. }).inject(categoryTopNode);
  186. var view = new MWF.xApplication.Forum.ColumnTemplate(categoryNode, this, this, {
  187. type: d.indexListStyle || "type_1_0",
  188. categoryId: d.id
  189. });
  190. view.load();
  191. //if (d.indexListStyle == "经典") {
  192. // var view = new MWF.xApplication.Forum.Main.ListView(categoryNode, this, this, {
  193. // templateUrl: this.path + "listItemList.json",
  194. // categoryId: d.id
  195. // }, {
  196. // lp: this.lp
  197. // });
  198. // view.load();
  199. //} else if (d.indexListStyle == "图片矩形") {
  200. // var view = new MWF.xApplication.Forum.Main.ImageView(categoryNode, this, this, {
  201. // templateUrl: this.path + "listItemImage.json",
  202. // categoryId: d.id
  203. // }, {
  204. // lp: this.lp
  205. // });
  206. // view.load();
  207. //} else {
  208. // var view = new MWF.xApplication.Forum.Main.TileView(categoryNode, this, this, {
  209. // templateUrl: this.path + "listItemTile.json",
  210. // categoryId: d.id
  211. // }, {
  212. // lp: this.lp
  213. // });
  214. // view.load();
  215. //}
  216. },
  217. clearContent: function () {
  218. if (this.explorer)this.explorer.destroy();
  219. this.explorer = null;
  220. if(this.setContentSizeFun)this.removeEvent("resize", this.setContentSizeFun );
  221. if(this.scrollBar && this.scrollBar.scrollVAreaNode)this.scrollBar.scrollVAreaNode.destroy();
  222. if( this.scrollBar )delete this.scrollBar;
  223. if (this.contentContainerNode) {
  224. this.contentContainerNode.destroy();
  225. //this.middleNode.destroy();
  226. //this.contentNode.destroy();
  227. }
  228. },
  229. openCategory : function( d ){
  230. var appId = "ForumCategory"+ d.id;
  231. if (this.desktop.apps[appId]){
  232. this.desktop.apps[appId].setCurrent();
  233. }else {
  234. this.desktop.openApplication(null, "ForumCategory", {
  235. "categoryId": d.id,
  236. "appId": appId
  237. });
  238. }
  239. },
  240. openView : function(){
  241. },
  242. openNavi: function () {
  243. MWF.xDesktop.requireApp("Forum", "Navi", null, false);
  244. this.clearContent();
  245. this.contentContainerNode = new Element("div.contentContainerNode", {
  246. "styles": this.css.contentContainerNode
  247. }).inject(this.node);
  248. this.createTopNode();
  249. this.middleNode = new Element("div.middleNode", {
  250. "styles": this.css.middleNode
  251. }).inject(this.contentContainerNode);
  252. this.contentNode = new Element("div.contentNode", {
  253. "styles": this.css.contentNode
  254. }).inject(this.middleNode);
  255. this.navi = new MWF.xApplication.Forum.Navi(this, this.contentNode, {});
  256. this.navi.load();
  257. },
  258. openSetting: function ( index ) {
  259. MWF.xDesktop.requireApp("Forum", "Setting", null, false);
  260. this.clearContent();
  261. this.contentContainerNode = new Element("div.contentContainerNode", {
  262. "styles": this.css.contentContainerNode
  263. }).inject(this.node);
  264. this.createTopNode();
  265. this.middleNode = new Element("div.middleNode", {
  266. "styles": this.css.middleNode
  267. }).inject(this.contentContainerNode);
  268. this.contentNode = new Element("div.contentNode", {
  269. "styles": this.css.contentNode
  270. }).inject(this.middleNode);
  271. this.explorer = new MWF.xApplication.Forum.Setting(this.contentNode, this, this.restActions, {"isAdmin": this.isAdmin() , "index" : (index || 0) });
  272. this.explorer.load();
  273. },
  274. recordStatus: function () {
  275. var status = {};
  276. if( this.explorer ){
  277. status = {
  278. setting : true,
  279. index : this.explorer.currentNaviItem.retrieve("index")
  280. };
  281. }
  282. return status;
  283. },
  284. openPerson : function( userName ){
  285. var appId = "ForumPerson"+userName;
  286. if (this.desktop.apps[appId]){
  287. this.desktop.apps[appId].setCurrent();
  288. }else {
  289. this.desktop.openApplication(null, "ForumPerson", {
  290. "personName" : userName,
  291. "appId": appId
  292. });
  293. }
  294. },
  295. createPersonNode : function( container, personName ){
  296. var persons = personName.split(",");
  297. persons.each( function(userName, i){
  298. var span = new Element("span", {
  299. "text" : userName.split('@')[0],
  300. "styles" : this.css.person
  301. }).inject(container);
  302. span.addEvents( {
  303. mouseover : function(){ this.node.setStyles( this.obj.css.person_over )}.bind( {node:span, obj:this} ),
  304. mouseout : function(){ this.node.setStyles( this.obj.css.person )}.bind( {node:span, obj:this} ),
  305. click : function(){ this.obj.openPerson( this.userName ) }.bind( {userName:userName, obj:this} )
  306. });
  307. if( i != persons.length - 1 ){
  308. new Element("span", {
  309. "text" : "、"
  310. }).inject(container);
  311. }
  312. }.bind(this))
  313. }
  314. });
  315. MWF.xApplication.Forum.Main.RecommandView = new Class({
  316. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  317. _createDocument: function (data, index) {
  318. return new MWF.xApplication.Forum.Main.RecommandDocument(this.viewNode, data, this.explorer, this, null, index);
  319. },
  320. _getCurrentPageData: function (callback, count) {
  321. if (!count)count = 12;
  322. this.actions.listRecommendedSubject(count, function (json) {
  323. if( !json.data )json.data = [];
  324. if (callback)callback(json);
  325. }.bind(this))
  326. },
  327. _removeDocument: function (documentData, all) {
  328. //this.actions.deleteSchedule(documentData.id, function(json){
  329. // this.reload();
  330. // this.app.notice(this.app.lp.deleteDocumentOK, "success");
  331. //}.bind(this));
  332. },
  333. _create: function () {
  334. },
  335. _openDocument: function (documentData) {
  336. },
  337. _queryCreateViewNode: function () {
  338. },
  339. _postCreateViewNode: function (viewNode) {
  340. },
  341. _queryCreateViewHead: function () {
  342. },
  343. _postCreateViewHead: function (headNode) {
  344. }
  345. });
  346. MWF.xApplication.Forum.Main.RecommandDocument = new Class({
  347. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  348. mouseoverDocument: function () {
  349. //this.node.getElements("[styles='documentItemTitleNode']").setStyles(this.css["documentItemTitleNode_over"]);
  350. //this.node.getElements("[styles='documentItemIconNode']").setStyles(this.css["documentItemIconNode_over"]);
  351. //this.node.getElements("[styles='documentItemStatNode']").setStyles(this.css["documentItemStatNode_over"]);
  352. },
  353. mouseoutDocument: function () {
  354. //this.node.getElements("[styles='documentItemTitleNode']").setStyles(this.css["documentItemTitleNode"]);
  355. //this.node.getElements("[styles='documentItemIconNode']").setStyles(this.css["documentItemIconNode"]);
  356. //this.node.getElements("[styles='documentItemStatNode']").setStyles(this.css["documentItemStatNode"]);
  357. },
  358. _queryCreateDocumentNode: function (itemData) {
  359. },
  360. _postCreateDocumentNode: function (itemNode, itemData) {
  361. },
  362. open: function( ){
  363. var data = this.data;
  364. var appId = "ForumDocument"+data.id;
  365. if (this.app.desktop.apps[appId]){
  366. this.app.desktop.apps[appId].setCurrent();
  367. }else {
  368. this.app.desktop.openApplication(null, "ForumDocument", {
  369. "sectionId" : data.sectionId,
  370. "id" : data.id,
  371. "appId": appId,
  372. "isEdited" : false,
  373. "isNew" : false
  374. });
  375. }
  376. },
  377. openSection : function( el ){
  378. var data = this.data;
  379. var appId = "ForumSection"+ data.sectionId;
  380. if (this.app.desktop.apps[appId]){
  381. this.app.desktop.apps[appId].setCurrent();
  382. }else {
  383. this.app.desktop.openApplication(el, "ForumSection", {
  384. "sectionId": data.sectionId,
  385. "appId": appId
  386. });
  387. }
  388. }
  389. });
  390. var getDateDiff = function (publishTime) {
  391. if(!publishTime)return "";
  392. var dateTimeStamp = Date.parse(publishTime.replace(/-/gi, "/"));
  393. var minute = 1000 * 60;
  394. var hour = minute * 60;
  395. var day = hour * 24;
  396. var halfamonth = day * 15;
  397. var month = day * 30;
  398. var year = month * 12;
  399. var now = new Date().getTime();
  400. var diffValue = now - dateTimeStamp;
  401. if (diffValue < 0) {
  402. //若日期不符则弹出窗口告之
  403. //alert("结束日期不能小于开始日期!");
  404. }
  405. var yesterday = new Date().decrement('day', 1);
  406. var beforYesterday = new Date().decrement('day', 2);
  407. var yearC = diffValue / year;
  408. var monthC = diffValue / month;
  409. var weekC = diffValue / (7 * day);
  410. var dayC = diffValue / day;
  411. var hourC = diffValue / hour;
  412. var minC = diffValue / minute;
  413. if (yesterday.getFullYear() == dateTimeStamp.getFullYear() && yesterday.getMonth() == dateTimeStamp.getMonth() && yesterday.getDate() == dateTimeStamp.getDate()) {
  414. result = "昨天 " + dateTimeStamp.getHours() + ":" + dateTimeStamp.getMinutes();
  415. } else if (beforYesterday.getFullYear() == dateTimeStamp.getFullYear() && beforYesterday.getMonth() == dateTimeStamp.getMonth() && beforYesterday.getDate() == dateTimeStamp.getDate()) {
  416. result = "前天 " + dateTimeStamp.getHours() + ":" + dateTimeStamp.getMinutes();
  417. } else if (yearC > 1) {
  418. result = dateTimeStamp.getFullYear() + "-" + (dateTimeStamp.getMonth() + 1) + "-" + dateTimeStamp.getDate();
  419. } else if (monthC >= 1) {
  420. //result= parseInt(monthC) + "个月前";
  421. // s.getFullYear()+"年";
  422. result = dateTimeStamp.getFullYear() + "-" + (dateTimeStamp.getMonth() + 1) + "-" + dateTimeStamp.getDate();
  423. } else if (weekC >= 1) {
  424. result = parseInt(weekC) + "周前";
  425. } else if (dayC >= 1) {
  426. result = parseInt(dayC) + "天前";
  427. } else if (hourC >= 1) {
  428. result = parseInt(hourC) + "小时前";
  429. } else if (minC >= 1) {
  430. result = parseInt(minC) + "分钟前";
  431. } else
  432. result = "刚刚发表";
  433. return result;
  434. };