Main.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. MWF.xApplication.Forum = MWF.xApplication.Forum || {};
  2. MWF.xApplication.ForumCategory = MWF.xApplication.ForumCategory || {};
  3. MWF.require("MWF.widget.O2Identity", null, false);
  4. MWF.xDesktop.requireApp("Forum", "Common", null, false);
  5. //MWF.xDesktop.requireApp("Forum", "Actions.RestActions", null, false);
  6. MWF.xDesktop.requireApp("Forum", "lp."+MWF.language, null, false);
  7. MWF.xDesktop.requireApp("Template", "Explorer", null, false);
  8. MWF.xDesktop.requireApp("Forum", "Access", null, false);
  9. MWF.xDesktop.requireApp("Forum", "ColumnTemplate", null, false);
  10. MWF.xDesktop.requireApp("Forum", "TopNode", null, false);
  11. MWF.xApplication.ForumCategory.options = {
  12. multitask: false,
  13. executable: true
  14. };
  15. MWF.xApplication.ForumCategory.Main = new Class({
  16. Extends: MWF.xApplication.Common.Main,
  17. Implements: [Options, Events],
  18. options: {
  19. "style": "default",
  20. "name": "ForumCategory",
  21. "icon": "icon.png",
  22. "width": "1230",
  23. "height": "700",
  24. "isResize": false,
  25. "isMax": true,
  26. "naviMode" : false,
  27. "hasTop" : true,
  28. "hasBreadCrumb" : true,
  29. "autoWidth" : false,
  30. "title": MWF.xApplication.ForumCategory.LP.title
  31. },
  32. onQueryLoad: function () {
  33. this.lp = MWF.xApplication.Forum.LP;
  34. },
  35. loadApplication: function (callback) {
  36. this.userName = layout.desktop.session.user.distinguishedName;
  37. this.restActions = MWF.Actions.get("x_bbs_assemble_control"); //new MWF.xApplication.Forum.Actions.RestActions();
  38. this.path = "/x_component_ForumCategory/$Main/" + this.options.style + "/";
  39. this.createNode();
  40. this.loadApplicationContent();
  41. },
  42. loadController: function (callback) {
  43. this.access = new MWF.xApplication.Forum.Access( this.restActions, this.lp );
  44. if (callback)callback();
  45. },
  46. createNode: function () {
  47. this.content.setStyle("overflow", "hidden");
  48. this.node = new Element("div", {
  49. "styles": this.css.node
  50. }).inject(this.content);
  51. },
  52. reload : function(){
  53. this.status = {
  54. categoryId : this.options.categoryId,
  55. noteHidden : this.noteNodeHidden
  56. };
  57. this.openMainPage();
  58. },
  59. loadApplicationContent: function () {
  60. if( !this.options.categoryId && this.status && this.status.categoryId ){
  61. this.options.categoryId = this.status.categoryId;
  62. }
  63. this.loadController(function () {
  64. this.access.login( function(){
  65. this.loadApplicationLayout();
  66. }.bind(this))
  67. }.bind(this))
  68. },
  69. loadApplicationLayout: function () {
  70. this.contentContainerNode = new Element("div.contentContainerNode", {
  71. "styles": this.options.autoWidth ? this.css.contentContainerNode_inContaienr : this.css.contentContainerNode
  72. }).inject(this.node);
  73. this.restActions.getCategory( this.options.categoryId, function (json) {
  74. this.data = json.data;
  75. this.setTitle( this.data.forumName );
  76. this.createTopNode();
  77. this.middleNode = new Element("div.middleNode", {
  78. "styles": this.options.autoWidth ? this.css.middleNode_inContainer : this.css.middleNode
  79. }).inject(this.contentContainerNode);
  80. this.createNoteNode();
  81. this.createContainerNode();
  82. }.bind(this))
  83. },
  84. loadTopObject : function(naviMode){
  85. if( this.options.hasTop ){
  86. var node = new MWF.xApplication.Forum.TopNode(this.contentContainerNode, this, this, {
  87. type: this.options.style,
  88. naviModeEnable : true,
  89. naviMode : naviMode
  90. });
  91. node.load();
  92. }
  93. },
  94. createTopNode: function () {
  95. this.loadTopObject( false );
  96. var forumColor = MWF.xApplication.Forum.ForumSetting[this.options.categoryId].forumColor;
  97. if( this.options.hasBreadCrumb || (this.data.forumNotice && this.data.forumNotice!="") ){
  98. var topNode = this.topNode = new Element("div.topNode", {
  99. "styles": this.options.autoWidth ? this.css.topNode_inContainer : this.css.topNode
  100. }).inject(this.contentContainerNode);
  101. //topNode.setStyle( "border-bottom" , "1px solid "+forumColor );
  102. }
  103. if( this.options.hasBreadCrumb ){
  104. var topTitleMiddleNode = new Element("div.topTitleMiddleNode", {
  105. "styles": this.css.topTitleMiddleNode
  106. }).inject(topNode);
  107. //topTitleMiddleNode.setStyle( "background-color" , forumColor )
  108. var topItemTitleNode = new Element("div.topItemTitleNode", {
  109. "styles": this.css.topItemTitleNode,
  110. "text": this.lp.title
  111. }).inject(topTitleMiddleNode);
  112. var topItemSepNode = new Element("div.topItemSepNode", {
  113. "styles": this.css.topItemSepNode,
  114. "text" : ">"
  115. }).inject(topTitleMiddleNode);
  116. topItemTitleNode.addEvent("click", function(){
  117. if( this.options.naviMode && this.forumNavi ){
  118. this.forumNavi.goto( MWFForum.NaviType.main )
  119. }else{
  120. var appId = "Forum";
  121. if (this.desktop.apps[appId]){
  122. this.desktop.apps[appId].setCurrent();
  123. }else {
  124. this.desktop.openApplication(null, "Forum", { "appId": appId });
  125. }
  126. if( !this.inBrowser ){
  127. this.close();
  128. }
  129. }
  130. }.bind(this));
  131. var topItemTitleNode = new Element("div.topItemTitleNode", {
  132. "styles": this.css.topItemTitleLastNode,
  133. "text": this.data.forumName
  134. }).inject(topTitleMiddleNode);
  135. }
  136. if( this.data.forumNotice && this.data.forumNotice!="" ){
  137. var topRightNode = new Element("div", {
  138. "styles": this.css.topRightNode
  139. }).inject(topNode);
  140. topRightNode.addEvents({
  141. "click" :function(){
  142. if( !this.noteNodeHidden ){
  143. this.noteNode.setStyle("display","none");
  144. this.topRightIconNode.setStyles(this.css.topRightIconDownNode);
  145. this.noteNodeHidden = true;
  146. }else{
  147. this.noteNode.setStyle("display","");
  148. this.topRightIconNode.setStyles(this.css.topRightIconNode);
  149. this.noteNodeHidden = false;
  150. }
  151. }.bind(this)
  152. });
  153. var topRightIconNode = this.topRightIconNode = new Element("div", {
  154. "styles": this.css.topRightIconNode
  155. }).inject(topRightNode);
  156. if( this.status && this.status.noteHidden ){
  157. this.topRightIconNode.setStyles(this.css.topRightIconDownNode);
  158. this.noteNodeHidden = true;
  159. }
  160. }
  161. this._createTopContent();
  162. },
  163. _createTopContent: function () {
  164. },
  165. createContainerNode: function () {
  166. this.createCategory();
  167. },
  168. createCategory: function () {
  169. if( !this.options.naviMode ){
  170. this.setContentSizeFun = this.setContentSize.bind(this);
  171. this.addEvent("resize", this.setContentSizeFun );
  172. this.setContentSize();
  173. }
  174. //MWF.require("MWF.widget.ScrollBar", function () {
  175. // this.scrollBar = new MWF.widget.ScrollBar(this.contentContainerNode, {
  176. // "indent": false,
  177. // "style": "xApp_TaskList",
  178. // "where": "before",
  179. // "distance": 30,
  180. // "friction": 4,
  181. // "axis": {"x": false, "y": true},
  182. // "onScroll": function (y) {
  183. // }
  184. // });
  185. //}.bind(this));
  186. this.contentNode = new Element("div.contentNode", {
  187. "styles": this.css.contentNode
  188. }).inject(this.middleNode);
  189. this._createCategory( this.data )
  190. },
  191. createNoteNode : function(){
  192. if( !this.data.forumNotice || this.data.forumNotice.trim() =="" ){
  193. return;
  194. }
  195. var noteNode = this.noteNode = new Element("div.noteNode", {
  196. "styles": this.css.noteNode
  197. }).inject(this.middleNode);
  198. var noteTopNode = new Element("div.noteTopNode", {
  199. "styles": this.css.noteTopNode
  200. }).inject(noteNode);
  201. var noteTopContent = new Element("div.noteTopContent", {
  202. "styles": this.css.noteTopContent
  203. }).inject(noteTopNode);
  204. var noteIcon = new Element("div.noteIcon", {
  205. "styles": this.css.noteIcon
  206. }).inject(noteTopContent);
  207. var noteTopText = new Element("div.noteTopText", {
  208. "styles": this.css.noteTopText,
  209. "text" : this.lp.forumNotice
  210. }).inject(noteTopContent);
  211. var noteContent = new Element("div.noteContent", {
  212. "styles": this.css.noteContent,
  213. "html" : this.data.forumNotice
  214. }).inject(noteNode);
  215. if( this.status && this.status.noteHidden ){
  216. noteNode.setStyle("display" , "none");
  217. }
  218. },
  219. setContentSize: function () {
  220. //var topSize = this.topNode ? this.topNode.getSize() : {"x": 0, "y": 0};
  221. var topSize = {"x": 0, "y": 0};
  222. var nodeSize = this.node.getSize();
  223. var pt = this.contentContainerNode.getStyle("padding-top").toFloat();
  224. var pb = this.contentContainerNode.getStyle("padding-bottom").toFloat();
  225. var height = nodeSize.y - topSize.y - pt - pb;
  226. this.contentContainerNode.setStyle("height", "" + height + "px");
  227. },
  228. _createCategory: function (d) {
  229. //var categoryNode = new Element("div.categoryNode", {
  230. // "styles": this.css.categoryNode
  231. //}).inject(this.contentNode);
  232. var categoryNode = new Element("div.categoryNode", {
  233. "styles": this.css.categoryNode
  234. }).inject(this.contentNode);
  235. var categoryTopNode = new Element("div.categoryTopNode", {
  236. "styles": this.css.categoryTopNode
  237. }).inject(categoryNode);
  238. //categoryTopNode.setStyle( "border-bottom" , "1px solid "+ d.forumColor || this.lp.defaultForumColor );
  239. var categoryTopTitleNode = new Element("div.categoryTopTitleNode", {
  240. "styles": this.css.categoryTopTitleNode,
  241. "text": d.forumName
  242. }).inject(categoryTopNode);
  243. categoryTopTitleNode.addEvents({
  244. click : function(el){ this.obj.openCategory( this.data ) }.bind({ obj : this, data : d })
  245. });
  246. categoryTopTitleNode.setStyle( "color" , d.forumColor || this.lp.defaultForumColor );
  247. var categoryTopRightNode = new Element("div.categoryTopRightNode", {
  248. "styles": this.css.categoryTopRightNode2
  249. }).inject(categoryTopNode);
  250. this.createPersonNode(categoryTopRightNode,d.forumManagerName );
  251. new Element("div.categoryTopRightNode", {
  252. "styles": this.css.categoryTopRightNode,
  253. "text": this.lp.categoryManager + ":" //+ d.forumManagerName
  254. }).inject(categoryTopNode);
  255. var view = new MWF.xApplication.Forum.ColumnTemplate(categoryNode, this, this, {
  256. type: d.indexListStyle || "type_1_0",
  257. style : this.options.naviMode ? "naviMode" : "default",
  258. naviMode : this.options.naviMode,
  259. categoryId: d.id,
  260. onPostLoad : function(){
  261. this.fireEvent("postLoadCategory")
  262. }.bind(this)
  263. });
  264. view.forumNavi = this.forumNavi;
  265. view.load();
  266. //
  267. //if (d.indexListStyle == "经典") {
  268. // var view = new MWF.xApplication.ForumCategory.Main.ListView(categoryNode, this, this, {
  269. // templateUrl: this.path + "listItemList.json",
  270. // categoryId: d.id
  271. // }, {
  272. // lp: this.lp
  273. // })
  274. // view.load();
  275. //} else if (d.indexListStyle == "图片矩形") {
  276. // var view = new MWF.xApplication.ForumCategory.Main.ImageView(categoryNode, this, this, {
  277. // templateUrl: this.path + "listItemImage.json",
  278. // categoryId: d.id
  279. // }, {
  280. // lp: this.lp
  281. // })
  282. // view.load();
  283. //} else {
  284. // var view = new MWF.xApplication.ForumCategory.Main.TileView(categoryNode, this, this, {
  285. // templateUrl: this.path + "listItemTile.json",
  286. // categoryId: d.id
  287. // }, {
  288. // lp: this.lp
  289. // })
  290. // view.load();
  291. //}
  292. },
  293. openNavi: function () {
  294. MWF.xDesktop.requireApp("Forum", "NaviMode", null, false);
  295. this.clearContent();
  296. this.contentContainerNode = new Element("div.contentContainerNode", {
  297. "styles": this.css.contentContainerNode
  298. }).inject(this.node);
  299. this.loadTopObject( true );
  300. this.middleNode = new Element("div.middleNode", {
  301. "styles": this.css.middleNode
  302. }).inject(this.contentContainerNode);
  303. this.contentNode = new Element("div.contentNode", {
  304. "styles": this.css.contentNode
  305. }).inject(this.middleNode);
  306. this.navi = new MWF.xApplication.Forum.NaviMode(this, this.contentNode, {
  307. type : MWFForum.NaviType.category,
  308. id : this.options.categoryId
  309. });
  310. this.navi.load();
  311. },
  312. closeNavi : function(){
  313. if( this.navi )this.navi.close();
  314. },
  315. destroy : function(){
  316. this.clearContent();
  317. },
  318. clearContent: function () {
  319. if (this.explorer)this.explorer.destroy();
  320. if(this.setContentSizeFun)this.removeEvent("resize", this.setContentSizeFun );
  321. if(this.scrollBar && this.scrollBar.scrollVAreaNode)this.scrollBar.scrollVAreaNode.destroy();
  322. if( this.scrollBar )delete this.scrollBar;
  323. if (this.contentContainerNode) {
  324. this.contentContainerNode.destroy();
  325. //this.middleNode.destroy();
  326. //this.contentNode.destroy();
  327. }
  328. },
  329. openMainPage : function(){
  330. this.clearContent();
  331. //this.createCategory();
  332. this.loadApplicationLayout();
  333. },
  334. recordStatus: function () {
  335. return {
  336. categoryId : this.options.categoryId,
  337. noteHidden : this.noteNodeHidden
  338. };
  339. },
  340. openPerson : function( userName ){
  341. var appId = "ForumPerson"+userName;
  342. if (this.desktop.apps[userName]){
  343. this.desktop.apps[userName].setCurrent();
  344. }else {
  345. this.desktop.openApplication(null, "ForumPerson", {
  346. "personName" : userName,
  347. "appId": appId
  348. });
  349. }
  350. },
  351. createPersonNode : function( container, personName ){
  352. var persons = personName.split(",");
  353. persons.each( function(userName, i){
  354. var span = new Element("span", {
  355. "text" : userName.split("@")[0],
  356. "styles" : this.css.person
  357. }).inject(container);
  358. span.addEvents( {
  359. mouseover : function(){ this.node.setStyles( this.obj.css.person_over )}.bind( {node:span, obj:this} ),
  360. mouseout : function(){ this.node.setStyles( this.obj.css.person )}.bind( {node:span, obj:this} ),
  361. click : function(){ this.obj.openPerson( this.userName ) }.bind( {userName:userName, obj:this} )
  362. });
  363. if( i != persons.length - 1 ){
  364. new Element("span", {
  365. "text" : ","
  366. }).inject(container);
  367. }
  368. }.bind(this))
  369. }
  370. });