diff --git a/pandora/text/models.py b/pandora/text/models.py index dedc9dae..af5c5c14 100644 --- a/pandora/text/models.py +++ b/pandora/text/models.py @@ -5,6 +5,7 @@ import os import re import subprocess from glob import glob +from urllib import quote from django.db import models from django.db.models import Max @@ -53,7 +54,10 @@ class Text(models.Model): return self.get_id() def get_absolute_url(self): - return '/texts/%s' % self.get_id() + return '/texts/%s' % quote(self.get_id()) + + def get_absolute_pdf_url(self): + return '/texts/%s/text.pdf' % quote(self.get_id()) def get_id(self): return u'%s:%s' % (self.user.username, self.name) diff --git a/pandora/text/templates/pdf/viewer.html b/pandora/text/templates/pdf/viewer.html new file mode 100644 index 00000000..dfea6593 --- /dev/null +++ b/pandora/text/templates/pdf/viewer.html @@ -0,0 +1,206 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+
+ + +
+
+
+
+
+ +
+
+ +
+ +
+
+
+
+ +
+ +
+ +
+ +
+ + + + +
+
+ + + + + + + + + + + + Current View +
+
+
+
+ +
+ +
+ + + +
+
+
+
+
+ + + + + + + + +
+
+
+ +
+
+
+
+ + +
+ +
+
+ + diff --git a/pandora/text/views.py b/pandora/text/views.py index f1d1cdf3..8e4444c6 100644 --- a/pandora/text/views.py +++ b/pandora/text/views.py @@ -12,6 +12,8 @@ from ox.django.shortcuts import render_to_json_response, get_object_or_404_json, from django import forms from django.db.models import Sum, Max from django.conf import settings +from django.shortcuts import render_to_response +from django.template import RequestContext from item import utils import models @@ -391,6 +393,19 @@ class ChunkForm(forms.Form): chunkId = forms.IntegerField(required=False) done = forms.IntegerField(required=False) +def pdf_viewer(request, id): + text = get_text_or_404_json(id) + if text.type == 'pdf' and text.file and not text.uploading: + context = RequestContext(request, { + 'editable': json.dumps(text.editable(request.user)), + 'links': json.dumps(text.links), + 'settings': settings, + 'url': text.get_absolute_pdf_url() + }) + return render_to_response('pdf/viewer.html', context) + response = json_response(status=404, text='file not found') + return render_to_json_response(response) + def pdf(request, id): text = get_text_or_404_json(id) if text.type == 'pdf' and text.file and not text.uploading: diff --git a/pandora/urls.py b/pandora/urls.py index 7763c8db..e2ca5e3b 100644 --- a/pandora/urls.py +++ b/pandora/urls.py @@ -30,7 +30,8 @@ urlpatterns = patterns('', (r'^resetUI$', 'user.views.reset_ui'), (r'^list/(?P.*?)/icon(?P\d*).jpg$', 'itemlist.views.icon'), (r'^text/(?P.*?)/icon(?P\d*).jpg$', 'text.views.icon'), - (r'^text/(?P.*?)/text.pdf$', 'text.views.pdf'), + (r'^texts/(?P.*?)/text.pdf$', 'text.views.pdf'), + (r'^texts/(?P.*?)/text.pdf.html$', 'text.views.pdf_viewer'), (r'^robots.txt$', serve_static_file, {'location': os.path.join(settings.STATIC_ROOT, 'robots.txt'), 'content_type': 'text/plain'}), (r'^favicon.ico$', serve_static_file, {'location': os.path.join(settings.STATIC_ROOT, 'png/icon.16.png'), 'content_type': 'image/x-icon'}), (r'^opensearch.xml$', 'app.views.opensearch_xml'), diff --git a/static/js/pandora/textPanel.js b/static/js/pandora/textPanel.js index 1646c5c7..29b2c253 100644 --- a/static/js/pandora/textPanel.js +++ b/static/js/pandora/textPanel.js @@ -123,8 +123,8 @@ pandora.ui.textPanel = function() { }) .appendTo($toolbar); } else { - $uploadButton = Ox.Button({ - title: 'upload', + $uploadButton = Ox.FileButton({ + image: 'upload', tooltip: 'Upload PDF', type: 'image' }) @@ -132,6 +132,16 @@ pandora.ui.textPanel = function() { float: 'left', margin: '4px 2px 4px 4px' }) + .bindEvent({ + click: function(data) { + if(data.files.length) { + pandora.$ui.uploadPDFDialog = pandora.ui.uploadPDFDialog({ + file: data.files[0], + id: pandora.user.ui.text + }).open(); + } + } + }) .appendTo($toolbar); } } @@ -270,9 +280,19 @@ pandora.ui.textHTML = function(text, tags) { pandora.ui.textPDF = function(text) { var that = Ox.Element(); + if (text.uploaded) { + $('