redmine-ldap-config/app/views/ldap_config/edit.html.erb
ioresponse e7dd7b0f19 Initial commit: Redmine LDAP Config Plugin
🤖 Generated with Claude Code
2025-12-23 00:21:35 +09:00

70 lines
2.6 KiB
Plaintext

<h2>Edit LDAP: <%= @ldap.name %></h2>
<%= javascript_tag do %>
var ldapPresets = <%= raw @presets.to_json %>;
function applyPreset(selectElement) {
var preset = selectElement.value;
if (preset && ldapPresets[preset]) {
var config = ldapPresets[preset];
document.getElementById('auth_source_ldap_name').value = config.name;
document.getElementById('auth_source_ldap_port').value = config.port;
document.getElementById('auth_source_ldap_tls').checked = config.tls;
document.getElementById('auth_source_ldap_base_dn').value = config.base_dn;
document.getElementById('auth_source_ldap_filter').value = config.filter;
document.getElementById('auth_source_ldap_attr_login').value = config.attr_login;
document.getElementById('auth_source_ldap_attr_firstname').value = config.attr_firstname;
document.getElementById('auth_source_ldap_attr_lastname').value = config.attr_lastname;
document.getElementById('auth_source_ldap_attr_mail').value = config.attr_mail;
}
}
function testLdapConnection() {
var form = document.getElementById('ldap-form');
var formData = new FormData(form);
var testBtn = document.getElementById('test-btn');
var resultDiv = document.getElementById('test-result');
testBtn.disabled = true;
testBtn.value = 'Testing...';
resultDiv.innerHTML = '';
fetch('<%= url_for(controller: 'ldap_config', action: 'test_connection') %>', {
method: 'POST',
body: formData,
headers: {
'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').content
}
})
.then(response => response.json())
.then(data => {
testBtn.disabled = false;
testBtn.value = 'Test Connection';
if (data.success) {
resultDiv.innerHTML = '<span style="color: green; font-weight: bold;">&#10004; ' + data.message + '</span>';
} else {
resultDiv.innerHTML = '<span style="color: red; font-weight: bold;">&#10008; ' + data.message + '</span>';
}
})
.catch(error => {
testBtn.disabled = false;
testBtn.value = 'Test Connection';
resultDiv.innerHTML = '<span style="color: red;">Error: ' + error + '</span>';
});
}
<% end %>
<%= form_for @ldap, url: ldap_config_update_path(@ldap), method: :patch,
html: { id: 'ldap-form', class: 'tabular' } do |f| %>
<%= render partial: 'ldap_form', locals: { f: f } %>
<p style="margin-top: 15px;">
<%= f.submit 'Save', class: 'button-positive' %>
<input type="button" id="test-btn" value="Test Connection" onclick="testLdapConnection()" class="button" />
<%= link_to 'Cancel', { controller: 'ldap_config', action: 'index' }, class: 'button' %>
<span id="test-result" style="margin-left: 10px;"></span>
</p>
<% end %>