function computeResourceSelected(item){ var compute = $(item).val(); var attrs = attribute_hash(['architecture_id', 'compute_resource_id', 'operatingsystem_id']); if(compute=='') { //Bare Metal $('#mac_address').show(); $("#model_name").show(); $('#compute_resource').empty(); $('#vm_details').empty(); $("#compute_resource_tab").hide(); update_capabilities('build'); } else { $('#mac_address').hide(); $("#model_name").hide(); $("#compute_resource_tab").show(); $('#vm_details').empty(); var url = $(item).attr('data-url'); $.ajax({ type:'post', url: url, data: attrs, success: function(result){ $('#compute_resource').html(result); update_capabilities($('#capabilities').val()); } }) } } function update_capabilities(capabilities){ var build = (/build/i.test(capabilities)); var image = (/image/i.test(capabilities)); if (build){ $('#manage_network').show(); $('#host_provision_method_build').click(); } else { $('#manage_network').hide(); $('#host_provision_method_image').click(); } if(build && image){ $('#provisioning_method').show(); }else{ $('#provisioning_method').hide(); } $('#image_provisioning').empty(); $('#image_selection').appendTo($('#image_provisioning')); update_provisioning_image(); } var stop_pooling; function submit_host(form){ var url = window.location.pathname.replace(/\/edit$|\/new$/,''); if(/\/clone$/.test(window.location.pathname)){ url = foreman_url('/hosts'); } $('#host_submit').attr('disabled', true); stop_pooling = false; $("body").css("cursor", "progress"); clear_errors(); animate_progress(); $.ajax({ type:'POST', url: url, data: form.serialize(), success: function(response){ if(response.redirect){ window.location.replace(response.redirect); } else{ $("#host-progress").hide(); $('#content').replaceWith($("#content", response)); onContentLoad(); onHostEditLoad(); } }, error: function(response){ $('#content').html(response.responseText); }, complete: function(){ stop_pooling = true; $("body").css("cursor", "auto"); $('#host_submit').attr('disabled', false); } }); return false; } function clear_errors(){ $('.error').children().children('.help-inline').remove(); $('.error').removeClass('error'); $('.tab-error').removeClass('tab-error'); $('.alert-error').remove(); } function animate_progress(){ if (stop_pooling == true) return; setTimeout(function() { var task_id = $('#host_progress_report_id').val(); $.get('/tasks/' + task_id, function (response){ update_progress(response); animate_progress(); }) }, 1600); } function update_progress(data){ var task_list_size = $('p',data).size(); if (task_list_size == 0 || stop_pooling == true) return; var done_tasks = $('.icon-check',data).size(); var failed_tasks = $('.icon-remove',data).size(); var $progress = $('.progress'); $("#host-progress").show(); if(failed_tasks > 0) { $progress.removeClass('progress-success').addClass('progress-danger'); }else{ $progress.removeClass('progress-danger').addClass('progress-success'); } $('.bar').width(done_tasks/task_list_size *$progress.width()); $('#tasks_progress').replaceWith(data); } function filter_puppet_classes(item){ var term = $(item).val().trim(); $('.puppetclass_group li.puppetclass.hide').addClass('hide-me'); if (term.length > 0) { $('.puppetclass_group li.puppetclass').removeClass('filter-marker').hide(); $('.puppetclass_group li.puppetclass:not(.hide-me, .selected-marker) span:contains('+term+')').parent('li').addClass('filter-marker').show(); } else{ $('.puppetclass_group li.puppetclass:not(.hide-me, .selected-marker)').addClass('filter-marker').show(); } var groups = $('li.filter-marker').closest('.puppetclass_group'); $('.puppetclass_group').hide(); groups.show(); } function add_puppet_class(item){ var id = $(item).attr('data-class-id'); var type = $(item).attr('data-type'); $(item).tooltip('hide'); var content = $(item).parent().clone(); content.attr('id', 'selected_puppetclass_'+ id); content.append(""); content.children('span').tooltip(); var link = content.children('a'); link.attr('onclick', 'remove_puppet_class(this)'); link.attr('data-original-title', 'Click to undo adding this class'); link.removeClass('icon-plus-sign').addClass('icon-remove-sign').tooltip(); $('#selected_classes').append(content); $("#selected_puppetclass_"+ id).show('highlight', 5000); $("#puppetclass_"+ id).addClass('selected-marker').hide(); load_puppet_class_parameters(link); } function remove_puppet_class(item){ var id = $(item).attr('data-class-id'); $('#puppetclass_' + id).removeClass('selected-marker').show(); $('#puppetclass_' + id).closest('.puppetclass_group').show(); $('#selected_puppetclass_' + id).children('a').tooltip('hide'); $('#selected_puppetclass_' + id).remove(); $('#puppetclass_' + id + '_params_loading').remove(); $('[id^="puppetclass_' + id + '_params\\["]').remove(); $('#params-tab').removeClass("tab-error"); if ($("#params").find('.control-group.error').length > 0) $('#params-tab').addClass('tab-error'); return false; } function load_puppet_class_parameters(item) { var id = $(item).attr('data-class-id'); var host_id = $("form").data('id') if ($('#puppetclass_' + id + '_params_loading').length > 0) return; // already loading if ($('[id^="#puppetclass_' + id + '_params\\["]').length > 0) return; // already loaded var url = $(item).attr('data-url'); var data = $("form").serialize().replace('method=put', 'method=post'); data = data + '&host_id=' + host_id if (url == undefined) return; // no parameters var placeholder = $(''+ '

Wait Loading parameters...

'+''); $('#inherited_puppetclasses_parameters').append(placeholder); $.ajax({ url: url, type: 'post', data: data, success: function(result, textstatus, xhr) { var params = $(result); placeholder.replaceWith(params); params.find('a[rel="popover"]').popover(); if (params.find('.error').length > 0) $('#params-tab').addClass('tab-error'); } }); } function hostgroup_changed(element) { var host_id = $("form").data('id') if (!host_id){ // a new host update_form(element); } else { // edit host update_puppetclasses(element); reload_host_params(); } } function organization_changed(element) { update_form(element); } function location_changed(element) { update_form(element); } function update_form(element) { var url = $(element).data('url'); var data = $('form').serialize().replace('method=put', 'method=post'); var indicator = $(element).parent().find('img'); indicator.show(); $.ajax({ type: 'post', url: url, data: data, success: function(response) { $('form').html(response); $("[id$='subnet_id']").first().change(); onContentLoad(); }, complete: function(){ indicator.hide(); } }) } function subnet_selected(element){ var subnet_id = $(element).val(); if (subnet_id == '' || $('#host_ip').size() == 0) return; // We do not query the proxy if the host_ip field is filled in and contains an // IP that is in the selected subnet var drop_text = $(element).children(":selected").text(); if (drop_text.length !=0 && drop_text.search(/^.+ \([0-9\.\/]+\)/) != -1) { var details = drop_text.replace(/^.+\(/, "").replace(")","").split("/"); if (subnet_contains(details[0], details[1], $('#host_ip').val())) return; } var attrs = attribute_hash(["subnet_id", "host_mac", 'organization_id', 'location_id']); $('#subnet_indicator').show(); var url = $(element).data('url'); $.ajax({ data: attrs, type:'post', url: url, complete: function(){$('#subnet_indicator').hide()}, success: function(data){ $('#host_ip').val(data.ip); } }) } function subnet_contains(number, cidr, ip){ var int_ip = _to_int(ip); var int_number = _to_int(number); var shift = 32 - parseInt(cidr); return (int_ip >> shift == int_number >> shift); } function _to_int(str){ var nibble = str.split("."); var integer = 0; for(var i=0;i<=3;i++){ integer = (integer * 256) + parseInt(nibble[i]); } return integer; } function domain_selected(element){ var attrs = attribute_hash(['domain_id', 'organization_id', 'location_id']); var url = $(element).data('url'); $('#domain_indicator').show(); $.ajax({ data: attrs, type:'post', url: url, complete: function(){$('#domain_indicator').hide()}, success: function(request) { $('#subnet_select').html(request); reload_host_params(); } }) } function architecture_selected(element){ var attrs = attribute_hash(['architecture_id', 'organization_id', 'location_id']); var url = $(element).attr('data-url'); $.ajax({ data: attrs, type:'post', url: url, success: function(request) { $('#os_select').html(request); } }) } function os_selected(element){ var attrs = attribute_hash(['operatingsystem_id', 'organization_id', 'location_id']); var url = $(element).attr('data-url'); $.ajax({ data: attrs, type:'post', url: url, success: function(request) { $('#media_select').html(request); reload_host_params(); } }); update_provisioning_image(); } function update_provisioning_image(){ var compute_id = $('[id$="_compute_resource_id"]').val(); var arch_id = $('[id$="_architecture_id"]').val(); var os_id = $('[id$="_operatingsystem_id"]').val(); if((compute_id == undefined) || (compute_id == "") || (arch_id == "") || (os_id == "")) return; var term = 'operatingsystem=' + os_id + ' architecture=' + arch_id; var image_options = $("[id$=compute_attributes_image_id]").empty(); $.ajax({ data:'search=' + encodeURIComponent(term), type:'get', url: foreman_url('/compute_resources/'+compute_id+'/images'), dataType: 'json', success: function(result) { $.each(result, function() { image_options.append($("