Merge branch 'master' into 2060-edit-tags-in-workbench
[arvados.git] / apps / workbench / app / assets / javascripts / application.js
1 // This is a manifest file that'll be compiled into application.js, which will include all the files
2 // listed below.
3 //
4 // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5 // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6 //
7 // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8 // the compiled file.
9 //
10 // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11 // GO AFTER THE REQUIRES BELOW.
12 //
13 //= require jquery
14 //= require jquery_ujs
15 //= require bootstrap
16 //= require bootstrap/dropdown
17 //= require bootstrap/tab
18 //= require bootstrap/tooltip
19 //= require bootstrap/popover
20 //= require bootstrap/collapse
21 //= require bootstrap3-editable/bootstrap-editable
22 //= require_tree .
23
24 jQuery(function($){
25     $.ajaxSetup({
26         headers: {
27             'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
28         }
29     });
30     $('.editable').editable();
31     $('[data-toggle=tooltip]').tooltip();
32
33     $('.expand-collapse-row').on('click', function(event) {
34         var targets = $('#' + $(this).attr('data-id'));
35         if (targets.css('display') == 'none') {
36             $(this).addClass('icon-minus-sign');
37             $(this).removeClass('icon-plus-sign');
38         } else {
39             $(this).addClass('icon-plus-sign');
40             $(this).removeClass('icon-minus-sign');
41         }
42         targets.fadeToggle(200);
43     });
44     $(document).
45         on('ajax:send', function(e, xhr) {
46             $('.loading').fadeTo('fast', 1);
47         }).
48         on('ajax:complete', function(e, status) {
49             $('.loading').fadeOut('fast', 0);
50         }).
51         on('click', '.removable-tag a', function(e) {
52             $(this).parents('[data-tag-link-uuid]').eq(0).next().andSelf().remove();
53         }).
54         on('click', 'a.add-tag-button', function(e) {
55             new_tag = window.prompt("Add tag for collection "+
56                                     $(this).parents('tr').attr('data-object-uuid'),
57                                     "");
58             if (new_tag != null) {
59                 $(this).
60                     parent().
61                     find('>span').
62                     append($('<span class="label label-info removable-tag" data-tag-link-uuid=""></span>').text(new_tag).append('&nbsp;<a>&times;</a>')).
63                     append('<br/>');
64             }
65             return false;
66         });
67
68     HeaderRowFixer = function(selector) {
69         var tables = $(selector);
70         this.duplicateTheadTr = function() {
71             $('>tbody', tables).each(function(){
72                 $(this).prepend($('thead>tr', this).clone().css('opacity:0'));
73             });
74         }
75         this.fixThead = function() {
76             tables.each(function() {
77                 var widths = [];
78                 $('> tbody > tr:eq(1) > td', this).each( function(i,v){
79                     widths.push($(v).width());
80                 });
81                 for(i=0;i<widths.length;i++) {
82                     $('thead th:eq('+i+')', this).width(widths[i]);
83                 }
84             });
85         }
86     }
87     var fixer = new HeaderRowFixer('.table-fixed-header-row');
88     fixer.fixThead();
89     fixer.duplicateTheadTr();
90     $(window).resize(function(){
91         fixer.fixThead();
92     });
93 })(jQuery);