|
13 | 13 | },
|
14 | 14 | options
|
15 | 15 | );
|
16 |
| - $(this.options.containerSelector).on('click', this.options.buttonSelector, this.clickHandler.bind(this)); |
| 16 | + $(this.options.containerSelector).on('click',this.options.buttonSelector,this.clickHandler.bind(this)); |
17 | 17 | };
|
18 | 18 |
|
19 | 19 | S2A.singleActionsManager.prototype = {
|
20 | 20 | clickHandler: function(evt){
|
21 | 21 | var $elt = $(evt.currentTarget);
|
22 |
| - |
23 |
| - if (!this.isConfirmed($elt)) { |
24 |
| - evt.preventDefault(); |
25 |
| - return; |
26 |
| - } |
27 |
| - |
28 |
| - if (this.isProtected($elt)) { |
| 22 | + if (this.isProtected($elt) && !this.needConfirmation($elt)) { |
29 | 23 | evt.preventDefault();
|
30 | 24 | this.sendSecured($elt);
|
31 | 25 | }
|
32 | 26 | },
|
33 | 27 |
|
34 |
| - isConfirmed: function($elt){ |
35 |
| - // TODO: move confirm() to custom popin |
36 |
| - return !$elt.data('confirm') || confirm($elt.data('confirm')); |
37 |
| - }, |
38 |
| - |
39 | 28 | isProtected: function($elt){
|
40 | 29 | return !!$elt.data('csrf-token');
|
41 | 30 | },
|
42 | 31 |
|
| 32 | + needConfirmation: function($elt){ |
| 33 | + return !!$elt.data('confirm'); |
| 34 | + }, |
| 35 | + |
43 | 36 | sendSecured: function($elt){
|
44 | 37 | // Transform in POST request
|
45 | 38 | var $form = $('<form />').attr({
|
|
53 | 46 | name: '_csrf_token',
|
54 | 47 | value: $elt.data('csrf-token')
|
55 | 48 | }).appendTo($form);
|
56 |
| - // TODO: add pre-submit trigger |
57 | 49 | $form.submit();
|
58 |
| - // TODO: add post-submit trigger |
59 | 50 | }
|
60 | 51 | };
|
61 |
| - |
62 | 52 | S2A.batchActionsManager = function(options){
|
63 | 53 | this.options = $.extend( {}, {
|
64 | 54 | containerSelector: 'document',
|
|
87 | 77 | }
|
88 | 78 |
|
89 | 79 | if (!this.hasElementsSelected()) {
|
90 |
| - // TODO: move this to a popin or dynamic message displayer |
91 |
| - alert(this.options.noElementSelectedMessage); |
| 80 | + evt.preventDefault(); |
92 | 81 | $elt.val(this.options.noActionValue);
|
| 82 | + $('#alertModal').find('.modal-title').text(this.options.noElementSelectedMessage); |
| 83 | + $('#alertModal').modal('show'); |
93 | 84 | return;
|
94 | 85 | }
|
95 | 86 |
|
96 |
| - if (!this.isConfirmed($elt)) { |
97 |
| - $elt.val(this.options.noActionValue); |
| 87 | + if (this.needConfirmation($elt)) { |
| 88 | + $(this.selectedOption($elt).data('confirm-modal')).modal('show', $elt); |
98 | 89 | return;
|
99 | 90 | }
|
100 | 91 |
|
101 |
| - // TODO: pre-submit trigger |
102 |
| - // Send the form |
103 | 92 | $elt[0].form.submit();
|
104 | 93 | },
|
105 | 94 |
|
|
119 | 108 | return 0 !== $(this.options.containerSelector + ' ' + this.options.elementSelector).filter(':checked').length;
|
120 | 109 | },
|
121 | 110 |
|
122 |
| - isConfirmed: function($elt){ |
123 |
| - var $selectedOption = $(':selected', $elt); |
124 |
| - |
125 |
| - if (0 == $selectedOption.length) { |
126 |
| - return false; |
127 |
| - } |
| 111 | + needConfirmation: function($elt){ |
| 112 | + return !!this.selectedOption($elt).data('confirm'); |
| 113 | + }, |
128 | 114 |
|
129 |
| - return !$selectedOption.data('confirm') || confirm($selectedOption.data('confirm')); |
| 115 | + selectedOption: function ($elt) { |
| 116 | + return $(':selected', $elt); |
130 | 117 | }
|
| 118 | + |
131 | 119 | };
|
132 | 120 |
|
133 | 121 | S2A.nestedListManager = function(options){
|
|
158 | 146 |
|
159 | 147 | // Force first tab to be displayed
|
160 | 148 | $('.nav-tabs *[data-toggle="tab"]:first').click();
|
161 |
| - |
| 149 | + |
162 | 150 | // Display number of errors on tabs
|
163 | 151 | $('.nav.nav-tabs li').each(function(i){
|
164 | 152 | $(this).find('a span.label-danger').remove();
|
|
167 | 155 | $(this).find('a:first').append('<span class="label label-danger">'+invalid_items.length+'</span>');
|
168 | 156 | }
|
169 | 157 | });
|
170 |
| - |
| 158 | + |
171 | 159 | // Display object actions tooltips
|
172 |
| - $('a.object-action[data-toggle="tooltip"]').tooltip(); |
| 160 | + $('a.object-action').tooltip(); |
| 161 | + |
| 162 | + // Save action for modals |
| 163 | + $('.object-action, .generic-action, select[name=action] option').each(function(index, item) { |
| 164 | + $item = $(item); |
| 165 | + $item.data('action', $item.attr('href')); |
| 166 | + $item.attr('href', $item.data('confirmModal')); |
| 167 | + }); |
| 168 | + |
| 169 | + // hookup on submit button |
| 170 | + $('button[type=submit].generic-action').click(function(event) { |
| 171 | + if ($(this).data('confirm')) { |
| 172 | + event.preventDefault(); |
| 173 | + } |
| 174 | + }); |
| 175 | + |
| 176 | + $('.confirm-object-modal, .confirm-generic-modal').on('show.bs.modal', function (event) { |
| 177 | + var $elt = $(event.relatedTarget); |
| 178 | + var $form = $(this).find('form'); |
| 179 | + var action = $elt.data('action'); |
| 180 | + var confirm = $elt.data('confirm'); |
| 181 | + var csrf_token = $elt.data('csrf-token'); |
| 182 | + $form.attr('action', action); |
| 183 | + $(this).find('.modal-title').text(confirm); |
| 184 | + // submit button confirmation |
| 185 | + if ($elt.is('button[type=submit]')) { |
| 186 | + $form.submit(function(event) { |
| 187 | + event.preventDefault(); |
| 188 | + $elt.closest('form').submit(); |
| 189 | + }); |
| 190 | + } |
| 191 | + if (csrf_token) { |
| 192 | + $('<input />').attr({ |
| 193 | + type: 'hidden', |
| 194 | + name: '_csrf_token', |
| 195 | + value: csrf_token |
| 196 | + }).appendTo($form); |
| 197 | + } |
| 198 | + }); |
| 199 | + |
| 200 | + $('.confirm-batch-modal').on('show.bs.modal', function (event) { |
| 201 | + var $elt = $(event.relatedTarget); |
| 202 | + var confirm = $(':selected', $elt).data('confirm'); |
| 203 | + $(this).find('.modal-title').text(confirm); |
| 204 | + $(this).find('.confirm').click(function() { |
| 205 | + $elt[0].form.submit(); |
| 206 | + }) |
| 207 | + $(this).find('.cancel').click(function() { |
| 208 | + $elt.val(S2A.batchActionsAdminOptions.noActionValue); |
| 209 | + }) |
| 210 | + }); |
173 | 211 |
|
174 | 212 | // Object actions
|
175 | 213 | if (S2A.hasOwnProperty('singleActionsAdminOptions')) {
|
|
0 commit comments