{% extends "shop_subscribe/base.html" %}
{# Used as a plugin template or include in other templates #}
{% load i18n sekizai_tags subscribe_tags %}


{% block content %}{% spaceless %}

{% if not form %}
{% confirm_form %}
{% endif %}

{% addtoblock "js" %}<script type="text/javascript">
angular.module('django.shop.confirm', ['djng.forms']).controller('ConfirmCtrl', function($scope, $http, $window, djangoForm) {
    $scope.submit = function() {
        var config = {headers: {'X-HTTP-Method-Override': 'PUT'}};
        $scope.{{ form.form_name }}.success = false;
        $http.post("{{ form.get_url }}", $scope.{{ form.scope_prefix }}, config)
            .success(function(out_data) {
                var action = "{{ action }}"
                $scope.{{ form.form_name }}.success = true;
                if (action === 'RELOAD_PAGE') {
                    $window.location.reload();
                } else if (action === 'DO_NOTHING') {
                } else {
                    // cmspage
                    $window.location.assign(action);
                }
            })
            .error(function(out_data) {
                djangoForm.setErrors($scope.{{ form.form_name }}, out_data.errors)
            });
    };
});
</script>{% endaddtoblock %}
{% addtoblock "ng-requires" %}django.shop.confirm{% endaddtoblock %}


<form ng-controller="ConfirmCtrl" name="{{ form.form_name }}" novalidate>
    {{ form.as_div }}
    <button type="button" ng-disabled="{{ form.form_name }}.$invalid" ng-click="submit()" class="btn btn-success btn-round">
        <i class="fa fa-send-o" aria-hidden="true"></i>&nbsp;{% trans "Update" %}
    </button>
</form>

{% endspaceless %}{% endblock %}
