Main.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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]){
  43. this.desktop.apps[aid].reload();
  44. }
  45. aid = "ForumCategory"+json.data.forumId;
  46. if (this.desktop.apps[aid]){
  47. this.desktop.apps[aid].reload();
  48. }
  49. aid = "ForumSection"+sectionId;
  50. if (this.desktop.apps[aid]){
  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 ){
  181. if( !userName || userName == "" ){
  182. }else{
  183. var appId = "ForumPerson"+userName;
  184. if (this.desktop.apps[userName]){
  185. this.desktop.apps[userName].setCurrent();
  186. }else {
  187. this.desktop.openApplication(null, "ForumPerson", {
  188. "personName" : userName,
  189. "appId": appId
  190. });
  191. }
  192. }
  193. },
  194. createPersonNode : function( container, personName ){
  195. var persons = personName.split(",");
  196. persons.each( function(userName, i){
  197. var span = new Element("span", {
  198. "text" : userName,
  199. "styles" : this.css.person
  200. }).inject(container);
  201. span.addEvents( {
  202. mouseover : function(){ this.node.setStyles( this.obj.css.person_over )}.bind( {node:span, obj:this} ),
  203. mouseout : function(){ this.node.setStyles( this.obj.css.person )}.bind( {node:span, obj:this} ),
  204. click : function(){ this.obj.openPerson( this.userName ) }.bind( {userName:userName, obj:this} )
  205. });
  206. if( i != persons.length - 1 ){
  207. new Element("span", {
  208. "text" : ","
  209. }).inject(container);
  210. }
  211. }.bind(this))
  212. }
  213. });
  214. MWF.xApplication.ForumSearch.Explorer = new Class({
  215. Extends: MWF.widget.Common,
  216. Implements: [Options, Events],
  217. options: {
  218. "style": "default",
  219. "viewPageNum" : 1
  220. },
  221. initialize: function (container, app, parent, options) {
  222. this.setOptions( options );
  223. this.container = container;
  224. this.parent = parent;
  225. this.app = app;
  226. this.css = this.parent.css;
  227. this.lp = this.app.lp;
  228. },
  229. load: function () {
  230. this.container.empty();
  231. this.loadToolbar();
  232. this.viewContainer = Element("div",{
  233. "styles" : this.css.viewContainer
  234. }).inject(this.container);
  235. this.loadToolbar();
  236. this.loadView();
  237. },
  238. destroy : function(){
  239. if(this.resizeWindowFun)this.app.removeEvent("resize",this.resizeWindowFun);
  240. this.view.destroy();
  241. },
  242. loadToolbar: function(){
  243. var toolbar = new Element("div",{
  244. styles : this.css.toolbar
  245. }).inject(this.container);
  246. if( this.toolbarTop ){
  247. this.toolbarBottom = toolbar;
  248. }else{
  249. this.toolbarTop = toolbar;
  250. }
  251. var fileterNode = new Element("div",{
  252. styles : this.css.fileterNode
  253. }).inject(toolbar);
  254. var pagingBar = new Element("div",{
  255. styles : this.css.fileterNode
  256. }).inject(toolbar);
  257. if( this.pagingBarTop ){
  258. this.pagingBarBottom = pagingBar;
  259. }else{
  260. this.pagingBarTop = pagingBar;
  261. }
  262. },
  263. reloadView : function(){
  264. //this.view.filterData = { searchContent : this.app.options.searchContent };
  265. //this.view.reload();
  266. this.view.destroy();
  267. this.loadView();
  268. },
  269. loadView : function(){
  270. //this.resizeWindow();
  271. //this.resizeWindowFun = this.resizeWindow.bind(this)
  272. //this.app.addEvent("resize", this.resizeWindowFun );
  273. this.view = new MWF.xApplication.ForumSearch.View( this.viewContainer, this.app, this, {
  274. templateUrl : this.parent.path+"listItem.json",
  275. pagingEnable : true,
  276. pagingPar : {
  277. currentPage : this.options.viewPageNum,
  278. countPerPage : 30,
  279. onPostLoad : function( pagingBar ){
  280. if(pagingBar.nextPageNode){
  281. pagingBar.nextPageNode.inject( this.toolbarBottom, "before" );
  282. }
  283. }.bind(this),
  284. onPageReturn : function( pagingBar ){
  285. var appId = "Forum";
  286. if (this.app.desktop.apps[appId]){
  287. this.app.desktop.apps[appId].setCurrent();
  288. }else {
  289. this.app.desktop.openApplication(null, "Forum", { "appId": appId });
  290. }
  291. this.app.close();
  292. }.bind(this)
  293. }
  294. } );
  295. this.view.filterData = { searchContent : this.app.options.searchContent };
  296. this.view.pagingContainerTop = this.pagingBarTop;
  297. this.view.pagingContainerBottom = this.pagingBarBottom;
  298. this.view.load();
  299. },
  300. resizeWindow: function(){
  301. var size = this.app.content.getSize();
  302. this.viewContainer.setStyles({"height":(size.y-121)+"px"});
  303. },
  304. createSubject: function(){
  305. var _self = this;
  306. var appId = "ForumDocument";
  307. if (_self.app.desktop.apps[appId]){
  308. _self.app.desktop.apps[appId].setCurrent();
  309. }else {
  310. this.app.desktop.openApplication(null, "ForumDocument", {
  311. "sectionId": this.app.sectionData.id,
  312. "appId": appId,
  313. "isNew" : true,
  314. "isEdited" : true,
  315. "onPostPublish" : function(){
  316. this.view.reload();
  317. }.bind(this)
  318. });
  319. }
  320. },
  321. openPerson : function( userName ){
  322. var appId = "ForumPerson"+userName;
  323. if (this.desktop.apps[userName]){
  324. this.desktop.apps[userName].setCurrent();
  325. }else {
  326. this.desktop.openApplication(null, "ForumPerson", {
  327. "personName" : userName,
  328. "appId": appId
  329. });
  330. }
  331. },
  332. createPersonNode : function( container, personName ){
  333. var persons = personName.split(",");
  334. persons.each( function(userName, i){
  335. var span = new Element("span", {
  336. "text" : userName,
  337. "styles" : this.css.person
  338. }).inject(container);
  339. span.addEvents( {
  340. mouseover : function(){ this.node.setStyles( this.obj.css.person_over )}.bind( {node:span, obj:this} ),
  341. mouseout : function(){ this.node.setStyles( this.obj.css.person )}.bind( {node:span, obj:this} ),
  342. click : function(){ this.obj.openPerson( this.userName ) }.bind( {userName:userName, obj:this} )
  343. });
  344. if( i != persons.length - 1 ){
  345. new Element("span", {
  346. "text" : ","
  347. }).inject(container);
  348. }
  349. }.bind(this))
  350. }
  351. });
  352. MWF.xApplication.ForumSearch.View = new Class({
  353. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  354. _createDocument: function(data, index){
  355. return new MWF.xApplication.ForumSearch.Document(this.viewNode, data, this.explorer, this, null, index);
  356. },
  357. _getCurrentPageData: function(callback, count, pageNum){
  358. this.clearBody();
  359. if(!count)count=30;
  360. if(!pageNum)pageNum = 1;
  361. var filter = this.filterData || {};
  362. this.actions.listSubjectSearchPage( pageNum, count, filter, function(json){
  363. if( !json.data )json.data = [];
  364. if( !json.count )json.count=0;
  365. if( callback )callback(json);
  366. }.bind(this))
  367. },
  368. _removeDocument: function(documentData, all){
  369. this.actions.deleteSubject(documentData.id, function(json){
  370. this.reload();
  371. this.app.reloadAllParents( documentData.sectionId );
  372. this.app.notice(this.app.lp.deleteDocumentOK, "success");
  373. }.bind(this));
  374. },
  375. _create: function(){
  376. },
  377. _openDocument: function( documentData,index ){
  378. var appId = "ForumDocument"+documentData.id;
  379. if (this.app.desktop.apps[appId]){
  380. this.app.desktop.apps[appId].setCurrent();
  381. }else {
  382. this.app.desktop.openApplication(null, "ForumDocument", {
  383. "sectionId" : documentData.sectionId,
  384. "id" : documentData.id,
  385. "appId": appId,
  386. "isEdited" : false,
  387. "isNew" : false,
  388. "index" : index
  389. });
  390. }
  391. },
  392. _queryCreateViewNode: function(){
  393. },
  394. _postCreateViewNode: function( viewNode ){
  395. },
  396. _queryCreateViewHead:function(){
  397. },
  398. _postCreateViewHead: function( headNode ){
  399. }
  400. });
  401. MWF.xApplication.ForumSearch.Document = new Class({
  402. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  403. _queryCreateDocumentNode:function( itemData ){
  404. },
  405. _postCreateDocumentNode: function( itemNode, itemData ){
  406. },
  407. open: function (e) {
  408. this.view._openDocument(this.data, this.index);
  409. },
  410. edit : function(){
  411. var appId = "ForumDocument"+this.data.id;
  412. if (this.app.desktop.apps[appId]){
  413. this.app.desktop.apps[appId].setCurrent();
  414. }else {
  415. this.app.desktop.openApplication(null, "ForumDocument", {
  416. "sectionId" : this.data.sectionId,
  417. "id" : this.data.id,
  418. "appId": appId,
  419. "isEdited" : true,
  420. "isNew" : false,
  421. "index" : this.index
  422. });
  423. }
  424. },
  425. openSection : function( ev ){
  426. var data = this.data;
  427. var appId = "ForumSection"+ data.sectionId;
  428. if (this.app.desktop.apps[appId]){
  429. this.app.desktop.apps[appId].setCurrent();
  430. }else {
  431. this.app.desktop.openApplication(ev, "ForumSection", {
  432. "sectionId": data.sectionId,
  433. "appId": appId
  434. });
  435. }
  436. ev.stopPropagation();
  437. },
  438. isAdmin: function(){
  439. return this.app.access.isAdmin();
  440. }
  441. });