rename files to documents and use media for media files

This commit is contained in:
j 2013-05-27 10:13:59 +00:00
parent aaa153e19d
commit 8da6badf4c
27 changed files with 1010 additions and 856 deletions

View file

@ -33,13 +33,13 @@
"canEditFeaturedEdits": {"staff": true, "admin": true},
"canEditFeaturedLists": {"staff": true, "admin": true},
"canEditFeaturedTexts": {"staff": true, "admin": true},
"canEditFiles": {"staff": true, "admin": true},
"canEditMedia": {"staff": true, "admin": true},
"canEditMetadata": {"staff": true, "admin": true},
"canEditPlaces": {"staff": true, "admin": true},
"canEditSitePages": {"staff": true, "admin": true},
"canEditUsers": {"admin": true},
"canImportAnnotations": {},
"canManageFiles": {"staff": true, "admin": true},
"canManageDocuments": {"staff": true, "admin": true},
"canManagePlacesAndEvents": {"staff": true, "admin": true},
"canManageTitlesAndNames": {"staff": true, "admin": true},
"canManageUsers": {"staff": true, "admin": true},
@ -50,7 +50,7 @@
"canSeeAccessed": {"staff": true, "admin": true},
"canSeeDebugMenu": {"staff": true, "admin": true},
"canSeeExtraItemViews": {"staff": true, "admin": true},
"canSeeFiles": {"staff": true, "admin": true},
"canSeeMedia": {"staff": true, "admin": true},
"canSeeItem": {"guest": 3, "member": 3, "friend": 4, "staff": 4, "admin": 4},
"canSeeSize": {"friend": true, "staff": true, "admin": true},
"canSeeSoftwareVersion": {"staff": true, "admin": true},
@ -392,7 +392,7 @@
"id": "resolution",
"title": "Resolution",
"type": ["integer"],
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"columnWidth": 90,
"format": {"type": "resolution", "args": ["px"]},
"sort": true
@ -409,7 +409,7 @@
"id": "pixels",
"title": "Pixels",
"type": "integer",
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"columnWidth": 90,
"format": {"type": "value", "args": ["px"]},
"sort": true
@ -496,7 +496,7 @@
"id": "bitrate",
"title": "Bitrate",
"type": "integer",
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"columnWidth": 60,
"format": {"type": "value", "args": ["bps"]},
"sort": true
@ -505,7 +505,7 @@
"id": "parts",
"title": "Number of Parts",
"type": "integer",
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"columnWidth": 60,
"sort": true
},
@ -513,7 +513,7 @@
"id": "numberoffiles",
"title": "Number of Files",
"type": "integer",
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"columnWidth": 60,
"sort": true,
"value": {"key": "files", "type": "length"}
@ -522,7 +522,7 @@
"id": "filename",
"title": "Filename",
"type": ["string"],
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"find": true
},
{
@ -607,7 +607,7 @@
{"id": "map", "title": "Map"},
{"id": "calendar", "title": "Calendar"},
{"id": "data", "title": "Data"},
{"id": "files", "title": "Files"}
{"id": "media", "title": "Media"}
],
// fixme: should be renamed to annotationLayers
"layers": [

View file

@ -34,13 +34,13 @@
"canEditFeaturedEdits": {"student": true, "staff": true, "admin": true},
"canEditFeaturedLists": {"student": true, "staff": true, "admin": true},
"canEditFeaturedTexts": {"student": true, "staff": true, "admin": true},
"canEditFiles": {"student": true, "staff": true, "admin": true},
"canEditMedia": {"student": true, "staff": true, "admin": true},
"canEditMetadata": {"student": true, "staff": true, "admin": true},
"canEditPlaces": {"student": true, "staff": true, "admin": true},
"canEditSitePages": {"staff": true, "admin": true},
"canEditUsers": {"staff": true, "admin": true},
"canImportAnnotations": {"student": true, "staff": true, "admin": true},
"canManageFiles": {"member": true, "student": true, "staff": true, "admin": true},
"canManageDocuments": {"member": true, "student": true, "staff": true, "admin": true},
"canManagePlacesAndEvents": {"member": true, "student": true, "staff": true, "admin": true},
"canManageTitlesAndNames": {"member": true, "student": true, "staff": true, "admin": true},
"canManageUsers": {"staff": true, "admin": true},
@ -51,7 +51,7 @@
"canSeeAccessed": {"student": true, "staff": true, "admin": true},
"canSeeDebugMenu": {"student": true, "staff": true, "admin": true},
"canSeeExtraItemViews": {"student": true, "staff": true, "admin": true},
"canSeeFiles": {"student": true, "staff": true, "admin": true},
"canSeeMedia": {"student": true, "staff": true, "admin": true},
"canSeeItem": {"guest": 3, "member": 3, "student": 3, "staff": 3, "admin": 3},
"canSeeSize": {"student": true, "staff": true, "admin": true},
"canSeeSoftwareVersion": {"student": true, "staff": true, "admin": true},
@ -434,7 +434,7 @@
"id": "resolution",
"title": "Resolution",
"type": ["integer"],
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"columnWidth": 90,
"format": {"type": "resolution", "args": ["px"]},
"sort": true
@ -451,7 +451,7 @@
"id": "pixels",
"title": "Pixels",
"type": "integer",
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"columnWidth": 90,
"format": {"type": "value", "args": ["px"]},
"sort": true
@ -538,7 +538,7 @@
"id": "bitrate",
"title": "Bitrate",
"type": "integer",
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"columnWidth": 60,
"format": {"type": "value", "args": ["bps"]},
"sort": true
@ -547,7 +547,7 @@
"id": "parts",
"title": "Number of Parts",
"type": "integer",
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"columnWidth": 60,
"sort": true
},
@ -555,7 +555,7 @@
"id": "numberoffiles",
"title": "Number of Files",
"type": "integer",
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"columnWidth": 60,
"sort": true,
"value": {"key": "files", "type": "length"}
@ -564,7 +564,7 @@
"id": "filename",
"title": "Filename",
"type": ["string"],
"capability": "canSeeFiles"
"capability": "canSeeMedia"
},
{
"id": "created",
@ -648,7 +648,7 @@
{"id": "map", "title": "Map"},
{"id": "calendar", "title": "Calendar"},
{"id": "data", "title": "Data"},
{"id": "files", "title": "Files"}
{"id": "media", "title": "Media"}
],
// fixme: should be renamed to annotationLayers
"layers": [

View file

@ -31,13 +31,13 @@
"canEditFeaturedEdits": {"staff": true, "admin": true},
"canEditFeaturedLists": {"staff": true, "admin": true},
"canEditFeaturedTexts": {"staff": true, "admin": true},
"canEditFiles": {"staff": true, "admin": true},
"canEditMedia": {"staff": true, "admin": true},
"canEditMetadata": {"staff": true, "admin": true},
"canEditPlaces": {"staff": true, "admin": true},
"canEditSitePages": {"staff": true, "admin": true},
"canEditUsers": {"admin": true},
"canImportAnnotations": {"member": true, "staff": true, "admin": true},
"canManageFiles": {"member": true, "staff": true, "admin": true},
"canManageDocuments": {"member": true, "staff": true, "admin": true},
"canManagePlacesAndEvents": {"member": true, "staff": true, "admin": true},
"canManageTitlesAndNames": {"member": true, "staff": true, "admin": true},
"canManageUsers": {"staff": true, "admin": true},
@ -48,7 +48,7 @@
"canSeeAccessed": {"staff": true, "admin": true},
"canSeeDebugMenu": {"staff": true, "admin": true},
"canSeeExtraItemViews": {"staff": true, "admin": true},
"canSeeFiles": {"staff": true, "admin": true},
"canSeeMedia": {"staff": true, "admin": true},
"canSeeItem": {"guest": 1, "member": 1, "staff": 4, "admin": 4},
"canSeeSize": {"staff": true, "admin": true},
"canSeeSoftwareVersion": {"staff": true, "admin": true},
@ -410,7 +410,7 @@
"id": "size",
"title": "Size",
"type": "integer",
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"columnWidth": 60,
"format": {"type": "value", "args": ["B"]},
"sort": true
@ -427,7 +427,7 @@
"id": "numberoffiles",
"title": "Number of Files",
"type": "integer",
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"columnWidth": 60,
"sort": true,
"value": {"key": "files", "type": "length"}
@ -436,14 +436,14 @@
"id": "user",
"title": "User",
"type": "string",
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"find": true
},
{
"id": "filename",
"title": "Filename",
"type": ["string"],
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"find": true
},
{
@ -524,7 +524,7 @@
{"id": "map", "title": "Map"},
{"id": "calendar", "title": "Calendar"},
{"id": "data", "title": "Data"},
{"id": "files", "title": "Files"}
{"id": "media", "title": "Media"}
],
"layers": [
{

View file

@ -31,13 +31,13 @@
"canEditFeaturedEdits": {"staff": true, "admin": true},
"canEditFeaturedLists": {"staff": true, "admin": true},
"canEditFeaturedTexts": {"staff": true, "admin": true},
"canEditFiles": {"staff": true, "admin": true},
"canEditMedia": {"staff": true, "admin": true},
"canEditMetadata": {"staff": true, "admin": true},
"canEditPlaces": {"staff": true, "admin": true},
"canEditSitePages": {"staff": true, "admin": true},
"canEditUsers": {"admin": true},
"canImportAnnotations": {"member": true, "staff": true, "admin": true},
"canManageFiles": {"member": true, "staff": true, "admin": true},
"canManageDocuments": {"member": true, "staff": true, "admin": true},
"canManagePlacesAndEvents": {"member": true, "staff": true, "admin": true},
"canManageTitlesAndNames": {"member": true, "staff": true, "admin": true},
"canManageUsers": {"staff": true, "admin": true},
@ -48,7 +48,7 @@
"canSeeAccessed": {"staff": true, "admin": true},
"canSeeDebugMenu": {"staff": true, "admin": true},
"canSeeExtraItemViews": {"staff": true, "admin": true},
"canSeeFiles": {"staff": true, "admin": true},
"canSeeMedia": {"staff": true, "admin": true},
"canSeeItem": {"guest": 1, "member": 1, "staff": 4, "admin": 4},
"canSeeSize": {"staff": true, "admin": true},
"canSeeSoftwareVersion": {"staff": true, "admin": true},
@ -351,7 +351,7 @@
"id": "size",
"title": "Size",
"type": "integer",
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"columnWidth": 60,
"format": {"type": "value", "args": ["B"]},
"sort": true
@ -368,7 +368,7 @@
"id": "numberoffiles",
"title": "Number of Files",
"type": "integer",
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"columnWidth": 60,
"sort": true,
"value": {"key": "files", "type": "length"}
@ -377,7 +377,7 @@
"id": "user",
"title": "User",
"type": "string",
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"find": true
},
{
@ -447,7 +447,7 @@
{"id": "map", "title": "Map"},
{"id": "calendar", "title": "Calendar"},
{"id": "data", "title": "Data"},
{"id": "files", "title": "Files"}
{"id": "media", "title": "Media"}
],
"layers": [
{

View file

@ -88,10 +88,10 @@ def parseConditions(conditions, operator, user):
return None
class FileManager(Manager):
class DocumentManager(Manager):
def get_query_set(self):
return super(FileManager, self).get_query_set()
return super(DocumentManager, self).get_query_set()
def find(self, data, user):
'''

View file

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
import os
from south.models import MigrationHistory
def was_applied(migration_file_path, app_name):
"""true if migration with a given file name ``migration_file``
was applied to app with name ``app_name``"""
try:
migration_file = os.path.basename(migration_file_path)
migration_name = migration_file.split('.')[0]
MigrationHistory.objects.get(
app_name = app_name,
migration = migration_name
)
return True
except MigrationHistory.DoesNotExist:
return False

View file

@ -4,10 +4,14 @@ from south.db import db
from south.v2 import SchemaMigration
from django.db import models
from ..migration_utils import was_applied
class Migration(SchemaMigration):
def forwards(self, orm):
if was_applied(__file__, 'file'):
return
# Adding model 'File'
db.create_table('file_file', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),

View file

@ -4,9 +4,14 @@ from south.db import db
from south.v2 import DataMigration
from django.db import models
from ..migration_utils import was_applied
class Migration(DataMigration):
def forwards(self, orm):
if was_applied(__file__, 'file'):
return
"Write your forwards methods here."
# Note: Remember to use orm['appname.ModelName'] rather than "from appname.models..."
import os

View file

@ -0,0 +1,90 @@
# -*- coding: utf-8 -*-
import os
from os.path import exists, join
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
from django.conf import settings
class Migration(SchemaMigration):
def forwards(self, orm):
files_path = join(settings.MEDIA_ROOT, 'files')
documents_path = join(settings.MEDIA_ROOT, 'documents')
if not exists(documents_path) and exists(files_path):
os.rename(files_path, documents_path)
db.rename_table('file_file', 'document_document')
for f in orm['document.Document'].objects.all():
f.file.name = f.file.name.replace('files/', 'documents/')
f.save()
def backwards(self, orm):
files_path = join(settings.MEDIA_ROOT, 'files')
documents_path = join(settings.MEDIA_ROOT, 'documents')
if not exists(files_path) and exists(documents_path):
os.rename(documents_path, files_path)
for f in orm['document.Document'].objects.all():
f.file.name = f.file.name.replace('documents/', 'files/')
f.save()
db.rename_table('document_document', 'file_file')
models = {
'auth.group': {
'Meta': {'object_name': 'Group'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
'auth.permission': {
'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '255', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
},
'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
'document.document': {
'Meta': {'unique_together': "(('user', 'name', 'extension'),)", 'object_name': 'Document'},
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'description': ('django.db.models.fields.TextField', [], {'default': "''"}),
'description_sort': ('django.db.models.fields.CharField', [], {'max_length': '512'}),
'extension': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'file': ('django.db.models.fields.files.FileField', [], {'default': 'None', 'max_length': '100', 'null': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'matches': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'name_sort': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'oshash': ('django.db.models.fields.CharField', [], {'max_length': '16', 'unique': 'True', 'null': 'True'}),
'ratio': ('django.db.models.fields.FloatField', [], {'default': '1'}),
'size': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'uploading': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'files'", 'to': "orm['auth.User']"})
}
}
complete_apps = ['document']

View file

@ -16,7 +16,7 @@ import ox
import managers
class File(models.Model):
class Document(models.Model):
class Meta:
unique_together = ("user", "name", "extension")
@ -35,7 +35,7 @@ class File(models.Model):
file = models.FileField(default=None, blank=True,null=True, upload_to=lambda f, x: f.path(x))
objects = managers.FileManager()
objects = managers.DocumentManager()
uploading = models.BooleanField(default = False)
name_sort = models.CharField(max_length=255)
@ -51,7 +51,7 @@ class File(models.Model):
self.name_sort = ox.sort_string(self.name or u'')[:255].lower()
self.description_sort = ox.sort_string(self.description or u'')[:512].lower()
super(File, self).save(*args, **kwargs)
super(Document, self).save(*args, **kwargs)
def __unicode__(self):
return self.get_id()
@ -82,7 +82,7 @@ class File(models.Model):
return False
if self.user == user or \
user.is_staff or \
user.get_profile().capability('canEditFiles') == True:
user.get_profile().capability('canEditDocuments') == True:
return True
return False
@ -94,7 +94,7 @@ class File(models.Model):
data['name'] = "Untitled"
name = data['name']
num = 1
while File.objects.filter(name=name, user=self.user, extension=self.extension).exclude(id=self.id).count()>0:
while Document.objects.filter(name=name, user=self.user, extension=self.extension).exclude(id=self.id).count()>0:
num += 1
name = data['name'] + ' [%d]' % num
self.name = name
@ -130,7 +130,7 @@ class File(models.Model):
def path(self, name=''):
h = "%07d" % self.id
return os.path.join('files', h[:2], h[2:4], h[4:6], h[6:], name)
return os.path.join('documents', h[:2], h[2:4], h[4:6], h[6:], name)
def save_chunk(self, chunk, chunk_id=-1, done=False):
if self.uploading:
@ -189,10 +189,10 @@ class File(models.Model):
matches += item.models.Item.objects.filter(data__contains=url).count()
matches += text.models.Text.objects.filter(text__contains=url).count()
if matches != self.matches:
File.objects.filter(id=self.id).update(matches=matches)
Document.objects.filter(id=self.id).update(matches=matches)
self.matches = matches
def delete_file(sender, **kwargs):
def delete_document(sender, **kwargs):
t = kwargs['instance']
if t.file:
if t.extension == 'pdf':
@ -200,5 +200,5 @@ def delete_file(sender, **kwargs):
if os.path.exists(thumb):
os.unlink(thumb)
t.file.delete()
pre_delete.connect(delete_file, sender=File)
pre_delete.connect(delete_document, sender=Document)

View file

@ -10,14 +10,44 @@ from ox.django.shortcuts import render_to_json_response, get_object_or_404_json,
from django import forms
from item import utils
from item.models import Item
import models
def get_file_or_404_json(id):
username, name, extension = models.File.parse_id(id)
return get_object_or_404_json(models.File, user__username=username, name=name, extension=extension)
def get_document_or_404_json(id):
username, name, extension = models.Document.parse_id(id)
return get_object_or_404_json(models.Document, user__username=username, name=name, extension=extension)
@login_required_json
def editFile(request):
def addDocument(request):
'''
add document(s) to item
takes {
item: string
id: string
or
ids: [string]
}
returns {
}
'''
response = json_response()
data = json.loads(request.POST['data'])
if 'ids' in data:
ids = data['ids']
else:
ids = [data['id']]
item = Item.objects.get(itemId=data['item'])
if item.editable(request.user):
for id in ids:
file = models.Document.get(id)
item.documents.add(file)
else:
response = json_response(status=403, file='permission denied')
return render_to_json_response(response)
actions.register(addDocument, cache=False)
@login_required_json
def editDocument(request):
'''
takes {
id: string
@ -32,7 +62,7 @@ def editFile(request):
response = json_response()
data = json.loads(request.POST['data'])
if data['id']:
file = models.File.get(data['id'])
file = models.Document.get(data['id'])
if file.editable(request.user):
file.edit(data, request.user)
file.save()
@ -42,7 +72,7 @@ def editFile(request):
else:
response = json_response(status=500, file='invalid request')
return render_to_json_response(response)
actions.register(editFile, cache=False)
actions.register(editDocument, cache=False)
def _order_query(qs, sort):
@ -69,11 +99,11 @@ def parse_query(data, user):
for key in ('keys', 'group', 'file', 'range', 'position', 'positions', 'sort'):
if key in data:
query[key] = data[key]
query['qs'] = models.File.objects.find(data, user).exclude(name='')
query['qs'] = models.Document.objects.find(data, user).exclude(name='')
return query
def findFiles(request):
def findDocuments(request):
'''
takes {
query: {
@ -121,35 +151,43 @@ def findFiles(request):
else:
response['data']['items'] = qs.count()
return render_to_json_response(response)
actions.register(findFiles)
actions.register(findDocuments)
@login_required_json
def removeFile(request):
def removeDocument(request):
'''
takes {
id: string,
or
ids: [string]
}
returns {
}
'''
data = json.loads(request.POST['data'])
response = json_response()
file = models.File.get(data['id'])
if 'ids' in data:
ids = data['ids']
else:
ids = [data['id']]
for id in ids:
file = models.Document.get(id)
if file.editable(request.user):
file.delete()
else:
response = json_response(status=403, file='not allowed')
break
return render_to_json_response(response)
actions.register(removeFile, cache=False)
actions.register(removeDocument, cache=False)
def file(request, id):
file = models.File.get(id)
return HttpFileResponse(file.file.path)
document = models.Document.get(id)
return HttpFileResponse(document.file.path)
def thumbnail(request, id):
file = models.File.get(id)
return HttpFileResponse(file.thumbnail())
document = models.Document.get(id)
return HttpFileResponse(document.thumbnail())
class ChunkForm(forms.Form):
chunk = forms.FileField()
@ -159,7 +197,7 @@ class ChunkForm(forms.Form):
@login_required_json
def upload(request):
if 'id' in request.GET:
file = models.File.get(request.GET['id'])
file = models.Document.get(request.GET['id'])
else:
extension = request.POST['filename'].split('.')
name = '.'.join(extension[:-1])
@ -185,7 +223,7 @@ def upload(request):
num = 1
_name = name
while not created:
file, created = models.File.objects.get_or_create(
file, created = models.Document.objects.get_or_create(
user=request.user, name=name, extension=extension)
if not created:
num += 1

View file

@ -128,7 +128,7 @@ INSTALLED_APPS = (
'user',
'urlalias',
'tv',
'file',
'document',
)
# Log errors into db

View file

@ -23,15 +23,15 @@ urlpatterns = patterns('',
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
(r'^admin/', include(admin.site.urls)),
(r'^api/upload/text/?$', 'text.views.upload'),
(r'^api/upload/file/?$', 'file.views.upload'),
(r'^api/upload/document/?$', 'document.views.upload'),
(r'^api/upload/direct/?$', 'archive.views.direct_upload'),
(r'^api/upload/?$', 'archive.views.firefogg_upload'),
(r'^url=(?P<url>.*)$', 'app.views.redirect_url'),
(r'^file/(?P<oshash>.*)$', 'archive.views.lookup_file'),
(r'^api/?$', include(ox.django.api.urls)),
(r'^resetUI$', 'user.views.reset_ui'),
(r'^files/(?P<id>.*?.pdf).jpg$', 'file.views.thumbnail'),
(r'^files/(?P<id>.*?.)$', 'file.views.file'),
(r'^documents/(?P<id>.*?.pdf).jpg$', 'document.views.thumbnail'),
(r'^documents/(?P<id>.*?.)$', 'document.views.file'),
(r'^list/(?P<id>.*?)/icon(?P<size>\d*).jpg$', 'itemlist.views.icon'),
(r'^text/(?P<id>.*?)/icon(?P<size>\d*).jpg$', 'text.views.icon'),
(r'^texts/(?P<id>.*?)/text.pdf$', 'text.views.pdf'),

View file

@ -1,13 +1,13 @@
// vim: et:ts=4:sw=4:sts=4:ft=javascript
'use strict';
pandora.ui.deleteFileDialog = function(file, callback) {
pandora.ui.deleteDocumentDialog = function(file, callback) {
var that = pandora.ui.iconDialog({
buttons: [
Ox.Button({
id: 'keep',
title: Ox._('Keep File')
title: Ox._('Keep Document')
}).bindEvent({
click: function() {
that.close();
@ -15,19 +15,19 @@ pandora.ui.deleteFileDialog = function(file, callback) {
}),
Ox.Button({
id: 'delete',
title: Ox._('Delete File')
title: Ox._('Delete Document')
}).bindEvent({
click: function() {
that.close();
pandora.api.removeFile({
pandora.api.removeDocument({
id: file
}, callback);
}
})
],
keys: {enter: 'delete', escape: 'keep'},
text: Ox._('Are you sure you want to delete the file "{0}"?', [file]),
title: Ox._('Delete File')
text: Ox._('Are you sure you want to delete the document "{0}"?', [file]),
title: Ox._('Delete Document')
});
return that;

View file

@ -2,7 +2,7 @@
'use strict';
pandora.ui.filesDialog = function() {
pandora.ui.documentsDialog = function() {
var dialogHeight = Math.round((window.innerHeight - 48) * 0.9),
dialogWidth = Math.round(window.innerWidth * 0.9),
@ -19,13 +19,13 @@ pandora.ui.filesDialog = function() {
.bindEvent({
click: function() {
$reloadButton.options({disabled: true});
Ox.Request.clearCache('findFiles');
Ox.Request.clearCache('findDocuments');
$list.reloadList(true);
}
}),
$userCheckbox = Ox.Checkbox({
title: Ox._('Only show my files'),
title: Ox._('Only show my documents'),
value: false
})
.css({float: 'left', margin: '4px 2px'})
@ -146,7 +146,7 @@ pandora.ui.filesDialog = function() {
}
],
columnsVisible: true,
items: pandora.api.findFiles,
items: pandora.api.findDocuments,
keys: ['ratio'],
query: {conditions: [], operator: '&'},
scrollbarVisible: true,
@ -179,7 +179,7 @@ pandora.ui.filesDialog = function() {
})
.bindEvent({
click: function() {
pandora.ui.embedFileDialog(
pandora.ui.embedDocumentDialog(
$list.options('selected')[0]
).open();
}
@ -209,8 +209,8 @@ pandora.ui.filesDialog = function() {
$itemToolbar = Ox.Bar({size: 24}),
$deleteButton = Ox.Button({
title: Ox._('Delete File...'),
width: 96
title: Ox._('Delete Document...'),
width: 128
})
.css({float: 'left', margin: '4px'})
.hide()
@ -221,8 +221,8 @@ pandora.ui.filesDialog = function() {
$uploadButton = Ox.FileButton({
maxFiles: 1,
title: Ox._('Upload File...'),
width: 96
title: Ox._('Upload Document...'),
width: 128
})
.css({float: 'right', margin: '4px'})
.bindEvent({
@ -284,7 +284,7 @@ pandora.ui.filesDialog = function() {
$itemLabel = Ox.Label({
textAlign: 'center',
title: Ox._('No file selected'),
title: Ox._('No document selected'),
width: getLabelWidth()
})
.css({
@ -312,7 +312,7 @@ pandora.ui.filesDialog = function() {
minWidth: 512,
padding: 0,
removeOnClose: true,
title: Ox._('Manage Files'),
title: Ox._('Manage Documents'),
width: dialogWidth
}),
@ -331,13 +331,13 @@ pandora.ui.filesDialog = function() {
that.superClose = that.close;
that.close = function() {
Ox.Request.clearCache('findFiles');
Ox.Request.clearCache('findDocuments');
that.superClose();
};
function deleteFile() {
pandora.ui.deleteFileDialog($list.options('selected')[0], function() {
Ox.Request.clearCache('findFiles');
pandora.ui.deleteDocumentDialog($list.options('selected')[0], function() {
Ox.Request.clearCache('findDocuments');
$list.reloadList();
}).open();
}
@ -364,7 +364,7 @@ pandora.ui.filesDialog = function() {
function renderForm() {
var file = $list.value(selected),
editable = file.user == pandora.user.username
|| pandora.site.capabilities.canEditFiles[pandora.user.level];
|| pandora.site.capabilities.canEditMedia[pandora.user.level];
return Ox.Form({
items: [
Ox.Input({
@ -428,7 +428,7 @@ pandora.ui.filesDialog = function() {
if (event.id == 'name') {
$list.value(file.id, 'id', result.data.id);
}
Ox.Request.clearCache('findFiles');
Ox.Request.clearCache('findDocuments');
$list.reloadList();
});
}
@ -438,7 +438,7 @@ pandora.ui.filesDialog = function() {
function renderPreview() {
var isImage = Ox.contains(['jpg', 'png'], selected.split('.').pop()),
size = getPreviewSize(),
src = '/files/' + selected + (isImage ? '' : '.jpg');
src = '/documents/' + selected + (isImage ? '' : '.jpg');
return Ox.ImageElement({
height: size.height,
src: src,
@ -453,7 +453,7 @@ pandora.ui.filesDialog = function() {
function selectFile() {
var file = $list.value(selected),
editable = file.user == pandora.user.username
|| pandora.site.capabilities.canEditFiles[pandora.user.level];
|| pandora.site.capabilities.canEditMedia[pandora.user.level];
$embedButton[selected ? 'show' : 'hide']();
$closeButton[selected ? 'show' : 'hide']();
setLabel();
@ -471,7 +471,7 @@ pandora.ui.filesDialog = function() {
$itemLabel.options({
title: selected
? selected.split(':').slice(1).join(':')
: Ox._('No file selected'),
: Ox._('No document selected'),
width: getLabelWidth()
});
}
@ -517,9 +517,9 @@ pandora.ui.filesDialog = function() {
}
function uploadFile(data) {
pandora.ui.uploadFileDialog(data.files[0], function(file) {
Ox.Request.clearCache('findFiles');
pandora.api.findFiles({
pandora.ui.uploadDocumentDialog(data.files[0], function(file) {
Ox.Request.clearCache('findDocuments');
pandora.api.findDocuments({
positions: [file.id],
query: $list.options('query'),
sort: $list.options('sort'),

View file

@ -1,11 +1,11 @@
// vim: et:ts=4:sw=4:sts=4:ft=javascript
'use strict';
pandora.ui.embedFileDialog = function(id) {
pandora.ui.embedDocumentDialog = function(id) {
var isImage = Ox.contains(['jpg', 'png'], selected.split('.').pop()),
url = 'http' + (pandora.site.site.https ? 's' : '') + '://'
+ pandora.site.site.url + '/files/' + id,
+ pandora.site.site.url + '/documents/' + id,
$content = Ox.Element()
.css({margin: '16px'})

View file

@ -1,582 +0,0 @@
// vim: et:ts=4:sw=4:sts=4:ft=javascript
'use strict';
pandora.ui.filesView = function(options, self) {
var self = self || {},
that = Ox.Element({}, self)
.defaults({
id: ''
})
.options(options || {});
self.filesQuery = {
conditions: [{
key: 'id',
value: self.options.id,
operator: '=='
}]
};
self.numberOfItems = 0;
self.selected = [];
self.wasChecked = false;
self.$toolbar = Ox.Bar({
size: 24
});
self.$menu = Ox.MenuButton({
items: [
{
disabled: true,
id: 'ignore',
title: Ox._('Ignore Selected Files')
},
{},
{
disabled: !pandora.site.capabilities.canRemoveItems[pandora.user.level],
id: 'delete',
title: Ox._('Delete {0}...', [Ox._(pandora.site.itemName.singular)])
}
],
title: 'set',
type: 'image'
})
.css({
float: 'left',
margin: '4px'
})
.bindEvent({
click: function(data) {
if (data.id == 'ignore') {
ignoreFiles();
} else if (data.id == 'delete') {
deleteItem();
}
}
})
.appendTo(self.$toolbar);
self.$saveButton = Ox.Button({
disabled: true,
title: Ox._('Save Changes'),
width: 128
})
.css({
float: 'right',
margin: '4px'
})
.bindEvent({
click: saveChanges
})
.appendTo(self.$toolbar);
self.$filesList = Ox.TableList({
columns: [
{
clickable: function(data) {
return !data.encoding;
},
format: function(value, data) {
return $('<img>')
.attr({
src: data.encoding
? Ox.UI.getImageURL('symbolSync')
: data.wanted
? Ox.UI.getImageURL('symbolUpload')
: Ox.UI.getImageURL('symbolCheck')
})
.css({
width: '10px',
height: '10px',
padding: '3px',
opacity: (value || data.wanted) ? 1 : 0
});
},
id: 'selected',
operator: '-',
title: Ox._('Status'),
titleImage: 'check',
tooltip: function (data) {
return data.encoding
? Ox._('Processing video on server')
: data.instances.filter(function(i) {return i.ignore; }).length > 0
? Ox._('Use this file')
: Ox._('Dont use this file');
},
visible: true,
width: 16
},
{
align: 'left',
id: 'users',
operator: '+',
title: Ox._('Users'),
visible: true,
width: 60
},
{
align: 'left',
id: 'path',
operator: '+',
title: Ox._('Path'),
visible: true,
width: 360
},
{
editable: true,
id: 'version',
operator: '+',
title: Ox._('Version'),
visible: true,
width: 60
},
{
editable: true,
id: 'part',
operator: '+',
title: Ox._('Part'),
visible: true,
width: 60
},
{
editable: true,
id: 'partTitle',
operator: '+',
title: Ox._('Part Title'),
visible: true,
width: 120
},
{
editable: true,
id: 'language',
operator: '+',
title: Ox._('Language'),
visible: true,
width: 60
},
{
editable: true,
id: 'extension',
operator: '+',
title: Ox._('Extension'),
visible: true,
width: 60
},
{
align: 'left',
id: 'type',
operator: '+',
title: Ox._('Type'),
visible: true,
width: 60
},
{
align: 'right',
format: {type: 'value', args: ['B']},
id: 'size',
operator: '-',
title: Ox._('Size'),
visible: true,
width: 90
},
{
align: 'right',
format: {type: 'resolution', args: ['px']},
id: 'resolution',
operator: '-',
title: Ox._('Resolution'),
visible: true,
width: 90
},
{
align: 'right',
format: {type: 'duration', args: [0, 'short']},
id: 'duration',
operator: '-',
title: Ox._('Duration'),
visible: true,
width: 90
},
{
align: 'left',
id: 'id',
operator: '+',
title: Ox._('ID'),
visible: false,
width: 120
},
{
align: 'left',
id: 'instances',
operator: '+',
title: Ox._('Instances'),
visible: false,
width: 120
}
],
columnsMovable: true,
columnsRemovable: true,
columnsResizable: true,
columnsVisible: true,
id: 'files',
items: function(data, callback) {
pandora.api.findMedia(Ox.extend(data, {
query: self.filesQuery
}), callback);
},
keys: ['encoding', 'instances', 'wanted'],
scrollbarVisible: true,
sort: [{key: 'path', operator: '+'}],
unique: 'id'
})
.bindEvent({
click: function(data) {
if (data.key == 'selected') {
var ignored = self.$filesList.value(data.id, 'instances')
.filter(function(i) {return i.ignore; }).length > 0;
pandora.api.editMedia({
files: [{
id: data.id,
ignore: !ignored
}]
}, function(result) {
Ox.Request.clearCache();
self.$filesList.reloadList();
});
}
},
'delete': function(data) {
var ids = data.ids.filter(function(id) {
return self.$filesList.value(id, 'instances').length == 0;
});
if (ids.length > 0 && pandora.user.level == 'admin') {
pandora.api.removeMedia({
ids: ids
}, function(result) {
Ox.Request.clearCache();
self.$filesList.reloadList();
});
}
},
init: function(data) {
self.numberOfItems = data.items;
},
select: selectFiles,
submit: function(data) {
var value = self.$filesList.value(data.id, data.key);
if (data.value != value && !(data.value === '' && value === null)) {
self.$saveButton.options({disabled: false});
self.$filesList.value(data.id, data.key, data.value || null);
}
}
});
self.$instancesList = Ox.TableList({
columns: [
{
align: 'left',
id: 'user',
operator: '+',
title: Ox._('User'),
visible: true,
width: 120
},
{
align: 'left',
id: 'volume',
operator: '+',
title: Ox._('Volume'),
visible: true,
width: 120
},
{
align: 'left',
id: 'path',
operator: '+',
title: Ox._('Path'),
visible: true,
width: 480
},
],
columnsMovable: true,
columnsRemovable: true,
columnsResizable: true,
columnsVisible: true,
id: 'files',
items: [],
scrollbarVisible: true,
sort: [{key: 'user', operator: '+'}],
unique: 'path'
})
.bindEvent({
open: openFiles
});
self.$movieLabel = Ox.Label({
textAlign: 'center',
title: Ox._('Move selected files to another {0}',
[Ox._(pandora.site.itemName.singular.toLowerCase())]),
width: 240
})
.css({margin: '8px'});
['title', 'director', 'year', 'id'].forEach(function(key) {
var itemKey = Ox.getObjectById(pandora.site.itemKeys, key);
self['$' + key + 'Input'] = Ox.Input({
label: Ox._(key == 'id' ? 'ID'
: itemKey ? itemKey.title : Ox.toTitleCase(key)),
labelWidth: 64,
width: 240
})
.bindEvent({
change: function(data) {
var conditions, matches;
if (key == 'id' && data.value.substr(0, 2) != '0x') {
if (pandora.site.site.id == '0xdb') {
matches = data.value.match(/\d{7}/);
} else {
matches = data.value.match(/[A-Z]+/);
}
data.value = matches ? matches[0] : '';
self.$idInput.value(data.value);
}
if (data.value.length) {
conditions = {};
['id', 'title', 'director', 'year'].map(function(key) {
var value = self['$' + key + 'Input'].value();
if (value.length) {
conditions[key] = key == 'director' ? value.split(', ') : value;
}
});
pandora.api.findId(conditions, function(result) {
var length = result.data.items.length;
if (length == 0) {
if (key != 'id') {
self.$idInput.value('');
}
} else if (result.data.items.length == 1) {
['title', 'director', 'year', 'id'].forEach(function(key) {
self['$' + key + 'Input'].value(
key == 'director'
? result.data.items[0][key].join(', ')
: result.data.items[0][key]
);
});
} else {
self.$idInput.value('');
}
});
}
}
});
});
self.$switch = Ox.Checkbox({
title: Ox._('Switch to this {0} after moving files',
[Ox._(pandora.site.itemName.singular.toLowerCase())]),
value: false,
width: 240
});
self.$movieForm = Ox.Form({
items: [
self.$titleInput,
self.$directorInput,
self.$yearInput,
self.$idInput,
self.$switch
],
width: 240
})
.css({margin: '8px'});
self.$clearButton = Ox.Button({
title: Ox._('Clear Form'),
width: 116
})
.css({margin: '0 4px 4px 8px'})
.bindEvent({
click: function() {
['title', 'director', 'year', 'id'].forEach(function(key) {
self['$' + key + 'Input'].value('');
});
}
});
self.$moveButton = Ox.Button({
disabled: true,
title: Ox._('Move Files'),
width: 116
})
.css({margin: '0 4px 4px 4px'})
.bindEvent({
click: moveFiles
});
self.$moviePanel = Ox.Element()
.append(self.$movieLabel)
.append(self.$movieForm)
.append(self.$clearButton)
.append(self.$moveButton);
that.setElement(Ox.SplitPanel({
elements: [
{
element: Ox.SplitPanel({
elements: [
{
element: self.$toolbar,
size: 24
},
{
element: self.$filesList
},
{
element: self.$instancesList,
size: 80
}
],
orientation: 'vertical'
})
},
{
collapsible: true,
element: self.$moviePanel,
size: 256
}
],
orientation: 'horizontal'
})
);
function deleteItem(data) {
pandora.api.get({
id: pandora.user.ui.item,
keys: ['id', 'title']
},function(result) {
pandora.ui.deleteItemDialog(result.data).open();
});
}
function ignoreFiles() {
pandora.api.editMedia({
files: self.selected.map(function(id) {
return {id: id, ignore: true};
})
}, function(result) {
Ox.Request.clearCache();
self.$filesList.reloadList();
});
}
function moveFiles(data) {
var data = {
ids: self.selected,
itemId: self.$idInput.value()
};
['title', 'director', 'year'].forEach(function(key) {
data[key] = self['$' + key + 'Input'].value();
});
self.$moveButton.options(
{disabled: true, title: Ox._('Moving Files...')}
);
pandora.api.moveMedia(data, function(result) {
if (
pandora.user.ui.item == self.options.id
&& pandora.user.ui.itemView == 'files'
) {
Ox.Request.clearCache(); // fixme: remove
if (self.$switch.value()) {
pandora.UI.set({item: result.data.itemId});
pandora.updateItemContext();
} else {
self.$filesList.reloadList();
self.$instancesList.reloadList();
self.$moveButton.options(
{disabled: false, title: Ox._('Move Files')}
);
}
}
});
}
function openFiles(data) {
data.ids.length == 1 && pandora.api.parsePath({
path: self.$instancesList.value(data.ids[0], 'path')
}, function(result) {
['title', 'director', 'year'].forEach(function(key) {
if (result.data[key]) {
self['$' + key + 'Input'].value(
key == 'director'
? result.data[key].join(', ')
: result.data[key]
);
}
});
updateForm();
self.$titleInput.triggerEvent('change', {value: result.data['title']});
});
}
function selectFiles(data) {
self.selected = data.ids;
self.$instancesList.options({
items: data.ids.length == 1
? self.$filesList.value(data.ids[0], 'instances') : []
});
updateForm();
}
function saveChanges() {
self.$saveButton.options({disabled: true, title: Ox._('Saving Changes...')});
pandora.api.findMedia({
keys: ['id'],
query: self.filesQuery
}, function(result) {
pandora.api.editMedia({
files: result.data.items.map(function(item) {
[
'version', 'part', 'partTitle', 'language', 'extension'
].forEach(function(key) {
Ox.extend(item, key, self.$filesList.value(item.id, key));
})
return item;
})
}, function(result) {
self.$saveButton.options({title: Ox._('Save Changes')});
Ox.Request.clearCache(); // fixme: remove
self.$filesList.reloadList();
});
});
}
function updateForm() {
if (self.selected.length == self.numberOfItems) {
self.wasChecked = self.$switch.value();
self.$switch.options({
disabled: true,
value: true
});
} else {
self.$switch.options({
disabled: false,
value: self.wasChecked
});
}
self.$moveButton.options({
disabled: self.selected.length == 0
});
self.$menu[
self.selected.length == 0 ? 'disableItem' : 'enableItem'
]('ignore');
}
that.reload = function() {
self.$filesList.reloadList();
}
return that;
};

View file

@ -116,10 +116,10 @@ pandora.ui.item = function() {
Ox.Container().append(pandora.$ui.item)
);
} else if (pandora.user.ui.itemView == 'files') {
} else if (pandora.user.ui.itemView == 'media') {
pandora.$ui.contentPanel.replaceElement(1,
pandora.$ui.item = pandora.ui.filesView({
pandora.$ui.item = pandora.ui.mediaView({
id: result.data.id
})
);
@ -127,7 +127,7 @@ pandora.ui.item = function() {
} else if (pandora.user.ui.itemView == 'frames' || pandora.user.ui.itemView == 'posters') {
pandora.$ui.contentPanel.replaceElement(1,
pandora.$ui.item = pandora.ui.mediaView().bindEvent({
pandora.$ui.item = pandora.ui.PostersView().bindEvent({
resize: function() {
pandora.$ui.item.resize();
}

View file

@ -178,7 +178,7 @@ pandora.ui.mainMenu = function() {
{ id: 'findsimilar', title: Ox._('Find Similar Clips...'), keyboard: 'alt control f', disabled: !pandora.getItemIdAndPosition() }
] },
{ id: 'dataMenu', title: Ox._('Data'), items: [
{ id: 'files', title: Ox._('Manage Files...'), disabled: !pandora.site.capabilities.canManageFiles[pandora.user.level] },
{ id: 'documents', title: Ox._('Manage Documents...'), disabled: !pandora.site.capabilities.canManageDocuments[pandora.user.level] },
{},
{ id: 'titles', title: Ox._('Manage Titles...'), disabled: !pandora.site.capabilities.canManageTitlesAndNames[pandora.user.level] },
{ id: 'names', title: Ox._('Manage Names...'), disabled: !pandora.site.capabilities.canManageTitlesAndNames[pandora.user.level] },
@ -374,8 +374,8 @@ pandora.ui.mainMenu = function() {
pandora.$ui.filterDialog = pandora.ui.filterDialog().open();
} else if (data.id == 'findsimilar') {
pandora.$ui.sequencesDialog = pandora.ui.sequencesDialog().open();
} else if (data.id == 'files') {
pandora.$ui.filesDialog = pandora.ui.filesDialog().open();
} else if (data.id == 'documents') {
pandora.$ui.documentsDialog = pandora.ui.documentsDialog().open();
} else if (data.id == 'titles') {
(pandora.$ui.titlesDialog || (
pandora.$ui.titlesDialog = pandora.ui.titlesDialog()

View file

@ -1,160 +1,582 @@
// vim: et:ts=4:sw=4:sts=4:ft=javascript
'use strict';
pandora.ui.mediaView = function() {
pandora.ui.mediaView = function(options, self) {
var item = pandora.user.ui.item,
view = pandora.user.ui.itemView,
listWidth = 144 + Ox.UI.SCROLLBAR_SIZE,
selectedImage = {};
$preview = Ox.Element(),
that = Ox.SplitPanel({
elements: [
var self = self || {},
that = Ox.Element({}, self)
.defaults({
id: ''
})
.options(options || {});
self.filesQuery = {
conditions: [{
key: 'id',
value: self.options.id,
operator: '=='
}]
};
self.numberOfItems = 0;
self.selected = [];
self.wasChecked = false;
self.$toolbar = Ox.Bar({
size: 24
});
self.$menu = Ox.MenuButton({
items: [
{
element: Ox.Element(),
size: listWidth
disabled: true,
id: 'ignore',
title: Ox._('Ignore Selected Media')
},
{},
{
disabled: !pandora.site.capabilities.canRemoveItems[pandora.user.level],
id: 'delete',
title: Ox._('Delete {0}...', [Ox._(pandora.site.itemName.singular)])
}
],
title: 'set',
type: 'image'
})
.css({
float: 'left',
margin: '4px'
})
.bindEvent({
click: function(data) {
if (data.id == 'ignore') {
ignoreFiles();
} else if (data.id == 'delete') {
deleteItem();
}
}
})
.appendTo(self.$toolbar);
self.$saveButton = Ox.Button({
disabled: true,
title: Ox._('Save Changes'),
width: 128
})
.css({
float: 'right',
margin: '4px'
})
.bindEvent({
click: saveChanges
})
.appendTo(self.$toolbar);
self.$filesList = Ox.TableList({
columns: [
{
clickable: function(data) {
return !data.encoding;
},
format: function(value, data) {
return $('<img>')
.attr({
src: data.encoding
? Ox.UI.getImageURL('symbolSync')
: data.wanted
? Ox.UI.getImageURL('symbolUpload')
: Ox.UI.getImageURL('symbolCheck')
})
.css({
width: '10px',
height: '10px',
padding: '3px',
opacity: (value || data.wanted) ? 1 : 0
});
},
id: 'selected',
operator: '-',
title: Ox._('Status'),
titleImage: 'check',
tooltip: function (data) {
return data.encoding
? Ox._('Processing video on server')
: data.instances.filter(function(i) {return i.ignore; }).length > 0
? Ox._('Use this file')
: Ox._('Dont use this file');
},
visible: true,
width: 16
},
{
element: $preview
align: 'left',
id: 'users',
operator: '+',
title: Ox._('Users'),
visible: true,
width: 60
},
{
align: 'left',
id: 'path',
operator: '+',
title: Ox._('Path'),
visible: true,
width: 360
},
{
editable: true,
id: 'version',
operator: '+',
title: Ox._('Version'),
visible: true,
width: 60
},
{
editable: true,
id: 'part',
operator: '+',
title: Ox._('Part'),
visible: true,
width: 60
},
{
editable: true,
id: 'partTitle',
operator: '+',
title: Ox._('Part Title'),
visible: true,
width: 120
},
{
editable: true,
id: 'language',
operator: '+',
title: Ox._('Language'),
visible: true,
width: 60
},
{
editable: true,
id: 'extension',
operator: '+',
title: Ox._('Extension'),
visible: true,
width: 60
},
{
align: 'left',
id: 'type',
operator: '+',
title: Ox._('Type'),
visible: true,
width: 60
},
{
align: 'right',
format: {type: 'value', args: ['B']},
id: 'size',
operator: '-',
title: Ox._('Size'),
visible: true,
width: 90
},
{
align: 'right',
format: {type: 'resolution', args: ['px']},
id: 'resolution',
operator: '-',
title: Ox._('Resolution'),
visible: true,
width: 90
},
{
align: 'right',
format: {type: 'duration', args: [0, 'short']},
id: 'duration',
operator: '-',
title: Ox._('Duration'),
visible: true,
width: 90
},
{
align: 'left',
id: 'id',
operator: '+',
title: Ox._('ID'),
visible: false,
width: 120
},
{
align: 'left',
id: 'instances',
operator: '+',
title: Ox._('Instances'),
visible: false,
width: 120
}
],
columnsMovable: true,
columnsRemovable: true,
columnsResizable: true,
columnsVisible: true,
id: 'files',
items: function(data, callback) {
pandora.api.findMedia(Ox.extend(data, {
query: self.filesQuery
}), callback);
},
keys: ['encoding', 'instances', 'wanted'],
scrollbarVisible: true,
sort: [{key: 'path', operator: '+'}],
unique: 'id'
})
.bindEvent({
click: function(data) {
if (data.key == 'selected') {
var ignored = self.$filesList.value(data.id, 'instances')
.filter(function(i) {return i.ignore; }).length > 0;
pandora.api.editMedia({
files: [{
id: data.id,
ignore: !ignored
}]
}, function(result) {
Ox.Request.clearCache();
self.$filesList.reloadList();
});
}
},
'delete': function(data) {
var ids = data.ids.filter(function(id) {
return self.$filesList.value(id, 'instances').length == 0;
});
if (ids.length > 0 && pandora.user.level == 'admin') {
pandora.api.removeMedia({
ids: ids
}, function(result) {
Ox.Request.clearCache();
self.$filesList.reloadList();
});
}
},
init: function(data) {
self.numberOfItems = data.items;
},
select: selectFiles,
submit: function(data) {
var value = self.$filesList.value(data.id, data.key);
if (data.value != value && !(data.value === '' && value === null)) {
self.$saveButton.options({disabled: false});
self.$filesList.value(data.id, data.key, data.value || null);
}
}
});
self.$instancesList = Ox.TableList({
columns: [
{
align: 'left',
id: 'user',
operator: '+',
title: Ox._('User'),
visible: true,
width: 120
},
{
align: 'left',
id: 'volume',
operator: '+',
title: Ox._('Volume'),
visible: true,
width: 120
},
{
align: 'left',
id: 'path',
operator: '+',
title: Ox._('Path'),
visible: true,
width: 480
},
],
columnsMovable: true,
columnsRemovable: true,
columnsResizable: true,
columnsVisible: true,
id: 'files',
items: [],
scrollbarVisible: true,
sort: [{key: 'user', operator: '+'}],
unique: 'path'
})
.bindEvent({
open: openFiles
});
self.$movieLabel = Ox.Label({
textAlign: 'center',
title: Ox._('Move selected files to another {0}',
[Ox._(pandora.site.itemName.singular.toLowerCase())]),
width: 240
})
.css({margin: '8px'});
['title', 'director', 'year', 'id'].forEach(function(key) {
var itemKey = Ox.getObjectById(pandora.site.itemKeys, key);
self['$' + key + 'Input'] = Ox.Input({
label: Ox._(key == 'id' ? 'ID'
: itemKey ? itemKey.title : Ox.toTitleCase(key)),
labelWidth: 64,
width: 240
})
.bindEvent({
change: function(data) {
var conditions, matches;
if (key == 'id' && data.value.substr(0, 2) != '0x') {
if (pandora.site.site.id == '0xdb') {
matches = data.value.match(/\d{7}/);
} else {
matches = data.value.match(/[A-Z]+/);
}
data.value = matches ? matches[0] : '';
self.$idInput.value(data.value);
}
if (data.value.length) {
conditions = {};
['id', 'title', 'director', 'year'].map(function(key) {
var value = self['$' + key + 'Input'].value();
if (value.length) {
conditions[key] = key == 'director' ? value.split(', ') : value;
}
});
pandora.api.findId(conditions, function(result) {
var length = result.data.items.length;
if (length == 0) {
if (key != 'id') {
self.$idInput.value('');
}
} else if (result.data.items.length == 1) {
['title', 'director', 'year', 'id'].forEach(function(key) {
self['$' + key + 'Input'].value(
key == 'director'
? result.data.items[0][key].join(', ')
: result.data.items[0][key]
);
});
} else {
self.$idInput.value('');
}
});
}
}
});
});
self.$switch = Ox.Checkbox({
title: Ox._('Switch to this {0} after moving files',
[Ox._(pandora.site.itemName.singular.toLowerCase())]),
value: false,
width: 240
});
self.$movieForm = Ox.Form({
items: [
self.$titleInput,
self.$directorInput,
self.$yearInput,
self.$idInput,
self.$switch
],
width: 240
})
.css({margin: '8px'});
self.$clearButton = Ox.Button({
title: Ox._('Clear Form'),
width: 116
})
.css({margin: '0 4px 4px 8px'})
.bindEvent({
click: function() {
['title', 'director', 'year', 'id'].forEach(function(key) {
self['$' + key + 'Input'].value('');
});
}
});
self.$moveButton = Ox.Button({
disabled: true,
title: Ox._('Move Media'),
width: 116
})
.css({margin: '0 4px 4px 4px'})
.bindEvent({
click: moveFiles
});
self.$moviePanel = Ox.Element()
.append(self.$movieLabel)
.append(self.$movieForm)
.append(self.$clearButton)
.append(self.$moveButton);
that.setElement(Ox.SplitPanel({
elements: [
{
element: Ox.SplitPanel({
elements: [
{
element: self.$toolbar,
size: 24
},
{
element: self.$filesList
},
{
element: self.$instancesList,
size: 80
}
],
orientation: 'vertical'
})
},
{
collapsible: true,
element: self.$moviePanel,
size: 256
}
],
orientation: 'horizontal'
});
that.resize = function() {
selectedImage.url && renderPreview();
}
pandora.api.get({
id: item,
keys: [view]
}, function(result) {
var images = result.data[view];
selectedImage = images.filter(function(image) {
return image.selected;
})[0];
var $list = Ox.IconList({
item: function(data, sort, size) {
var ratio = data.width / data.height;
size = size || 128;
return {
height: ratio <= 1 ? size : size / ratio,
id: data['id'],
info: data.width + ' x ' + data.height + ' px',
title: view == 'frames' ? Ox.formatDuration(data.position) : data.source,
url: data.url,
width: ratio >= 1 ? size : size * ratio
}
},
items: images,
keys: view == 'frames'
? ['index', 'position', 'width', 'height', 'url']
: ['index', 'source', 'width', 'height', 'url'],
max: 1,
min: 1,
orientation: 'vertical',
selected: [selectedImage['index']],
size: 128,
sort: [{key: 'index', operator: '+'}],
unique: 'index'
})
.css({background: 'rgb(16, 16, 16)'})
.bindEvent({
select: function(event) {
var index = event.ids[0];
selectedImage = images.filter(function(image) {
return image.index == index;
})[0];
renderPreview(selectedImage);
pandora.api[view == 'frames' ? 'setPosterFrame' : 'setPoster'](Ox.extend({
id: item
}, view == 'frames' ? {
position: selectedImage.index // api slightly inconsistent
} : {
source: selectedImage.source
}), function(result) {
var imageRatio = selectedImage.width / selectedImage.height;
$('img[src*="/' + item + '/poster"]').each(function() {
var $this = $(this),
size = Math.max($this.width(), $this.height()),
src = $this.attr('src').split('?')[0] + '?' + Ox.uid();
$('<img>')
.attr({src: src})
.load(function() {
$this.attr({src: src});
view == 'posters' && $this.css(imageRatio < 1 ? {
width: Math.round(size * imageRatio) + 'px',
height: size + 'px'
} : {
width: size + 'px',
height: Math.round(size / imageRatio) + 'px'
});
});
});
});
}
});
that.replaceElement(0, $list);
renderPreview();
});
function renderPreview() {
var previewWidth = pandora.$ui.document.width() - pandora.$ui.mainPanel.size(0) - 1 - listWidth,
previewHeight = pandora.$ui.contentPanel.size(1),
previewRatio = previewWidth / previewHeight,
imageRatio = selectedImage.width / selectedImage.height,
imageWidth = imageRatio > previewRatio ? previewWidth : Math.round(previewHeight * imageRatio),
imageHeight = imageRatio < previewRatio ? previewHeight : Math.round(previewWidth / imageRatio),
imageLeft = Math.floor((previewWidth - imageWidth) / 2),
imageTop = Math.floor((previewHeight - imageHeight) / 2);
$preview.html(
$('<img>')
.attr({
src: selectedImage.url
})
.css({
position: 'absolute',
left: imageLeft + 'px',
top: imageTop + 'px',
width: imageWidth + 'px',
height: imageHeight + 'px'
})
);
if (view == 'frames') {
var left = Math.floor((imageWidth - imageHeight) / 2),
right = Math.ceil((imageWidth - imageHeight) / 2);
$('<div>')
.addClass('OxPosterMarker OxPosterMarkerLeft')
.css({
display: 'block',
left: imageLeft + 'px',
top: imageTop + 'px',
width: left + 'px',
height: imageHeight + 'px'
})
.appendTo($preview.$element);
$('<div>')
.addClass('OxPosterMarker OxPosterMarkerCenter')
.css({
display: 'block',
left: imageLeft + left + 'px',
top: imageTop + 'px',
width: imageHeight - 2 + 'px',
height: imageHeight - 2 + 'px'
})
.appendTo($preview.$element);
$('<div>')
.addClass('OxPosterMarker OxPosterMarkerRight')
.css({
display: 'block',
left: imageLeft + left + imageHeight + 'px',
top: imageTop + 'px',
width: right + 'px',
height: imageHeight + 'px'
})
.appendTo($preview.$element);
}
function deleteItem(data) {
pandora.api.get({
id: pandora.user.ui.item,
keys: ['id', 'title']
},function(result) {
pandora.ui.deleteItemDialog(result.data).open();
});
}
function ignoreFiles() {
pandora.api.editMedia({
files: self.selected.map(function(id) {
return {id: id, ignore: true};
})
}, function(result) {
Ox.Request.clearCache();
self.$filesList.reloadList();
});
}
function moveFiles(data) {
var data = {
ids: self.selected,
itemId: self.$idInput.value()
};
['title', 'director', 'year'].forEach(function(key) {
data[key] = self['$' + key + 'Input'].value();
});
self.$moveButton.options(
{disabled: true, title: Ox._('Moving Media...')}
);
pandora.api.moveMedia(data, function(result) {
if (
pandora.user.ui.item == self.options.id
&& pandora.user.ui.itemView == 'files'
) {
Ox.Request.clearCache(); // fixme: remove
if (self.$switch.value()) {
pandora.UI.set({item: result.data.itemId});
pandora.updateItemContext();
} else {
self.$filesList.reloadList();
self.$instancesList.reloadList();
self.$moveButton.options(
{disabled: false, title: Ox._('Move Media')}
);
}
}
});
}
function openFiles(data) {
data.ids.length == 1 && pandora.api.parsePath({
path: self.$instancesList.value(data.ids[0], 'path')
}, function(result) {
['title', 'director', 'year'].forEach(function(key) {
if (result.data[key]) {
self['$' + key + 'Input'].value(
key == 'director'
? result.data[key].join(', ')
: result.data[key]
);
}
});
updateForm();
self.$titleInput.triggerEvent('change', {value: result.data['title']});
});
}
function selectFiles(data) {
self.selected = data.ids;
self.$instancesList.options({
items: data.ids.length == 1
? self.$filesList.value(data.ids[0], 'instances') : []
});
updateForm();
}
function saveChanges() {
self.$saveButton.options({disabled: true, title: Ox._('Saving Changes...')});
pandora.api.findMedia({
keys: ['id'],
query: self.filesQuery
}, function(result) {
pandora.api.editMedia({
files: result.data.items.map(function(item) {
[
'version', 'part', 'partTitle', 'language', 'extension'
].forEach(function(key) {
Ox.extend(item, key, self.$filesList.value(item.id, key));
})
return item;
})
}, function(result) {
self.$saveButton.options({title: Ox._('Save Changes')});
Ox.Request.clearCache(); // fixme: remove
self.$filesList.reloadList();
});
});
}
function updateForm() {
if (self.selected.length == self.numberOfItems) {
self.wasChecked = self.$switch.value();
self.$switch.options({
disabled: true,
value: true
});
} else {
self.$switch.options({
disabled: false,
value: self.wasChecked
});
}
self.$moveButton.options({
disabled: self.selected.length == 0
});
self.$menu[
self.selected.length == 0 ? 'disableItem' : 'enableItem'
]('ignore');
}
that.reload = function() {
self.$filesList.reloadList();
}
return that;
}
};

View file

@ -0,0 +1,160 @@
'use strict';
pandora.ui.posterView = function() {
var item = pandora.user.ui.item,
view = pandora.user.ui.itemView,
listWidth = 144 + Ox.UI.SCROLLBAR_SIZE,
selectedImage = {};
$preview = Ox.Element(),
that = Ox.SplitPanel({
elements: [
{
element: Ox.Element(),
size: listWidth
},
{
element: $preview
}
],
orientation: 'horizontal'
});
that.resize = function() {
selectedImage.url && renderPreview();
}
pandora.api.get({
id: item,
keys: [view]
}, function(result) {
var images = result.data[view];
selectedImage = images.filter(function(image) {
return image.selected;
})[0];
var $list = Ox.IconList({
item: function(data, sort, size) {
var ratio = data.width / data.height;
size = size || 128;
return {
height: ratio <= 1 ? size : size / ratio,
id: data['id'],
info: data.width + ' x ' + data.height + ' px',
title: view == 'frames' ? Ox.formatDuration(data.position) : data.source,
url: data.url,
width: ratio >= 1 ? size : size * ratio
}
},
items: images,
keys: view == 'frames'
? ['index', 'position', 'width', 'height', 'url']
: ['index', 'source', 'width', 'height', 'url'],
max: 1,
min: 1,
orientation: 'vertical',
selected: [selectedImage['index']],
size: 128,
sort: [{key: 'index', operator: '+'}],
unique: 'index'
})
.css({background: 'rgb(16, 16, 16)'})
.bindEvent({
select: function(event) {
var index = event.ids[0];
selectedImage = images.filter(function(image) {
return image.index == index;
})[0];
renderPreview(selectedImage);
pandora.api[view == 'frames' ? 'setPosterFrame' : 'setPoster'](Ox.extend({
id: item
}, view == 'frames' ? {
position: selectedImage.index // api slightly inconsistent
} : {
source: selectedImage.source
}), function(result) {
var imageRatio = selectedImage.width / selectedImage.height;
$('img[src*="/' + item + '/poster"]').each(function() {
var $this = $(this),
size = Math.max($this.width(), $this.height()),
src = $this.attr('src').split('?')[0] + '?' + Ox.uid();
$('<img>')
.attr({src: src})
.load(function() {
$this.attr({src: src});
view == 'posters' && $this.css(imageRatio < 1 ? {
width: Math.round(size * imageRatio) + 'px',
height: size + 'px'
} : {
width: size + 'px',
height: Math.round(size / imageRatio) + 'px'
});
});
});
});
}
});
that.replaceElement(0, $list);
renderPreview();
});
function renderPreview() {
var previewWidth = pandora.$ui.document.width() - pandora.$ui.mainPanel.size(0) - 1 - listWidth,
previewHeight = pandora.$ui.contentPanel.size(1),
previewRatio = previewWidth / previewHeight,
imageRatio = selectedImage.width / selectedImage.height,
imageWidth = imageRatio > previewRatio ? previewWidth : Math.round(previewHeight * imageRatio),
imageHeight = imageRatio < previewRatio ? previewHeight : Math.round(previewWidth / imageRatio),
imageLeft = Math.floor((previewWidth - imageWidth) / 2),
imageTop = Math.floor((previewHeight - imageHeight) / 2);
$preview.html(
$('<img>')
.attr({
src: selectedImage.url
})
.css({
position: 'absolute',
left: imageLeft + 'px',
top: imageTop + 'px',
width: imageWidth + 'px',
height: imageHeight + 'px'
})
);
if (view == 'frames') {
var left = Math.floor((imageWidth - imageHeight) / 2),
right = Math.ceil((imageWidth - imageHeight) / 2);
$('<div>')
.addClass('OxPosterMarker OxPosterMarkerLeft')
.css({
display: 'block',
left: imageLeft + 'px',
top: imageTop + 'px',
width: left + 'px',
height: imageHeight + 'px'
})
.appendTo($preview.$element);
$('<div>')
.addClass('OxPosterMarker OxPosterMarkerCenter')
.css({
display: 'block',
left: imageLeft + left + 'px',
top: imageTop + 'px',
width: imageHeight - 2 + 'px',
height: imageHeight - 2 + 'px'
})
.appendTo($preview.$element);
$('<div>')
.addClass('OxPosterMarker OxPosterMarkerRight')
.css({
display: 'block',
left: imageLeft + left + imageHeight + 'px',
top: imageTop + 'px',
width: right + 'px',
height: imageHeight + 'px'
})
.appendTo($preview.$element);
}
}
return that;
}

View file

@ -1,7 +1,7 @@
// vim: et:ts=4:sw=4:sts=4:ft=javascript
'use strict';
pandora.ui.uploadFileDialog = function(file, callback) {
pandora.ui.uploadDocumentDialog = function(file, callback) {
var extension = file.name.split('.').pop().toLowerCase(),
@ -65,7 +65,7 @@ pandora.ui.uploadFileDialog = function(file, callback) {
filename: filename
},
file: file,
url: '/api/upload/file/',
url: '/api/upload/document/',
})
.bindEvent({
done: function(data) {
@ -89,7 +89,7 @@ pandora.ui.uploadFileDialog = function(file, callback) {
return errorDialog(Ox._('Supported file types are GIF, JPG, PNG and PDF.'));
} else {
Ox.oshash(file, function(oshash) {
pandora.api.findFiles({
pandora.api.findDocuments({
keys: ['id'],
query: {
conditions: [{key: 'oshash', value: oshash, operator: '=='}],

View file

@ -1031,7 +1031,7 @@ pandora.getSpan = function(state, str, callback) {
pandora.getStatusText = function(data) {
var ui = pandora.user.ui,
canSeeFiles = pandora.site.capabilities.canSeeFiles[pandora.user.level],
canSeeMedia = pandora.site.capabilities.canSeeMedia[pandora.user.level],
canSeeSize = pandora.site.capabilities.canSeeSize[pandora.user.level],
itemName = ui.listView == 'clip'
? (data.items == 1 ? Ox._('Clip') : Ox._('Clips'))
@ -1043,7 +1043,7 @@ pandora.getStatusText = function(data) {
} else if (data.duration) {
parts.push(Ox.formatDuration(data.duration, 'short'));
}
if (canSeeFiles) {
if (canSeeMedia) {
data.files && parts.push(
Ox.formatCount(data.files, 'file')
);
@ -1052,7 +1052,7 @@ pandora.getStatusText = function(data) {
if (canSeeSize) {
data.size && parts.push(Ox.formatValue(data.size, 'B'));
}
if (canSeeFiles) {
if (canSeeMedia) {
data.pixels && parts.push(Ox.formatValue(data.pixels, 'px'));
}
return parts.join(', ');

View file

@ -7,7 +7,7 @@ pandora.ui.viewSelect = function() {
sortKey = !ui.item ? 'listSort' : 'itemSort',
viewKey = !ui.item ? 'listView' : 'itemView',
items = pandora.site[viewKey + 's'].filter(function(view) {
return view.id != 'data' && view.id != 'files';
return view.id != 'data' && view.id != 'media';
}).map(function(view) {
return {id: view.id, title: Ox._('View {0}', [Ox._(view.title)])};
}),
@ -19,7 +19,7 @@ pandora.ui.viewSelect = function() {
items = items.concat([
{},
{id: 'data', title: Ox._('View Data')},
{id: 'files', title: Ox._('View Files')}
{id: 'media', title: Ox._('View Media')}
]);
}
that = Ox.Select({

View file

@ -65,8 +65,8 @@
"Default View: ...": "",
"Define Place or Event...": "",
"Delete": "",
"Delete File": "",
"Delete File...": "",
"Delete Document": "",
"Delete Document...": "",
"Delete Selected List...": "",
"Delete Selected Text...": "",
"Delete {0}": "",
@ -106,7 +106,7 @@
"Editor View": "",
"Edits": "",
"Embed": "",
"Embed File": "",
"Embed Document": "",
"Embed Video": "",
"Embeds": "",
"Enable": "",
@ -134,7 +134,6 @@
"Featuring": "",
"File contains {0} annotation": "",
"Filename": "",
"Files": "",
"Filters": "",
"Find Clips": "",
"Find Similar Clips...": "",
@ -173,7 +172,7 @@
"IP Address": "",
"Icon": "",
"Icons": "",
"Ignore Selected Files": "",
"Ignore Selected Media": "",
"Import": "",
"Import Annotations": "",
"Import {0}...": "",
@ -195,7 +194,7 @@
"Invalid e-mail address": "",
"Invert Selection": "",
"Items": "",
"Keep File": "",
"Keep Document": "",
"Keep List Public": "",
"Keep {0}": "",
"Keyframes": "",
@ -225,8 +224,8 @@
"Manage Events...": "",
"Manage Favorite {0}": "",
"Manage Featured {0}": "",
"Manage Files": "",
"Manage Files...": "",
"Manage Documents": "",
"Manage Documents...": "",
"Manage Names": "",
"Manage Names...": "",
"Manage Personal Lists": "",
@ -244,9 +243,9 @@
"Message Sent": "",
"Modified": "",
"Mount Volume": "",
"Move Files": "",
"Move Media": "",
"Move selected files to another {0}": "",
"Moving Files...": "",
"Moving Media...": "",
"Names": "",
"Navigation": "",
"New PDF": "",
@ -449,8 +448,8 @@
"Update Results in the Background": "",
"Upload": "",
"Upload Failed.": "",
"Upload File": "",
"Upload File...": "",
"Upload Document": "",
"Upload Document...": "",
"Upload PDF": "",
"Upload Video": "",
"Upload Video...": "",
@ -467,7 +466,7 @@
"Videos": "",
"View Data": "",
"View Error Logs...": "",
"View Files": "",
"View Media": "",
"View List": "",
"View on IMDb": "",
"View {0}": "",