2872: Rearrange folder index. Show collection tags and files in folder view.
[arvados.git] / apps / workbench / app / assets / javascripts / select_modal.js
1 $(document).on('click', '.selectable', function() {
2     var $this = $(this);
3     if (!$this.hasClass('multiple')) {
4         $this.closest('.selectable-container').
5             find('.selectable').
6             removeClass('active');
7     }
8     $this.toggleClass('active');
9 }).on('click', '.modal button[data-action-href]', function() {
10     var selection = [];
11     var data = [];
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});
19     });
20     $.each(action_data, function(key, value) {
21         data.push({name: key, value: value});
22     });
23     $.ajax($(this).attr('data-action-href'),
24            {dataType: 'json',
25             type: $(this).attr('data-method'),
26             data: data,
27             traditional: true,
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("; ");
34             } else {
35                 message = "Request failed.";
36             }
37             this.modal.find('.modal-error').
38                 html('<div class="alert alert-danger">' + message + '</div>').
39                 show();
40         }).
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]);
46         });
47 });
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(/^[^\/]*\/\/[^\/]*/, '');
52 });