mc_edit.inc.js 11.8 KB
var var_kind;
var var_bgColor="#f3f3f3";
var var_borderColor="#d0d1d0";
var var_xmlWindow;
var var_ul;
var var_body;
var var_div;
var var_http = null;
var var_window_width="580";
var var_targetInput;
var var_src = "http://localhost/losp/";
var obj_urls = new Object();
obj_urls["service"] = "service.php?output=xml&p[0]=showSingle&p[1]=ID&p[2]=";
obj_urls["c"] = "&c[";
obj_urls["image"] = "&p[3]=FileBC";
obj_urls["image_c"] = "][FileBC][0][ListCondition-equal][Mime][1]=image";
obj_urls["friend"] = "&p[3]=FriendList";
obj_urls["friend_c"] = false;

obj_urls["next"] = false;
obj_urls["back"] = false;
var obj_text = new Object();
obj_text["image"] = "Bitte ein Bild aussuchen:";
obj_text["friend"] = "Bitte Freundschaften aussuchen:";


var a_next;
var i_next;
var a_back;
var i_back;
var var_NaB;
var var_id;
function fnc_xmlChooser(id, kind, target){
	var_kind=kind;
	var_id=id;
	var_targetInput = target;
	fnc_newWindow();
	fnc_mkDiv(kind);
	fnc_loading(var_div, true);
	fnc_mkHttp(kind);
}

function fnc_newWindow(title, adress){
	var_xmlWindow = window.open (
		"",
		"Dateien", // Name des neuen Fensters
		+"toolbar=0" // Toolbar
		+",location=0" // Adress-Leiste
		+",directories=0" // Zusatzleisten
		+",status=0" // Statusleiste
		+",menubar=0" // Men
		+",scrollbars=0" // Scrollbars
		+",resizable=0" // Fenstergrsse vernderbar?
		+",width="+var_window_width+"px" // Fensterbreite in Pixeln
		//+",height=500" // Fensterhhe in Pixeln
	);
	var_body = var_xmlWindow.document.getElementsByTagName('body')[0];
	var_body.focus();
	var_body.style.backgroundColor=var_bgColor;
//	window.document.getElementsByTagName('body')[0].setAttribute("onFocus","javascript:var_xmlWindow.close()");

}
function fnc_mkDiv(kind){
	var_div = var_xmlWindow.document.createElement('div');
	var_div.style.display = "block";
	var_div.style.cssFloat="left";
	var_div.style.width=var_window_width+"px";

	var_body.appendChild(var_xmlWindow.document.createTextNode(obj_text[kind]));
	var_ul = var_xmlWindow.document.createElement('ul');
	var_ul.style.cssFloat="left";
	var_ul.style.padding="0px";
	var_ul.style.listStyle="none";
	var_ul.style.backgroundColor="white";

	a_next = document.createElement("div");
	a_next.style.background="url('include/Forest/mensch.coop/Images/buttonAll.png') -20px -160px no-repeat";
	a_next.style.width="20px";
	a_next.style.height="20px";
	a_next.style.cssFloat="right";
	a_next.style.textDecoration="none";
/*	a_next.onmouseover = fnc_nextMouseover;
	a_next.onmouseout = fnc_nextMouseout;
	a_next.onclick = fnc_nextOnclick;*/

	i_next = document.createElement("div");
	i_next.style.background="url('include/Forest/mensch.coop/Images/buttonAll.png') -20px -300px no-repeat";
	i_next.style.width="20px";
	i_next.style.height="20px";
	i_next.style.cssFloat="right";
	i_next.style.textDecoration="none";

	a_back = document.createElement("div");
	a_back.style.background="url('include/Forest/mensch.coop/Images/buttonAll.png') -20px -140px no-repeat";
	a_back.style.width="20px";
	a_back.style.height="20px";
	a_back.style.cssFloat="left";
	a_back.style.textDecoration="none";
/*	a_back.onmouseover = fnc_backMouseover;
	a_back.onmouseout = fnc_backMouseout;
	a_back.onclick = fnc_backOnclick;*/

	i_back = document.createElement("div");
	i_back.style.background="url('include/Forest/mensch.coop/Images/buttonAll.png') 0px -300px no-repeat";
	i_back.style.width="20px";
	i_back.style.height="20px";
	i_back.style.cssFloat="left";
	i_back.textDecoration="none";

  	var_NaB = var_xmlWindow.document.createElement('div');
  	var_NaB.style.margin="auto";
 	var_NaB.style.width="100px";
 	var_NaB.style.height="28px";
 	var_NaB.style.display="block";
 	var_div.appendChild(var_NaB);
 	var_div.appendChild(var_ul);
	var_body.appendChild(var_div);


}
function fnc_loading(where, start){
	if(start){
		var var_imageLoad = new Image();
		var_imageLoad.setAttribute("id", "loading");
		var_imageLoad.hspace=var_window_width/2-50;
		var_imageLoad.src = "include/Forest/mensch.coop/Images/loading.gif";
		where.appendChild(var_imageLoad);
	}
	else{
		where.removeChild(var_xmlWindow.document.getElementById("loading"));
	}
}
function fnc_mkHttp(kind){

	if (window.XMLHttpRequest) {
	   var_http = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
	   var_http = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if(var_http != null) {
//	   var_http.open("GET", "service.php?output=xml&p[0]=showSingle&p[1]=ID&p[2]=6&p[3]=FileBC&c[6][FileBC][0][ListCondition-equal][Mime][1]=image", true);
		if(kind != "next" || kind != "back"){
			var tmp_url=obj_urls["service"]+var_id+obj_urls[kind];
			if(obj_urls[kind+"_c"]!=false){
				tmp_url=tmp_url+obj_urls["c"]+var_id+obj_urls[kind+"_c"];
			}
			var_http.open("GET", tmp_url, true);
	   	}
	   	else{
	   		var_http.open("GET", obj_urls[kind], true);
	   	}
	   	var_http.onreadystatechange = fnc_mkContent;
	   	var_http.send(null);
	}
}

function fnc_mkContent() {

	fnc_clearNaB();

	if(var_http.readyState == 4){
		fnc_loading(var_div, false);
		var daten = var_http.responseText;
	    if (window.ActiveXObject) {
    		var xml = new ActiveXObject("Microsoft.XMLDOM");
			xml.loadXML(daten);
		} else if (document.implementation) {
			var xml = (new DOMParser()).parseFromString(daten, "text/xml");
		}

	  	var var_be=xml.getElementsByTagName("BasisElement");
	  	switch (var_kind){
			case "image" :
						  	for (var i = 0; i < var_be.length; i++) {
						  		var var_li = var_xmlWindow.document.createElement('li');

								var_li.style.cssFloat="left";
								var_li.style.width="100px";
								var_li.style.paddingTop="2px";
								var_li.style.margin="4px";
								var_li.style.overflow="hidden";
								var_li.style.border="3px solid "+var_bgColor;
								var_li.onmouseover = fnc_liMouseover;
								var_li.onclick = fnc_liFileOnclick;
								var_li.onmouseout = fnc_liMouseout;

						  		if(var_be[i].getAttribute("class")=="FileBE" && var_be[i].parentNode.getAttribute("class")=="FileBC"){
						  			var var_headline=var_xmlWindow.document.createTextNode(var_be[i].getElementsByTagName("Headline")[0].getElementsByTagName("Element")[0].firstChild.nodeValue)
						  			var_li.appendChild(var_headline);
						  			var var_element=var_be[i].getElementsByTagName("Element");
						  			for (var j = 0; j < var_element.length; j++) {
						  				if(var_element[j].getAttribute("type")=="file"){
						  					if(var_kind=='image'){
							  					var var_url = var_element[j].firstChild.nodeValue;
							  					var image = new Image();
							  					image.height=100;
							  					image.width=100;
							  					var_li.name="files/"+var_url;
							  					//image.src = var_src+"files/"+var_url.replace(/(\/)/, "/tn_");
							  					image.src = "files/"+var_url.replace(/(\/)/, "/tn_");
							  					var_li.appendChild(image);
							  				}
						  				}
						  			}
									var_ul.appendChild(var_li);
						  		}
						  	}
						  	break;
			case "friend" :
							for (var i = 0; i < var_be.length; i++) {

						  		var var_li = var_xmlWindow.document.createElement('li');

								var_li.style.width="200px";
								var_li.style.paddingTop="2px";
								var_li.style.margin="4px";
								var_li.style.overflow="hidden";
								var_li.style.border="3px solid "+var_bgColor;
								var_li.onmouseover = fnc_liMouseover;
								var_li.onclick = fnc_liFriendOnclick;
								var_li.onmouseout = fnc_liMouseout;


								if(var_be[i].getAttribute("class")=="Profile" && var_be[i].parentNode.getAttribute("class")=="FriendList"){



									var tmp_text=var_be[i].getElementsByTagName("Headline")[0].getElementsByTagName("Element")[0].firstChild.nodeValue;

									var tmp_headline=var_xmlWindow.document.createTextNode("   "+tmp_text)

									var_li.name=var_be[i].getAttribute("id")+"-"+tmp_text;

				  					var var_element=var_be[i].getElementsByTagName("Element");

		  							var image = new Image();
				  					image.height=20;
				  					image.width=20;
				  					image.src="include/Forest/mensch.coop/Images/Avatar.png";
						  			for (var j = 0; j < var_element.length; j++) {
						  				if(var_element[j].getAttribute("objvar")=="Avatar"){
						  					var var_url = var_element[j].nodeValue;
						  					if(var_url != null){
						  						image.src=var_url;
						  					}
						  				}
						  			}
				  					var_li.appendChild(image);
						  			var_li.appendChild(tmp_headline);

					  				var_ul.appendChild(var_li);
						  		}
						  	}
							break;
		}

		fnc_mkNaB(xml);

   }
   function fnc_mkNaB(xml){
   		var var_link=xml.getElementsByTagName("Link");

		for (var i = 0; i < var_link.length; i++) {
	  		if(var_link[i].getAttribute("kind")=="back"){
	  			obj_urls["back"] = "service.php?output=xml&"+var_link[i].getAttribute("parameter");

		  	}
		  	else if(var_link[i].getAttribute("kind")=="next"){
				obj_urls["next"] = "service.php?output=xml&"+var_link[i].getAttribute("parameter");

		  	}
	  	}
	  	if(obj_urls["next"]!=false){
			var_NaB.appendChild(a_next);
			a_next.onmouseover = fnc_nextMouseover;
			a_next.onmouseout = fnc_nextMouseout;
			a_next.onclick = fnc_nextOnclick;
		}

		else{
			var_NaB.appendChild(i_next);
		}

		if(obj_urls["back"]!=false){
			var_NaB.appendChild(a_back);
			a_back.onmouseover = fnc_backMouseover;
			a_back.onmouseout = fnc_backMouseout;
			a_back.onclick = fnc_backOnclick;
		}
		else{
			var_NaB.appendChild(i_back);
		}




   }
	function fnc_clearUl(){
		var var_lis = var_ul.getElementsByTagName("li");
		for(var i = var_lis.length-1; i >= 0; i--) {
			var_ul.removeChild(var_lis[i]);
		}
	}
	function fnc_clearNaB(){
		obj_urls["next"]=false;
		obj_urls["back"]=false;
		for(var i = var_NaB.getElementsByTagName("div").length - 1; i >= 0; i--) {
			var_NaB.removeChild(var_NaB.getElementsByTagName("div")[i]);
		}
	}
	function fnc_nextOnclick(){
		fnc_clearUl();
		fnc_loading(var_div, true);
		fnc_mkHttp("next");
	}
	function fnc_backOnclick(){
		fnc_clearUl();
		fnc_loading(var_div, true);
		fnc_mkHttp("back");
	}
	function fnc_nextMouseover(){
		this.style.cursor="pointer";
	//	this.style.background="url('include/Forest/mensch.coop/Images/buttonAll.png') 0px -160px no-repeat";
	}
	function fnc_nextMouseout(){
		//this.style.background="url('include/Forest/mensch.coop/Images/buttonAll.png') -20px -160px no-repeat";
	}
	function fnc_backMouseover(){
		this.style.cursor="pointer";
	//	this.style.background="url('include/Forest/mensch.coop/Images/buttonAll.png') 0px -160px no-repeat";
	}
	function fnc_backMouseout(){
		//this.style.background="url('include/Forest/mensch.coop/Images/buttonAll.png') -20px -160px no-repeat";
	}
	function fnc_liMouseover(){
		this.style.cursor="pointer";
		this.style.border="3px solid "+var_borderColor;
	}
	function fnc_liFileOnclick(){
		window.document.getElementById(var_targetInput).value=this.getAttribute("name");
		var_xmlWindow.close();
	}
	function fnc_chkElementExists(param_target, param_name, param_attribute, param_value){
		var tmp_elementArray = param_target.getElementsByTagName(param_name);
		for(var i = tmp_elementArray.length -1; i >= 0; i--) {
			if(tmp_elementArray[i].getAttribute(param_attribute).substring(0,tmp_elementArray[i].getAttribute(param_attribute).indexOf("-")) == param_value){
				return true;
			}
		}
		return false;
	}
	function fnc_liFriendOnclick(){

		if(!fnc_chkElementExists(window.document.getElementById(var_targetInput), "li", "name", this.name.substring(0,this.name.indexOf("-")))){
			var tmp_li = window.document.createElement('li');
			tmp_li.name=this.name;
			var tmp_input=window.document.createElement('input');
			tmp_input.type="checkbox";
			tmp_input.name="ReadSelected[]";
			tmp_input.checked="checked";
			tmp_input.value=this.name.substring(0,this.name.indexOf("-"));
			tmp_li.appendChild(tmp_input);
			tmp_li.appendChild(var_xmlWindow.document.createTextNode(this.name.substr(this.name.indexOf("-")+1)))
			window.document.getElementById(var_targetInput).appendChild(tmp_li);
		}

	}
	function fnc_liMouseout(){
		this.style.border="3px solid "+var_bgColor;
	}
}