- initial import

This commit is contained in:
Jan Dittberner 2007-08-28 08:18:04 +00:00
commit 5e60bf4a9a
37 changed files with 2204 additions and 0 deletions

View file

@ -0,0 +1,305 @@
// $Id$
/*
* Autocompletion for input fields, ideas from Drupal autocompletion
*/
/**
* Attaches the autocomplete behaviour to all required fields
*/
DAV.autocompleteAutoAttach = function () {
var acdb = [];
$('input.autocomplete').each(function () {
var uri = this.value;
if (!acdb[uri]) {
acdb[uri] = new DAV.ACDB(uri);
}
var input = $('#' + this.id.substr(0, this.id.length - 13))
.attr('autocomplete', 'OFF')[0];
$(input.form).submit(DAV.autocompleteSubmit);
new DAV.jsAC(input, acdb[uri]);
});
}
/**
* Prevents the form from submitting if the suggestions popup is open
* and closes the suggestions popup when doing so.
*/
DAV.autocompleteSubmit = function () {
return $('#autocomplete').each(function () {
this.owner.hidePopup();
}).size() == 0;
}
/**
* An AutoComplete object
*/
DAV.jsAC = function (input, db) {
var ac = this;
this.input = input;
this.db = db;
$(this.input)
.keydown(function (event) { return ac.onkeydown(this, event); })
.keyup(function (event) { ac.onkeyup(this, event) })
.blur(function () { ac.hidePopup(); ac.db.cancel(); });
};
/**
* Handler for the "keydown" event
*/
DAV.jsAC.prototype.onkeydown = function (input, e) {
if (!e) {
e = window.event;
}
switch (e.keyCode) {
case 40: // down arrow
this.selectDown();
return false;
case 38: // up arrow
this.selectUp();
return false;
default: // all other keys
return true;
}
}
/**
* Handler for the "keyup" event
*/
DAV.jsAC.prototype.onkeyup = function (input, e) {
if (!e) {
e = window.event;
}
switch (e.keyCode) {
case 16: // shift
case 17: // ctrl
case 18: // alt
case 20: // caps lock
case 33: // page up
case 34: // page down
case 35: // end
case 36: // home
case 37: // left arrow
case 38: // up arrow
case 39: // right arrow
case 40: // down arrow
return true;
case 9: // tab
case 13: // enter
case 27: // esc
this.hidePopup(e.keyCode);
return true;
default: // all other keys
if (input.value.length > 0)
this.populatePopup();
else
this.hidePopup(e.keyCode);
return true;
}
}
/**
* Puts the currently highlighted suggestion into the autocomplete field
*/
DAV.jsAC.prototype.select = function (node) {
this.input.value = node.autocompleteValue;
}
/**
* Highlights the next suggestion
*/
DAV.jsAC.prototype.selectDown = function () {
if (this.selected && this.selected.nextSibling) {
this.highlight(this.selected.nextSibling);
}
else {
var lis = $('li', this.popup);
if (lis.size() > 0) {
this.highlight(lis.get(0));
}
}
}
/**
* Highlights the previous suggestion
*/
DAV.jsAC.prototype.selectUp = function () {
if (this.selected && this.selected.previousSibling) {
this.highlight(this.selected.previousSibling);
}
}
/**
* Highlights a suggestion
*/
DAV.jsAC.prototype.highlight = function (node) {
if (this.selected) {
$(this.selected).removeClass('selected');
}
$(node).addClass('selected');
this.selected = node;
}
/**
* Unhighlights a suggestion
*/
DAV.jsAC.prototype.unhighlight = function (node) {
$(node).removeClass('selected');
this.selected = false;
}
/**
* Hides the autocomplete suggestions
*/
DAV.jsAC.prototype.hidePopup = function (keycode) {
// Select item if the right key or mousebutton was pressed
if (this.selected && ((keycode && keycode != 46 && keycode != 8 && keycode != 27) || !keycode)) {
this.input.value = this.selected.autocompleteValue;
}
// Hide popup
var popup = this.popup;
if (popup) {
this.popup = null;
$(popup).fadeOut('fast', function() { $(popup).remove(); });
}
this.selected = false;
}
/**
* Positions the suggestions popup and starts a search
*/
DAV.jsAC.prototype.populatePopup = function () {
// Show popup
if (this.popup) {
$(this.popup).remove();
}
this.selected = false;
this.popup = document.createElement('div');
this.popup.id = 'autocomplete';
this.popup.owner = this;
$(this.popup).css({
marginTop: this.input.offsetHeight +'px',
width: (this.input.offsetWidth - 4) +'px',
display: 'none'
});
$(this.input).before(this.popup);
// Do search
this.db.owner = this;
this.db.search(this.input.value);
}
/**
* Fills the suggestion popup with any matches received
*/
DAV.jsAC.prototype.found = function (matches) {
// If no value in the textfield, do not show the popup.
if (!this.input.value.length) {
return false;
}
// Prepare matches
var ul = document.createElement('ul');
var ac = this;
for (key in matches) {
var li = document.createElement('li');
$(li)
.html('<div>'+ matches[key] +'</div>')
.mousedown(function () { ac.select(this); })
.mouseover(function () { ac.highlight(this); })
.mouseout(function () { ac.unhighlight(this); });
li.autocompleteValue = key;
$(ul).append(li);
}
// Show popup with matches, if any
if (this.popup) {
if (ul.childNodes.length > 0) {
$(this.popup).empty().append(ul).show();
}
else {
$(this.popup).css({visibility: 'hidden'});
this.hidePopup();
}
}
}
DAV.jsAC.prototype.setStatus = function (status) {
switch (status) {
case 'begin':
$(this.input).addClass('throbbing');
break;
case 'cancel':
case 'error':
case 'found':
$(this.input).removeClass('throbbing');
break;
}
}
/**
* An AutoComplete DataBase object
*/
DAV.ACDB = function (uri) {
this.uri = uri;
this.delay = 300;
this.cache = {};
}
/**
* Performs a cached and delayed search
*/
DAV.ACDB.prototype.search = function (searchString) {
var db = this;
this.searchString = searchString;
// See if this key has been searched for before
if (this.cache[searchString]) {
return this.owner.found(this.cache[searchString]);
}
// Initiate delayed search
if (this.timer) {
clearTimeout(this.timer);
}
this.timer = setTimeout(function() {
db.owner.setStatus('begin');
// Ajax GET request for autocompletion
$.ajax({
type: "GET",
url: db.uri +'/'+ DAV.encodeURIComponent(searchString),
success: function (data) {
// Parse back result
var matches = DAV.parseJson(data);
if (typeof matches['status'] == 'undefined' || matches['status'] != 0) {
db.cache[searchString] = matches;
// Verify if these are still the matches the user wants to see
if (db.searchString == searchString) {
db.owner.found(matches);
}
db.owner.setStatus('found');
}
},
error: function (xmlhttp) {
alert('An HTTP error '+ xmlhttp.status +' occured.\n'+ db.uri);
}
});
}, this.delay);
}
/**
* Cancels the current autocomplete request
*/
DAV.ACDB.prototype.cancel = function() {
if (this.owner) this.owner.setStatus('cancel');
if (this.timer) clearTimeout(this.timer);
this.searchString = '';
}
// Assign autocomplete
$(document).ready(DAV.autocompleteAutoAttach);

View file

@ -0,0 +1,148 @@
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(
"/dav/admin/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)); });
});
});

29
admin/scripts/helper.js Normal file
View file

@ -0,0 +1,29 @@
// $Id$
/**
* Helper code. Ideas from Drupal.
*/
var DAV = DAV || {};
/**
* Parse a JSON response.
*
* The result is either the JSON object, or an object with 'status' 0 and
* 'data' an error message.
*/
DAV.parseJson = function (data) {
if ((data.substring(0, 1) != '{') && (data.substring(0, 1) != '[')) {
return { status: 0, data: data.length ? data : 'Unspecified error' };
}
return eval('(' + data + ');');
};
/**
* Wrapper to address the mod_rewrite url encoding bug.
*/
DAV.encodeURIComponent = function (item, uri) {
uri = uri || location.href;
item = encodeURIComponent(item).replace('%2F', '/');
return uri.indexOf('?q=') ? item : item.replace('%26', '%2526').replace('%23', '%2523');
};

1
admin/scripts/jquery.js vendored Normal file

File diff suppressed because one or more lines are too long

189
admin/scripts/users.js Normal file
View file

@ -0,0 +1,189 @@
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);
$('#content').show();
return true;
}
return false;
}
function updateusers(xmldata) {
var uid = $(xmldata).find('uid').text();
var username = $(xmldata).find('username').text();
var firstname = $(xmldata).find('firstname').text();
var lastname = $(xmldata).find('lastname').text();
var loggedin = $(xmldata).find('loggedin').text();
var htmltext = '<td>' + username + '</td><td>' + lastname + ', ' + firstname + '</td><td><a id="edit' + uid + '" class="editlink" href="#" title="Die Daten dieses Nutzers bearbeiten"><img class="actionicon" src="images/edit.png" width="16" height="16" alt="bearbeiten"/></a>';
if (loggedin == '0') {
htmltext = htmltext + '<a id="delete' + uid + '" class="deletelink" href="#" title="Die Daten dieses Nutzers löschen"><img class="actionicon" src="images/delete.png" width="16" height="16" alt="löschen" /></a>';
}
htmltext = htmltext + '</td>';
$('#usertable').find('tr#uid' + uid).empty().append(htmltext);
if (!($('#usertable').find('tr#uid' + uid).size())) {
var rows = $('#usertable').find('tr');
var inserted = false;
for (var i = 0; !inserted && i < rows.length; i++) {
if ($(rows[i]).find('td:first').text() > username) {
$(rows[i]).before(
'<tr id="uid' + uid + '">' + htmltext + '</tr>');
inserted = true;
}
}
if (!inserted) {
$(rows[rows.length-1]).before(
'<tr id="uid' + uid + '">' + htmltext + '</tr>');
}
}
$('#usertable').find('tr#uid' + uid).find('a.editlink').click(function() {
edituser(this.id.substr(4));
});
$('#usertable').find('tr#uid' + uid).find('a.deletelink').click(function() {
deleteuser(this.id.substr(6));
});
$('#content').show();
}
function getEditUserForm(title, username, firstname, lastname, groups, userid) {
var retval;
retval = '<form action="#" id="userform"><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="input-username">Nutzername:</label><input id="input-username" type="text" name="username" value="' + username + '" ';
if (userid != null) {
retval = retval + ' readonly="readonly"';
}
retval = retval + '/></div><div class="formelement"><label for="input-firstname">Vorname:</label><input id="input-firstname" type="text" name="firstname" value="' + firstname + '" /></div><div class="formelement"><label for="input-lastname">Nachname:</label><input id="input-lastname" type="text" name="lastname" value="' + lastname + '" /></div><div class="formelement"><label for="pwd1">Passwort:</label><input type="password" name="pwd1" /></div><div class="formelement"><label for="pwd2">Wiederholung:</label><input type="password" name="pwd2" /></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></fieldset></form>';
return retval;
}
function displayusereditor(title, userid, username, firstname, lastname, groups) {
$('#content').hide();
$('#usereditor').hide().empty().append(getEditUserForm(title, username, firstname, lastname, groups, userid)).show();
DAV.autocompleteAutoAttach();
$('#closer').click(function() {
$('#usereditor').hide().empty();
$('#content').show();
});
$('#userform').find('#input-username').focus();
$('#userform').submit(function() {
var params;
if (userid == null) {
if (!this.username.value.match(/^[a-zA-Z0-9]{2,}$/)) {
alert('Der Nutzername muss aus mindestens 2 Buchstaben oder Ziffern bestehen und darf keine sonstigen Zeichen enthalten.');
this.username.focus();
return false;
}
}
if (userid == null || this.pwd1.value.length > 0) {
if (this.pwd1.value.length < 8) {
alert('Das Passwort muss mindestens 8 Zeichen lang sein!');
this.pwd1.focus();
return false;
}
if (this.pwd1.value != this.pwd2.value) {
alert('Passwort und Wiederholung müssen übereinstimmen!');
this.pwd2.focus();
return false;
}
}
if (!this.groups.value.match(/^([0-9a-zA-z]+[,\s]*)+$/)) {
alert('Die Gruppenangabe muss eine durch Kommata getrennte Liste von Gruppennamen, die aus Buchstaben und Ziffern zusammengesetzt sein können, sein.');
this.groups.focus();
return false;
}
if (userid == null) {
params = {method : 'submituser',
username : this.username.value,
firstname : this.firstname.value,
lastname : this.lastname.value,
password : this.pwd1.value,
groups : this.groups.value};
} else {
params = {method : 'submituser',
uid : userid,
username : this.username.value,
firstname : this.firstname.value,
lastname : this.lastname.value,
password : this.pwd1.value,
groups : this.groups.value};
}
$.post(
"users.php", params,
function(retval) {
$('div#usereditor').hide().empty();
if (!handleerror(retval)) {
updateusers(retval);
}
});
return false;
});
}
function deleteuserdialog(userid, username, firstname, lastname) {
$("#usereditor").hide().empty();
var msg = 'Soll der Nutzer ' + firstname + ' ' + lastname +
' mit dem Login ' + username + ' wirklich gelöscht werden?';
if (confirm(msg) == true) {
$.post(
"users.php",
{method : 'deleteuser',
uid : userid},
function(retval) {
if (!handleerror(retval)) {
var deluid = $('uid:first', retval).text();
$('#usertable').find('tr#uid' + deluid).remove();
}
});
}
}
function deleteuser(userid) {
$.get(
"users.php",
{uid : userid,
method : 'getuserdata'},
function(retval) {
if (!handleerror(retval)) {
var username, lastname, firstname;
username = $("username:first", retval).text();
lastname = $("lastname:first", retval).text();
firstname = $("firstname:first", retval).text();
deleteuserdialog(userid, username, firstname, lastname);
}
});
}
function edituser(userid) {
$.get(
"users.php",
{uid : userid,
method : 'getuserdata'},
function(retval) {
if (!handleerror(retval)) {
var username, lastname, firstname, groups;
username = $("username:first", retval).text();
lastname = $("lastname:first", retval).text();
firstname = $("firstname:first", retval).text();
groups = $("groups:first", retval).text();
displayusereditor('Nutzerdaten bearbeiten', userid, username,
firstname, lastname, groups);
}
});
}
function newuser() {
displayusereditor('Neuen Nutzer anlegen', null, '', '', '', '');
}
$(function() {
$("a.editlink").each(function(i) {
$(this).click(function() { edituser(this.id.substr(4)); });
});
$("a.newlink").each(function(i) {
$(this).click(function() { newuser(); });
});
$("a.deletelink").each(function(i) {
$(this).click(function() { deleteuser(this.id.substr(6)); });
});
});