summaryrefslogtreecommitdiff
path: root/skins/default/includes/ldapscripts.html
blob: 0dfda6cb7956116add3ad4d2ab040aba9db08b3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<script type="text/javascript">
var ldap_server_select = document.getElementById('rcfmd_ldap_public_servers');
if (ldap_server_select) {
  // attach event to ldap server drop down
  ldap_server_select.onchange = function() {
    updateLdapSearchFields(this);
    return false;
  }
}

// update the fields on page load
updateLdapSearchFields(ldap_server_select);

/**
 * function to change the attributes of the ldap server search fields select box
 * this function is triggered by an onchange event in the server select box 
 */
function updateLdapSearchFields(element) {

  // get the search fields select element
  var search_fields = document.getElementById('rcfmd_ldap_public_search_field');

  // get rid of the current options for the select
  for (i = search_fields.length - 1; i>=0; i--)
    search_fields.remove(i);

  // get the array containing this servers search fields
  var server_fields = rcmail.env[element.value + '_search_fields'];

  // add a new option for each of the possible search fields for the selected server
  for (i = 0; i < server_fields.length; i++) {

    // the last array value is for fuzzy search, so skip that one
    if (i < (server_fields.length - 1)) {
      var new_option = document.createElement('option');
      new_option.text  = server_fields[i];
      new_option.value = server_fields[i];

      // standards compliant browsers
      try {
        search_fields.add(new_option, null);
      }
      // for the standards challenged one...
      catch(e) {
        search_fields.add(new_option);      
      }
    } else {
      // ok, last member of array, so check the value of fuzzy_search
      var fuzzy_search = server_fields[i];
      var search_check_box = document.getElementById('rcmfd_ldap_public_search_type');

      if (fuzzy_search == 'fuzzy') {
        // we should enable the check box
        if (search_check_box.disabled)
          search_check_box.disabled = false;

        // make sure the checkbox is unchecked
        if (search_check_box.checked)
          search_check_box.checked = false;

      } else {
        // we should disable the check box
        if (!search_check_box.disabled)
          search_check_box.disabled = true;

        // check the checkbox (just a visual clue for the user)
        if (!search_check_box.checked)
          search_check_box.checked = true;
      }
    }
  }
}
</script>