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

View File

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

View File

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