ColumnTemplate.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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. "style": "default",
  10. "width": "1230",
  11. "type": "type_1_0",
  12. "categoryId" : ""
  13. },
  14. initialize : function( container, app, explorer, options ){
  15. this.setOptions(options);
  16. if( !this.options.type )this.options.type = "type_1_0";
  17. this.container = container;
  18. this.app = app;
  19. this.lp = app.lp;
  20. this.actions = app.restActions;
  21. this.explorer = explorer;
  22. this.path = "/x_component_Forum/$ColumnTemplate/";
  23. this.cssPath = "/x_component_Forum/$ColumnTemplate/" + this.options.style + "/css.wcss";
  24. this._loadCss();
  25. },
  26. load: function(){
  27. this.loadSetting();
  28. this.loadView();
  29. },
  30. _loadSetting: function(){
  31. var path = "/x_component_Forum/$ColumnTemplate/template/setting.json";
  32. var templateSetting;
  33. if (MWF.xApplication.Forum.ColumnTemplate.Setting){
  34. templateSetting = MWF.xApplication.Forum.ColumnTemplate.Setting;
  35. }else{
  36. var r = new Request.JSON({
  37. url: path,
  38. secure: false,
  39. async: false,
  40. method: "get",
  41. noCache: false,
  42. onSuccess: function(responseJSON, responseText){
  43. templateSetting = MWF.xApplication.Forum.ColumnTemplate.Setting = responseJSON;
  44. }.bind(this),
  45. onError: function(text, error){
  46. alert(error + text);
  47. }
  48. });
  49. r.send();
  50. }
  51. return templateSetting;
  52. },
  53. loadSetting: function(){
  54. var setting = this._loadSetting();
  55. this.setting = setting[this.options.type];
  56. },
  57. loadView: function(){
  58. this.view = new MWF.xApplication.Forum.ColumnTemplate.View(this.container, this.app, this, {
  59. setting : this.setting,
  60. templateUrl: this.setting.template,
  61. categoryId: this.options.categoryId
  62. }, {
  63. css: this.css
  64. });
  65. this.view.load();
  66. }
  67. });
  68. MWF.xApplication.Forum.ColumnTemplate.View = new Class({
  69. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  70. _createDocument: function (data, index) {
  71. if( this.app.access.isSectionViewer( data ) ){
  72. return new MWF.xApplication.Forum.ColumnTemplate.Document(this.viewNode, data, this.explorer, this, null, index);
  73. }
  74. },
  75. _getCurrentPageData: function (callback, count) {
  76. if (!count)count = 20;
  77. var id = (this.items.length) ? this.items[this.items.length - 1].data.id : "(0)";
  78. var filter = this.filterData || {};
  79. this.actions.listSection(this.options.categoryId, function (json) {
  80. if( !json.data )json.data = [];
  81. if (callback)callback(json);
  82. }.bind(this))
  83. },
  84. _removeDocument: function (documentData, all) {
  85. //this.actions.deleteSchedule(documentData.id, function(json){
  86. // this.reload();
  87. // this.app.notice(this.app.lp.deleteDocumentOK, "success");
  88. //}.bind(this));
  89. },
  90. _create: function () {
  91. },
  92. _openDocument: function (documentData) {
  93. },
  94. _queryCreateViewNode: function () {
  95. },
  96. _postCreateViewNode: function (viewNode) {
  97. },
  98. _queryCreateViewHead: function () {
  99. },
  100. _postCreateViewHead: function (headNode) {
  101. }
  102. });
  103. MWF.xApplication.Forum.ColumnTemplate.Document = new Class({
  104. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  105. mouseoverDocument: function () {
  106. //this.node.getElements("[styles='itemTitleNode']").setStyles(this.css["itemTitleNode_over"]);
  107. //this.node.getElements("[styles='itemIconNode']").setStyles(this.css["itemIconNode_over"]);
  108. //this.node.getElements("[styles='itemStatNode']").setStyles(this.css["itemStatNode_over"]);
  109. },
  110. mouseoutDocument: function () {
  111. //this.node.getElements("[styles='itemTitleNode']").setStyles(this.css["itemTitleNode"]);
  112. //this.node.getElements("[styles='itemIconNode']").setStyles(this.css["itemIconNode"]);
  113. //this.node.getElements("[styles='itemStatNode']").setStyles(this.css["itemStatNode"]);
  114. },
  115. _queryCreateDocumentNode: function (itemData) {
  116. },
  117. _postCreateDocumentNode: function (itemNode, itemData) {
  118. var personNode = itemNode.getElements("[item='moderatorNames']")[0];
  119. if(personNode)this.createPersonNode( personNode, itemData.moderatorNames );
  120. var _self = this;
  121. var setting = this.view.options.setting;
  122. var columnCount = setting.column;
  123. if( (this.index + 1) % columnCount == 0 ){
  124. itemNode.setStyle("margin-right" , "0px" );
  125. }
  126. if( setting.hasBorder ){
  127. this.container.setStyle("padding-bottom", "10px");
  128. }
  129. if( setting.image ){
  130. this._loadImage( itemNode );
  131. }
  132. this._loadSubjectList( itemNode );
  133. },
  134. _loadSubjectList: function( itemNode ){
  135. var listNode = itemNode.getElements("[item='itemListNode']")[0];
  136. var replyListNode = itemNode.getElements("[item='itemReplyListNode']")[0];
  137. if (listNode) {
  138. this._getListData(function (json) {
  139. json.data.each(function (d,i) {
  140. var div = new Element("div", {
  141. "styles": this.css.itemListItemNode,
  142. "text": d.title,
  143. "title": d.title
  144. }).inject(listNode);
  145. div.addEvents({
  146. "mouseover": function () {
  147. this.node.setStyles(this.obj.css.itemListItemNode_over)
  148. }.bind({node: div, obj: this}),
  149. "mouseout": function () {
  150. this.node.setStyles(this.obj.css.itemListItemNode)
  151. }.bind({node: div, obj: this}),
  152. "click" : function(){
  153. var appId = "ForumDocument"+this.da.id;
  154. if (this.obj.app.desktop.apps[appId]){
  155. this.obj.app.desktop.apps[appId].setCurrent();
  156. }else {
  157. this.obj.app.desktop.openApplication(null, "ForumDocument", {
  158. "sectionId" : this.da.sectionId,
  159. "id" : this.da.id,
  160. "appId": appId,
  161. "isEdited" : false,
  162. "isNew" : false,
  163. "index" : i
  164. });
  165. }
  166. }.bind({da: d, obj: this})
  167. });
  168. if(replyListNode){
  169. var replyNode = new Element("div", {
  170. "styles": this.css.itemReplyListItemNode
  171. }).inject(replyListNode);
  172. var div = new Element("div", {
  173. "styles": this.css.itemReplyPersonNode,
  174. "text": ( d.creatorName || "" ).split("@")[0]
  175. }).inject(replyNode);
  176. div.addEvents({
  177. "mouseover": function () {
  178. this.node.setStyles(this.obj.css.itemReplyPersonNode_over)
  179. }.bind({node: div, obj: this}),
  180. "mouseout": function () {
  181. this.node.setStyles(this.obj.css.itemReplyPersonNode)
  182. }.bind({node: div, obj: this}),
  183. "click" : function(){
  184. this.obj.app.openPerson( this.userName );
  185. }.bind( {userName : d.creatorName, obj:this} )
  186. });
  187. var div = new Element("div", {
  188. "styles": this.css.itemReplyTimeNode,
  189. "text": this.getDateDiff(d.createTime),
  190. "title": d.createTime
  191. }).inject(replyNode);
  192. }
  193. }.bind(this))
  194. }.bind(this), this.view.options.setting.itemCount)
  195. }
  196. },
  197. _loadImage: function( itemNode ){
  198. var _self = this;
  199. var imageNode = itemNode.getElements("[item='itemImage']")[0];
  200. var filterData = {
  201. "sectionId": this.data.id,
  202. "needPicture" : true
  203. };
  204. if(imageNode){
  205. this.actions.listSubjectForBBSIndex(1, 1, filterData, function( json ){
  206. if( json.data ){
  207. var d = json.data[0];
  208. this.node.set("title", d.title);
  209. if(d.picId){
  210. this.node.set("src", MWF.xDesktop.getImageSrc(d.picId) );
  211. this.node.setStyle("cursor", "pointer");
  212. }
  213. this.node.addEvents({
  214. "click": function () {
  215. var appId = "ForumDocument" + this.da.id;
  216. if (_self.app.desktop.apps[appId]) {
  217. _self.app.desktop.apps[appId].setCurrent();
  218. } else {
  219. _self.app.desktop.openApplication(null, "ForumDocument", {
  220. "sectionId": this.da.sectionId,
  221. "id": this.da.id,
  222. "appId": appId,
  223. "isEdited": false,
  224. "isNew": false
  225. });
  226. }
  227. }.bind({da: d})
  228. })
  229. }
  230. }.bind({ node : imageNode }))
  231. }
  232. },
  233. _getListData: function (callback, count) {
  234. if (!count)count = 6;
  235. var filterData = {
  236. "sectionId": this.data.id
  237. };
  238. this.actions.listSubjectForBBSIndex(1, count, filterData, function (json) {
  239. if (!json.data)json.data = [];
  240. if (callback)callback(json);
  241. }.bind(this))
  242. },
  243. removeCenterWork: function (itemData) {
  244. //if(isAdmin){
  245. // return true;
  246. //}
  247. return false;
  248. },
  249. openSection : function( el ){
  250. var appId = "ForumSection"+ this.data.id;
  251. if (this.app.desktop.apps[appId]){
  252. this.app.desktop.apps[appId].setCurrent();
  253. }else {
  254. this.app.desktop.openApplication(el, "ForumSection", {
  255. "sectionId": this.data.id,
  256. "appId": appId
  257. });
  258. }
  259. },
  260. openPerson : function( userName ){
  261. var appId = "ForumPerson"+userName;
  262. if (this.app.desktop.apps[appId]){
  263. this.app.desktop.apps[appId].setCurrent();
  264. }else {
  265. this.app.desktop.openApplication(null, "ForumPerson", {
  266. "personName" : userName,
  267. "appId": appId
  268. });
  269. }
  270. },
  271. createPersonNode : function( container, personName ){
  272. var persons = personName.split(",");
  273. persons.each( function(userName, i){
  274. var span = new Element("span", {
  275. "text" : userName.split('@')[0],
  276. "styles" : this.css.person
  277. }).inject(container);
  278. span.addEvents( {
  279. mouseover : function(){ this.node.setStyles( this.obj.css.person_over )}.bind( {node:span, obj:this} ),
  280. mouseout : function(){ this.node.setStyles( this.obj.css.person )}.bind( {node:span, obj:this} ),
  281. click : function(){ this.obj.openPerson( this.userName ) }.bind( {userName:userName, obj:this} )
  282. });
  283. if( i != persons.length - 1 ){
  284. new Element("span", {
  285. "text" : "、"
  286. }).inject(container);
  287. }
  288. }.bind(this))
  289. },
  290. getDateDiff: function (publishTime) {
  291. if(!publishTime)return "";
  292. var dateTimeStamp = Date.parse(publishTime.replace(/-/gi, "/"));
  293. var minute = 1000 * 60;
  294. var hour = minute * 60;
  295. var day = hour * 24;
  296. var halfamonth = day * 15;
  297. var month = day * 30;
  298. var year = month * 12;
  299. var now = new Date().getTime();
  300. var diffValue = now - dateTimeStamp;
  301. if (diffValue < 0) {
  302. //若日期不符则弹出窗口告之
  303. //alert("结束日期不能小于开始日期!");
  304. }
  305. var yesterday = new Date().decrement('day', 1);
  306. var beforYesterday = new Date().decrement('day', 2);
  307. var yearC = diffValue / year;
  308. var monthC = diffValue / month;
  309. var weekC = diffValue / (7 * day);
  310. var dayC = diffValue / day;
  311. var hourC = diffValue / hour;
  312. var minC = diffValue / minute;
  313. if (yesterday.getFullYear() == dateTimeStamp.getFullYear() && yesterday.getMonth() == dateTimeStamp.getMonth() && yesterday.getDate() == dateTimeStamp.getDate()) {
  314. result = "昨天 " + dateTimeStamp.getHours() + ":" + dateTimeStamp.getMinutes();
  315. } else if (beforYesterday.getFullYear() == dateTimeStamp.getFullYear() && beforYesterday.getMonth() == dateTimeStamp.getMonth() && beforYesterday.getDate() == dateTimeStamp.getDate()) {
  316. result = "前天 " + dateTimeStamp.getHours() + ":" + dateTimeStamp.getMinutes();
  317. } else if (yearC > 1) {
  318. result = dateTimeStamp.getFullYear() + "-" + (dateTimeStamp.getMonth() + 1) + "-" + dateTimeStamp.getDate();
  319. } else if (monthC >= 1) {
  320. //result= parseInt(monthC) + "个月前";
  321. // s.getFullYear()+"年";
  322. result = dateTimeStamp.getFullYear() + "-" + (dateTimeStamp.getMonth() + 1) + "-" + dateTimeStamp.getDate();
  323. } else if (weekC >= 1) {
  324. result = parseInt(weekC) + "周前";
  325. } else if (dayC >= 1) {
  326. result = parseInt(dayC) + "天前";
  327. } else if (hourC >= 1) {
  328. result = parseInt(hourC) + "小时前";
  329. } else if (minC >= 1) {
  330. result = parseInt(minC) + "分钟前";
  331. } else
  332. result = "刚刚发表";
  333. return result;
  334. }
  335. });