Mobile.js 17 KB

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