var Com = new Object();
Com.CSS_NAME_BACKGROUND_INVALID = "red";
Com.CSS_NAME_BACKGROUND_VALID = "green";
Com.TXT_ERROR_CATEGORY_INVALID = 'Kategorie muss ausgewählt werden';
Com.TXT_ERROR_COM_ADD = 'Com konnte nicht angelegt werden.';
Com.TXT_ERROR_NAME_INVALID = 'Name ungültig! Möglicherweise existiert bereits eine Com mit dem gleichen Namen';
Com.TXT_MESSAGE_COM_ADD_SUCCESS = 'Com erfolgreich angelegt.';
Com.TXT_MESSAGE_COM_INEXISTENT_SELECT = 'keine Coms vorhanden, bitte wählen';
Com.isNameValid = false;
Com.start = 1;
Com.picurl = "";
Com.checkName = function() {
if($('#comName').val() == '') {
$('#comName').css("background", Com.CSS_NAME_BACKGROUND_INVALID);
Com.isNameValid = false;
return;
}
comName = document.getElementById("comName");
if(comName.defaultValue == $("#comName").val()) {
$('#comName').css("background", Com.CSS_NAME_BACKGROUND_VALID);
Com.isNameValid = true;
return;
}
var parameters = {
action: 'checkName',
name: $('#comName').val()
};
$.post('/backend/com.php', parameters, this.afterCheckName);
}
Com.afterCheckName = function($isValid) {
if($isValid) {
$('#comName').css("background", Com.CSS_NAME_BACKGROUND_VALID);
Com.isNameValid = true;
}
else {
$('#comName').css("background", Com.CSS_NAME_BACKGROUND_INVALID);
Com.isNameValid = false;
}
}
Com.acceptApplicantsAll = function() {
if(!confirm("Willst Du die/den Bewerber wirklich annehmen?")) {
return;
}
action = $("#comFormAllApplicants").attr("action") + "/acceptAll";
$("#comFormAllApplicants").attr("action", action);
form = document.getElementById("comFormAllApplicants");
form.submit();
}
Com.refuseApplicantsAll = function() {
if(!confirm("Willst Du die/den Bewerber wirklich ablehnen?")) {
return;
}
action = $("#comFormAllApplicants").attr("action") + "/refuseAll";
$("#comFormAllApplicants").attr("action", action);
form = document.getElementById("comFormAllApplicants");
form.submit();
}
Com.acceptApplicantsByList = function() {
if(!confirm("Willst Du die/den Bewerber wirklich annehmen?")) {
return;
}
action = $("#comFormListOfApplicants").attr("action") + "/acceptList";
$("#comFormListOfApplicants").attr("action", action);
form = document.getElementById("comFormListOfApplicants");
form.submit();
}
Com.refuseApplicantsByList = function() {
if(!confirm("Willst Du die/den Bewerber wirklich ablehnen?")) {
return;
}
action = $("#comFormListOfApplicants").attr("action") + "/refuseList";
$("#comFormListOfApplicants").attr("action", action);
form = document.getElementById("comFormListOfApplicants");
form.submit();
}
Com.acceptApplicantsByNumber = function() {
if(!confirm("Willst Du die/den Bewerber wirklich annehmen?")) {
return;
}
action = $("#comFormNumberOfApplicants").attr("action") + "/acceptNumber";
$("#comFormNumberOfApplicants").attr("action", action);
form = document.getElementById("comFormNumberOfApplicants");
form.submit();
}
Com.refuseApplicantsByNumber = function() {
if(!confirm("Willst Du die/den Bewerber wirklich ablehnen?")) {
return;
}
action = $("#comFormNumberOfApplicants").attr("action") + "/refuseNumber";
$("#comFormNumberOfApplicants").attr("action", action);
form = document.getElementById("comFormNumberOfApplicants");
form.submit();
}
Com.confirmApplicationWithdraw = function(form) {
if(confirm("Willst Du deine Bewerbung wirklich zurückziehen?")) {
form.submit();
}
}
Com.confirmApplication = function(form) {
if(confirm("Willst Du dich wirklich bei der Com bewerben?")) {
form.submit();
}
}
Com.confirmApplicantAccept = function(form) {
if(confirm("Willst Du die/den Bewerber wirklich annehmen?")) {
form.submit();
}
}
Com.confirmApplicantRefuse = function(form) {
if(confirm("Willst Du die/den Bewerber wirklich ablehnen?")) {
form.submit();
}
}
Com.confirmComLeave = function(form) {
if(confirm("Willst Du die Mitgliedschaft wirklich beenden?")) {
form.submit();
}
}
Com.onSubmit = function() {
if(Com.isNameValid == false) {
alert(Com.TXT_ERROR_NAME_INVALID);
return false;
}
if(CategorySelector.getCurrentCategoryId() < 1) {
alert(Com.TXT_ERROR_CATEGORY_INVALID);
return false;
}
$('#comCategoryId').val(CategorySelector.getCurrentCategoryId());
$('#comCategoryPath').val(CategorySelector.getPath());
return true;
}
Com.onSubmitFormComConfiguration = function() {
comName = document.getElementById("comName");
if(Com.isNameValid == false) {
alert(Com.TXT_ERROR_NAME_INVALID);
return false;
}
return true;
}
Com.setCategoryToMove = function() {
categoryId = $("#cmPathwayItemCategoryId" + CategorySelector.currentPathwayItemId).val(),
$('#comCategoryId').val(categoryId);
}
Com.showByElementId = function(elementId) {
$('#' + elementId).show();
}
Com.getComsByCategoryId = function() {
var parameters = {
action: 'getComs',
categoryId: $("#cmPathwayItemCategoryId" + CategorySelector.currentPathwayItemId).val(),
start: Com.start
};
$.getJSON(CategorySelector.scriptUrl, parameters, Com.afterGetComsByCategoryId);
}
Com.afterGetComsByCategoryId = function(data) {
$("#comComCategoryName").empty();
$("#comComCategoryName").html($("#cmPathwayItemCategoryName" + CategorySelector.currentPathwayItemId).val());
$("#comComs").empty();
if(data == 1) {
$("#comComs").append(Com.TXT_MESSAGE_COM_INEXISTENT_SELECT);
$("#comComNavigation").hide();
}
else {
$("#comComNavigation").show();
if((Com.start * data["navigation"]["entriesPerPage"]) >= data["navigation"]["numberOfEntries"]) {
$("#comComNavigationForward").hide();
}
else {
$("#comComNavigationForward").show();
}
if((Com.start < 2) || (data["navigation"]["entriesPerPage"] >= data["navigation"]["numberOfEntries"])) {
$("#comComNavigationBack").hide();
}
else {
$("#comComNavigationBack").show();
}
for(var n in data["coms"]) {
$("#comComs").append(
'<div class="cf lh20">' +
'<div class="fl w300"><a href="/com/' + data["coms"][n]["id"] + '" class="fs12"><b>' + data["coms"][n]["name"] + '</b></a></div>' +
'<div class="fr w70">' + data["coms"][n]["numberOfMembers"] + ' <img src="' + Com.picurl + '/i/alm/tn.gif"></div>' +
'</div>'
);
}
}
}
Com.hideByElementId = function(elementId) {
$('#' + elementId).hide();
}
Com.switchStatus = function(status) {
switch(status) {
case "PresentationAlter":
$('#comPresentation').hide();
$('#comFormPresentationAlter').show();
Edit.insertText($("#default").val());
break;
case "IconAlter":
$('#comFormIconAlter').show();
break;
case "normal":
$('#comFormIconAlter').hide();
$('#comFormPresentationAlter').hide();
$('#comPresentation').show();
break;
}
}
Com.turn = function(numberOfPages) {
Com.start += numberOfPages;
Com.getComsByCategoryId();
}
Com.searchSuggest = {
comId: null,
userHasKickLicense: false,
start: function (trigger, comId, kickLicense) {
this.comId = comId;
this.userHasKickLicense = (kickLicense && kickLicense == true) ? true : false;
if (trigger.value == "Hier suchen ..." || (/Hier suchen/).test(trigger.value) == true) trigger.value = "";
this.trigger = trigger;
if (Jpy.getApp() > -1) {
var inputs = trigger.parentNode.getElementsByTagName("input");
inputs[0].className = "enter hover";
trigger.onblur = function () {
inputs[0].className = "enter";
Com.searchSuggest.leave();
}
}
else {
trigger.style.color = "000000";
trigger.onblur = function () {
Com.searchSuggest.leave();
}
}
Jpy.show("lyComSearchSuggest");
trigger.onkeydown = function (event) {
return Com.searchSuggest.blockSubmit(event)
}
trigger.onkeyup = function (event) {
Com.searchSuggest.watchKeyCodes(event);
}
},
leave: function () {
window.setTimeout(function(){Jpy.hide("lyComSearchSuggest")},200)
},
lock: {
timestamp: null,
difference: 750
},
lastSearch: "",
resultsBackendSearch: [],
results: [],
len: 0,
prepare: function () {
this.len = this.trigger.value.length;
if (this.dom == undefined) {
this.injectFrame();
}
if (this.len == 0) {
if (this.dom.frame) {
this.dom.frame.style.display = "none";
this.dom.backendResults.innerHTML = "";
}
return;
}
else if (this.len > 2) {
this.searchNickname();
}
else {
return;
}
},
stopQueue: function () {
if (typeof Com.searchSuggest.searchRequest == "number") {
window.clearTimeout(Com.searchSuggest.searchRequest);
delete Com.searchSuggest.searchRequest;
}
},
searchNickname: function () {
var searchString = this.trigger.value;
if (this.cache[searchString]) {
var cacheResults = this.cache[searchString]
this.resultsBackendSearch = [];
for (var i = 0, len = cacheResults.length; i < len; i++) {
this.resultsBackendSearch.push(cacheResults[i]);
}
this.injectSearchResults()
return;
}
var now = new Date();
if (!this.lock.timestamp) {
this.lock.timestamp = now;
this.lastSearch = this.trigger.value;
}
else if ((this.lock.timestamp.getTime() + this.lock.difference) > now.getTime()) {
this.stopQueue();
this.searchRequest = window.setTimeout(function(){Com.searchSuggest.prepare()}, 300)
return;
}
else if (this.lastSearch == this.trigger.value) {
return;
}
else {
this.stopQueue();
this.lock.timestamp = now;
this.lastSearch = this.trigger.value;
}
var search = new AjaxHandler();
var callback = {
json: true,
success: function(results) {
if (results < 0) {
return;
}
Com.searchSuggest.resultsBackendSearch = [];
if (typeof(results) === "object") {
for (var i = 0, len = results.length; i < len; i++) {
Com.searchSuggest.resultsBackendSearch.push(results[i]);
}
if (/^[a-zA-Z]{3,10}/.test(searchString) == true) {
Com.searchSuggest.cache[searchString] = results;
}
}
Com.searchSuggest.injectSearchResults();
}
};
var parameters = {
nickname : this.trigger.value,
comId : this.comId
};
search.request('POST', "/backend/com/comSearch.php?h="+User.hash, callback, parameters);
},
cache: {},
resultLayout: function (result) {
this.box = DOM.div({className:"entry cf"});
var picture = DOM.div({className:"picture"});
if (result.friendId) {
picture.className = "picture buddy";
}
var userImage = Jpy.getUserImage(result.stamp.profileImage, 45);
userImage.height = 45;
picture.appendChild(userImage);
this.box.appendChild(picture);
var plain = DOM.div({className:"plain"});
var buddyStamp = Userstamp.read(result.stamp);
plain.innerHTML = buddyStamp;
if (result.realName) {
if (result.realName.firstname || result.realName.surname) {
if (!result.realName.surname) result.realName.surname = "";
plain.innerHTML += "<br><span class='rn'>"+result.realName.firstname+" "+result.realName.surname+"</span>";
}
else {
plain.innerHTML += "<br><span class='rn'>"+result.realName+"</span>";
}
}
if(Com.searchSuggest.userHasKickLicense == true) {
plain.innerHTML += "<br><br><span class=\"fr\"><a href=\"#\" onclick=\"Com.kickUser(this, '"+Com.searchSuggest.comId+"', '"+result.userId+"', '"+result.stamp.nickname+"');return false\" class=\"inCo rb3 cp\"><span class='icDelete'>&nbsp;</span>rauswerfen</a></span>";
}
this.box.appendChild(plain);
this.box.onmouseover = (function (box) {
return function () {
Jpy.css.hoverClass(box, 'hover');
}
})(this.box);
},
injectFrame: function () {
this.dom = new this.resultFrame();
},
resultFrame: function () {
var layer = new Jpy.layer.get({
trigger: Com.searchSuggest.trigger,
offset: {x:0,y:22},
id: "lyComSearchSuggest"
});
this.frame = layer.frame;
this.frame.className = "searchSuggest";
this.buddiesResults = DOM.div();
this.frame.appendChild(this.buddiesResults);
this.backendResults = DOM.div();
this.frame.appendChild(this.backendResults);
this.frame.style.display = "none";
},
dom: undefined,
injectSearchResults: function () {
this.dom.backendResults.innerHTML = "";
var results = Com.searchSuggest.resultsBackendSearch;
this.layout.backend = [];
var fragment = document.createDocumentFragment();
for (var i = 0; i < results.length; i++) {
var layout = new this.resultLayout(results[i]);
fragment.appendChild(layout.box);
this.layout.backend.push({
link: results[i].stamp.nickname,
dom: layout.box
})
}
this.dom.backendResults.appendChild(fragment);
if (this.dom.frame.style.display == "none") this.dom.frame.style.display = "block";
},
layout: {
backend: []
},
blockSubmit: function (e) {
var key = Jpy.getKeycode(e).keyCode;
if (key == 13 || key == 38 || key == 40 || key == 27 || key == 9) {
return false;
}
},
watchKeyCodes: function (e) {
var key = Jpy.getKeycode(e).keyCode;
if (key == 40 || key == 9) {
this.navigate.down();
}
else if (key == 38) {
this.navigate.up();
}
else if (key == 27) {
this.leave();
}
else if (key == 13) {
if (this.navigate.active != undefined) {
this.open();
}
else {
this.trigger.form.submit();
}
}
else {
Com.searchSuggest.prepare();
}
},
open: function () {
var nickname = this.layout[this.navigate.active.type][this.navigate.active.id].link;
if (User.profilePopup == "y") {
Jpy.popupProfile(nickname);
}
else {
location.href = "/user/"+this.layout[this.navigate.active.type][this.navigate.active.id].link;
}
this.leave();
},
navigate: {
start: "backend",
active: undefined,
up: function () {
if (this.active == undefined) {
return;
}
else {
if (this.active.type == "buddies" && this.active.id == 0) {
Com.searchSuggest.hoverResult(-1);
}
else if (this.active.type == "backend" && this.active.id == 0 && Com.searchSuggest.layout.buddies.length != 0) {
Com.searchSuggest.hoverResult(Com.searchSuggest.layout.buddies.length-1, "buddies");
}
else {
Com.searchSuggest.hoverResult(parseInt(this.active.id)-1, this.active.type);
}
}
},
down: function () {
if (Com.searchSuggest.layout.buddies.length == 0) {
this.start = "backend";
}
if (this.active == undefined) {
Com.searchSuggest.hoverResult(0, Com.searchSuggest.navigate.start);
}
else if (Com.searchSuggest.layout[this.active.type].length-1 > this.active.id) {
Com.searchSuggest.hoverResult(parseInt(this.active.id)+1, this.active.type);
}
else if (this.active.type == "buddies" && Com.searchSuggest.layout.backend.length != 0) {
Com.searchSuggest.hoverResult(0, "backend");
}
else {
return;
}
}
},
hoverResult: function (id, type) {
if (this.navigate.active != undefined) {
this.layout[this.navigate.active.type][this.navigate.active.id].dom.className = "entry cf";
}
if (id >= 0) {
this.layout[type][id].dom.className = "entry active cf";
this.navigate.active = {
id: id,
type: type
}
}
else {
this.navigate.active = undefined;
}
}
}
Com.kickUser = function(trigger, comId, userId, nickname) {
SystemMessage.confirm.show(nickname+" wirklich aus dieser Gruppe rauswerfen?", trigger, "window.location = '/com/"+comId+"/configuration/member/"+userId+"/delete?h="+User.hash+"'");
}
// Wed Jan  5 15:27:31 2011
