add fargo dropbox support to file fields (#6651)
This commit is contained in:
parent
62821a9c95
commit
b3bf4b7c32
|
@ -0,0 +1,60 @@
|
|||
import urllib
|
||||
import urlparse
|
||||
import json
|
||||
|
||||
from quixote import get_publisher, get_request, redirect, get_response, get_session
|
||||
from quixote.directory import Directory
|
||||
from quixote.html import TemplateIO, htmltext
|
||||
|
||||
import qommon.form
|
||||
|
||||
|
||||
class FargoDirectory(Directory):
|
||||
_q_exports = ['pick']
|
||||
|
||||
@property
|
||||
def fargo_url(self):
|
||||
return get_publisher().get_site_option('fargo_url')
|
||||
|
||||
def pick (self):
|
||||
request = get_request()
|
||||
if 'cancel' in request.form:
|
||||
get_response().add_javascript(['jquery.js'])
|
||||
get_response().page_template_key = 'iframe'
|
||||
r = TemplateIO(html=True)
|
||||
r += htmltext('<html><body>')
|
||||
r += htmltext('<script>window.top.document.fargo_close_dialog();</script>')
|
||||
r += htmltext('</body></html>')
|
||||
return r.getvalue()
|
||||
elif 'url' in request.form:
|
||||
# Download file
|
||||
# FIXME: handle error cases
|
||||
url = request.form['url']
|
||||
document = urllib.urlopen(request.form['url']).read()
|
||||
scheme, netloc, path, qs, frag = urlparse.urlsplit(url)
|
||||
path = map(None, path.split('/'))
|
||||
name = urllib.unquote(path[-1])
|
||||
download = qommon.form.PicklableUpload(name,
|
||||
content_type='application/pdf')
|
||||
download.__setstate__({
|
||||
'data': document,
|
||||
})
|
||||
token = get_session().add_tempfile(download)
|
||||
return self.set_token(token, name)
|
||||
else:
|
||||
# Display file picker
|
||||
frontoffice_url = get_publisher().get_frontoffice_url()
|
||||
self_url = frontoffice_url
|
||||
self_url += '/fargo/pick'
|
||||
return redirect('%s?pick=%s' % (self.fargo_url,
|
||||
urllib.quote(self_url)))
|
||||
|
||||
def set_token(self, token, title):
|
||||
get_response().add_javascript(['jquery.js'])
|
||||
get_response().page_template_key = 'iframe'
|
||||
r = TemplateIO(html=True)
|
||||
r += htmltext('<html><body>')
|
||||
r += htmltext('<script>window.top.document.fargo_set_token(%s, %s);</script>' % (
|
||||
json.dumps(token), json.dumps(title)))
|
||||
r += htmltext('</body></html>')
|
||||
return r.getvalue()
|
|
@ -4,16 +4,15 @@ from qommon.form import *
|
|||
class FileWithPreviewAndStrongboxWidget(FileWithPreviewWidget):
|
||||
def render_hint(self, hint):
|
||||
t = CompositeWidget.render_hint(self, hint)
|
||||
root_url = get_publisher().get_root_url()
|
||||
if get_publisher().has_site_option('strongbox') and get_request().user and not self.preview:
|
||||
get_response().add_javascript(['../../aq/js/strongbox.js'])
|
||||
root_url = get_publisher().get_root_url()
|
||||
t += htmltext('''<p class="use-file-from-strongbox"><span
|
||||
data-url="%smyspace/strongbox/pick"
|
||||
rel="popup">%s</span></p>''') % (
|
||||
root_url, _('Use file from strongbox'))
|
||||
if get_publisher().get_site_option('msp') is not None and not self.preview:
|
||||
get_response().add_javascript(['../../aq/js/msp.js'])
|
||||
root_url = get_publisher().get_root_url()
|
||||
t += htmltext('''<p class="use-file-from-msp"><span
|
||||
data-src="%smsp/pick"
|
||||
data-width="500"
|
||||
|
@ -22,4 +21,14 @@ class FileWithPreviewAndStrongboxWidget(FileWithPreviewWidget):
|
|||
rel="popup">%s</span></p>''') % (
|
||||
root_url, _('Pick a file on mon.Service-Public.fr'),
|
||||
_('Use file from mon.Service-Public.fr'))
|
||||
if get_publisher().get_site_option('fargo_url') is not None and not self.preview:
|
||||
get_response().add_javascript(['../../aq/js/fargo.js'])
|
||||
t += htmltext('''<p class="use-file-from-fargo"><span
|
||||
data-src="%sfargo/pick"
|
||||
data-width="500"
|
||||
data-height="400"
|
||||
data-title="%s"
|
||||
rel="popup">%s</span></p>''') % (
|
||||
root_url, _('Pick a file from your dropbox'),
|
||||
_('Use file from my dropbox'))
|
||||
return t
|
||||
|
|
|
@ -54,6 +54,7 @@ import qommon.ident.password
|
|||
import qommon.ident.idp
|
||||
|
||||
import msp_ui
|
||||
import fargo_ui
|
||||
|
||||
def category_get_homepage_position(self):
|
||||
if hasattr(self, 'homepage_position') and self.homepage_position:
|
||||
|
@ -758,7 +759,7 @@ class AlternateRootDirectory(OldRootDirectory):
|
|||
'myspace', 'services', 'agenda', 'categories', 'user',
|
||||
('tmp-upload', 'tmp_upload'), 'json', '__version__',
|
||||
'themes', 'pages', 'payment', 'invoices', 'accesscode', 'roles',
|
||||
'msp', 'api', 'code']
|
||||
'msp', 'api', 'code', 'fargo']
|
||||
|
||||
admin = admin.AdminRootDirectory()
|
||||
announces_dir = AnnouncesDirectory()
|
||||
|
@ -771,6 +772,7 @@ class AlternateRootDirectory(OldRootDirectory):
|
|||
payment = PublicPaymentDirectory()
|
||||
invoices = InvoicesDirectory()
|
||||
msp = msp_ui.MSPDirectory()
|
||||
fargo = fargo_ui.FargoDirectory()
|
||||
code = wcs.forms.root.TrackingCodesDirectory()
|
||||
|
||||
def get_substitution_variables(self):
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
|
||||
$(function() {
|
||||
var iframe = $('<iframe frameborder="0" marginwidth="0" marginheight="0" allowfullscreen></iframe>');
|
||||
var dialog = $("<div></div>").append(iframe).appendTo("body").dialog({
|
||||
autoOpen: false,
|
||||
modal: true,
|
||||
resizable: false,
|
||||
width: "auto",
|
||||
height: "auto",
|
||||
close: function () {
|
||||
iframe.attr("src", "");
|
||||
}
|
||||
});
|
||||
$('p.use-file-from-fargo span').click(function(e) {
|
||||
e.preventDefault();
|
||||
var base_widget = $(this).parents('.file-upload-widget');
|
||||
document.fargo_set_token = function (token, title) {
|
||||
if (token) {
|
||||
$(base_widget).find('.filename').text(title);
|
||||
$(base_widget).find('.fileinfo').show();
|
||||
$(base_widget).find('input[type=hidden]').val(token);
|
||||
$(base_widget).find('input[type=file]').hide();
|
||||
}
|
||||
document.fargo_close_dialog();
|
||||
}
|
||||
document.fargo_close_dialog = function () {
|
||||
document.fargo_set_token = undefined;
|
||||
dialog.dialog('close');
|
||||
}
|
||||
var src = $(this).data('src');
|
||||
var title = $(this).data("title");
|
||||
var width = $(this).data("width");
|
||||
var height = $(this).data("height");
|
||||
iframe.attr({
|
||||
width: parseInt(width),
|
||||
height: parseInt(height),
|
||||
src: src
|
||||
});
|
||||
dialog.dialog("option", "title", title);
|
||||
dialog.dialog("open");
|
||||
});
|
||||
});
|
Reference in New Issue