list.html 4.53 KB
Newer Older
Denis S. Valdenaire's avatar
Denis S. Valdenaire committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
<div class="modal-content">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
    <h4 class="modal-title" id="myModalLabel">
        <span class="glyphicon glyphicon-list-alt" style="margin-right: 10px;" ></span>
        Paiement(s) de l'adhésion {{ object.id }}
        <input type="hidden" id="subscription_id" value="{{ object.id }}">
    </h4>
  </div>
  <div class="modal-body">

    <div id="existing_payments">
      {% for key, payment in object.payments %}
      {% include 'payments/single_payment.html' %}
      {% endfor %}
    </div>

    <div id="new_payment">
        <div class="form-group">
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
            <label class="control-label col-md-2" for="payment_method_name">Méthode</label>
            <div class="col-md-5">
                <select id="payment_method_name" name="payment_method_name" class="form-control">
                {% for key2, val2 in methods %}<option value="{{ val2.method }}">{{ val2.name }}</option>
                {% endfor %}
                <select>
                <!--
                <select id="payment_method_name" name="payment_method_name" class="form-control">
                </select>
                <script>
                $('#payment_method_name').html('<option value="">Loading...</option>');
                // FIXME : do not call compta directly, use the saas !!!!
                $.ajax({url: '/ludotm/compta/webroot/rest/payment_methods',
                     success: function(output) {
                        var html = '';
                        $.each(output, function(key, val){
                          html = html + '<option value="' + val.method + '">'
                                + val.description + '</option>';
                        });
                        $('#payment_method_name').html(html);
                    },
                  error: function (xhr, ajaxOptions, thrownError) {
                    // well, that's weird, ok :)
                    $('#payment_method_name').html('<option value="">' + xhr.status + ' ' + thrownError + '</option>');
                    // alert(xhr.status + " " + thrownError);
                  }});
                </script>
                -->
Denis S. Valdenaire's avatar
Denis S. Valdenaire committed
48 49
            </div>
            <label class="control-label col-md-2" for="amount">Montant</label>
50
            <div class="col-md-2">
Denis S. Valdenaire's avatar
Denis S. Valdenaire committed
51
                <input style="text-align: right" type="text" class="form-control"
52
                    name="amount" id="amount" align="right" value=""></div>
Denis S. Valdenaire's avatar
Denis S. Valdenaire committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
        </div>
        <div class="form-group">
            <label class="control-label col-md-2" for="comments">Note</label>
            <div class="col-md-7">
                <input type="text" class="form-control"
                    name="comments" id="comments" align="right" value=""></div>
            <div class="col-md-1 col-md-offset-1">
                <button type="button" class="save_payment_button btn btn-primary btn-md" data-id="0">
                        <i class="glyphicon glyphicon-floppy-save"></i>
                </button>
            </div>
        </div>
    </div>

  </div>
  <div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
  </div>
</div>


<script>
    // buttons events
    $('.save_payment_button').on('click', function(){
        if($('#amount').val() == '') {
            alert ("Vous n'avez pas saisi de montant !");
            return false;
        }
        // save the operation
        $.post('index.php', {
                o: 'payments', a: 'create', i: '',
                subscription_id: $('#subscription_id').val(),
85
                payment_method_name: $('#payment_method_name').val(),
Denis S. Valdenaire's avatar
Denis S. Valdenaire committed
86 87 88 89 90 91 92 93
                comments: $('#comments').val(),
                amount: $('#amount').val()
            })
            .done(function( data ) {
                $('#existing_payments').append(data);
                // set the new_payment fields to default values !
                $('#amount').val('');
                $('#comments').val('');
94
                $("#payment_method_name").prop('selectedIndex',0);
Denis S. Valdenaire's avatar
Denis S. Valdenaire committed
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
            });
        return true;
    });

    function delete_payment(id) {
        var msg = 'Voulez-vous réellement supprimer ce paiement ?';
        if(confirm(msg)) {
            // save the operation
            $.post('api.php', {
                o: 'payments', a: 'delete', i: id
            })
            .done(function( data ) {
                $(".payment_" + id).remove();
            });
            return true;
        }
    }
</script>