Main.js 17 KB

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