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 microplugin
41 Es6ObjectAssign.polyfill()
42 window.m = Object.assign(window.Mithril, {stream: window.m.stream})
45 $(document).ajaxStart(function(){
46 $('.modal-with-loading-spinner .spinner').show();
47 }).ajaxStop(function(){
48 $('.modal-with-loading-spinner .spinner').hide();
51 $('[data-toggle=tooltip]').tooltip();
53 $('.expand-collapse-row').on('click', function(event) {
54 var targets = $('#' + $(this).attr('data-id'));
55 if (targets.css('display') == 'none') {
56 $(this).addClass('icon-minus-sign');
57 $(this).removeClass('icon-plus-sign');
59 $(this).addClass('icon-plus-sign');
60 $(this).removeClass('icon-minus-sign');
62 targets.fadeToggle(200);
68 on('ajax:send', function(e, xhr) {
71 $('.loading').fadeTo('fast', 1);
74 on('ajax:complete', function(e, status) {
77 $('.loading').fadeOut('fast', 0);
80 on('ajaxSend', function(e, xhr) {
81 // jQuery triggers 'ajaxSend' event when starting an ajax call, but
82 // rails-generated ajax triggers generate 'ajax:send'. Workbench
83 // event listeners currently expect 'ajax:send', so trigger the
84 // rails event in response to the jQuery one.
85 $(document).trigger('ajax:send');
87 on('ajaxComplete', function(e, xhr) {
88 // See comment above about ajaxSend/ajax:send
89 $(document).trigger('ajax:complete');
91 on('click', '.removable-tag a', function(e) {
92 var tag_span = $(this).parents('[data-tag-link-uuid]').eq(0)
93 tag_span.fadeTo('fast', 0.2);
94 $.ajax('/links/' + tag_span.attr('data-tag-link-uuid'),
97 data: { '_method': 'DELETE' },
99 done(function(data, status, jqxhr) {
102 fail(function(jqxhr, status, error) {
103 this.addClass('label-danger').fadeTo('fast', '1');
107 on('click', 'a.add-tag-button', function(e) {
109 var new_tag_uuid = 'new-tag-' + Math.random();
110 var tag_head_uuid = $(this).parents('tr').attr('data-object-uuid');
111 var new_tag = window.prompt("Add tag for collection "+
117 $('<span class="label label-info removable-tag"></span>').
118 attr('data-tag-link-uuid', new_tag_uuid).
120 css('opacity', '0.2').
121 append(' <span class="removable-tag"><a title="Delete tag"><i class="fa fa-fw fa-trash-o"></i></a></span>');
125 append(new_tag_span).
127 $.ajax($(this).attr('data-remote-href'),
129 type: $(this).attr('data-remote-method'),
131 'link[head_uuid]': tag_head_uuid,
132 'link[link_class]': 'tag',
133 'link[name]': new_tag
135 context: new_tag_span}).
136 done(function(data, status, jqxhr) {
137 this.attr('data-tag-link-uuid', data.uuid).
140 fail(function(jqxhr, status, error) {
141 this.addClass('label-danger').fadeTo('fast', '1');
145 on('click focusin', 'input.select-on-focus', function(event) {
146 event.target.select();
150 on('ajax:complete ready', function() {
151 // See http://getbootstrap.com/javascript/#buttons
154 on('ready ajax:complete', function() {
155 $('[data-toggle~=tooltip]').tooltip({container:'body'});
157 on('ready ajax:complete', function() {
158 // This makes the dialog close on Esc key, obviously.
159 $('.modal').attr('tabindex', '-1')
161 on('ready', function() {
162 // Need this to trigger input validation/synchronization callbacks because some browsers
163 // auto-fill form fields (e.g., when navigating "back" to a page where some text
164 // had been entered in a search box) without triggering a change or input event.
165 $('input').each(function(el) {
166 $(el).trigger($.Event('input', {currentTarget: el}));
170 HeaderRowFixer = function(selector) {
171 this.duplicateTheadTr = function() {
172 $(selector).each(function() {
173 var the_table = this;
174 if ($('>tbody>tr:first>th', the_table).length > 0)
176 $('>tbody', the_table).
177 prepend($('>thead>tr', the_table).
182 this.fixThead = function() {
183 $(selector).each(function() {
185 $('> tbody > tr:eq(1) > td', this).each( function(i,v){
186 widths.push($(v).width());
188 for(i=0;i<widths.length;i++) {
189 $('thead th:eq('+i+')', this).width(widths[i]);
195 var fixer = new HeaderRowFixer('.table-fixed-header-row');
196 fixer.duplicateTheadTr();
198 $(window).resize(function(){
201 $(document).on('ajax:complete', function(e, status) {
202 fixer.duplicateTheadTr();
206 $(document).ready(function() {
207 /* When wiselinks is initialized, selection.js is not working. Since we want to stop
208 using selection.js in the near future, let's not initialize wiselinks for now. */
210 // window.wiselinks = new Wiselinks();
212 $(document).off('page:loading').on('page:loading', function(event, $target, render, url){
213 $("#page-wrapper").fadeOut(200);
216 $(document).off('page:redirected').on('page:redirected', function(event, $target, render, url){
219 $(document).off('page:always').on('page:always', function(event, xhr, settings){
220 $("#page-wrapper").fadeIn(200);
223 $(document).off('page:done').on('page:done', function(event, $target, status, url, data){
226 $(document).off('page:fail').on('page:fail', function(event, $target, status, url, error, code){
230 $(document).on('click', '.compute-detail', function(e) {
231 $(e.target).collapse('hide');
234 $(document).on('click', '.compute-node-summary', function(e) {
235 $(e.target.href).collapse('toggle');
238 $(document).on('click', '.force-cache-reload', function(e) {
239 history.replaceState( { nocache: true }, '' );
243 window.addEventListener("DOMContentLoaded", function(e) {
245 if(history.state.nocache) {
247 history.replaceState( {}, '' );
248 location.reload(true);
253 function showLoadingModal() {
254 $('#loading-modal').modal('show');
257 function hideLoadingModal() {
258 $('#loading-modal').modal('hide');
261 function hasHTML5History() {
262 return !!(window.history && window.history.pushState);