Main.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. MWF.xApplication.Forum = MWF.xApplication.Forum || {};
  2. MWF.require("MWF.widget.Identity", 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("Template", "Explorer", null, false);
  7. MWF.xApplication.Forum.options = {
  8. multitask: false,
  9. executable: true
  10. }
  11. MWF.xApplication.Forum.Main = new Class({
  12. Extends: MWF.xApplication.Common.Main,
  13. Implements: [Options, Events],
  14. options: {
  15. "style": "default",
  16. "name": "Forum",
  17. "icon": "icon.png",
  18. "width": "1230",
  19. "height": "700",
  20. "isResize": true,
  21. "isMax": true,
  22. "title": MWF.xApplication.Forum.LP.title
  23. },
  24. onQueryLoad: function () {
  25. this.lp = MWF.xApplication.Forum.LP;
  26. },
  27. loadApplication: function (callback) {
  28. this.userName = layout.desktop.session.user.name;
  29. this.restActions = new MWF.xApplication.Forum.Actions.RestActions();
  30. this.path = "/x_component_Forum/$Main/" + this.options.style + "/";
  31. this.createNode();
  32. this.loadApplicationContent();
  33. },
  34. loadController: function (callback) {
  35. this.access = new MWF.xApplication.Forum.Access( this.restActions, this.lp );
  36. if (callback)callback();
  37. },
  38. reload : function(){
  39. this.clearContent();
  40. if( this.explorer ){
  41. this.openSetting( this.explorer.currentNaviItem.retrieve("index") )
  42. }else{
  43. this.loadApplicationLayout();
  44. }
  45. },
  46. isAdmin : function(){
  47. return this.access.isAdmin();
  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. loadApplicationContent: function () {
  56. this.loadController(function () {
  57. this.access.login( function(){
  58. if( this.status && this.status.setting ){
  59. this.openSetting( this.status.index )
  60. }else{
  61. this.loadApplicationLayout();
  62. }
  63. }.bind(this))
  64. }.bind(this))
  65. },
  66. loaNavi: function (callback) {
  67. this.naviNode = new Element("div.naviNode", {
  68. "styles": this.css.naviNode
  69. }).inject(this.node);
  70. var curNavi = {"id": ""};
  71. if (this.status) {
  72. curNavi.id = this.status.id;
  73. }
  74. this.navi = new MWF.xApplication.Forum.Navi(this, this.naviNode, curNavi);
  75. },
  76. loadApplicationLayout: function () {
  77. this.contentContainerNode = new Element("div.contentContainerNode", {
  78. "styles": this.css.contentContainerNode
  79. }).inject(this.node);
  80. this.createTopNode();
  81. this.createContainerNode();
  82. },
  83. createTopNode: function () {
  84. this.topContainerNode = new Element("div.topContainerNode", {
  85. "styles": this.css.topContainerNode
  86. }).inject(this.contentContainerNode);
  87. this.topNode = new Element("div.topNode", {
  88. "styles": this.css.topNode
  89. }).inject(this.topContainerNode);
  90. this.topMainPageNode = new Element("div.topMainPageNode",{
  91. "styles" : { "cursor" : "pointer" }
  92. }).inject(this.topNode);
  93. this.topMainPageNode.addEvent("click", function(){
  94. this.openMainPage();
  95. }.bind(this));
  96. //this.getSystemSetting( "BBS_LOGO_NAME", function( data ){
  97. this.restActions.getBBSName( function( json ){
  98. var data = json.data;
  99. if( data.configValue && data.configValue!="" && data.configValue!="企业论坛" ){
  100. this.topTextNode = new Element("div.topTextNode", {
  101. "styles": this.css.topTextNode,
  102. "text": data.configValue
  103. }).inject(this.topMainPageNode)
  104. }else{
  105. this.topIconNode = new Element("div", {
  106. "styles": this.css.topIconNode
  107. }).inject(this.topMainPageNode)
  108. }
  109. }.bind(this), null, false );
  110. //}.bind(this), false )
  111. this.topContentNode = new Element("div", {
  112. "styles": this.css.topContentNode
  113. }).inject(this.topNode);
  114. if( this.access.isAnonymous() ){
  115. if( this.access.signUpMode != "disable" ){
  116. this.signupNode = new Element("div", {
  117. "styles": this.css.signupNode
  118. }).inject(this.topContentNode);
  119. //this.signupIconNode = new Element("div", {
  120. // "styles": this.css.signupIconNode
  121. //}).inject(this.signupNode);
  122. this.signupTextNode = new Element("div", {
  123. "styles": this.css.signupTextNode,
  124. "text": this.lp.signup
  125. }).inject(this.signupNode);
  126. this.signupNode.addEvent("click", function(){ this.openSignUpForm( ) }.bind(this))
  127. }
  128. new Element("div",{
  129. "styles" : this.css.topSepNode,
  130. "text" : "/"
  131. }).inject(this.topContentNode);
  132. this.loginNode = new Element("div", {
  133. "styles": this.css.loginNode
  134. }).inject(this.topContentNode);
  135. //this.loginIconNode = new Element("div", {
  136. // "styles": this.css.loginIconNode
  137. //}).inject(this.loginNode);
  138. this.loginTextNode = new Element("div", {
  139. "styles": this.css.loginTextNode,
  140. "text": this.lp.login
  141. }).inject(this.loginNode);
  142. this.loginNode.addEvent("click", function(){ this.openLoginForm( ) }.bind(this))
  143. }else{
  144. if( this.inBrowser ){
  145. this.logoutNode = new Element("div", {
  146. "styles": this.css.logoutNode
  147. }).inject(this.topContentNode);
  148. //this.logoutIconNode = new Element("div", {
  149. // "styles": this.css.logoutIconNode
  150. //}).inject(this.logoutNode);
  151. this.logoutTextNode = new Element("div", {
  152. "styles": this.css.logoutTextNode,
  153. "text": this.lp.logout
  154. }).inject(this.logoutNode);
  155. this.logoutNode.addEvent("click", function(){ this.logout( ) }.bind(this))
  156. new Element("div",{
  157. "styles" : this.css.topSepNode,
  158. "text" : "/"
  159. }).inject(this.topContentNode);
  160. }
  161. this.settingNode = new Element("div", {
  162. "styles": this.css.settingNode
  163. }).inject(this.topContentNode);
  164. //this.settingIconNode = new Element("div", {
  165. // "styles": this.css.settingIconNode
  166. //}).inject(this.settingNode);
  167. this.settingTextNode = new Element("div", {
  168. "styles": this.css.settingTextNode,
  169. "text": this.lp.setting
  170. }).inject(this.settingNode);
  171. this.settingNode.addEvent("click", function(){ this.openSetting( ) }.bind(this));
  172. new Element("div",{
  173. "styles" : this.css.topSepNode,
  174. "text" : "/"
  175. }).inject(this.topContentNode);
  176. this.personNode = new Element("div", {
  177. "styles": this.css.personNode
  178. }).inject(this.topContentNode);
  179. //this.personIconNode = new Element("div", {
  180. // "styles": this.css.personIconNode
  181. //}).inject(this.personNode);
  182. this.personTextNode = new Element("div", {
  183. "styles": this.css.personTextNode,
  184. "text": this.lp.personCenter
  185. }).inject(this.personNode);
  186. this.personNode.addEvent("click", function(){ this.openPerson(this.userName ) }.bind(this))
  187. }
  188. this.searchDiv = new Element("div.searchDiv",{
  189. "styles" : this.css.searchDiv
  190. }).inject(this.topNode);
  191. this.searchInput = new Element("input.searchInput",{
  192. "styles" : this.css.searchInput,
  193. "value" : this.lp.searchKey,
  194. "title" : this.lp.searchTitle
  195. }).inject(this.searchDiv);
  196. var _self = this;
  197. this.searchInput.addEvents({
  198. "focus": function(){
  199. if (this.value==_self.lp.searchKey) this.set("value", "");
  200. },
  201. "blur": function(){if (!this.value) this.set("value", _self.lp.searchKey);},
  202. "keydown": function(e){
  203. if (e.code==13){
  204. this.search();
  205. e.preventDefault();
  206. }
  207. }.bind(this)
  208. });
  209. this.searchAction = new Element("div.searchAction",{
  210. "styles" : this.css.searchAction
  211. }).inject(this.searchDiv);
  212. this.searchAction.addEvents({
  213. "click": function(){ this.search(); }.bind(this),
  214. "mouseover": function(e){
  215. this.searchAction.setStyles( this.css.searchAction_over2 );
  216. e.stopPropagation();
  217. }.bind(this),
  218. "mouseout": function(){ this.searchAction.setStyles( this.css.searchAction ) }.bind(this)
  219. });
  220. this.searchDiv.addEvents( {
  221. "mouseover" : function(){
  222. this.searchInput.setStyles( this.css.searchInput_over );
  223. this.searchAction.setStyles( this.css.searchAction_over )
  224. }.bind(this),
  225. "mouseout" : function(){
  226. this.searchInput.setStyles( this.css.searchInput );
  227. this.searchAction.setStyles( this.css.searchAction )
  228. }.bind(this)
  229. });
  230. this._createTopContent();
  231. },
  232. _createTopContent: function () {
  233. },
  234. getSystemSetting : function( code, callback, async ){
  235. this.restActions.getSystemSettingByCode( {configCode : code }, function(json) {
  236. if (callback)callback(json.data);
  237. }.bind(this), null, async )
  238. },
  239. search : function(){
  240. var val = this.searchInput.get("value");
  241. if( val == "" || val == this.lp.searchKey ){
  242. this.notice( this.lp.noSearchContentNotice, "error" );
  243. return;
  244. }
  245. var appId = "ForumSearch";
  246. if (this.desktop.apps[appId] && !this.inBrowser){
  247. this.desktop.apps[appId].close();
  248. }
  249. this.desktop.openApplication(null, "ForumSearch", {
  250. "appId": appId,
  251. "searchContent" : val
  252. });
  253. },
  254. createContainerNode: function () {
  255. this.createContent();
  256. },
  257. createContent: function () {
  258. this.middleNode = new Element("div.middleNode", {
  259. "styles": this.css.middleNode
  260. }).inject(this.contentContainerNode);
  261. this.setContentSizeFun = this.setContentSize.bind(this);
  262. this.addEvent("resize", this.setContentSizeFun );
  263. this.setContentSize();
  264. //MWF.require("MWF.widget.ScrollBar", function () {
  265. // this.scrollBar = new MWF.widget.ScrollBar(this.contentContainerNode, {
  266. // "indent": false,
  267. // "style": "xApp_TaskList",
  268. // "where": "before",
  269. // "distance": 30,
  270. // "friction": 4,
  271. // "axis": {"x": false, "y": true},
  272. // "onScroll": function (y) {
  273. // }
  274. // });
  275. //}.bind(this));
  276. this.contentNode = new Element("div.contentNode", {
  277. "styles": this.css.contentNode
  278. }).inject(this.middleNode);
  279. this.createRecommand();
  280. this.restActions.listCategoryAll(function (json) {
  281. if( !json.data )json.data = [];
  282. json.data.each(function (d, idx) {
  283. if(d.forumStatus != this.lp.invalid ){
  284. this._createCategory(d, idx);
  285. }
  286. }.bind(this))
  287. }.bind(this))
  288. },
  289. setContentSize: function () {
  290. //var topSize = this.topNode ? this.topNode.getSize() : {"x": 0, "y": 0};
  291. var topSize = {"x": 0, "y": 0};
  292. var nodeSize = this.node.getSize();
  293. var pt = this.contentContainerNode.getStyle("padding-top").toFloat();
  294. var pb = this.contentContainerNode.getStyle("padding-bottom").toFloat();
  295. var height = nodeSize.y - topSize.y - pt - pb;
  296. this.contentContainerNode.setStyle("height", "" + height + "px");
  297. },
  298. createRecommand: function () {
  299. var recommandNode = new Element("div.recommandNode", {
  300. "styles": this.css.recommandNode
  301. }).inject(this.contentNode);
  302. var recommandTopNode = new Element("div.recommandTopNode", {
  303. "styles": this.css.recommandTopNode
  304. }).inject(recommandNode);
  305. //recommandTopNode.setStyle( "border-bottom" , "1px solid "+this.lp.defaultForumColor );
  306. var recommandTopTitleNode = new Element("div.recommandTopTitleNode", {
  307. "styles": this.css.recommandTopTitleNode,
  308. "text": this.lp.recommandSubject
  309. }).inject(recommandTopNode);
  310. //recommandTopTitleNode.setStyle( "background-color" , this.lp.defaultForumColor );
  311. //categoryTopTitleNode.addEvents({
  312. // click : function(el){ this.obj.openCategory( this.data ) }.bind({ obj : this, data : d })
  313. //})
  314. //var categoryTopRightNode = new Element("div.categoryTopRightNode", {
  315. // "styles": this.css.categoryTopRightNode,
  316. // "text": this.lp.recommandSubject
  317. //}).inject(categoryTopNode);
  318. var view = new MWF.xApplication.Forum.Main.RecommandView(recommandNode, this, this, {
  319. templateUrl: this.path + "listItemRecommand.json"
  320. }, {
  321. lp: this.lp
  322. });
  323. view.load();
  324. },
  325. _createCategory: function (d, idx) {
  326. var categoryNode = new Element("div.categoryNode", {
  327. "styles": this.css.categoryNode
  328. }).inject(this.contentNode);
  329. var categoryTopNode = new Element("div.categoryTopNode", {
  330. "styles": this.css.categoryTopNode
  331. }).inject(categoryNode);
  332. //categoryTopNode.setStyle( "border-bottom" , "1px solid "+ d.forumColor || this.lp.defaultForumColor );
  333. var categoryTopTitleNode = new Element("div.categoryTopTitleNode", {
  334. "styles": this.css.categoryTopTitleNode,
  335. "text": d.forumName
  336. }).inject(categoryTopNode);
  337. categoryTopTitleNode.addEvents({
  338. click : function(el){ this.obj.openCategory( this.data ) }.bind({ obj : this, data : d })
  339. });
  340. categoryTopTitleNode.setStyle( "color" , d.forumColor || this.lp.defaultForumColor );
  341. var categoryTopRightNode = new Element("div.categoryTopRightNode", {
  342. "styles": this.css.categoryTopRightNode2
  343. }).inject(categoryTopNode);
  344. this.createPersonNode(categoryTopRightNode,d.forumManagerName );
  345. new Element("div.categoryTopRightNode", {
  346. "styles": this.css.categoryTopRightNode,
  347. "text": this.lp.categoryManager + ":" //+ d.forumManagerName
  348. }).inject(categoryTopNode);
  349. var view = new MWF.xApplication.Forum.ColumnTemplate(categoryNode, this, this, {
  350. type: d.indexListStyle || "type_1_0",
  351. categoryId: d.id
  352. });
  353. view.load();
  354. //if (d.indexListStyle == "经典") {
  355. // var view = new MWF.xApplication.Forum.Main.ListView(categoryNode, this, this, {
  356. // templateUrl: this.path + "listItemList.json",
  357. // categoryId: d.id
  358. // }, {
  359. // lp: this.lp
  360. // });
  361. // view.load();
  362. //} else if (d.indexListStyle == "图片矩形") {
  363. // var view = new MWF.xApplication.Forum.Main.ImageView(categoryNode, this, this, {
  364. // templateUrl: this.path + "listItemImage.json",
  365. // categoryId: d.id
  366. // }, {
  367. // lp: this.lp
  368. // });
  369. // view.load();
  370. //} else {
  371. // var view = new MWF.xApplication.Forum.Main.TileView(categoryNode, this, this, {
  372. // templateUrl: this.path + "listItemTile.json",
  373. // categoryId: d.id
  374. // }, {
  375. // lp: this.lp
  376. // });
  377. // view.load();
  378. //}
  379. },
  380. clearContent: function () {
  381. if (this.explorer)this.explorer.destroy();
  382. this.explorer = null;
  383. if(this.setContentSizeFun)this.removeEvent("resize", this.setContentSizeFun );
  384. if(this.scrollBar && this.scrollBar.scrollVAreaNode)this.scrollBar.scrollVAreaNode.destroy();
  385. if( this.scrollBar )delete this.scrollBar;
  386. if (this.contentContainerNode) {
  387. this.contentContainerNode.destroy();
  388. //this.middleNode.destroy();
  389. //this.contentNode.destroy();
  390. }
  391. },
  392. openMainPage : function(){
  393. this.clearContent();
  394. //this.createCategory();
  395. this.loadApplicationLayout();
  396. },
  397. openCategory : function( d ){
  398. var appId = "ForumCategory"+ d.id;
  399. if (this.desktop.apps[appId]){
  400. this.desktop.apps[appId].setCurrent();
  401. }else {
  402. this.desktop.openApplication(null, "ForumCategory", {
  403. "categoryId": d.id,
  404. "appId": appId
  405. });
  406. }
  407. },
  408. openLoginForm : function(){
  409. //MWF.xDesktop.requireApp("Forum", "Login", null, false);
  410. //var login = new MWF.xApplication.Forum.Login(this, {
  411. // onPostOk : function(){
  412. // window.location.reload();
  413. // }
  414. //});
  415. //login.openLoginForm();
  416. MWF.require("MWF.xDesktop.Authentication", null, false);
  417. var authentication = new MWF.xDesktop.Authentication({
  418. style : "application",
  419. onPostOk : function(){
  420. window.location.reload();
  421. }
  422. },this);
  423. authentication.openLoginForm();
  424. },
  425. openSignUpForm : function(){
  426. //MWF.xDesktop.requireApp("Forum", "Login", null, false);
  427. //var login = new MWF.xApplication.Forum.Login(this, {});
  428. //login.openSignUpForm();
  429. MWF.require("MWF.xDesktop.Authentication", null, false);
  430. var authentication = new MWF.xDesktop.Authentication( {
  431. style : "application",
  432. onPostOk : function(){
  433. }
  434. }, this);
  435. authentication.openSignUpForm();
  436. },
  437. openSetting: function ( index ) {
  438. MWF.xDesktop.requireApp("Forum", "Setting", null, false);
  439. this.clearContent();
  440. this.contentContainerNode = new Element("div.contentContainerNode", {
  441. "styles": this.css.contentContainerNode
  442. }).inject(this.node);
  443. this.createTopNode();
  444. this.middleNode = new Element("div.middleNode", {
  445. "styles": this.css.middleNode
  446. }).inject(this.contentContainerNode);
  447. this.contentNode = new Element("div.contentNode", {
  448. "styles": this.css.contentNode
  449. }).inject(this.middleNode);
  450. this.explorer = new MWF.xApplication.Forum.Setting(this.contentNode, this, this.restActions, {"isAdmin": this.isAdmin() , "index" : (index || 0) });
  451. this.explorer.load();
  452. },
  453. recordStatus: function () {
  454. var status = {};
  455. if( this.explorer ){
  456. status = {
  457. setting : true,
  458. index : this.explorer.currentNaviItem.retrieve("index")
  459. };
  460. }
  461. return status;
  462. },
  463. openPerson : function( userName ){
  464. var appId = "ForumPerson"+userName;
  465. if (this.desktop.apps[appId]){
  466. this.desktop.apps[appId].setCurrent();
  467. }else {
  468. this.desktop.openApplication(null, "ForumPerson", {
  469. "personName" : userName,
  470. "appId": appId
  471. });
  472. }
  473. },
  474. createPersonNode : function( container, personName ){
  475. var persons = personName.split(",");
  476. persons.each( function(userName, i){
  477. var span = new Element("span", {
  478. "text" : userName,
  479. "styles" : this.css.person
  480. }).inject(container);
  481. span.addEvents( {
  482. mouseover : function(){ this.node.setStyles( this.obj.css.person_over )}.bind( {node:span, obj:this} ),
  483. mouseout : function(){ this.node.setStyles( this.obj.css.person )}.bind( {node:span, obj:this} ),
  484. click : function(){ this.obj.openPerson( this.userName ) }.bind( {userName:userName, obj:this} )
  485. })
  486. if( i != persons.length - 1 ){
  487. new Element("span", {
  488. "text" : "、"
  489. }).inject(container);
  490. }
  491. }.bind(this))
  492. },
  493. logout: function(){
  494. this.restActions.logout( function(){
  495. layout.desktop.session.user.name = "anonymous";
  496. this.clearContent();
  497. this.loadApplicationContent();
  498. this.openLoginForm();
  499. }.bind(this))
  500. }
  501. });
  502. MWF.xApplication.Forum.Main.RecommandView = new Class({
  503. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  504. _createDocument: function (data, index) {
  505. return new MWF.xApplication.Forum.Main.RecommandDocument(this.viewNode, data, this.explorer, this, null, index);
  506. },
  507. _getCurrentPageData: function (callback, count) {
  508. if (!count)count = 12;
  509. this.actions.listRecommendedSubject(count, function (json) {
  510. if( !json.data )json.data = [];
  511. if (callback)callback(json);
  512. }.bind(this))
  513. },
  514. _removeDocument: function (documentData, all) {
  515. //this.actions.deleteSchedule(documentData.id, function(json){
  516. // this.reload();
  517. // this.app.notice(this.app.lp.deleteDocumentOK, "success");
  518. //}.bind(this));
  519. },
  520. _create: function () {
  521. },
  522. _openDocument: function (documentData) {
  523. },
  524. _queryCreateViewNode: function () {
  525. },
  526. _postCreateViewNode: function (viewNode) {
  527. },
  528. _queryCreateViewHead: function () {
  529. },
  530. _postCreateViewHead: function (headNode) {
  531. }
  532. });
  533. MWF.xApplication.Forum.Main.RecommandDocument = new Class({
  534. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  535. mouseoverDocument: function () {
  536. //this.node.getElements("[styles='documentItemTitleNode']").setStyles(this.css["documentItemTitleNode_over"]);
  537. //this.node.getElements("[styles='documentItemIconNode']").setStyles(this.css["documentItemIconNode_over"]);
  538. //this.node.getElements("[styles='documentItemStatNode']").setStyles(this.css["documentItemStatNode_over"]);
  539. },
  540. mouseoutDocument: function () {
  541. //this.node.getElements("[styles='documentItemTitleNode']").setStyles(this.css["documentItemTitleNode"]);
  542. //this.node.getElements("[styles='documentItemIconNode']").setStyles(this.css["documentItemIconNode"]);
  543. //this.node.getElements("[styles='documentItemStatNode']").setStyles(this.css["documentItemStatNode"]);
  544. },
  545. _queryCreateDocumentNode: function (itemData) {
  546. },
  547. _postCreateDocumentNode: function (itemNode, itemData) {
  548. },
  549. open: function( ){
  550. var data = this.data;
  551. var appId = "ForumDocument"+data.id;
  552. if (this.app.desktop.apps[appId]){
  553. this.app.desktop.apps[appId].setCurrent();
  554. }else {
  555. this.app.desktop.openApplication(null, "ForumDocument", {
  556. "sectionId" : data.sectionId,
  557. "id" : data.id,
  558. "appId": appId,
  559. "isEdited" : false,
  560. "isNew" : false
  561. });
  562. }
  563. },
  564. openSection : function( el ){
  565. var data = this.data;
  566. var appId = "ForumSection"+ data.sectionId;
  567. if (this.app.desktop.apps[appId]){
  568. this.app.desktop.apps[appId].setCurrent();
  569. }else {
  570. this.app.desktop.openApplication(el, "ForumSection", {
  571. "sectionId": data.sectionId,
  572. "appId": appId
  573. });
  574. }
  575. }
  576. });
  577. var getDateDiff = function (publishTime) {
  578. if(!publishTime)return "";
  579. var dateTimeStamp = Date.parse(publishTime.replace(/-/gi, "/"));
  580. var minute = 1000 * 60;
  581. var hour = minute * 60
  582. var day = hour * 24;
  583. var halfamonth = day * 15;
  584. var month = day * 30;
  585. var year = month * 12;
  586. var now = new Date().getTime();
  587. var diffValue = now - dateTimeStamp;
  588. if (diffValue < 0) {
  589. //若日期不符则弹出窗口告之
  590. //alert("结束日期不能小于开始日期!");
  591. }
  592. var yesterday = new Date().decrement('day', 1);
  593. var beforYesterday = new Date().decrement('day', 2);
  594. var yearC = diffValue / year;
  595. var monthC = diffValue / month;
  596. var weekC = diffValue / (7 * day);
  597. var dayC = diffValue / day;
  598. var hourC = diffValue / hour;
  599. var minC = diffValue / minute;
  600. if (yesterday.getFullYear() == dateTimeStamp.getFullYear() && yesterday.getMonth() == dateTimeStamp.getMonth() && yesterday.getDate() == dateTimeStamp.getDate()) {
  601. result = "昨天 " + dateTimeStamp.getHours() + ":" + dateTimeStamp.getMinutes();
  602. } else if (beforYesterday.getFullYear() == dateTimeStamp.getFullYear() && beforYesterday.getMonth() == dateTimeStamp.getMonth() && beforYesterday.getDate() == dateTimeStamp.getDate()) {
  603. result = "前天 " + dateTimeStamp.getHours() + ":" + dateTimeStamp.getMinutes();
  604. } else if (yearC > 1) {
  605. result = dateTimeStamp.getFullYear() + "年" + (dateTimeStamp.getMonth() + 1) + "月" + dateTimeStamp.getDate() + "日";
  606. } else if (monthC >= 1) {
  607. //result= parseInt(monthC) + "个月前";
  608. // s.getFullYear()+"年";
  609. result = (dateTimeStamp.getMonth() + 1) + "月" + dateTimeStamp.getDate() + "日";
  610. } else if (weekC >= 1) {
  611. result = parseInt(weekC) + "周前";
  612. } else if (dayC >= 1) {
  613. result = parseInt(dayC) + "天前";
  614. } else if (hourC >= 1) {
  615. result = parseInt(hourC) + "小时前";
  616. } else if (minC >= 1) {
  617. result = parseInt(minC) + "分钟前";
  618. } else
  619. result = "刚刚发表";
  620. return result;
  621. };