MWF.xApplication.AppMarketV2.Application.Comment = new Class({
Implements: [Options, Events],
options: {
"view": "applicationComment.html"
},
initialize: function(app, container, options){
this.setOptions(options);
this.app = app;
this.appdata = this.app.appdata;
this.container = container;
this.viewPath = this.app.path+this.app.options.style+"/"+this.options.view;
this.iconPath = this.app.path+this.app.options.style+"/icon/";
this.actions = MWF.Actions.load("x_program_center");
this.load();
},
load: function(){
this.container.loadHtml(this.viewPath, {"bind": {"lp": this.app.lp}, "module": this}, function(){
this.loadApplication(function(){
this.fireEvent("load");
}.bind(this));
}.bind(this));
},
loadApplication: function(callback){
if (!this.isLoading){
if (!this.applicationsContentV){
this.applicationsContentV = new MWF.xApplication.AppMarketV2.Application.Comment.ViewPage(this, {
"onLoad": function(){ if (callback) callback(); }
});
}else{
this.applicationsContentV.load();
}
}
}
});
MWF.xApplication.AppMarketV2.Application.Comment.ViewPage= new Class({
Implements: [Options, Events],
options: {
"type": "commentViewPage"
},
initialize: function(content, options){
this.setOptions(options);
this.content = content;
this.app = this.content.app;
this.appdata = this.content.appdata;
this.actions = this.app.actions;
this.container = this.content.container;
this.page = 1;
this.pageSize = 100;
this.querydata = {};
this.bbsUrlPath = "";
this.bbsUrl = "";
this.load();
},
load: function(){
if (this.app.collectToken=="" || this.app.collectUrl==""){
//先登录collcect
this.actions.CollectAction.login(//平台封装好的方法
function( json ){ //服务调用成功的回调函数, json为服务传回的数据
if (json.type && json.type=="success"){
data = json.data; //为变量data赋值
this.app.collectUrl = data.collectUrl;
this.app.collectToken = data.collectToken;
this.loadCommentsGrade(this,this.commentsGrade.bind(this));
//this.loadCommentPower(this,this.commentsPower.bind(this));
this.loadCommentPower(this);
this.loadCommentsList(this,this.commentsView.bind(this));
}
}.bind(this),null,false //同步执行
);
}else{
//this.loadBbsInfo(this);
this.loadCommentsGrade(this,this.commentsGrade.bind(this));
//this.loadCommentPower(this,this.commentsPower.bind(this));
this.loadCommentPower(this);
this.loadCommentsList(this,this.commentsView.bind(this));
}
},
loadBbsInfo: function(content){
this.actions.CollectAction.bbs(//平台封装好的方法
function( json ){ //服务调用成功的回调函数, json为服务传回的数据
if (json.type && json.type=="success"){debugger;
data = json.data; //为变量data赋值
this.bbsUrlPath = data.bbsUrlPath;
this.bbsUrl = data.bbsUrl;
}
}.bind(this),null,false //同步执行
);
},
loadCommentsGrade: function(content,callback){
this.loadBbsInfo(content);
var json = null;
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();
debugger;
var res = new Request.JSON({
url: commenturl,
headers : {'x-debugger' : true,'Authorization':content.app.collectToken,'c-token':content.app.collectToken},
secure: false,
method: "get",
async: true,
withCredentials: true,
contentType : 'application/json',
crossDomain : true,
onSuccess: function(responseJSON, responseText){
debugger;
json = responseJSON;
if (typeOf(callback).toLowerCase() == 'function'){
callback(responseJSON);
}else{
o2.runCallback(callback, "success", [responseJSON, responseText]);
}
}.bind(this),
onFailure: function(xhr){
o2.runCallback(callback, "requestFailure", [xhr]);
}.bind(this),
onError: function(text, error){
o2.runCallback(callback, "error", [text, error]);
}.bind(this)
});
res.send();
},
loadCommentPower: function(content,callback){
//var bbsurl = content.app.lp.bbsurl;
debugger;
var commentbuttondiv = new Element("div",{"class":"o2_appmarket_application_comment_middle_tip"}).inject(this.content.applicationcommentmiddle);
new Element("span",{
"class":"o2_appmarket_application_introduce_tab_current",
"text":content.app.lp.bbsNotice
}).inject(commentbuttondiv);
commentbuttondiv.addEvents({
"click": function(e){
debugger;
window.open(content.bbsUrl);
}
})
},
loadCommentsList:function(content,callback){
var commentdata = {};
commentdata["sectionName"] = content.app.lp.title;
commentdata["subjectType"] = content.appdata.name;
//var commenturl = content.app.lp.commentpath+'/x_bbs_assemble_control/jaxrs/subject/filter/listsubjectinfo/page/1/count/10';
var commenturl = this.bbsUrlPath+'/x_bbs_assemble_control/jaxrs/subject/filter/listsubjectinfo/page/1/count/10';
debugger;
var res = new Request.JSON({
"url": commenturl,
"headers" : {"Content-Type": "application/json; charset=utf-8","x-debugger" : true},
secure: false,
"method": "POST",
async: true,
emulation: false,
noCache: true,
withCredentials: true,
crossDomain : true,
"data": JSON.stringify(commentdata),
onSuccess: function(responseJSON, responseText){
debugger;
json = responseJSON;
if (typeOf(callback).toLowerCase() == 'function'){
callback(responseJSON);
}else{
o2.runCallback(callback, "success", [responseJSON, responseText]);
}
}.bind(this),
onFailure: function(xhr){
debugger;
o2.runCallback(callback, "requestFailure", [xhr]);
}.bind(this),
onError: function(text, error){
debugger;
o2.runCallback(callback, "error", [text, error]);
}.bind(this)
});
debugger;
res.send();
},
loadCommentsList_bak:function(content,callback){
var json = null;
var commenturl = content.app.collectUrl +'/o2_collect_assemble/jaxrs/comment/list/app/'+content.appdata.id+'?time='+(new Date()).getMilliseconds();
var res = new Request.JSON({
url: commenturl,
headers : {'x-debugger' : true,'Authorization':content.app.collectToken,'c-token':content.app.collectToken},
secure: false,
method: "get",
async: true,
withCredentials: true,
contentType : 'application/json',
crossDomain : true,
onSuccess: function(responseJSON, responseText){
json = responseJSON;
if (typeOf(callback).toLowerCase() == 'function'){
callback(responseJSON);
}else{
o2.runCallback(callback, "success", [responseJSON, responseText]);
}
}.bind(this),
onFailure: function(xhr){
o2.runCallback(callback, "requestFailure", [xhr]);
}.bind(this),
onError: function(text, error){
o2.runCallback(callback, "error", [text, error]);
}.bind(this)
});
res.send();
},
commentsGrade:function(commentdata){
debugger;
var commentcount = 0;
var grade = 0;
var totalgrade = 0;
var commentratiolist = commentdata.data;
var gradeList = ["0","0","0","0","0"];
commentratiolist.each(function(pergrade){
gradeList[parseInt(pergrade.grade)-1]=pergrade.count;
commentcount +=parseInt(pergrade.count)
}.bind(this));
gradeList.each(function(pergrade,index){
totalgrade += parseInt(pergrade)*(index+1)
})
if (commentcount>0){
grade = this.numberFix(totalgrade/commentcount,1)
}
debugger;
this.content.applicationcommenttopgrade.set("text",grade+"");
var intgrade = parseInt(grade);
var dotgrade = grade - intgrade;
for (var tmpnum=0;tmpnum