Main.js 17 KB

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