From b0e935d6af8eb37e423b8bb862e477d9e09af0f5 Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Sat, 6 Nov 2010 23:44:51 +0100 Subject: [PATCH] Remove ajax.js. A large part of ajax.js has been integrated as an extension of jQuery ($([selector]).updateHtml(), ...). Signed-off-by: Florent Bruneau --- htdocs/javascript/ajax.js | 115 ---------------------------------- htdocs/javascript/igoogle.js | 2 +- htdocs/javascript/profile.js | 26 ++++---- htdocs/javascript/xorg.js | 103 +++++++++++++++++++++++++++++- modules/admin.php | 1 - modules/email.php | 1 - modules/events.php | 3 - modules/lists.php | 1 - modules/profile.php | 1 - modules/search.php | 3 - modules/xnetgrp.php | 2 - templates/admin/user.tpl | 1 - templates/emails/alias.tpl | 6 +- templates/emails/antispam.tpl | 20 +++--- templates/emails/index.tpl | 16 +++-- templates/emails/redirect.tpl | 8 +-- templates/emails/send.tpl | 6 +- templates/events/form.tpl | 2 +- templates/events/index.tpl | 2 +- templates/gadgets/ig-skin.tpl | 1 - templates/include/tips.tpl | 2 +- templates/lists/index.tpl | 16 +++++ templates/lists/liste.inc.tpl | 10 +-- templates/profile/fiche_referent.tpl | 1 - templates/reminder/base.tpl | 6 +- templates/reminder/gapps.tpl | 4 +- templates/reminder/ml.tpl | 4 +- templates/reminder/profile_update.tpl | 2 +- templates/search/referent.tpl | 2 - templates/xnetevents/edit.tpl | 1 - templates/xnetgrp/edit.tpl | 1 - templates/xnetgrp/membres-add.tpl | 7 +-- 32 files changed, 184 insertions(+), 192 deletions(-) delete mode 100644 htdocs/javascript/ajax.js diff --git a/htdocs/javascript/ajax.js b/htdocs/javascript/ajax.js deleted file mode 100644 index 95ee31f..0000000 --- a/htdocs/javascript/ajax.js +++ /dev/null @@ -1,115 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2003-2010 Polytechnique.org * - * http://opensource.polytechnique.org/ * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software * - * Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - ***************************************************************************/ - -function AjaxEngine() -{ - this.update_html = function(obj, src, func) - { - $.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."); - } - }, '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: diff --git a/htdocs/javascript/igoogle.js b/htdocs/javascript/igoogle.js index b59adc1..67889c7 100644 --- a/htdocs/javascript/igoogle.js +++ b/htdocs/javascript/igoogle.js @@ -30,7 +30,7 @@ function markEventAsRead(event_id) _toggle(_gel("mark-read-" + event_id)); _gel("evt-" + event_id).setAttribute("class", "read"); _gel("link-" + event_id).setAttribute("href", "events/unread/" + event_id); - Ajax.update_html(null, "events/read/" + event_id); + $.xget("events/read/" + event_id, 'text'); return false; } diff --git a/htdocs/javascript/profile.js b/htdocs/javascript/profile.js index 7e6b683..9ba2071 100644 --- a/htdocs/javascript/profile.js +++ b/htdocs/javascript/profile.js @@ -71,10 +71,12 @@ function addSearchName(isFemale) while ($('#search_name_' + i).length != 0) { i++; } - Ajax.update_html('search_name_' + i, 'profile/ajax/searchname/' + i + '/' + isFemale, function(data){ - $('#searchname').before(data); - changeNameFlag(i); - }); + $('#search_name_' + i) + .updateHtml('profile/ajax/searchname/' + i + '/' + isFemale, + function(data) { + $('#searchname').before(data); + changeNameFlag(i); + }); } function removeSearchName(i, isFemale) @@ -111,11 +113,12 @@ function updateNameDisplay(isFemale) searchnames += $('#search_name_' + i).find(':text').val() + ';;'; } } - Ajax.update_html(null, 'profile/ajax/buildnames/' + searchnames + '/' + isFemale, function(data){ - var name = data.split(';'); - $('#public_name').html(name[0]); - $('#private_name').html(name[0] + name[1]); - }); + $.xget('profile/ajax/buildnames/' + searchnames + '/' + isFemale, 'text', + function(data){ + var name = data.split(';'); + $('#public_name').html(name[0]); + $('#private_name').html(name[0] + name[1]); + }); } function toggleParticle(id) @@ -315,7 +318,8 @@ function addAddress() i++; } $('#add_address').before('
'); - Ajax.update_html('addresses_' + i + '_cont', 'profile/ajax/address/' + i, checkCurrentAddress()); + $('#addresses_' + i + '_cont').updateHtml('profile/ajax/address/' + i, + checkCurrentAddress()); } function addressChanged(prefid) @@ -348,7 +352,7 @@ function addTel(prefid, prefname) i++; } $('#' + prefix + 'add').before('
'); - Ajax.update_html(prefix + i, 'profile/ajax/tel/' + prefid + '/' + prefname + '/' + i); + $('#' + prefix + i).updateHtml('profile/ajax/tel/' + prefid + '/' + prefname + '/' + i); } function removeTel(prefname, prefid, id) diff --git a/htdocs/javascript/xorg.js b/htdocs/javascript/xorg.js index 532e696..d804403 100644 --- a/htdocs/javascript/xorg.js +++ b/htdocs/javascript/xorg.js @@ -258,7 +258,6 @@ function auto_links() { // }}} - /*************************************************************************** * Password check */ @@ -359,6 +358,108 @@ function checkPassword(box, okLabel) { } // }}} +// {{{ jQuery object extension + +(function($) { + $.xget = function(source, type, onSuccess, onError) { + function ajaxHandler(data, textStatus) { + if (textStatus == 'success') { + if (onSuccess) { + onSuccess(data); + } + } else if (textStatus == 'error') { + if (onError) { + onError(data); + } else { + alert("Une error s'est produite lors du traitement de la requête.\n" + + "Ta session a peut-être expiré"); + } + } + } + $.get(source, ajaxHandler, type); + return false; + } + + $.fn.tmpMessage = function(message, success) { + if (success) { + this.html(" " + message) + .css('color', 'green'); + } else { + this.html(" " + message) + .css('color', 'red'); + } + return this.css('fontWeight', 'bold') + .show() + .delay(1000) + .fadeOut(500); + } + + $.fn.updateHtml = function(source, callback) { + var elements = this; + function handler(data) { + elements.html(data); + if (callback) { + callback(data); + } + } + $.xget(source, 'text', handler); + return this; + } + + $.fn.successMessage = function(source, message) { + var elements = this; + $.xget(source, 'text', function() { + elements.tmpMessage(message, true); + }); + return this; + } + + $.fn.wiki = function(text, withTitle) { + if (text == '') { + return this.html(''); + } + var url = 'wiki_preview'; + if (!withTitle) { + url += '/notitile'; + } + var $this = this; + $.post(url, { text: text }, + function (data) { + $this.html(data); + }, 'text'); + return this; + } +})(jQuery); + +// }}} +// {{{ preview wiki + +function previewWiki(idFrom, idTo, withTitle, idShow) +{ + $('#' + idTo).wiki($('#' + idFrom).val(), withTitle); + if (idShow != null) { + $('#' + idShow).show(); + } +} + +// }}} +// {{{ send test email + +function sendTestEmail(token, hruid) +{ + var url = 'emails/test'; + var msg = "Un email a été envoyé avec succès"; + if (hruid != null) { + url += '/' + hruid; + msg += " sur l'adresse de " + hruid + "."; + } else { + msg += " sur ton addresse."; + } + $('#mail_sent').successMessage($url + '?token=' + token, msg); + return false; +} + +// }}} /*************************************************************************** diff --git a/modules/admin.php b/modules/admin.php index e16538e..1271882 100644 --- a/modules/admin.php +++ b/modules/admin.php @@ -1075,7 +1075,6 @@ class AdminModule extends PLModule $page->changeTpl('admin/validation.tpl'); $page->setTitle('Administration - Valider une demande'); $page->addCssLink('nl.css'); - $page->addJsLink('ajax.js'); if ($action == 'edit' && !is_null($id)) { $page->assign('preview_id', $id); diff --git a/modules/email.php b/modules/email.php index 6f85504..8701f75 100644 --- a/modules/email.php +++ b/modules/email.php @@ -370,7 +370,6 @@ class EmailModule extends PLModule function handler_send(&$page) { $page->changeTpl('emails/send.tpl'); - $page->addJsLink('ajax.js'); $page->setTitle('Envoyer un email'); diff --git a/modules/events.php b/modules/events.php index 4888268..6997bc5 100644 --- a/modules/events.php +++ b/modules/events.php @@ -103,7 +103,6 @@ class EventsModule extends PLModule function handler_ev(&$page, $action = 'list', $eid = null, $pound = null) { $page->changeTpl('events/index.tpl'); - $page->addJsLink('ajax.js'); $user = S::user(); @@ -254,7 +253,6 @@ class EventsModule extends PLModule function handler_ev_submit(&$page) { $page->changeTpl('events/submit.tpl'); - $page->addJsLink('ajax.js'); $wp = new PlWikiPage('Xorg.Annonce'); $wp->buildCache(); @@ -332,7 +330,6 @@ class EventsModule extends PLModule function handler_admin_events(&$page, $action = 'list', $eid = null) { $page->changeTpl('events/admin.tpl'); - $page->addJsLink('ajax.js'); $page->setTitle('Administration - Evenements'); $page->register_modifier('hde', 'html_entity_decode'); diff --git a/modules/lists.php b/modules/lists.php index 5587714..894b807 100644 --- a/modules/lists.php +++ b/modules/lists.php @@ -91,7 +91,6 @@ class ListsModule extends PLModule $domain = $this->prepare_client($page); $page->changeTpl('lists/index.tpl'); - $page->addJsLink('ajax.js'); $page->setTitle('Listes de diffusion'); diff --git a/modules/profile.php b/modules/profile.php index be8648e..29ac6f5 100644 --- a/modules/profile.php +++ b/modules/profile.php @@ -328,7 +328,6 @@ class ProfileModule extends PLModule } // Build the page - $page->addJsLink('ajax.js'); $page->addJsLink('education.js', false); /* dynamic content */ $page->addJsLink('grades.js', false); /* dynamic content */ $page->addJsLink('profile.js'); diff --git a/modules/search.php b/modules/search.php index 06c729a..28b1c3b 100644 --- a/modules/search.php +++ b/modules/search.php @@ -66,7 +66,6 @@ class SearchModule extends PLModule $page->changeTpl('search/index.tpl'); $page->setTitle('Annuaire'); $page->assign('formulaire', 1); - $page->addJsLink('ajax.js'); return; } @@ -140,7 +139,6 @@ class SearchModule extends PLModule } } else { $page->assign('formulaire',1); - $page->addJsLink('ajax.js'); } $page->changeTpl('search/index.tpl'); @@ -192,7 +190,6 @@ class SearchModule extends PLModule } $page->changeTpl('search/index.tpl', $model == 'mini' ? SIMPLE : SKINNED); - $page->addJsLink('ajax.js'); $page->assign('public_directory',0); } diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php index 9187c47..b1f851b 100644 --- a/modules/xnetgrp.php +++ b/modules/xnetgrp.php @@ -253,7 +253,6 @@ class XnetGrpModule extends PLModule $globals->asso('mail_domain')); $page->assign('listes', $mmlist->get_lists()); $page->assign('user', S::user()); - $page->addJsLink('ajax.js'); if (Post::has('send')) { S::assert_xsrf_token(); @@ -628,7 +627,6 @@ class XnetGrpModule extends PLModule global $globals; $page->changeTpl('xnetgrp/membres-add.tpl'); - $page->addJsLink('ajax.js'); if (is_null($email)) { return; diff --git a/templates/admin/user.tpl b/templates/admin/user.tpl index 9e6e91d..6a27fd4 100644 --- a/templates/admin/user.tpl +++ b/templates/admin/user.tpl @@ -464,7 +464,6 @@ $(document).ready(function() { -{javascript name="ajax"} {test_email hruid=$user->login()}

Autres adresses de l'utilisateur

diff --git a/templates/emails/alias.tpl b/templates/emails/alias.tpl index 14e6cf6..2760d6a 100644 --- a/templates/emails/alias.tpl +++ b/templates/emails/alias.tpl @@ -36,15 +36,13 @@ {if $actuel} - {javascript name=ajax} {if $user->hasProfile()}
baseurl}/emails/alias/set/'+(this.checked?'public':'private')+'?token={xsrf_token}'); + $('#mail_public').html((this.checked?'public et apparaît donc sur ta fiche':'privé et n\'apparaît nulle part sur le site') + '.'); " /> diff --git a/templates/emails/antispam.tpl b/templates/emails/antispam.tpl index 12d1cdd..16fabfb 100644 --- a/templates/emails/antispam.tpl +++ b/templates/emails/antispam.tpl @@ -22,27 +22,29 @@ {include wiki=Xorg.Antispam part=1} -{javascript name=ajax}
Choisis ton propre réglage : - +
- +
- +
- +
diff --git a/templates/emails/index.tpl b/templates/emails/index.tpl index 8146bfe..97a5c23 100644 --- a/templates/emails/index.tpl +++ b/templates/emails/index.tpl @@ -22,12 +22,18 @@

Gestion de mes emails

-{javascript name=ajax} {literal} {/literal} @@ -38,7 +44,7 @@ Tes adresses polytechniciennes sont :
{iterate from=$aliases item=a} -
{if $liste.sub eq 2} + onclick="return updateHtml('list_{$liste.list}', '{$platal->ns}lists/ajax/{$liste.list}?unsubscribe=1&token={xsrf_token}');"> {icon name=cross title="me désinscrire"} {elseif $liste.sub eq 1} {icon name=flag_orange title='inscription en attente de modération'} {else} + onclick="return updateHtml('list_{$liste.list}', '{$platal->ns}lists/ajax/{$liste.list}?subscribe=1&token={xsrf_token}');"> {icon name=add title="m'inscrire"} {/if} diff --git a/templates/profile/fiche_referent.tpl b/templates/profile/fiche_referent.tpl index a35e521..737332c 100644 --- a/templates/profile/fiche_referent.tpl +++ b/templates/profile/fiche_referent.tpl @@ -20,7 +20,6 @@ {* *} {**************************************************************************} -{javascript name=ajax} {assign var=terms value=$profile->getMentoringTerms()} {assign var=countries value=$profile->getMentoringCountries()}
diff --git a/templates/reminder/base.tpl b/templates/reminder/base.tpl index a7a5277..31b93de 100644 --- a/templates/reminder/base.tpl +++ b/templates/reminder/base.tpl @@ -38,13 +38,13 @@ {$reminder->text()}
- + {icon name=add} M'inscrire - - + {icon name=delete} Ne pas m'inscrire - - + {icon name=cross} Décider plus tard {if $reminder->info()} diff --git a/templates/reminder/gapps.tpl b/templates/reminder/gapps.tpl index 7304234..0ce784c 100644 --- a/templates/reminder/gapps.tpl +++ b/templates/reminder/gapps.tpl @@ -30,10 +30,10 @@ {icon name=add} M'inscrire - - + {icon name=delete} Ne pas m'inscrire - - + {icon name=cross} Décider plus tard - {icon name=information} En savoir plus diff --git a/templates/reminder/ml.tpl b/templates/reminder/ml.tpl index e53b7d8..a576a24 100644 --- a/templates/reminder/ml.tpl +++ b/templates/reminder/ml.tpl @@ -41,10 +41,10 @@ diff --git a/templates/reminder/profile_update.tpl b/templates/reminder/profile_update.tpl index 55bf9db..f5ebef8 100644 --- a/templates/reminder/profile_update.tpl +++ b/templates/reminder/profile_update.tpl @@ -51,7 +51,7 @@ {/if} diff --git a/templates/search/referent.tpl b/templates/search/referent.tpl index ab57b71..d7a5839 100644 --- a/templates/search/referent.tpl +++ b/templates/search/referent.tpl @@ -33,14 +33,12 @@ Actuellement, {$mentors_number} mentors et référents se sont déclarés sur {#globals.core.sitename#}.

-{javascript name=ajax} {javascript name=jquery.jstree} {javascript name=jobtermstree} -- 2.1.4