1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 // This is a manifest file that'll be compiled into application.js, which will include all the files
8 // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
9 // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
11 // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
14 // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
15 // GO AFTER THE REQUIRES BELOW.
18 //= require jquery_ujs
20 //= require bootstrap/dropdown
21 //= require bootstrap/tab
22 //= require bootstrap/tooltip
23 //= require bootstrap/popover
24 //= require bootstrap/collapse
25 //= require bootstrap/modal
26 //= require bootstrap/button
27 //= require bootstrap3-editable/bootstrap-editable
28 //= require bootstrap-tab-history
33 //= require jquery.number.min
34 //= require npm-dependencies
35 //= require mithril/stream/stream
38 Es6ObjectAssign.polyfill()
39 window.m = Object.assign(window.Mithril, {stream: window.m.stream})
42 $(document).ajaxStart(function(){
43 $('.modal-with-loading-spinner .spinner').show();
44 }).ajaxStop(function(){
45 $('.modal-with-loading-spinner .spinner').hide();
48 $('[data-toggle=tooltip]').tooltip();
50 $('.expand-collapse-row').on('click', function(event) {
51 var targets = $('#' + $(this).attr('data-id'));
52 if (targets.css('display') == 'none') {
53 $(this).addClass('icon-minus-sign');
54 $(this).removeClass('icon-plus-sign');
56 $(this).addClass('icon-plus-sign');
57 $(this).removeClass('icon-minus-sign');
59 targets.fadeToggle(200);
65 on('ajax:send', function(e, xhr) {
68 $('.loading').fadeTo('fast', 1);
71 on('ajax:complete', function(e, status) {
74 $('.loading').fadeOut('fast', 0);
77 on('ajaxSend', function(e, xhr) {
78 // jQuery triggers 'ajaxSend' event when starting an ajax call, but
79 // rails-generated ajax triggers generate 'ajax:send'. Workbench
80 // event listeners currently expect 'ajax:send', so trigger the
81 // rails event in response to the jQuery one.
82 $(document).trigger('ajax:send');
84 on('ajaxComplete', function(e, xhr) {
85 // See comment above about ajaxSend/ajax:send
86 $(document).trigger('ajax:complete');
88 on('click', '.removable-tag a', function(e) {
89 var tag_span = $(this).parents('[data-tag-link-uuid]').eq(0)
90 tag_span.fadeTo('fast', 0.2);
91 $.ajax('/links/' + tag_span.attr('data-tag-link-uuid'),
94 data: { '_method': 'DELETE' },
96 done(function(data, status, jqxhr) {
99 fail(function(jqxhr, status, error) {
100 this.addClass('label-danger').fadeTo('fast', '1');
104 on('click', 'a.add-tag-button', function(e) {
106 var new_tag_uuid = 'new-tag-' + Math.random();
107 var tag_head_uuid = $(this).parents('tr').attr('data-object-uuid');
108 var new_tag = window.prompt("Add tag for collection "+
114 $('<span class="label label-info removable-tag"></span>').
115 attr('data-tag-link-uuid', new_tag_uuid).
117 css('opacity', '0.2').
118 append(' <span class="removable-tag"><a title="Delete tag"><i class="fa fa-fw fa-trash-o"></i></a></span>');
122 append(new_tag_span).
124 $.ajax($(this).attr('data-remote-href'),
126 type: $(this).attr('data-remote-method'),
128 'link[head_uuid]': tag_head_uuid,
129 'link[link_class]': 'tag',
130 'link[name]': new_tag
132 context: new_tag_span}).
133 done(function(data, status, jqxhr) {
134 this.attr('data-tag-link-uuid', data.uuid).
137 fail(function(jqxhr, status, error) {
138 this.addClass('label-danger').fadeTo('fast', '1');
142 on('click focusin', 'input.select-on-focus', function(event) {
143 event.target.select();
147 on('ajax:complete ready', function() {
148 // See http://getbootstrap.com/javascript/#buttons
151 on('ready ajax:complete', function() {
152 $('[data-toggle~=tooltip]').tooltip({container:'body'});
154 on('ready ajax:complete', function() {
155 // This makes the dialog close on Esc key, obviously.
156 $('.modal').attr('tabindex', '-1')
158 on('ready', function() {
159 // Need this to trigger input validation/synchronization callbacks because some browsers
160 // auto-fill form fields (e.g., when navigating "back" to a page where some text
161 // had been entered in a search box) without triggering a change or input event.
162 $('input').each(function(el) {
163 $(el).trigger($.Event('input', {currentTarget: el}));
167 HeaderRowFixer = function(selector) {
168 this.duplicateTheadTr = function() {
169 $(selector).each(function() {
170 var the_table = this;
171 if ($('>tbody>tr:first>th', the_table).length > 0)
173 $('>tbody', the_table).
174 prepend($('>thead>tr', the_table).
179 this.fixThead = function() {
180 $(selector).each(function() {
182 $('> tbody > tr:eq(1) > td', this).each( function(i,v){
183 widths.push($(v).width());
185 for(i=0;i<widths.length;i++) {
186 $('thead th:eq('+i+')', this).width(widths[i]);
192 var fixer = new HeaderRowFixer('.table-fixed-header-row');
193 fixer.duplicateTheadTr();
195 $(window).resize(function(){
198 $(document).on('ajax:complete', function(e, status) {
199 fixer.duplicateTheadTr();
203 $(document).ready(function() {
204 /* When wiselinks is initialized, selection.js is not working. Since we want to stop
205 using selection.js in the near future, let's not initialize wiselinks for now. */
207 // window.wiselinks = new Wiselinks();
209 $(document).off('page:loading').on('page:loading', function(event, $target, render, url){
210 $("#page-wrapper").fadeOut(200);
213 $(document).off('page:redirected').on('page:redirected', function(event, $target, render, url){
216 $(document).off('page:always').on('page:always', function(event, xhr, settings){
217 $("#page-wrapper").fadeIn(200);
220 $(document).off('page:done').on('page:done', function(event, $target, status, url, data){
223 $(document).off('page:fail').on('page:fail', function(event, $target, status, url, error, code){
227 $(document).on('click', '.compute-detail', function(e) {
228 $(e.target).collapse('hide');
231 $(document).on('click', '.compute-node-summary', function(e) {
232 $(e.target.href).collapse('toggle');
235 $(document).on('click', '.force-cache-reload', function(e) {
236 history.replaceState( { nocache: true }, '' );
240 window.addEventListener("DOMContentLoaded", function(e) {
242 if(history.state.nocache) {
244 history.replaceState( {}, '' );
245 location.reload(true);
250 function showLoadingModal() {
251 $('#loading-modal').modal('show');
254 function hideLoadingModal() {
255 $('#loading-modal').modal('hide');
258 function hasHTML5History() {
259 return !!(window.history && window.history.pushState);