Main.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. MWF.xApplication.Forum = MWF.xApplication.Forum || {};
  2. MWF.xApplication.ForumSearch = MWF.xApplication.ForumSearch || {};
  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.ForumSearch.options = {
  10. multitask: true,
  11. executable: true
  12. };
  13. MWF.xApplication.ForumSearch.Main = new Class({
  14. Extends: MWF.xApplication.Common.Main,
  15. Implements: [Options, Events],
  16. options: {
  17. "style": "default",
  18. "name": "ForumSearch",
  19. "icon": "icon.png",
  20. "width": "1230",
  21. "height": "700",
  22. "isResize": false,
  23. "isMax": true,
  24. "title": MWF.xApplication.ForumSearch.LP.title,
  25. "searchContent" : ""
  26. },
  27. onQueryLoad: function(){
  28. this.lp = MWF.xApplication.Forum.LP;
  29. },
  30. loadApplication: function(callback){
  31. this.userName = layout.desktop.session.user.distinguishedName;
  32. this.restActions = MWF.Actions.get("x_bbs_assemble_control"); //new MWF.xApplication.Forum.Actions.RestActions();
  33. this.path = "/x_component_ForumSearch/$Main/"+this.options.style+"/";
  34. this.createNode();
  35. this.loadApplicationContent();
  36. },
  37. reloadAllParents : function( sectionId ){
  38. this.restActions.getSection( sectionId, function( json ){
  39. var aid = "Forum";
  40. if (this.desktop.apps[aid]){
  41. this.desktop.apps[aid].reload();
  42. }
  43. aid = "ForumCategory"+json.data.forumId;
  44. if (this.desktop.apps[aid]){
  45. this.desktop.apps[aid].reload();
  46. }
  47. aid = "ForumSection"+sectionId;
  48. if (this.desktop.apps[aid]){
  49. this.desktop.apps[aid].reload();
  50. }
  51. }.bind(this) )
  52. },
  53. loadController: function(callback){
  54. this.access = new MWF.xApplication.Forum.Access( this.restActions, this.lp );
  55. if(callback)callback();
  56. },
  57. createNode: function(){
  58. this.content.setStyle("overflow", "hidden");
  59. this.node = new Element("div", {
  60. "styles": this.css.node
  61. }).inject(this.content);
  62. },
  63. clearContent: function(){
  64. this.node.empty();
  65. },
  66. loadApplicationContent: function(){
  67. if( !this.options.searchContent && this.status && this.status.searchContent ){
  68. this.options.searchContent = this.status.searchContent;
  69. }
  70. this.loadController(function(){
  71. this.access.login( function () {
  72. this.loadApplicationLayout();
  73. }.bind(this))
  74. }.bind(this))
  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.createMiddleNode();
  82. },
  83. search : function( searchContent ){
  84. this.options.searchContent = searchContent;
  85. this.middleNode.empty();
  86. this.topItemTitleNode.set("text", this.lp.search + ":" + searchContent );
  87. this._createMiddleNode();
  88. },
  89. createTopNode: function(){
  90. var node = new MWF.xApplication.Forum.TopNode(this.contentContainerNode, this, this, {
  91. type: this.options.style
  92. });
  93. node.load();
  94. var forumColor = this.lp.defaultForumColor;
  95. var topNode = this.topNode = new Element("div.topNode", {
  96. "styles": this.css.topNode
  97. }).inject(this.contentContainerNode);
  98. var topTitleMiddleNode = new Element("div.topTitleMiddleNode", {
  99. "styles": this.css.topTitleMiddleNode
  100. }).inject(topNode);
  101. var topItemTitleNode = new Element("div.topItemTitleNode", {
  102. "styles": this.css.topItemTitleNode,
  103. "text": this.lp.title
  104. }).inject(topTitleMiddleNode);
  105. topItemTitleNode.addEvent("click", function(){
  106. var appId = "Forum";
  107. if (this.desktop.apps[appId]){
  108. this.desktop.apps[appId].setCurrent();
  109. }else {
  110. this.desktop.openApplication(null, "Forum", { "appId": appId });
  111. }
  112. if( !this.inBrowser ){
  113. this.close();
  114. }
  115. //this.close();
  116. }.bind(this));
  117. var topItemSepNode = new Element("div.topItemSepNode", {
  118. "styles": this.css.topItemSepNode,
  119. "text" : ">"
  120. }).inject(topTitleMiddleNode);
  121. this.topItemTitleNode = new Element("div.topItemTitleNode", {
  122. "styles": this.css.topItemTitleLastNode,
  123. "text": this.lp.search + ":" + this.options.searchContent
  124. }).inject(topTitleMiddleNode);
  125. },
  126. createMiddleNode: function(){
  127. this.middleNode = new Element("div.middleNode", {
  128. "styles": this.css.middleNode
  129. }).inject(this.contentContainerNode);
  130. this._createMiddleNode();
  131. this.addEvent("resize", function () {
  132. this.setContentSize();
  133. }.bind(this));
  134. this.setContentSize();
  135. //MWF.require("MWF.widget.ScrollBar", function () {
  136. // new MWF.widget.ScrollBar(this.contentContainerNode, {
  137. // "indent": false,
  138. // "style": "xApp_TaskList",
  139. // "where": "before",
  140. // "distance": 30,
  141. // "friction": 4,
  142. // "axis": {"x": false, "y": true},
  143. // "onScroll": function (y) {
  144. // }
  145. // });
  146. //}.bind(this));
  147. },
  148. _createMiddleNode : function(){
  149. this.contentDiv = new Element("div.contentDiv",{"styles":this.css.contentDiv}).inject(this.middleNode);
  150. if( this.contentDiv )this.contentDiv.empty();
  151. if( this.explorer ){
  152. this.explorer.destroy();
  153. delete this.explorer;
  154. }
  155. if( this.options.searchContent ){
  156. this.explorer = new MWF.xApplication.ForumSearch.Explorer(this.contentDiv, this, this,{
  157. style:this.options.style,
  158. viewPageNum : ( this.status && this.status.viewPageNum ) ? this.status.viewPageNum : 1
  159. });
  160. this.explorer.load();
  161. }
  162. },
  163. setContentSize: function () {
  164. //var topSize = this.topNode ? this.topNode.getSize() : {"x": 0, "y": 0};
  165. var topSize = {"x": 0, "y": 0};
  166. var nodeSize = this.node.getSize();
  167. var pt = this.contentContainerNode.getStyle("padding-top").toFloat();
  168. var pb = this.contentContainerNode.getStyle("padding-bottom").toFloat();
  169. var height = nodeSize.y - topSize.y - pt - pb;
  170. this.contentContainerNode.setStyle("height", "" + height + "px");
  171. },
  172. recordStatus: function(){
  173. return {
  174. searchContent : this.options.searchContent,
  175. viewPageNum : this.explorer.view.getCurrentPageNum()
  176. };
  177. },
  178. getDateDiff: function (publishTime) {
  179. if(!publishTime)return "";
  180. var dateTimeStamp = Date.parse(publishTime.replace(/-/gi, "/"));
  181. var minute = 1000 * 60;
  182. var hour = minute * 60;
  183. var day = hour * 24;
  184. var halfamonth = day * 15;
  185. var month = day * 30;
  186. var year = month * 12;
  187. var now = new Date().getTime();
  188. var diffValue = now - dateTimeStamp;
  189. if (diffValue < 0) {
  190. //若日期不符则弹出窗口告之
  191. //alert("结束日期不能小于开始日期!");
  192. }
  193. var yesterday = new Date().decrement('day', 1);
  194. var beforYesterday = new Date().decrement('day', 2);
  195. var yearC = diffValue / year;
  196. var monthC = diffValue / month;
  197. var weekC = diffValue / (7 * day);
  198. var dayC = diffValue / day;
  199. var hourC = diffValue / hour;
  200. var minC = diffValue / minute;
  201. if (yesterday.getFullYear() == dateTimeStamp.getFullYear() && yesterday.getMonth() == dateTimeStamp.getMonth() && yesterday.getDate() == dateTimeStamp.getDate()) {
  202. result = "昨天 " + dateTimeStamp.getHours() + ":" + dateTimeStamp.getMinutes();
  203. } else if (beforYesterday.getFullYear() == dateTimeStamp.getFullYear() && beforYesterday.getMonth() == dateTimeStamp.getMonth() && beforYesterday.getDate() == dateTimeStamp.getDate()) {
  204. result = "前天 " + dateTimeStamp.getHours() + ":" + dateTimeStamp.getMinutes();
  205. } else if (yearC > 1) {
  206. result = dateTimeStamp.getFullYear() + "-" + (dateTimeStamp.getMonth() + 1) + "-" + dateTimeStamp.getDate();
  207. } else if (monthC >= 1) {
  208. //result= parseInt(monthC) + "个月前";
  209. // s.getFullYear()+"年";
  210. result = dateTimeStamp.getFullYear() + "-" + (dateTimeStamp.getMonth() + 1) + "-" + dateTimeStamp.getDate();
  211. } else if (weekC >= 1) {
  212. result = parseInt(weekC) + "周前";
  213. } else if (dayC >= 1) {
  214. result = parseInt(dayC) + "天前";
  215. } else if (hourC >= 1) {
  216. result = parseInt(hourC) + "小时前";
  217. } else if (minC >= 1) {
  218. result = parseInt(minC) + "分钟前";
  219. } else
  220. result = "刚刚发表";
  221. return result;
  222. },
  223. openPerson : function( userName ){
  224. if( !userName || userName == "" ){
  225. }else{
  226. var appId = "ForumPerson"+userName;
  227. if (this.desktop.apps[userName]){
  228. this.desktop.apps[userName].setCurrent();
  229. }else {
  230. this.desktop.openApplication(null, "ForumPerson", {
  231. "personName" : userName,
  232. "appId": appId
  233. });
  234. }
  235. }
  236. },
  237. createPersonNode : function( container, personName ){
  238. var persons = personName.split(",");
  239. persons.each( function(userName, i){
  240. var span = new Element("span", {
  241. "text" : userName,
  242. "styles" : this.css.person
  243. }).inject(container);
  244. span.addEvents( {
  245. mouseover : function(){ this.node.setStyles( this.obj.css.person_over )}.bind( {node:span, obj:this} ),
  246. mouseout : function(){ this.node.setStyles( this.obj.css.person )}.bind( {node:span, obj:this} ),
  247. click : function(){ this.obj.openPerson( this.userName ) }.bind( {userName:userName, obj:this} )
  248. });
  249. if( i != persons.length - 1 ){
  250. new Element("span", {
  251. "text" : ","
  252. }).inject(container);
  253. }
  254. }.bind(this))
  255. }
  256. });
  257. MWF.xApplication.ForumSearch.Explorer = new Class({
  258. Extends: MWF.widget.Common,
  259. Implements: [Options, Events],
  260. options: {
  261. "style": "default",
  262. "viewPageNum" : 1
  263. },
  264. initialize: function (container, app, parent, options) {
  265. this.setOptions( options );
  266. this.container = container;
  267. this.parent = parent;
  268. this.app = app;
  269. this.css = this.parent.css;
  270. this.lp = this.app.lp;
  271. },
  272. load: function () {
  273. this.container.empty();
  274. this.loadToolbar();
  275. this.viewContainer = Element("div",{
  276. "styles" : this.css.viewContainer
  277. }).inject(this.container);
  278. this.loadToolbar();
  279. this.loadView();
  280. },
  281. destroy : function(){
  282. if(this.resizeWindowFun)this.app.removeEvent("resize",this.resizeWindowFun);
  283. this.view.destroy();
  284. },
  285. loadToolbar: function(){
  286. var toolbar = new Element("div",{
  287. styles : this.css.toolbar
  288. }).inject(this.container);
  289. if( this.toolbarTop ){
  290. this.toolbarBottom = toolbar;
  291. }else{
  292. this.toolbarTop = toolbar;
  293. }
  294. var fileterNode = new Element("div",{
  295. styles : this.css.fileterNode
  296. }).inject(toolbar);
  297. var pagingBar = new Element("div",{
  298. styles : this.css.fileterNode
  299. }).inject(toolbar);
  300. if( this.pagingBarTop ){
  301. this.pagingBarBottom = pagingBar;
  302. }else{
  303. this.pagingBarTop = pagingBar;
  304. }
  305. },
  306. reloadView : function(){
  307. //this.view.filterData = { searchContent : this.app.options.searchContent };
  308. //this.view.reload();
  309. this.view.destroy();
  310. this.loadView();
  311. },
  312. loadView : function(){
  313. //this.resizeWindow();
  314. //this.resizeWindowFun = this.resizeWindow.bind(this)
  315. //this.app.addEvent("resize", this.resizeWindowFun );
  316. this.view = new MWF.xApplication.ForumSearch.View( this.viewContainer, this.app, this, {
  317. templateUrl : this.parent.path+"listItem.json",
  318. pagingEnable : true,
  319. pagingPar : {
  320. currentPage : this.options.viewPageNum,
  321. countPerPage : 30,
  322. onPostLoad : function( pagingBar ){
  323. if(pagingBar.nextPageNode){
  324. pagingBar.nextPageNode.inject( this.toolbarBottom, "before" );
  325. }
  326. }.bind(this),
  327. onPageReturn : function( pagingBar ){
  328. var appId = "Forum";
  329. if (this.app.desktop.apps[appId]){
  330. this.app.desktop.apps[appId].setCurrent();
  331. }else {
  332. this.app.desktop.openApplication(null, "Forum", { "appId": appId });
  333. }
  334. this.app.close();
  335. }.bind(this)
  336. }
  337. } );
  338. this.view.filterData = { searchContent : this.app.options.searchContent };
  339. this.view.pagingContainerTop = this.pagingBarTop;
  340. this.view.pagingContainerBottom = this.pagingBarBottom;
  341. this.view.load();
  342. },
  343. resizeWindow: function(){
  344. var size = this.app.content.getSize();
  345. this.viewContainer.setStyles({"height":(size.y-121)+"px"});
  346. },
  347. createSubject: function(){
  348. var _self = this;
  349. var appId = "ForumDocument";
  350. if (_self.app.desktop.apps[appId]){
  351. _self.app.desktop.apps[appId].setCurrent();
  352. }else {
  353. this.app.desktop.openApplication(null, "ForumDocument", {
  354. "sectionId": this.app.sectionData.id,
  355. "appId": appId,
  356. "isNew" : true,
  357. "isEdited" : true,
  358. "onPostPublish" : function(){
  359. this.view.reload();
  360. }.bind(this)
  361. });
  362. }
  363. },
  364. openPerson : function( userName ){
  365. var appId = "ForumPerson"+userName;
  366. if (this.desktop.apps[userName]){
  367. this.desktop.apps[userName].setCurrent();
  368. }else {
  369. this.desktop.openApplication(null, "ForumPerson", {
  370. "personName" : userName,
  371. "appId": appId
  372. });
  373. }
  374. },
  375. createPersonNode : function( container, personName ){
  376. var persons = personName.split(",");
  377. persons.each( function(userName, i){
  378. var span = new Element("span", {
  379. "text" : userName,
  380. "styles" : this.css.person
  381. }).inject(container);
  382. span.addEvents( {
  383. mouseover : function(){ this.node.setStyles( this.obj.css.person_over )}.bind( {node:span, obj:this} ),
  384. mouseout : function(){ this.node.setStyles( this.obj.css.person )}.bind( {node:span, obj:this} ),
  385. click : function(){ this.obj.openPerson( this.userName ) }.bind( {userName:userName, obj:this} )
  386. });
  387. if( i != persons.length - 1 ){
  388. new Element("span", {
  389. "text" : ","
  390. }).inject(container);
  391. }
  392. }.bind(this))
  393. }
  394. });
  395. MWF.xApplication.ForumSearch.View = new Class({
  396. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  397. _createDocument: function(data, index){
  398. return new MWF.xApplication.ForumSearch.Document(this.viewNode, data, this.explorer, this, null, index);
  399. },
  400. _getCurrentPageData: function(callback, count, pageNum){
  401. this.clearBody();
  402. if(!count)count=30;
  403. if(!pageNum)pageNum = 1;
  404. var filter = this.filterData || {};
  405. this.actions.listSubjectSearchPage( pageNum, count, filter, function(json){
  406. if( !json.data )json.data = [];
  407. if( !json.count )json.count=0;
  408. if( callback )callback(json);
  409. }.bind(this))
  410. },
  411. _removeDocument: function(documentData, all){
  412. this.actions.deleteSubject(documentData.id, function(json){
  413. this.reload();
  414. this.app.reloadAllParents( documentData.sectionId );
  415. this.app.notice(this.app.lp.deleteDocumentOK, "success");
  416. }.bind(this));
  417. },
  418. _create: function(){
  419. },
  420. _openDocument: function( documentData,index ){
  421. var appId = "ForumDocument"+documentData.id;
  422. if (this.app.desktop.apps[appId]){
  423. this.app.desktop.apps[appId].setCurrent();
  424. }else {
  425. this.app.desktop.openApplication(null, "ForumDocument", {
  426. "sectionId" : documentData.sectionId,
  427. "id" : documentData.id,
  428. "appId": appId,
  429. "isEdited" : false,
  430. "isNew" : false,
  431. "index" : index
  432. });
  433. }
  434. },
  435. _queryCreateViewNode: function(){
  436. },
  437. _postCreateViewNode: function( viewNode ){
  438. },
  439. _queryCreateViewHead:function(){
  440. },
  441. _postCreateViewHead: function( headNode ){
  442. }
  443. });
  444. MWF.xApplication.ForumSearch.Document = new Class({
  445. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  446. _queryCreateDocumentNode:function( itemData ){
  447. },
  448. _postCreateDocumentNode: function( itemNode, itemData ){
  449. },
  450. open: function (e) {
  451. this.view._openDocument(this.data, this.index);
  452. },
  453. edit : function(){
  454. var appId = "ForumDocument"+this.data.id;
  455. if (this.app.desktop.apps[appId]){
  456. this.app.desktop.apps[appId].setCurrent();
  457. }else {
  458. this.app.desktop.openApplication(null, "ForumDocument", {
  459. "sectionId" : this.data.sectionId,
  460. "id" : this.data.id,
  461. "appId": appId,
  462. "isEdited" : true,
  463. "isNew" : false,
  464. "index" : this.index
  465. });
  466. }
  467. },
  468. openSection : function( ev ){
  469. var data = this.data;
  470. var appId = "ForumSection"+ data.sectionId;
  471. if (this.app.desktop.apps[appId]){
  472. this.app.desktop.apps[appId].setCurrent();
  473. }else {
  474. this.app.desktop.openApplication(ev, "ForumSection", {
  475. "sectionId": data.sectionId,
  476. "appId": appId
  477. });
  478. }
  479. ev.stopPropagation();
  480. },
  481. isAdmin: function(){
  482. return this.app.access.isAdmin();
  483. }
  484. });