<%= form_for @simple_plan, :url => {:action => :create_simple_plan}, :html => {:class => 'form-horizontal'} do |f| %>
<%= f.hidden_field_tag(:id, @tenant.id) %>
<% end %>
<%= form_tag({:action => :upload_catalog}, :method => 'post', :multipart => true, :class => 'form-horizontal') do %>
<%= hidden_field_tag(:id, @tenant.id) %>
<% end %>
<%= javascript_tag do %>
function known_products() {
var result = [];
var selected_category = $("#simple_plan_product_category option:selected" ).text();
if (selected_category == 'Base') {
result = $('#simple_plan_product_name').attr('known_base');
} else if (selected_category == 'Add_on') {
result = $('#simple_plan_product_name').attr('known_ao');
} else {
result = $('#simple_plan_product_name').attr('known_std');
}
return result.split(",");
}
function switch_xml_config() {
$('#catalog_simple').hide();
$('#catalog_xml').show();
}
function recompute_available_base_products_for_ao() {
if ($("#simple_plan_product_category option:selected" ).text() != 'Add_on') {
return;
}
var product_name = $('#simple_plan_product_name').val();
var ao_mappings_str = $('#simple_plan_product_name').attr('ao_mappings');
if (ao_mappings_str != "") {
var ao_mappings = {};
$.map(ao_mappings_str.split(";"), function(el) { sel = el.split(':'); ao_mappings[sel[0]] = sel[1].split(',') });
if (ao_mappings[product_name] != undefined) {
$('#simple_plan_available_base_products').val(ao_mappings[product_name]);
return;
}
}
/* Unless we found a mapping to update, we clear the existing mapping */
$('#simple_plan_available_base_products').val([]);
}
function display_available_base_products_for_ao() {
/* Reset prodcut name value; known_products from auto completion will also be updated accordingly */
$('#simple_plan_product_name').val('');
if ($("#simple_plan_product_category option:selected" ).text() == 'Add_on') {
$('#form_base_products').show();
} else {
$('#form_base_products').hide();
}
}
function switch_basic_config() {
$('#catalog_xml').hide();
$('#catalog_simple').show();
}
$(document).ready(function() {
switch_basic_config();
$('#simple_plan_product_name').autocomplete({
source: function(query, process) {
process(known_products());
}
});
$('#simple_plan_product_category').change(function() {
display_available_base_products_for_ao();
});
display_available_base_products_for_ao();
$('#simple_plan_product_name').on('mouseleave', function() {
recompute_available_base_products_for_ao();
});
});
<% end %>