148 lines
5.9 KiB
JavaScript
148 lines
5.9 KiB
JavaScript
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 = '<td>' + dirname + '</td><td>' + groups + '</td><td>' + filecount + ', ' + filesize + '</td><td><a id="edit' + dirname + '" class="editlink" href="#" title="Die Gruppenzuordnungen dieses Verzeichnisses bearbeiten"><img class="actionicon" src="images/groups.png" width="16" height="16" alt="Gruppen"/></a>';
|
|
if (maydelete == '1') {
|
|
htmltext = htmltext + '<a id="delete' + dirname + '" class="deletelink" href="#" title="Dieses Verzeichnis löschen"><img class="actionicon" src="images/delete.png" width="16" height="16" alt="löschen" /></a>';
|
|
}
|
|
htmltext = htmltext + '</td>';
|
|
$('#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(
|
|
'<tr id="dir' + dirname + '">' + htmltext + '</tr>');
|
|
inserted = true;
|
|
}
|
|
}
|
|
if (!inserted) {
|
|
$(rows[rows.length-1]).before(
|
|
'<tr id="dir' + dirname + '">' + htmltext + '</tr>');
|
|
}
|
|
}
|
|
$('#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 '<form action="#" id="dirform"><fieldset class="dynaform"><legend><img id="closer" src="images/x.png" width="16" height="16" alt="Schließen" /> ' + title + '</legend><div class="formelement"><label for="dirname">Verzeichnisname:</label><input type="text" name="dirname" id="input-dirname" value="' + dirname + '" /></div><div class="formelement"><label for="groups">Gruppen:</label><input type="text" name="groups" class="form-autocomplete" id="input-groups" value="' + groups + '" /><input type="hidden" class="autocomplete" id="input-groups-autocomplete" value="getgroups.php" /></div><div class="formactions"><input type="submit" name="submit" value="Absenden" /></div></div></fieldset></form>';
|
|
}
|
|
|
|
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)); });
|
|
});
|
|
});
|