Main.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  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. holdMouseDownStyles : true,
  277. pagingPar : {
  278. currentPage : this.options.viewPageNum,
  279. countPerPage : 30,
  280. onPostLoad : function( pagingBar ){
  281. if(pagingBar.nextPageNode){
  282. pagingBar.nextPageNode.inject( this.toolbarBottom, "before" );
  283. }
  284. }.bind(this),
  285. onPageReturn : function( pagingBar ){
  286. var appId = "Forum";
  287. if (this.app.desktop.apps[appId]){
  288. this.app.desktop.apps[appId].setCurrent();
  289. }else {
  290. this.app.desktop.openApplication(null, "Forum", { "appId": appId });
  291. }
  292. this.app.close();
  293. }.bind(this)
  294. }
  295. } );
  296. this.view.filterData = { searchContent : this.app.options.searchContent };
  297. this.view.pagingContainerTop = this.pagingBarTop;
  298. this.view.pagingContainerBottom = this.pagingBarBottom;
  299. this.view.load();
  300. },
  301. resizeWindow: function(){
  302. var size = this.app.content.getSize();
  303. this.viewContainer.setStyles({"height":(size.y-121)+"px"});
  304. },
  305. createSubject: function(){
  306. var _self = this;
  307. var appId = "ForumDocument";
  308. if (_self.app.desktop.apps[appId]){
  309. _self.app.desktop.apps[appId].setCurrent();
  310. }else {
  311. this.app.desktop.openApplication(null, "ForumDocument", {
  312. "sectionId": this.app.sectionData.id,
  313. "appId": appId,
  314. "isNew" : true,
  315. "isEdited" : true,
  316. "onPostPublish" : function(){
  317. this.view.reload();
  318. }.bind(this)
  319. });
  320. }
  321. },
  322. openPerson : function( userName ){
  323. var appId = "ForumPerson"+userName;
  324. if (this.desktop.apps[userName]){
  325. this.desktop.apps[userName].setCurrent();
  326. }else {
  327. this.desktop.openApplication(null, "ForumPerson", {
  328. "personName" : userName,
  329. "appId": appId
  330. });
  331. }
  332. },
  333. createPersonNode : function( container, personName ){
  334. var persons = personName.split(",");
  335. persons.each( function(userName, i){
  336. var span = new Element("span", {
  337. "text" : userName,
  338. "styles" : this.css.person
  339. }).inject(container);
  340. span.addEvents( {
  341. mouseover : function(){ this.node.setStyles( this.obj.css.person_over )}.bind( {node:span, obj:this} ),
  342. mouseout : function(){ this.node.setStyles( this.obj.css.person )}.bind( {node:span, obj:this} ),
  343. click : function(){ this.obj.openPerson( this.userName ) }.bind( {userName:userName, obj:this} )
  344. });
  345. if( i != persons.length - 1 ){
  346. new Element("span", {
  347. "text" : ","
  348. }).inject(container);
  349. }
  350. }.bind(this))
  351. }
  352. });
  353. MWF.xApplication.ForumSearch.View = new Class({
  354. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  355. _createDocument: function(data, index){
  356. return new MWF.xApplication.ForumSearch.Document(this.viewNode, data, this.explorer, this, null, index);
  357. },
  358. _getCurrentPageData: function(callback, count, pageNum){
  359. this.clearBody();
  360. if(!count)count=30;
  361. if(!pageNum)pageNum = 1;
  362. var filter = this.filterData || {};
  363. this.actions.listSubjectSearchPage( pageNum, count, filter, function(json){
  364. if( !json.data )json.data = [];
  365. if( !json.count )json.count=0;
  366. if( callback )callback(json);
  367. }.bind(this))
  368. },
  369. _removeDocument: function(documentData, all){
  370. this.actions.deleteSubject(documentData.id, function(json){
  371. this.reload();
  372. this.app.reloadAllParents( documentData.sectionId );
  373. this.app.notice(this.app.lp.deleteDocumentOK, "success");
  374. }.bind(this));
  375. },
  376. _create: function(){
  377. },
  378. _openDocument: function( documentData,index ){
  379. var appId = "ForumDocument"+documentData.id;
  380. if (this.app.desktop.apps[appId]){
  381. this.app.desktop.apps[appId].setCurrent();
  382. }else {
  383. this.app.desktop.openApplication(null, "ForumDocument", {
  384. "sectionId" : documentData.sectionId,
  385. "id" : documentData.id,
  386. "appId": appId,
  387. "isEdited" : false,
  388. "isNew" : false,
  389. "index" : index
  390. });
  391. }
  392. },
  393. _queryCreateViewNode: function(){
  394. },
  395. _postCreateViewNode: function( viewNode ){
  396. },
  397. _queryCreateViewHead:function(){
  398. },
  399. _postCreateViewHead: function( headNode ){
  400. }
  401. });
  402. MWF.xApplication.ForumSearch.Document = new Class({
  403. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  404. _queryCreateDocumentNode:function( itemData ){
  405. },
  406. _postCreateDocumentNode: function( itemNode, itemData ){
  407. },
  408. open: function (e) {
  409. this.view._openDocument(this.data, this.index);
  410. },
  411. edit : function(){
  412. var appId = "ForumDocument"+this.data.id;
  413. if (this.app.desktop.apps[appId]){
  414. this.app.desktop.apps[appId].setCurrent();
  415. }else {
  416. this.app.desktop.openApplication(null, "ForumDocument", {
  417. "sectionId" : this.data.sectionId,
  418. "id" : this.data.id,
  419. "appId": appId,
  420. "isEdited" : true,
  421. "isNew" : false,
  422. "index" : this.index
  423. });
  424. }
  425. },
  426. openSection : function( ev ){
  427. var data = this.data;
  428. var appId = "ForumSection"+ data.sectionId;
  429. if (this.app.desktop.apps[appId]){
  430. this.app.desktop.apps[appId].setCurrent();
  431. }else {
  432. this.app.desktop.openApplication(ev, "ForumSection", {
  433. "sectionId": data.sectionId,
  434. "appId": appId
  435. });
  436. }
  437. ev.stopPropagation();
  438. },
  439. isAdmin: function(){
  440. return this.app.access.isAdmin();
  441. }
  442. });