<% 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) %>
<%= label_tag :plugin_name, 'Plugin name', :class => 'col-sm-2 control-label' %>
<%= text_field_tag :plugin_name, nil, :class => 'form-control', :plugin_config => @plugin_config, :tenant_plugin_config => @tenant_plugin_config %>
<%= submit_tag 'Upload', :class => 'btn btn-default' %>
<% end %>
<% end %> <%= javascript_tag do %> function get_existing_tenant_plugin_properties(plugin_name) { var tenant_plugin_properties = $('#plugin_name').attr('tenant_plugin_config'); var res = {} if (tenant_plugin_properties != undefined) { $.each(tenant_plugin_properties.split(';'), function(idx, el) { var el_parts = el.split('::'); var el_plugin_name = el_parts[0]; var el_props = el_parts[1]; if (el_plugin_name == plugin_name) { if (el_props.split('=')[0] == 'raw_config') { res['raw_config'] = el_props.substr(11); } else { $.map(el_props.split(','), function(el) { var parts = el.split('='); res[parts[0]] = parts[1]; }); } return false; } }); } return res; } function get_selected_plugin_info() { var plugin_name = $('#plugin_name').val(); var plugin_config_str = $('#plugin_name').attr('plugin_config'); var res = {} /* Deserialize plugin/properties (see AdminTenant model)*/ $.each(plugin_config_str.split(';'), function(idx, el) { var el_parts = el.split(':'); var el_parts_key = el_parts[0].split('#'); var el_plugin_name = el_parts_key[0]; var el_plugin_type = el_parts_key[1]; var el_plugin_props = el_parts[1]; if (el_plugin_name == plugin_name) { res['type'] = el_plugin_type; res['props'] = el_plugin_props == "" ? [] : (el_plugin_type == "" ? ['raw_config'] : el_plugin_props.split(',')); return false; } }); if (res['props'] == undefined) { res['type'] = ''; res['props'] = ['raw_config']; } return res; } function init_plugin_config_source() { var plugin_config_str = $('#plugin_name').attr('plugin_config'); var res = [] $.map(plugin_config_str.split(";"), function(el) { res.push(el.split(':')[0].split('#')[0]) }); return res; } function add_properties_for_plugin(plugin_name, plugin_info) { if (plugin_name == "") { $('#plugin_config_properties').empty(); return; } if ($('#plugin_config_properties').attr('plugin_name') == plugin_name) { /* Already set...*/ return; } var type = plugin_info['type']; var props = plugin_info['props'] /* Prune the tree to restart from scratch */ $('#plugin_config_properties').empty(); $('#plugin_config_properties').append(''); $('#plugin_config_properties').append(''); $('#plugin_config_properties').append('
'); /* Retrieve existing plugin properties for this tenant */ var existing_props = get_existing_tenant_plugin_properties(plugin_name); var merged_props_with_values = existing_props; if (props != undefined) { $.each(props, function(idx, p) { if (merged_props_with_values[p] == undefined) { merged_props_with_values[p] = ''; } }); } $.each(merged_props_with_values, function(p, v) { add_property_form_entry(format_label(p), p, v); }); $('#plugin_config_properties').attr('plugin_name', plugin_name); } function format_label(input) { /* Keep latest piece of a system property to keep it short */ var label_name = input.split('.').pop(); /* Replace underscore with comma */ label_name = label_name.replace(/_/g, ','); /* Replace uppercase with comma + uppercase */ label_name = label_name.replace(/([A-Z]+)/g, ",$1"); /* Split name make sure each word starts with Uppercase */ var tmp1 = label_name.split(','); var label_name_array = []; $.map(tmp1, function(el) { label_name_array.push(el.charAt(0).toUpperCase() + el.slice(1)) }); label_name = label_name_array.join(' '); return label_name; } function add_property_form_entry(property_label, property, current_value) { var clone = $('#PluginConfig form div').first().clone(); clone.children("label").attr('for', property).text(property_label); clone.children("div").first().attr("name", property).attr("id", property); var input = clone.children("div").children("input").first(); input.removeAttr('autocomplete').removeAttr('plugin_config'); if (property == 'raw_config') { var text_area = $('