edit file title / description on upload page

This commit is contained in:
Sanj 2011-07-01 22:40:00 +05:30
parent 64d262ff77
commit 3c69ca5325
3 changed files with 23 additions and 10 deletions

View File

@ -148,14 +148,15 @@ def chunk(request, id):
canEdit = True canEdit = True
if form.is_valid() and canEdit: if form.is_valid() and canEdit:
f = form.cleaned_data['chunk'] f = form.cleaned_data['chunk']
response = {
'resultUrl': '/files/' + str(item.id),
'fileId': item.id
}
if item.title: if item.title:
name = item.title name = item.title
else: else:
name = f.name name = f.name
response = {
'resultUrl': '/files/' + str(item.id),
'fileId': item.id,
'title': name
}
if not item.save_chunk(f.read(), name): if not item.save_chunk(f.read(), name):
response['result'] = 'failed' response['result'] = 'failed'
elif form.cleaned_data['done']: elif form.cleaned_data['done']:
@ -274,12 +275,16 @@ def fileList(request):
paginator = Paginator(qset, RESULTS_PER_PAGE) paginator = Paginator(qset, RESULTS_PER_PAGE)
try: try:
results = paginator.page(page) results = paginator.page(page)
current_page = page
except (EmptyPage, InvalidPage): except (EmptyPage, InvalidPage):
results = paginator.page(paginator.num_pages) results = paginator.page(paginator.num_pages)
current_page = paginator.num_pages
files = results.object_list files = results.object_list
d = {} d = {}
d['noOfResults'] = qset.count() d['noOfResults'] = qset.count()
d['noOfPages'] = paginator.num_pages d['noOfPages'] = paginator.num_pages
d['currentPage'] = current_page
# d['hasPrev'] = paginator.has_previous() # d['hasPrev'] = paginator.has_previous()
# d['hasNext'] = paginator.has_next() # d['hasNext'] = paginator.has_next()
d['files'] = [] d['files'] = []

View File

@ -18,7 +18,7 @@ $(function() {
$('#fileList').empty(); $('#fileList').empty();
$('#noOfPages').text(data.noOfPages); $('#noOfPages').text(data.noOfPages);
$('#noOfResults').text(data.noOfResults); $('#noOfResults').text(data.noOfResults);
$('#currentPageNo').text($('#page_no').val()); $('#currentPageNo').text(data.currentPage);
for (var i=0; i<files.length; i++) { for (var i=0; i<files.length; i++) {
// console.log(files[i]); // console.log(files[i]);
var $file = getJQ(files[i]); var $file = getJQ(files[i]);

View File

@ -103,25 +103,33 @@ UploadQueue.prototype.upload = function(no) {
function fileUploadedCallback(jq, data) { function fileUploadedCallback(jq, data) {
// alert("hi"); // alert("hi");
var fileId = data.fileId; // console.log(data);
var d = JSON.parse(data.responseText);
var fileId = d.fileId;
jq.data("fileId", fileId); jq.data("fileId", fileId);
if (data.hasOwnProperty("errors")) { if (d.hasOwnProperty("errors")) {
var $error = $('<div />').addClass("fileError").text(data.errors[0]).appendTo(jq); var $error = $('<div />').addClass("fileError").text(data.errors[0]).appendTo(jq);
} else { } else {
var $formContainer = $('<div />').addClass("fileForm"); var $formContainer = $('<div />').addClass("fileForm");
var $titleInput = $('<input />').attr("type", "text").addClass("fileTitle").appendTo($formContainer); // console.log(data);
var $titleInput = $('<input />').attr("type", "text").addClass("fileTitle").val(d.title);
// console.log($titleInput);
$titleInput.appendTo($formContainer);
var $descInput = $('<textarea />').addClass("fileDesc").appendTo($formContainer); var $descInput = $('<textarea />').addClass("fileDesc").appendTo($formContainer);
var $submitBtn = $('<button />').text("Submit").click(function() { var $submitBtn = $('<button />').text("Submit").click(function() {
var $this = $(this);
$this.attr("disabled", "disabled");
var $parent = $(this).parents('.uploaded'); var $parent = $(this).parents('.uploaded');
var fileId = $parent.data("fileId"); var fileId = $parent.data("fileId");
var title = $parent.find(".fileTitle").val(); var title = $parent.find(".fileTitle").val();
var description = $parent.find(".fileDesc").val(); var description = $parent.find(".fileDesc").val();
$.post("/files/editFile", { $.post("/files/editFile/", {
'id': fileId, 'id': fileId,
'title': title, 'title': title,
'description': description 'description': description
}, function(response) { }, function(response) {
console.log(response); $this.removeAttr("disabled");
}, },
"json"); "json");
}).appendTo($formContainer); }).appendTo($formContainer);