X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=htdocs%2Fjavascript%2Fajax.js;h=95ee31f2aa451828909cf1235d1a8742e5318e31;hb=b4816e6f8d43f267a1cfba62ab9d67e5575822e6;hp=ec485a7a7ccf89ddb05712bcd43e1fd9ca18d46d;hpb=7743e0e58199e7d59177ab8a6bac8a6310456c86;p=platal.git
diff --git a/htdocs/javascript/ajax.js b/htdocs/javascript/ajax.js
index ec485a7..95ee31f 100644
--- a/htdocs/javascript/ajax.js
+++ b/htdocs/javascript/ajax.js
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2003-2006 Polytechnique.org *
+ * Copyright (C) 2003-2010 Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -18,45 +18,98 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************/
-Ajax = {
- xml_client: null,
- init: false,
-
- prepare_client: function()
- {
- if (!Ajax.init) {
- if (window.XMLHttpRequest) {
- Ajax.xml_client = new XMLHttpRequest();
- } else if (window.ActiveXObject) {
- try {
- Ajax.xml_client = new ActiveXObject("Msxml2.XMLHTTP");
- } catch (e) {
- Ajax.xml_client = new ActiveXObject("Microsoft.XMLHTTP");
- }
- }
- if (Ajax.xml_client == null) {
- alert("Ton client ne supporte pas Ajax, nécessaire pour certaines fonctionalités de cette page");
- }
- }
- Ajax.init = true;
- },
-
- update_html: function(obj, src)
+function AjaxEngine()
+{
+ this.update_html = function(obj, src, func)
{
- Ajax.prepare_client();
- if (Ajax.xml_client == null) {
- return true;
- }
- Ajax.xml_client.onreadystatechange =
- function()
- {
- if(Ajax.xml_client.readyState == 4) {
- document.getElementById(obj).innerHTML = Ajax.xml_client.responseText;
+ $.get(src,
+ function(data, textStatus) {
+ if (textStatus == "success") {
+ if (obj) {
+ $('#' + obj).html(data);
+ }
+ if (func)Â {
+ func(data);
+ }
+ } else if (textStatus == "error") {
+ alert("Une erreur s'est produite lors du traitement de la requête.\n"
+ +"Ta session a peut-être expirée.");
}
- };
- Ajax.xml_client.open ('GET', src, true);
- Ajax.xml_client.send (null);
+ }, 'text');
+ return false;
+ }
+}
+
+var Ajax = new AjaxEngine();
+
+var currentTempMessage = 0;
+function setOpacity(obj, opacity)
+{
+ opacity = (opacity == 100)?99:opacity;
+ // IE
+ obj.style.filter = "alpha(opacity:"+opacity+")";
+ // Safari < 1.2, Konqueror
+ obj.style.KHTMLOpacity = opacity/100;
+ // Old Mozilla
+ obj.style.MozOpacity = opacity/100;
+ // Safari >= 1.2, Firefox and Mozilla, CSS3
+ obj.style.opacity = opacity/100
+}
+
+function _showTempMessage(id, state, back)
+{
+ var obj = document.getElementById(id);
+ if (currentTempMessage != state) {
+ return;
+ }
+ setOpacity(obj, back * 4);
+ if (back > 0) {
+ setTimeout("_showTempMessage('" + id + "', " + currentTempMessage + "," + (back-1) + ")", 125);
+ } else {
+ obj.innerHTML = "";
+ }
+}
+
+function showTempMessage(id, message, success)
+{
+ var obj = document.getElementById(id);
+ obj.innerHTML = (success ? " "
+ : " ") + message;
+ obj.style.fontWeight = "bold";
+ obj.style.color = (success ? "green" : "red");;
+ currentTempMessage++;
+ setOpacity(obj, 100);
+ setTimeout("_showTempMessage('" + id + "', " + currentTempMessage + ", 25)", 1000);
+}
+
+function previewWiki(idFrom, idTo, withTitle, idShow)
+{
+ var text = document.getElementById(idFrom).value;
+ if (text == "") {
return false;
}
+ var url = "wiki_preview";
+ if (!withTitle) {
+ url += "/notitle";
+ }
+ $.post(url, { text: text },
+ function(data) {
+ $("#" + idTo).html(data);
+ },
+ 'text');
+ if (idShow != null) {
+ document.getElementById(idShow).style.display = "";
+ }
+}
+
+function sendTestEmail(token, hruid)
+{
+ Ajax.update_html(null, 'emails/test' + (hruid == null ? '' : '/' + hruid) + '?token=' + token,
+ function() {
+ showTempMessage('mail_sent', "Un email a été envoyé avec succès"
+ + (hruid == null ? " sur ton adresse." : " sur l'adresse de " + hruid),
+ true); });
+ return false;
}
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: