function handleerror(xmldata) { if ($('error', xmldata).size()) { var msg = 'Es ist ein Fehler aufgetreten:\n'; $('error', xmldata).find('errormsg').each(function(i) { msg += $(this).text(); }); alert(msg); return true; } return false; $('#content').show(); } function updateDirectories(xmldata) { var dirname = $('dirname', xmldata).text(); var groups = $('groups', xmldata).text(); var filecount = $('filecount', xmldata).text(); var filesize = $('filesize', xmldata).text(); var maydelete = $('maydelete', xmldata).text(); var htmltext = '' + dirname + '' + groups + '' + filecount + ', ' + filesize + 'Gruppen'; if (maydelete == '1') { htmltext = htmltext + 'löschen'; } htmltext = htmltext + ''; $('#dirtable').find('tr#dir' + dirname).empty().append(htmltext); if (!($('#dirtable').find('tr#dir' + dirname).size())) { var rows = $('#dirtable').find('tr'); var inserted = false; for (var i = 0; !inserted && i < rows.length; i++) { if ($(rows[i]).find('td:first').text() > dirname) { $(rows[i]).before( '' + htmltext + ''); inserted = true; } } if (!inserted) { $(rows[rows.length-1]).before( '' + htmltext + ''); } } $('#dirtable').find('tr#dir' + dirname).find('a.editlink').click(function() { editdirectory(this.id.substr(4)); }); $('#dirtable').find('tr#dir' + dirname).find('a.deletelink').click(function() { removedirectory(this.id.substr(6)); }); } function getDirectoryForm(title, dirname, groups) { return '
Schließen ' + title + '
'; } function displaydirectoryeditor(title, dirname, groups) { $('#content').hide(); $('#direditor').hide().empty().append(getDirectoryForm(title, dirname, groups)).show(); DAV.autocompleteAutoAttach(); $('#dirform').find('#input-dirname').focus(); $('#closer').click(function() { $('#direditor').hide().empty(); $('#content').show(); }); $('#dirform').submit(function() { if (!this.dirname.value.match(/^[a-zA-Z0-9 -_.]+$/)) { alert("Ungültiger Verzeichnisname."); this.dirname.focus(); return false; } $.post( "/davadmin/directories.php", {method : 'submitdirectory', dirname : this.dirname.value, groups : this.groups.value}, function(retval) { $('div#direditor').hide().empty(); if (!handleerror(retval)) { updateDirectories(retval); $('#content').show(); } }); return false; }); } function editdirectory(dirname) { $.get( "directories.php", {dirname : dirname, method : 'getdirectorydata'}, function(retval) { if (!handleerror(retval)) { var dirname, groups; dirname = $("dirname:first", retval).text(); groups = $("groups:first", retval).text(); displaydirectoryeditor("Verzeichnisdaten bearbeiten", dirname, groups); } }); } function newdirectory() { displaydirectoryeditor('Neues Verzeichnis anlegen', '', ''); } function deletedirectorydialog(dirname) { $("#direditor").hide().empty(); var msg = 'Soll das Verzeichnis ' + dirname + ' wirklich gelöscht werden?'; if (confirm(msg) == true) { $.post( "directories.php", {method : 'deletedirectory', dirname : dirname}, function(retval) { if (!handleerror(retval)) { var dirname = $('dirname:first', retval).text(); $('#dirtable').find('tr#dir' + dirname).remove(); } }); } } function removedirectory(dirname) { $.get( "directories.php", {dirname : dirname, method : 'getdirectorydata'}, function(retval) { if (!handleerror(retval)) { var username, lastname, firstname; var dirname, groups; dirname = $("dirname:first", retval).text(); deletedirectorydialog(dirname); } }); } $(function() { $("a.editlink").each(function(i) { $(this).click(function() { editdirectory(this.id.substr(4)); }); }); $("a.newlink").each(function(i) { $(this).click(function() { newdirectory(); }); }); $("a.deletelink").each(function(i) { $(this).click(function() { removedirectory(this.id.substr(6)); }); }); });