function showMusicRank(objName,id,type,rank,voteRank,voteUserCount,isPrev){
rank=(rank==null)?3:rank;
if(rank>5)rank=5;
voteRank=(voteRank==null)?0:voteRank;
voteUserCount=(voteUserCount==null)?0:voteUserCount;
var ss;
if(isPrev){
ss=['<div class="vote_star star_d'+rank+'" title="总计 '+voteUserCount+' 人投票，共 '+voteRank+' 分"><div class="default">&nbsp;</div>']
}else{
ss=['<div class="vote_star vote_star_d star_d'+rank+'" title="总计 '+voteUserCount+' 人投票，共 '+voteRank+' 分"><div class="default">&nbsp;</div>']
}
if(isPrev){
for(var i=1;i<=5;i++){
ss.push('<a class="star_'+i+'" href="#" onclick="'+objName+'.voteMusicRank(\''+id+'\',\''+type+'\','+i+');return false;">&nbsp;</a>');
}
}else{
for(var i=1;i<=5;i++){
ss.push('<a class="star_'+i+'" href="#">&nbsp;</a>');
}
}
ss.push('</div>');
return ss.join('');
}
var musicComment;
var musicCommentType;
var MusicCommentBean;
var musicCommentCallBack;
function loadComment(musicId,type,commentCount,mainCommentCount,commentList,commentRank,bean,callBack){
commentList=commentList||[];
for(var i=0;i<commentList.length;i++){
convertComment(commentList[i]);
}
musicCommentType=type;
Element.show('_$_comment_div');
$('$$_comment_count').innerHTML=commentCount+'';
var option={
bCanClose:true,bHasCancelBtn:true,bSupportDeleteComment:true,
bNeedCheckLogin:false,bNeedCheckRight:true,iAllowComment:commentRank,iPageSize:10,
iHostId:UD.hostId,sHostName:UD.hostName,iVisitorId:UD.visitorId,sVisitorName:UD.visitorName,
sVisitorNickname:UD.visitorNickname,sVisitorAvatar:UD.visitorAvatar,iVisitorRank:UD.visitorRank,sVisitorIP:UD.visitorIP,bShowSpaceUrl:true,
iInputWidth:460,iEditorHeight:90,fnOpenCommentEffect:null,iMainCommentCount:mainCommentCount,
fnAddComment:addNewComment,oAddCommentParams:{parentId:musicId,type:type},
fnDelComment:delComment,oDelCommentParams:{parentId:musicId,type:type},
fnMoreData:getCommentsByPage,
fnAfterAddComment:afterAddComment,oAfterAddCommentParams:{parentId:musicId,type:type},
fnAfterDelComment:afterDelComment,oAfterDelCommentParams:{parentId:musicId,type:type},fnReportBad:reportBad,
fnCloseComments:closeComments,sObjName:'musicComment',bDefaultPubClose:false,iEditorMaxLen:1000
};
musicComment=new NetEase.CommentPublish(commentList,musicId,mainCommentCount,'_$_comments','_$_comment_editor',option);
MusicCommentBean=bean;
musicCommentCallBack=callBack||Prototype.emptyFunction();
}
function convertComment(com){
com.publisherId=com.publishUserId;
com.publisherName=com.publishName;
com.publisherNickname=com.publishNickName;
com.publisherAvatar=com.publishAvatar;
com.publisherAvatarUrl=com.publishAvatar;
if(com.subComments!=null&&com.subComments.length>0){
for(var i=0;i<com.subComments.length;i++){
var scom=com.subComments[i];
scom.publisherId=scom.publishUserId;
scom.publisherName=scom.publishName;
scom.publisherNickname=scom.publishNickName;
scom.publisherAvatar=scom.publishAvatar;
scom.publisherAvatarUrl=scom.publishAvatar;
}
}
}
function addNewComment(newComment,params,postAddCommentFunc){
var com={};
com.musicId=params.parentId;
com.type=params.type
com.content=newComment.content;
com.publishUserId=newComment.publisherId;
com.publishName=newComment.publisherName;
com.publishNickName=newComment.publisherNickname;
com.publishAvatar=newComment.publisherAvatarUrl;
com.ip=newComment.ip;
com.replyToUserId=newComment.replyToUserId;
com.mainComId=newComment.mainComId;
com.replyComId=newComment.replyComId;
com.replyToUserName=newComment.replyToUserName;
com.replyToUserNick=newComment.replyToUserNick;
var filterType=0;
var valcodeelem=$("valcode"+params.valcodeid);
var valcode;
if(valcodeelem!=null)
valcode=valcodeelem.value;
else
valcode=-1;
if(UD.visitorRank<Const.Rank.Friend){
var match=checkOtherSiteUrl(newComment.content);
if(match){
alert(Local.Message.Blog[0]);
postAddCommentFunc(null);
return false;
}
}
MusicCommentBean.addMusicComment(com,com.type,params.valcodeid,valcode,{
callback:function(dataFromServer){
if(dataFromServer!=null)convertComment(dataFromServer);
postAddCommentFunc(dataFromServer);
},
errorHandler:function(errorString,ex){
if(captchaWarning(ex,"$$_comsubmithint"+params.valcodeid)){
postAddCommentFunc(null);
return false;
}
var filterType=filterWarning(ex);
if(filterType==-1){
postAddCommentFunc(null);
return false;
}
postAddCommentFunc(null);
}
});
}
function delComment(commentId,params,isMainComment,postDelCommentFunc){
MusicCommentBean.deleteComment(commentId,params.parentId,params.type,isMainComment,{
callback:function(dataFromServer){
postDelCommentFunc(dataFromServer,commentId,isMainComment);
}
});
}
function getCommentsByPage(musicId,limit,offset,postPageCommentFunc){
MusicCommentBean.getMusicCommentList(musicId,musicCommentType,offset,limit,{
callback:function(dataFromServer){
if(dataFromServer!=null){
for(var i=0;i<dataFromServer.length;i++){
convertComment(dataFromServer[i]);
}
}
postPageCommentFunc(dataFromServer);
}
});
}
function afterAddComment(){
updateTargetCount('$$_comment_count',1);
updateTargetCount('$$_comment_count_0',1);
musicCommentCallBack(1);
}
function afterDelComment(oParams){
var _count=0-oParams.iSuccCount;
updateTargetCount('$$_comment_count',_count);
updateTargetCount('$$_comment_count_0',_count);
musicCommentCallBack(_count);
}
function updateTargetCount(target,diff){
if($(target)){
$(target).innerHTML=parseInt($(target).innerHTML)+(diff)+'';
}
}
function reportBad(report,postReportFunc){
PreUserReportBean.addUserReport(report,postReportFunc);
}
function closeComments(){
$('_$_comments_zone').style.display=($('_$_comments_zone').style.display=='none')?'':'none';
}
function fillConstellation(target,value){
$(target).innerHTML=value>0?constellationArray[value][1]:'';
}
function fillfavoriteMusic(target,value,notBr){
var html=''
if(value!=null){
var ts=value.split('|')[0].split(',');
for(var i=0;i<ts.length;i++){
if(!musicArray[ts[i]])continue;
html+=musicArray[ts[i]][1]
if(i%2==0){
html+='&nbsp;&nbsp;';
}else{
html+=notBr?'&nbsp;&nbsp;':'<br/>';
}
}
html=html.replace(/,$/,"");
}
$(target).innerHTML=html;
}
function isPublishedAlbum(album){
return album!=null&&album.coverPhSmallId>0&&!isStrBlank(album.description)&&!isStrBlank(album.tagIds);
}
function isStrBlank(str){
return str==null||str.trim()=='';
}
var constellationArray=[
["0","星座"],
["1","水瓶座"],
["2","双鱼座"],
["3","白羊座"],
["4","金牛座"],
["5","双子座"],
["6","巨蟹座"],
["7","狮子座"],
["8","处女座"],
["9","天秤座"],
["10","天蝎座"],
["11","射手座"],
["12","摩羯座"]
];
var musicArray=[
["0","流行音乐"],
["1","摇滚/重金属"],
["2","爵士/蓝调"],
["3","Hip Hop"],
["4","古典音乐"],
["5","乡村/民谣"],
["6","民族音乐"],
["7","交响乐"],
["8","其他"]
];
var musicAlbumTagMap={
'0':'流行金曲',
'1':'经典怀旧',
'2':'动漫游戏',
'3':'影视音乐',
'4':'校园民谣',
'5':'戏剧类',
'6':'纯音乐',
'7':'原创作品',
'100':'伤感',
'101':'安静',
'102':'寂寞',
'103':'浪漫',
'104':'幸福',
'105':'失恋',
'106':'思念',
'107':'励志',
'108':'甜蜜',
'109':'深情',
'110':'激情',
'111':'其它'
}
NetEase.DiyMusicEntryAbstract=Class.create();
NetEase.DiyMusicEntryAbstract.prototype={
initialize:function(diyMusic,isEdit){
this.options=Object.extend(
{
objName:'diyMusicObj'
},arguments[2]||{}
);
this.diyMusic=diyMusic;
this.isEdit=isEdit;
if(this.isEdit)
this._init();
this.tabData={
"music":{
target:'$$_music_tab',
baseCss:'c06',
selectedCss:'c07 selitm select'
}
}
this.selectTab('s_intro','music');
},
selectTab:function(css,type){
if(!this.tabData[type])return;
var tab=this.tabData[type];
var obj=$('$$_tab_'+css);
if(obj==tab.lastSelectTab)return;
if(tab.lastSelectTab){
var _csses=tab.selectedCss.split(' ');
for(var i=0;i<_csses.length;i++){
Element.removeClassName(tab.lastSelectTab,_csses[i].trim());
}
Element.addClassName(tab.lastSelectTab,tab.baseCss);
Element.removeClassName($(tab.target),tab.lastSelectCss);
}
tab.lastSelectTab=obj;
tab.lastSelectCss=css;
var _csses=tab.baseCss.split(' ');
for(var i=0;i<_csses.length;i++){
Element.removeClassName(obj,_csses[i].trim());
}
Element.addClassName(obj,tab.selectedCss);
Element.addClassName($(tab.target),css);
},
initPriContent:function(toShow){
if(!$('$$_pri_savebar'))return;
if(toShow){
Element.show('$$_pri_savebar');
}else{
Element.hide('$$_pri_savebar');
$('$$_pri_allow_view').checked=(this.diyMusic.allowView==1);
$('$$_pri_allow_collect').checked=(this.diyMusic.allowCollect==1);
$('$$_pri_allow_download').checked=(this.diyMusic.allowDownload==1);
}
},
savePriContent:function(){
var allowView=$('$$_pri_allow_view').checked?1:0;
var allowCollect=$('$$_pri_allow_collect').checked?1:0;
var allowDownload=$('$$_pri_allow_download').checked?1:0;
DiyMusicBean.updateMusicPrivacy(this.diyMusic.id,allowView,allowCollect,allowDownload,
this._updateMusicPrivacy.bind(this,allowView,allowCollect,allowDownload));
},
deleteDiyMusic:function(){
if(window.confirm("是否确认删除?!")){
DiyMusicBean.deleteMusic(this.diyMusic.id,this._afterDeleteDiyMusic.bind(this));
}
},
voteMusicRank:function(id,type,rank){
if(UD.visitorId<=0){
showLoginDlg('blog.163.com');
return;
}
if(type=='r_diy'){
DiyMusicBean.voteMusicRank(id,rank,function(s){
if(s){
dwrlog('投票成功!','ok');
this.diyMusic.voteUserCount++;
this.diyMusic.voteRank+=rank;
$(type+id).innerHTML=showMusicRank(this.options.objName,id,type,rank,this.diyMusic.voteRank,this.diyMusic.voteUserCount,false);
}else{
dwrlog('投票失败!','error');
}
}.bind(this));
}
},
collect:function(){
if(UD.visitorId<=0){
showLoginDlg('blog.163.com');
return;
}
if(this.albumList!=null){
this._showAlbumList(this.albumList);
}else{
MusicBean.getMusicAlbumListByVisit(-1,this._showAlbumList.bind(this));
}
},
download:function(){
if(UD.visitorId<=0){
showLoginDlg('blog.163.com');
return;
}
DiyMusicBean.getMD5DownloadUrl(this.diyMusic.id,function(s){
if(s!=null&&s.trim()!=''&&s!='about:blank'){
window.location=s;
if(UD.hostId!=UD.visitorId){
updateTargetCount('$$_download_count',1);
}
}
});
},
addMusicCollect:function(id){
var albumId=$('album_collect_select').value;
DiyMusicBean.collectDiyMusic(id,albumId,function(s){
if(s){
dwrlog('收藏音乐成功','ok');
this.musicCollectLayer.hiddenWindow();
if(UD.hostId!=UD.visitorId){
updateTargetCount('$$_recent_collect_count',1);
updateTargetCount('$$_recent_collect_count_0',1);
}
}else{
dwrlog('收藏音乐失败','error');
}
}.bind(this));
},
_init:function(){
new NetEase.PlaceEdit('$$_music_intro',this.diyMusic.id,this._updateMusicIntroduction.bind(this),
{editIcon:'$$_music_intro_icon',editType:'text',dataStream:this.diyMusic,itemIdx:'introduction',maxLength:2000,editStyle:'wz_txtarea brd01',savaButStyle:'wz_button butn ok"',cancelButStyle:'wz_button butn cancel',emptyText:'<i style="color:#999">点击这里添加歌曲描述</i>'}
).resetAll();
new NetEase.PlaceEdit('$$_music_lyric',this.diyMusic.id,this._updateMusicLyric.bind(this),
{editIcon:'$$_music_lyric_icon',editType:'text',dataStream:this.diyMusic,itemIdx:'lyric',maxLength:2000,editStyle:'wz_txtarea brd01',savaButStyle:'wz_button butn ok"',cancelButStyle:'wz_button butn cancel',emptyText:'<i style="color:#999">点击这里添加歌曲歌词</i>'}
).resetAll();
},
_updateMusicIntroduction:function(id,desc,callback){
DiyMusicBean.updateMusicIntroduction(id,desc,{
callback:callback,
errorHandler:function(errorString,ex){
callback(false);
filterWarning(ex,false);;
}
});
},
_updateMusicLyric:function(id,desc,callback){
DiyMusicBean.updateMusicLyric(id,desc,{
callback:callback,
errorHandler:function(errorString,ex){
callback(false);
filterWarning(ex,false);;
}
});
},
_updateMusicPrivacy:function(allowView,allowCollect,allowDownload,s){
if(s){
dwrlog('保存歌曲权限成功!','ok');
this.diyMusic.allowView=allowView;
this.diyMusic.allowCollect=allowCollect;
this.diyMusic.allowDownload=allowDownload;
this.initPriContent();
}else{
dwrlog('保存歌曲权限失败!','error');
}
},
_afterDeleteDiyMusic:function(type,s){
if(s){
dwrlog("删除成功!","ok");
window.location=UD.hostPath+'/music/diy/';
}else{
dwrlog("删除失败!","error");
}
},
_showAlbumList:function(albumList){
this.albumList=albumList;
if(!this.musicCollectLayer){
this.musicCollectLayer=jsWindowManager.createWindow('music_collect',{
className:"layer-search-music",title:'收藏音乐',allowDrag:false,needCover:true,top:370,width:300,height:100,notKeepPos:true
});
this.musicCollectLayer.panel.innerHTML=this._renderTemplate(jst_collect_music,{id:this.diyMusic.id});
$('album_collect_select_zone').innerHTML=this._createSelect('album_collect_select',-1,'95%');
}
this.musicCollectLayer.showWindow();
},
_renderTemplate:function(template,data){
if(template==null)return'';
data=data||{};
data.objName=this.options.objName;
data.hostPath=UD.hostPath;
data.isPrev=!this.isEdit;
data.isOwner=(UD.hostName==UD.visitorName);
return template.processUseCache(data);
},
_createSelect:function(sId,sSelectId,sWidth){
var _sel='<select nohide="true" class="bd01 g_c_mpdin" id="'+sId+'" style="width:'+sWidth+'">';
var _albumList=this.albumList;
for(var i=0;i<_albumList.length;i++){
if(_albumList[i].id==sSelectId)
_sel+='<option value="'+_albumList[i].id+'" selected="true">'+_albumList[i].name+'</option>';
else
_sel+='<option value="'+_albumList[i].id+'">'+_albumList[i].name+'</option>';
}
_sel+='</select>';
return _sel;
}
}
var diyMusicObj;
function g_onloadFunc(diyMusic,isEdit){
$("$_oppoPageUrlForLogin").value=UD.hostPath+'/music/diy/entry/'+diyMusic.id+'/';
diyMusicObj=new NetEase.DiyMusicEntryAbstract(diyMusic,isEdit);
}
function loadCommentByDiyMusicEntry(musicId,commentCount,mainCommentCount,commentList,commentRank){
loadComment(musicId,0,commentCount,mainCommentCount,commentList,commentRank,DiyMusicBean,function(diff){});
}
function updateMusicStyleRank(type,goodRank,badRank){
if(UD.visitorId<=0){
showLoginDlg('blog.163.com');
return;
}
DiyMusicBean.voteMusicStyleRank(type,function(s){
if(s){
if(type==0)goodRank++;
else badRank++;
dwrlog('投票成功!','ok');
}else{
dwrlog('投票失败!','ok');
}
$('$$_music_style_rank_zone').innerHTML='<div>有才：<span class="g_t_bold">'+goodRank+'</span></div><div>无才：<span class="g_t_bold">'+badRank+'</span></div>';
});
}
var jst_collect_music=new String('\
 <div style="margin:10px;"><label>选择专辑：</label><span id="album_collect_select_zone"></span></div>\
 <div style="text-align:center;margin:10px;"><input class="btncm btnok" type="button" value="确定" onclick="${objName}.addMusicCollect(\'${id}\');"/></div>\
');
if(NetEase==undefined){
var NetEase={};
}
NetEase.CommonShare=Class.create();
NetEase.CommonShare.prototype={
initialize:function(objName){
this.options=Object.extend(
{
},arguments[1]||{});
this.objName=objName;
this.resource={};
},
shareResource:function(type,resourceName,url){
if(UD.visitorRank<0){
showLoginDlg(UD.serverName);
return;
}
this.resource.type=type;
this.resource.name=resourceName;
this.resource.url=url;
var options=Object.extend({
title:'推荐给我的博友',
left:false,
top:false,
needCover:true
},arguments[3]||[]);
var validcodeUrl=this.genValidCodeImg();
if(!this.shareResourceLayer){
this.shareResourceLayer=jsWindowManager.createWindow('resource_share',{className:'layer-common-share',
left:options.left,top:options.top,width:410,height:310,title:options.title,needCover:options.needCover,notKeepPos:true});
RemindBean.getChummies(function(dataList){
this.chummyList=dataList;
this.shareResourceLayer.panel.innerHTML=this.jst_resource_share.processUseCache({itemList:this.chummyList,objName:this.objName,validcodeUrl:validcodeUrl});
}.bind(this));
}else{
this.shareResourceLayer.panel.innerHTML=this.jst_resource_share.processUseCache({itemList:this.chummyList,objName:this.objName,validcodeUrl:validcodeUrl});
}
this.shareResourceLayer.showWindow();
},
showNotice:function(n){
if($("commonShareObj_notice")){
$("commonShareObj_notice").innerHTML=n;
setTimeout(' $("commonShareObj_notice").innerHTML = "&nbsp;";',3000);
}
},
sendShareResource:function(){
var content=$F('common_share_msg').trim();
if(content.length>250){
dwrlog('附言不能超过250个字!',"error");
return;
}
var msgValcode=$F('commonShareObj_Valcode').trim();
if(msgValcode==undefined||msgValcode==null||msgValcode==""){
this.showNotice("请输入验证码!");
this.genValidCodeImg();
return;
}
else if(msgValcode!=undefined&&msgValcode!=null&&msgValcode!=""&&msgValcode.length<4){
this.showNotice("验证码为4位!");
this.genValidCodeImg();
return;
}
var receives=[];
if(this.chummyList&&this.chummyList.length>0){
var cbId;
for(var i=0;i<this.chummyList.length;i++){
cbId='common_share_cb_'+this.chummyList[i].userId;
if($(cbId)&&$(cbId).checked){
receives.push(this.chummyList[i].userId);
}
}
}
if(receives.length>0){
$("commonShareObj_submit_button").enable=false;
RemindBean.sendShareResource(receives,content,this.resource.name,this.resource.url,this.resource.type,msgValcode,{
callback:function(s){
$("commonShareObj_submit_button").enable=true;
if(s){
dwrlog('推荐给博友成功!','ok');
this.shareResourceLayer.hiddenWindow();
}else{
dwrlog('推荐给博友失败!','error');
}
}.bind(this),
errorHandler:function(errorString,ex){
if(ex==undefined||ex==null||ex.type=="CaptchaException"){
this.showNotice("验证码不正确!");
this.genValidCodeImg();
$("commonShareObj_submit_button").enable=true;
}
}.bind(this)
});
}else{
dwrlog("你没有选择关注的博友，不能分享!","error");
}
},
selectAll:function(){
var checked=$('common_share_selall').checked;
if(this.chummyList&&this.chummyList.length>0){
var cbId;
for(var i=0;i<this.chummyList.length;i++){
cbId='common_share_cb_'+this.chummyList[i].userId;
if($(cbId)){
$(cbId).checked=checked;
}
}
}
},
genValidCodeImg:function(){
var _iRandom=Math.floor(Math.random()*10001);
var _sId=(_iRandom+"_"+new Date().getTime()).toString();
var ss="/cap/captcha.jpgx?parentId="+encodeURIComponent(UD.hostId)+"&"+_sId;
if($("commonShareObj_valimg")){
$("commonShareObj_valimg").src=ss;
}
return ss;
},
jst_resource_share:new String('\
  <div class="left" style="margin-bottom:0;">\
   <div class="list">\
   {for item in itemList}\
    {if item.userId > 0 &&  item.userName!= null }\
        <div class="g_t_hide"><input type="checkbox" id="common_share_cb_${item.userId}"/><a href="http://${DomainMap.getParentDomain(item.userName)}/" target="_blank">${item.nickname|default:""|escape}</a></div> \
     {/if}\
   {/for}\
   </div>\
   <div class="ctrl">\
    <input type="checkbox" id="common_share_selall" onclick="${objName}.selectAll();"><label for="common_share_selall" onclick="${objName}.selectAll();">全选</label>\
   </div>\
  </div>\
  <div class="right">\
   <div>附言：</div>\
   <div><textarea id="common_share_msg"></textarea></div>\
   <div class="op" style="text-align:left">\
      <div class="g_t_14" ><span style="line-height:24px;">验证码：</span><input  style="width:50px;vertical-align:middle;padding:3px 2px 4px" value="" maxlength="4" id="commonShareObj_Valcode" /><img id="commonShareObj_valimg" class ="valcodeimg" style="vertical-align:middle;margin-left:5px;cursor:pointer;"  alt="验证码" src="${validcodeUrl}" title="点击刷新验证码" onclick="this.src=commonShareObj.genValidCodeImg();"/>\
      <input id="commonShareObj_submit_button" class="btncm btnok" type="button" value="确定" onclick="${objName}.sendShareResource()" style="vertical-align:middle;width:60px;"/>\
      </div>\
      <p style="margin-top:5px"><span id="commonShareObj_notice" style="color:red">&nbsp;</span></p>\
   </div>\
  </div><br class="g_p_clear" />\
 ')
}
var commonShareObj=new NetEase.CommonShare('commonShareObj');

