Catalog Configuration Enable Advanced Configuration (Upload XML)

<%= form_for @simple_plan, :url => {:action => :create_simple_plan}, :html => {:class => 'form-horizontal'} do |f| %> <%= f.hidden_field_tag(:id, @tenant.id) %>
<%= f.label :product_category, 'Product Category', :class => 'col-sm-3 control-label' %>
<%= f.select :product_category, options_for_select(@product_categories.map {|p| [humanized_product_category(p), p] }, :Base), :class => 'form-control' %>
<%= f.label :product_name, 'Product Name', :class => 'col-sm-3 control-label' %>
<%= f.text_field :product_name, :class => 'form-control', :known_base => @available_base_products.join(","), :known_ao => @available_ao_products.join(","), :known_std => @available_standalone_products.join(","), :ao_mappings => @ao_mapping %>
<%= f.label :plan_id, 'Plan Name', :class => 'col-sm-3 control-label' %>
<%= f.text_field :plan_id, :class => 'form-control' %>
<%= f.label :available_base_products, 'Available Base Products', :class => 'col-sm-3 control-label' %>
<%= f.select :available_base_products, options_for_select(@available_base_products), {}, {:multiple => true, :class => "form-control"} %>
<%= f.label :amount, 'Amount', :class => 'col-sm-3 control-label' %>
<%= f.text_field :amount, :class => 'form-control' %>
<%= f.label :currency, 'Currency', :class => 'col-sm-3 control-label' %>
<%= f.select :currency, currencies, {:selected => 'USD'}, :class => 'form-control' %>
<%= f.label :billing_period, 'Billing Period', :class => 'col-sm-3 control-label' %>
<%= f.select :billing_period, options_for_select(@billing_period.map {|bp| [humanized_billing_period(bp), bp] }, :MONTHLY), :class => 'form-control' %>
<%= f.label :trial_length, 'Trial Length', :class => 'col-sm-3 control-label' %>
<%= f.text_field :trial_length, :value => 0, :class => 'form-control' %>
<%= f.label :trial_time_unit, 'Trial Time Unit', :class => 'col-sm-3 control-label' %>
<%= f.select :trial_time_unit, options_for_select(@time_units.map {|tu| [humanized_time_unit(tu), tu]}, :UNLIMITED), :class => 'form-control' %>
<%= submit_tag 'Save', :class => 'btn btn-default' %>
<% end %>

Advanced Configuration Enable Simple Configuration

<%= form_tag({:action => :upload_catalog}, :method => 'post', :multipart => true, :class => 'form-horizontal') do %> <%= hidden_field_tag(:id, @tenant.id) %>
<%= file_field_tag 'catalog', :class => 'form-control' %>
<%= submit_tag 'Upload', :class => 'btn btn-default' %>
<% 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 %>