foreman/app/assets/javascripts/application.js @ a79bc7ab
feacea35 | Amos Benari | //= require jquery
|
|
3dfb6e4c | Dominic Cleal | //= require i18n
|
|
feacea35 | Amos Benari | //= require jquery_ujs
|
|
//= require jquery.ui.autocomplete
|
|||
//= require scoped_search
|
|||
d31eea8c | Amos Benari | //= require bootstrap
|
|
8285778b | Joseph Magen | //= require multi-select
|
|
feacea35 | Amos Benari | //= require charts
|
|
dfd511ba | Amos Benari | //= require topbar
|
|
f60942c6 | Amos Benari | //= require two-pane
|
|
feacea35 | Amos Benari | //= require vendor
|
|
8b80115c | Amos Benari | //= require about
|
|
e3a220be | Amos Benari | //= require jquery.extentions
|
|
8285778b | Joseph Magen | //= require jquery.multi-select
|
|
d31eea8c | Amos Benari | //= require settings
|
|
1e1b2f13 | Ohad Levy | ||
$(document).on('ContentLoad', function(){onContentLoad()});
|
|||
01984fb7 | Amos Benari | $(function() {
|
|
1e1b2f13 | Ohad Levy | $(document.body).trigger('ContentLoad');
|
|
dd42df0a | Ohad Levy | });
|
|
function onContentLoad(){
|
|||
f60942c6 | Amos Benari | if($('.autocomplete-clear').size() == 0){
|
|
$('.autocomplete-input').scopedSearch();
|
|||
bf4a13d3 | Walden Raines | $('.ui-helper-hidden-accessible').remove();
|
|
f60942c6 | Amos Benari | }
|
|
feacea35 | Amos Benari | ||
ad4ab250 | Ohad Levy | $('.flash.error').each(function(index, item) {
|
|
ede5687c | Ohad Levy | if ($('.alert.alert-danger.base').length == 0) {
|
|
dd42df0a | Ohad Levy | if ($('#host-conflicts-modal').length == 0) {
|
|
93498295 | Ohad Levy | notify(item, 'error');
|
|
dd42df0a | Ohad Levy | }
|
|
}
|
|||
});
|
|||
ad4ab250 | Ohad Levy | $('.flash.warning').each(function(index, item) {
|
|
93498295 | Ohad Levy | notify(item, 'warning');
|
|
dd42df0a | Ohad Levy | });
|
|
ad4ab250 | Ohad Levy | $('.flash.notice').each(function(index, item) {
|
|
93498295 | Ohad Levy | notify(item, 'success');
|
|
dd42df0a | Ohad Levy | });
|
|
// adds buttons classes to all links
|
|||
bf4a13d3 | Walden Raines | $("#title_action a").addClass("btn btn-default");
|
|
$("#title_action li a").removeClass("btn btn-default").addClass("la");
|
|||
$("#title_action span").removeClass("btn btn-default").addClass("btn-group");
|
|||
$("#title_action a[href*='new']").removeClass('btn-default').addClass("btn-success");
|
|||
53a78d40 | Ohad Levy | ||
dfd511ba | Amos Benari | if ($("#login-form").size() > 0) {
|
|
$("#login_login").focus();
|
|||
return false;
|
|||
}
|
|||
dd42df0a | Ohad Levy | // highlight tabs with errors
|
|
ede5687c | Ohad Levy | $(".tab-content").find(".form-group.has-error").each(function() {
|
|
dd42df0a | Ohad Levy | var id = $(this).parentsUntil(".tab-content").last().attr("id");
|
|
$("a[href=#"+id+"]").addClass("tab-error");
|
|||
})
|
|||
//set the tooltips
|
|||
e62f5a26 | Amos Benari | $('a[rel="popover"]').popover({html: true});
|
|
dd42df0a | Ohad Levy | $('[rel="twipsy"]').tooltip();
|
|
3630239a | Ohad Levy | $('*[title]').not('*[rel]').tooltip();
|
|
6b7b2fa2 | Ohad Levy | $('[data-table=inline]').not('.dataTable').dataTable(
|
|
{
|
|||
bf4a13d3 | Walden Raines | "sDom": "<'row'<'col-md-6'f>r>t<'row'<'col-md-6'i><'col-md-6'p>>",
|
|
6b7b2fa2 | Ohad Levy | "sPaginationType": "bootstrap"
|
|
}
|
|||
);
|
|||
397a5481 | Sam Kottler | ||
// Prevents all links with the disabled attribute set to "disabled"
|
|||
// from being clicked.
|
|||
$('a[disabled="disabled"]').click(function() {
|
|||
return false;
|
|||
});
|
|||
ba946542 | Amos Benari | ||
1e1b2f13 | Ohad Levy | // allow opening new window for selected links
|
|
$('a[rel="external"]').click( function() {
|
|||
window.open( $(this).attr('href') );
|
|||
return false;
|
|||
});
|
|||
a79bc7ab | Amos Benari | $('*[data-ajax-url]').each(function() {
|
|
var url = $(this).data('ajax-url');
|
|||
$(this).load(url, function(response, status, xhr) {
|
|||
if (status == "error") {
|
|||
$(this).closest(".tab-content").find("#spinner").html(__('Failed to fetch: ') + xhr.status + " " + xhr.statusText);
|
|||
}
|
|||
if ($(this).data('on-complete')){
|
|||
window[$(this).data('on-complete')].call(null, this, status);
|
|||
}
|
|||
});
|
|||
});
|
|||
ba946542 | Amos Benari | multiSelectOnLoad();
|
|
dd42df0a | Ohad Levy | }
|
|
53a78d40 | Ohad Levy | ||
fa7070ca | Ohad Levy | function remove_fields(link) {
|
|
8ba2e00a | Ohad Levy | $(link).prev("input[type=hidden]").val("1");
|
|
$(link).closest(".fields").hide();
|
|||
995b1748 | Amos Benari | mark_params_override();
|
|
}
|
|||
function mark_params_override(){
|
|||
$('#inherited_parameters .override-param').removeClass('override-param');
|
|||
$('#inherited_parameters span').show();
|
|||
$('#parameters').find('[id$=_name]:visible').each(function(){
|
|||
var param_name = $(this);
|
|||
$('#inherited_parameters').find('[id^=name_]').each(function(){
|
|||
298756ca | Amos Benari | if (param_name.val() == $(this).text()){
|
|
995b1748 | Amos Benari | $(this).addClass('override-param');
|
|
298756ca | Amos Benari | $(this).closest('tr').find('textarea').addClass('override-param')
|
|
$(this).closest('tr').find('[data-tag=override]').hide();
|
|||
995b1748 | Amos Benari | }
|
|
})
|
|||
})
|
|||
298756ca | Amos Benari | $('#inherited_puppetclasses_parameters .override-param').removeClass('override-param');
|
|
$('#inherited_puppetclasses_parameters [data-tag=override]').show();
|
|||
$('#puppetclasses_parameters').find('[data-property=class]:visible').each(function(){
|
|||
var klass = $(this).val();
|
|||
var name = $(this).siblings('[data-property=name]').val();
|
|||
$('#inherited_puppetclasses_parameters [id^="puppetclass_"][id*="_params\\["][id$="\\]"]').each(function(){
|
|||
var param = $(this);
|
|||
if (param.find('[data-property=class]').text() == klass && param.find('[data-property=name]').text() == name) {
|
|||
param.find('.error').removeClass('error');
|
|||
param.find('.warning').removeClass('warning');
|
|||
param.addClass('override-param');
|
|||
param.find('input, textarea').addClass('override-param');
|
|||
param.find('[data-tag=override]').hide();
|
|||
}
|
|||
});
|
|||
});
|
|||
$('#params-tab').removeClass("tab-error");
|
|||
bf4a13d3 | Walden Raines | if ($("#params").find('.form-group.error').length > 0) $('#params-tab').addClass('tab-error');
|
|
e62f5a26 | Amos Benari | $('a[rel="popover"]').popover({html: true});
|
|
fa7070ca | Ohad Levy | }
|
|
function add_fields(link, association, content) {
|
|||
var new_id = new Date().getTime();
|
|||
9afa092e | Ohad Levy | var regexp = new RegExp("new_" + association, "g");
|
|
995b1748 | Amos Benari | $(link).before(content.replace(regexp, new_id));
|
|
8ba2e00a | Ohad Levy | }
|
|
feacea35 | Amos Benari | $(document).ready(function() {
|
|
$("#check_all_roles").click(function(e) {
|
|||
e.preventDefault();
|
|||
$(".role_checkbox").prop('checked', true);
|
|||
});
|
|||
$("#uncheck_all_roles").click(function(e) {
|
|||
e.preventDefault();
|
|||
$(".role_checkbox").prop('checked', false);
|
|||
});
|
|||
});
|
|||
8ba2e00a | Ohad Levy | ||
function toggleCheckboxesBySelector(selector) {
|
|||
boxes = $(selector);
|
|||
var all_checked = true;
|
|||
3c673e9e | Ohad Levy | for (i = 0; i < boxes.length; i++) { if (!boxes[i].checked) { all_checked = false; } }
|
|
8ba2e00a | Ohad Levy | for (i = 0; i < boxes.length; i++) { boxes[i].checked = !all_checked; }
|
|
}
|
|||
function toggleRowGroup(el) {
|
|||
var tr = $(el).closest('tr');
|
|||
var n = tr.next();
|
|||
tr.toggleClass('open');
|
|||
82e47ae0 | Amos Benari | while (n.length > 0 && !n.hasClass('group')) {
|
|
8ba2e00a | Ohad Levy | n.toggle();
|
|
n = n.next();
|
|||
}
|
|||
fa7070ca | Ohad Levy | }
|
|
2ef88134 | Ohad Levy | ||
69f9cb82 | Ohad Levy | function template_info(div, url) {
|
|
99527500 | Jimmi Dyson | // Ignore method as PUT redirects to host page if used on update
|
|
form = $("form :input[name!='_method']").serialize();
|
|||
be162e11 | Amos Benari | build = $('input:radio[name$="[provision_method]"]:checked').val();
|
|
69f9cb82 | Ohad Levy | ||
1546388e | Amos Benari | $(div).html(spinner_placeholder());
|
|
99527500 | Jimmi Dyson | ||
// Use a post to avoid request URI too large issues with big forms
|
|||
$.ajax({
|
|||
type: "POST",
|
|||
url: url + "?provisioning=" + build,
|
|||
data: form,
|
|||
success: function(response, status, xhr) {
|
|||
$(div).html(response);
|
|||
},
|
|||
error: function(jqXHR, textStatus, errorThrown) {
|
|||
$(div).html('<div class="alert alert-warning alert-dismissable">' +
|
|||
'<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>' +
|
|||
__('Sorry but no templates were configured.') + '</div>');
|
|||
}
|
|||
});
|
|||
69f9cb82 | Ohad Levy | }
|
|
b7cb4996 | Ohad Levy | ||
05ab4c16 | Ohad Levy | //add bookmark dialog
|
|
b7cb4996 | Ohad Levy | $(function() {
|
|
56469be7 | Joseph Mitchell Magen | $('#bookmarks-modal .modal-footer .btn-primary').on('click', function(){
|
|
$('#bookmarks-modal .modal-body .btn-primary').click();
|
|||
05ab4c16 | Ohad Levy | });
|
|
bf4a13d3 | Walden Raines | $("#bookmarks-modal").bind('shown.bs.modal', function () {
|
|
05ab4c16 | Ohad Levy | var query = encodeURI($("#search").val());
|
|
82e47ae0 | Amos Benari | var url = $("#bookmark").attr('data-url');
|
|
$("#bookmarks-modal .modal-body").empty();
|
|||
ad01d4d2 | Walden Raines | $("#bookmarks-modal .modal-body").append("<span id='loading'>" + __('Loading ...') + "</span>");
|
|
82e47ae0 | Amos Benari | $("#bookmarks-modal .modal-body").load(url + '&query=' + query + ' form',
|
|
b7cb4996 | Ohad Levy | function(response, status, xhr) {
|
|
$("#loading").hide();
|
|||
$("#bookmarks-modal .modal-body .btn").hide()
|
|||
});
|
|||
05ab4c16 | Ohad Levy | });
|
|
});
|
|||
2b54d6ef | Ohad Levy | ||
82e47ae0 | Amos Benari | function filter_by_level(item){
|
|
var level = $(item).val();
|
|||
51a63dc9 | Michael Moll | // Note that class names don't map to log level names (label-info == notice)
|
|
if(level == 'info'){
|
|||
82e47ae0 | Amos Benari | $('.label-info').closest('tr').show();
|
|
94f61f7b | Ohad Levy | $('.label-default').closest('tr').show();
|
|
82e47ae0 | Amos Benari | $('.label-warning').closest('tr').show();
|
|
bf4a13d3 | Walden Raines | $('.label-danger').closest('tr').show();
|
|
56baba5c | Amos Benari | }
|
|
51a63dc9 | Michael Moll | if(level == 'notice'){
|
|
$('.label-info').closest('tr').show();
|
|||
$('.label-default').closest('tr').hide();
|
|||
$('.label-warning').closest('tr').show();
|
|||
5f45920e | Amos Benari | $('.label-danger').closest('tr').show();
|
|
51a63dc9 | Michael Moll | }
|
|
56baba5c | Amos Benari | if(level == 'warning'){
|
|
82e47ae0 | Amos Benari | $('.label-info').closest('tr').hide();
|
|
94f61f7b | Ohad Levy | $('.label-default').closest('tr').hide();
|
|
82e47ae0 | Amos Benari | $('.label-warning').closest('tr').show();
|
|
bf4a13d3 | Walden Raines | $('.label-danger').closest('tr').show();
|
|
56baba5c | Amos Benari | }
|
|
if(level == 'error'){
|
|||
94f61f7b | Ohad Levy | $('.label-info').closest('tr').hide();
|
|
$('.label-default').closest('tr').hide();
|
|||
82e47ae0 | Amos Benari | $('.label-warning').closest('tr').hide();
|
|
bf4a13d3 | Walden Raines | $('.label-danger').closest('tr').show();
|
|
56baba5c | Amos Benari | }
|
|
5f080138 | Ohad Levy | if($("#report_log tr:visible ").size() ==1 || $("#report_log tr:visible ").size() ==2 && $('#ntsh:visible').size() > 0 ){
|
|
56baba5c | Amos Benari | $('#ntsh').show();
|
|
}
|
|||
else{
|
|||
$('#ntsh').hide();
|
|||
}
|
|||
}
|
|||
017e1049 | Ohad Levy | ||
function auth_source_selected(){
|
|||
feacea35 | Amos Benari | var auth_source_id = $('#user_auth_source_id').val();
|
|
if (auth_source_id == '') {
|
|||
$("#password").hide();
|
|||
} else {
|
|||
$("#password").show();
|
|||
}
|
|||
017e1049 | Ohad Levy | }
|
|
feacea35 | Amos Benari | ||
017e1049 | Ohad Levy | function show_release(element){
|
|
var os_family = $(element).val();
|
|||
if (os_family == 'Debian' || os_family == 'Solaris') {
|
|||
a1a46f7d | Ohad Levy | $("#release_name").show();
|
|
017e1049 | Ohad Levy | } else {
|
|
$("#release_name").hide();
|
|||
}
|
|||
}
|
|||
7e031001 | Ohad Levy | // return a hash with values of all attributes
|
|
function attribute_hash(attributes){
|
|||
var attrs = {};
|
|||
for (i=0;i < attributes.length; i++) {
|
|||
01122c8b | Joseph Mitchell Magen | var attr = $('*[id$='+attributes[i]+']');
|
|
1f1367d6 | Amos Benari | if (attr.size() > 0) {
|
|
if(attr.attr("type")=="checkbox"){
|
|||
attrs[attributes[i]] = [];
|
|||
$("*[id*="+attributes[i]+"]:checked").each(function(index,item){
|
|||
attrs[attributes[i]].push($(item).val());
|
|||
})
|
|||
}else{
|
|||
04157eed | Amos Benari | if (attr.val() != null) attrs[attributes[i]] = attr.val();
|
|
1f1367d6 | Amos Benari | }
|
|
}
|
|||
7e031001 | Ohad Levy | }
|
|
return attrs;
|
|||
}
|
|||
1b3cbe60 | Amos Benari | ||
function ignore_subnet(item){
|
|||
$(item).tooltip('hide');
|
|||
$(item).closest('.accordion-group').remove();
|
|||
}
|
|||
function show_rdoc(item){
|
|||
var url = $(item).attr('data-url');
|
|||
window.open(url);
|
|||
67905725 | Ohad Levy | }
|
|
// shows provisioning templates in a new window
|
|||
$(function() {
|
|||
$('[data-provisioning-template=true]').click(function(){
|
|||
window.open(this.href, [width='300',height='400',scrollbars='yes']);
|
|||
return false;
|
|||
});
|
|||
});
|
|||
298756ca | Amos Benari | ||
8f34dc60 | Ohad Levy | function update_puppetclasses(element) {
|
|
8bfaec2a | Joseph Mitchell Magen | var host_id = $("form").data('id')
|
|
feacea35 | Amos Benari | var env_id = $('*[id*=environment_id]').val();
|
|
8f34dc60 | Ohad Levy | var url = $(element).attr('data-url');
|
|
8bfaec2a | Joseph Mitchell Magen | var data = $("form").serialize().replace('method=put', 'method=post');
|
|
data = data + '&host_id=' + host_id
|
|||
8f34dc60 | Ohad Levy | if (env_id == "") return;
|
|
5d6ab0b1 | Amos Benari | $(element).indicator_show();
|
|
8f34dc60 | Ohad Levy | $.ajax({
|
|
type: 'post',
|
|||
url: url,
|
|||
8bfaec2a | Joseph Mitchell Magen | data: data,
|
|
8f34dc60 | Ohad Levy | success: function(request) {
|
|
$('#puppet_klasses').html(request);
|
|||
8bfaec2a | Joseph Mitchell Magen | reload_puppetclass_params();
|
|
feacea35 | Amos Benari | $('[rel="twipsy"]').tooltip();
|
|
8f34dc60 | Ohad Levy | },
|
|
complete: function() {
|
|||
5d6ab0b1 | Amos Benari | $(element).indicator_hide();
|
|
8f34dc60 | Ohad Levy | }
|
|
})
|
|||
}
|
|||
5f75d98a | Ivan Necas | ||
// generates an absolute, needed in case of running Foreman from a subpath
|
|||
function foreman_url(path) {
|
|||
return URL_PREFIX + path;
|
|||
}
|
|||
40df7dfb | Daniel Lobato | ||
89b9ecb0 | Amos Benari | $.fn.indicator_show = function(){
|
|
5d6ab0b1 | Amos Benari | $(this).parents('.form-group').find('img').show();
|
|
89b9ecb0 | Amos Benari | }
|
|
$.fn.indicator_hide = function(){
|
|||
5d6ab0b1 | Amos Benari | $(this).parents('.form-group').find('img').hide();
|
|
89b9ecb0 | Amos Benari | }
|
|
1546388e | Amos Benari | ||
function spinner_placeholder(text){
|
|||
if (text == undefined) text = "";
|
|||
return "<div class='spinner-placeholder'>" + text + "</div>"
|
|||
}
|
|||
93498295 | Ohad Levy | ||
function notify(item, type) {
|
|||
var options = { type: type, sticky: (type != 'success') };
|
|||
$.jnotify($(item).text(), options);
|
|||
$(item).remove();
|
|||
}
|
|||
e3a220be | Amos Benari | ||
function filter_permissions(item){
|
|||
var term = $(item).val().trim();
|
|||
if (term.length > 0) {
|
|||
bf4a13d3 | Walden Raines | $(".form-group .collapse").parents('.form-group').hide();
|
|
$(".form-group .control-label:icontains('"+term+"')").parents('.form-group').show();
|
|||
e3a220be | Amos Benari | } else{
|
|
bf4a13d3 | Walden Raines | $(".form-group .collapse").parents('.form-group').show();
|
|
e3a220be | Amos Benari | }
|
|
}
|
|||
bf4a13d3 | Walden Raines | ||
88ed4900 | Amos Benari | function setPowerState(item, status){
|
|
if(status=='success') {
|
|||
var place_holder = $('#loading_power_state').parent('.btn-group');
|
|||
var power_actions = $('#power_actions');
|
|||
power_actions.find('.btn-sm').removeClass('btn-sm');
|
|||
if (power_actions.find('.btn-group').exists()){
|
|||
power_actions.contents().replaceAll(place_holder);
|
|||
}else{
|
|||
power_actions.contents().appendTo(place_holder);
|
|||
$('#loading_power_state').remove();
|
|||
}
|
|||
}else{
|
|||
$('#loading_power_state').text(_('Unknown power state'))
|
|||
}
|
|||
$('[rel="twipsy"]').tooltip();
|
|||
bf4a13d3 | Walden Raines | }
|