Replace Document, still some cache issues, fixes #2855
This commit is contained in:
parent
21a6007f8c
commit
6f9fb06da3
3 changed files with 46 additions and 18 deletions
|
@ -1,6 +1,8 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
from __future__ import division
|
||||
import os
|
||||
from glob import glob
|
||||
|
||||
import ox
|
||||
from ox.utils import json
|
||||
|
@ -317,11 +319,11 @@ def thumbnail(request, id, size=256, page=None):
|
|||
def upload(request):
|
||||
if 'id' in request.GET:
|
||||
file = models.Document.get(request.GET['id'])
|
||||
elif 'id' in request.POST:
|
||||
file = models.Document.get(request.POST['id'])
|
||||
else:
|
||||
file = None
|
||||
extension = request.POST['filename'].split('.')
|
||||
name = '.'.join(extension[:-1])
|
||||
extension = extension[-1].lower()
|
||||
name, extension = request.POST['filename'].rsplit('.', 1)
|
||||
response = json_response(status=400, text='this request requires POST')
|
||||
if 'chunk' in request.FILES:
|
||||
if file.editable(request.user):
|
||||
|
@ -348,8 +350,15 @@ def upload(request):
|
|||
file.save()
|
||||
else:
|
||||
#replace existing file
|
||||
file.file.delete()
|
||||
if file.file:
|
||||
folder = os.path.dirname(file.file.path)
|
||||
for f in glob('%s/*' % folder):
|
||||
if f != file.file.path:
|
||||
os.unlink(f)
|
||||
file.file.delete()
|
||||
file.uploading = True
|
||||
name, extension = request.POST['filename'].rsplit('.', 1)
|
||||
file.extension = extension
|
||||
file.save()
|
||||
upload_url = request.build_absolute_uri('/api/upload/document?id=%s' % file.get_id())
|
||||
return render_to_json_response({
|
||||
|
|
|
@ -253,7 +253,7 @@ pandora.ui.documentsPanel = function(options) {
|
|||
{id: 'add', title: ''},
|
||||
{id: 'embed', title: Ox._('Embed Document...')},
|
||||
{},
|
||||
{id: 'replace', title: Ox._('Replace {0}...', [Ox._('Document')])},
|
||||
{id: 'replace', title: Ox._('Replace {0}...', [Ox._('Document')]), file: {width: 192}},
|
||||
{id: 'delete', title: '', keyboard: 'delete'}
|
||||
],
|
||||
title: 'set',
|
||||
|
@ -276,7 +276,7 @@ pandora.ui.documentsPanel = function(options) {
|
|||
} else if (data.id == 'remove') {
|
||||
removeDocuments();
|
||||
} else if (data.id == 'replace') {
|
||||
replaceDocument(data.files);
|
||||
replaceDocument(data);
|
||||
} else if (data.id == 'upload') {
|
||||
uploadDocuments(data);
|
||||
}
|
||||
|
@ -509,8 +509,22 @@ pandora.ui.documentsPanel = function(options) {
|
|||
).open();
|
||||
}
|
||||
|
||||
function replaceDocument(file) {
|
||||
function replaceDocument(data) {
|
||||
var id = $list.options('selected')[0];
|
||||
pandora.ui.uploadDocumentDialog({
|
||||
files: data.files,
|
||||
id: id
|
||||
}, function(files) {
|
||||
if (files) {
|
||||
Ox.Request.clearCache();
|
||||
$list.bindEventOnce({
|
||||
load: function() {
|
||||
$list.options({selected: files.ids});
|
||||
}
|
||||
})
|
||||
.reloadList();
|
||||
}
|
||||
}).open();
|
||||
}
|
||||
|
||||
function removeDocuments() {
|
||||
|
@ -816,7 +830,7 @@ pandora.ui.documentsPanel = function(options) {
|
|||
function renderList() {
|
||||
var options = {
|
||||
items: pandora.api.findDocuments,
|
||||
keys: ['description', 'dimensions', 'extension', 'id', 'name', 'ratio', 'size', 'user', 'entities'],
|
||||
keys: ['description', 'dimensions', 'extension', 'id', 'name', 'ratio', 'size', 'user', 'entities', 'modified'],
|
||||
query: {
|
||||
conditions: isItemView ? [{ key: 'item', value: ui.item, operator: '==' }] : [],
|
||||
operator: '&'
|
||||
|
@ -845,7 +859,7 @@ pandora.ui.documentsPanel = function(options) {
|
|||
id: data.id,
|
||||
info: info,
|
||||
title: data.name,
|
||||
url: pandora.getMediaURL('/documents/' + data.id + '/256p.jpg'),
|
||||
url: pandora.getMediaURL('/documents/' + data.id + '/256p.jpg?' + data.modified),
|
||||
width: Math.round(data.ratio > 1 ? size : size * data.ratio)
|
||||
};
|
||||
},
|
||||
|
@ -973,7 +987,6 @@ pandora.ui.documentsPanel = function(options) {
|
|||
hasListSelection && ui.listSelection.length > 1
|
||||
? 'plural' : 'singular'])
|
||||
]))
|
||||
.setItemTitle('replace', Ox._('Replace {0}...', [string]))
|
||||
.setItemTitle('delete', Ox._('Delete {0}...', [string]))
|
||||
[selected.length && (hasItemView || hasListSelection) ? 'enableItem' : 'disableItem']('add')
|
||||
[selected.length ? 'enableItem' : 'disableItem']('embed')
|
||||
|
@ -1035,7 +1048,9 @@ pandora.ui.documentsPanel = function(options) {
|
|||
}
|
||||
|
||||
function uploadDocuments(data) {
|
||||
pandora.ui.uploadDocumentDialog(data.files, function(files) {
|
||||
pandora.ui.uploadDocumentDialog({
|
||||
files: data.files
|
||||
}, function(files) {
|
||||
if (files) {
|
||||
Ox.Request.clearCache('findDocuments');
|
||||
$list.bindEventOnce({
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
// vim: et:ts=4:sw=4:sts=4:ft=javascript
|
||||
'use strict';
|
||||
|
||||
pandora.ui.uploadDocumentDialog = function(files, callback) {
|
||||
|
||||
var extensions = files.map(function(file) {
|
||||
pandora.ui.uploadDocumentDialog = function(options, callback) {
|
||||
var files = options.files,
|
||||
extensions = files.map(function(file) {
|
||||
return file.name.split('.').pop().toLowerCase()
|
||||
}),
|
||||
|
||||
|
@ -137,16 +137,20 @@ pandora.ui.uploadDocumentDialog = function(files, callback) {
|
|||
}
|
||||
|
||||
function uploadFile(part) {
|
||||
var file = files[part],
|
||||
var data = {
|
||||
},
|
||||
file = files[part],
|
||||
extension = file.name.split('.').pop().toLowerCase(),
|
||||
filename = file.name.split('.').slice(0, -1).join('.') + '.'
|
||||
+ (extension == 'jpeg' ? 'jpg' : extension);
|
||||
|
||||
$text.html(Ox._('Uploading {0}', [file.name]));
|
||||
if (options.id) {
|
||||
data.id = options.id;
|
||||
}
|
||||
data.filename = filename;
|
||||
upload = pandora.chunkupload({
|
||||
data: {
|
||||
filename: filename
|
||||
},
|
||||
data: data,
|
||||
file: file,
|
||||
url: '/api/upload/document/',
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue