1 $(document).on('click', '.selectable', function() {
4 if (!$this.hasClass('multiple')) {
5 $this.closest('.selectable-container').
9 $this.toggleClass('active');
11 closest('.selectable-container').
12 find('.selectable.active').length > 0)
15 find('[data-enable-if-selection]').
16 prop('disabled', !any);
17 }).on('click', '.modal button[data-action-href]', function() {
20 var $modal = $(this).closest('.modal');
21 var action_data = $(this).data('action-data');
22 var selection_param = action_data.selection_param;
23 $modal.find('.modal-error').removeClass('hide').hide();
24 $modal.find('.selectable.active[data-object-uuid]').each(function() {
25 var val = $(this).attr('data-object-uuid');
26 data.push({name: selection_param, value: val});
28 $.each(action_data, function(key, value) {
29 data.push({name: key, value: value});
31 $.ajax($(this).attr('data-action-href'),
33 type: $(this).attr('data-method'),
36 context: {modal: $modal, action_data: action_data}}).
37 fail(function(jqxhr, status, error) {
38 if (jqxhr.readyState == 0 || jqxhr.status == 0) {
39 message = "Cancelled."
40 } else if (jqxhr.responseJSON && jqxhr.responseJSON.errors) {
41 message = jqxhr.responseJSON.errors.join("; ");
43 message = "Request failed.";
45 this.modal.find('.modal-error').
46 html('<div class="alert alert-danger">' + message + '</div>').
49 done(function(data, status, jqxhr) {
50 var event_name = this.action_data.success;
51 this.modal.find('.modal-error').hide();
52 $(document).trigger(event_name!=null ? event_name : 'page-refresh',
53 [data, status, jqxhr, this.action_data]);
56 $(document).on('page-refresh', function(event, data, status, jqxhr, action_data) {
57 window.location.reload();
58 }).on('redirect-to-created-object', function(event, data, status, jqxhr, action_data) {
59 window.location.href = data.href.replace(/^[^\/]*\/\/[^\/]*/, '');