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
28 //= require jquery.number.min
34 'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
38 $(document).ajaxStart(function(){
39 $('.modal-with-loading-spinner .spinner').show();
40 }).ajaxStop(function(){
41 $('.modal-with-loading-spinner .spinner').hide();
44 $('[data-toggle=tooltip]').tooltip();
46 $('.expand-collapse-row').on('click', function(event) {
47 var targets = $('#' + $(this).attr('data-id'));
48 if (targets.css('display') == 'none') {
49 $(this).addClass('icon-minus-sign');
50 $(this).removeClass('icon-plus-sign');
52 $(this).addClass('icon-plus-sign');
53 $(this).removeClass('icon-minus-sign');
55 targets.fadeToggle(200);
61 on('ajax:send', function(e, xhr) {
64 $('.loading').fadeTo('fast', 1);
67 on('ajax:complete', function(e, status) {
70 $('.loading').fadeOut('fast', 0);
73 on('ajaxSend', function(e, xhr) {
74 // jQuery triggers 'ajaxSend' event when starting an ajax call, but
75 // rails-generated ajax triggers generate 'ajax:send'. Workbench
76 // event listeners currently expect 'ajax:send', so trigger the
77 // rails event in response to the jQuery one.
78 $(document).trigger('ajax:send');
80 on('ajaxComplete', function(e, xhr) {
81 // See comment above about ajaxSend/ajax:send
82 $(document).trigger('ajax:complete');
84 on('click', '.removable-tag a', function(e) {
85 var tag_span = $(this).parents('[data-tag-link-uuid]').eq(0)
86 tag_span.fadeTo('fast', 0.2);
87 $.ajax('/links/' + tag_span.attr('data-tag-link-uuid'),
90 data: { '_method': 'DELETE' },
92 done(function(data, status, jqxhr) {
95 fail(function(jqxhr, status, error) {
96 this.addClass('label-danger').fadeTo('fast', '1');
100 on('click', 'a.add-tag-button', function(e) {
102 var new_tag_uuid = 'new-tag-' + Math.random();
103 var tag_head_uuid = $(this).parents('tr').attr('data-object-uuid');
104 var new_tag = window.prompt("Add tag for collection "+
110 $('<span class="label label-info removable-tag"></span>').
111 attr('data-tag-link-uuid', new_tag_uuid).
113 css('opacity', '0.2').
114 append(' <span class="removable-tag"><a title="Delete tag"><i class="fa fa-fw fa-trash-o"></i></a></span>');
118 append(new_tag_span).
120 $.ajax($(this).attr('data-remote-href'),
122 type: $(this).attr('data-remote-method'),
124 'link[head_uuid]': tag_head_uuid,
125 'link[link_class]': 'tag',
126 'link[name]': new_tag
128 context: new_tag_span}).
129 done(function(data, status, jqxhr) {
130 this.attr('data-tag-link-uuid', data.uuid).
133 fail(function(jqxhr, status, error) {
134 this.addClass('label-danger').fadeTo('fast', '1');
140 on('ajax:complete ready', function() {
141 // See http://getbootstrap.com/javascript/#buttons
144 on('ready ajax:complete', function() {
145 $('[data-toggle~=tooltip]').tooltip({container:'body'});
147 on('ready ajax:complete', function() {
148 // This makes the dialog close on Esc key, obviously.
149 $('.modal').attr('tabindex', '-1')
152 HeaderRowFixer = function(selector) {
153 this.duplicateTheadTr = function() {
154 $(selector).each(function() {
155 var the_table = this;
156 if ($('>tbody>tr:first>th', the_table).length > 0)
158 $('>tbody', the_table).
159 prepend($('>thead>tr', the_table).
164 this.fixThead = function() {
165 $(selector).each(function() {
167 $('> tbody > tr:eq(1) > td', this).each( function(i,v){
168 widths.push($(v).width());
170 for(i=0;i<widths.length;i++) {
171 $('thead th:eq('+i+')', this).width(widths[i]);
177 var fixer = new HeaderRowFixer('.table-fixed-header-row');
178 fixer.duplicateTheadTr();
180 $(window).resize(function(){
183 $(document).on('ajax:complete', function(e, status) {
184 fixer.duplicateTheadTr();
188 $(document).ready(function() {
189 /* When wiselinks is initialized, selection.js is not working. Since we want to stop
190 using selection.js in the near future, let's not initialize wiselinks for now. */
192 // window.wiselinks = new Wiselinks();
194 $(document).off('page:loading').on('page:loading', function(event, $target, render, url){
195 $("#page-wrapper").fadeOut(200);
198 $(document).off('page:redirected').on('page:redirected', function(event, $target, render, url){
201 $(document).off('page:always').on('page:always', function(event, xhr, settings){
202 $("#page-wrapper").fadeIn(200);
205 $(document).off('page:done').on('page:done', function(event, $target, status, url, data){
208 $(document).off('page:fail').on('page:fail', function(event, $target, status, url, error, code){
212 $(document).on('click', '.compute-detail', function(e) {
213 $(e.target).collapse('hide');
216 $(document).on('click', '.compute-node-summary', function(e) {
217 $(e.target.href).collapse('toggle');
220 $(document).on('click', '.force-cache-reload', function(e) {
221 history.replaceState( { nocache: true }, '' );
225 window.addEventListener("DOMContentLoaded", function(e) {
227 if(history.state.nocache) {
229 history.replaceState( {}, '' );
230 location.reload(true);
235 function showLoadingModal() {
236 $('#loading-modal').modal('show');
239 function hideLoadingModal() {
240 $('#loading-modal').modal('hide');
243 function hasHTML5History() {
244 return !!(window.history && window.history.pushState);