Commit 6011d6d3 by chrisndodge

Merge pull request #928 from MITx/fix/cdodge/asset-upload-tweeks

improvements on asset upload refresh. Now we don't need to refresh the w...
parents b76556b9 82e77a26
......@@ -720,7 +720,17 @@ def upload_asset(request, org, course, coursename):
contentstore().save(content)
del_cached_content(content.location)
response = HttpResponse('Upload completed')
# readback the saved content - we need the database timestamp
readback = contentstore().find(content.location)
response_payload = {'displayname' : content.name,
'uploadDate' : get_date_display(readback.last_modified_at),
'url' : StaticContent.get_url_path_from_location(content.location),
'thumb_url' : StaticContent.get_url_path_from_location(thumbnail_content.location) if thumbnail_content is not None else None,
'msg' : 'Upload completed'
}
response = HttpResponse(json.dumps(response_payload))
response['asset_url'] = StaticContent.get_url_path_from_location(content.location)
return response
......@@ -869,6 +879,10 @@ def asset_index(request, org, course, name):
course_reference = StaticContent.compute_location(org, course, name)
assets = contentstore().get_all_content_for_course(course_reference)
# sort in reverse upload date order
assets = sorted(assets, key=lambda asset: asset['uploadDate'], reverse=True)
thumbnails = contentstore().get_all_content_thumbnails_for_course(course_reference)
asset_display = []
for asset in assets:
......
......@@ -341,10 +341,21 @@ function displayFinishedUpload(xhr) {
if(xhr.status = 200){
markAsLoaded();
}
var resp = JSON.parse(xhr.responseText);
$('.upload-modal .copy-button').attr('href', xhr.getResponseHeader('asset_url'));
$('.upload-modal .progress-fill').html(xhr.responseText);
$('.upload-modal .progress-fill').html(resp.msg);
$('.upload-modal .choose-file-button').html('Load Another File').show();
$('.upload-modal .progress-fill').width('100%');
// see if this id already exists, if so, then user must have updated an existing piece of content
$("tr[data-id='" + resp.url + "']").remove();
var template = $('#new-asset-element').html();
var html = Mustache.to_html(template, resp);
$('table > tbody > tr:first').before(html);
$("tr[data-id='" + resp.url + "'] a.show-xml").toggle(showEmbeddableXML, hideEmbeddableXML);
}
function markAsLoaded() {
......@@ -356,7 +367,6 @@ function hideModal(e) {
e.preventDefault();
$('.modal').hide();
$modalCover.hide();
location.reload();
}
function onKeyUp(e) {
......
......@@ -3,8 +3,36 @@
<%block name="bodyclass">assets</%block>
<%block name="title">Courseware Assets</%block>
<%namespace name='static' file='static_content.html'/>
<%block name="jsextra">
<script src="${static.url('js/vendor/mustache.js')}"></script>
</%block>
<%block name="content">
<script type="text/template" id="new-asset-element">
<tr data-id='{{url}}'>
<td class="thumb-col">
<div class="thumb">
{{#thumb_url}}
<img src="{{thumb_url}}">
{{/thumb_url}}
</div>
</td>
<td class="name-col">
<a href="{{url}}" class="filename">{{displayname}}</a>
<div class="embeddable-xml"></div>
</td>
<td class="date-col">
{{uploadDate}}
</td>
<td class="embed-col">
<a class="show-xml" href="{{url}}">XML</a>
</td>
</tr>
</script>
<div class="main-wrapper">
<div class="inner-wrapper">
<h1>Asset Library</h1>
......@@ -22,9 +50,9 @@
<th class="embed-col">Embed</th>
</tr>
</thead>
<tbody>
<tbody id="asset_table_body">
% for asset in assets:
<tr>
<tr data-id="${asset['url']}">
<td class="thumb-col">
<div class="thumb">
% if asset['thumb_url'] is not None:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment