Comment.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. MWF.xApplication.AppMarketV2.Application.Comment = new Class({
  2. Implements: [Options, Events],
  3. options: {
  4. "view": "applicationComment.html"
  5. },
  6. initialize: function(app, container, options){
  7. this.setOptions(options);
  8. this.app = app;
  9. this.appdata = this.app.appdata;
  10. this.container = container;
  11. this.viewPath = this.app.path+this.app.options.style+"/"+this.options.view;
  12. this.iconPath = this.app.path+this.app.options.style+"/icon/";
  13. this.actions = MWF.Actions.load("x_program_center");
  14. this.load();
  15. },
  16. load: function(){
  17. this.container.loadHtml(this.viewPath, {"bind": {"lp": this.app.lp}, "module": this}, function(){
  18. this.loadApplication(function(){
  19. this.fireEvent("load");
  20. }.bind(this));
  21. }.bind(this));
  22. },
  23. loadApplication: function(callback){
  24. if (!this.isLoading){
  25. if (!this.applicationsContentV){
  26. this.applicationsContentV = new MWF.xApplication.AppMarketV2.Application.Comment.ViewPage(this, {
  27. "onLoad": function(){ if (callback) callback(); }
  28. });
  29. }else{
  30. this.applicationsContentV.load();
  31. }
  32. }
  33. }
  34. });
  35. MWF.xApplication.AppMarketV2.Application.Comment.ViewPage= new Class({
  36. Implements: [Options, Events],
  37. options: {
  38. "type": "commentViewPage"
  39. },
  40. initialize: function(content, options){
  41. this.setOptions(options);
  42. this.content = content;
  43. this.app = this.content.app;
  44. this.appdata = this.content.appdata;
  45. this.actions = this.app.actions;
  46. this.container = this.content.container;
  47. this.page = 1;
  48. this.pageSize = 100;
  49. this.querydata = {};
  50. this.bbsUrlPath = "";
  51. this.bbsUrl = "";
  52. this.load();
  53. },
  54. load: function(){
  55. if (this.app.collectToken=="" || this.app.collectUrl==""){
  56. //先登录collcect
  57. this.actions.CollectAction.login(//平台封装好的方法
  58. function( json ){ //服务调用成功的回调函数, json为服务传回的数据
  59. if (json.type && json.type=="success"){
  60. data = json.data; //为变量data赋值
  61. this.app.collectUrl = data.collectUrl;
  62. this.app.collectToken = data.collectToken;
  63. this.loadCommentsGrade(this,this.commentsGrade.bind(this));
  64. //this.loadCommentPower(this,this.commentsPower.bind(this));
  65. this.loadCommentPower(this);
  66. this.loadCommentsList(this,this.commentsView.bind(this));
  67. }
  68. }.bind(this),null,false //同步执行
  69. );
  70. }else{
  71. //this.loadBbsInfo(this);
  72. this.loadCommentsGrade(this,this.commentsGrade.bind(this));
  73. //this.loadCommentPower(this,this.commentsPower.bind(this));
  74. this.loadCommentPower(this);
  75. this.loadCommentsList(this,this.commentsView.bind(this));
  76. }
  77. },
  78. loadBbsInfo: function(content){
  79. this.actions.CollectAction.bbs(//平台封装好的方法
  80. function( json ){ //服务调用成功的回调函数, json为服务传回的数据
  81. if (json.type && json.type=="success"){debugger;
  82. data = json.data; //为变量data赋值
  83. this.bbsUrlPath = data.bbsUrlPath;
  84. this.bbsUrl = data.bbsUrl;
  85. }
  86. }.bind(this),null,false //同步执行
  87. );
  88. },
  89. loadCommentsGrade: function(content,callback){
  90. this.loadBbsInfo(content);
  91. var json = null;
  92. var commenturl = this.bbsUrlPath +'/x_bbs_assemble_control/jaxrs/subject/statgrade/sectionName/'+encodeURI(content.app.lp.title)+'/subjectType/'+encodeURI(content.appdata.name)+'?time='+(new Date()).getMilliseconds();
  93. debugger;
  94. var res = new Request.JSON({
  95. url: commenturl,
  96. headers : {'x-debugger' : true,'Authorization':content.app.collectToken,'c-token':content.app.collectToken},
  97. secure: false,
  98. method: "get",
  99. async: true,
  100. withCredentials: true,
  101. contentType : 'application/json',
  102. crossDomain : true,
  103. onSuccess: function(responseJSON, responseText){
  104. debugger;
  105. json = responseJSON;
  106. if (typeOf(callback).toLowerCase() == 'function'){
  107. callback(responseJSON);
  108. }else{
  109. o2.runCallback(callback, "success", [responseJSON, responseText]);
  110. }
  111. }.bind(this),
  112. onFailure: function(xhr){
  113. o2.runCallback(callback, "requestFailure", [xhr]);
  114. }.bind(this),
  115. onError: function(text, error){
  116. o2.runCallback(callback, "error", [text, error]);
  117. }.bind(this)
  118. });
  119. res.send();
  120. },
  121. loadCommentPower: function(content,callback){
  122. //var bbsurl = content.app.lp.bbsurl;
  123. debugger;
  124. var commentbuttondiv = new Element("div",{"class":"o2_appmarket_application_comment_middle_tip"}).inject(this.content.applicationcommentmiddle);
  125. new Element("span",{
  126. "class":"o2_appmarket_application_introduce_tab_current",
  127. "text":content.app.lp.bbsNotice
  128. }).inject(commentbuttondiv);
  129. commentbuttondiv.addEvents({
  130. "click": function(e){
  131. debugger;
  132. window.open(content.bbsUrl);
  133. }
  134. })
  135. },
  136. loadCommentsList:function(content,callback){
  137. var commentdata = {};
  138. commentdata["sectionName"] = content.app.lp.title;
  139. commentdata["subjectType"] = content.appdata.name;
  140. //var commenturl = content.app.lp.commentpath+'/x_bbs_assemble_control/jaxrs/subject/filter/listsubjectinfo/page/1/count/10';
  141. var commenturl = this.bbsUrlPath+'/x_bbs_assemble_control/jaxrs/subject/filter/listsubjectinfo/page/1/count/10';
  142. debugger;
  143. var res = new Request.JSON({
  144. "url": commenturl,
  145. "headers" : {"Content-Type": "application/json; charset=utf-8","x-debugger" : true},
  146. secure: false,
  147. "method": "POST",
  148. async: true,
  149. emulation: false,
  150. noCache: true,
  151. withCredentials: true,
  152. crossDomain : true,
  153. "data": JSON.stringify(commentdata),
  154. onSuccess: function(responseJSON, responseText){
  155. debugger;
  156. json = responseJSON;
  157. if (typeOf(callback).toLowerCase() == 'function'){
  158. callback(responseJSON);
  159. }else{
  160. o2.runCallback(callback, "success", [responseJSON, responseText]);
  161. }
  162. }.bind(this),
  163. onFailure: function(xhr){
  164. debugger;
  165. o2.runCallback(callback, "requestFailure", [xhr]);
  166. }.bind(this),
  167. onError: function(text, error){
  168. debugger;
  169. o2.runCallback(callback, "error", [text, error]);
  170. }.bind(this)
  171. });
  172. debugger;
  173. res.send();
  174. },
  175. loadCommentsList_bak:function(content,callback){
  176. var json = null;
  177. var commenturl = content.app.collectUrl +'/o2_collect_assemble/jaxrs/comment/list/app/'+content.appdata.id+'?time='+(new Date()).getMilliseconds();
  178. var res = new Request.JSON({
  179. url: commenturl,
  180. headers : {'x-debugger' : true,'Authorization':content.app.collectToken,'c-token':content.app.collectToken},
  181. secure: false,
  182. method: "get",
  183. async: true,
  184. withCredentials: true,
  185. contentType : 'application/json',
  186. crossDomain : true,
  187. onSuccess: function(responseJSON, responseText){
  188. json = responseJSON;
  189. if (typeOf(callback).toLowerCase() == 'function'){
  190. callback(responseJSON);
  191. }else{
  192. o2.runCallback(callback, "success", [responseJSON, responseText]);
  193. }
  194. }.bind(this),
  195. onFailure: function(xhr){
  196. o2.runCallback(callback, "requestFailure", [xhr]);
  197. }.bind(this),
  198. onError: function(text, error){
  199. o2.runCallback(callback, "error", [text, error]);
  200. }.bind(this)
  201. });
  202. res.send();
  203. },
  204. commentsGrade:function(commentdata){
  205. debugger;
  206. var commentcount = 0;
  207. var grade = 0;
  208. var totalgrade = 0;
  209. var commentratiolist = commentdata.data;
  210. var gradeList = ["0","0","0","0","0"];
  211. commentratiolist.each(function(pergrade){
  212. gradeList[parseInt(pergrade.grade)-1]=pergrade.count;
  213. commentcount +=parseInt(pergrade.count)
  214. }.bind(this));
  215. gradeList.each(function(pergrade,index){
  216. totalgrade += parseInt(pergrade)*(index+1)
  217. })
  218. if (commentcount>0){
  219. grade = this.numberFix(totalgrade/commentcount,1)
  220. }
  221. debugger;
  222. this.content.applicationcommenttopgrade.set("text",grade+"");
  223. var intgrade = parseInt(grade);
  224. var dotgrade = grade - intgrade;
  225. for (var tmpnum=0;tmpnum<intgrade;tmpnum++){
  226. new Element("img",{"src":this.content.iconPath+"blackfiveangular.png","class":"o2_appmarket_application_introduce_memo_remark_inner_pic"}).inject(this.content.applicationcommenttopangular)
  227. }
  228. if (dotgrade>=0.5){
  229. new Element("img",{"src":this.content.iconPath+"halffiveangular.png","class":"o2_appmarket_application_introduce_memo_remark_inner_pic"}).inject(this.content.applicationcommenttopangular);
  230. intgrade++;
  231. }
  232. for (var tmpnum=0;tmpnum<5-intgrade;tmpnum++){
  233. new Element("img",{"src":this.content.iconPath+"whitefiveangular.png","class":"o2_appmarket_application_introduce_memo_remark_inner_pic"}).inject(this.content.applicationcommenttopangular);
  234. }
  235. new Element("span",{
  236. "class":"o2_appmarket_application_introduce_memo_remark_inner_text",
  237. "text":this.app.lp.commentCountText.replace("{n}",commentcount)
  238. }).inject(this.content.applicationcommenttopangular);
  239. //5星
  240. new Element("div",{"text":"5","class":"o2_appmarket_application_comment_top_right_graderatioItem"}).inject(this.content.applicationcommentrightfive);
  241. gradeangular = new Element("div",{"class":"o2_appmarket_application_comment_top_right_graderatioItem"}).inject(this.content.applicationcommentrightfive);
  242. new Element("img",{"src":this.content.iconPath+"blackfiveangular.png","class":"o2_appmarket_application_introduce_memo_remark_inner_pic"}).inject(gradeangular)
  243. graderatiodiv = new Element("div",{"class":"o2_appmarket_application_comment_gradetotal"}).inject(this.content.applicationcommentrightfive);
  244. blackratiodiv = new Element("div",{"class":"o2_appmarket_application_comment_graderatio"}).inject(graderatiodiv);
  245. graderratiodivwidth = graderatiodiv.clientWidth;
  246. if (commentcount==0){
  247. blackratio = 0;
  248. blackratiodiv.setStyle("width","0px");
  249. }else{
  250. blackratio = parseInt(gradeList[4])/commentcount;
  251. blackratiowidth = blackratio*graderratiodivwidth;
  252. blackratiodiv.setStyle("width",blackratiowidth+"px");
  253. }
  254. new Element("div",{"text":this.numberFix(blackratio*100,1)+"%","class":"o2_appmarket_application_comment_top_right_graderatioItem"}).inject(this.content.applicationcommentrightfive);
  255. debugger;
  256. //4星
  257. new Element("div",{"text":"4","class":"o2_appmarket_application_comment_top_right_graderatioItem"}).inject(this.content.applicationcommentrightfour);
  258. gradeangular = new Element("div",{"class":"o2_appmarket_application_comment_top_right_graderatioItem"}).inject(this.content.applicationcommentrightfour);
  259. new Element("img",{"src":this.content.iconPath+"blackfiveangular.png","class":"o2_appmarket_application_introduce_memo_remark_inner_pic"}).inject(gradeangular)
  260. graderatiodiv = new Element("div",{"class":"o2_appmarket_application_comment_gradetotal"}).inject(this.content.applicationcommentrightfour);
  261. blackratiodiv = new Element("div",{"class":"o2_appmarket_application_comment_graderatio"}).inject(graderatiodiv);
  262. graderratiodivwidth = graderatiodiv.clientWidth;
  263. if (commentcount==0){
  264. blackratio = 0;
  265. blackratiodiv.setStyle("width","0px");
  266. }else{
  267. blackratio = parseInt(gradeList[3])/commentcount;
  268. blackratiowidth = blackratio*graderratiodivwidth;
  269. blackratiodiv.setStyle("width",blackratiowidth+"px");
  270. }
  271. new Element("div",{"text":this.numberFix(blackratio*100,1)+"%","class":"o2_appmarket_application_comment_top_right_graderatioItem"}).inject(this.content.applicationcommentrightfour);
  272. //3星
  273. new Element("div",{"text":"3","class":"o2_appmarket_application_comment_top_right_graderatioItem"}).inject(this.content.applicationcommentrightthree);
  274. gradeangular = new Element("div",{"class":"o2_appmarket_application_comment_top_right_graderatioItem"}).inject(this.content.applicationcommentrightthree);
  275. new Element("img",{"src":this.content.iconPath+"blackfiveangular.png","class":"o2_appmarket_application_introduce_memo_remark_inner_pic"}).inject(gradeangular)
  276. graderatiodiv = new Element("div",{"class":"o2_appmarket_application_comment_gradetotal"}).inject(this.content.applicationcommentrightthree);
  277. blackratiodiv = new Element("div",{"class":"o2_appmarket_application_comment_graderatio"}).inject(graderatiodiv);
  278. graderratiodivwidth = graderatiodiv.clientWidth;
  279. if (commentcount==0){
  280. blackratio = 0;
  281. blackratiodiv.setStyle("width","0px");
  282. }else{
  283. blackratio = (parseInt(gradeList[2])/commentcount).toFixed(4);
  284. blackratiowidth = blackratio*graderratiodivwidth;
  285. blackratiodiv.setStyle("width",blackratiowidth+"px");
  286. }
  287. new Element("div",{"text":this.numberFix(blackratio*100,1)+"%","class":"o2_appmarket_application_comment_top_right_graderatioItem"}).inject(this.content.applicationcommentrightthree);
  288. //2星
  289. new Element("div",{"text":"2","class":"o2_appmarket_application_comment_top_right_graderatioItem"}).inject(this.content.applicationcommentrighttwo);
  290. gradeangular = new Element("div",{"class":"o2_appmarket_application_comment_top_right_graderatioItem"}).inject(this.content.applicationcommentrighttwo);
  291. new Element("img",{"src":this.content.iconPath+"blackfiveangular.png","class":"o2_appmarket_application_introduce_memo_remark_inner_pic"}).inject(gradeangular)
  292. graderatiodiv = new Element("div",{"class":"o2_appmarket_application_comment_gradetotal"}).inject(this.content.applicationcommentrighttwo);
  293. blackratiodiv = new Element("div",{"class":"o2_appmarket_application_comment_graderatio"}).inject(graderatiodiv);
  294. graderratiodivwidth = graderatiodiv.clientWidth;
  295. if (commentcount==0){
  296. blackratio = 0;
  297. blackratiodiv.setStyle("width","0px");
  298. }else{
  299. blackratio = (parseInt(gradeList[1])/commentcount).toFixed(4);
  300. blackratiowidth = blackratio*graderratiodivwidth;
  301. blackratiodiv.setStyle("width",blackratiowidth+"px");
  302. }
  303. new Element("div",{"text":this.numberFix(blackratio*100,1)+"%","class":"o2_appmarket_application_comment_top_right_graderatioItem"}).inject(this.content.applicationcommentrighttwo);
  304. //1星
  305. new Element("div",{"text":"1","class":"o2_appmarket_application_comment_top_right_graderatioItem"}).inject(this.content.applicationcommentrightone);
  306. gradeangular = new Element("div",{"class":"o2_appmarket_application_comment_top_right_graderatioItem"}).inject(this.content.applicationcommentrightone);
  307. new Element("img",{"src":this.content.iconPath+"blackfiveangular.png","class":"o2_appmarket_application_introduce_memo_remark_inner_pic"}).inject(gradeangular)
  308. graderatiodiv = new Element("div",{"class":"o2_appmarket_application_comment_gradetotal"}).inject(this.content.applicationcommentrightone);
  309. blackratiodiv = new Element("div",{"class":"o2_appmarket_application_comment_graderatio"}).inject(graderatiodiv);
  310. graderratiodivwidth = graderatiodiv.clientWidth;
  311. if (commentcount==0){
  312. blackratio = 0;
  313. blackratiodiv.setStyle("width","0px");
  314. }else{
  315. blackratio = (parseInt(gradeList[0])/commentcount).toFixed(4);
  316. blackratiowidth = blackratio*graderratiodivwidth;
  317. blackratiodiv.setStyle("width",blackratiowidth+"px");
  318. }
  319. new Element("div",{"text":this.numberFix(blackratio*100,1)+"%","class":"o2_appmarket_application_comment_top_right_graderatioItem"}).inject(this.content.applicationcommentrightone);
  320. },
  321. commentsPower:function(commentdata){
  322. var commentText = "";
  323. if (commentdata.type && commentdata.type=="success"){
  324. if (commentdata.data.value){
  325. commentText = this.app.lp.commented;
  326. }
  327. }
  328. if (this.appdata.installedVersion==""){
  329. commentText = this.app.lp.notInstall;
  330. }
  331. if (commentText == ""){
  332. var commentbuttondiv = new Element("div",{"class":"o2_appmarket_application_comment_middle_commentbutton"}).inject(this.content.applicationcommentmiddle);
  333. new Element("span",{
  334. "class":"o2_appmarket_application_comment_middle_commentbutton_InnerSpan",
  335. "text":this.app.lp.iNeedComment
  336. }).inject(commentbuttondiv);
  337. var _self = this;
  338. commentbuttondiv.addEvents({
  339. "click": function(e){
  340. _self.createComment(e);
  341. }
  342. })
  343. }else{
  344. new Element("div",{"class":"o2_appmarket_application_comment_middle_tip","text":commentText}).inject(this.content.applicationcommentmiddle);
  345. }
  346. },
  347. commentsView:function(commentdata){
  348. var commentsList = commentdata.data;
  349. debugger
  350. commentsList.each(function(percomment){
  351. var commentcontentdiv = new Element("div",{"class":"o2_appmarket_application_comment_content"}).inject(this.content.applicationcommentbottom);
  352. var commentcontentleft = new Element("div",{"class":"o2_appmarket_application_comment_content_left"}).inject(commentcontentdiv);
  353. var iconpersondiv = new Element("div",{"class":"o2_appmarket_application_comment_content_left_icon"}).inject(commentcontentleft);
  354. new Element("img",{"src":this.content.iconPath+"icon_men.png"}).inject(iconpersondiv);
  355. debugger;
  356. new Element("div",{"class":"o2_appmarket_application_comment_content_left_name","text":percomment.creatorNameShort}).inject(commentcontentleft);
  357. var commentcontentright = new Element("div",{"class":"o2_appmarket_application_comment_content_right"}).inject(commentcontentdiv);
  358. var commentangulardiv = new Element("div").inject(commentcontentright);
  359. for (var tmpi=0;tmpi<parseInt(percomment.grade);tmpi++){
  360. new Element("img",{"src":this.content.iconPath+"blackfiveangular.png","class":"o2_appmarket_application_introduce_memo_remark_inner_pic"}).inject(commentangulardiv)
  361. }
  362. for (var tmpi=0;tmpi<5-parseInt(percomment.grade);tmpi++){
  363. new Element("img",{"src":this.content.iconPath+"whitefiveangular.png","class":"o2_appmarket_application_introduce_memo_remark_inner_pic"}).inject(commentangulardiv)
  364. }
  365. var content = percomment.content;
  366. var percommentConent = content.replace("<p>","").replace("</p>","");
  367. var subjectUrl = this.bbsUrlPath;
  368. if(subjectUrl.indexOf(":",8)>0){
  369. subjectUrl = subjectUrl.slice(0,subjectUrl.indexOf(":",8));
  370. }
  371. subjectUrl = subjectUrl+"/x_desktop/forum.html?app=ForumDocument&id="+percomment.id;
  372. debugger
  373. var subjectDiv= new Element("div",{"class":"o2_appmarket_application_comment_content_title"}).inject(commentcontentright);
  374. var subjectA = new Element("a",{"class":"o2_appmarket_application_comment_content_title_a","text":percomment.title,"href":subjectUrl,"target":"_blank"}).inject(subjectDiv);
  375. //subjectA.setStyle("text-decoration","none");
  376. var conentDiv = new Element("div",{"class":"o2_appmarket_application_comment_content_text"}).inject(commentcontentright);
  377. var conentHtml = percomment.content;
  378. conentDiv.set("html",conentHtml);
  379. }.bind(this))
  380. },
  381. commentsView_bak:function(commentdata){
  382. var commentsList = commentdata.data;
  383. commentsList.each(function(percomment){
  384. var commentcontentdiv = new Element("div",{"class":"o2_appmarket_application_comment_content"}).inject(this.content.applicationcommentbottom);
  385. var commentcontentleft = new Element("div",{"class":"o2_appmarket_application_comment_content_left"}).inject(commentcontentdiv);
  386. var iconpersondiv = new Element("div",{"class":"o2_appmarket_application_comment_content_left_icon"}).inject(commentcontentleft);
  387. new Element("img",{"src":this.content.iconPath+"icon_men.png"}).inject(iconpersondiv);
  388. new Element("div",{"class":"o2_appmarket_application_comment_content_left_name","text":percomment.person}).inject(commentcontentleft);
  389. var commentcontentright = new Element("div",{"class":"o2_appmarket_application_comment_content_right"}).inject(commentcontentdiv);
  390. var commentangulardiv = new Element("div").inject(commentcontentright);
  391. for (var tmpi=0;tmpi<parseInt(percomment.grade);tmpi++){
  392. new Element("img",{"src":this.content.iconPath+"blackfiveangular.png","class":"o2_appmarket_application_introduce_memo_remark_inner_pic"}).inject(commentangulardiv)
  393. }
  394. for (var tmpi=0;tmpi<5-parseInt(percomment.grade);tmpi++){
  395. new Element("img",{"src":this.content.iconPath+"whitefiveangular.png","class":"o2_appmarket_application_introduce_memo_remark_inner_pic"}).inject(commentangulardiv)
  396. }
  397. new Element("div",{"class":"o2_appmarket_application_comment_content_title","text":percomment.title}).inject(commentcontentright);
  398. new Element("div",{"class":"o2_appmarket_application_comment_content_text","text":percomment.comment,"title":percomment.comment}).inject(commentcontentright);
  399. }.bind(this))
  400. },
  401. reload: function(){
  402. if (!this.content.isLoading) {
  403. this.loadComments();
  404. this.loadCommentPower();
  405. }
  406. },
  407. emptyLoadContent: function(){
  408. this.content.commentnode.empty();
  409. this.content.isLoading = false;
  410. },
  411. createComment:function(targetnode){
  412. var content = new Element("div", {"styles": {"margin": "20px"}});
  413. var xingdiv = new Element("div").inject(content);
  414. new Element("div",{"class":"comment_dlg_title","text": this.app.lp.score }).inject(xingdiv);
  415. xingpngdiv = new Element("div",{"class":"comment_dlg_png"}).inject(xingdiv);
  416. var starnode;
  417. var _self = this;
  418. var selectstar = 0;
  419. for (var tmpi=0;tmpi<5;tmpi++){
  420. starnode = new Element("img",{"src":this.content.iconPath+"whitefiveangular.png","class":tmpi+"star comment_dlg_star"}).inject(xingpngdiv);
  421. starnode.store("id",tmpi);
  422. starnode.addEvents({
  423. "click": function(e){
  424. var idnum = this.retrieve("id");
  425. selectstar = idnum + 1;
  426. var starblacknode = this;
  427. var starwhitenode = this.nextElementSibling;
  428. while(starwhitenode){
  429. starwhitenode.set("src",_self.content.iconPath+"whitefiveangular.png");
  430. starwhitenode = starwhitenode.nextElementSibling;
  431. }
  432. while(starblacknode){
  433. starblacknode.set("src",_self.content.iconPath+"blackfiveangular.png");
  434. starblacknode = starblacknode.previousElementSibling
  435. }
  436. }
  437. })
  438. }
  439. var cleardiv = new Element("div",{"style":"clear:both"}).inject(content);
  440. var commentdiv = new Element("div").inject(content);
  441. new Element("div",{"class":"comment_dlg_title","text":"评论:"}).inject(commentdiv);
  442. inputdiv = new Element("div",{"class":"comment_dlg_input_div"}).inject(commentdiv);
  443. commentcontentNode = new Element("textarea",{"class":"comment_dlg_input"}).inject(inputdiv);
  444. o2.DL.open({
  445. "title": this.app.lp.commentTitle,
  446. "content": content,
  447. "width": 740,
  448. "height": 520,
  449. "buttonList": [
  450. {
  451. "text": this.app.lp.ok,
  452. "class":"comment_dlg_button_ok",
  453. "action": function(){
  454. debugger;
  455. if (selectstar==0 || commentcontentNode.get("value")==""){
  456. MWF.xDesktop.notice("error", {x: "right", y:"top"}, this.app.lp.commentNotice);
  457. }else{
  458. var commentdata = {};
  459. commentdata["title"] = "";
  460. commentdata["application"] = _self.appdata.id;
  461. commentdata["grade"] = selectstar+"";
  462. commentdata["comment"] = commentcontentNode.get("value");
  463. _self.submitComment(commentdata);
  464. this.close();
  465. }
  466. }
  467. },
  468. {
  469. "text": this.app.lp.cancel,
  470. "class":"comment_dlg_button_cancel",
  471. "action": function(){this.close();}
  472. }
  473. ]
  474. });
  475. },
  476. submitComment:function(commentdata){
  477. var tmpjson= JSON.stringify(commentdata);
  478. var commenturl = this.app.collectUrl +'/o2_collect_assemble/jaxrs/comment';
  479. var res = new Request.JSON({
  480. "url": commenturl,
  481. "headers" : {"Content-Type": "application/json; charset=utf-8","x-debugger" : true,"Authorization":this.app.collectToken,"c-token":this.app.collectToken},
  482. secure: false,
  483. "method": "POST",
  484. secure: false,
  485. emulation: false,
  486. noCache: true,
  487. withCredentials: true,
  488. crossDomain : true,
  489. "data": JSON.stringify(commentdata),
  490. onSuccess: function(responseJSON, responseText){
  491. debugger;
  492. MWF.xDesktop.notice("success", {x: "right", y:"top"}, this.app.lp.commentsuccess);
  493. this.app.loadIntroduceComment();
  494. }.bind(this),
  495. onFailure: function(xhr){
  496. MWF.xDesktop.notice("error", {x: "right", y:"top"}, xhr);
  497. }.bind(this),
  498. onError: function(text, error){
  499. MWF.xDesktop.notice("error", {x: "right", y:"top"}, text);
  500. }.bind(this)
  501. });
  502. res.send();
  503. },
  504. numberFix:function(data,n){
  505. var numbers = '';
  506. // 保留几位小数后面添加几个0
  507. for (var i = 0; i < n; i++) {
  508. numbers += '0';
  509. }
  510. var s = 1 + numbers;
  511. // 如果是整数需要添加后面的0
  512. var spot = "." + numbers;
  513. // Math.round四舍五入
  514. // parseFloat() 函数可解析一个字符串,并返回一个浮点数。
  515. var value = Math.round(parseFloat(data) * s) / s;
  516. // 从小数点后面进行分割
  517. var d = value.toString().split(".");
  518. if (d.length == 1) {
  519. value = value.toString();
  520. return value;
  521. }
  522. if (d.length > 1) {
  523. if (d[1].length < n) {
  524. value = value.toString() + "0";
  525. }
  526. return value;
  527. }
  528. }
  529. })