Main.js 13 KB

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