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
36 //= require awesomplete
40 Es6ObjectAssign.polyfill()
41 window.m = Object.assign(window.Mithril, {stream: window.m.stream})
44 $(document).ajaxStart(function(){
45 $('.modal-with-loading-spinner .spinner').show();
46 }).ajaxStop(function(){
47 $('.modal-with-loading-spinner .spinner').hide();
50 $('[data-toggle=tooltip]').tooltip();
52 $('.expand-collapse-row').on('click', function(event) {
53 var targets = $('#' + $(this).attr('data-id'));
54 if (targets.css('display') == 'none') {
55 $(this).addClass('icon-minus-sign');
56 $(this).removeClass('icon-plus-sign');
58 $(this).addClass('icon-plus-sign');
59 $(this).removeClass('icon-minus-sign');
61 targets.fadeToggle(200);
67 on('ajax:send', function(e, xhr) {
70 $('.loading').fadeTo('fast', 1);
73 on('ajax:complete', function(e, status) {
76 $('.loading').fadeOut('fast', 0);
79 on('ajaxSend', function(e, xhr) {
80 // jQuery triggers 'ajaxSend' event when starting an ajax call, but
81 // rails-generated ajax triggers generate 'ajax:send'. Workbench
82 // event listeners currently expect 'ajax:send', so trigger the
83 // rails event in response to the jQuery one.
84 $(document).trigger('ajax:send');
86 on('ajaxComplete', function(e, xhr) {
87 // See comment above about ajaxSend/ajax:send
88 $(document).trigger('ajax:complete');
90 on('click', '.removable-tag a', function(e) {
91 var tag_span = $(this).parents('[data-tag-link-uuid]').eq(0)
92 tag_span.fadeTo('fast', 0.2);
93 $.ajax('/links/' + tag_span.attr('data-tag-link-uuid'),
96 data: { '_method': 'DELETE' },
98 done(function(data, status, jqxhr) {
101 fail(function(jqxhr, status, error) {
102 this.addClass('label-danger').fadeTo('fast', '1');
106 on('click', 'a.add-tag-button', function(e) {
108 var new_tag_uuid = 'new-tag-' + Math.random();
109 var tag_head_uuid = $(this).parents('tr').attr('data-object-uuid');
110 var new_tag = window.prompt("Add tag for collection "+
116 $('<span class="label label-info removable-tag"></span>').
117 attr('data-tag-link-uuid', new_tag_uuid).
119 css('opacity', '0.2').
120 append(' <span class="removable-tag"><a title="Delete tag"><i class="fa fa-fw fa-trash-o"></i></a></span>');
124 append(new_tag_span).
126 $.ajax($(this).attr('data-remote-href'),
128 type: $(this).attr('data-remote-method'),
130 'link[head_uuid]': tag_head_uuid,
131 'link[link_class]': 'tag',
132 'link[name]': new_tag
134 context: new_tag_span}).
135 done(function(data, status, jqxhr) {
136 this.attr('data-tag-link-uuid', data.uuid).
139 fail(function(jqxhr, status, error) {
140 this.addClass('label-danger').fadeTo('fast', '1');
144 on('click focusin', 'input.select-on-focus', function(event) {
145 event.target.select();
149 on('ajax:complete ready', function() {
150 // See http://getbootstrap.com/javascript/#buttons
153 on('ready ajax:complete', function() {
154 $('[data-toggle~=tooltip]').tooltip({container:'body'});
156 on('ready ajax:complete', function() {
157 // This makes the dialog close on Esc key, obviously.
158 $('.modal').attr('tabindex', '-1')
160 on('ready', function() {
161 // Need this to trigger input validation/synchronization callbacks because some browsers
162 // auto-fill form fields (e.g., when navigating "back" to a page where some text
163 // had been entered in a search box) without triggering a change or input event.
164 $('input').each(function(el) {
165 $(el).trigger($.Event('input', {currentTarget: el}));
169 HeaderRowFixer = function(selector) {
170 this.duplicateTheadTr = function() {
171 $(selector).each(function() {
172 var the_table = this;
173 if ($('>tbody>tr:first>th', the_table).length > 0)
175 $('>tbody', the_table).
176 prepend($('>thead>tr', the_table).
181 this.fixThead = function() {
182 $(selector).each(function() {
184 $('> tbody > tr:eq(1) > td', this).each( function(i,v){
185 widths.push($(v).width());
187 for(i=0;i<widths.length;i++) {
188 $('thead th:eq('+i+')', this).width(widths[i]);
194 var fixer = new HeaderRowFixer('.table-fixed-header-row');
195 fixer.duplicateTheadTr();
197 $(window).resize(function(){
200 $(document).on('ajax:complete', function(e, status) {
201 fixer.duplicateTheadTr();
205 $(document).ready(function() {
206 /* When wiselinks is initialized, selection.js is not working. Since we want to stop
207 using selection.js in the near future, let's not initialize wiselinks for now. */
209 // window.wiselinks = new Wiselinks();
211 $(document).off('page:loading').on('page:loading', function(event, $target, render, url){
212 $("#page-wrapper").fadeOut(200);
215 $(document).off('page:redirected').on('page:redirected', function(event, $target, render, url){
218 $(document).off('page:always').on('page:always', function(event, xhr, settings){
219 $("#page-wrapper").fadeIn(200);
222 $(document).off('page:done').on('page:done', function(event, $target, status, url, data){
225 $(document).off('page:fail').on('page:fail', function(event, $target, status, url, error, code){
229 $(document).on('click', '.compute-detail', function(e) {
230 $(e.target).collapse('hide');
233 $(document).on('click', '.compute-node-summary', function(e) {
234 $(e.target.href).collapse('toggle');
237 $(document).on('click', '.force-cache-reload', function(e) {
238 history.replaceState( { nocache: true }, '' );
242 window.addEventListener("DOMContentLoaded", function(e) {
244 if(history.state.nocache) {
246 history.replaceState( {}, '' );
247 location.reload(true);
252 function showLoadingModal() {
253 $('#loading-modal').modal('show');
256 function hideLoadingModal() {
257 $('#loading-modal').modal('hide');
260 function hasHTML5History() {
261 return !!(window.history && window.history.pushState);