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 $(".modal-dialog-preview-pane").html('<div class="spinner spinner-32px spinner-h-center spinner-v-center"></div>');
20 $.ajax($this.attr('data-preview-href'),
22 done(function(data, status, jqxhr) {
23 $(".modal-dialog-preview-pane").html(data);
25 fail(function(data, status, jqxhr) {
26 $(".modal-dialog-preview-pane").text('Preview load failed.');
30 }).on('click', '.modal button[data-action-href]', function() {
33 var $modal = $(this).closest('.modal');
34 var action_data = $(this).data('action-data');
35 var selection_param = action_data.selection_param;
36 $modal.find('.modal-error').removeClass('hide').hide();
37 $modal.find('.selectable.active[data-object-uuid]').each(function() {
38 var val = $(this).attr('data-object-uuid');
39 data.push({name: selection_param, value: val});
41 $.each(action_data, function(key, value) {
42 data.push({name: key, value: value});
44 $.ajax($(this).attr('data-action-href'),
46 type: $(this).attr('data-method'),
49 context: {modal: $modal, action_data: action_data}}).
50 fail(function(jqxhr, status, error) {
51 if (jqxhr.readyState == 0 || jqxhr.status == 0) {
52 message = "Cancelled."
53 } else if (jqxhr.responseJSON && jqxhr.responseJSON.errors) {
54 message = jqxhr.responseJSON.errors.join("; ");
56 message = "Request failed.";
58 this.modal.find('.modal-error').
59 html('<div class="alert alert-danger">' + message + '</div>').
62 done(function(data, status, jqxhr) {
63 var event_name = this.action_data.success;
64 this.modal.find('.modal-error').hide();
65 $(document).trigger(event_name!=null ? event_name : 'page-refresh',
66 [data, status, jqxhr, this.action_data]);
69 $(document).on('page-refresh', function(event, data, status, jqxhr, action_data) {
70 window.location.reload();
71 }).on('redirect-to-created-object', function(event, data, status, jqxhr, action_data) {
72 window.location.href = data.href.replace(/^[^\/]*\/\/[^\/]*/, '');