0001-add-fargo-dropbox-support-to-file-fields-6651.patch
extra/modules/fargo_ui.py | ||
---|---|---|
1 |
import urllib |
|
2 |
import urlparse |
|
3 |
import json |
|
4 | ||
5 |
from quixote import get_publisher, get_request, redirect, get_response, get_session |
|
6 |
from quixote.directory import Directory |
|
7 |
from quixote.html import TemplateIO, htmltext |
|
8 | ||
9 |
import qommon.form |
|
10 | ||
11 | ||
12 |
class FargoDirectory(Directory): |
|
13 |
_q_exports = ['pick'] |
|
14 | ||
15 |
@property |
|
16 |
def fargo_url(self): |
|
17 |
return get_publisher().get_site_option('fargo_url') |
|
18 | ||
19 |
def pick (self): |
|
20 |
request = get_request() |
|
21 |
if 'cancel' in request.form: |
|
22 |
get_response().add_javascript(['jquery.js']) |
|
23 |
get_response().page_template_key = 'iframe' |
|
24 |
r = TemplateIO(html=True) |
|
25 |
r += htmltext('<html><body>') |
|
26 |
r += htmltext('<script>window.top.document.fargo_close_dialog();</script>') |
|
27 |
r += htmltext('</body></html>') |
|
28 |
return r.getvalue() |
|
29 |
elif 'url' in request.form: |
|
30 |
# Download file |
|
31 |
# FIXME: handle error cases |
|
32 |
url = request.form['url'] |
|
33 |
document = urllib.urlopen(request.form['url']).read() |
|
34 |
scheme, netloc, path, qs, frag = urlparse.urlsplit(url) |
|
35 |
path = map(None, path.split('/')) |
|
36 |
name = urllib.unquote(path[-1]) |
|
37 |
download = qommon.form.PicklableUpload(name, |
|
38 |
content_type='application/pdf') |
|
39 |
download.__setstate__({ |
|
40 |
'data': document, |
|
41 |
}) |
|
42 |
token = get_session().add_tempfile(download) |
|
43 |
return self.set_token(token, name) |
|
44 |
else: |
|
45 |
# Display file picker |
|
46 |
frontoffice_url = get_publisher().get_frontoffice_url() |
|
47 |
self_url = frontoffice_url |
|
48 |
self_url += '/fargo/pick' |
|
49 |
return redirect('%s?pick=%s' % (self.fargo_url, |
|
50 |
urllib.quote(self_url))) |
|
51 | ||
52 |
def set_token(self, token, title): |
|
53 |
get_response().add_javascript(['jquery.js']) |
|
54 |
get_response().page_template_key = 'iframe' |
|
55 |
r = TemplateIO(html=True) |
|
56 |
r += htmltext('<html><body>') |
|
57 |
r += htmltext('<script>window.top.document.fargo_set_token(%s, %s);</script>' % ( |
|
58 |
json.dumps(token), json.dumps(title))) |
|
59 |
r += htmltext('</body></html>') |
|
60 |
return r.getvalue() |
extra/modules/form.py | ||
---|---|---|
1 | 1 |
from qommon.form import * |
2 | 2 | |
3 | 3 | |
4 | 4 |
class FileWithPreviewAndStrongboxWidget(FileWithPreviewWidget): |
5 | 5 |
def render_hint(self, hint): |
6 | 6 |
t = CompositeWidget.render_hint(self, hint) |
7 |
root_url = get_publisher().get_root_url() |
|
7 | 8 |
if get_publisher().has_site_option('strongbox') and get_request().user and not self.preview: |
8 | 9 |
get_response().add_javascript(['../../aq/js/strongbox.js']) |
9 |
root_url = get_publisher().get_root_url() |
|
10 | 10 |
t += htmltext('''<p class="use-file-from-strongbox"><span |
11 | 11 |
data-url="%smyspace/strongbox/pick" |
12 | 12 |
rel="popup">%s</span></p>''') % ( |
13 | 13 |
root_url, _('Use file from strongbox')) |
14 | 14 |
if get_publisher().get_site_option('msp') is not None and not self.preview: |
15 | 15 |
get_response().add_javascript(['../../aq/js/msp.js']) |
16 |
root_url = get_publisher().get_root_url() |
|
17 | 16 |
t += htmltext('''<p class="use-file-from-msp"><span |
18 | 17 |
data-src="%smsp/pick" |
19 | 18 |
data-width="500" |
20 | 19 |
data-height="400" |
21 | 20 |
data-title="%s" |
22 | 21 |
rel="popup">%s</span></p>''') % ( |
23 | 22 |
root_url, _('Pick a file on mon.Service-Public.fr'), |
24 | 23 |
_('Use file from mon.Service-Public.fr')) |
24 |
if get_publisher().get_site_option('fargo_url') is not None and not self.preview: |
|
25 |
get_response().add_javascript(['../../aq/js/fargo.js']) |
|
26 |
t += htmltext('''<p class="use-file-from-fargo"><span |
|
27 |
data-src="%sfargo/pick" |
|
28 |
data-width="500" |
|
29 |
data-height="400" |
|
30 |
data-title="%s" |
|
31 |
rel="popup">%s</span></p>''') % ( |
|
32 |
root_url, _('Pick a file from your dropbox'), |
|
33 |
_('Use file from my dropbox')) |
|
25 | 34 |
return t |
extra/modules/root.py | ||
---|---|---|
49 | 49 |
from saml2 import Saml2Directory |
50 | 50 | |
51 | 51 |
OldRootDirectory = wcs.root.RootDirectory |
52 | 52 | |
53 | 53 |
import qommon.ident.password |
54 | 54 |
import qommon.ident.idp |
55 | 55 | |
56 | 56 |
import msp_ui |
57 |
import fargo_ui |
|
57 | 58 | |
58 | 59 |
def category_get_homepage_position(self): |
59 | 60 |
if hasattr(self, 'homepage_position') and self.homepage_position: |
60 | 61 |
return self.homepage_position |
61 | 62 |
if self.url_name == 'consultations': |
62 | 63 |
return '2nd' |
63 | 64 |
return '1st' |
64 | 65 |
Category.get_homepage_position = category_get_homepage_position |
... | ... | |
753 | 754 |
_q_exports = ['', 'admin', 'backoffice', 'forms', 'login', 'logout', |
754 | 755 |
'token', 'saml', 'register', 'ident', 'afterjobs', |
755 | 756 |
('informations-editeur', 'informations_editeur'), 'index2', |
756 | 757 |
('announces', 'announces_dir'), |
757 | 758 |
'accessibility', 'contact', 'help', |
758 | 759 |
'myspace', 'services', 'agenda', 'categories', 'user', |
759 | 760 |
('tmp-upload', 'tmp_upload'), 'json', '__version__', |
760 | 761 |
'themes', 'pages', 'payment', 'invoices', 'accesscode', 'roles', |
761 |
'msp', 'api', 'code'] |
|
762 |
'msp', 'api', 'code', 'fargo']
|
|
762 | 763 | |
763 | 764 |
admin = admin.AdminRootDirectory() |
764 | 765 |
announces_dir = AnnouncesDirectory() |
765 | 766 |
register = AlternateRegisterDirectory() |
766 | 767 |
login = AlternateLoginDirectory() |
767 | 768 |
ident = AlternateIdentDirectory() |
768 | 769 |
myspace = MyspaceDirectory() |
769 | 770 |
agenda = AgendaDirectory() |
770 | 771 |
saml = Saml2Directory() |
771 | 772 |
payment = PublicPaymentDirectory() |
772 | 773 |
invoices = InvoicesDirectory() |
773 | 774 |
msp = msp_ui.MSPDirectory() |
775 |
fargo = fargo_ui.FargoDirectory() |
|
774 | 776 |
code = wcs.forms.root.TrackingCodesDirectory() |
775 | 777 | |
776 | 778 |
def get_substitution_variables(self): |
777 | 779 |
d = {} |
778 | 780 |
def print_links(fd): |
779 | 781 |
fd.write(str(self.links())) |
780 | 782 |
d['links'] = print_links |
781 | 783 |
return d |
static/js/fargo.js | ||
---|---|---|
1 | ||
2 |
$(function() { |
|
3 |
var iframe = $('<iframe frameborder="0" marginwidth="0" marginheight="0" allowfullscreen></iframe>'); |
|
4 |
var dialog = $("<div></div>").append(iframe).appendTo("body").dialog({ |
|
5 |
autoOpen: false, |
|
6 |
modal: true, |
|
7 |
resizable: false, |
|
8 |
width: "auto", |
|
9 |
height: "auto", |
|
10 |
close: function () { |
|
11 |
iframe.attr("src", ""); |
|
12 |
} |
|
13 |
}); |
|
14 |
$('p.use-file-from-fargo span').click(function(e) { |
|
15 |
e.preventDefault(); |
|
16 |
var base_widget = $(this).parents('.file-upload-widget'); |
|
17 |
document.fargo_set_token = function (token, title) { |
|
18 |
if (token) { |
|
19 |
$(base_widget).find('.filename').text(title); |
|
20 |
$(base_widget).find('.fileinfo').show(); |
|
21 |
$(base_widget).find('input[type=hidden]').val(token); |
|
22 |
$(base_widget).find('input[type=file]').hide(); |
|
23 |
} |
|
24 |
document.fargo_close_dialog(); |
|
25 |
} |
|
26 |
document.fargo_close_dialog = function () { |
|
27 |
document.fargo_set_token = undefined; |
|
28 |
dialog.dialog('close'); |
|
29 |
} |
|
30 |
var src = $(this).data('src'); |
|
31 |
var title = $(this).data("title"); |
|
32 |
var width = $(this).data("width"); |
|
33 |
var height = $(this).data("height"); |
|
34 |
iframe.attr({ |
|
35 |
width: parseInt(width), |
|
36 |
height: parseInt(height), |
|
37 |
src: src |
|
38 |
}); |
|
39 |
dialog.dialog("option", "title", title); |
|
40 |
dialog.dialog("open"); |
|
41 |
}); |
|
42 |
}); |
|
0 |
- |