Commit f5f88eff authored by Nicolas Joyard's avatar Nicolas Joyard

Ajout formulaire confirmation et annulation

parent 8b37d8a8
......@@ -36,9 +36,19 @@ def setup_routes(app):
if not parl:
pris_en_charge = False
if session.get('user') and parl.etape.ordre == ETAPE_A_CONFIRMER:
action = [a for a in parl.actions
if a.etape.ordre == ETAPE_A_CONFIRMER
and a.nick == session.get('user')['nick']
and == session.get('user')['email']]
if len(action):
pris_en_charge = True
return render_template(
@app.route('/parlementaires/<id>/envoi', endpoint='envoi')
......@@ -76,4 +86,38 @@ def setup_routes(app):
return redirect(url_for('parlementaire', id=id))
\ No newline at end of file
@app.route('/parlementaire/<id>/annuler', endpoint='annuler')
def annuler(id):
parl = Parlementaire.query.filter_by(id=id) \
.options(joinedload(Parlementaire.groupe)) \
.options(joinedload(Parlementaire.etape)) \
.options(joinedload(Parlementaire.actions)) \
if not parl:
pris_en_charge = False
if parl.etape.ordre == ETAPE_A_CONFIRMER:
action = [a for a in parl.actions
if a.etape.ordre == ETAPE_A_CONFIRMER
and a.nick == session.get('user')['nick']
and == session.get('user')['email']]
if len(action):
pris_en_charge = True
action = action[0]
if not pris_en_charge:
msg = 'Oups, vous n\'avez pas pris en charge l\'envoi pour ce ' \
'parlementaire !'
return redirect_back(error=msg,
fallback=url_for('parlementaire', id=id))
parl.etape = Etape.query.filter_by(ordre=ETAPE_A_ENVOYER).first()
return redirect(url_for('parlementaire', id=id))
Bootstrap - File Input
This is meant to convert all file input tags into a set of elements that displays consistently in all browsers.
Converts all
<input type="file">
into Bootstrap buttons
<a class="btn">Browse</a>
(function($) {
$.fn.bootstrapFileInput = function() {
var $elem = $(elem);
// Maybe some fields don't need to be standardized.
if (typeof $elem.attr('data-bfi-disabled') != 'undefined') {
// Set the word to be displayed on the button
var buttonWord = 'Browse';
if (typeof $elem.attr('title') != 'undefined') {
buttonWord = $elem.attr('title');
var className = '';
if (!!$elem.attr('class')) {
className = ' ' + $elem.attr('class');
// Now we're going to wrap that input field with a Bootstrap button.
// The input will actually still be there, it will just be float above and transparent (done with the CSS).
$elem.wrap('<a class="file-input-wrapper btn btn-default ' + className + '"></a>').parent().prepend($('<span></span>').html(buttonWord));
// After we have found all of the file inputs let's apply a listener for tracking the mouse movement.
// This is important because the in order to give the illusion that this is a button in FF we actually need to move the button from the file input under the cursor. Ugh.
.promise().done( function(){
// As the cursor moves over our new Bootstrap button we need to adjust the position of the invisible file input Browse button to be under the cursor.
// This gives us the pointer cursor that FF denies us
$('.file-input-wrapper').mousemove(function(cursor) {
var input, wrapper,
wrapperX, wrapperY,
inputWidth, inputHeight,
cursorX, cursorY;
// This wrapper element (the button surround this file input)
wrapper = $(this);
// The invisible file input element
input = wrapper.find("input");
// The left-most position of the wrapper
wrapperX = wrapper.offset().left;
// The top-most position of the wrapper
wrapperY = wrapper.offset().top;
// The with of the browsers input field
inputWidth= input.width();
// The height of the browsers input field
inputHeight= input.height();
//The position of the cursor in the wrapper
cursorX = cursor.pageX;
cursorY = cursor.pageY;
//The positions we are to move the invisible file input
// The 20 at the end is an arbitrary number of pixels that we can shift the input such that cursor is not pointing at the end of the Browse button but somewhere nearer the middle
moveInputX = cursorX - wrapperX - inputWidth + 20;
// Slides the invisible input Browse button to be positioned middle under the cursor
moveInputY = cursorY- wrapperY - (inputHeight/2);
// Apply the positioning styles to actually move the invisible file input
$('body').on('change', '.file-input-wrapper input[type=file]', function(){
var fileName;
fileName = $(this).val();
// Remove any previous file names
if (!!$(this).prop('files') && $(this).prop('files').length > 1) {
fileName = $(this)[0].files.length+' files';
else {
fileName = fileName.substring(fileName.lastIndexOf('\\') + 1, fileName.length);
// Don't try to show the name if there is none
if (!fileName) {
var selectedFileNamePlacement = $(this).data('filename-placement');
if (selectedFileNamePlacement === 'inside') {
// Print the fileName inside
$(this).attr('title', fileName);
} else {
// Print the fileName aside (right after the the button)
$(this).parent().after('<span class="file-input-name">'+fileName+'</span>');
// Add the styles before the first stylesheet
// This ensures they can be easily overridden with developer styles
var cssHtml = '<style>'+
'.file-input-wrapper { overflow: hidden; position: relative; cursor: pointer; z-index: 1; }'+
'.file-input-wrapper input[type=file], .file-input-wrapper input[type=file]:focus, .file-input-wrapper input[type=file]:hover { position: absolute; top: 0; left: 0; cursor: pointer; opacity: 0; filter: alpha(opacity=0); z-index: 99; outline: 0; }'+
'.file-input-name { margin-left: 8px; }'+
......@@ -38,6 +38,32 @@
{% endif %}
{% elif pris_en_charge %}
<section class="panel panel-default">
<header class="panel-heading">
<b>Confirmation d'envoi</b>
<article class="panel-body">
Vous avez pris en charge l'envoi du courrier à ce parlementaire. Pour confirmer l'envoi,
merci de nous envoyer une photo ou un scan de la preuve de dépôt à l'aide du formulaire ci-dessous.
<div class="form-group">
<label class="col-md-4" for="file">Preuve d'envoi</label>
<div class="col-md-8">
<input class="name="file" type="file" title="Choisissez un fichier...">
<div class="form-group">
<div class="col-md-offset-4 col-md-8">
<input class="btn btn-primary" type="submit" value="Confirmer !">
<a href="{{ url_for('annuler', }}" class="btn btn-danger">Annuler la prise en charge</a>
{% endif %}
......@@ -101,9 +127,12 @@
{% endblock %}
{% block scripts %}
<script src="{{ url_for('static', filename='bootstrap.file-input.js') }}"></script>
$('#identify-link').click(function() {
$('.login .dropdown-toggle').dropdown('toggle');
{% endblock %}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment