Main.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. MWF.xApplication.Forum = MWF.xApplication.Forum || {};
  2. window.MWFForum = window.MWFForum || MWF.xApplication.Forum;
  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", "Access", null, false);
  7. MWF.xDesktop.requireApp("Forum", "ColumnTemplate", null, false);
  8. MWF.xDesktop.requireApp("Forum", "TopNode", null, false);
  9. MWF.xDesktop.requireApp("Template", "Explorer", null, false);
  10. MWF.xApplication.Forum.options = {
  11. multitask: false,
  12. executable: true
  13. };
  14. MWF.xApplication.Forum.Main = new Class({
  15. Extends: MWF.xApplication.Common.Main,
  16. Implements: [Options, Events],
  17. options: {
  18. "style": "default",
  19. "name": "Forum",
  20. "icon": "icon.png",
  21. "width": "1230",
  22. "height": "700",
  23. "isResize": true,
  24. "isMax": true,
  25. "title": MWF.xApplication.Forum.LP.title
  26. },
  27. onQueryLoad: function () {
  28. this.lp = MWF.xApplication.Forum.LP;
  29. this.setTitle( this.getMainPageTitle() )
  30. },
  31. getMainPageTitle : function(){
  32. var tail = (this.inBrowser && layout.desktop.session.user.name !== "anonymous") ? (MWFForum.getSystemConfigValue( MWFForum.BBS_TITLE_TAIL ) || "") : "";
  33. return ( MWFForum.getBBSName() || MWF.xApplication.Forum.LP.title ) + tail;
  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_Forum/$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. reload : function(){
  47. this.clearContent();
  48. if( this.explorer ){
  49. this.openSetting( this.explorer.currentNaviItem.retrieve("index") )
  50. }else{
  51. this.loadApplicationLayout();
  52. }
  53. },
  54. isAdmin : function(){
  55. return this.access.isAdmin();
  56. },
  57. createNode: function () {
  58. this.content.setStyle("overflow", "hidden");
  59. this.node = new Element("div", {
  60. "styles": this.css.node
  61. }).inject(this.content);
  62. },
  63. loadApplicationContent: function () {
  64. this.loadController(function () {
  65. this.access.login( function(){
  66. if( this.status && this.status.setting ){
  67. this.openSetting( this.status.index )
  68. }else{
  69. this.loadApplicationLayout();
  70. }
  71. }.bind(this))
  72. }.bind(this))
  73. },
  74. loaNavi: function (callback) {
  75. this.naviNode = new Element("div.naviNode", {
  76. "styles": this.css.naviNode
  77. }).inject(this.node);
  78. var curNavi = {"id": ""};
  79. if (this.status) {
  80. curNavi.id = this.status.id;
  81. }
  82. this.navi = new MWF.xApplication.Forum.Navi(this, this.naviNode, curNavi);
  83. },
  84. loadApplicationLayout: function () {
  85. this.contentContainerNode = new Element("div.contentContainerNode", {
  86. "styles": this.css.contentContainerNode
  87. }).inject(this.node);
  88. this.createTopNode( false );
  89. this.createContainerNode();
  90. },
  91. createTopNode: function( naviMode ){
  92. var node = this.topObject = new MWF.xApplication.Forum.TopNode(this.contentContainerNode, this, this, {
  93. type: this.options.style,
  94. settingEnable : true,
  95. naviModeEnable : true,
  96. naviMode : naviMode
  97. });
  98. node.load();
  99. },
  100. createContainerNode: function () {
  101. this.createContent();
  102. },
  103. createContent: function () {
  104. this.middleNode = new Element("div.middleNode", {
  105. "styles": this.css.middleNode
  106. }).inject(this.contentContainerNode);
  107. this.setContentSizeFun = this.setContentSize.bind(this);
  108. this.addEvent("resize", this.setContentSizeFun );
  109. this.setContentSize();
  110. //MWF.require("MWF.widget.ScrollBar", function () {
  111. // this.scrollBar = new MWF.widget.ScrollBar(this.contentContainerNode, {
  112. // "indent": false,
  113. // "style": "xApp_TaskList",
  114. // "where": "before",
  115. // "distance": 30,
  116. // "friction": 4,
  117. // "axis": {"x": false, "y": true},
  118. // "onScroll": function (y) {
  119. // }
  120. // });
  121. //}.bind(this));
  122. this.contentNode = new Element("div.contentNode", {
  123. "styles": this.css.contentNode
  124. }).inject(this.middleNode);
  125. this.createRecommand();
  126. this.restActions.listCategoryAll(function (json) {
  127. if( !json.data )json.data = [];
  128. json.data.each(function (d, idx) {
  129. if(d.forumStatus != this.lp.invalid ){
  130. this._createCategory(d, idx);
  131. }
  132. }.bind(this))
  133. }.bind(this))
  134. },
  135. setContentSize: function () {
  136. //var topSize = this.topNode ? this.topNode.getSize() : {"x": 0, "y": 0};
  137. var topSize = {"x": 0, "y": 0};
  138. var nodeSize = this.node.getSize();
  139. var pt = this.contentContainerNode.getStyle("padding-top").toFloat();
  140. var pb = this.contentContainerNode.getStyle("padding-bottom").toFloat();
  141. var height = nodeSize.y - topSize.y - pt - pb;
  142. this.contentContainerNode.setStyle("height", "" + height + "px");
  143. },
  144. createRecommand: function () {
  145. var recommandNode = new Element("div.recommandNode", {
  146. "styles": this.css.recommandNode
  147. }).inject(this.contentNode);
  148. var recommandTopNode = new Element("div.recommandTopNode", {
  149. "styles": this.css.recommandTopNode
  150. }).inject(recommandNode);
  151. //recommandTopNode.setStyle( "border-bottom" , "1px solid "+this.lp.defaultForumColor );
  152. var recommandTopTitleNode = new Element("div.recommandTopTitleNode", {
  153. "styles": this.css.recommandTopTitleNode,
  154. "text": this.lp.recommandSubject
  155. }).inject(recommandTopNode);
  156. //recommandTopTitleNode.setStyle( "background-color" , this.lp.defaultForumColor );
  157. //categoryTopTitleNode.addEvents({
  158. // click : function(el){ this.obj.openCategory( this.data ) }.bind({ obj : this, data : d })
  159. //})
  160. //var categoryTopRightNode = new Element("div.categoryTopRightNode", {
  161. // "styles": this.css.categoryTopRightNode,
  162. // "text": this.lp.recommandSubject
  163. //}).inject(categoryTopNode);
  164. var view = new MWF.xApplication.Forum.Main.RecommandView(recommandNode, this, this, {
  165. templateUrl: this.path + "listItemRecommand.json"
  166. }, {
  167. lp: this.lp
  168. });
  169. view.load();
  170. },
  171. _createCategory: function (d, idx) {
  172. var categoryNode = new Element("div.categoryNode", {
  173. "styles": this.css.categoryNode
  174. }).inject(this.contentNode);
  175. var categoryTopNode = new Element("div.categoryTopNode", {
  176. "styles": this.css.categoryTopNode
  177. }).inject(categoryNode);
  178. //categoryTopNode.setStyle( "border-bottom" , "1px solid "+ d.forumColor || this.lp.defaultForumColor );
  179. var categoryTopTitleNode = new Element("div.categoryTopTitleNode", {
  180. "styles": this.css.categoryTopTitleNode,
  181. "text": d.forumName
  182. }).inject(categoryTopNode);
  183. categoryTopTitleNode.addEvents({
  184. click : function(el){ this.obj.openCategory( this.data ) }.bind({ obj : this, data : d })
  185. });
  186. categoryTopTitleNode.setStyle( "color" , d.forumColor || this.lp.defaultForumColor );
  187. var categoryTopRightNode = new Element("div.categoryTopRightNode", {
  188. "styles": this.css.categoryTopRightNode2
  189. }).inject(categoryTopNode);
  190. this.createPersonNode(categoryTopRightNode,d.forumManagerName );
  191. new Element("div.categoryTopRightNode", {
  192. "styles": this.css.categoryTopRightNode,
  193. "text": this.lp.categoryManager + ":" //+ d.forumManagerName
  194. }).inject(categoryTopNode);
  195. var view = new MWF.xApplication.Forum.ColumnTemplate(categoryNode, this, this, {
  196. type: d.indexListStyle || "type_1_0",
  197. categoryId: d.id
  198. });
  199. view.load();
  200. //if (d.indexListStyle == "经典") {
  201. // var view = new MWF.xApplication.Forum.Main.ListView(categoryNode, this, this, {
  202. // templateUrl: this.path + "listItemList.json",
  203. // categoryId: d.id
  204. // }, {
  205. // lp: this.lp
  206. // });
  207. // view.load();
  208. //} else if (d.indexListStyle == "图片矩形") {
  209. // var view = new MWF.xApplication.Forum.Main.ImageView(categoryNode, this, this, {
  210. // templateUrl: this.path + "listItemImage.json",
  211. // categoryId: d.id
  212. // }, {
  213. // lp: this.lp
  214. // });
  215. // view.load();
  216. //} else {
  217. // var view = new MWF.xApplication.Forum.Main.TileView(categoryNode, this, this, {
  218. // templateUrl: this.path + "listItemTile.json",
  219. // categoryId: d.id
  220. // }, {
  221. // lp: this.lp
  222. // });
  223. // view.load();
  224. //}
  225. },
  226. clearContent: function () {
  227. if (this.explorer)this.explorer.destroy();
  228. this.explorer = null;
  229. if(this.setContentSizeFun)this.removeEvent("resize", this.setContentSizeFun );
  230. if(this.scrollBar && this.scrollBar.scrollVAreaNode)this.scrollBar.scrollVAreaNode.destroy();
  231. if( this.scrollBar )delete this.scrollBar;
  232. if (this.contentContainerNode) {
  233. this.contentContainerNode.destroy();
  234. //this.middleNode.destroy();
  235. //this.contentNode.destroy();
  236. }
  237. },
  238. openCategory : function( d ){
  239. var appId = "ForumCategory"+ d.id;
  240. if (this.desktop.apps[appId]){
  241. this.desktop.apps[appId].setCurrent();
  242. }else {
  243. this.desktop.openApplication(null, "ForumCategory", {
  244. "categoryId": d.id,
  245. "appId": appId
  246. });
  247. }
  248. },
  249. openView : function(){
  250. },
  251. openNavi: function () {
  252. MWF.xDesktop.requireApp("Forum", "NaviMode", null, false);
  253. this.clearContent();
  254. this.contentContainerNode = new Element("div.contentContainerNode", {
  255. "styles": this.css.contentContainerNode
  256. }).inject(this.node);
  257. this.createTopNode( true );
  258. this.middleNode = new Element("div.middleNode", {
  259. "styles": this.css.middleNode
  260. }).inject(this.contentContainerNode);
  261. this.contentNode = new Element("div.contentNode", {
  262. "styles": this.css.contentNode
  263. }).inject(this.middleNode);
  264. this.navi = new MWF.xApplication.Forum.NaviMode(this, this.contentNode, {});
  265. this.navi.load();
  266. },
  267. closeNavi : function(){
  268. if( this.navi )this.navi.close();
  269. },
  270. openSetting: function ( index ) {
  271. MWF.xDesktop.requireApp("Forum", "Setting", null, false);
  272. this.clearContent();
  273. this.contentContainerNode = new Element("div.contentContainerNode", {
  274. "styles": this.css.contentContainerNode
  275. }).inject(this.node);
  276. this.createTopNode( false );
  277. this.middleNode = new Element("div.middleNode", {
  278. "styles": this.css.middleNode
  279. }).inject(this.contentContainerNode);
  280. this.contentNode = new Element("div.contentNode", {
  281. "styles": this.css.contentNode
  282. }).inject(this.middleNode);
  283. this.explorer = new MWF.xApplication.Forum.Setting(this.contentNode, this, this.restActions, {"isAdmin": this.isAdmin() , "index" : (index || 0) });
  284. this.explorer.load();
  285. },
  286. recordStatus: function () {
  287. var status = {};
  288. if( this.explorer ){
  289. status = {
  290. setting : true,
  291. index : this.explorer.currentNaviItem.retrieve("index")
  292. };
  293. }
  294. return status;
  295. },
  296. openPerson : function( userName, data ){
  297. MWFForum.openPersonCenter( userName, data );
  298. },
  299. createPersonNode : function( container, personName ){
  300. var persons = personName.split(",");
  301. persons.each( function(userName, i){
  302. Promise.resolve( MWFForum.getDisplayName( userName ) ).then(function (name) {
  303. var span = new Element("span", {
  304. "text": name.split('@')[0],
  305. "styles": this.css.person
  306. }).inject(container);
  307. span.addEvents({
  308. mouseover: function () {
  309. this.node.setStyles(this.obj.css.person_over)
  310. }.bind({node: span, obj: this}),
  311. mouseout: function () {
  312. this.node.setStyles(this.obj.css.person)
  313. }.bind({node: span, obj: this}),
  314. click: function () {
  315. this.obj.openPerson(this.userName)
  316. }.bind({userName: userName, obj: this})
  317. });
  318. if (i != persons.length - 1) {
  319. new Element("span", {
  320. "text": "、"
  321. }).inject(container);
  322. }
  323. }.bind(this))
  324. }.bind(this))
  325. }
  326. });
  327. MWF.xApplication.Forum.Main.RecommandView = new Class({
  328. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  329. _createDocument: function (data, index) {
  330. return new MWF.xApplication.Forum.Main.RecommandDocument(this.viewNode, data, this.explorer, this, null, index);
  331. },
  332. _getCurrentPageData: function (callback, count) {
  333. if (!count)count = 12;
  334. this.actions.listRecommendedSubject(count, function (json) {
  335. if( !json.data )json.data = [];
  336. if (callback)callback(json);
  337. }.bind(this))
  338. },
  339. _removeDocument: function (documentData, all) {
  340. //this.actions.deleteSchedule(documentData.id, function(json){
  341. // this.reload();
  342. // this.app.notice(this.app.lp.deleteDocumentOK, "success");
  343. //}.bind(this));
  344. },
  345. _create: function () {
  346. },
  347. _openDocument: function (documentData) {
  348. },
  349. _queryCreateViewNode: function () {
  350. },
  351. _postCreateViewNode: function (viewNode) {
  352. },
  353. _queryCreateViewHead: function () {
  354. },
  355. _postCreateViewHead: function (headNode) {
  356. }
  357. });
  358. MWF.xApplication.Forum.Main.RecommandDocument = new Class({
  359. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  360. mouseoverDocument: function () {
  361. //this.node.getElements("[styles='documentItemTitleNode']").setStyles(this.css["documentItemTitleNode_over"]);
  362. //this.node.getElements("[styles='documentItemIconNode']").setStyles(this.css["documentItemIconNode_over"]);
  363. //this.node.getElements("[styles='documentItemStatNode']").setStyles(this.css["documentItemStatNode_over"]);
  364. },
  365. mouseoutDocument: function () {
  366. //this.node.getElements("[styles='documentItemTitleNode']").setStyles(this.css["documentItemTitleNode"]);
  367. //this.node.getElements("[styles='documentItemIconNode']").setStyles(this.css["documentItemIconNode"]);
  368. //this.node.getElements("[styles='documentItemStatNode']").setStyles(this.css["documentItemStatNode"]);
  369. },
  370. _queryCreateDocumentNode: function (itemData) {
  371. },
  372. _postCreateDocumentNode: function (itemNode, itemData) {
  373. },
  374. open: function( ){
  375. var data = this.data;
  376. var appId = "ForumDocument"+data.id;
  377. if (this.app.desktop.apps[appId]){
  378. this.app.desktop.apps[appId].setCurrent();
  379. }else {
  380. this.app.desktop.openApplication(null, "ForumDocument", {
  381. "sectionId" : data.sectionId,
  382. "id" : data.id,
  383. "appId": appId,
  384. "isEdited" : false,
  385. "isNew" : false
  386. });
  387. }
  388. },
  389. openSection : function( el ){
  390. var data = this.data;
  391. var appId = "ForumSection"+ data.sectionId;
  392. if (this.app.desktop.apps[appId]){
  393. this.app.desktop.apps[appId].setCurrent();
  394. }else {
  395. this.app.desktop.openApplication(el, "ForumSection", {
  396. "sectionId": data.sectionId,
  397. "appId": appId
  398. });
  399. }
  400. }
  401. });