ColumnTemplate.js 14 KB

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