Main.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. MWF.xApplication.HotArticle = MWF.xApplication.HotArticle || {};
  2. MWF.require("MWF.widget.O2Identity", null, false);
  3. //MWF.xDesktop.requireApp("HotArticle", "Access", null, false);
  4. //MWF.xDesktop.requireApp("HotArticle", "Actions.RestActions", null, false);
  5. MWF.xDesktop.requireApp("Template", "Explorer", null, false);
  6. MWF.xApplication.HotArticle.options = {
  7. multitask: false,
  8. executable: true
  9. };
  10. MWF.xApplication.HotArticle.Main = new Class({
  11. Extends: MWF.xApplication.Common.Main,
  12. Implements: [Options, Events],
  13. options: {
  14. "style": "default",
  15. "name": "HotArticle",
  16. "icon": "icon.png",
  17. "width": "1220",
  18. "height": "700",
  19. "isResize": true,
  20. "isMax": true,
  21. "title": MWF.xApplication.HotArticle.LP.title
  22. },
  23. onQueryLoad: function () {
  24. this.lp = MWF.xApplication.HotArticle.LP;
  25. },
  26. loadApplication: function (callback) {
  27. this.userName = layout.desktop.session.user.distinguishedName;
  28. this.restActions = MWF.Actions.get("x_hotpic_assemble_control"); //new MWF.xApplication.HotArticle.Actions.RestActions();
  29. this.path = "/x_component_HotArticle/$Main/" + this.options.style + "/";
  30. this.createNode();
  31. this.loadApplicationContent();
  32. },
  33. loadController: function (callback) {
  34. //this.access = new MWF.xApplication.HotArticle.Access( this.restActions, this.lp );
  35. if (callback)callback();
  36. },
  37. reload : function(){
  38. this.clearContent();
  39. if( this.explorer ){
  40. this.openSetting( this.explorer.currentNaviItem.retrieve("index") )
  41. }else{
  42. this.loadApplicationLayout();
  43. }
  44. },
  45. isAdmin : function(){
  46. return this.access.isAdmin();
  47. },
  48. createNode: function () {
  49. this.content.setStyle("overflow", "hidden");
  50. this.node = new Element("div", {
  51. "styles": this.css.node
  52. }).inject(this.content);
  53. },
  54. loadApplicationContent: function () {
  55. this.loadController(function () {
  56. this.loadApplicationLayout();
  57. }.bind(this))
  58. },
  59. loadApplicationLayout: function () {
  60. this.contentContainerNode = new Element("div.contentContainerNode", {
  61. "styles": this.css.contentContainerNode
  62. }).inject(this.node);
  63. this.createTopNode();
  64. this.createContainerNode();
  65. },
  66. createTopNode: function () {
  67. this.topContainerNode = new Element("div.topContainerNode", {
  68. "styles": this.css.topContainerNode
  69. }).inject(this.contentContainerNode);
  70. this.topNode = new Element("div.topNode", {
  71. "styles": this.css.topNode
  72. }).inject(this.topContainerNode);
  73. this.topIconNode = new Element("div", {
  74. "styles": this.css.topIconNode
  75. }).inject(this.topNode);
  76. this.topTextNode = new Element("div", {
  77. "styles": this.css.topTextNode,
  78. "text": this.options.title
  79. }).inject(this.topNode);
  80. this.topContentNode = new Element("div", {
  81. "styles": this.css.topContentNode
  82. }).inject(this.topNode);
  83. //this.searchDiv = new Element("div.searchDiv",{
  84. // "styles" : this.css.searchDiv
  85. //}).inject(this.topNode)
  86. //this.searchInput = new Element("input.searchInput",{
  87. // "styles" : this.css.searchInput,
  88. // "value" : this.lp.searchKey,
  89. // "title" : this.lp.searchTitle
  90. //}).inject(this.searchDiv)
  91. //var _self = this;
  92. //this.searchInput.addEvents({
  93. // "focus": function(){
  94. // if (this.value==_self.lp.searchKey) this.set("value", "");
  95. // },
  96. // "blur": function(){if (!this.value) this.set("value", _self.lp.searchKey);},
  97. // "keydown": function(e){
  98. // if (e.code==13){
  99. // this.search();
  100. // e.preventDefault();
  101. // }
  102. // }.bind(this)
  103. //});
  104. //
  105. //this.searchAction = new Element("div.searchAction",{
  106. // "styles" : this.css.searchAction
  107. //}).inject(this.searchDiv);
  108. //this.searchAction.addEvents({
  109. // "click": function(){ this.search(); }.bind(this),
  110. // "mouseover": function(e){
  111. // this.searchAction.setStyles( this.css.searchAction_over2 );
  112. // e.stopPropagation();
  113. // }.bind(this),
  114. // "mouseout": function(){ this.searchAction.setStyles( this.css.searchAction ) }.bind(this)
  115. //});
  116. //this.searchDiv.addEvents( {
  117. // "mouseover" : function(){
  118. // this.searchInput.setStyles( this.css.searchInput_over )
  119. // this.searchAction.setStyles( this.css.searchAction_over )
  120. // }.bind(this),
  121. // "mouseout" : function(){
  122. // this.searchInput.setStyles( this.css.searchInput )
  123. // this.searchAction.setStyles( this.css.searchAction )
  124. // }.bind(this)
  125. //} )
  126. },
  127. createContainerNode: function () {
  128. this.createContent();
  129. },
  130. createContent: function () {
  131. this.middleNode = new Element("div.middleNode", {
  132. "styles": this.css.middleNode
  133. }).inject(this.contentContainerNode);
  134. //MWF.require("MWF.widget.ScrollBar", function () {
  135. // this.scrollBar = new MWF.widget.ScrollBar(this.contentContainerNode, {
  136. // "indent": false,
  137. // "style": "xApp_TaskList",
  138. // "where": "before",
  139. // "distance": 30,
  140. // "friction": 4,
  141. // "axis": {"x": false, "y": true},
  142. // "onScroll": function (y) {
  143. // }
  144. // });
  145. //}.bind(this));
  146. this.contentNode = new Element("div.contentNode", {
  147. "styles": this.css.contentNode
  148. }).inject(this.middleNode);
  149. this.createView();
  150. this.setContentSizeFun = this.setContentSize.bind(this);
  151. this.addEvent("resize", this.setContentSizeFun );
  152. this.setContentSize();
  153. },
  154. setContentSize: function () {
  155. var topSize = this.topNode ? this.topNode.getSize() : {"x": 0, "y": 0};
  156. //var topSize = {"x": 0, "y": 0};
  157. var nodeSize = this.node.getSize();
  158. var pt = this.viewContainerNode.getStyle("padding-top").toFloat();
  159. var pb = this.viewContainerNode.getStyle("padding-bottom").toFloat();
  160. var height = nodeSize.y - topSize.y - pt - pb;
  161. this.viewContainerNode.setStyle("height", "" + height + "px");
  162. },
  163. createView: function () {
  164. var viewContainerNode = this.viewContainerNode = new Element("div.viewContainerNode", {
  165. "styles": this.css.viewContainerNode
  166. }).inject(this.contentNode);
  167. var view = new MWF.xApplication.HotArticle.Main.View(viewContainerNode, this, this, {
  168. templateUrl: this.path + "listItem.json",
  169. "scrollEnable" : true
  170. }, {
  171. lp: this.lp
  172. });
  173. view.load();
  174. },
  175. clearContent: function () {
  176. if (this.explorer)this.explorer.destroy();
  177. this.explorer = null;
  178. if(this.setContentSizeFun)this.removeEvent("resize", this.setContentSizeFun );
  179. if(this.scrollBar && this.scrollBar.scrollVAreaNode)this.scrollBar.scrollVAreaNode.destroy();
  180. if( this.scrollBar )delete this.scrollBar;
  181. if (this.contentContainerNode) {
  182. this.contentContainerNode.destroy();
  183. //this.middleNode.destroy();
  184. //this.contentNode.destroy();
  185. }
  186. },
  187. openCategory : function( d ){
  188. var appId = "HotArticleCategory"+ d.id;
  189. if (this.desktop.apps[appId]){
  190. this.desktop.apps[appId].setCurrent();
  191. }else {
  192. this.desktop.openApplication(null, "HotArticleCategory", {
  193. "categoryId": d.id,
  194. "appId": appId
  195. });
  196. }
  197. },
  198. recordStatus: function () {
  199. var status = {};
  200. if( this.explorer ){
  201. status = {
  202. setting : true,
  203. index : this.explorer.currentNaviItem.retrieve("index")
  204. };
  205. }
  206. return status;
  207. }
  208. });
  209. MWF.xApplication.HotArticle.Main.View = new Class({
  210. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  211. _createDocument: function (data, index) {
  212. return new MWF.xApplication.HotArticle.Main.Document(this.viewNode, data, this.explorer, this, null, index);
  213. },
  214. _getCurrentPageData: function(callback, count, pageNum){
  215. if(!count)count=9;
  216. if(!pageNum){
  217. if( this.pageNum ){
  218. pageNum = this.pageNum = this.pageNum+1;
  219. }else{
  220. pageNum = this.pageNum = 1;
  221. }
  222. }else{
  223. this.pageNum = pageNum;
  224. }
  225. this.getPictureUrlHost();
  226. var filter = this.filterData || {};
  227. //filter.withTopSubject = false;
  228. this.actions.listHotPicFilterPage( pageNum, count, filter, function(json){
  229. if( !json.data )json.data = [];
  230. if( !json.count )json.count=0;
  231. if( callback )callback(json);
  232. }.bind(this))
  233. },
  234. _removeDocument: function (documentData, all) {
  235. this.actions.removeHotPic(documentData.id, function(json){
  236. this.pageNum = 0;
  237. this.reload();
  238. this.app.notice(this.app.lp.deleteDocumentOK, "success");
  239. }.bind(this));
  240. },
  241. _create: function () {
  242. },
  243. _openDocument: function (documentData) {
  244. },
  245. _queryCreateViewNode: function () {
  246. },
  247. _postCreateViewNode: function (viewNode) {
  248. },
  249. _queryCreateViewHead: function () {
  250. },
  251. _postCreateViewHead: function (headNode) {
  252. },
  253. getPictureUrlHost: function() {
  254. var addressObj = layout.serviceAddressList["x_hotpic_assemble_control"];
  255. this.pictureUrlHost = "http://"+addressObj.host + ( addressObj.port != 80 ? (":"+ addressObj.port +"/") : "/" );
  256. }
  257. });
  258. MWF.xApplication.HotArticle.Main.Document = new Class({
  259. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  260. mouseoverDocument : function(itemNode, ev){
  261. var removeNode = itemNode.getElements("[styles='removeNode']")[0];
  262. if( removeNode )removeNode.setStyle("opacity",1)
  263. },
  264. mouseoutDocument : function(itemNode, ev){
  265. var removeNode = itemNode.getElements("[styles='removeNode']")[0];
  266. if( removeNode )removeNode.setStyle("opacity",0)
  267. },
  268. _queryCreateDocumentNode: function (itemData) {
  269. },
  270. _postCreateDocumentNode: function (itemNode, itemData) {
  271. //var iconNode = itemNode.getElements("[item='icon']")[0];
  272. //MWF.getJSON( this.view.pictureUrlHost + iconNode.get("picUrl"), function( json ){
  273. // iconNode.set("src", json.data.value);
  274. //} )
  275. },
  276. getRemovePermission: function( d ){
  277. if( this.app.userName == d.creator ){
  278. return true;
  279. }
  280. //if( d.application == "BBS" && MWF.AC.isBBSManager() ){
  281. // return true;
  282. //}
  283. //if( d.application == "CMS" && MWF.AC.isCMSManager() ){
  284. // return true;
  285. //}
  286. if( MWF.AC.isHotPictureManager() ){
  287. return true;
  288. }
  289. return false;
  290. },
  291. open: function( ){
  292. var data = this.data;
  293. if( data.application == "BBS" ){
  294. var appId = "ForumDocument"+data.infoId;
  295. if (this.app.desktop.apps[appId]){
  296. this.app.desktop.apps[appId].setCurrent();
  297. }else {
  298. this.app.desktop.openApplication(null, "ForumDocument", {
  299. "id" : data.infoId,
  300. "appId": appId,
  301. "isEdited" : false,
  302. "isNew" : false
  303. });
  304. }
  305. }else{
  306. var appId = "cms.Document"+data.infoId;
  307. if (this.app.desktop.apps[appId]){
  308. this.app.desktop.apps[appId].setCurrent();
  309. }else {
  310. this.app.desktop.openApplication(null, "cms.Document", {
  311. "documentId" : data.infoId,
  312. "appId": appId,
  313. "readonly" : true
  314. });
  315. }
  316. }
  317. }
  318. });
  319. var getDateDiff = function (publishTime) {
  320. if(!publishTime)return "";
  321. var dateTimeStamp = Date.parse(publishTime.replace(/-/gi, "/"));
  322. var minute = 1000 * 60;
  323. var hour = minute * 60;
  324. var day = hour * 24;
  325. var halfamonth = day * 15;
  326. var month = day * 30;
  327. var year = month * 12;
  328. var now = new Date().getTime();
  329. var diffValue = now - dateTimeStamp;
  330. if (diffValue < 0) {
  331. //若日期不符则弹出窗口告之
  332. //alert("结束日期不能小于开始日期!");
  333. }
  334. var yesterday = new Date().decrement('day', 1);
  335. var beforYesterday = new Date().decrement('day', 2);
  336. var yearC = diffValue / year;
  337. var monthC = diffValue / month;
  338. var weekC = diffValue / (7 * day);
  339. var dayC = diffValue / day;
  340. var hourC = diffValue / hour;
  341. var minC = diffValue / minute;
  342. if (yesterday.getFullYear() == dateTimeStamp.getFullYear() && yesterday.getMonth() == dateTimeStamp.getMonth() && yesterday.getDate() == dateTimeStamp.getDate()) {
  343. result = "昨天 " + dateTimeStamp.getHours() + ":" + dateTimeStamp.getMinutes();
  344. } else if (beforYesterday.getFullYear() == dateTimeStamp.getFullYear() && beforYesterday.getMonth() == dateTimeStamp.getMonth() && beforYesterday.getDate() == dateTimeStamp.getDate()) {
  345. result = "前天 " + dateTimeStamp.getHours() + ":" + dateTimeStamp.getMinutes();
  346. } else if (yearC > 1) {
  347. result = dateTimeStamp.getFullYear() + "-" + (dateTimeStamp.getMonth() + 1) + "-" + dateTimeStamp.getDate();
  348. } else if (monthC >= 1) {
  349. //result= parseInt(monthC) + "个月前";
  350. // s.getFullYear()+"年";
  351. result = dateTimeStamp.getFullYear() + "-" + (dateTimeStamp.getMonth() + 1) + "-" + dateTimeStamp.getDate();
  352. } else if (weekC >= 1) {
  353. result = parseInt(weekC) + "周前";
  354. } else if (dayC >= 1) {
  355. result = parseInt(dayC) + "天前";
  356. } else if (hourC >= 1) {
  357. result = parseInt(hourC) + "小时前";
  358. } else if (minC >= 1) {
  359. result = parseInt(minC) + "分钟前";
  360. } else
  361. result = "刚刚发表";
  362. return result;
  363. };