Mobile.js 14 KB

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