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
29 //= require jquery.number.min
33 $(document).ajaxStart(function(){
34 $('.modal-with-loading-spinner .spinner').show();
35 }).ajaxStop(function(){
36 $('.modal-with-loading-spinner .spinner').hide();
39 $('[data-toggle=tooltip]').tooltip();
41 $('.expand-collapse-row').on('click', function(event) {
42 var targets = $('#' + $(this).attr('data-id'));
43 if (targets.css('display') == 'none') {
44 $(this).addClass('icon-minus-sign');
45 $(this).removeClass('icon-plus-sign');
47 $(this).addClass('icon-plus-sign');
48 $(this).removeClass('icon-minus-sign');
50 targets.fadeToggle(200);
56 on('ajax:send', function(e, xhr) {
59 $('.loading').fadeTo('fast', 1);
62 on('ajax:complete', function(e, status) {
65 $('.loading').fadeOut('fast', 0);
68 on('ajaxSend', function(e, xhr) {
69 // jQuery triggers 'ajaxSend' event when starting an ajax call, but
70 // rails-generated ajax triggers generate 'ajax:send'. Workbench
71 // event listeners currently expect 'ajax:send', so trigger the
72 // rails event in response to the jQuery one.
73 $(document).trigger('ajax:send');
75 on('ajaxComplete', function(e, xhr) {
76 // See comment above about ajaxSend/ajax:send
77 $(document).trigger('ajax:complete');
79 on('click', '.removable-tag a', function(e) {
80 var tag_span = $(this).parents('[data-tag-link-uuid]').eq(0)
81 tag_span.fadeTo('fast', 0.2);
82 $.ajax('/links/' + tag_span.attr('data-tag-link-uuid'),
85 data: { '_method': 'DELETE' },
87 done(function(data, status, jqxhr) {
90 fail(function(jqxhr, status, error) {
91 this.addClass('label-danger').fadeTo('fast', '1');
95 on('click', 'a.add-tag-button', function(e) {
97 var new_tag_uuid = 'new-tag-' + Math.random();
98 var tag_head_uuid = $(this).parents('tr').attr('data-object-uuid');
99 var new_tag = window.prompt("Add tag for collection "+
105 $('<span class="label label-info removable-tag"></span>').
106 attr('data-tag-link-uuid', new_tag_uuid).
108 css('opacity', '0.2').
109 append(' <span class="removable-tag"><a title="Delete tag"><i class="fa fa-fw fa-trash-o"></i></a></span>');
113 append(new_tag_span).
115 $.ajax($(this).attr('data-remote-href'),
117 type: $(this).attr('data-remote-method'),
119 'link[head_uuid]': tag_head_uuid,
120 'link[link_class]': 'tag',
121 'link[name]': new_tag
123 context: new_tag_span}).
124 done(function(data, status, jqxhr) {
125 this.attr('data-tag-link-uuid', data.uuid).
128 fail(function(jqxhr, status, error) {
129 this.addClass('label-danger').fadeTo('fast', '1');
135 on('ajax:complete ready', function() {
136 // See http://getbootstrap.com/javascript/#buttons
139 on('ready ajax:complete', function() {
140 $('[data-toggle~=tooltip]').tooltip({container:'body'});
142 on('ready ajax:complete', function() {
143 // This makes the dialog close on Esc key, obviously.
144 $('.modal').attr('tabindex', '-1')
147 HeaderRowFixer = function(selector) {
148 this.duplicateTheadTr = function() {
149 $(selector).each(function() {
150 var the_table = this;
151 if ($('>tbody>tr:first>th', the_table).length > 0)
153 $('>tbody', the_table).
154 prepend($('>thead>tr', the_table).
159 this.fixThead = function() {
160 $(selector).each(function() {
162 $('> tbody > tr:eq(1) > td', this).each( function(i,v){
163 widths.push($(v).width());
165 for(i=0;i<widths.length;i++) {
166 $('thead th:eq('+i+')', this).width(widths[i]);
172 var fixer = new HeaderRowFixer('.table-fixed-header-row');
173 fixer.duplicateTheadTr();
175 $(window).resize(function(){
178 $(document).on('ajax:complete', function(e, status) {
179 fixer.duplicateTheadTr();
183 $(document).ready(function() {
184 /* When wiselinks is initialized, selection.js is not working. Since we want to stop
185 using selection.js in the near future, let's not initialize wiselinks for now. */
187 // window.wiselinks = new Wiselinks();
189 $(document).off('page:loading').on('page:loading', function(event, $target, render, url){
190 $("#page-wrapper").fadeOut(200);
193 $(document).off('page:redirected').on('page:redirected', function(event, $target, render, url){
196 $(document).off('page:always').on('page:always', function(event, xhr, settings){
197 $("#page-wrapper").fadeIn(200);
200 $(document).off('page:done').on('page:done', function(event, $target, status, url, data){
203 $(document).off('page:fail').on('page:fail', function(event, $target, status, url, error, code){
207 $(document).on('click', '.compute-detail', function(e) {
208 $(e.target).collapse('hide');
211 $(document).on('click', '.compute-node-summary', function(e) {
212 $(e.target.href).collapse('toggle');
215 $(document).on('click', '.force-cache-reload', function(e) {
216 history.replaceState( { nocache: true }, '' );
220 window.addEventListener("DOMContentLoaded", function(e) {
222 if(history.state.nocache) {
224 history.replaceState( {}, '' );
225 location.reload(true);
230 function showLoadingModal() {
231 $('#loading-modal').modal('show');
234 function hideLoadingModal() {
235 $('#loading-modal').modal('hide');
238 function hasHTML5History() {
239 return !!(window.history && window.history.pushState);