Commit ad809e0b authored by buttle's avatar buttle

First attempt at embedding forms

parent dc0cc2c5
......@@ -32,7 +32,7 @@ babel = Babel(app)
csrf = CSRFProtect()
csrf.init_app(app)
app.config['APP_VERSION'] = 37
app.config['APP_VERSION'] = 38
app.config['SCHEMA_VERSION'] = 13
app.config['RESERVED_SLUGS'] = ['login', 'static', 'admin', 'admins', 'user', 'users',
......
......@@ -314,6 +314,10 @@ class Form(db.Document):
def url(self):
return "%s%s" % (self.site.host_url, self.slug)
@property
def embed_url(self):
return "%se/%s" % (self.site.host_url, self.slug)
def isDataConsentEnabled(self):
if not self.site.isPersonalDataConsentEnabled():
return False
......
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="/static/jquery/jquery.min.js"></script>
<link rel="stylesheet" href="/static/css/bootstrap.min.css">
<link rel="stylesheet" href="/static/css/style.css">
<link rel="stylesheet" href="/static/css/custom.css">
</head>
<body>
{% block content %}{% endblock %}
<p>&nbsp;</p>
<div class="footer" style="text-align:right">
GNGforms. AGPLv3
<a href="https://gitlab.com/lleialtec/gngforms">{%trans%}Source code{%endtrans%}</a>
&nbsp;
</div>
</body>
</html>
......@@ -178,7 +178,11 @@
</table>
{% if form.editors[g.current_user.id|string] is defined %}
<hr />
<div id="embed_snippet" style="display:none">
<pre><code>{{'<iframe width="500" height="600" src="'}}{{form.embed_url}}{{'"></iframe>'}}</code></pre>
</div>
<input class="btn-primary btn btn-sm" type="button" value="{%trans%}Edit form{%endtrans%}" onClick="location.href='/forms/edit/{{ form.id }}'">
<input class="btn-primary btn btn-sm" type="button" value="{%trans%}Embed form{%endtrans%}" onClick="js:$('#embed_snippet').show();">
<input class="btn-primary btn btn-sm" type="button" value="{%trans%}Duplicate form{%endtrans%}" onClick="location.href='/forms/duplicate/{{ form.id }}'">
<p></p>
{% if form.totalEntries == 0 %}
......
{% extends "base.html" %}
{% if embedded %}{% extends "embedded.html" %}{% else %}{% extends "base.html" %}{% endif %}
{% block content %}
<div class="container">
......
{% extends "base.html" %}
{% if embedded %}{% extends "embedded.html" %}{% else %}{% extends "base.html" %}{% endif %}
{% block content %}
<script src="/static/formBuilder/form-render.min.js"></script>
......@@ -7,7 +7,9 @@
<div class="row col-md-3"></div>
<div class="row col-md-6">
<form method="POST">
{% if not embedded %}
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
{% endif %}
<div id="fb-render"></div>
{% if form.isDataConsentEnabled() %}
<div class="formDataConsent">
......
......@@ -21,7 +21,7 @@ import json, re, os, datetime
from flask import g, request, Response, render_template, redirect, url_for
from flask import session, flash, send_file, after_this_request
from flask_wtf.csrf import CSRFError
from GNGforms import app, db, babel
from GNGforms import app, db, babel, csrf
from threading import Thread
from flask_babel import gettext, refresh
from GNGforms.persistence import *
......@@ -80,9 +80,18 @@ def handle_csrf_error(e):
def index():
return render_template('index.html', site=g.site, wtform=wtf.Login())
@app.route('/e/<string:slug>', methods=['GET', 'POST'])
@anon_required
@csrf.exempt
@sanitized_slug_required
def view_embedded_form(slug):
return view_form(slug=slug, embedded=True)
@app.route('/<string:slug>', methods=['GET', 'POST'])
@sanitized_slug_required
def view_form(slug):
def view_form(slug, embedded=False):
queriedForm = Form.find(slug=slug, hostname=g.site.hostname)
if not queriedForm:
if g.current_user:
......@@ -149,8 +158,8 @@ def view_form(slug):
smtp.sendNewFormEntryNotification(emails, data, queriedForm.slug)
thread = Thread(target=sendEntryNotification())
thread.start()
return render_template('thankyou.html', form=queriedForm)
return render_template('view-form.html', form=queriedForm)
return render_template('thankyou.html', form=queriedForm, embedded=embedded)
return render_template('view-form.html', form=queriedForm, embedded=embedded)
@app.route('/<string:slug>/results/<string:key>', methods=['GET'])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment