Existing Plans
<% if can? :config_upload, Kaui::AdminTenant %>
<%= link_to ''.html_safe,
admin_tenant_new_catalog_path(:id => @tenant.id),
:class => 'btn btn-xs' %>
<% end %>
<%= link_to ''.html_safe,
download_catalog_xml_path(:id => @tenant.id, :effective_date => @latest_version),
:class => 'btn btn-xs', :id => 'download_link' %>
<% if can?(:delete, Kaui::AdminTenant) %>
<%= link_to ''.html_safe,
admin_tenant_delete_catalog_path(:id => @tenant.id), :method => :delete, :class => 'btn btn-xs' %>
<% end %>
Enable XML View
Catalog Versions:
Plan Id |
Product |
Category |
Billing Period |
|
Trial |
|
<%= javascript_tag do %>
window.onload = function() {
fetchCatalog('<%= @latest_version %>');
};
function renderCurrencySelect(data) {
var template = $("#currencies_template").html();
var currencies_html = Mustache.render(template,data);
$("#currency_select").html(currencies_html);
}
function renderCatalog(data){
for (var i = 0; i < data.catalog.length; i++) {
var current = data.catalog[i];
for (var j = 0; j < current.plans.length; j++) {
var plan = current.plans[j];
plan['currenciesWithPrices'] = [];
for (var currency in plan['prices']) {
plan['currenciesWithPrices'].push({currency: currency, price: plan['prices'][currency]});
}
plan['new_plan_currency_path'] = Routes.kaui_engine_admin_tenant_new_plan_currency_path(<%= @tenant.id %>, {plan_id: plan['plan_id']});
plan['humanized_product_name'] = function(){
return function (input, render) {
var product_name = render(input);
return product_name.toLowerCase().replace(/\b\w/g, function(l){ return l.toUpperCase() });
}
}
plan['humanized_product_category'] = function(){
return function (input, render) {
var product_category = render(input);
if (product_category == 'BASE') {
return 'Base'
} else if (product_category == 'ADD_ON') {
return 'Add-on'
} else {
return product_category.toLowerCase().replace(/\b\w/g, function(l){ return l.toUpperCase() });
}
}
}
plan['humanized_billing_period'] = function(){
return function (input, render) {
var billing_period = render(input);
if (billing_period == 'NO_BILLING_PERIOD') {
return 'No billing period'
} else {
return billing_period.toLowerCase().replace(/\b\w/g, function(l){ return l.toUpperCase() });
}
}
}
plan['humanized_time_unit'] = function(){
return function (input, render) {
var time_unit = render(input);
return time_unit.toLowerCase().replace(/\b\w/g, function(l){ return l.toUpperCase() });
}
}
}
}
var template = $("#selected_catalog_template").html();
var catalog_html = Mustache.render(template,data);
$("#catalog_detail").html(catalog_html);
displayAmountsForCurrency();
}
function initBasicConfig() {
displayAmountsForCurrency();
}
function displayAmountsForCurrency() {
$('[class^="plan_currency_"]').hide();
$("[class^=plan_currency_" + $("#select_currencies option:selected" ).text() + "]").show();
}
function fetchCatalog(effectiveDate) {
if (effectiveDate == '')
return;
$.ajax(
{
url: Routes.kaui_engine_catalog_by_effective_date_path(),
type: "GET",
dataType: "json",
data: {
id: <%= @tenant.id %>,
effective_date: effectiveDate
},
success: function(data) {
renderCurrencySelect(data);
renderCatalog(data);
//update the download path
var download_path = Routes.kaui_engine_download_catalog_xml_path(<%= @tenant.id %>, { 'effective_date': effectiveDate });
$('#download_link').attr('href',download_path);
}
});
}
$(document).ready(function() {
$("#select_catalog").change(function() {
fetchCatalog(this.value);
});
$('[id^="select_currencies"]').change(function() {
displayAmountsForCurrency();
});
});
<% end %>