|
66 | 66 | {% endfor %}
|
67 | 67 | </ul>
|
68 | 68 | </div>
|
69 |
| - <span id="delete-library-output"></span> |
| 69 | + <div id="delete-library-output"></div> |
70 | 70 | {% endif %}
|
71 | 71 | <br/><br/>
|
72 | 72 | {% if meta.gitOwner and meta.gitRepo and meta.gitLastCommit %}
|
|
129 | 129 | </h4>
|
130 | 130 | </div>
|
131 | 131 | <div class="modal-body">
|
132 |
| - <p>You are about to permanently delete version <span class="modal_library_version"></span> |
| 132 | + <p>You are about to permanently delete version <strong></string><span class="modal_library_version"></span></strong> from |
| 133 | + <strong> |
133 | 134 | {% if meta.name is defined %}
|
134 | 135 | {{ meta.name }}
|
135 | 136 | {% else %}
|
136 | 137 | {{ library }}
|
137 | 138 | {% endif %}
|
| 139 | + </strong> |
138 | 140 | library. Are you sure?</p>
|
| 141 | + <div id="new_latest_version_div" style="margin: 10px 0"> |
| 142 | + You are about to delete a latest version of the library, please specify a new latest version: |
| 143 | + <div> |
| 144 | + <select class="form-control" style="width: 20%" id="new_latest_version_select"></select> |
| 145 | + </div> |
| 146 | + </div> |
139 | 147 | <button id="yes-button" class="btn btn-danger">Do it!</button>
|
140 | 148 | <button id="no-button" class="btn btn-default" data-dismiss="modal">God no..</button>
|
141 | 149 | </div>
|
|
148 | 156 | <!-- Modal content-->
|
149 | 157 | <div class="modal-content">
|
150 | 158 | <div class="modal-header">
|
151 |
| - <h4 class="modal-title">Library <span id="modal_library_name"></span> deleted!</h4> |
| 159 | + <h4 class="modal-title">Version <span class="modal_library_version"></span> |
| 160 | + from |
| 161 | + {% if meta.name is defined %} |
| 162 | + {{ meta.name }} |
| 163 | + {% else %} |
| 164 | + {{ library }} |
| 165 | + {% endif %} |
| 166 | + library is deleted!</h4> |
152 | 167 | </div>
|
153 | 168 | <div class="modal-body">
|
154 | 169 | <p>Click on the button below to get redirected to the library addition page.</p>
|
155 |
| - <button id="redirect-button" class="btn btn-default">Take me there</button> |
| 170 | + <button id="redirect-button" class="btn btn-info">Take me there</button> |
156 | 171 | <p><strong>Don't forget to delete the cached library object files from the compiler!</strong></p>
|
157 | 172 | </div>
|
158 | 173 | </div>
|
|
186 | 201 | }
|
187 | 202 |
|
188 | 203 | $(function() {
|
| 204 | + var latestVersion = "{{ meta.latestVersionName }}"; |
| 205 | + var versions = {{ versions|json_encode|raw }}; |
189 | 206 | // add modal handler to each delete button
|
190 | 207 | $('a.delete-library-version').each(function() {
|
191 | 208 | $(this).on("click", function(){
|
| 209 | + $('#new_latest_version_div').hide(); |
| 210 | + $('#new_latest_version_select').html(''); |
192 | 211 | $('#deletionModal').modal('show');
|
193 |
| - var version = $(this).data('version'); |
194 |
| - $('.modal_library_version').text(version); |
| 212 | + var selectedVersion = $(this).data('version'); |
| 213 | + $('.modal_library_version').text(selectedVersion); |
| 214 | +
|
| 215 | + // if we are deleting a version that is a latest version but not the only version of the library |
| 216 | + if (versions.length > 1 && selectedVersion === latestVersion) { |
| 217 | + // show the div |
| 218 | + $('#new_latest_version_div').show(); |
| 219 | + versions.forEach(function(version) { |
| 220 | + if (version.version !== selectedVersion) { |
| 221 | + $('#new_latest_version_select').append('<option value="' + version.version + '">' + version.version + '</option>'); |
| 222 | + } |
| 223 | + }); |
| 224 | + } |
195 | 225 | });
|
196 | 226 | });
|
| 227 | +
|
| 228 | + $("#yes-button").click(function () { |
| 229 | + $('#deletionModal').modal('hide'); |
| 230 | + var deleteVersion = $('.modal_library_version').first().text(); |
| 231 | + var newLatestVersion = $('#new_latest_version_select').val(); |
| 232 | + var data = { |
| 233 | + type: 'deleteLibrary', |
| 234 | + library: '{{ library }}', |
| 235 | + version: deleteVersion |
| 236 | + }; |
| 237 | +
|
| 238 | + if (newLatestVersion) { |
| 239 | + data['nextLatestVersion'] = newLatestVersion; |
| 240 | + } |
| 241 | +
|
| 242 | + $.ajax({ |
| 243 | + type: "POST", |
| 244 | + url: '{{ path('codebender_api_handler_v2', {'authorizationKey' : authorizationKey}) }}', |
| 245 | + data: JSON.stringify(data), |
| 246 | + dataType: 'json' |
| 247 | + }) |
| 248 | + .done(function(data) { |
| 249 | + if(!data.success) { |
| 250 | + $("#delete-library-output").html(data.message); |
| 251 | + } |
| 252 | + if(data.success) { |
| 253 | + $('.btn').attr('disabled', 'disabled'); //disable all buttons to avoid performing operations on a deleted library |
| 254 | + $('#redirect-button').removeAttr('disabled'); |
| 255 | + $('#deletedModal').modal({ |
| 256 | + keyboard: false, |
| 257 | + backdrop: 'static', |
| 258 | + show: false |
| 259 | + }); |
| 260 | + $('#deletedModal').modal('show'); |
| 261 | + } |
| 262 | + }); |
| 263 | + }); |
| 264 | +
|
| 265 | + $('#redirect-button').click(function(){ |
| 266 | + window.location.replace("{{ path('codebender_library_new_external_v2', {'authorizationKey': authorizationKey}) }}"); |
| 267 | + }); |
197 | 268 | });
|
198 | 269 |
|
199 | 270 | </script>
|
|
0 commit comments