muzich.js 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. /*
  2. * Scripts de Muzi.ch
  3. * Rédigé et propriété de Sevajol Bastien (http://www.bux.fr) sauf si mention
  4. * contraire sur la fonction.
  5. *
  6. */
  7. // Controle du focus sur la page
  8. function onBlur() {
  9. document.body.className = 'blurred';
  10. }
  11. function onFocus(){
  12. document.body.className = 'focused';
  13. }
  14. if (/*@cc_on!@*/false) { // check for Internet Explorer
  15. document.onfocusin = onFocus;
  16. document.onfocusout = onBlur;
  17. } else {
  18. window.onfocus = onFocus;
  19. window.onblur = onBlur;
  20. }
  21. // Messages flashs
  22. var myMessages = ['info','warning','error','success']; // define the messages types
  23. function hideAllMessages()
  24. {
  25. var messagesHeights = new Array(); // this array will store height for each
  26. for (i=0; i<myMessages.length; i++)
  27. {
  28. messagesHeights[i] = $('.' + myMessages[i]).outerHeight();
  29. $('.' + myMessages[i]).css('top', -messagesHeights[i]); //move element outside viewport
  30. }
  31. }
  32. $(document).ready(function(){
  33. // Initially, hide them all
  34. hideAllMessages();
  35. $('.message').animate({top:"0"}, 500);
  36. // When message is clicked, hide it
  37. $('.message a.message-close').click(function(){
  38. $(this).parent('.message').animate({top: -$(this).outerHeight()-50}, 700);
  39. return false;
  40. });
  41. });
  42. function findKeyWithValue(arrayt, value)
  43. {
  44. for(i in arrayt)
  45. {
  46. if (arrayt[i] == value)
  47. {
  48. return i;
  49. }
  50. }
  51. return "";
  52. }
  53. function json_to_array(json_string)
  54. {
  55. if (json_string.length)
  56. {
  57. return eval("(" + json_string + ")");
  58. }
  59. return new Array();
  60. }
  61. function strpos (haystack, needle, offset) {
  62. // Finds position of first occurrence of a string within another
  63. //
  64. // version: 1109.2015
  65. // discuss at: http://phpjs.org/functions/strpos // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  66. // + improved by: Onno Marsman
  67. // + bugfixed by: Daniel Esteban
  68. // + improved by: Brett Zamir (http://brett-zamir.me)
  69. // * example 1: strpos('Kevin van Zonneveld', 'e', 5); // * returns 1: 14
  70. var i = (haystack + '').indexOf(needle, (offset || 0));
  71. return i === -1 ? false : i;
  72. }
  73. /**
  74. * Converts the given data structure to a JSON string.
  75. * Argument: arr - The data structure that must be converted to JSON
  76. * Example: var json_string = array2json(['e', {pluribus: 'unum'}]);
  77. * var json = array2json({"success":"Sweet","failure":false,"empty_array":[],"numbers":[1,2,3],"info":{"name":"Binny","site":"http:\/\/www.openjs.com\/"}});
  78. * http://www.openjs.com/scripts/data/json_encode.php
  79. */
  80. function array2json(arr) {
  81. var parts = [];
  82. var is_list = (Object.prototype.toString.apply(arr) === '[object Array]');
  83. for(var key in arr) {
  84. var value = arr[key];
  85. if(typeof value == "object") { //Custom handling for arrays
  86. if(is_list) parts.push(array2json(value)); /* :RECURSION: */
  87. else parts[key] = array2json(value); /* :RECURSION: */
  88. } else {
  89. var str = "";
  90. if(!is_list) str = '"' + key + '":';
  91. //Custom handling for multiple data types
  92. if(typeof value == "number") str += value; //Numbers
  93. else if(value === false) str += 'false'; //The booleans
  94. else if(value === true) str += 'true';
  95. else str += '"' + value + '"'; //All other things
  96. // :TODO: Is there any more datatype we should be in the lookout for? (Functions?)
  97. parts.push(str);
  98. }
  99. }
  100. var json = parts.join(",");
  101. if(is_list) return '[' + json + ']';//Return numerical JSON
  102. return '{' + json + '}';//Return associative JSON
  103. }
  104. function isInteger(s) {
  105. return (s.toString().search(/^-?[0-9]+$/) == 0);
  106. }
  107. function inArray(array, p_val) {
  108. var l = array.length;
  109. for(var i = 0; i < l; i++) {
  110. if(array[i] == p_val) {
  111. return true;
  112. }
  113. }
  114. return false;
  115. }
  116. if(typeof(String.prototype.trim) === "undefined")
  117. {
  118. String.prototype.trim = function()
  119. {
  120. return String(this).replace(/^\s+|\s+$/g, '');
  121. };
  122. }
  123. function str_replace (search, replace, subject, count) {
  124. // Replaces all occurrences of search in haystack with replace
  125. //
  126. // version: 1109.2015
  127. // discuss at: http://phpjs.org/functions/str_replace // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  128. // + improved by: Gabriel Paderni
  129. // + improved by: Philip Peterson
  130. // + improved by: Simon Willison (http://simonwillison.net)
  131. // + revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com) // + bugfixed by: Anton Ongson
  132. // + input by: Onno Marsman
  133. // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  134. // + tweaked by: Onno Marsman
  135. // + input by: Brett Zamir (http://brett-zamir.me) // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  136. // + input by: Oleg Eremeev
  137. // + improved by: Brett Zamir (http://brett-zamir.me)
  138. // + bugfixed by: Oleg Eremeev
  139. // % note 1: The count parameter must be passed as a string in order // % note 1: to find a global variable in which the result will be given
  140. // * example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
  141. // * returns 1: 'Kevin.van.Zonneveld'
  142. // * example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
  143. // * returns 2: 'hemmo, mars' var i = 0,
  144. j = 0,
  145. temp = '',
  146. repl = '',
  147. sl = 0, fl = 0,
  148. f = [].concat(search),
  149. r = [].concat(replace),
  150. s = subject,
  151. ra = Object.prototype.toString.call(r) === '[object Array]', sa = Object.prototype.toString.call(s) === '[object Array]';
  152. s = [].concat(s);
  153. if (count) {
  154. this.window[count] = 0;
  155. }
  156. for (i = 0, sl = s.length; i < sl; i++) {
  157. if (s[i] === '') {
  158. continue;
  159. }for (j = 0, fl = f.length; j < fl; j++) {
  160. temp = s[i] + '';
  161. repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
  162. s[i] = (temp).split(f[j]).join(repl);
  163. if (count && s[i] !== temp) {this.window[count] += (temp.length - s[i].length) / f[j].length;
  164. }
  165. }
  166. }
  167. return sa ? s : s[0];
  168. }
  169. $(document).ready(function(){
  170. // Bouton de personalisation du filtre
  171. // pour le moment ce ne sotn que des redirection vers des actions
  172. $('.tags_prompt input.clear, a.filter_clear_url').live("click", function(){
  173. $(location).attr('href', $('input.filter_clear_url').val());
  174. });
  175. $('.tags_prompt input.mytags').live("click", function(){
  176. $(location).attr('href', $('input.filter_mytags_url').val());
  177. });
  178. // Affichage un/des embed
  179. $('a.element_embed_open_link').live("click", function(){
  180. li = $(this).parent('td').parent('tr').parent().parent().parent('li.element');
  181. li.find('a.element_embed_close_link').show();
  182. li.find('a.element_embed_open_link_text').hide();
  183. li.find('div.element_embed').show();
  184. return false;
  185. });
  186. $('a.element_name_embed_open_link').live("click", function(){
  187. li = $(this).parent('span').parent('td').parent('tr').parent().parent().parent('li.element');
  188. li.find('a.element_embed_close_link').show();
  189. li.find('a.element_embed_open_link_text').hide();
  190. li.find('div.element_embed').show();
  191. return false;
  192. });
  193. // Fermeture du embed si demandé
  194. $('a.element_embed_close_link').live("click", function(){
  195. li = $(this).parent('td').parent('tr').parent().parent().parent('li.element');
  196. li.find('div.element_embed').hide();
  197. li.find('a.element_embed_open_link_text').show();
  198. $(this).hide();
  199. return false;
  200. });
  201. // Mise en favoris
  202. $('a.favorite_link').live("click", function(){
  203. link = $(this);
  204. $.getJSON($(this).attr('href'), function(response) {
  205. img = link.find('img');
  206. link.attr('href', response.link_new_url);
  207. img.attr('src', response.img_new_src);
  208. img.attr('title', response.img_new_title);
  209. });
  210. return false;
  211. });
  212. // Affichage du bouton Modifier et Supprimer
  213. $('ul.elements li.element').live({
  214. mouseenter:
  215. function()
  216. {
  217. $(this).find('a.element_edit_link').show();
  218. $(this).find('a.element_remove_link').show();
  219. },
  220. mouseleave:
  221. function()
  222. {
  223. if (!$(this).find('a.element_edit_link').hasClass('mustBeDisplayed'))
  224. {
  225. $(this).find('a.element_edit_link').hide();
  226. }
  227. if (!$(this).find('a.element_remove_link').hasClass('mustBeDisplayed'))
  228. {
  229. $(this).find('a.element_remove_link').hide();
  230. }
  231. }
  232. }
  233. );
  234. // Plus d'éléments
  235. last_id = null;
  236. $('a.elements_more').click(function(){
  237. link = $(this);
  238. last_element = $('ul.elements li.element:last-child');
  239. id_last = str_replace('element_', '', last_element.attr('id'));
  240. invertcolor = 0;
  241. if (last_element.hasClass('even'))
  242. {
  243. invertcolor = 1;
  244. }
  245. $('img.elements_more_loader').show();
  246. $.getJSON(link.attr('href')+'/'+id_last+'/'+invertcolor, function(response) {
  247. if (response.count)
  248. {
  249. $('ul.elements').append(response.html);
  250. $('img.elements_more_loader').hide();
  251. }
  252. if (response.end || response.count < 1)
  253. {
  254. $('img.elements_more_loader').hide();
  255. $('ul.elements').after('<div class="no_elements"><p class="no-elements">'+
  256. response.message+'</p></div>');
  257. link.hide();
  258. }
  259. });
  260. return false;
  261. });
  262. tag_box_input_value = $('ul.tagbox input[type="text"]').val();
  263. // Filtre et affichage éléments ajax
  264. $('form[name="search"] input[type="submit"]').click(function(){
  265. $('ul.elements').html('');
  266. $('div.no_elements').hide();
  267. $('img.elements_more_loader').show();
  268. });
  269. $('form[name="search"]').ajaxForm(function(response) {
  270. $('ul.elements').html(response.html);
  271. if (response.count)
  272. {
  273. $('img.elements_more_loader').hide();
  274. $('span.elements_more').show();
  275. $('a.elements_more').show();
  276. }
  277. if (response.count < 1)
  278. {
  279. $('img.elements_more_loader').hide();
  280. $('ul.elements').after('<div class="no_elements"><p class="no-elements">'+
  281. response.message+'</p></div>');
  282. $('a.elements_more').hide()
  283. ;
  284. }
  285. $('ul.tagbox input[type="text"]').val($('ul.tagbox input[type="text"]').val());
  286. });
  287. // Suppression d'un element
  288. $('a.element_remove_link').jConfirmAction({
  289. question : "Vraiment supprimer ?",
  290. yesAnswer : "Oui",
  291. cancelAnswer : "Non",
  292. onYes: function(link){
  293. li = link.parent('td').parent('tr').parent().parent().parent('li.element');
  294. li.find('img.element_loader').show();
  295. $.getJSON(link.attr('href'), function(response){
  296. if (response.status == 'success')
  297. {
  298. li.remove();
  299. }
  300. else
  301. {
  302. li.find('img.element_loader').hide();
  303. }
  304. });
  305. return false;
  306. },
  307. onOpen: function(link){
  308. li = link.parent('td').parent('tr').parent().parent().parent('li.element');
  309. li.find('a.element_edit_link').addClass('mustBeDisplayed');
  310. li.find('a.element_remove_link').addClass('mustBeDisplayed');
  311. },
  312. onClose: function(link){
  313. li = link.parent('td').parent('tr').parent().parent().parent('li.element');
  314. li.find('a.element_edit_link').removeClass('mustBeDisplayed');
  315. li.find('a.element_remove_link').removeClass('mustBeDisplayed');
  316. li.find('a.element_edit_link').hide();
  317. li.find('a.element_remove_link').hide();
  318. }
  319. });
  320. elements_edited = new Array();
  321. // Ouverture du formulaire de modification
  322. $('a.element_edit_link').live('click', function(){
  323. link = $(this);
  324. li = link.parent('td').parent('tr').parent().parent().parent('li.element');
  325. // On garde en mémoire l'élément édité en cas d'annulation
  326. elements_edited[li.attr('id')] = li.html();
  327. div_loader = li.find('div.loader');
  328. li.html(div_loader);
  329. li.find('img.element_loader').show();
  330. $.getJSON($(this).attr('href'), function(response) {
  331. // On prépare le tagBox
  332. li.html(response.html);
  333. var options = new Array();
  334. options.form_name = response.form_name;
  335. options.tag_init = response.tags;
  336. ajax_query_timestamp = null;
  337. $("#tags_prompt_list_"+response.form_name).tagBox(options);
  338. // On rend ce formulaire ajaxFormable
  339. $('form[name="'+response.form_name+'"] input[type="submit"]').live('click', function(){
  340. li.prepend(div_loader);
  341. li.find('img.element_loader').show();
  342. });
  343. $('form[name="'+response.form_name+'"]').ajaxForm(function(response){
  344. if (response.status == 'success')
  345. {
  346. li.html(response.html);
  347. delete(elements_edited[li.attr('id')]);
  348. }
  349. else if (response.status == 'error')
  350. {
  351. li.find('img.element_loader').hide();
  352. li.find('ul.error_list').remove();
  353. ul_errors = $('<ul>').addClass('error_list');
  354. for (i in response.errors)
  355. {
  356. ul_errors.append($('<li>').append(response.errors[i]));
  357. }
  358. li.prepend(ul_errors);
  359. }
  360. });
  361. });
  362. return false;
  363. });
  364. // Annulation d'un formulaire de modification d'élément
  365. $('form.edit_element input.cancel_edit').live('click', function(){
  366. var li = $(this).parent('form').parent('li');
  367. li.html(elements_edited[li.attr('id')]);
  368. delete(elements_edited[li.attr('id')]);
  369. });
  370. ////////////////// TAG PROMPT ///////////////
  371. ajax_query_timestamp = null;
  372. tag_text_help = $('input.tag_text_help').val();
  373. // Les deux clicks ci-dessous permettent de faire disparaitre
  374. // la div de tags lorsque l'on clique ailleurs
  375. $('html').click(function() {
  376. if ($("div.search_tag_list").is(':visible'))
  377. {
  378. $("div.search_tag_list").hide();
  379. }
  380. });
  381. $("div.search_tag_list").live('click', function(event){
  382. event.stopPropagation();
  383. });
  384. function autocomplete_tag(input, form_name)
  385. {
  386. // Il doit y avoir au moin un caractère
  387. if (input.val().length > 0)
  388. {
  389. // on met en variable l'input
  390. inputTag = input;
  391. // On récupére la div de tags
  392. divtags = $("#search_tag_"+form_name);
  393. // Si la fenêtre de tags est caché
  394. if (!divtags.is(':visible'))
  395. {
  396. // On la replace
  397. position = input.position();
  398. divtags.css('left', Math.round(position.left) + 5);
  399. divtags.css('top', Math.round(position.top) + 28);
  400. // Et on l'affiche
  401. divtags.show();
  402. }
  403. // On affiche le loader
  404. $('#tag_loader_'+form_name).show();
  405. // On cache la liste de tags
  406. search_tag_list = divtags.find('ul.search_tag_list');
  407. // On supprime les anciens li
  408. search_tag_list.find('li').remove();
  409. search_tag_list.hide();
  410. // Et on affiche une info
  411. span_info = divtags.find('span.info');
  412. span_info.show();
  413. span_info.text("Recherche des tags correspondants à \""+input.val()+"\" ...");
  414. // C'est en fonction du nb de resultats qu'il sera affiché
  415. divtags.find('a.more').hide();
  416. // On récupère le timestamp pour reconnaitre la dernière requête effectué
  417. ajax_query_timestamp = new Date().getTime();
  418. // Récupération des tags correspondants
  419. $.getJSON('/app_dev.php/fr/search/tag/'+input.val()+'/'+ajax_query_timestamp, function(data) {
  420. // Ce contrôle permet de ne pas continuer si une requete
  421. // ajax a été faite depuis.
  422. if (data.timestamp == ajax_query_timestamp)
  423. {
  424. status = data.status;
  425. tags = data.data;
  426. // Si on spécifie une erreur
  427. if (status == 'error')
  428. {
  429. // On l'affiche a l'utilisateur
  430. span_info.text(data.error);
  431. }
  432. // Si c'est un succés
  433. else if (status == 'success')
  434. {
  435. if (tags.length > 0)
  436. {
  437. more = false;
  438. // Pour chaque tags retournés
  439. for (i in tags)
  440. {
  441. var tag_name = tags[i]['name'];
  442. var tag_id = tags[i]['id'];
  443. // On construit un li
  444. var sstr = $.trim(input.val());
  445. var re = new RegExp(sstr, "i") ;
  446. var t_string = tag_name.replace(re,"<strong>" + sstr + "</strong>");
  447. li_tag =
  448. $('<li>').append(
  449. $('<a>').attr('href','#'+tag_id+'#'+tag_name)
  450. // qui réagit quand on clique dessus
  451. .click(function(e){
  452. // On récupère le nom du tag
  453. name = $(this).attr('href').substr(1,$(this).attr('href').length);
  454. name = name.substr(strpos(name, '#')+1, name.length);
  455. id = $(this).attr('href').substr(1,$(this).attr('href').length);
  456. id = str_replace(name, '', id);
  457. id = str_replace('#', '', id);
  458. $('input#tags_selected_tag_'+form_name).val(id);
  459. inputTag.val(name);
  460. // Et on execute l'évènement selectTag de l'input
  461. inputTag.trigger("selectTag");
  462. // On cache la liste puisque le choix vient d'être fait
  463. divtags.hide();
  464. inputTag.val(tag_text_help);
  465. return false;
  466. })
  467. .append(t_string)
  468. );
  469. // Si on depasse les 30 tags
  470. if (i > 30)
  471. {
  472. more = true;
  473. // On le cache
  474. li_tag.hide();
  475. }
  476. // On ajout ce li a la liste
  477. search_tag_list.append(li_tag);
  478. }
  479. if (more)
  480. {
  481. divtags.find('a.more').show();
  482. }
  483. // On cache l'info
  484. span_info.hide();
  485. // Et on affiche la liste
  486. search_tag_list.show();
  487. }
  488. else
  489. {
  490. span_info.text("Aucun tag de trouvé pour \""+inputTag.val()+"\"");
  491. }
  492. }
  493. // On cache le loader
  494. $('#tag_loader_'+form_name).hide();
  495. }
  496. });
  497. }
  498. }
  499. last_keypress = 0;
  500. function check_timelaps_and_search(input, form_name, time_id, timed, info)
  501. {
  502. if (!timed)
  503. {
  504. // C'est une nouvelle touche (pas redirigé) on lui donne un id
  505. // et on met a jour l'id de la dernière pressé
  506. last_keypress = new Date().getTime();
  507. var this_time_id = last_keypress;
  508. }
  509. else
  510. {
  511. // Si elle a été redirigé, on met son id dans cette variable
  512. var this_time_id = time_id;
  513. }
  514. // C'est une touche redirigé dans le temps qui a été suivit d'une autre touche
  515. if (time_id != last_keypress && timed)
  516. {
  517. // elle disparait
  518. }
  519. else
  520. {
  521. //
  522. if ((new Date().getTime() - last_keypress) < 600 || timed == false)
  523. {
  524. // Si elle vient d'être tapé (timed == false) elle doit attendre (au cas ou une autre touche soit tapé)
  525. // Si c'est une redirigé qui n'a pas été remplacé par une nouvelle lettre
  526. // elle doit attendre au cas ou soit pressé.
  527. setTimeout(function(){check_timelaps_and_search(input, form_name, this_time_id, true, info)}, 700);
  528. }
  529. else
  530. {
  531. // il n'y a plus a attendre, on envoie la demande de tag.
  532. autocomplete_tag(input, form_name);
  533. }
  534. }
  535. }
  536. // Autocompletion de tags
  537. $("div.tags_prompt ul.tagbox li.input input").live('keypress', function(e){
  538. var form_name = $(this).parent('li').parent('ul.tagbox')
  539. .parent('div.tags_prompt').parent('form').attr('name')
  540. ;
  541. var code = (e.keyCode ? e.keyCode : e.which);
  542. if ((e.which !== 0 && e.charCode !== 0) || (code == 8 || code == 46))
  543. {
  544. check_timelaps_and_search($(this), form_name, new Date().getTime(), false, $(this).val());
  545. }
  546. });
  547. // Un click sur ce lien affiche tout les tags cachés de la liste
  548. $('div.search_tag_list a.more').live('click', function(){
  549. jQuery.each( $(this).parent('div').find('ul.search_tag_list li') , function(){
  550. $(this).show();
  551. });
  552. return false;
  553. });
  554. $('ul.tagbox li.input input[type="text"]').val(tag_text_help);
  555. $('ul.tagbox li.input input[type="text"]').formDefaults();
  556. ////////////////// FIN TAG PROMPT ///////////////
  557. // Suppression d'un element
  558. $('a.group_remove_link').jConfirmAction({
  559. question : "Supprimer ce groupe ?",
  560. yesAnswer : "Oui",
  561. cancelAnswer : "Non",
  562. onYes: function(link){
  563. window.location = link.attr('href');
  564. return false;
  565. },
  566. onOpen: function(){},
  567. onClose: function(){}
  568. });
  569. // Selection Réseau global / Mon réseau
  570. $('div.select_network a').live('click', function(){
  571. divSelect = $(this).parent('div');
  572. if ($(this).hasClass('all_network'))
  573. {
  574. divSelect.find('a.all_network').addClass('active');
  575. divSelect.find('a.my_network').removeClass('active');
  576. divSelect.find('select').val('network_public');
  577. }
  578. else
  579. {
  580. divSelect.find('a.my_network').addClass('active');
  581. divSelect.find('a.all_network').removeClass('active');
  582. divSelect.find('select').val('network_personal');
  583. }
  584. });
  585. // Ajout d'un element
  586. $('form[name="add"] input[type="submit"]').live('click', function(){
  587. $('form[name="add"]').find('img.tag_loader').show();
  588. });
  589. $('form[name="add"]').ajaxForm(function(response) {
  590. $('form[name="add"] img.tag_loader').hide();
  591. if (response.status == 'success')
  592. {
  593. $('form[name="add"]').find('ul.error_list').remove();
  594. $('ul.elements').prepend(response.html);
  595. $('form[name="add"] input[type="text"]').val('');
  596. $('div#element_add_box').slideUp();
  597. $('a#element_add_link').show();
  598. if ($('form[name="search"]').length)
  599. {
  600. $('form[name="search"]').slideDown();
  601. }
  602. }
  603. else if (response.status == 'error')
  604. {
  605. $('form[name="add"]').find('ul.error_list').remove();
  606. ul_errors = $('<ul>').addClass('error_list');
  607. for (i in response.errors)
  608. {
  609. ul_errors.append($('<li>').append(response.errors[i]));
  610. }
  611. $('form[name="add"]').prepend(ul_errors);
  612. }
  613. return false;
  614. });
  615. // Check périodique
  616. // TODO.
  617. });