Mobile.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. MWF.xApplication.Forum = MWF.xApplication.Forum || {};
  2. MWF.xApplication.ForumDocument = MWF.xApplication.ForumDocument || {};
  3. MWF.xDesktop.requireApp("Template", "Explorer", null, false);
  4. MWF.xApplication.ForumDocument.Mobile = new Class({
  5. Implements: [Options, Events],
  6. options: {
  7. "id" : "",
  8. "sectionId" : "",
  9. "viewPageNum" : 1,
  10. "replyIndex" : null,
  11. "isNew": false,
  12. "isEdited" : false
  13. },
  14. initialize: function (node, app, actions, lp, css, options) {
  15. this.setOptions(options);
  16. this.app = app;
  17. this.node = $(node);
  18. this.actions = actions;
  19. this.lp = lp;
  20. this.css = css;
  21. this.path = "/x_component_ForumDocument/$Mobile/default/";
  22. },
  23. load: function () {
  24. this.actions.login( {}, function( json ){
  25. this.actions.listSubjectPermission( this.options.id, function( permission ){
  26. this.permission = permission.data;
  27. this.actions.getSubjectView( this.options.id , function( data ){
  28. this.data = data.data.currentSubject;
  29. this.options.sectionId = this.data.sectionId;
  30. this.createMiddleNode();
  31. }.bind(this))
  32. }.bind(this))
  33. }.bind(this))
  34. },
  35. createMiddleNode: function(){
  36. this.middleNode = new Element("div.middleNode", {
  37. "styles": this.css.middleNode
  38. }).inject(this.node);
  39. this.subjectConainer = new Element("div.subjectConainer",{
  40. "styles" : this.css.subjectConainer
  41. }).inject( this.middleNode );
  42. this.replyViewConainer = new Element("div.replyViewConainer",{
  43. "styles" : this.css.replyViewConainer
  44. }).inject( this.middleNode );
  45. //this.createPagingBar();
  46. this.createSubject();
  47. this.createReplyView();
  48. },
  49. createSubject : function(){
  50. this.subjectView = new MWF.xApplication.ForumDocument.Mobile.SubjectView( this.subjectConainer, this.app, this, {
  51. templateUrl : this.path + "listItemSubject.json",
  52. scrollEnable : false
  53. } )
  54. this.subjectView.data = this.data;
  55. this.subjectView.load();
  56. },
  57. createReplyView : function(){
  58. new Element("div.itemReplyTitle", {
  59. styles : this.css.itemReplyTitle,
  60. text : this.lp.reply
  61. }).inject(this.replyViewConainer);
  62. this.replyView = new MWF.xApplication.ForumDocument.Mobile.ReplyView( this.replyViewConainer, this.app, this, {
  63. templateUrl : this.path + "listItemReply.json",
  64. scrollEnable : false,
  65. pagingEnable : true,
  66. documentKeyWord : "orderNumber",
  67. pagingPar : {
  68. currentPage : this.options.viewPageNum || 1,
  69. countPerPage : 10,
  70. hasPrevPage : true,
  71. hasTruningBar : false,
  72. onPostLoad : function(){
  73. if( this.replyView.getCurrentPageNum() == 1 ){
  74. if( this.replyView.paging && this.replyView.paging.nextPageNode)this.replyView.paging.nextPageNode.setStyle("width","99%");
  75. }else if( this.replyView.getCurrentPageNum() == this.replyView.getPageSize() ){
  76. if( this.replyView.paging && this.replyView.paging.prevPageNode)this.replyView.paging.prevPageNode.setStyle("width","99%");
  77. }else{
  78. if( this.replyView.paging && this.replyView.paging.prevPageNode)this.replyView.paging.prevPageNode.setStyle("width","49%");
  79. if( this.replyView.paging && this.replyView.paging.nextPageNode)this.replyView.paging.nextPageNode.setStyle("width","49%");
  80. }
  81. }.bind(this)
  82. }
  83. } )
  84. this.replyView.data = this.data;
  85. this.replyView.filterData = { "subjectId" : this.data.id };
  86. this.replyView.load();
  87. },
  88. getDateDiff: function (publishTime) {
  89. var dateTimeStamp = Date.parse(publishTime.replace(/-/gi, "/"));
  90. var minute = 1000 * 60;
  91. var hour = minute * 60;
  92. var day = hour * 24;
  93. var halfamonth = day * 15;
  94. var month = day * 30;
  95. var year = month * 12;
  96. var now = new Date().getTime();
  97. var diffValue = now - dateTimeStamp;
  98. if (diffValue < 0) {
  99. //若日期不符则弹出窗口告之
  100. //alert("结束日期不能小于开始日期!");
  101. }
  102. var yesterday = new Date().decrement('day', 1);
  103. var beforYesterday = new Date().decrement('day', 2);
  104. var yearC = diffValue / year;
  105. var monthC = diffValue / month;
  106. var weekC = diffValue / (7 * day);
  107. var dayC = diffValue / day;
  108. var hourC = diffValue / hour;
  109. var minC = diffValue / minute;
  110. if (yesterday.getFullYear() == dateTimeStamp.getFullYear() && yesterday.getMonth() == dateTimeStamp.getMonth() && yesterday.getDate() == dateTimeStamp.getDate()) {
  111. result = "昨天 " + dateTimeStamp.getHours() + ":" + dateTimeStamp.getMinutes();
  112. } else if (beforYesterday.getFullYear() == dateTimeStamp.getFullYear() && beforYesterday.getMonth() == dateTimeStamp.getMonth() && beforYesterday.getDate() == dateTimeStamp.getDate()) {
  113. result = "前天 " + dateTimeStamp.getHours() + ":" + dateTimeStamp.getMinutes();
  114. } else if (yearC > 1) {
  115. result = dateTimeStamp.getFullYear() + "年" + (dateTimeStamp.getMonth() + 1) + "月" + dateTimeStamp.getDate() + "日";
  116. } else if (monthC >= 1) {
  117. //result= parseInt(monthC) + "个月前";
  118. // s.getFullYear()+"年";
  119. result = (dateTimeStamp.getMonth() + 1) + "月" + dateTimeStamp.getDate() + "日";
  120. } else if (weekC >= 1) {
  121. result = parseInt(weekC) + "周前";
  122. } else if (dayC >= 1) {
  123. result = parseInt(dayC) + "天前";
  124. } else if (hourC >= 1) {
  125. result = parseInt(hourC) + "小时前";
  126. } else if (minC >= 1) {
  127. result = parseInt(minC) + "分钟前";
  128. } else
  129. result = "刚才";
  130. return result;
  131. }
  132. });
  133. MWF.xApplication.ForumDocument.Mobile.SubjectView = new Class({
  134. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  135. _createDocument: function(data, index){
  136. data.index = index;
  137. this.getUserData( data.creatorName, function(json ){
  138. data.userIcon = json.data.icon;
  139. return new MWF.xApplication.ForumDocument.Mobile.SubjectDocument(this.viewNode, data, this.explorer, this, null, data.index );
  140. //this.actions.getUserInfor( {"userName":data.creatorName}, function( json ){
  141. // data.subject = json.data.subjectCount;
  142. // data.reply = json.data.replyCount;
  143. // data.todaySubject = json.data.subjectCountToday;
  144. // data.todayReply = json.data.replyCountToday;
  145. // data.prime = json.data.creamCount;
  146. // data.accessed = json.data.popularity;
  147. // return new MWF.xApplication.ForumDocument.SubjectDocument(this.viewNode, data, this.explorer, this, null, data.index );
  148. //}.bind(this))
  149. }.bind(this) )
  150. },
  151. getUserData : function( name, callback ){
  152. this.actions.getPerson( function( json ){
  153. if( callback )callback( json );
  154. }.bind(this), null, name, true )
  155. },
  156. _getCurrentPageData: function(callback, count){
  157. var json = {
  158. type: "success",
  159. count : 1,
  160. size : 1,
  161. data : [this.data]
  162. };
  163. if (callback)callback(json)
  164. },
  165. _removeDocument: function(documentData, all){
  166. this.actions.deleteSection(documentData.id, function(json){
  167. this.reload();
  168. this.app.notice(this.app.lp.deleteDocumentOK, "success");
  169. }.bind(this));
  170. },
  171. _create: function(){
  172. },
  173. _queryCreateViewNode: function(){
  174. },
  175. _postCreateViewNode: function( viewNode ){
  176. },
  177. _queryCreateViewHead:function(){
  178. },
  179. _postCreateViewHead: function( headNode ){
  180. }
  181. })
  182. MWF.xApplication.ForumDocument.Mobile.SubjectDocument = new Class({
  183. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  184. mouseoverSubject : function(subjectNode, ev){
  185. },
  186. mouseoutSubject : function(subjectNode, ev){
  187. },
  188. _queryCreateDocumentNode:function( itemData ){
  189. },
  190. _postCreateDocumentNode: function( itemNode, itemData ){
  191. },
  192. createReply : function(itemNode, ev ){
  193. var form = new MWF.xApplication.ForumDocument.ReplyForm(this, {}, {
  194. "toMain" : true,
  195. onPostOk : function( id ){
  196. this.app.postCreateReply( id )
  197. }.bind(this)
  198. })
  199. form.mainData = this.data;
  200. form.create()
  201. }
  202. })
  203. MWF.xApplication.ForumDocument.Mobile.ReplyView = new Class({
  204. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  205. _createDocument: function(data, index){
  206. data.index = index;
  207. return new MWF.xApplication.ForumDocument.Mobile.ReplyDocument(this.viewNode, data, this.explorer, this, null, data.index );
  208. },
  209. _getCurrentPageData: function(callback, count, pageNum){
  210. this.clearBody();
  211. if(!count)count=10;
  212. if(!pageNum)pageNum = 1;
  213. if( pageNum == 1 ){
  214. this.explorer.subjectConainer.setStyle("display","block");
  215. }else{
  216. this.explorer.subjectConainer.setStyle("display","none");
  217. }
  218. var filter = this.filterData || {};
  219. this.actions.listReplyFilterPage( pageNum, count, filter, function(json){
  220. if( !json.data )json.data = [];
  221. if( !json.count )json.count=0;
  222. if( callback )callback(json);
  223. }.bind(this))
  224. },
  225. _removeDocument: function(documentData, all){
  226. this.actions.deleteReply( documentData.id, function(){
  227. this.reload();
  228. this.app.notice( this.lp.deleteReplySuccess, "ok")
  229. }.bind(this) )
  230. },
  231. _create: function(){
  232. },
  233. _queryCreateViewNode: function(){
  234. },
  235. _postCreateViewNode: function( viewNode ){
  236. },
  237. _queryCreateViewHead:function(){
  238. },
  239. _postCreateViewHead: function( headNode ){
  240. }
  241. })
  242. MWF.xApplication.ForumDocument.Mobile.ReplyDocument = new Class({
  243. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  244. mouseoverSubject : function(subjectNode, ev){
  245. },
  246. mouseoutSubject : function(subjectNode, ev){
  247. },
  248. getUserData : function( name, callback ){
  249. this.actions.getPerson( function( json ){
  250. if( callback )callback( json );
  251. }.bind(this), null, name, true )
  252. },
  253. _queryCreateDocumentNode:function( itemData ){
  254. },
  255. _postCreateDocumentNode: function( itemNode, itemData ){
  256. if( itemData.parentId && itemData.parentId != "" ){
  257. var quoteContainer = itemNode.getElements( "[item='quoteContent']" )[0];
  258. this.actions.getReply( itemData.parentId, function( json ){
  259. var data = this.parentData = json.data;
  260. var quoteContent = new Element("div", { "styles" : this.css.itemQuote }).inject(quoteContainer)
  261. var content = quoteContent.set("html", data.content).get("text");
  262. quoteContent.empty();
  263. data.contentText = content;
  264. //new Element( "div", {styles : this.css.quoteLeft} ).inject( quoteContent );
  265. var quoteArea = new Element( "div", {styles : this.css.quoteArea } ).inject( quoteContent );
  266. var quoteInfor = new Element( "div", {
  267. styles : this.css.quoteInfor,
  268. text : this.lp.replyTo + " " + data.orderNumber + this.lp.floor + " " + data.creatorName + " " + data.createTime
  269. }).inject( quoteArea );
  270. new Element( "div", {
  271. styles : this.css.quoteText,
  272. text : content.length > 100 ? (content.substr(0, 100) + "...") : content
  273. }).inject( quoteArea );
  274. //new Element( "div", {styles : this.css.quoteRight} ).inject( quoteContent );
  275. }.bind(this) , function( json ){
  276. new Element( "div" , {
  277. "styles" : this.css.replyBeinngDelete,
  278. "text" : this.lp.quoteReplyBeingDeleted
  279. }).inject(quoteContainer)
  280. }.bind(this)
  281. )
  282. }
  283. var userIcon = itemNode.getElements( "[item='userIcon']" )[0];
  284. this.getUserData( itemData.creatorName, function(json ){
  285. userIcon.src = "data:image/png;base64,"+json.data.icon;
  286. }.bind(this) );
  287. },
  288. createReply : function(itemNode, ev ){ // 对回复进行回复
  289. var ua = navigator.userAgent.toLowerCase();
  290. if (/iphone|ipad|ipod/.test(ua)) {
  291. window.webkit.messageHandlers.ReplyAction.postMessage({body:this.data.id});
  292. } else if (/android/.test(ua)) {
  293. window.o2bbs.reply( this.data.id );
  294. }
  295. }
  296. })