|
32 | 32 | </div> |
33 | 33 | </div> |
34 | 34 | @else |
35 | | - <form action="{{ route('admin.settings.mail') }}" method="POST"> |
| 35 | + <form> |
36 | 36 | <div class="box-body"> |
37 | 37 | <div class="row"> |
38 | 38 | <div class="form-group col-md-6"> |
|
99 | 99 | <div class="box-footer"> |
100 | 100 | {{ csrf_field() }} |
101 | 101 | <div class="pull-right"> |
102 | | - <a href="{{ route('admin.settings.mail.test') }}" class="btn btn-sm btn-success">Test</a> |
103 | | - <button type="submit" name="_method" value="PATCH" class="btn btn-sm btn-primary">Save</button> |
| 102 | + <button type="button" id="testButton" class="btn btn-sm btn-success">Test</button> |
| 103 | + <button type="button" id="saveButton" class="btn btn-sm btn-primary">Save</button> |
104 | 104 | </div> |
105 | 105 | </div> |
106 | 106 | </form> |
|
109 | 109 | </div> |
110 | 110 | </div> |
111 | 111 | @endsection |
| 112 | + |
| 113 | +@section('footer-scripts') |
| 114 | + {!! Theme::js('js/laroute.js?t={cache-version}') !!} |
| 115 | + {!! Theme::js('vendor/jquery/jquery.min.js?t={cache-version}') !!} |
| 116 | + {!! Theme::js('vendor/sweetalert/sweetalert.min.js?t={cache-version}') !!} |
| 117 | + |
| 118 | + <script> |
| 119 | + function saveSettings() { |
| 120 | + return $.ajax({ |
| 121 | + method: 'PATCH', |
| 122 | + url: Router.route('admin.settings.mail'), |
| 123 | + contentType: 'application/json', |
| 124 | + data: JSON.stringify({ |
| 125 | + 'mail:host': $('input[name="mail:host"]').val(), |
| 126 | + 'mail:port': $('input[name="mail:port"]').val(), |
| 127 | + 'mail:encryption': $('select[name="mail:encryption"]').val(), |
| 128 | + 'mail:username': $('input[name="mail:username"]').val(), |
| 129 | + 'mail:password': $('input[name="mail:password"]').val(), |
| 130 | + 'mail:from:address': $('input[name="mail:from:address"]').val(), |
| 131 | + 'mail:from:name': $('input[name="mail:from:name"]').val() |
| 132 | + }), |
| 133 | + headers: { 'X-CSRF-Token': $('input[name="_token"]').val() } |
| 134 | + }).fail(function (jqXHR) { |
| 135 | + showErrorDialog(jqXHR, 'save'); |
| 136 | + }); |
| 137 | + } |
| 138 | +
|
| 139 | + function testSettings() { |
| 140 | + return $.ajax({ |
| 141 | + method: 'GET', |
| 142 | + url: Router.route('admin.settings.mail.test'), |
| 143 | + headers: { 'X-CSRF-Token': $('input[name="_token"]').val() } |
| 144 | + }).fail(function (jqXHR) { |
| 145 | + showErrorDialog(jqXHR, 'test'); |
| 146 | + }).done(function () { |
| 147 | + swal({ |
| 148 | + title: 'Success', |
| 149 | + text: 'The test message was sent successfully.', |
| 150 | + type: 'success' |
| 151 | + }); |
| 152 | + }); |
| 153 | + } |
| 154 | +
|
| 155 | + function saveAndTestSettings() { |
| 156 | + saveSettings().done(testSettings); |
| 157 | + } |
| 158 | +
|
| 159 | + function showErrorDialog(jqXHR, verb) { |
| 160 | + console.error(jqXHR); |
| 161 | + var errorText; |
| 162 | + if (jqXHR.responseJSON.error) { |
| 163 | + errorText = jqXHR.responseJSON.error; |
| 164 | + } else if (jqXHR.responseJSON.errors) { |
| 165 | + $.each(jqXHR.responseJSON.errors, function (i, v) { |
| 166 | + errorText += ', ' + v.detail; |
| 167 | + }); |
| 168 | + } |
| 169 | +
|
| 170 | + swal({ |
| 171 | + title: 'Whoops!', |
| 172 | + text: 'An error occurred while attempting to ' + verb + ' mail settings: ' + errorText, |
| 173 | + type: 'error' |
| 174 | + }); |
| 175 | + } |
| 176 | +
|
| 177 | + $(document).ready(function () { |
| 178 | + $('#testButton').on('click', saveAndTestSettings); |
| 179 | + $('#saveButton').on('click', function () { |
| 180 | + saveSettings().done(function () { |
| 181 | + swal({ |
| 182 | + title: 'Success', |
| 183 | + text: 'Mail settings have been updated successfully and the queue worker was restarted to apply these changes.', |
| 184 | + type: 'success' |
| 185 | + }); |
| 186 | + }); |
| 187 | + }); |
| 188 | + }); |
| 189 | + </script> |
| 190 | +@endsection |
0 commit comments