From 90861c22d03537a95e4fc9c4c2c425d3e88af375 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Wed, 17 Oct 2012 12:26:56 -0400 Subject: [PATCH 1/2] improvements on asset upload refresh. Now we don't need to refresh the whole page, just insert the table tow --- cms/djangoapps/contentstore/views.py | 16 +++++++++++++- cms/static/js/base.js | 14 ++++++++++-- cms/templates/asset_index.html | 32 ++++++++++++++++++++++++++-- 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/cms/djangoapps/contentstore/views.py b/cms/djangoapps/contentstore/views.py index d95322f2f8..76bdfb6242 100644 --- a/cms/djangoapps/contentstore/views.py +++ b/cms/djangoapps/contentstore/views.py @@ -718,8 +718,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 @@ -866,6 +876,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 867f81e973..14d76a260e 100644 --- a/cms/static/js/base.js +++ b/cms/static/js/base.js @@ -335,10 +335,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() { @@ -350,7 +361,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: From 82e77a26c600473430057eba9764f2a95dfab484 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Wed, 17 Oct 2012 13:47:07 -0400 Subject: [PATCH 2/2] add mustache.js to common static repo --- common/static/js/vendor/mustache.js | 613 ++++++++++++++++++++++++++++ 1 file changed, 613 insertions(+) create mode 100644 common/static/js/vendor/mustache.js 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; //