Main.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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. var tail = (this.inBrowser && layout.desktop.session.user.name !== "anonymous") ? (MWFForum.getSystemConfigValue( MWFForum.BBS_TITLE_TAIL ) || "") : "";
  76. this.setTitle( this.data.forumName + tail);
  77. this.createTopNode();
  78. this.middleNode = new Element("div.middleNode", {
  79. "styles": this.options.autoWidth ? this.css.middleNode_inContainer : this.css.middleNode
  80. }).inject(this.contentContainerNode);
  81. this.createNoteNode();
  82. this.createContainerNode();
  83. }.bind(this))
  84. },
  85. loadTopObject : function(naviMode){
  86. if( this.options.hasTop ){
  87. var node = new MWF.xApplication.Forum.TopNode(this.contentContainerNode, this, this, {
  88. type: this.options.style,
  89. naviModeEnable : true,
  90. naviMode : naviMode
  91. });
  92. node.load();
  93. }
  94. },
  95. createTopNode: function () {
  96. this.loadTopObject( false );
  97. var forumColor = MWF.xApplication.Forum.ForumSetting[this.options.categoryId].forumColor;
  98. if( this.options.hasBreadCrumb || (this.data.forumNotice && this.data.forumNotice!="") ){
  99. var topNode = this.topNode = new Element("div.topNode", {
  100. "styles": this.options.autoWidth ? this.css.topNode_inContainer : this.css.topNode
  101. }).inject(this.contentContainerNode);
  102. //topNode.setStyle( "border-bottom" , "1px solid "+forumColor );
  103. }
  104. if( this.options.hasBreadCrumb ){
  105. var topTitleMiddleNode = new Element("div.topTitleMiddleNode", {
  106. "styles": this.css.topTitleMiddleNode
  107. }).inject(topNode);
  108. //topTitleMiddleNode.setStyle( "background-color" , forumColor )
  109. var topItemTitleNode = new Element("div.topItemTitleNode", {
  110. "styles": this.css.topItemTitleNode,
  111. "text": MWFForum.getBBSName() || MWF.xApplication.Forum.LP.title
  112. }).inject(topTitleMiddleNode);
  113. var topItemSepNode = new Element("div.topItemSepNode", {
  114. "styles": this.css.topItemSepNode,
  115. "text" : ">"
  116. }).inject(topTitleMiddleNode);
  117. topItemTitleNode.addEvent("click", function(){
  118. if( this.options.naviMode && this.forumNavi ){
  119. this.forumNavi.goto( MWFForum.NaviType.main )
  120. }else{
  121. var appId = "Forum";
  122. if (this.desktop.apps[appId]){
  123. this.desktop.apps[appId].setCurrent();
  124. }else {
  125. this.desktop.openApplication(null, "Forum", { "appId": appId });
  126. }
  127. if( !this.inBrowser ){
  128. this.close();
  129. }
  130. }
  131. }.bind(this));
  132. var topItemTitleNode = new Element("div.topItemTitleNode", {
  133. "styles": this.css.topItemTitleLastNode,
  134. "text": this.data.forumName
  135. }).inject(topTitleMiddleNode);
  136. }
  137. if( this.data.forumNotice && this.data.forumNotice!="" ){
  138. var topRightNode = new Element("div", {
  139. "styles": this.css.topRightNode
  140. }).inject(topNode);
  141. topRightNode.addEvents({
  142. "click" :function(){
  143. if( !this.noteNodeHidden ){
  144. this.noteNode.setStyle("display","none");
  145. this.topRightIconNode.setStyles(this.css.topRightIconDownNode);
  146. this.noteNodeHidden = true;
  147. }else{
  148. this.noteNode.setStyle("display","");
  149. this.topRightIconNode.setStyles(this.css.topRightIconNode);
  150. this.noteNodeHidden = false;
  151. }
  152. }.bind(this)
  153. });
  154. var topRightIconNode = this.topRightIconNode = new Element("div", {
  155. "styles": this.css.topRightIconNode
  156. }).inject(topRightNode);
  157. if( this.status && this.status.noteHidden ){
  158. this.topRightIconNode.setStyles(this.css.topRightIconDownNode);
  159. this.noteNodeHidden = true;
  160. }
  161. }
  162. this._createTopContent();
  163. },
  164. _createTopContent: function () {
  165. },
  166. createContainerNode: function () {
  167. this.createCategory();
  168. },
  169. createCategory: function () {
  170. if( !this.options.naviMode ){
  171. this.setContentSizeFun = this.setContentSize.bind(this);
  172. this.addEvent("resize", this.setContentSizeFun );
  173. this.setContentSize();
  174. }
  175. //MWF.require("MWF.widget.ScrollBar", function () {
  176. // this.scrollBar = new MWF.widget.ScrollBar(this.contentContainerNode, {
  177. // "indent": false,
  178. // "style": "xApp_TaskList",
  179. // "where": "before",
  180. // "distance": 30,
  181. // "friction": 4,
  182. // "axis": {"x": false, "y": true},
  183. // "onScroll": function (y) {
  184. // }
  185. // });
  186. //}.bind(this));
  187. this.contentNode = new Element("div.contentNode", {
  188. "styles": this.css.contentNode
  189. }).inject(this.middleNode);
  190. this._createCategory( this.data )
  191. },
  192. createNoteNode : function(){
  193. if( !this.data.forumNotice || this.data.forumNotice.trim() =="" ){
  194. return;
  195. }
  196. var noteNode = this.noteNode = new Element("div.noteNode", {
  197. "styles": this.css.noteNode
  198. }).inject(this.middleNode);
  199. var noteTopNode = new Element("div.noteTopNode", {
  200. "styles": this.css.noteTopNode
  201. }).inject(noteNode);
  202. var noteTopContent = new Element("div.noteTopContent", {
  203. "styles": this.css.noteTopContent
  204. }).inject(noteTopNode);
  205. var noteIcon = new Element("div.noteIcon", {
  206. "styles": this.css.noteIcon
  207. }).inject(noteTopContent);
  208. var noteTopText = new Element("div.noteTopText", {
  209. "styles": this.css.noteTopText,
  210. "text" : this.lp.forumNotice
  211. }).inject(noteTopContent);
  212. var noteContent = new Element("div.noteContent", {
  213. "styles": this.css.noteContent,
  214. "html" : this.data.forumNotice
  215. }).inject(noteNode);
  216. if( this.status && this.status.noteHidden ){
  217. noteNode.setStyle("display" , "none");
  218. }
  219. },
  220. setContentSize: function () {
  221. //var topSize = this.topNode ? this.topNode.getSize() : {"x": 0, "y": 0};
  222. var topSize = {"x": 0, "y": 0};
  223. var nodeSize = this.node.getSize();
  224. var pt = this.contentContainerNode.getStyle("padding-top").toFloat();
  225. var pb = this.contentContainerNode.getStyle("padding-bottom").toFloat();
  226. var height = nodeSize.y - topSize.y - pt - pb;
  227. this.contentContainerNode.setStyle("height", "" + height + "px");
  228. },
  229. _createCategory: function (d) {
  230. //var categoryNode = new Element("div.categoryNode", {
  231. // "styles": this.css.categoryNode
  232. //}).inject(this.contentNode);
  233. var categoryNode = new Element("div.categoryNode", {
  234. "styles": this.css.categoryNode
  235. }).inject(this.contentNode);
  236. var categoryTopNode = new Element("div.categoryTopNode", {
  237. "styles": this.css.categoryTopNode
  238. }).inject(categoryNode);
  239. //categoryTopNode.setStyle( "border-bottom" , "1px solid "+ d.forumColor || this.lp.defaultForumColor );
  240. var categoryTopTitleNode = new Element("div.categoryTopTitleNode", {
  241. "styles": this.css.categoryTopTitleNode,
  242. "text": d.forumName
  243. }).inject(categoryTopNode);
  244. categoryTopTitleNode.addEvents({
  245. click : function(el){ this.obj.openCategory( this.data ) }.bind({ obj : this, data : d })
  246. });
  247. categoryTopTitleNode.setStyle( "color" , d.forumColor || this.lp.defaultForumColor );
  248. var categoryTopRightNode = new Element("div.categoryTopRightNode", {
  249. "styles": this.css.categoryTopRightNode2
  250. }).inject(categoryTopNode);
  251. this.createPersonNode(categoryTopRightNode,d.forumManagerName );
  252. new Element("div.categoryTopRightNode", {
  253. "styles": this.css.categoryTopRightNode,
  254. "text": this.lp.categoryManager + ":" //+ d.forumManagerName
  255. }).inject(categoryTopNode);
  256. var view = new MWF.xApplication.Forum.ColumnTemplate(categoryNode, this, this, {
  257. type: d.indexListStyle || "type_1_0",
  258. style : this.options.naviMode ? "naviMode" : "default",
  259. naviMode : this.options.naviMode,
  260. categoryId: d.id,
  261. onPostLoad : function(){
  262. this.fireEvent("postLoadCategory")
  263. }.bind(this)
  264. });
  265. view.forumNavi = this.forumNavi;
  266. view.load();
  267. //
  268. //if (d.indexListStyle == "经典") {
  269. // var view = new MWF.xApplication.ForumCategory.Main.ListView(categoryNode, this, this, {
  270. // templateUrl: this.path + "listItemList.json",
  271. // categoryId: d.id
  272. // }, {
  273. // lp: this.lp
  274. // })
  275. // view.load();
  276. //} else if (d.indexListStyle == "图片矩形") {
  277. // var view = new MWF.xApplication.ForumCategory.Main.ImageView(categoryNode, this, this, {
  278. // templateUrl: this.path + "listItemImage.json",
  279. // categoryId: d.id
  280. // }, {
  281. // lp: this.lp
  282. // })
  283. // view.load();
  284. //} else {
  285. // var view = new MWF.xApplication.ForumCategory.Main.TileView(categoryNode, this, this, {
  286. // templateUrl: this.path + "listItemTile.json",
  287. // categoryId: d.id
  288. // }, {
  289. // lp: this.lp
  290. // })
  291. // view.load();
  292. //}
  293. },
  294. openNavi: function () {
  295. MWF.xDesktop.requireApp("Forum", "NaviMode", null, false);
  296. this.clearContent();
  297. this.contentContainerNode = new Element("div.contentContainerNode", {
  298. "styles": this.css.contentContainerNode
  299. }).inject(this.node);
  300. this.loadTopObject( true );
  301. this.middleNode = new Element("div.middleNode", {
  302. "styles": this.css.middleNode
  303. }).inject(this.contentContainerNode);
  304. this.contentNode = new Element("div.contentNode", {
  305. "styles": this.css.contentNode
  306. }).inject(this.middleNode);
  307. this.navi = new MWF.xApplication.Forum.NaviMode(this, this.contentNode, {
  308. type : MWFForum.NaviType.category,
  309. id : this.options.categoryId
  310. });
  311. this.navi.load();
  312. },
  313. closeNavi : function(){
  314. if( this.navi )this.navi.close();
  315. },
  316. destroy : function(){
  317. this.clearContent();
  318. },
  319. clearContent: function () {
  320. if (this.explorer)this.explorer.destroy();
  321. if(this.setContentSizeFun)this.removeEvent("resize", this.setContentSizeFun );
  322. if(this.scrollBar && this.scrollBar.scrollVAreaNode)this.scrollBar.scrollVAreaNode.destroy();
  323. if( this.scrollBar )delete this.scrollBar;
  324. if (this.contentContainerNode) {
  325. this.contentContainerNode.destroy();
  326. //this.middleNode.destroy();
  327. //this.contentNode.destroy();
  328. }
  329. },
  330. openMainPage : function(){
  331. this.clearContent();
  332. //this.createCategory();
  333. this.loadApplicationLayout();
  334. },
  335. recordStatus: function () {
  336. return {
  337. categoryId : this.options.categoryId,
  338. noteHidden : this.noteNodeHidden
  339. };
  340. },
  341. openPerson : function( userName, data ){
  342. MWFForum.openPersonCenter( userName, data );
  343. },
  344. createPersonNode : function( container, personName ){
  345. var persons = personName.split(",");
  346. persons.each( function(userName, i){
  347. Promise.resolve( MWFForum.getDisplayName( userName ) ).then(function (name) {
  348. var span = new Element("span", {
  349. "text" : name.split("@")[0],
  350. "styles" : this.css.person
  351. }).inject(container);
  352. span.addEvents( {
  353. mouseover : function(){ this.node.setStyles( this.obj.css.person_over )}.bind( {node:span, obj:this} ),
  354. mouseout : function(){ this.node.setStyles( this.obj.css.person )}.bind( {node:span, obj:this} ),
  355. click : function(){ this.obj.openPerson( this.userName ) }.bind( {userName:userName, obj:this} )
  356. });
  357. if( i != persons.length - 1 ){
  358. new Element("span", {
  359. "text" : ","
  360. }).inject(container);
  361. }
  362. }.bind(this))
  363. }.bind(this))
  364. }
  365. });