Bontiv-Sourceer source code viewer
Root | Help
./wordpress-bontivCalendar/adminExt.js
/**
* Commons fonctions
**/
Action = {
Active: 'confirm',
onError: function(){},
onFinish: function(){},
onglets: new Array('NewEvent', 'confirm', 'Table', 'load'),

Hide: function(){
document.getElementById(this.Active).style.display = 'none';
},
Show: function(){
document.getElementById(this.Active).style.display = 'bloc';
},
yes: function(){
this.Hide();
this.onFinish();
},
no: function(){
this.Hide();
this.onError();
},
setYes: function(){
document.getElementById('start_houre').removeAttribute("disabled");
document.getElementById('start_min').removeAttribute("disabled");
document.getElementById('end_month').removeAttribute("disabled");
document.getElementById('end_year').removeAttribute("disabled");
document.getElementById('end_min').removeAttribute("disabled");
document.getElementById('end_houre').removeAttribute("disabled");
document.getElementById('end_day').removeAttribute("disabled");
},
setNo: function(){
document.getElementById('start_houre').setAttribute("disabled", null);
document.getElementById('start_min').setAttribute("disabled", null);
document.getElementById('end_houre').setAttribute("disabled", null);
document.getElementById('end_min').setAttribute("disabled", null);
document.getElementById('end_day').setAttribute("disabled", null);
document.getElementById('end_month').setAttribute("disabled", null);
document.getElementById('end_year').setAttribute("disabled", null);
},
Display: function(Onglet){
for(var i = 0; i < this.onglets.length; i++)
document.getElementById(this.onglets[i]).style.display = 'none';
document.getElementById(Onglet).style.display = 'block';
},
Reset: function(){
document.getElementById('title').value = '';
document.getElementById('text').value = '';
},
Go: function(){
if (document.getElementById('title').value == '') {
alert('Vous devez spécifier un titre');
return false;
}
if (document.getElementById('text').value == '') {
alert('Vous devez spécifier un texte');
return false;
}

//Lecture du formulaire
var args = new Array();
for (var i = 0; i < document.forms["NewEvent"].elements.length; i++)
{
args[document.forms["NewEvent"].elements[i].name] = document.forms["NewEvent"].elements[i].value;
}
args["fullday"] = document.getElementById('yes').checked;

//céation de la chaine
var str = "";
for (var elemt in args)
str += "&" + elemt + "=" + UrlEncoder(args[elemt]);

//envoi des donnés
var sender = new ajax();
sender.Query("calendaraction=new", str);
return false;
}

}

EventList = {
Clear: function(){
document.getElementById('EventList').innerHTML = '';
},

Add: function(id, title, date){
var row = document.createElement('tr');

var td = document.createElement('td');
var text = document.createTextNode(title);
td.appendChild(text);
row.appendChild(td);

var td = document.createElement('td');
var text = document.createTextNode(date);
td.appendChild(text);
row.appendChild(td);

var td = document.createElement('td');
var a = document.createElement('a');
var text = document.createTextNode("Supprimer");
a.appendChild(text);
a.setAttribute("href","javascript:EventList.Delete(\""+id+"\");",false);
td.appendChild(a);
row.appendChild(td);

document.getElementById('EventList').appendChild(row);
},

Delete: function(id){
var sender = new ajax();
sender.Query("calendaraction=delete&event=" + id);
Action.Display('load');
}
}

/**
 * Translate a string to his URL format
 * @access public
 * @return string
 **/
 function UrlEncoder(url)
 {
if (typeof url === "string")
{
while (url.search(/=/) >= 0)
url = url.replace(/=/, "%3d");
while (url.search(/ /) >= 0)
url = url.replace(/ /, "%20");
while (url.search(/\?/) >= 0)
url = url.replace(/\?/, "%3f");
while (url.search(/\+/) >= 0)
url = url.replace(/\+/, "%2b");
while (url.search(/:/) >= 0)
url = url.replace(/:/, "%3a");
while (url.search(/\//) >= 0)
url = url.replace(/\//, "%2f");
while (url.search(/;/) >= 0)
url = url.replace(/;/, "%3b");
}
return url;
 }

/**
 * Test if a variable is undefined
 * @access public
 * @return bool
 **/
function isUndefined(object) {
  return typeof object === "undefined";
}

var xhr = null;
if(window.XMLHttpRequest) // Firefox et autres
   xhr = XMLHttpRequest();
else if(window.ActiveXObject){ // Internet Explorer
   try {
               xhr = ActiveXObject("Msxml2.XMLHTTP");
           } catch (e) {
               xhr = ActiveXObject("Microsoft.XMLHTTP");
           }
}
else { // XMLHttpRequest non supporté par le navigateur
   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
   xhr = false;
}

ajax = function(){
this.Query = function(URLparams, POSTparam){
Action.Display('load');
if (isUndefined(POSTparam) || POSTparam == null) {
this.open('GET', document.location.pathname+"?"+URLparams, true);
this.send(null);
} else {
this.open('POST', document.location.pathname+"?"+URLparams, true);
this.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
this.send(POSTparam);
}
}
}
ajax.prototype = xhr;
ajax.prototype.onFinish = function(){
var doc = this.responseXML.getElementsByTagName("ajax")[0];
for (var i = 0; i < doc.childNodes.length; i++)
{
var action = doc.childNodes[i];
switch (action.nodeName)
{
case 'popup':
alert(action.firstChild.data);
break;
case 'display':
Action.Display(action.firstChild.data);
break;
case "elements":
EventList.Clear();
for (var e = 0; e < action.childNodes.length; e++)
{
var event = action.childNodes[e];
var id = event.getAttribute("id");
var title = "";
var date = "";
for (var j = 0; j < event.childNodes.length; j++)
{
if (event.childNodes[j].nodeName == "title") {
title = event.childNodes[j].firstChild.data;
} else if (event.childNodes[j].nodeName == "start"){
date = event.childNodes[j].firstChild.data;
}
}
EventList.Add(id, title, date);
}
break;
case 'update':
Update();
break;
default:
alert('Undefined action: '+action.nodeName);
}
}
}
ajax.prototype.onEror = function(){
alert('Une erreur est survenu lors de la communication');
}

ajax.prototype.onreadystatechange = function(){
if (this.readyState == 4)
switch(Math.ceil(this.status / 100)){
case 2:
this.onFinish();
break;
case 4:
case 5:
this.onFinish();
break;
default:
alert('Undefined error: ' + this.status + ' (' + this.statusText + ')');
} // switch
}

/**
 *
 * @access public
 * @return void
 **/
function Update(){
var updater = new ajax();
updater.Query("calendaraction=update");
}

/**
 * Show a dialog box
 * @access public
 * @return void
 **/
function ShowBox(boxID, arg){
switch(boxID){
default:
alert('Dialog error: dialog box not found ('+boxID+'/'+arg+')');
return false;
} // switch
}

//setTimeout('Action.Display(\'Table\');', 1500);
Presented with Bontiv-Sourceer