').text(jsonElement["filename"]);
var fileLink = $('').attr('href', "index.php?action=download&path=" + jsonElement["filelink"]);
var fileNode = $('')
.append(fileIcon)
.append(fileText)
.append(fileLink);
return fileNode;
}
function loadDownloads(ScoID){
$("#download-list").empty();
$.ajax({
url: 'index.php?action=download&sco_id=' + ScoID,
type: 'GET',
dataType: 'json',
success: function(json){
$.each(json, function(index, row){
var file = createDownloadElement(row);
$("#download-list").append(file);
});
}
});
}
//function for discussion
var DiscussionLoader = {
'timer' : [],
'interval' : 10000,
'currentid' : null,
'scoid' : null,
'limit' : 50,
};
function createDiscussionElement(jsonElement){
//var discUser = $('
').text(jsonElement["nickname"]);
var discText = $('
').text(jsonElement["discussion_text"]);
var discTime = $('
').text(jsonElement["discussion_entry"]);
var discUserProfileImg = $('').attr('src', jsonElement["profile"]);
var discContentL = $('').append(discUserProfileImg);
var discContentR = $('')
//.append(discUser)
.append(discText)
.append(discTime);
var discContent = $('')
.append(discContentL)
.append(discContentR);
var discNode = $('').append(discContent);
return discNode;
}
function loadDiscussion(ScoID){
//clear or stop timer
while(DiscussionLoader['timer'].length > 0){
clearInterval(DiscussionLoader['timer'].shift());
}
if(ScoID){
$("#disc-list").empty();
DiscussionLoader['scoid'] = ScoID;
DiscussionLoader['currentid'] = null;
}
//load discussion and create a new timer
if(DiscussionLoader['scoid']){
$.ajax({
type: 'GET',
url: 'index.php',
data: {
action : 'discussion',
current_id : DiscussionLoader['currentid'],
sco_id: DiscussionLoader['scoid'],
limit : DiscussionLoader['limit'],
},
dataType: 'json',
success: function(json){
$.each(json, function(index, row){
var discussion = createDiscussionElement(row);
$("#disc-list").prepend(discussion.hide().fadeIn(300));
DiscussionLoader['currentid'] = row["discussion_id"];
while($('#disc-list li').length > DiscussionLoader['limit']){
$('#disc-list li:last-child').remove();
}
});
},
complete: function(){
DiscussionLoader['timer'].push(setInterval(loadDiscussion, DiscussionLoader['interval']));
},
});
}
}
function saveDiscussion(){
var form = $("#disc");
var disc = form.find("textarea[name='disc[discussion_text]']");
var text = $.trim(disc.val());
if(text != ""){
$.ajax({
url: form.attr('action'),
type: form.attr('method'),
data: form.serialize(),
success: function(json){
loadDiscussion();
},
error: function(XMLHttpRequest, textStatus, errorThrown){
alert("通信エラー発生[" + XMLHttpRequest.status + ":" + errorThrown + "]");
}
});
disc.val("");
}
}
$(document).ready(function(){
loadDownloads($("input[type=radio][name=scos]:checked").val());
$("input[type=radio][name=scos]").change(function(){
if($(this).prop("checked")){
$("input[type=hidden][name='note[sco_id]']").val($(this).val());
$("input[type=hidden][name='disc[sco_id]']").val($(this).val());
scoTo(Number($(this).attr("index")));
loadDownloads($(this).val());
}
});
$("form textarea").keydown(function(e){
if(e.keyCode == 13){
$(this.form).submit();
return false;
}
});
});