Project

General

Profile

Download (8.43 KB) Statistics
| Branch: | Tag: | Revision:
01984fb7 Amos Benari
$(function() {
05ab4c16 Ohad Levy
$('.flash.error').hide().each(function(index, item) {
82e47ae0 Amos Benari
if ($('.alert-message.alert-error.base').length == 0) {
334d0359 Amos Benari
if ($('#host-conflicts-modal').length == 0) {
30ae12bf Ohad Levy
$.jnotify($(item).text(), { type: "error", sticky: true });
}
53a78d40 Ohad Levy
}
});

05ab4c16 Ohad Levy
$('.flash.warning').hide().each(function(index, item) {
53a78d40 Ohad Levy
$.jnotify($(item).text(), { type: "warning", sticky: true });
});

05ab4c16 Ohad Levy
$('.flash.notice').hide().each(function(index, item) {
53a78d40 Ohad Levy
$.jnotify($(item).text(), { type: "success", sticky: false });
});
01984fb7 Amos Benari
});

fa7070ca Ohad Levy
function remove_fields(link) {
8ba2e00a Ohad Levy
$(link).prev("input[type=hidden]").val("1");
$(link).closest(".fields").hide();
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");
8ba2e00a Ohad Levy
$(link).parent().before(content.replace(regexp, new_id));
}

function checkAll (id, checked) {
82e47ae0 Amos Benari
$(id).attr('checked',checked);
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
// allow opening new window for selected links
$(function() {
$('a[rel="external"]').click( function() {
window.open( $(this).attr('href') );
return false;
});
});
69f9cb82 Ohad Levy
function template_info(div, url) {
os_id = $("#host_operatingsystem_id :selected").attr("value");
env_id = $("#host_environment_id :selected").attr("value");
hostgroup_id = $("#host_hostgroup_id :selected").attr("value");

$(div).html('<img src="/images/spinner.gif" alt="Wait" />');
68c19214 Ohad Levy
$(div).load(url + "?operatingsystem_id=" + os_id + "&hostgroup_id=" + hostgroup_id + "&environment_id=" + env_id,
b7cb4996 Ohad Levy
function(response, status, xhr) {
if (status == "error") {
dec6f148 Amos Benari
$(div).html("<div class='alert alert-warning'><a class='close' data-di smiss='alert'>&times;</a><p>Sorry but no templates were configured.</p></div>");
b7cb4996 Ohad Levy
}
});
69f9cb82 Ohad Levy
}
b7cb4996 Ohad Levy
52e114a6 Ohad Levy
$(document).ready(function() {
var common_settings = {
method : 'PUT',
indicator : "<img src='../images/spinner.gif' />",
tooltip : 'Click to edit..',
placeholder : 'Click to edit..',
submitdata : {authenticity_token: AUTH_TOKEN, format : "json"},
df886c98 Ohad Levy
onedit : function(data) { $(this).removeClass("editable"); },
callback : function(value, settings) { $(this).addClass("editable"); },
52e114a6 Ohad Levy
onsuccess : function(data) {
var parsed = $.parseJSON(data);
3c673e9e Ohad Levy
var key = $(this).attr('name').split("[")[0];
5d8d8a6e Ohad Levy
var val = $(this).attr('data-field');
$(this).html(String(parsed[key][val]));
52e114a6 Ohad Levy
},
onerror : function(settings, original, xhr) {
original.reset();
3c673e9e Ohad Levy
var error = $.parseJSON(xhr.responseText)["errors"];
52e114a6 Ohad Levy
$.jnotify(error, { type: "error", sticky: true });
}
};

$('.edit_textfield').each(function() {
var settings = {
type : 'text',
name : $(this).attr('name'),
d6b486f8 Amos Benari
width: '95%'
52e114a6 Ohad Levy
};
$(this).editable($(this).attr('data-url'), $.extend(common_settings, settings));
});

$('.edit_textarea').each(function() {
var settings = {
type : 'textarea',
name : $(this).attr('name'),
rows : 8,
cols : 36
};
$(this).editable($(this).attr('data-url'), $.extend(common_settings, settings));
});

5d8d8a6e Ohad Levy
$('.edit_select').each(function() {
var settings = {
type : 'select',
name : $(this).attr('name'),
data : $(this).attr('select_values'),
d6b486f8 Amos Benari
submit : 'Save'
5d8d8a6e Ohad Levy
};
$(this).editable($(this).attr('data-url'), $.extend(common_settings, settings));
});
});
05ab4c16 Ohad Levy
// adds buttons classes to all links
$(function(){
$("#title_action a").addClass("btn");
82e47ae0 Amos Benari
$("#title_action a[href*='new']").addClass("btn-success");
$('.delete').parent('td').children('a').addClass('btn');
05ab4c16 Ohad Levy
});

b7cb4996 Ohad Levy
$(function() {
60e9b0c1 Ohad Levy
if ($("#login-form").size() > 0) {
$("#login_login").focus();
$(".logo, .logo-text").hide();
return false;
}

05ab4c16 Ohad Levy
magic_line("#menu" , 1);
magic_line("#menu2", 0);
82e47ae0 Amos Benari
$('.dropdown-toggle').dropdown();
$('.auto_complete_input').addClass ('search-query');
$('.auto_complete_clear').addClass ('icon-remove');
05ab4c16 Ohad Levy
});

function magic_line(id, combo) {
b7cb4996 Ohad Levy
var $el, leftPos, newWidth, $mainNav = $(id);

$mainNav.append("<li class='magic-line'></li>");
var $magicLine = $(id + " .magic-line");
82e47ae0 Amos Benari
if ($('[data-toggle=collapse]:visible').length > 0){
$magicLine.hide();
}else{$magicLine.show();}
b7cb4996 Ohad Levy
if ( $(".active").size() > 0){
$magicLine
.width($(id +" .active").width() + $(id + " .active.dropdown").width() * combo)
.css("left", $(".active").position().left)
.data("origLeft", $magicLine.position().left)
.data("origWidth", $magicLine.width());
} else {
$magicLine.width(0).css("left", 0)
.data("origLeft", $magicLine.position().left)
.data("origWidth", $magicLine.width());
}
$(id + " li").hover(function() {
82e47ae0 Amos Benari
if ($('[data-toggle=collapse]:visible').length > 0){
$magicLine.hide();
return;
}
$magicLine.show();
b7cb4996 Ohad Levy
$el = $(this);
if ($el.parent().hasClass("dropdown-menu")){
$el=$el.parent().parent();
}
leftPos = $el.position().left;
newWidth = $el.width();
if ($el.find("a").hasClass("narrow-right")){
newWidth = newWidth + $(".dropdown").width() * combo;
20b08bc9 Amos Benari
}
b7cb4996 Ohad Levy
$magicLine.stop().animate({
left: leftPos,
width: newWidth
05ab4c16 Ohad Levy
});
b7cb4996 Ohad Levy
}, function() {
82e47ae0 Amos Benari
if ($('[data-toggle=collapse]:visible').length > 0){
$magicLine.hide();
}else{
$magicLine.stop().animate({
left: $magicLine.data("origLeft"),
width: $magicLine.data("origWidth")
});
}
b7cb4996 Ohad Levy
});
05ab4c16 Ohad Levy
}

//add bookmark dialog
b7cb4996 Ohad Levy
$(function() {
82e47ae0 Amos Benari
$('#bookmarks-modal .btn-primary').click(function(){
05ab4c16 Ohad Levy
$("#bookmark_submit").click();
});
$("#bookmarks-modal").bind('shown', function () {
var query = encodeURI($("#search").val());
82e47ae0 Amos Benari
var url = $("#bookmark").attr('data-url');
$("#bookmarks-modal .modal-body").empty();
05ab4c16 Ohad Levy
$("#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
ff8e0364 Ohad Levy
13c2409d Ohad Levy
// highlight tabs with errors
$(function(){
82e47ae0 Amos Benari
$(".tab-content").find(".control-group.error").each(function() {
13c2409d Ohad Levy
// find each tab id
da6fa387 Ohad Levy
var id = $(this).parentsUntil(".tab-content").last().attr("id");
13c2409d Ohad Levy
// now add a class to that tab
82e47ae0 Amos Benari
$("a[href=#"+id+"]").addClass("tab-error");
13c2409d Ohad Levy
})
});
2b54d6ef Ohad Levy
$(function () {
82e47ae0 Amos Benari
$('a[rel="popover"]').popover();
$('[rel="twipsy"]').tooltip();
2b54d6ef Ohad Levy
});
56baba5c Amos Benari
82e47ae0 Amos Benari
function filter_by_level(item){
var level = $(item).val();

56baba5c Amos Benari
if(level == 'notice'){
82e47ae0 Amos Benari
$('.label-info').closest('tr').show();
$('.label-warning').closest('tr').show();
$('.label-important').closest('tr').show();
56baba5c Amos Benari
}
if(level == 'warning'){
82e47ae0 Amos Benari
$('.label-info').closest('tr').hide();
$('.label-warning').closest('tr').show();
$('.label-important').closest('tr').show();
56baba5c Amos Benari
}
if(level == 'error'){
82e47ae0 Amos Benari
$('.label-info ').closest('tr').hide();
$('.label-warning').closest('tr').hide();
$('.label-important').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(){
var auth_source_id = $('#user_auth_source_id').attr('value');
if (auth_source_id == '') return false;
$.ajax({
type:'get',
url:'/users/auth_source_selected',
data:'auth_source_id=' + auth_source_id
})
}
function show_release(element){
var os_family = $(element).val();
if (os_family == 'Debian' || os_family == 'Solaris') {
$("#release_name").show('highlight', 1000);
} 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++) {
var attr = $('*[id*='+attributes[i]+']');
if (attr.size() > 0) { attrs[attributes[i]] = attr.val(); }
}
return attrs;
}