1 // This is a manifest file that'll be compiled into application.js, which will include all the files
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.
7 // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
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.
14 //= require jquery_ujs
16 //= require bootstrap/dropdown
17 //= require bootstrap/tab
18 //= require bootstrap/tooltip
19 //= require bootstrap/popover
20 //= require bootstrap/collapse
21 //= require bootstrap/modal
22 //= require bootstrap/button
23 //= require bootstrap3-editable/bootstrap-editable
24 //= require bootstrap-tab-history
31 'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
35 $(document).ajaxStart(function(){
36 $('.modal-with-loading-spinner .spinner').show();
37 }).ajaxStop(function(){
38 $('.modal-with-loading-spinner .spinner').hide();
41 $('[data-toggle=tooltip]').tooltip();
43 $('.expand-collapse-row').on('click', function(event) {
44 var targets = $('#' + $(this).attr('data-id'));
45 if (targets.css('display') == 'none') {
46 $(this).addClass('icon-minus-sign');
47 $(this).removeClass('icon-plus-sign');
49 $(this).addClass('icon-plus-sign');
50 $(this).removeClass('icon-minus-sign');
52 targets.fadeToggle(200);
58 on('ajax:send', function(e, xhr) {
61 $('.loading').fadeTo('fast', 1);
64 on('ajax:complete', function(e, status) {
67 $('.loading').fadeOut('fast', 0);
70 on('ajaxSend', function(e, xhr) {
71 // jQuery triggers 'ajaxSend' event when starting an ajax call, but
72 // rails-generated ajax triggers generate 'ajax:send'. Workbench
73 // event listeners currently expect 'ajax:send', so trigger the
74 // rails event in response to the jQuery one.
75 $(document).trigger('ajax:send');
77 on('ajaxComplete', function(e, xhr) {
78 // See comment above about ajaxSend/ajax:send
79 $(document).trigger('ajax:complete');
81 on('click', '.removable-tag a', function(e) {
82 var tag_span = $(this).parents('[data-tag-link-uuid]').eq(0)
83 tag_span.fadeTo('fast', 0.2);
84 $.ajax('/links/' + tag_span.attr('data-tag-link-uuid'),
87 data: { '_method': 'DELETE' },
89 done(function(data, status, jqxhr) {
92 fail(function(jqxhr, status, error) {
93 this.addClass('label-danger').fadeTo('fast', '1');
97 on('click', 'a.add-tag-button', function(e) {
99 var new_tag_uuid = 'new-tag-' + Math.random();
100 var tag_head_uuid = $(this).parents('tr').attr('data-object-uuid');
101 var new_tag = window.prompt("Add tag for collection "+
107 $('<span class="label label-info removable-tag"></span>').
108 attr('data-tag-link-uuid', new_tag_uuid).
110 css('opacity', '0.2').
111 append(' <span class="removable-tag"><a title="Delete tag"><i class="fa fa-fw fa-trash-o"></i></a></span>');
115 append(new_tag_span).
117 $.ajax($(this).attr('data-remote-href'),
119 type: $(this).attr('data-remote-method'),
121 'link[head_uuid]': tag_head_uuid,
122 'link[link_class]': 'tag',
123 'link[name]': new_tag
125 context: new_tag_span}).
126 done(function(data, status, jqxhr) {
127 this.attr('data-tag-link-uuid', data.uuid).
130 fail(function(jqxhr, status, error) {
131 this.addClass('label-danger').fadeTo('fast', '1');
137 on('ajax:complete ready', function() {
138 // See http://getbootstrap.com/javascript/#buttons
141 on('ready ajax:complete', function() {
142 $('[data-toggle~=tooltip]').tooltip({container:'body'});
144 on('ready ajax:complete', function() {
145 // This makes the dialog close on Esc key, obviously.
146 $('.modal').attr('tabindex', '-1')
149 HeaderRowFixer = function(selector) {
150 this.duplicateTheadTr = function() {
151 $(selector).each(function() {
152 var the_table = this;
153 if ($('>tbody>tr:first>th', the_table).length > 0)
155 $('>tbody', the_table).
156 prepend($('>thead>tr', the_table).
161 this.fixThead = function() {
162 $(selector).each(function() {
164 $('> tbody > tr:eq(1) > td', this).each( function(i,v){
165 widths.push($(v).width());
167 for(i=0;i<widths.length;i++) {
168 $('thead th:eq('+i+')', this).width(widths[i]);
174 var fixer = new HeaderRowFixer('.table-fixed-header-row');
175 fixer.duplicateTheadTr();
177 $(window).resize(function(){
180 $(document).on('ajax:complete', function(e, status) {
181 fixer.duplicateTheadTr();
185 $(document).ready(function() {
186 /* When wiselinks is initialized, selection.js is not working. Since we want to stop
187 using selection.js in the near future, let's not initialize wiselinks for now. */
189 // window.wiselinks = new Wiselinks();
191 $(document).off('page:loading').on('page:loading', function(event, $target, render, url){
192 $("#page-wrapper").fadeOut(200);
195 $(document).off('page:redirected').on('page:redirected', function(event, $target, render, url){
198 $(document).off('page:always').on('page:always', function(event, xhr, settings){
199 $("#page-wrapper").fadeIn(200);
202 $(document).off('page:done').on('page:done', function(event, $target, status, url, data){
205 $(document).off('page:fail').on('page:fail', function(event, $target, status, url, error, code){
209 $(document).on('click', '.compute-detail', function(e) {
210 $(e.target).collapse('hide');
213 $(document).on('click', '.compute-node-summary', function(e) {
214 $(e.target.href).collapse('toggle');
217 $(document).on('click', '.force-cache-reload', function(e) {
218 history.replaceState( { nocache: true }, '' );
222 window.addEventListener("DOMContentLoaded", function(e) {
224 if(history.state.nocache) {
226 history.replaceState( {}, '' );
227 location.reload(true);
232 function showLoadingModal() {
233 $('#loading-modal').modal('show');
236 function hideLoadingModal() {
237 $('#loading-modal').modal('hide');
240 function hasHTML5History() {
241 return !!(window.history && window.history.pushState);