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
33 'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
37 $(document).ajaxStart(function(){
38 $('.modal-with-loading-spinner .spinner').show();
39 }).ajaxStop(function(){
40 $('.modal-with-loading-spinner .spinner').hide();
43 $('[data-toggle=tooltip]').tooltip();
45 $('.expand-collapse-row').on('click', function(event) {
46 var targets = $('#' + $(this).attr('data-id'));
47 if (targets.css('display') == 'none') {
48 $(this).addClass('icon-minus-sign');
49 $(this).removeClass('icon-plus-sign');
51 $(this).addClass('icon-plus-sign');
52 $(this).removeClass('icon-minus-sign');
54 targets.fadeToggle(200);
60 on('ajax:send', function(e, xhr) {
63 $('.loading').fadeTo('fast', 1);
66 on('ajax:complete', function(e, status) {
69 $('.loading').fadeOut('fast', 0);
72 on('ajaxSend', function(e, xhr) {
73 // jQuery triggers 'ajaxSend' event when starting an ajax call, but
74 // rails-generated ajax triggers generate 'ajax:send'. Workbench
75 // event listeners currently expect 'ajax:send', so trigger the
76 // rails event in response to the jQuery one.
77 $(document).trigger('ajax:send');
79 on('ajaxComplete', function(e, xhr) {
80 // See comment above about ajaxSend/ajax:send
81 $(document).trigger('ajax:complete');
83 on('click', '.removable-tag a', function(e) {
84 var tag_span = $(this).parents('[data-tag-link-uuid]').eq(0)
85 tag_span.fadeTo('fast', 0.2);
86 $.ajax('/links/' + tag_span.attr('data-tag-link-uuid'),
89 data: { '_method': 'DELETE' },
91 done(function(data, status, jqxhr) {
94 fail(function(jqxhr, status, error) {
95 this.addClass('label-danger').fadeTo('fast', '1');
99 on('click', 'a.add-tag-button', function(e) {
101 var new_tag_uuid = 'new-tag-' + Math.random();
102 var tag_head_uuid = $(this).parents('tr').attr('data-object-uuid');
103 var new_tag = window.prompt("Add tag for collection "+
109 $('<span class="label label-info removable-tag"></span>').
110 attr('data-tag-link-uuid', new_tag_uuid).
112 css('opacity', '0.2').
113 append(' <span class="removable-tag"><a title="Delete tag"><i class="fa fa-fw fa-trash-o"></i></a></span>');
117 append(new_tag_span).
119 $.ajax($(this).attr('data-remote-href'),
121 type: $(this).attr('data-remote-method'),
123 'link[head_uuid]': tag_head_uuid,
124 'link[link_class]': 'tag',
125 'link[name]': new_tag
127 context: new_tag_span}).
128 done(function(data, status, jqxhr) {
129 this.attr('data-tag-link-uuid', data.uuid).
132 fail(function(jqxhr, status, error) {
133 this.addClass('label-danger').fadeTo('fast', '1');
139 on('ajax:complete ready', function() {
140 // See http://getbootstrap.com/javascript/#buttons
143 on('ready ajax:complete', function() {
144 $('[data-toggle~=tooltip]').tooltip({container:'body'});
146 on('ready ajax:complete', function() {
147 // This makes the dialog close on Esc key, obviously.
148 $('.modal').attr('tabindex', '-1')
151 HeaderRowFixer = function(selector) {
152 this.duplicateTheadTr = function() {
153 $(selector).each(function() {
154 var the_table = this;
155 if ($('>tbody>tr:first>th', the_table).length > 0)
157 $('>tbody', the_table).
158 prepend($('>thead>tr', the_table).
163 this.fixThead = function() {
164 $(selector).each(function() {
166 $('> tbody > tr:eq(1) > td', this).each( function(i,v){
167 widths.push($(v).width());
169 for(i=0;i<widths.length;i++) {
170 $('thead th:eq('+i+')', this).width(widths[i]);
176 var fixer = new HeaderRowFixer('.table-fixed-header-row');
177 fixer.duplicateTheadTr();
179 $(window).resize(function(){
182 $(document).on('ajax:complete', function(e, status) {
183 fixer.duplicateTheadTr();
187 $(document).ready(function() {
188 /* When wiselinks is initialized, selection.js is not working. Since we want to stop
189 using selection.js in the near future, let's not initialize wiselinks for now. */
191 // window.wiselinks = new Wiselinks();
193 $(document).off('page:loading').on('page:loading', function(event, $target, render, url){
194 $("#page-wrapper").fadeOut(200);
197 $(document).off('page:redirected').on('page:redirected', function(event, $target, render, url){
200 $(document).off('page:always').on('page:always', function(event, xhr, settings){
201 $("#page-wrapper").fadeIn(200);
204 $(document).off('page:done').on('page:done', function(event, $target, status, url, data){
207 $(document).off('page:fail').on('page:fail', function(event, $target, status, url, error, code){
211 $(document).on('click', '.compute-detail', function(e) {
212 $(e.target).collapse('hide');
215 $(document).on('click', '.compute-node-summary', function(e) {
216 $(e.target.href).collapse('toggle');
219 $(document).on('click', '.force-cache-reload', function(e) {
220 history.replaceState( { nocache: true }, '' );
224 window.addEventListener("DOMContentLoaded", function(e) {
226 if(history.state.nocache) {
228 history.replaceState( {}, '' );
229 location.reload(true);
234 function showLoadingModal() {
235 $('#loading-modal').modal('show');
238 function hideLoadingModal() {
239 $('#loading-modal').modal('hide');
242 function hasHTML5History() {
243 return !!(window.history && window.history.pushState);