Mobile.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. MWF.xApplication.Forum = MWF.xApplication.Forum || {};
  2. MWF.xApplication.ForumDocument = MWF.xApplication.ForumDocument || {};
  3. MWF.xDesktop.requireApp("Forum", "Common", null, false);
  4. MWF.xDesktop.requireApp("Template", "Explorer", null, false);
  5. MWF.xApplication.ForumDocument.Mobile = new Class({
  6. Implements: [Options, Events],
  7. options: {
  8. "id" : "",
  9. "sectionId" : "",
  10. "viewPageNum" : 1,
  11. "replyIndex" : null,
  12. "isNew": false,
  13. "isEdited" : false
  14. },
  15. initialize: function (node, app, actions, lp, css, options) {
  16. this.setOptions(options);
  17. this.app = app;
  18. this.node = $(node);
  19. this.actions = actions;
  20. this.lp = lp;
  21. this.css = css;
  22. this.path = "/x_component_ForumDocument/$Mobile/default/";
  23. },
  24. load: function () {
  25. this.actions.login( {}, function( json ){
  26. this.actions.listSubjectPermission( this.options.id, function( permission ){
  27. this.permission = permission.data;
  28. this.actions.getSubjectView( this.options.id , function( data ){
  29. this.data = data.data.currentSubject;
  30. this.options.sectionId = this.data.sectionId;
  31. this.createMiddleNode();
  32. }.bind(this))
  33. }.bind(this))
  34. }.bind(this))
  35. },
  36. createMiddleNode: function(){
  37. this.middleNode = new Element("div.middleNode", {
  38. "styles": this.css.middleNode
  39. }).inject(this.node);
  40. this.subjectConainer = new Element("div.subjectConainer",{
  41. "styles" : this.css.subjectConainer
  42. }).inject( this.middleNode );
  43. if( this.data.typeCategory == this.lp.question ){
  44. this.satisfiedReplyViewConainer = new Element("div.satisfiedReplyViewConainer",{
  45. "styles" : this.css.replyViewConainer
  46. }).inject( this.middleNode );
  47. }
  48. this.replyViewConainer = new Element("div.replyViewConainer",{
  49. "styles" : this.css.replyViewConainer
  50. }).inject( this.middleNode );
  51. //this.createPagingBar();
  52. this.createSubject();
  53. if( this.data.typeCategory == this.lp.question ) {
  54. if( this.data.acceptReplyId ){
  55. this.createSatisfiedReplyView();
  56. }
  57. }
  58. this.createReplyView();
  59. },
  60. createSubject : function(){
  61. this.subjectView = new MWF.xApplication.ForumDocument.Mobile.SubjectView( this.subjectConainer, this.app, this, {
  62. templateUrl : this.path + "listItemSubject.json",
  63. scrollEnable : false
  64. } );
  65. this.subjectView.data = this.data;
  66. this.subjectView.load();
  67. },
  68. showReply : function( id ){
  69. this.replyView.showReply( id );
  70. },
  71. createReplyView : function(){
  72. var itemReplyTitleArea = new Element("div.itemReplyTitleArea", {
  73. styles : this.css.itemReplyTitleArea
  74. }).inject(this.replyViewConainer);
  75. new Element("div.itemReplyTitle", {
  76. styles : this.css.itemReplyTitle,
  77. text : this.lp.allReply + "(" + this.data.replyTotal + ")"
  78. }).inject(itemReplyTitleArea);
  79. this.replyView = new MWF.xApplication.ForumDocument.Mobile.ReplyView( this.replyViewConainer, this.app, this, {
  80. templateUrl : this.path + "listItemReply.json",
  81. scrollEnable : false,
  82. pagingEnable : true,
  83. documentKeyWord : "orderNumber",
  84. pagingPar : {
  85. currentPage : this.options.viewPageNum || 1,
  86. countPerPage : 10,
  87. hasPrevPage : true,
  88. hasTruningBar : false,
  89. onPostLoad : function(){
  90. if( this.replyView.getCurrentPageNum() == 1 ){
  91. if( this.replyView.paging && this.replyView.paging.nextPageNode)this.replyView.paging.nextPageNode.setStyle("width","99%");
  92. }else if( this.replyView.getCurrentPageNum() == this.replyView.getPageSize() ){
  93. if( this.replyView.paging && this.replyView.paging.prevPageNode)this.replyView.paging.prevPageNode.setStyle("width","99%");
  94. }else{
  95. if( this.replyView.paging && this.replyView.paging.prevPageNode)this.replyView.paging.prevPageNode.setStyle("width","49%");
  96. if( this.replyView.paging && this.replyView.paging.nextPageNode)this.replyView.paging.nextPageNode.setStyle("width","49%");
  97. }
  98. }.bind(this)
  99. }
  100. } );
  101. this.replyView.data = this.data;
  102. this.replyView.filterData = { "subjectId" : this.data.id };
  103. this.replyView.load();
  104. },
  105. createSatisfiedReplyView : function( ){
  106. var itemReplyTitleArea = new Element("div.itemReplyTitleArea", {
  107. styles : this.css.itemReplyTitleArea
  108. }).inject(this.satisfiedReplyViewConainer);
  109. new Element("div.itemReplyTitle", {
  110. styles : this.css.itemReplyTitle_accepted,
  111. text : this.lp.satisfiedAnswer
  112. }).inject(itemReplyTitleArea);
  113. this.satisfiedReplyView = new MWF.xApplication.ForumDocument.Mobile.SatisfiedReplyView( this.satisfiedReplyViewConainer, this, this, {
  114. templateUrl : this.path + "listItemSatisfied.json",
  115. scrollEnable : false
  116. } );
  117. this.satisfiedReplyView.data = this.data;
  118. this.satisfiedReplyView.load();
  119. },
  120. getUserIcon: function( name ){
  121. var icon = "";
  122. var url = MWF.Actions.get("x_organization_assemble_personal").getIcon(name);
  123. if( url ){
  124. icon = url;
  125. }else{
  126. icon = "/x_component_ForumDocument/$Main/default/icon/noavatar_big.gif";
  127. }
  128. //MWF.Actions.get("x_organization_assemble_control").getPersonIcon(name, function(url){
  129. // icon = url;
  130. //}.bind(this), function(){
  131. // icon = "/x_component_ForumDocument/$Main/default/icon/noavatar_big.gif";
  132. //});
  133. return icon;
  134. }
  135. });
  136. MWF.xApplication.ForumDocument.Mobile.SubjectView = new Class({
  137. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  138. _createDocument: function(data, index){
  139. data.index = index;
  140. return new MWF.xApplication.ForumDocument.Mobile.SubjectDocument(this.viewNode, data, this.explorer, this, null, data.index );
  141. //this.getUserData( data.creatorName, function(json ){
  142. // data.userIcon = json.data ? json.data.icon : "";
  143. // return new MWF.xApplication.ForumDocument.Mobile.SubjectDocument(this.viewNode, data, this.explorer, this, null, data.index );
  144. //}.bind(this) )
  145. },
  146. getUserData : function( name, callback ){
  147. MWF.Actions.get("x_organization_assemble_control").getPerson( function( json ){
  148. if( callback )callback( json );
  149. }.bind(this), null, name, true )
  150. },
  151. _getCurrentPageData: function(callback, count){
  152. var json = {
  153. type: "success",
  154. count : 1,
  155. size : 1,
  156. data : [this.data]
  157. };
  158. if (callback)callback(json)
  159. },
  160. _removeDocument: function(documentData, all){
  161. this.actions.deleteSection(documentData.id, function(json){
  162. this.reload();
  163. this.app.notice(this.app.lp.deleteDocumentOK, "success");
  164. }.bind(this));
  165. },
  166. _create: function(){
  167. },
  168. _queryCreateViewNode: function(){
  169. },
  170. _postCreateViewNode: function( viewNode ){
  171. },
  172. _queryCreateViewHead:function(){
  173. },
  174. _postCreateViewHead: function( headNode ){
  175. }
  176. });
  177. MWF.xApplication.ForumDocument.Mobile.SubjectDocument = new Class({
  178. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  179. mouseoverSubject : function(subjectNode, ev){
  180. },
  181. mouseoutSubject : function(subjectNode, ev){
  182. },
  183. _queryCreateDocumentNode:function( itemData ){
  184. },
  185. _postCreateDocumentNode: function( itemNode, itemData ){
  186. var content = itemNode.getElements( "[item='content']" )[0];
  187. content.getElements("img").each( function( img ){
  188. img.setStyles({
  189. "height": "auto",
  190. "max-width" : "100%"
  191. });
  192. }.bind(this));
  193. if( this.data.typeCategory == this.lp.vote ){
  194. var voteArea = itemNode.getElement("[item='vote']");
  195. MWF.xDesktop.requireApp("ForumDocument", "Vote", function(){
  196. this.vote = new MWF.xApplication.ForumDocument.Vote(voteArea, this.app, {
  197. isNew : false,
  198. isEdited : false
  199. }, this.data);
  200. this.vote.load();
  201. }.bind(this), true)
  202. }
  203. },
  204. createReply : function(itemNode, ev ){
  205. var form = new MWF.xApplication.ForumDocument.ReplyForm(this, {}, {
  206. "toMain" : true,
  207. onPostOk : function( id ){
  208. this.app.postCreateReply( id )
  209. }.bind(this)
  210. });
  211. form.mainData = this.data;
  212. form.create()
  213. }
  214. });
  215. MWF.xApplication.ForumDocument.Mobile.ReplyView = new Class({
  216. Extends: MWF.xApplication.Template.Explorer.ComplexView,
  217. showReply: function( id ){
  218. this.actions.getReply( id, function( json ){
  219. new MWF.xApplication.ForumDocument.Mobile.ReplyDocument(this.viewNode, json.data, this.explorer, this, null, null );
  220. }.bind(this) )
  221. },
  222. _createDocument: function(data, index){
  223. data.index = index;
  224. return new MWF.xApplication.ForumDocument.Mobile.ReplyDocument(this.viewNode, data, this.explorer, this, null, data.index );
  225. },
  226. _getCurrentPageData: function(callback, count, pageNum){
  227. this.clearBody();
  228. if(!count)count=10;
  229. if(!pageNum)pageNum = 1;
  230. if( pageNum == 1 ){
  231. this.explorer.subjectConainer.setStyle("display","block");
  232. if( this.explorer.satisfiedReplyViewConainer )this.explorer.satisfiedReplyViewConainer.setStyle("display","block");
  233. }else{
  234. this.explorer.subjectConainer.setStyle("display","none");
  235. if( this.explorer.satisfiedReplyViewConainer )this.explorer.satisfiedReplyViewConainer.setStyle("display","none");
  236. }
  237. var filter = this.filterData || {};
  238. this.actions.listReplyFilterPage( pageNum, count, filter, function(json){
  239. if( !json.data )json.data = [];
  240. if( !json.count )json.count=0;
  241. if( callback )callback(json);
  242. }.bind(this))
  243. },
  244. _removeDocument: function(documentData, all){
  245. this.actions.deleteReply( documentData.id, function(){
  246. this.reload();
  247. this.app.notice( this.lp.deleteReplySuccess, "ok")
  248. }.bind(this) )
  249. },
  250. _create: function(){
  251. },
  252. _queryCreateViewNode: function(){
  253. },
  254. _postCreateViewNode: function( viewNode ){
  255. },
  256. _queryCreateViewHead:function(){
  257. },
  258. _postCreateViewHead: function( headNode ){
  259. }
  260. });
  261. MWF.xApplication.ForumDocument.Mobile.ReplyDocument = new Class({
  262. Extends: MWF.xApplication.Template.Explorer.ComplexDocument,
  263. mouseoverSubject : function(subjectNode, ev){
  264. },
  265. mouseoutSubject : function(subjectNode, ev){
  266. },
  267. getUserData : function( name, callback ){
  268. MWF.Actions.get("x_organization_assemble_control").getPerson( function( json ){
  269. if( callback )callback( json );
  270. }.bind(this), null, name, true )
  271. },
  272. _queryCreateDocumentNode:function( itemData ){
  273. },
  274. _postCreateDocumentNode: function( itemNode, itemData ){
  275. var content = itemNode.getElements( "[item='content']" )[0];
  276. content.getElements("img").each( function( img ){
  277. img.setStyles({
  278. "height": "auto",
  279. "max-width" : "100%"
  280. });
  281. }.bind(this));
  282. if( itemData.parentId && itemData.parentId != "" ){
  283. var quoteContainer = itemNode.getElements( "[item='quoteContent']" )[0];
  284. this.actions.getReply( itemData.parentId, function( json ){
  285. var data = this.parentData = json.data;
  286. var quoteContent = new Element("div", { "styles" : this.css.itemQuote }).inject(quoteContainer);
  287. var content = quoteContent.set("html", data.content).get("text");
  288. quoteContent.empty();
  289. data.contentText = content;
  290. //new Element( "div", {styles : this.css.quoteLeft} ).inject( quoteContent );
  291. var quoteArea = new Element( "div", {styles : this.css.quoteArea } ).inject( quoteContent );
  292. var quoteInfor = new Element( "div", {
  293. styles : this.css.quoteInfor,
  294. text : this.lp.replyTo + " " + data.orderNumber + this.lp.floor + " " + data.creatorName.split("@")[0] + " " + data.createTime
  295. }).inject( quoteArea );
  296. new Element( "div", {
  297. styles : this.css.quoteText,
  298. text : content.length > 100 ? (content.substr(0, 100) + "...") : content
  299. }).inject( quoteArea );
  300. //new Element( "div", {styles : this.css.quoteRight} ).inject( quoteContent );
  301. }.bind(this) , function( json ){
  302. new Element( "div" , {
  303. "styles" : this.css.replyBeinngDelete,
  304. "text" : this.lp.quoteReplyBeingDeleted
  305. }).inject(quoteContainer)
  306. }.bind(this)
  307. )
  308. }
  309. //var userIcon = itemNode.getElements( "[item='userIcon']" )[0];
  310. //this.getUserData( itemData.creatorName, function(json ){
  311. // userIcon.src = "data:image/png;base64,"+json.data.icon;
  312. //}.bind(this) );
  313. },
  314. createReply : function(itemNode, ev ){ // 对回复进行回复
  315. var ua = navigator.userAgent.toLowerCase();
  316. if (/iphone|ipad|ipod/.test(ua)) {
  317. window.webkit.messageHandlers.ReplyAction.postMessage({body:this.data.id});
  318. } else if (/android/.test(ua)) {
  319. window.o2bbs.reply( this.data.id );
  320. }
  321. }
  322. });
  323. MWF.xApplication.ForumDocument.Mobile.SatisfiedReplyView = new Class({
  324. Extends: MWF.xApplication.ForumDocument.Mobile.ReplyView,
  325. _createDocument: function (data, index) {
  326. data.index = index;
  327. return new MWF.xApplication.ForumDocument.Mobile.SatisfiedReplyDocument(this.viewNode, data, this.explorer, this, null, data.index);
  328. },
  329. _getCurrentPageData: function(callback, count, pageNum){
  330. this.clearBody();
  331. if(!count)count=1;
  332. if(!pageNum)pageNum = 1;
  333. var filter = this.filterData || {};
  334. this.actions.getAcceptedReply( this.data.acceptReplyId, function(json){
  335. if( !json.data ){
  336. json.data = [];
  337. }else if( typeOf( json.data ) == "object" ){
  338. json.data = [ json.data ];
  339. json.count = 1;
  340. }
  341. if( !json.count )json.count=0;
  342. if( callback )callback(json);
  343. }.bind(this))
  344. }
  345. });
  346. MWF.xApplication.ForumDocument.Mobile.SatisfiedReplyDocument = new Class({
  347. Extends: MWF.xApplication.ForumDocument.Mobile.ReplyDocument
  348. });