ColumnTemplate.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /**
  2. * Created by CXY on 2017/4/26.
  3. */
  4. MWF.xDesktop.requireApp("Template", "Explorer", null, false);
  5. MWF.xApplication.Forum.ColumnTemplate = new Class({
  6. Extends: MWF.widget.Common,
  7. Implements: [Options, Events],
  8. options: {
  9. "naviMode" : false,
  10. "style": "default",
  11. "width": "1230",
  12. "type": "type_1_0",
  13. "categoryId" : ""
  14. },
  15. initialize : function( container, app, explorer, options ){
  16. this.setOptions(options);
  17. if( !this.options.type )this.options.type = "type_1_0";
  18. this.container = container;
  19. this.app = app;
  20. this.lp = app.lp;
  21. this.actions = app.restActions;
  22. this.explorer = explorer;
  23. this.path = "/x_component_Forum/$ColumnTemplate/";
  24. this.cssPath = "/x_component_Forum/$ColumnTemplate/" + this.options.style + "/css.wcss";
  25. this._loadCss();
  26. },
  27. load: function(){
  28. this.loadSetting();
  29. this.loadView();
  30. },
  31. _loadSetting: function(){
  32. var path = "/x_component_Forum/$ColumnTemplate/template/setting.json";
  33. var templateSetting;
  34. if (MWF.xApplication.Forum.ColumnTemplate.Setting){
  35. templateSetting = MWF.xApplication.Forum.ColumnTemplate.Setting;
  36. }else{
  37. var r = new Request.JSON({
  38. url: path,
  39. secure: false,
  40. async: false,
  41. method: "get",
  42. noCache: false,
  43. onSuccess: function(responseJSON, responseText){
  44. templateSetting = MWF.xApplication.Forum.ColumnTemplate.Setting = responseJSON;
  45. }.bind(this),
  46. onError: function(text, error){
  47. alert(error + text);
  48. }
  49. });
  50. r.send();
  51. }
  52. return templateSetting;
  53. },
  54. loadSetting: function(){
  55. var setting = this._loadSetting();
  56. this.setting = setting[this.options.type];
  57. },
  58. loadView: function(){
  59. this.view = new MWF.xApplication.Forum.ColumnTemplate.View(this.container, this.app, this, {
  60. setting : this.setting,
  61. templateUrl: this.setting.template,
  62. categoryId: this.options.categoryId,
  63. onPostCreateViewBody : function(){
  64. this.fireEvent("postLoad");
  65. }.bind(this)
  66. }, {
  67. css: this.css
  68. });
  69. this.view.load();
  70. }
  71. });
  72. MWF.xApplication.Forum.ColumnTemplate.View = new Class({
  73. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  74. _createDocument: function (data, index) {
  75. if( this.app.access.isSectionViewer( data ) ){
  76. return new MWF.xApplication.Forum.ColumnTemplate.Document(this.viewNode, data, this.explorer, this, null, index);
  77. }
  78. },
  79. _getCurrentPageData: function (callback, count) {
  80. if (!count)count = 20;
  81. var id = (this.items.length) ? this.items[this.items.length - 1].data.id : "(0)";
  82. var filter = this.filterData || {};
  83. this.actions.listSection(this.options.categoryId, function (json) {
  84. if( !json.data )json.data = [];
  85. if (callback)callback(json);
  86. }.bind(this))
  87. },
  88. _removeDocument: function (documentData, all) {
  89. //this.actions.deleteSchedule(documentData.id, function(json){
  90. // this.reload();
  91. // this.app.notice(this.app.lp.deleteDocumentOK, "success");
  92. //}.bind(this));
  93. },
  94. _create: function () {
  95. },
  96. _openDocument: function (documentData) {
  97. },
  98. _queryCreateViewNode: function () {
  99. },
  100. _postCreateViewNode: function (viewNode) {
  101. },
  102. _queryCreateViewHead: function () {
  103. },
  104. _postCreateViewHead: function (headNode) {
  105. }
  106. });
  107. MWF.xApplication.Forum.ColumnTemplate.Document = new Class({
  108. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  109. mouseoverDocument: function () {
  110. //this.node.getElements("[styles='itemTitleNode']").setStyles(this.css["itemTitleNode_over"]);
  111. //this.node.getElements("[styles='itemIconNode']").setStyles(this.css["itemIconNode_over"]);
  112. //this.node.getElements("[styles='itemStatNode']").setStyles(this.css["itemStatNode_over"]);
  113. },
  114. mouseoutDocument: function () {
  115. //this.node.getElements("[styles='itemTitleNode']").setStyles(this.css["itemTitleNode"]);
  116. //this.node.getElements("[styles='itemIconNode']").setStyles(this.css["itemIconNode"]);
  117. //this.node.getElements("[styles='itemStatNode']").setStyles(this.css["itemStatNode"]);
  118. },
  119. _queryCreateDocumentNode: function (itemData) {
  120. },
  121. _postCreateDocumentNode: function (itemNode, itemData) {
  122. var personNode = itemNode.getElements("[item='moderatorNames']")[0];
  123. if(personNode)this.createPersonNode( personNode, itemData.moderatorNames );
  124. var _self = this;
  125. var setting = this.view.options.setting;
  126. var columnCount = setting.column;
  127. if( (this.index + 1) % columnCount == 0 ){
  128. itemNode.setStyle("margin-right" , "0px" );
  129. }
  130. if( setting.hasBorder ){
  131. this.container.setStyle("padding-bottom", "10px");
  132. }
  133. if( setting.image ){
  134. this._loadImage( itemNode );
  135. }
  136. this._loadSubjectList( itemNode );
  137. },
  138. _loadSubjectList: function( itemNode ){
  139. var listNode = itemNode.getElements("[item='itemListNode']")[0];
  140. var replyListNode = itemNode.getElements("[item='itemReplyListNode']")[0];
  141. if (listNode) {
  142. this._getListData(function (json) {
  143. json.data.each(function (d,i) {
  144. var div = new Element("div", {
  145. "styles": this.css.itemListItemNode,
  146. "text": d.title,
  147. "title": d.title
  148. }).inject(listNode);
  149. div.addEvents({
  150. "mouseover": function () {
  151. this.node.setStyles(this.obj.css.itemListItemNode_over)
  152. }.bind({node: div, obj: this}),
  153. "mouseout": function () {
  154. this.node.setStyles(this.obj.css.itemListItemNode)
  155. }.bind({node: div, obj: this}),
  156. "click" : function(){
  157. var appId = "ForumDocument"+this.da.id;
  158. if (this.obj.app.desktop.apps[appId]){
  159. this.obj.app.desktop.apps[appId].setCurrent();
  160. }else {
  161. this.obj.app.desktop.openApplication(null, "ForumDocument", {
  162. "sectionId" : this.da.sectionId,
  163. "id" : this.da.id,
  164. "appId": appId,
  165. "isEdited" : false,
  166. "isNew" : false,
  167. "index" : i
  168. });
  169. }
  170. }.bind({da: d, obj: this})
  171. });
  172. if(replyListNode){
  173. var replyNode = new Element("div", {
  174. "styles": this.css.itemReplyListItemNode
  175. }).inject(replyListNode);
  176. var div = new Element("div", {
  177. "styles": this.css.itemReplyPersonNode,
  178. "text": ( d.creatorName || "" ).split("@")[0]
  179. }).inject(replyNode);
  180. div.addEvents({
  181. "mouseover": function () {
  182. this.node.setStyles(this.obj.css.itemReplyPersonNode_over)
  183. }.bind({node: div, obj: this}),
  184. "mouseout": function () {
  185. this.node.setStyles(this.obj.css.itemReplyPersonNode)
  186. }.bind({node: div, obj: this}),
  187. "click" : function(){
  188. this.obj.app.openPerson( this.userName );
  189. }.bind( {userName : d.creatorName, obj:this} )
  190. });
  191. var div = new Element("div", {
  192. "styles": this.css.itemReplyTimeNode,
  193. "text": MWFForum.getDateDiff(d.latestReplyTime),
  194. "title": d.latestReplyTime
  195. }).inject(replyNode);
  196. }
  197. }.bind(this))
  198. }.bind(this), this.view.options.setting.itemCount)
  199. }
  200. },
  201. _loadImage: function( itemNode ){
  202. var _self = this;
  203. var imageNode = itemNode.getElements("[item='itemImage']")[0];
  204. var filterData = {
  205. "sectionId": this.data.id,
  206. "needPicture" : true
  207. };
  208. if(imageNode){
  209. this.actions.listSubjectForBBSIndex(1, 1, filterData, function( json ){
  210. if( json.data ){
  211. var d = json.data[0];
  212. this.node.set("title", d.title);
  213. if(d.picId){
  214. this.node.set("src", MWF.xDesktop.getImageSrc(d.picId) );
  215. this.node.setStyle("cursor", "pointer");
  216. }
  217. this.node.addEvents({
  218. "click": function () {
  219. var appId = "ForumDocument" + this.da.id;
  220. if (_self.app.desktop.apps[appId]) {
  221. _self.app.desktop.apps[appId].setCurrent();
  222. } else {
  223. _self.app.desktop.openApplication(null, "ForumDocument", {
  224. "sectionId": this.da.sectionId,
  225. "id": this.da.id,
  226. "appId": appId,
  227. "isEdited": false,
  228. "isNew": false
  229. });
  230. }
  231. }.bind({da: d})
  232. })
  233. }
  234. }.bind({ node : imageNode }))
  235. }
  236. },
  237. _getListData: function (callback, count) {
  238. if (!count)count = 6;
  239. var filterData = {
  240. "sectionId": this.data.id
  241. };
  242. this.actions.listSubjectForBBSIndex(1, count, filterData, function (json) {
  243. if (!json.data)json.data = [];
  244. if (callback)callback(json);
  245. }.bind(this))
  246. },
  247. removeCenterWork: function (itemData) {
  248. //if(isAdmin){
  249. // return true;
  250. //}
  251. return false;
  252. },
  253. openSection : function( el ){
  254. if( this.explorer.options.naviMode && this.explorer.forumNavi ){
  255. this.explorer.forumNavi.goto( MWFForum.NaviType.section, this.data.id );
  256. }else {
  257. var appId = "ForumSection"+ this.data.id;
  258. if (this.app.desktop.apps[appId]){
  259. this.app.desktop.apps[appId].setCurrent();
  260. }else {
  261. this.app.desktop.openApplication(el, "ForumSection", {
  262. "sectionId": this.data.id,
  263. "appId": appId
  264. });
  265. }
  266. }
  267. },
  268. openPerson : function( userName ){
  269. var appId = "ForumPerson"+userName;
  270. if (this.app.desktop.apps[appId]){
  271. this.app.desktop.apps[appId].setCurrent();
  272. }else {
  273. this.app.desktop.openApplication(null, "ForumPerson", {
  274. "personName" : userName,
  275. "appId": appId
  276. });
  277. }
  278. },
  279. createPersonNode : function( container, personName ){
  280. var persons = personName.split(",");
  281. persons.each( function(userName, i){
  282. var span = new Element("span", {
  283. "text" : userName.split('@')[0],
  284. "styles" : this.css.person
  285. }).inject(container);
  286. span.addEvents( {
  287. mouseover : function(){ this.node.setStyles( this.obj.css.person_over )}.bind( {node:span, obj:this} ),
  288. mouseout : function(){ this.node.setStyles( this.obj.css.person )}.bind( {node:span, obj:this} ),
  289. click : function(){ this.obj.openPerson( this.userName ) }.bind( {userName:userName, obj:this} )
  290. });
  291. if( i != persons.length - 1 ){
  292. new Element("span", {
  293. "text" : "、"
  294. }).inject(container);
  295. }
  296. }.bind(this))
  297. }
  298. });