1 $(document).on('click', '.selectable', function() {
3 if (!$this.hasClass('multiple')) {
4 $this.closest('.selectable-container').
8 $this.toggleClass('active');
9 }).on('click', '.modal button[data-action-href]', function() {
12 var $modal = $(this).closest('.modal');
13 var action_data = $(this).data('action-data');
14 var selection_param = action_data.selection_param;
15 $modal.find('.modal-error').removeClass('hide').hide();
16 $modal.find('.selectable.active[data-object-uuid]').each(function() {
17 var val = $(this).attr('data-object-uuid');
18 data.push({name: selection_param, value: val});
20 $.each(action_data, function(key, value) {
21 data.push({name: key, value: value});
23 $.ajax($(this).attr('data-action-href'),
25 type: $(this).attr('data-method'),
28 context: {modal: $modal, action_data: action_data}}).
29 fail(function(jqxhr, status, error) {
30 if (jqxhr.readyState == 0 || jqxhr.status == 0) {
31 message = "Cancelled."
32 } else if (jqxhr.responseJSON && jqxhr.responseJSON.errors) {
33 message = jqxhr.responseJSON.errors.join("; ");
35 message = "Request failed.";
37 this.modal.find('.modal-error').
38 html('<div class="alert alert-danger">' + message + '</div>').
41 done(function(data, status, jqxhr) {
42 var event_name = this.action_data.success;
43 this.modal.find('.modal-error').hide();
44 $(document).trigger(event_name!=null ? event_name : 'page-refresh',
45 [data, status, jqxhr, this.action_data]);
48 $(document).on('page-refresh', function(event, data, status, jqxhr, action_data) {
49 window.location.reload();
50 }).on('redirect-to-created-object', function(event, data, status, jqxhr, action_data) {
51 window.location.href = data.href.replace(/^[^\/]*\/\/[^\/]*/, '');