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);
18 if ($this.hasClass('active')) {
19 var no_preview_available = '<div class="spinner-h-center spinner-v-center"><center>(No preview available)</center></div>';
20 if (!$this.attr('data-preview-href')) {
21 $(".modal-dialog-preview-pane").html(no_preview_available);
24 $(".modal-dialog-preview-pane").html('<div class="spinner spinner-32px spinner-h-center spinner-v-center"></div>');
25 $.ajax($this.attr('data-preview-href'),
27 done(function(data, status, jqxhr) {
28 $(".modal-dialog-preview-pane").html(data);
30 fail(function(data, status, jqxhr) {
31 $(".modal-dialog-preview-pane").html(no_preview_available);
35 }).on('click', '.modal button[data-action-href]', function() {
38 var $modal = $(this).closest('.modal');
39 var action_data = $(this).data('action-data');
40 var selection_param = action_data.selection_param;
41 $modal.find('.modal-error').removeClass('hide').hide();
42 $modal.find('.selectable.active[data-object-uuid]').each(function() {
43 var val = $(this).attr('data-object-uuid');
44 data.push({name: selection_param, value: val});
46 $.each(action_data, function(key, value) {
47 data.push({name: key, value: value});
49 $.ajax($(this).attr('data-action-href'),
51 type: $(this).attr('data-method'),
54 context: {modal: $modal, action_data: action_data}}).
55 fail(function(jqxhr, status, error) {
56 if (jqxhr.readyState == 0 || jqxhr.status == 0) {
57 message = "Cancelled."
58 } else if (jqxhr.responseJSON && jqxhr.responseJSON.errors) {
59 message = jqxhr.responseJSON.errors.join("; ");
61 message = "Request failed.";
63 this.modal.find('.modal-error').
64 html('<div class="alert alert-danger">' + message + '</div>').
67 done(function(data, status, jqxhr) {
68 var event_name = this.action_data.success;
69 this.modal.find('.modal-error').hide();
70 $(document).trigger(event_name!=null ? event_name : 'page-refresh',
71 [data, status, jqxhr, this.action_data]);
74 $(document).on('page-refresh', function(event, data, status, jqxhr, action_data) {
75 window.location.reload();
76 }).on('tab-refresh', function(event, data, status, jqxhr, action_data) {
77 $(document).trigger('arv:pane:reload:all');
78 $('body > .modal-container .modal').modal('hide');
79 }).on('redirect-to-created-object', function(event, data, status, jqxhr, action_data) {
80 window.location.href = data.href.replace(/^[^\/]*\/\/[^\/]*/, '');