<% if can? :config_upload, Kaui::AdminTenant %>

Upload Plugin Configuration

<%= form_tag({:action => :upload_plugin_config}, :method => 'post', :multipart => true, :class => 'form-horizontal') do %> <%= hidden_field_tag(:id, @tenant.id) %> <%= hidden_field_tag(:plugin_name) %> <%= hidden_field_tag(:plugin_key) %> <%= hidden_field_tag(:plugin_type) %>
<%= label_tag :entered_plugin_name, 'Plugin name', :class => 'col-sm-2 control-label' %>
<%= text_field_tag :entered_plugin_name, nil, :placeholder => 'as defined in the plugin Activator file', :class => 'form-control', :tenant_plugin_config => @tenant_plugin_config.to_json %>
<%= label_tag :configuration, 'Configuration', :class => 'col-sm-2 control-label' %>
<%= submit_tag 'Upload', :class => 'btn btn-default' %>
<% end %>
<% end %> <%= javascript_tag do %> $(document).ready(function() { $(".spinner").hide(); $('#plugin_config_properties_header').hide(); $('#entered_plugin_name').toggle(); $('#toggle_input').on('change', function() { $('#select_plugin_name').toggle(); $('#entered_plugin_name').toggle(); $('.toggle-label').toggleClass('text-muted'); $("#plugin_name").val(''); $("#plugin_key").val(''); $("#plugin_type").val(''); $('#entered_plugin_name').val(''); $('#select_plugin_name').val(''); $('#plugin_config_properties').attr('plugin_name', ''); $('#plugin_config_properties').empty(); $('#plugin_config_properties_header').hide(); $(".plugin-suggestion").html(''); $("#raw_config").val(''); }); /* Intercept TAB and potentially display known properties */ $('#entered_plugin_name').keydown(function (e) { if (e.keyCode === 9) { $("#plugin_name").val($('#entered_plugin_name').val()); $("#plugin_key").val(''); render_plugin_key_values(); } }); /* Intercept mouseleave and potentially display known properties */ $('#entered_plugin_name').on('mouseleave', function() { $("#plugin_name").val($('#entered_plugin_name').val()); $("#plugin_key").val(''); render_plugin_key_values(); }); $("#toggle_raw").on('change', function(e) { $("#plugin_name").val($('#entered_plugin_name').val()); $("#plugin_key").val(''); render_plugin_key_values(); }); $('#select_plugin_name').on('change', function(e) { // User has selected a plugin from the dropdown var selectedOption = e.target.selectedOptions; if (selectedOption.length > 0) { var plugin_name = selectedOption[0].value; var plugin_key = selectedOption[0].text; $("#plugin_name").val(plugin_name); $("#plugin_key").val(plugin_key); $("#plugin_type").val(selectedOption[0].dataset['pluginType']); // java or ruby $('#plugin_config_properties').attr('plugin_name', ''); $('#plugin_config_properties_header').hide(); $("#toggle_raw").prop('checked', false); render_plugin_key_values(); } }); populate_plugin_name_options(); function populate_plugin_name_options(){ var all_plugins = JSON.parse($("#plugin_repository").val()); // We only list installed plugins as to not confuse the user var plugin_repository = all_plugins.filter(plugin => plugin.installed); for (var idx = 0, size = plugin_repository.length; idx < size; idx++) { if (idx == 0 && plugin_repository[idx].installed) { plugin_repository[idx]['start_installed'] = true; } if (idx > 0 && !plugin_repository[idx].installed && plugin_repository[idx - 1].installed) { plugin_repository[idx]['end_installed'] = true; break; } } for (var idx = 0, size = plugin_repository.length; idx < size; idx++) { if (plugin_repository[idx]['plugin_key']) { plugin_repository[idx]['display_name'] = plugin_repository[idx]['plugin_key']; } else { plugin_repository[idx]['display_name'] = plugin_repository[idx]['plugin_name']; } } var template = $("#plugin_name_options_template").html(); var options_html = Mustache.render( template , { plugin_repository: plugin_repository }); $("#select_plugin_name").html(options_html); } function get_existing_tenant_plugin_properties(entered_plugin_name) { var tenant_plugin_properties = $('#entered_plugin_name').attr('tenant_plugin_config'); var res = JSON.parse(tenant_plugin_properties); return res[entered_plugin_name]; } function get_tenant_plugin_properties(plugin_key, plugin_name) { /* Retrieve existing plugin properties for this tenant */ var existing_props = get_existing_tenant_plugin_properties(plugin_key); // Try by plugin name for proprietary plugins if (isBlank(existing_props) && !isBlank(plugin_name)) { existing_props = get_existing_tenant_plugin_properties(plugin_name); if (isBlank(existing_props)) { // For proprietary plugins, the killbill- prefix likely doesn't exist (see Kaui::PluginHelper discussion) plugin_name = plugin_name.replace('killbill-', ''); existing_props = get_existing_tenant_plugin_properties(plugin_name); if (isBlank(existing_props)) { // For proprietary plugins, our docs suggest acme:foo as the format for the plugin key, and often the plugin name becomes acme-foo plugin_name = plugin_name.replace(':', '-'); existing_props = get_existing_tenant_plugin_properties(plugin_name); } } } return existing_props; } function render_plugin_key_values() { var plugin_name = ""; var plugin_key = ""; if (isBlank($('#entered_plugin_name').val())) { plugin_name = $("#plugin_name").val(); plugin_key = $("#plugin_key").val(); } else { plugin_name = $("#entered_plugin_name").val(); } var existing_props = get_tenant_plugin_properties(plugin_key, plugin_name); $("#raw_config").val(existing_props); } }); <% end %>