diff --git a/cms/djangoapps/contentstore/views.py b/cms/djangoapps/contentstore/views.py index 651af7a3e2..28b1742621 100644 --- a/cms/djangoapps/contentstore/views.py +++ b/cms/djangoapps/contentstore/views.py @@ -719,8 +719,18 @@ def upload_asset(request, org, course, coursename): #then commit the content contentstore().save(content) del_cached_content(content.location) + + # readback the saved content - we need the database timestamp + readback = contentstore().find(content.location) - response = HttpResponse('Upload completed') + 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: diff --git a/cms/static/js/base.js b/cms/static/js/base.js index 7ef7aff963..1486a10c5b 100644 --- a/cms/static/js/base.js +++ b/cms/static/js/base.js @@ -345,10 +345,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() { @@ -360,7 +371,6 @@ function hideModal(e) { e.preventDefault(); $('.modal').hide(); $modalCover.hide(); - location.reload(); } function onKeyUp(e) { diff --git a/cms/templates/asset_index.html b/cms/templates/asset_index.html index 1d093c1365..4244bd2542 100644 --- a/cms/templates/asset_index.html +++ b/cms/templates/asset_index.html @@ -3,8 +3,36 @@ <%block name="bodyclass">assets <%block name="title">Courseware Assets +<%namespace name='static' file='static_content.html'/> + +<%block name="jsextra"> + + + <%block name="content"> + +

Asset Library

@@ -22,9 +50,9 @@ Embed - + % for asset in assets: - +
% if asset['thumb_url'] is not None: diff --git a/common/static/js/vendor/mustache.js b/common/static/js/vendor/mustache.js new file mode 100644 index 0000000000..aab62f9ddc --- /dev/null +++ b/common/static/js/vendor/mustache.js @@ -0,0 +1,613 @@ +/*! + * mustache.js - Logic-less {{mustache}} templates with JavaScript + * http://github.com/janl/mustache.js + */ + +var Mustache; + +(function (exports) { + if (typeof module !== "undefined") { + module.exports = exports; // CommonJS + } else if (typeof define === "function") { + define(exports); // AMD + } else { + Mustache = exports; //