Mobile.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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. if( this.data.typeCategory == this.lp.question ){
  43. this.satisfiedReplyViewConainer = new Element("div.satisfiedReplyViewConainer",{
  44. "styles" : this.css.replyViewConainer
  45. }).inject( this.middleNode );
  46. }
  47. this.replyViewConainer = new Element("div.replyViewConainer",{
  48. "styles" : this.css.replyViewConainer
  49. }).inject( this.middleNode );
  50. //this.createPagingBar();
  51. this.createSubject();
  52. if( this.data.typeCategory == this.lp.question ) {
  53. if( this.data.acceptReplyId ){
  54. this.createSatisfiedReplyView();
  55. }
  56. }
  57. this.createReplyView();
  58. },
  59. createSubject : function(){
  60. this.subjectView = new MWF.xApplication.ForumDocument.Mobile.SubjectView( this.subjectConainer, this.app, this, {
  61. templateUrl : this.path + "listItemSubject.json",
  62. scrollEnable : false
  63. } );
  64. this.subjectView.data = this.data;
  65. this.subjectView.load();
  66. },
  67. showReply : function( id ){
  68. this.replyView.showReply( id );
  69. },
  70. createReplyView : function(){
  71. var itemReplyTitleArea = new Element("div.itemReplyTitleArea", {
  72. styles : this.css.itemReplyTitleArea
  73. }).inject(this.replyViewConainer);
  74. new Element("div.itemReplyTitle", {
  75. styles : this.css.itemReplyTitle,
  76. text : this.lp.allReply + "(" + this.data.replyTotal + ")"
  77. }).inject(itemReplyTitleArea);
  78. this.replyView = new MWF.xApplication.ForumDocument.Mobile.ReplyView( this.replyViewConainer, this.app, this, {
  79. templateUrl : this.path + "listItemReply.json",
  80. scrollEnable : false,
  81. pagingEnable : true,
  82. documentKeyWord : "orderNumber",
  83. pagingPar : {
  84. currentPage : this.options.viewPageNum || 1,
  85. countPerPage : 10,
  86. hasPrevPage : true,
  87. hasTruningBar : false,
  88. onPostLoad : function(){
  89. if( this.replyView.getCurrentPageNum() == 1 ){
  90. if( this.replyView.paging && this.replyView.paging.nextPageNode)this.replyView.paging.nextPageNode.setStyle("width","99%");
  91. }else if( this.replyView.getCurrentPageNum() == this.replyView.getPageSize() ){
  92. if( this.replyView.paging && this.replyView.paging.prevPageNode)this.replyView.paging.prevPageNode.setStyle("width","99%");
  93. }else{
  94. if( this.replyView.paging && this.replyView.paging.prevPageNode)this.replyView.paging.prevPageNode.setStyle("width","49%");
  95. if( this.replyView.paging && this.replyView.paging.nextPageNode)this.replyView.paging.nextPageNode.setStyle("width","49%");
  96. }
  97. }.bind(this)
  98. }
  99. } );
  100. this.replyView.data = this.data;
  101. this.replyView.filterData = { "subjectId" : this.data.id };
  102. this.replyView.load();
  103. },
  104. createSatisfiedReplyView : function( ){
  105. var itemReplyTitleArea = new Element("div.itemReplyTitleArea", {
  106. styles : this.css.itemReplyTitleArea
  107. }).inject(this.satisfiedReplyViewConainer);
  108. new Element("div.itemReplyTitle", {
  109. styles : this.css.itemReplyTitle_accepted,
  110. text : this.lp.satisfiedAnswer
  111. }).inject(itemReplyTitleArea);
  112. this.satisfiedReplyView = new MWF.xApplication.ForumDocument.Mobile.SatisfiedReplyView( this.satisfiedReplyViewConainer, this, this, {
  113. templateUrl : this.path + "listItemSatisfied.json",
  114. scrollEnable : false
  115. } );
  116. this.satisfiedReplyView.data = this.data;
  117. this.satisfiedReplyView.load();
  118. },
  119. getUserIcon: function( name ){
  120. var icon = "";
  121. var url = MWF.Actions.get("x_organization_assemble_personal").getIcon(name);
  122. if( url ){
  123. icon = url;
  124. }else{
  125. icon = "/x_component_ForumDocument/$Main/default/icon/noavatar_big.gif";
  126. }
  127. //MWF.Actions.get("x_organization_assemble_control").getPersonIcon(name, function(url){
  128. // icon = url;
  129. //}.bind(this), function(){
  130. // icon = "/x_component_ForumDocument/$Main/default/icon/noavatar_big.gif";
  131. //});
  132. return icon;
  133. },
  134. getDateDiff: function (publishTime) {
  135. if(!publishTime)return "";
  136. var dateTimeStamp = Date.parse(publishTime.replace(/-/gi, "/"));
  137. var minute = 1000 * 60;
  138. var hour = minute * 60;
  139. var day = hour * 24;
  140. var halfamonth = day * 15;
  141. var month = day * 30;
  142. var year = month * 12;
  143. var now = new Date().getTime();
  144. var diffValue = now - dateTimeStamp;
  145. if (diffValue < 0) {
  146. //若日期不符则弹出窗口告之
  147. //alert("结束日期不能小于开始日期!");
  148. }
  149. var yesterday = new Date().decrement('day', 1);
  150. var beforYesterday = new Date().decrement('day', 2);
  151. var yearC = diffValue / year;
  152. var monthC = diffValue / month;
  153. var weekC = diffValue / (7 * day);
  154. var dayC = diffValue / day;
  155. var hourC = diffValue / hour;
  156. var minC = diffValue / minute;
  157. if (yesterday.getFullYear() == dateTimeStamp.getFullYear() && yesterday.getMonth() == dateTimeStamp.getMonth() && yesterday.getDate() == dateTimeStamp.getDate()) {
  158. result = "昨天 " + dateTimeStamp.getHours() + ":" + dateTimeStamp.getMinutes();
  159. } else if (beforYesterday.getFullYear() == dateTimeStamp.getFullYear() && beforYesterday.getMonth() == dateTimeStamp.getMonth() && beforYesterday.getDate() == dateTimeStamp.getDate()) {
  160. result = "前天 " + dateTimeStamp.getHours() + ":" + dateTimeStamp.getMinutes();
  161. } else if (yearC > 1) {
  162. result = dateTimeStamp.getFullYear() + "-" + (dateTimeStamp.getMonth() + 1) + "-" + dateTimeStamp.getDate() + " " + dateTimeStamp.getHours() + ":" + dateTimeStamp.getMinutes();
  163. } else if (monthC >= 1) {
  164. //result= parseInt(monthC) + "个月前";
  165. // s.getFullYear()+"年";
  166. result = dateTimeStamp.getFullYear() + "-" + (dateTimeStamp.getMonth() + 1) + "-" + dateTimeStamp.getDate() + " " + dateTimeStamp.getHours() + ":" + dateTimeStamp.getMinutes();
  167. } else if (weekC >= 1) {
  168. result = parseInt(weekC) + "周前";
  169. } else if (dayC >= 1) {
  170. result = parseInt(dayC) + "天前";
  171. } else if (hourC >= 1) {
  172. result = parseInt(hourC) + "小时前";
  173. } else if (minC >= 1) {
  174. result = parseInt(minC) + "分钟前";
  175. } else
  176. result = "刚才";
  177. return result;
  178. }
  179. });
  180. MWF.xApplication.ForumDocument.Mobile.SubjectView = new Class({
  181. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  182. _createDocument: function(data, index){
  183. data.index = index;
  184. return new MWF.xApplication.ForumDocument.Mobile.SubjectDocument(this.viewNode, data, this.explorer, this, null, data.index );
  185. //this.getUserData( data.creatorName, function(json ){
  186. // data.userIcon = json.data ? json.data.icon : "";
  187. // return new MWF.xApplication.ForumDocument.Mobile.SubjectDocument(this.viewNode, data, this.explorer, this, null, data.index );
  188. //}.bind(this) )
  189. },
  190. getUserData : function( name, callback ){
  191. MWF.Actions.get("x_organization_assemble_control").getPerson( function( json ){
  192. if( callback )callback( json );
  193. }.bind(this), null, name, true )
  194. },
  195. _getCurrentPageData: function(callback, count){
  196. var json = {
  197. type: "success",
  198. count : 1,
  199. size : 1,
  200. data : [this.data]
  201. };
  202. if (callback)callback(json)
  203. },
  204. _removeDocument: function(documentData, all){
  205. this.actions.deleteSection(documentData.id, function(json){
  206. this.reload();
  207. this.app.notice(this.app.lp.deleteDocumentOK, "success");
  208. }.bind(this));
  209. },
  210. _create: function(){
  211. },
  212. _queryCreateViewNode: function(){
  213. },
  214. _postCreateViewNode: function( viewNode ){
  215. },
  216. _queryCreateViewHead:function(){
  217. },
  218. _postCreateViewHead: function( headNode ){
  219. }
  220. });
  221. MWF.xApplication.ForumDocument.Mobile.SubjectDocument = new Class({
  222. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  223. mouseoverSubject : function(subjectNode, ev){
  224. },
  225. mouseoutSubject : function(subjectNode, ev){
  226. },
  227. _queryCreateDocumentNode:function( itemData ){
  228. },
  229. _postCreateDocumentNode: function( itemNode, itemData ){
  230. var content = itemNode.getElements( "[item='content']" )[0];
  231. content.getElements("img").each( function( img ){
  232. img.setStyles({
  233. "height": "auto",
  234. "max-width" : "100%"
  235. });
  236. }.bind(this));
  237. if( this.data.typeCategory == this.lp.vote ){
  238. var voteArea = itemNode.getElement("[item='vote']");
  239. MWF.xDesktop.requireApp("ForumDocument", "Vote", function(){
  240. this.vote = new MWF.xApplication.ForumDocument.Vote(voteArea, this.app, {
  241. isNew : false,
  242. isEdited : false
  243. }, this.data);
  244. this.vote.load();
  245. }.bind(this), true)
  246. }
  247. },
  248. createReply : function(itemNode, ev ){
  249. var form = new MWF.xApplication.ForumDocument.ReplyForm(this, {}, {
  250. "toMain" : true,
  251. onPostOk : function( id ){
  252. this.app.postCreateReply( id )
  253. }.bind(this)
  254. });
  255. form.mainData = this.data;
  256. form.create()
  257. }
  258. });
  259. MWF.xApplication.ForumDocument.Mobile.ReplyView = new Class({
  260. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  261. showReply: function( id ){
  262. this.actions.getReply( id, function( json ){
  263. new MWF.xApplication.ForumDocument.Mobile.ReplyDocument(this.viewNode, json.data, this.explorer, this, null, null );
  264. }.bind(this) )
  265. },
  266. _createDocument: function(data, index){
  267. data.index = index;
  268. return new MWF.xApplication.ForumDocument.Mobile.ReplyDocument(this.viewNode, data, this.explorer, this, null, data.index );
  269. },
  270. _getCurrentPageData: function(callback, count, pageNum){
  271. this.clearBody();
  272. if(!count)count=10;
  273. if(!pageNum)pageNum = 1;
  274. if( pageNum == 1 ){
  275. this.explorer.subjectConainer.setStyle("display","block");
  276. if( this.explorer.satisfiedReplyViewConainer )this.explorer.satisfiedReplyViewConainer.setStyle("display","block");
  277. }else{
  278. this.explorer.subjectConainer.setStyle("display","none");
  279. if( this.explorer.satisfiedReplyViewConainer )this.explorer.satisfiedReplyViewConainer.setStyle("display","none");
  280. }
  281. var filter = this.filterData || {};
  282. this.actions.listReplyFilterPage( pageNum, count, filter, function(json){
  283. if( !json.data )json.data = [];
  284. if( !json.count )json.count=0;
  285. if( callback )callback(json);
  286. }.bind(this))
  287. },
  288. _removeDocument: function(documentData, all){
  289. this.actions.deleteReply( documentData.id, function(){
  290. this.reload();
  291. this.app.notice( this.lp.deleteReplySuccess, "ok")
  292. }.bind(this) )
  293. },
  294. _create: function(){
  295. },
  296. _queryCreateViewNode: function(){
  297. },
  298. _postCreateViewNode: function( viewNode ){
  299. },
  300. _queryCreateViewHead:function(){
  301. },
  302. _postCreateViewHead: function( headNode ){
  303. }
  304. });
  305. MWF.xApplication.ForumDocument.Mobile.ReplyDocument = new Class({
  306. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  307. mouseoverSubject : function(subjectNode, ev){
  308. },
  309. mouseoutSubject : function(subjectNode, ev){
  310. },
  311. getUserData : function( name, callback ){
  312. MWF.Actions.get("x_organization_assemble_control").getPerson( function( json ){
  313. if( callback )callback( json );
  314. }.bind(this), null, name, true )
  315. },
  316. _queryCreateDocumentNode:function( itemData ){
  317. },
  318. _postCreateDocumentNode: function( itemNode, itemData ){
  319. var content = itemNode.getElements( "[item='content']" )[0];
  320. content.getElements("img").each( function( img ){
  321. img.setStyles({
  322. "height": "auto",
  323. "max-width" : "100%"
  324. });
  325. }.bind(this));
  326. if( itemData.parentId && itemData.parentId != "" ){
  327. var quoteContainer = itemNode.getElements( "[item='quoteContent']" )[0];
  328. this.actions.getReply( itemData.parentId, function( json ){
  329. var data = this.parentData = json.data;
  330. var quoteContent = new Element("div", { "styles" : this.css.itemQuote }).inject(quoteContainer);
  331. var content = quoteContent.set("html", data.content).get("text");
  332. quoteContent.empty();
  333. data.contentText = content;
  334. //new Element( "div", {styles : this.css.quoteLeft} ).inject( quoteContent );
  335. var quoteArea = new Element( "div", {styles : this.css.quoteArea } ).inject( quoteContent );
  336. var quoteInfor = new Element( "div", {
  337. styles : this.css.quoteInfor,
  338. text : this.lp.replyTo + " " + data.orderNumber + this.lp.floor + " " + data.creatorName.split("@")[0] + " " + data.createTime
  339. }).inject( quoteArea );
  340. new Element( "div", {
  341. styles : this.css.quoteText,
  342. text : content.length > 100 ? (content.substr(0, 100) + "...") : content
  343. }).inject( quoteArea );
  344. //new Element( "div", {styles : this.css.quoteRight} ).inject( quoteContent );
  345. }.bind(this) , function( json ){
  346. new Element( "div" , {
  347. "styles" : this.css.replyBeinngDelete,
  348. "text" : this.lp.quoteReplyBeingDeleted
  349. }).inject(quoteContainer)
  350. }.bind(this)
  351. )
  352. }
  353. //var userIcon = itemNode.getElements( "[item='userIcon']" )[0];
  354. //this.getUserData( itemData.creatorName, function(json ){
  355. // userIcon.src = "data:image/png;base64,"+json.data.icon;
  356. //}.bind(this) );
  357. },
  358. createReply : function(itemNode, ev ){ // 对回复进行回复
  359. var ua = navigator.userAgent.toLowerCase();
  360. if (/iphone|ipad|ipod/.test(ua)) {
  361. window.webkit.messageHandlers.ReplyAction.postMessage({body:this.data.id});
  362. } else if (/android/.test(ua)) {
  363. window.o2bbs.reply( this.data.id );
  364. }
  365. }
  366. });
  367. MWF.xApplication.ForumDocument.Mobile.SatisfiedReplyView = new Class({
  368. Extends: MWF.xApplication.ForumDocument.Mobile.ReplyView,
  369. _createDocument: function (data, index) {
  370. data.index = index;
  371. return new MWF.xApplication.ForumDocument.Mobile.SatisfiedReplyDocument(this.viewNode, data, this.explorer, this, null, data.index);
  372. },
  373. _getCurrentPageData: function(callback, count, pageNum){
  374. this.clearBody();
  375. if(!count)count=1;
  376. if(!pageNum)pageNum = 1;
  377. var filter = this.filterData || {};
  378. this.actions.getAcceptedReply( this.data.acceptReplyId, function(json){
  379. if( !json.data ){
  380. json.data = [];
  381. }else if( typeOf( json.data ) == "object" ){
  382. json.data = [ json.data ];
  383. json.count = 1;
  384. }
  385. if( !json.count )json.count=0;
  386. if( callback )callback(json);
  387. }.bind(this))
  388. }
  389. });
  390. MWF.xApplication.ForumDocument.Mobile.SatisfiedReplyDocument = new Class({
  391. Extends: MWF.xApplication.ForumDocument.Mobile.ReplyDocument
  392. });