| 1 | /*************************************************************************** |
| 2 | * Copyright (C) 2003-2009 Polytechnique.org * |
| 3 | * http://opensource.polytechnique.org/ * |
| 4 | * * |
| 5 | * This program is free software; you can redistribute it and/or modify * |
| 6 | * it under the terms of the GNU General Public License as published by * |
| 7 | * the Free Software Foundation; either version 2 of the License, or * |
| 8 | * (at your option) any later version. * |
| 9 | * * |
| 10 | * This program is distributed in the hope that it will be useful, * |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 13 | * GNU General Public License for more details. * |
| 14 | * * |
| 15 | * You should have received a copy of the GNU General Public License * |
| 16 | * along with this program; if not, write to the Free Software * |
| 17 | * Foundation, Inc., * |
| 18 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
| 19 | ***************************************************************************/ |
| 20 | |
| 21 | function AjaxEngine() |
| 22 | { |
| 23 | this.update_html = function(obj, src, func) |
| 24 | { |
| 25 | $.get(src, |
| 26 | function(data, textStatus) { |
| 27 | if (textStatus == "success") { |
| 28 | if (obj) { |
| 29 | $('#' + obj).html(data); |
| 30 | } |
| 31 | if (func) { |
| 32 | func(data); |
| 33 | } |
| 34 | } else if (textStatus == "error") { |
| 35 | alert("Une erreur s'est produite lors du traitement de la requête.\n" |
| 36 | +"Ta session a peut-être expirée."); |
| 37 | } |
| 38 | }, 'text'); |
| 39 | return false; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | var Ajax = new AjaxEngine(); |
| 44 | |
| 45 | var currentTempMessage = 0; |
| 46 | function setOpacity(obj, opacity) |
| 47 | { |
| 48 | opacity = (opacity == 100)?99:opacity; |
| 49 | // IE |
| 50 | obj.style.filter = "alpha(opacity:"+opacity+")"; |
| 51 | // Safari < 1.2, Konqueror |
| 52 | obj.style.KHTMLOpacity = opacity/100; |
| 53 | // Old Mozilla |
| 54 | obj.style.MozOpacity = opacity/100; |
| 55 | // Safari >= 1.2, Firefox and Mozilla, CSS3 |
| 56 | obj.style.opacity = opacity/100 |
| 57 | } |
| 58 | |
| 59 | function _showTempMessage(id, state, back) |
| 60 | { |
| 61 | var obj = document.getElementById(id); |
| 62 | if (currentTempMessage != state) { |
| 63 | return; |
| 64 | } |
| 65 | setOpacity(obj, back * 4); |
| 66 | if (back > 0) { |
| 67 | setTimeout("_showTempMessage('" + id + "', " + currentTempMessage + "," + (back-1) + ")", 125); |
| 68 | } else { |
| 69 | obj.innerHTML = ""; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | function showTempMessage(id, message, success) |
| 74 | { |
| 75 | var obj = document.getElementById(id); |
| 76 | obj.innerHTML = (success ? "<img src='images/icons/wand.gif' alt='' /> " |
| 77 | : "<img src='images/icons/error.gif' alt='' /> ") + message; |
| 78 | obj.style.fontWeight = "bold"; |
| 79 | obj.style.color = (success ? "green" : "red");; |
| 80 | currentTempMessage++; |
| 81 | setOpacity(obj, 100); |
| 82 | setTimeout("_showTempMessage('" + id + "', " + currentTempMessage + ", 25)", 1000); |
| 83 | } |
| 84 | |
| 85 | function previewWiki(idFrom, idTo, withTitle, idShow) |
| 86 | { |
| 87 | var text = document.getElementById(idFrom).value; |
| 88 | if (text == "") { |
| 89 | return false; |
| 90 | } |
| 91 | var url = "wiki_preview"; |
| 92 | if (!withTitle) { |
| 93 | url += "/notitle"; |
| 94 | } |
| 95 | $.post(url, { text: text }, |
| 96 | function(data) { |
| 97 | $("#" + idTo).html(data); |
| 98 | }, |
| 99 | 'text'); |
| 100 | if (idShow != null) { |
| 101 | document.getElementById(idShow).style.display = ""; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | function sendTestEmail(token, hruid) |
| 106 | { |
| 107 | Ajax.update_html(null, 'emails/test' + (hruid == null ? '' : '/' + hruid) + '?token=' + token, |
| 108 | function() { |
| 109 | showTempMessage('mail_sent', "Un email a été envoyé avec succès" |
| 110 | + (hruid == null ? " sur ton adresse." : " sur l'adresse de " + hruid), |
| 111 | true); }); |
| 112 | return false; |
| 113 | } |
| 114 | |
| 115 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |