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('<img src="/assets/ajax-loader.gif"></img>');
20 $.ajax($(this).attr('data-preview-href'),
21 {dataType: "html"}).done(function(data, status, jqxhr) {
22 $(".modal-dialog-preview-pane").html(data);
26 }).on('click', '.modal button[data-action-href]', function() {
29 var $modal = $(this).closest('.modal');
30 var action_data = $(this).data('action-data');
31 var selection_param = action_data.selection_param;
32 $modal.find('.modal-error').removeClass('hide').hide();
33 $modal.find('.selectable.active[data-object-uuid]').each(function() {
34 var val = $(this).attr('data-object-uuid');
35 data.push({name: selection_param, value: val});
37 $.each(action_data, function(key, value) {
38 data.push({name: key, value: value});
40 $.ajax($(this).attr('data-action-href'),
42 type: $(this).attr('data-method'),
45 context: {modal: $modal, action_data: action_data}}).
46 fail(function(jqxhr, status, error) {
47 if (jqxhr.readyState == 0 || jqxhr.status == 0) {
48 message = "Cancelled."
49 } else if (jqxhr.responseJSON && jqxhr.responseJSON.errors) {
50 message = jqxhr.responseJSON.errors.join("; ");
52 message = "Request failed.";
54 this.modal.find('.modal-error').
55 html('<div class="alert alert-danger">' + message + '</div>').
58 done(function(data, status, jqxhr) {
59 var event_name = this.action_data.success;
60 this.modal.find('.modal-error').hide();
61 $(document).trigger(event_name!=null ? event_name : 'page-refresh',
62 [data, status, jqxhr, this.action_data]);
65 $(document).on('page-refresh', function(event, data, status, jqxhr, action_data) {
66 window.location.reload();
67 }).on('redirect-to-created-object', function(event, data, status, jqxhr, action_data) {
68 window.location.href = data.href.replace(/^[^\/]*\/\/[^\/]*/, '');