Main.js 16 KB

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