muzich.js 69KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410
  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. // Messages flashs
  8. var myMessages = ['info','warning','error','success']; // define the messages types
  9. function hideAllMessages()
  10. {
  11. var messagesHeights = new Array(); // this array will store height for each
  12. for (i=0; i<myMessages.length; i++)
  13. {
  14. messagesHeights[i] = $('.' + myMessages[i]).outerHeight();
  15. $('.' + myMessages[i]).css('top', -messagesHeights[i]); //move element outside viewport
  16. }
  17. }
  18. $(document).ready(function(){
  19. // Initially, hide them all
  20. hideAllMessages();
  21. $('.message').animate({top:"0"}, 500);
  22. // When message is clicked, hide it
  23. $('.message a.message-close').click(function(){
  24. $('.message').hide();
  25. return false;
  26. });
  27. });
  28. function findKeyWithValue(arrayt, value)
  29. {
  30. for(i in arrayt)
  31. {
  32. if (arrayt[i] == value)
  33. {
  34. return i;
  35. }
  36. }
  37. return "";
  38. }
  39. function array_key_exists (key, search) {
  40. // http://kevin.vanzonneveld.net
  41. // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  42. // + improved by: Felix Geisendoerfer (http://www.debuggable.com/felix)
  43. // * example 1: array_key_exists('kevin', {'kevin': 'van Zonneveld'});
  44. // * returns 1: true
  45. // input sanitation
  46. if (!search || (search.constructor !== Array && search.constructor !== Object)) {
  47. return false;
  48. }
  49. return key in search;
  50. }
  51. function json_to_array(json_string)
  52. {
  53. if (json_string.length)
  54. {
  55. return eval("(" + json_string + ")");
  56. }
  57. return new Array();
  58. }
  59. function strpos (haystack, needle, offset) {
  60. // Finds position of first occurrence of a string within another
  61. //
  62. // version: 1109.2015
  63. // discuss at: http://phpjs.org/functions/strpos // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  64. // + improved by: Onno Marsman
  65. // + bugfixed by: Daniel Esteban
  66. // + improved by: Brett Zamir (http://brett-zamir.me)
  67. // * example 1: strpos('Kevin van Zonneveld', 'e', 5); // * returns 1: 14
  68. var i = (haystack + '').indexOf(needle, (offset || 0));
  69. return i === -1 ? false : i;
  70. }
  71. /**
  72. * Converts the given data structure to a JSON string.
  73. * Argument: arr - The data structure that must be converted to JSON
  74. * Example: var json_string = array2json(['e', {pluribus: 'unum'}]);
  75. * var json = array2json({"success":"Sweet","failure":false,"empty_array":[],"numbers":[1,2,3],"info":{"name":"Binny","site":"http:\/\/www.openjs.com\/"}});
  76. * http://www.openjs.com/scripts/data/json_encode.php
  77. */
  78. function array2json(arr) {
  79. var parts = [];
  80. var is_list = (Object.prototype.toString.apply(arr) === '[object Array]');
  81. for(var key in arr) {
  82. var value = arr[key];
  83. if(typeof value == "object") { //Custom handling for arrays
  84. if(is_list) parts.push(array2json(value)); /* :RECURSION: */
  85. else parts[key] = array2json(value); /* :RECURSION: */
  86. } else {
  87. var str = "";
  88. if(!is_list) str = '"' + key + '":';
  89. //Custom handling for multiple data types
  90. if(typeof value == "number") str += value; //Numbers
  91. else if(value === false) str += 'false'; //The booleans
  92. else if(value === true) str += 'true';
  93. else str += '"' + value + '"'; //All other things
  94. // :TODO: Is there any more datatype we should be in the lookout for? (Functions?)
  95. parts.push(str);
  96. }
  97. }
  98. var json = parts.join(",");
  99. if(is_list) return '[' + json + ']';//Return numerical JSON
  100. return '{' + json + '}';//Return associative JSON
  101. }
  102. function isInteger(s) {
  103. return (s.toString().search(/^-?[0-9]+$/) == 0);
  104. }
  105. function inArray(array, p_val) {
  106. var l = array.length;
  107. for(var i = 0; i < l; i++) {
  108. if(array[i] == p_val) {
  109. return true;
  110. }
  111. }
  112. return false;
  113. }
  114. if(typeof(String.prototype.trim) === "undefined")
  115. {
  116. String.prototype.trim = function()
  117. {
  118. return String(this).replace(/^\s+|\s+$/g, '');
  119. };
  120. }
  121. function str_replace (search, replace, subject, count) {
  122. // Replaces all occurrences of search in haystack with replace
  123. //
  124. // version: 1109.2015
  125. // discuss at: http://phpjs.org/functions/str_replace // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  126. // + improved by: Gabriel Paderni
  127. // + improved by: Philip Peterson
  128. // + improved by: Simon Willison (http://simonwillison.net)
  129. // + revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com) // + bugfixed by: Anton Ongson
  130. // + input by: Onno Marsman
  131. // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  132. // + tweaked by: Onno Marsman
  133. // + input by: Brett Zamir (http://brett-zamir.me) // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  134. // + input by: Oleg Eremeev
  135. // + improved by: Brett Zamir (http://brett-zamir.me)
  136. // + bugfixed by: Oleg Eremeev
  137. // % 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
  138. // * example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
  139. // * returns 1: 'Kevin.van.Zonneveld'
  140. // * example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
  141. // * returns 2: 'hemmo, mars' var i = 0,
  142. j = 0,
  143. temp = '',
  144. repl = '',
  145. sl = 0, fl = 0,
  146. f = [].concat(search),
  147. r = [].concat(replace),
  148. s = subject,
  149. ra = Object.prototype.toString.call(r) === '[object Array]', sa = Object.prototype.toString.call(s) === '[object Array]';
  150. s = [].concat(s);
  151. if (count) {
  152. this.window[count] = 0;
  153. }
  154. for (i = 0, sl = s.length; i < sl; i++) {
  155. if (s[i] === '') {
  156. continue;
  157. }for (j = 0, fl = f.length; j < fl; j++) {
  158. temp = s[i] + '';
  159. repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
  160. s[i] = (temp).split(f[j]).join(repl);
  161. if (count && s[i] !== temp) {this.window[count] += (temp.length - s[i].length) / f[j].length;
  162. }
  163. }
  164. }
  165. return sa ? s : s[0];
  166. }
  167. function explode (delimiter, string, limit) {
  168. // Splits a string on string separator and return array of components. If limit is positive only limit number of components is returned. If limit is negative all components except the last abs(limit) are returned.
  169. //
  170. // version: 1109.2015
  171. // discuss at: http://phpjs.org/functions/explode // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  172. // + improved by: kenneth
  173. // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  174. // + improved by: d3x
  175. // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // * example 1: explode(' ', 'Kevin van Zonneveld');
  176. // * returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
  177. // * example 2: explode('=', 'a=bc=d', 2);
  178. // * returns 2: ['a', 'bc=d']
  179. var emptyArray = {0: ''
  180. };
  181. // third argument is not required
  182. if (arguments.length < 2 || typeof arguments[0] == 'undefined' || typeof arguments[1] == 'undefined') {return null;
  183. }
  184. if (delimiter === '' || delimiter === false || delimiter === null) {
  185. return false;}
  186. if (typeof delimiter == 'function' || typeof delimiter == 'object' || typeof string == 'function' || typeof string == 'object') {
  187. return emptyArray;
  188. }
  189. if (delimiter === true) {
  190. delimiter = '1';
  191. }
  192. if (!limit) {
  193. return string.toString().split(delimiter.toString());
  194. }
  195. // support for limit argument
  196. var splitted = string.toString().split(delimiter.toString());var partA = splitted.splice(0, limit - 1);
  197. var partB = splitted.join(delimiter.toString());
  198. partA.push(partB);
  199. return partA;
  200. }
  201. // fonction de nettoyage des tags
  202. function remove_tags(form_name)
  203. {
  204. //tagsAddeds[form_name] = new Array();
  205. $('form[name="'+form_name+'"] ul.tagbox li.tag').remove();
  206. $('form[name="'+form_name+'"] input.tagBox_tags_ids').val('');
  207. }
  208. $(document).ready(function(){
  209. // Controle du focus sur la page
  210. function onBlur() {
  211. document.body.className = 'blurred';
  212. }
  213. function onFocus(){
  214. document.body.className = 'focused';
  215. do_action_body_focused();
  216. }
  217. if (/*@cc_on!@*/false) { // check for Internet Explorer
  218. document.onfocusin = onFocus;
  219. document.onfocusout = onBlur;
  220. } else {
  221. window.onfocus = onFocus;
  222. window.onblur = onBlur;
  223. }
  224. // Bouton de personalisation du filtre
  225. // Aucun tags
  226. $('.tags_prompt input.clear, a.filter_clear_url').live("click", function(){
  227. $('img.elements_more_loader').show();
  228. $('ul.elements').html('');
  229. // On initialise la liste de tags déjà ajouté
  230. tagsAddeds['search'] = new Array;
  231. var form = $('form[name="search"]');
  232. remove_tags(form.attr('name'));
  233. form.submit();
  234. });
  235. // tags préférés
  236. $('.tags_prompt input.mytags').live("click", function(){
  237. $('img.elements_more_loader').show();
  238. $('ul.elements').html('');
  239. // On initialise la liste de tags déjà ajouté
  240. tagsAddeds['search'] = new Array;
  241. var form = $(this).parents('form[name="search"]');
  242. $.getJSON(url_get_favorites_tags, function(response) {
  243. if (response.status == 'mustbeconnected')
  244. {
  245. $(location).attr('href', url_index);
  246. }
  247. remove_tags(form.attr('name'));
  248. // if (tags.length)
  249. // {
  250. var inputTag = $("div#tags_prompt_"+form.attr('name')+" input.form-default-value-processed");
  251. for (i in response.tags)
  252. {
  253. $('input#tags_selected_tag_'+form.attr('name')).val(i);
  254. inputTag.val(response.tags[i]);
  255. // Et on execute l'évènement selectTag de l'input
  256. inputTag.trigger("selectTag");
  257. }
  258. form.submit();
  259. //}
  260. });
  261. });
  262. // Tag cliqué dans la liste d'éléments
  263. $('ul.element_tags li a.element_tag').live('click', function(){
  264. // Si il y a une liste de tags (comme sur la page favoris, profil)
  265. var id;
  266. // On initialise la liste de tags déjà ajouté
  267. tagsAddeds['search'] = new Array;
  268. if ($('ul#favorite_tags').length)
  269. {
  270. id = str_replace('element_tag_', '', $(this).attr('id'));
  271. var link = $('a#filtering_tag_'+id);
  272. list_tag_clicked(link, true);
  273. }
  274. if ($('form[name="search"]').length)
  275. {
  276. $('img.elements_more_loader').show();
  277. $('ul.elements').html('');
  278. var form = $('form[name="search"]');
  279. id = str_replace('element_tag_', '', $(this).attr('id'));
  280. remove_tags('search');
  281. var inputTag = $("div#tags_prompt_search input.form-default-value-processed");
  282. $('input#tags_selected_tag_search').val(id);
  283. inputTag.val($(this).html());
  284. inputTag.trigger("selectTag");
  285. form.submit();
  286. }
  287. });
  288. function element_last_opened(li)
  289. {
  290. $('li.element').removeClass('shadows');
  291. li.addClass('shadows');
  292. }
  293. // Affichage un/des embed
  294. // 1328283150_media-playback-start.png
  295. // 1328283201_emblem-symbolic-link.png
  296. $('a.element_embed_open_link').live("click", function(){
  297. var li = $(this).parents('li.element');
  298. element_last_opened(li);
  299. li.find('a.element_embed_close_link').show();
  300. li.find('a.element_embed_open_link_text').hide();
  301. li.find('div.element_embed').show();
  302. return false;
  303. });
  304. $('a.element_name_embed_open_link').live("click", function(){
  305. var li = $(this).parents('li.element');
  306. element_last_opened(li);
  307. li.find('a.element_embed_close_link').show();
  308. li.find('a.element_embed_open_link_text').hide();
  309. li.find('div.element_embed').show();
  310. return false;
  311. });
  312. // Fermeture du embed si demandé
  313. $('a.element_embed_close_link').live("click", function(){
  314. var li = $(this).parents('li.element');
  315. li.removeClass('shadows');
  316. li.find('div.element_embed').hide();
  317. li.find('a.element_embed_open_link_text').show();
  318. $(this).hide();
  319. return false;
  320. });
  321. // Affichage du "play" ou du "open" (image png)
  322. $('li.element a.a_thumbnail, li.element img.open, li.element img.play').live({
  323. mouseenter:
  324. function()
  325. {
  326. var td = $(this).parent('td');
  327. var a = td.find('a.a_thumbnail');
  328. if (a.hasClass('embed'))
  329. {
  330. td.find('img.play').show();
  331. }
  332. else
  333. {
  334. td.find('img.open').show();
  335. }
  336. },
  337. mouseleave:
  338. function()
  339. {
  340. var td = $(this).parent('td');
  341. var a = td.find('a.a_thumbnail');
  342. if (a.hasClass('embed'))
  343. {
  344. td.find('img.play').hide();
  345. }
  346. else
  347. {
  348. td.find('img.open').hide();
  349. }
  350. }
  351. }
  352. );
  353. // Mise en favoris
  354. $('a.favorite_link').live("click", function(){
  355. var link = $(this);
  356. // Pour ne pas attendre la fin du chargement ajax:
  357. var img = link.find('img');
  358. if (!link.hasClass('loading'))
  359. {
  360. if (img.attr('src') == '/bundles/muzichcore/img/favorite_bw.png')
  361. {
  362. img.attr('src', '/bundles/muzichcore/img/favorite.png');
  363. }
  364. else
  365. {
  366. img.attr('src', '/bundles/muzichcore/img/favorite_bw.png');
  367. }
  368. }
  369. link.addClass('loading');
  370. $.getJSON($(this).attr('href'), function(response) {
  371. if (response.status == 'mustbeconnected')
  372. {
  373. $(location).attr('href', url_index);
  374. }
  375. var img = link.find('img');
  376. link.attr('href', response.link_new_url);
  377. img.attr('src', response.img_new_src);
  378. img.attr('title', response.img_new_title);
  379. link.removeClass('loading');
  380. });
  381. return false;
  382. });
  383. // Affichage du bouton Modifier et Supprimer
  384. $('ul.elements li.element').live({
  385. mouseenter:
  386. function()
  387. {
  388. $(this).find('a.element_edit_link').show();
  389. $(this).find('a.element_remove_link').show();
  390. },
  391. mouseleave:
  392. function()
  393. {
  394. if (!$(this).find('a.element_edit_link').hasClass('mustBeDisplayed'))
  395. {
  396. $(this).find('a.element_edit_link').hide();
  397. }
  398. if (!$(this).find('a.element_remove_link').hasClass('mustBeDisplayed'))
  399. {
  400. $(this).find('a.element_remove_link').hide();
  401. }
  402. }
  403. }
  404. );
  405. // Plus d'éléments
  406. var last_id = null;
  407. $('a.elements_more').click(function(){
  408. var link = $(this);
  409. var last_element = $('ul.elements li.element:last-child');
  410. var id_last = str_replace('element_', '', last_element.attr('id'));
  411. var invertcolor = 0;
  412. if (last_element.hasClass('even'))
  413. {
  414. invertcolor = 1;
  415. }
  416. $('img.elements_more_loader').show();
  417. var url = link.attr('href')+'/'+id_last+'/'+invertcolor;
  418. // Cas exeptionel si on se trouve sur la global_search
  419. if ($('div#results_search_form').length)
  420. {
  421. url = link.attr('href')+id_last+'/'+$('div#results_search_form form input[type="text"]').val();
  422. }
  423. var old_form_action = $('form[name="search"]').attr('action');
  424. $('form[name="search"]').attr('action', url);
  425. $.ajax({
  426. type: 'POST',
  427. url: url,
  428. data: $('form[name="search"]').serialize(),
  429. success: function(response) {
  430. if (response.status == 'mustbeconnected')
  431. {
  432. $(location).attr('href', url_index);
  433. }
  434. if (response.count)
  435. {
  436. $('ul.elements').append(response.html);
  437. $('img.elements_more_loader').hide();
  438. recolorize_element_list();
  439. }
  440. if (response.end || response.count < 1)
  441. {
  442. $('img.elements_more_loader').hide();
  443. $('ul.elements').after('<div class="no_elements"><p class="no-elements">'+
  444. response.message+'</p></div>');
  445. link.hide();
  446. }
  447. },
  448. dataType: "json"
  449. });
  450. $('form[name="search"]').attr('action', old_form_action);
  451. // $.getJSON(url, function(response) {
  452. // if (response.status == 'mustbeconnected')
  453. // {
  454. // $(location).attr('href', url_index);
  455. // }
  456. //
  457. // if (response.count)
  458. // {
  459. // $('ul.elements').append(response.html);
  460. // $('img.elements_more_loader').hide();
  461. // recolorize_element_list();
  462. // }
  463. //
  464. // if (response.end || response.count < 1)
  465. // {
  466. // $('img.elements_more_loader').hide();
  467. // $('ul.elements').after('<div class="no_elements"><p class="no-elements">'+
  468. // response.message+'</p></div>');
  469. // link.hide();
  470. // }
  471. // });
  472. return false;
  473. });
  474. tag_box_input_value = $('ul.tagbox input[type="text"]').val();
  475. // Filtre et affichage éléments ajax
  476. $('form[name="search"] input[type="submit"]').click(function(){
  477. $('ul.elements').html('');
  478. $('div.no_elements').hide();
  479. $('img.elements_more_loader').show();
  480. });
  481. $('form[name="search"]').ajaxForm(function(response) {
  482. if (response.status == 'mustbeconnected')
  483. {
  484. $(location).attr('href', url_index);
  485. }
  486. $('ul.elements').html(response.html);
  487. if (response.count)
  488. {
  489. $('img.elements_more_loader').hide();
  490. $('span.elements_more').show();
  491. $('a.elements_more').show();
  492. }
  493. if (response.count < 1)
  494. {
  495. $('img.elements_more_loader').hide();
  496. $('ul.elements').after('<div class="no_elements"><p class="no-elements">'+
  497. response.message+'</p></div>');
  498. $('a.elements_more').hide()
  499. ;
  500. }
  501. $('ul.tagbox input[type="text"]').val($('ul.tagbox input[type="text"]').val());
  502. });
  503. // Suppression d'un element
  504. $('a.element_remove_link').jConfirmAction({
  505. question : string_element_delete_confirm_sentence,
  506. yesAnswer : string_element_delete_confirm_yes,
  507. cancelAnswer : string_element_delete_confirm_no,
  508. onYes: function(link){
  509. var li = link.parents('li.element');
  510. li.find('img.element_loader').show();
  511. $.getJSON(link.attr('href'), function(response){
  512. if (response.status == 'mustbeconnected')
  513. {
  514. $(location).attr('href', url_index);
  515. }
  516. if (response.status == 'success')
  517. {
  518. li.remove();
  519. }
  520. else
  521. {
  522. li.find('img.element_loader').hide();
  523. }
  524. });
  525. return false;
  526. },
  527. onOpen: function(link){
  528. var li = link.parents('li.element');
  529. li.find('a.element_edit_link').addClass('mustBeDisplayed');
  530. li.find('a.element_remove_link').addClass('mustBeDisplayed');
  531. },
  532. onClose: function(link){
  533. var li = link.parents('li.element');
  534. li.find('a.element_edit_link').removeClass('mustBeDisplayed');
  535. li.find('a.element_remove_link').removeClass('mustBeDisplayed');
  536. li.find('a.element_edit_link').hide();
  537. li.find('a.element_remove_link').hide();
  538. }
  539. });
  540. var elements_edited = new Array();
  541. // Ouverture du formulaire de modification
  542. $('a.element_edit_link').live('click', function(){
  543. var link = $(this);
  544. var li = link.parents('li.element');
  545. // On garde en mémoire l'élément édité en cas d'annulation
  546. elements_edited[li.attr('id')] = li.html();
  547. var div_loader = li.find('div.loader');
  548. li.html(div_loader);
  549. li.find('img.element_loader').show();
  550. $.getJSON($(this).attr('href'), function(response) {
  551. if (response.status == 'mustbeconnected')
  552. {
  553. $(location).attr('href', url_index);
  554. }
  555. // On prépare le tagBox
  556. li.html(response.html);
  557. // Pour le click sur l'input de saisie de tag
  558. li.find('ul.tagbox li.input input[type="text"]').formDefaults();
  559. var options = new Array();
  560. options.form_name = response.form_name;
  561. options.tag_init = response.tags;
  562. ajax_query_timestamp = null;
  563. $("#tags_prompt_list_"+response.form_name).tagBox(options);
  564. // On rend ce formulaire ajaxFormable
  565. $('form[name="'+response.form_name+'"] input[type="submit"]').live('click', function(){
  566. var li = $(this).parents('li.element');
  567. li.prepend(div_loader);
  568. li.find('img.element_loader').show();
  569. });
  570. $('form[name="'+response.form_name+'"]').ajaxForm(function(response){
  571. if (response.status == 'mustbeconnected')
  572. {
  573. $(location).attr('href', url_index);
  574. }
  575. var li = $('li#'+response.dom_id);
  576. if (response.status == 'success')
  577. {
  578. li.html(response.html);
  579. delete(elements_edited[li.attr('id')]);
  580. }
  581. else if (response.status == 'error')
  582. {
  583. li.find('img.element_loader').hide();
  584. li.find('ul.error_list').remove();
  585. var ul_errors = $('<ul>').addClass('error_list');
  586. for (i in response.errors)
  587. {
  588. ul_errors.append($('<li>').append(response.errors[i]));
  589. }
  590. li.prepend(ul_errors);
  591. }
  592. });
  593. });
  594. return false;
  595. });
  596. // Annulation d'un formulaire de modification d'élément
  597. $('form.edit_element input.cancel_edit').live('click', function(){
  598. var li = $(this).parents('li.element');
  599. li.html(elements_edited[li.attr('id')]);
  600. delete(elements_edited[li.attr('id')]);
  601. });
  602. ////////////////// TAG PROMPT ///////////////
  603. var ajax_query_timestamp = null;
  604. // Les deux clicks ci-dessous permettent de faire disparaitre
  605. // la div de tags lorsque l'on clique ailleurs
  606. $('html').click(function() {
  607. if ($("div.search_tag_list").is(':visible'))
  608. {
  609. $("div.search_tag_list").hide();
  610. }
  611. });
  612. $("div.search_tag_list, div.search_tag_list a.more").live('click', function(event){
  613. event.stopPropagation();
  614. $("div.search_tag_list").show();
  615. });
  616. function autocomplete_tag(input, form_name)
  617. {
  618. // Il doit y avoir au moin un caractère
  619. if (input.val().length > 0)
  620. {
  621. // on met en variable l'input
  622. var inputTag = input;
  623. // On récupére la div de tags
  624. var divtags = $("#search_tag_"+form_name);
  625. // Si la fenêtre de tags est caché
  626. if (!divtags.is(':visible'))
  627. {
  628. // On la replace
  629. var position = input.position();
  630. divtags.css('left', Math.round(position.left) + 5);
  631. divtags.css('top', Math.round(position.top) + 28);
  632. // Et on l'affiche
  633. divtags.show();
  634. }
  635. // On affiche le loader
  636. $('#tag_loader_'+form_name).show();
  637. // On cache la liste de tags
  638. var search_tag_list = divtags.find('ul.search_tag_list');
  639. // On supprime les anciens li
  640. search_tag_list.find('li').remove();
  641. search_tag_list.hide();
  642. // Et on affiche une info
  643. var span_info = divtags.find('span.info');
  644. span_info.show();
  645. // TODO: multilingue !
  646. span_info.text(str_replace('%string_search%', input.val(), string_search_tag_title));
  647. // C'est en fonction du nb de resultats qu'il sera affiché
  648. divtags.find('a.more').hide();
  649. // On récupère le timestamp pour reconnaitre la dernière requête effectué
  650. ajax_query_timestamp = new Date().getTime();
  651. // Récupération des tags correspondants
  652. $.ajax({
  653. type: 'POST',
  654. url: url_search_tag+'/'+ajax_query_timestamp,
  655. dataType: 'json',
  656. data: {'string_search':input.val()},
  657. success: function(data) {
  658. if (data.status == 'mustbeconnected')
  659. {
  660. $(location).attr('href', url_index);
  661. }
  662. // Ce contrôle permet de ne pas continuer si une requete
  663. // ajax a été faite depuis.
  664. if (data.timestamp == ajax_query_timestamp)
  665. {
  666. var status = data.status;
  667. var tags = data.data;
  668. // Si on spécifie une erreur
  669. if (status == 'error')
  670. {
  671. // On l'affiche a l'utilisateur
  672. span_info.text(data.error);
  673. }
  674. // Si c'est un succés
  675. else if (status == 'success')
  676. {
  677. if (tags.length > 0)
  678. {
  679. var more = false;
  680. // Pour chaque tags retournés
  681. for (i in tags)
  682. {
  683. var tag_name = tags[i]['name'];
  684. var tag_id = tags[i]['id'];
  685. var t_string = tag_name
  686. // On construit un li
  687. var r_string = $.trim(input.val());
  688. var re = new RegExp(r_string, "i");
  689. t_string = t_string.replace(re,"<strong>" + r_string + "</strong>");
  690. var li_tag =
  691. $('<li>').append(
  692. $('<a>').attr('id','searched_tag_'+tag_id)
  693. .attr('href', '#')
  694. // qui réagit quand on clique dessus
  695. .click(function(e){
  696. var id = str_replace('searched_tag_', '', $(this).attr('id'));
  697. var name = $('span#tag_prompt_tag_'+id+'_name').html();
  698. $('input#tags_selected_tag_'+form_name).val(id);
  699. inputTag.val(name);
  700. // Et on execute l'évènement selectTag de l'input
  701. inputTag.trigger("selectTag");
  702. // On cache la liste puisque le choix vient d'être fait
  703. divtags.hide();
  704. // On vide le champs de saisie du tag
  705. $('input.form-default-value-processed').val('');
  706. return false;
  707. })
  708. .append(t_string)
  709. ).append($('<span style="display: none;" id="tag_prompt_tag_'+tag_id+'_name">'+tag_name+'</span>'));
  710. // Si on depasse les 30 tags
  711. if (i > 30)
  712. {
  713. more = true;
  714. // On le cache
  715. li_tag.hide();
  716. }
  717. // On ajout ce li a la liste
  718. search_tag_list.append(li_tag);
  719. }
  720. if (more)
  721. {
  722. divtags.find('a.more').show();
  723. }
  724. span_info.show();
  725. span_info.text(data.message);
  726. // Et on affiche la liste
  727. search_tag_list.show();
  728. }
  729. else
  730. {
  731. span_info.show();
  732. span_info.text(data.message);
  733. search_tag_list.show();
  734. // Dans ce cas ou aucun tag n'a été trouvé, la proposition
  735. // d'ajout s'affichecf en dessous
  736. //span_info.text("Aucun tag de trouvé pour \""+inputTag.val()+"\"");
  737. }
  738. // Si le tag ne semble pas connu en base
  739. if (!data.same_found)
  740. {
  741. li_tag =
  742. $('<li>').addClass('new').append(
  743. $('<a>').attr('href','#new#'+$.trim(input.val()))
  744. // qui réagit quand on clique dessus
  745. .click({
  746. inputTag: inputTag,
  747. form_name: form_name,
  748. divtags: divtags
  749. }, event_click_new_tag_proposition)
  750. .append($.trim(input.val()))
  751. );
  752. search_tag_list.append(li_tag);
  753. }
  754. }
  755. // On cache le loader
  756. $('#tag_loader_'+form_name).hide();
  757. }
  758. }
  759. });
  760. //$.getJSON(url_search_tag+'/'+input.val()+'/'+ajax_query_timestamp, );
  761. }
  762. }
  763. function event_click_new_tag_proposition(event)
  764. {
  765. form_add_open_dialog_for_new_tag($(event.target), event.data.inputTag, event.data.form_name, event.data.divtags);
  766. }
  767. function form_add_open_dialog_for_new_tag(link_add_tag, inputTag, form_name, divtags)
  768. {
  769. // Effet fade-in du fond opaque
  770. $('body').append($('<div>').attr('id', 'fade'));
  771. //Apparition du fond - .css({'filter' : 'alpha(opacity=80)'}) pour corriger les bogues de IE
  772. $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
  773. // En premier lieux on fait apparaître la fenêtre de confirmation
  774. var popup = $('<div>')
  775. .attr('id', 'add_tag')
  776. .addClass('popin_block')
  777. .css('width', '400px')
  778. //.append($('<h2>').append(string_tag_add_title))
  779. .append($('<form>')
  780. .attr('action', url_add_tag)
  781. .attr('method', 'post')
  782. .attr('name', 'add_tag')
  783. .ajaxForm(function(response) {
  784. /*
  785. *
  786. */
  787. if (response.status == 'mustbeconnected')
  788. {
  789. $(location).attr('href', url_index);
  790. }
  791. if (response.status == 'success')
  792. {
  793. var tag_id = response.tag_id;
  794. var tag_name = response.tag_name;
  795. $('input#tags_selected_tag_'+form_name).val(tag_id);
  796. inputTag.val(tag_name);
  797. // Et on execute l'évènement selectTag de l'input
  798. inputTag.trigger("selectTag");
  799. // On cache la liste puisque le choix vient d'être fait
  800. divtags.hide();
  801. link_add_tag.parents('div.search_tag_list').find('img.tag_loader').hide();
  802. $('#fade').fadeOut(400, function(){$('#fade').remove();});
  803. $('#add_tag').remove();
  804. }
  805. if (response.status == 'error')
  806. {
  807. $('form[name="add_tag"]').find('ul.error_list').remove();
  808. var ul_errors = $('<ul>').addClass('error_list');
  809. for (i in response.errors)
  810. {
  811. ul_errors.append($('<li>').append(response.errors[i]));
  812. }
  813. $('form[name="add_tag"]').prepend(ul_errors);
  814. }
  815. return false;
  816. })
  817. .append($('<div>').addClass('tag')
  818. .append($('<ul>')
  819. .append($('<li>').addClass('button')
  820. .append(link_add_tag.text()))))
  821. .append($('<p>').append(string_tag_add_text))
  822. .append($('<p>').append(string_tag_add_argument))
  823. .append($('<textarea>').attr('name', 'argument'))
  824. .append($('<div>').addClass('inputs')
  825. .append($('<input>')
  826. .attr('type', 'button')
  827. .attr('value', string_tag_add_inputs_cancel)
  828. .addClass('button')
  829. .click(function(){
  830. $('#fade').fadeOut(1000, function(){$('#fade').remove();});
  831. $('#add_tag').remove();
  832. return false;
  833. })
  834. )
  835. .append($('<input>')
  836. .attr('type', 'submit')
  837. .attr('value', string_tag_add_inputs_submit)
  838. .addClass('button')
  839. .click(function(){
  840. link_add_tag.parents('div.search_tag_list').find('img.tag_loader').show();
  841. })
  842. )
  843. .append($('<input>').attr('type', 'hidden').attr('name', 'tag_name').val(link_add_tag.text()))
  844. ))
  845. ;
  846. // Il faut ajouter le popup au dom avant de le positionner en css
  847. // Sinon la valeur height n'est pas encore calculable
  848. $('body').prepend(popup);
  849. //Récupération du margin, qui permettra de centrer la fenêtre - on ajuste de 80px en conformité avec le CSS
  850. var popMargTop = (popup.height() + 50) / 2;
  851. var popMargLeft = (popup.width() + 50) / 2;
  852. //On affecte le margin
  853. $(popup).css({
  854. 'margin-top' : -popMargTop,
  855. 'margin-left' : -popMargLeft
  856. });
  857. return false;
  858. }
  859. var last_keypress = 0;
  860. function check_timelaps_and_search(input, form_name, time_id, timed, info)
  861. {
  862. if (!timed)
  863. {
  864. // C'est une nouvelle touche (pas redirigé) on lui donne un id
  865. // et on met a jour l'id de la dernière pressé
  866. last_keypress = new Date().getTime();
  867. var this_time_id = last_keypress;
  868. }
  869. else
  870. {
  871. // Si elle a été redirigé, on met son id dans cette variable
  872. var this_time_id = time_id;
  873. }
  874. // C'est une touche redirigé dans le temps qui a été suivit d'une autre touche
  875. if (time_id != last_keypress && timed)
  876. {
  877. // elle disparait
  878. }
  879. else
  880. {
  881. //
  882. if ((new Date().getTime() - last_keypress) < 600 || timed == false)
  883. {
  884. // Si elle vient d'être tapé (timed == false) elle doit attendre (au cas ou une autre touche soit tapé)
  885. // Si c'est une redirigé qui n'a pas été remplacé par une nouvelle lettre
  886. // elle doit attendre au cas ou soit pressé.
  887. setTimeout(function(){check_timelaps_and_search(input, form_name, this_time_id, true, info)}, 700);
  888. }
  889. else
  890. {
  891. // il n'y a plus a attendre, on envoie la demande de tag.
  892. autocomplete_tag(input, form_name);
  893. }
  894. }
  895. }
  896. // Autocompletion de tags
  897. $("div.tags_prompt ul.tagbox li.input input").live('keypress', function(e){
  898. var form_name = $(this).parents('form').attr('name');
  899. var code = (e.keyCode ? e.keyCode : e.which);
  900. if ((e.which !== 0 && e.charCode !== 0) || (code == 8 || code == 46))
  901. {
  902. check_timelaps_and_search($(this), form_name, new Date().getTime(), false, $(this).val());
  903. }
  904. });
  905. // Un click sur ce lien affiche tout les tags cachés de la liste
  906. $('div.search_tag_list a.more').live('click', function(){
  907. jQuery.each( $(this).parent('div').find('ul.search_tag_list li') , function(){
  908. $(this).show();
  909. });
  910. $(this).hide();
  911. return false;
  912. });
  913. $('ul.tagbox li.input input[type="text"]').formDefaults();
  914. ////////////////// FIN TAG PROMPT ///////////////
  915. // Suppression d'un element
  916. $('a.group_remove_link').jConfirmAction({
  917. question : "Supprimer ce groupe ?",
  918. yesAnswer : "Oui",
  919. cancelAnswer : "Non",
  920. onYes: function(link){
  921. window.location = link.attr('href');
  922. return false;
  923. },
  924. onOpen: function(){},
  925. onClose: function(){}
  926. });
  927. // Selection Réseau global / Mon réseau
  928. $('div.select_network a').live('click', function(){
  929. var divSelect = $(this).parent('div');
  930. if ($(this).hasClass('all_network'))
  931. {
  932. divSelect.find('a.all_network').addClass('active');
  933. divSelect.find('a.my_network').removeClass('active');
  934. divSelect.find('select').val('network_public');
  935. }
  936. else
  937. {
  938. divSelect.find('a.my_network').addClass('active');
  939. divSelect.find('a.all_network').removeClass('active');
  940. divSelect.find('select').val('network_personal');
  941. }
  942. });
  943. function element_add_proceed_json_response(response)
  944. {
  945. if (response.status == 'success')
  946. {
  947. $('form[name="add"]').find('ul.error_list').remove();
  948. $('ul.elements').prepend(response.html);
  949. $('form[name="add"] input[type="text"]').val('');
  950. if ($('form[name="search"]').length)
  951. {
  952. $('form[name="search"]').slideDown();
  953. }
  954. remove_tags('add');
  955. recolorize_element_list();
  956. $('div#element_add_box').slideUp();
  957. if (response.groups.length)
  958. {
  959. // Des groupes sont proposés pour diffuser cet élément
  960. $('div#added_element_to_group').slideDown();
  961. for (i in response.groups)
  962. {
  963. var group = response.groups[i];
  964. $('ul#groups_to_add_element').html('');
  965. $('ul#groups_to_add_element')
  966. .append($('<li>')
  967. .append($('<a>')
  968. .addClass('added_element_add_to_group')
  969. .attr('href', group.url)
  970. .append(group.name)
  971. )
  972. )
  973. ;
  974. }
  975. }
  976. else
  977. {
  978. $('a#element_add_link').show();
  979. }
  980. form_add_hide_errors();
  981. return true;
  982. }
  983. else if (response.status == 'error')
  984. {
  985. form_add_display_errors(response.errors);
  986. $('#form_add_loader').hide();
  987. return false;
  988. }
  989. return false;
  990. }
  991. function form_add_hide_errors()
  992. {
  993. $('form[name="add"]').find('ul.error_list').remove();
  994. }
  995. // Affichage des erreurs lors de laprocédure d'ajout d'un élément
  996. function form_add_display_errors(errors)
  997. {
  998. $('form[name="add"]').find('ul.error_list').remove();
  999. var ul_errors = $('<ul>').addClass('error_list');
  1000. for (i in errors)
  1001. {
  1002. ul_errors.append($('<li>').append(errors[i]));
  1003. }
  1004. $('form[name="add"]').prepend(ul_errors);
  1005. }
  1006. // Ajout d'un element #ajouter (première partie)
  1007. // // Click sur "ajouter" (l'url)
  1008. // $('a#form_add_check_url').click(function(){
  1009. //
  1010. // // On fait tourner notre gif loader
  1011. // $('img#form_add_loader').show();
  1012. //
  1013. // $.ajax({
  1014. // type: 'POST',
  1015. // url: url_datas_api,
  1016. // data: {'url':$('input#element_add_url').val()},
  1017. // success: function(response){
  1018. //
  1019. // if (response.status == 'mustbeconnected')
  1020. // {
  1021. // $(location).attr('href', url_index);
  1022. // }
  1023. //
  1024. // if (response.status == 'success')
  1025. // {
  1026. // // On cache notre gif loader.
  1027. // $('img#form_add_loader').hide();
  1028. //
  1029. // // On commence par renseigner les champs si on a du concret
  1030. // // name
  1031. // if (response.name)
  1032. // {
  1033. // $('input#element_add_name').val(response.name);
  1034. // }
  1035. //
  1036. // // thumb
  1037. // $('div#form_add_thumb img').attr('src', '/bundles/muzichcore/img/nothumb.png');
  1038. // if (response.thumb)
  1039. // {
  1040. // $('div#form_add_thumb img').attr('src', response.thumb);
  1041. // }
  1042. //
  1043. // // Proposition de tags
  1044. // if (response.tags)
  1045. // {
  1046. // $('ul#form_add_prop_tags li').remove();
  1047. // $('ul#form_add_prop_tags').show();
  1048. // $('ul#form_add_prop_tags_text').show();
  1049. //
  1050. // for (tags_index = 0; tags_index < response.tags.length; tags_index++)
  1051. // {
  1052. // var tag = response.tags[tags_index];
  1053. // var tag_id = '';
  1054. // var tag_name = tag.original_name;
  1055. // // Si il y a des équivalent en base.
  1056. // if (tag.like_found)
  1057. // {
  1058. // tag_id = tag.like.id;
  1059. // tag_name = tag.like.name;
  1060. // }
  1061. //
  1062. // // On aura plus qu'a vérifie le href pour savoir si c'est une demande d'ajout de tags =)
  1063. // $('ul#form_add_prop_tags').append(
  1064. // '<li>'+
  1065. // '<a href="#'+tag_id+'" class="form_add_prop_tag">'+
  1066. // tag_name+
  1067. // '</a>'+
  1068. // '</li>'
  1069. // );
  1070. // }
  1071. // }
  1072. //
  1073. // // On a plus qu'a afficher les champs
  1074. // $('div#form_add_second_part').slideDown();
  1075. // $('div#form_add_first_part').slideUp();
  1076. // form_add_hide_errors();
  1077. // }
  1078. // else if (response.status == 'error')
  1079. // {
  1080. // form_add_display_errors(response.errors);
  1081. // $('#form_add_loader').hide();
  1082. // return false;
  1083. // }
  1084. // },
  1085. // dataType: 'json'
  1086. // });
  1087. //
  1088. // });
  1089. function element_add_proceed_data_apis(response)
  1090. {
  1091. if (response.status == 'mustbeconnected')
  1092. {
  1093. $(location).attr('href', url_index);
  1094. }
  1095. if (response.status == 'success')
  1096. {
  1097. // On cache notre gif loader.
  1098. $('img#form_add_loader').hide();
  1099. // On commence par renseigner les champs si on a du concret
  1100. // name
  1101. if (response.name)
  1102. {
  1103. $('input#element_add_name').val(response.name);
  1104. }
  1105. // thumb
  1106. $('div#form_add_thumb img').attr('src', '/bundles/muzichcore/img/nothumb.png');
  1107. if (response.thumb)
  1108. {
  1109. $('div#form_add_thumb img').attr('src', response.thumb);
  1110. }
  1111. // Proposition de tags
  1112. if (response.tags)
  1113. {
  1114. $('ul#form_add_prop_tags li').remove();
  1115. $('ul#form_add_prop_tags_api').show();
  1116. $('p#form_add_prop_tags_text').hide();
  1117. if (response.tags.length)
  1118. {
  1119. $('p#form_add_prop_tags_text').show();
  1120. }
  1121. $('ul#form_add_prop_tags_api li').remove();
  1122. for (tags_index = 0; tags_index < response.tags.length; tags_index++)
  1123. {
  1124. var tag = response.tags[tags_index];
  1125. var tag_id = '';
  1126. var tag_name = tag.original_name;
  1127. // Si il y a des équivalent en base.
  1128. if (tag.like_found)
  1129. {
  1130. tag_id = tag.like.id;
  1131. tag_name = tag.like.name;
  1132. }
  1133. // On aura plus qu'a vérifie le href pour savoir si c'est une demande d'ajout de tags =)
  1134. $('ul#form_add_prop_tags_api').append(
  1135. '<li>'+
  1136. '<a href="#'+tag_id+'" class="form_add_prop_tag">'+
  1137. tag_name+
  1138. '</a>'+
  1139. '</li>'
  1140. );
  1141. }
  1142. }
  1143. return true;
  1144. }
  1145. else if (response.status == 'error')
  1146. {
  1147. return false;
  1148. }
  1149. return true;
  1150. }
  1151. /*
  1152. * Formulaire d'ajout: click sur proposition de tags du a une api
  1153. */
  1154. $('a.form_add_prop_tag').live('click', function(){
  1155. var form_name = "add";
  1156. var tag_id = str_replace('#', '', $(this).attr('href'));
  1157. var input_tag = $("div.tags_prompt ul.tagbox li.input input");
  1158. // Si on connait le tag id (pas un nouveau tag donc)
  1159. if (tag_id)
  1160. {
  1161. $('input#tags_selected_tag_'+form_name).val(tag_id);
  1162. input_tag.val($(this).text());
  1163. // Et on execute l'évènement selectTag de l'input
  1164. input_tag.trigger("selectTag");
  1165. }
  1166. else
  1167. {
  1168. // Cette var sert a rien ici, mais c'est la refactorisation qui
  1169. // pose problmeme (corrigeable cela dit)
  1170. var divtags = $("#search_tag_"+form_name);
  1171. form_add_open_dialog_for_new_tag($(this), input_tag, form_name, divtags);
  1172. }
  1173. // On nettoie le champs de saisie des tags
  1174. $('input.form-default-value-processed').val('');
  1175. });
  1176. // #ajouter ajouter un élément (envoi du formulaire)
  1177. $('form[name="add"] input[type="submit"]').live('click', function(){
  1178. $('form[name="add"]').find('img.tag_loader').show();
  1179. });
  1180. $('form[name="add"]').ajaxForm(function(response) {
  1181. if (response.status == 'mustbeconnected')
  1182. {
  1183. $(location).attr('href', url_index);
  1184. }
  1185. $('form[name="add"] img.tag_loader').hide();
  1186. // Si on en est a la promière étape la réponse sera des données récupérés auprès
  1187. // des apis
  1188. if ($('input#form_add_step').val() == '1')
  1189. {
  1190. if (element_add_proceed_data_apis(response))
  1191. {
  1192. // On a plus qu'a afficher les champs
  1193. $('div#form_add_second_part').slideDown();
  1194. $('div#form_add_first_part').slideUp();
  1195. form_add_hide_errors();
  1196. $('#form_add_loader').hide();
  1197. $('input#form_add_step').val('2');
  1198. // On doit avoir le slug du groupe si on ajoute a un groupe
  1199. if (!$('input#add_element_group_page').length)
  1200. {
  1201. $('form[name="add"]').attr('action', url_element_add);
  1202. }
  1203. else
  1204. {
  1205. $('form[name="add"]').attr('action', url_element_add+'/'+$('input#add_element_group_page').val());
  1206. }
  1207. $('span#add_url_title_url').html($('input#element_add_url').val());
  1208. }
  1209. else
  1210. {
  1211. form_add_display_errors(response.errors);
  1212. $('#form_add_loader').hide();
  1213. }
  1214. }
  1215. else if ($('input#form_add_step').val() == '2')
  1216. {
  1217. if (element_add_proceed_json_response(response))
  1218. {
  1219. form_add_reinit();
  1220. }
  1221. }
  1222. return false;
  1223. });
  1224. function form_add_reinit()
  1225. {
  1226. $('div#element_add_box').slideUp();
  1227. $('div#form_add_first_part').show();
  1228. $('div#form_add_second_part').hide();
  1229. $('ul#form_add_prop_tags_api').hide();
  1230. $('ul#form_add_prop_tags_text').hide();
  1231. $('input#element_add_url').val('');
  1232. $('input#element_add_name').val('');
  1233. $('input#form_add_step').val(1);
  1234. $('form[name="add"]').attr('action', url_datas_api);
  1235. }
  1236. /////////////////////
  1237. var tags_ids_for_filter = new Array();
  1238. // Filtre par tags (show, favorite)
  1239. function refresh_elements_with_tags_selected(link)
  1240. {
  1241. // Puis on fait notre rekékéte ajax.
  1242. $('ul.elements').html('');
  1243. $('div.no_elements').hide();
  1244. $('img.elements_more_loader').show();
  1245. $.getJSON($('input#get_elements_url').val()+'/'+array2json(tags_ids_for_filter), function(response){
  1246. if (response.status == 'mustbeconnected')
  1247. {
  1248. $(location).attr('href', url_index);
  1249. }
  1250. $('ul.elements').html(response.html);
  1251. if (response.count)
  1252. {
  1253. $('img.elements_more_loader').hide();
  1254. $('span.elements_more').show();
  1255. $('a.elements_more').show();
  1256. }
  1257. });
  1258. return false;
  1259. }
  1260. function list_tag_clicked(link, erease)
  1261. {
  1262. if (erease)
  1263. {
  1264. $('ul#favorite_tags a.tag').removeClass('active');
  1265. }
  1266. // Ensuite on l'active ou le désactive
  1267. if (link.hasClass('active'))
  1268. {
  1269. link.removeClass('active');
  1270. }
  1271. else
  1272. {
  1273. link.addClass('active');
  1274. }
  1275. // On construit notre liste de tags
  1276. tags_ids_for_filter = new Array();
  1277. $('ul#favorite_tags a.tag.active').each(function(index){
  1278. var id = str_replace('filtering_tag_', '', $(this).attr('id'));
  1279. tags_ids_for_filter[id] = id;
  1280. });
  1281. // On adapte le lien afficher plus de résultats
  1282. var a_more = $('a.elements_more');
  1283. a_more.attr('href', $('input#more_elements_url').val()+'/'+array2json(tags_ids_for_filter));
  1284. // On adapte aussi le lien de l'autoplay
  1285. $('a#autoplay_launch').attr('href', $('input#autoplay_url').val()+'/'+array2json(tags_ids_for_filter));
  1286. return check_timelaps_and_find_with_tags(link, new Date().getTime(), false);
  1287. }
  1288. $('ul#favorite_tags a.tag').click(function(){
  1289. list_tag_clicked($(this));
  1290. });
  1291. last_keypress = 0;
  1292. function check_timelaps_and_find_with_tags(link, time_id, timed)
  1293. {
  1294. if (!timed)
  1295. {
  1296. // C'est une nouvelle touche (pas redirigé) on lui donne un id
  1297. // et on met a jour l'id de la dernière pressé
  1298. last_keypress = new Date().getTime();
  1299. var this_time_id = last_keypress;
  1300. }
  1301. else
  1302. {
  1303. // Si elle a été redirigé, on met son id dans cette variable
  1304. var this_time_id = time_id;
  1305. }
  1306. // C'est une touche redirigé dans le temps qui a été suivit d'une autre touche
  1307. if (time_id != last_keypress && timed)
  1308. {
  1309. // elle disparait
  1310. }
  1311. else
  1312. {
  1313. //
  1314. if ((new Date().getTime() - last_keypress) < 800 || timed == false)
  1315. {
  1316. // Si elle vient d'être tapé (timed == false) elle doit attendre (au cas ou une autre touche soit tapé)
  1317. // Si c'est une redirigé qui n'a pas été remplacé par une nouvelle lettre
  1318. // elle doit attendre au cas ou soit pressé.
  1319. setTimeout(function(){check_timelaps_and_find_with_tags(link, this_time_id, true)}, 900);
  1320. }
  1321. else
  1322. {
  1323. // il n'y a plus a attendre, on envoie la demande de tag.
  1324. return refresh_elements_with_tags_selected(link);
  1325. }
  1326. }
  1327. return null;
  1328. }
  1329. ////////////////////////////////////////
  1330. /// Gestion de nouveaux éléments
  1331. var do_check_new_elements = false;
  1332. function check_new_elements()
  1333. {
  1334. if ($('ul.elements li').length)
  1335. {
  1336. // Si l'utilisateur a quitté la page on reporte le check
  1337. if ($('body.blurred').length)
  1338. {
  1339. // on passe la variable a vrai de façon a ce que lorsque la page
  1340. // et ré affiché on lance le check
  1341. do_check_new_elements = true;
  1342. }
  1343. else
  1344. {
  1345. var url = url_element_new_count
  1346. +'/'
  1347. +str_replace('element_', '', $('ul.elements li:first').attr('id'))
  1348. ;
  1349. $.ajax({
  1350. type: 'POST',
  1351. url: url,
  1352. data: $('form[name="search"]').serialize(),
  1353. success: function(response){
  1354. if (response.status == 'mustbeconnected')
  1355. {
  1356. $(location).attr('href', url_index);
  1357. }
  1358. if (response.status == 'success' && response.count)
  1359. {
  1360. $('div.display_more_elements').show();
  1361. $('div.display_more_elements span').html(response.message);
  1362. }
  1363. setTimeout(check_new_elements, 150000);
  1364. },
  1365. dataType: "json"
  1366. });
  1367. // $.getJSON(url, function(response){
  1368. //
  1369. // if (response.status == 'mustbeconnected')
  1370. // {
  1371. // $(location).attr('href', url_index);
  1372. // }
  1373. //
  1374. // if (response.status == 'success' && response.count)
  1375. // {
  1376. // $('div.display_more_elements').show();
  1377. // $('div.display_more_elements span').html(response.message);
  1378. // }
  1379. //
  1380. // setTimeout(check_new_elements, 150000);
  1381. // });
  1382. do_check_new_elements = false;
  1383. }
  1384. }
  1385. }
  1386. if ($('div.display_more_elements').length)
  1387. {
  1388. setTimeout(check_new_elements, 150000);
  1389. }
  1390. $('a.show_new_elements').live('click', function(){
  1391. var url = url_element_new_get
  1392. +'/'
  1393. +str_replace('element_', '', $('ul.elements li:first').attr('id'))
  1394. ;
  1395. $('img.elements_new_loader').show();
  1396. $.ajax({
  1397. type: 'POST',
  1398. url: url,
  1399. data: $('form[name="search"]').serialize(),
  1400. success: function(response){
  1401. if (response.status == 'mustbeconnected')
  1402. {
  1403. $(location).attr('href', url_index);
  1404. }
  1405. if (response.status == 'success')
  1406. {
  1407. if (response.count)
  1408. {
  1409. $('div.display_more_elements').show();
  1410. $('div.display_more_elements span').html(response.message);
  1411. }
  1412. else
  1413. {
  1414. $('div.display_more_elements').hide();
  1415. }
  1416. $('ul.elements').prepend(response.html);
  1417. recolorize_element_list();
  1418. }
  1419. $('img.elements_new_loader').hide();
  1420. },
  1421. dataType: "json"
  1422. });
  1423. // $.getJSON(url, function(response){
  1424. //
  1425. // if (response.status == 'mustbeconnected')
  1426. // {
  1427. // $(location).attr('href', url_index);
  1428. // }
  1429. //
  1430. // if (response.status == 'success')
  1431. // {
  1432. // if (response.count)
  1433. // {
  1434. // $('div.display_more_elements').show();
  1435. // $('div.display_more_elements span').html(response.message);
  1436. // }
  1437. // else
  1438. // {
  1439. // $('div.display_more_elements').hide();
  1440. // }
  1441. //
  1442. // $('ul.elements').prepend(response.html);
  1443. // recolorize_element_list();
  1444. // }
  1445. //
  1446. // $('img.elements_new_loader').hide();
  1447. // });
  1448. });
  1449. function recolorize_element_list()
  1450. {
  1451. $('ul.elements li.element').each(function(index){
  1452. if ((index & 1) == 1)
  1453. {
  1454. $(this).removeClass('even');
  1455. $(this).removeClass('odd');
  1456. $(this).addClass('odd');
  1457. }
  1458. else
  1459. {
  1460. $(this).removeClass('odd');
  1461. $(this).removeClass('even');
  1462. $(this).addClass('even');
  1463. }
  1464. });
  1465. }
  1466. /*
  1467. * Action a effectuer lorsque l'utilisateur met le focus sur la page
  1468. */
  1469. function do_action_body_focused()
  1470. {
  1471. if (do_check_new_elements)
  1472. {
  1473. check_new_elements();
  1474. }
  1475. }
  1476. /*
  1477. * Commentaires d'élément
  1478. */
  1479. // Afficher les commentaires
  1480. $('td.element_content a.display_comments').live('click', function(){
  1481. display_comments($(this).parents('li.element'));
  1482. });
  1483. $('td.element_content a.hide_comments').live('click', function(){
  1484. hide_comments($(this).parents('li.element'));
  1485. });
  1486. function display_comments(li_element)
  1487. {
  1488. li_element.find('div.comments').slideDown();
  1489. li_element.find('a.display_comments').hide();
  1490. li_element.find('a.hide_comments').show();
  1491. }
  1492. function hide_comments(li_element)
  1493. {
  1494. li_element.find('div.comments').slideUp();
  1495. li_element.find('a.display_comments').show();
  1496. li_element.find('a.hide_comments').hide();
  1497. }
  1498. // Ajouter un commentaire
  1499. $('li.element a.add_comment').live('click', function(){
  1500. display_add_comment($(this).parents('li.element'));
  1501. });
  1502. $('form.add_comment input[type="submit"]').live('click', function(){
  1503. $(this).parents('div.comments').find('img.comments_loader').show();
  1504. });
  1505. function display_add_comment(li_element)
  1506. {
  1507. display_comments(li_element);
  1508. li_element.find('a.add_comment').hide();
  1509. li_element.find('form.add_comment').show();
  1510. li_element.find('form.add_comment').ajaxForm(function(response) {
  1511. if (response.status == 'mustbeconnected')
  1512. {
  1513. $(location).attr('href', url_index);
  1514. }
  1515. li_element.find('img.comments_loader').hide();
  1516. if (response.status == 'success')
  1517. {
  1518. li_element.find('form.add_comment').find('ul.error_list').remove();
  1519. li_element.find('div.comments ul.comments').append(response.html);
  1520. hide_add_comment(li_element);
  1521. }
  1522. else if (response.status == 'error')
  1523. {
  1524. li_element.find('form.add_comment').find('ul.error_list').remove();
  1525. var ul_errors = $('<ul>').addClass('error_list');
  1526. for (i in response.errors)
  1527. {
  1528. ul_errors.append($('<li>').append(response.errors[i]));
  1529. }
  1530. li_element.find('form.add_comment').prepend(ul_errors);
  1531. }
  1532. return false;
  1533. });
  1534. }
  1535. $('form.add_comment input.cancel').live('click', function(){
  1536. var li_element = $(this).parents('li.element');
  1537. hide_add_comment(li_element);
  1538. });
  1539. function hide_add_comment(li_element)
  1540. {
  1541. li_element.find('a.add_comment').show();
  1542. li_element.find('form.add_comment').hide();
  1543. li_element.find('form.add_comment textarea').val('');
  1544. }
  1545. // Modifier et supprimer
  1546. // Affichage du bouton Modifier et Supprimer
  1547. $('ul.comments li.comment').live({
  1548. mouseenter:
  1549. function()
  1550. {
  1551. $(this).find('a.comment_edit_link').show();
  1552. $(this).find('a.comment_remove_link').show();
  1553. },
  1554. mouseleave:
  1555. function()
  1556. {
  1557. if (!$(this).find('a.comment_edit_link').hasClass('mustBeDisplayed'))
  1558. {
  1559. $(this).find('a.comment_edit_link').hide();
  1560. }
  1561. if (!$(this).find('a.comment_remove_link').hasClass('mustBeDisplayed'))
  1562. {
  1563. $(this).find('a.comment_remove_link').hide();
  1564. }
  1565. }
  1566. }
  1567. );
  1568. // Supprimer
  1569. $('a.comment_remove_link').jConfirmAction({
  1570. question : string_comment_delete_confirm_sentence,
  1571. yesAnswer : string_comment_delete_confirm_yes,
  1572. cancelAnswer : string_comment_delete_confirm_no,
  1573. onYes: function(link){
  1574. var li = link.parents('li.comment');
  1575. li.find('img.comment_loader').show();
  1576. $.getJSON(link.attr('href'), function(response){
  1577. li.find('img.comment_loader').hide();
  1578. if (response.status == 'mustbeconnected')
  1579. {
  1580. $(location).attr('href', url_index);
  1581. }
  1582. if (response.status == 'success')
  1583. {
  1584. li.remove();
  1585. }
  1586. });
  1587. return false;
  1588. },
  1589. onOpen: function(link){
  1590. var li = link.parents('li.comment');
  1591. li.find('a.comment_edit_link').addClass('mustBeDisplayed');
  1592. li.find('a.comment_remove_link').addClass('mustBeDisplayed');
  1593. },
  1594. onClose: function(link){
  1595. var li = link.parents('li.comment');
  1596. li.find('a.comment_edit_link').removeClass('mustBeDisplayed');
  1597. li.find('a.comment_remove_link').removeClass('mustBeDisplayed');
  1598. li.find('a.comment_edit_link').hide();
  1599. li.find('a.comment_remove_link').hide();
  1600. }
  1601. });
  1602. var comments_edited = new Array();
  1603. // Modification
  1604. // Ouverture du formulaire de modification
  1605. $('a.comment_edit_link').live('click', function(){
  1606. var link = $(this);
  1607. var li = link.parents('li.comment');
  1608. // On garde en mémoire l'élément édité en cas d'annulation
  1609. comments_edited[li.attr('id')] = li.html();
  1610. var loader = li.find('img.comment_loader');
  1611. li.html(loader);
  1612. li.find('img.comment_loader').show();
  1613. $.getJSON($(this).attr('href'), function(response) {
  1614. if (response.status == 'mustbeconnected')
  1615. {
  1616. $(location).attr('href', url_index);
  1617. }
  1618. li.html(response.html);
  1619. // On rend ce formulaire ajaxFormable
  1620. $('li#'+li.attr('id')+' form.edit_comment input[type="submit"]').live('click', function(){
  1621. var li_current = $(this).parents('li.comment');
  1622. li_current.prepend(loader);
  1623. li_current.find('img.comment_loader').show();
  1624. });
  1625. li.find('form.edit_comment').ajaxForm(function(response){
  1626. li = $('li#'+response.dom_id);
  1627. li.find('img.comment_loader').hide();
  1628. if (response.status == 'mustbeconnected')
  1629. {
  1630. $(location).attr('href', url_index);
  1631. }
  1632. if (response.status == 'success')
  1633. {
  1634. li.html(response.html);
  1635. delete(comments_edited[li.attr('id')]);
  1636. }
  1637. else if (response.status == 'error')
  1638. {
  1639. li.find('ul.error_list').remove();
  1640. var ul_errors = $('<ul>').addClass('error_list');
  1641. for (i in response.errors)
  1642. {
  1643. ul_errors.append($('<li>').append(response.errors[i]));
  1644. }
  1645. li.prepend(ul_errors);
  1646. }
  1647. });
  1648. });
  1649. return false;
  1650. });
  1651. // Annulation d'un formulaire de modification d'un comment
  1652. $('form.edit_comment input.cancel').live('click', function(){
  1653. var li = $(this).parents('li.comment');
  1654. li.html(comments_edited[li.attr('id')]);
  1655. delete(comments_edited[li.attr('id')]);
  1656. });
  1657. /*
  1658. * Ajout d'un tag en favoris a partir d'un élément
  1659. */
  1660. $('li.element_tag').live({
  1661. mouseenter:
  1662. function()
  1663. {
  1664. $(this).find('a.tag_to_favorites').show();
  1665. $(this).find('a.element_tag').addClass('element_tag_large_for_fav');
  1666. },
  1667. mouseleave:
  1668. function()
  1669. {
  1670. if (!$(this).find('a.tag_to_favorites').hasClass('mustBeDisplayed'))
  1671. {
  1672. $(this).find('a.tag_to_favorites').hide();
  1673. $(this).find('a.element_tag').removeClass('element_tag_large_for_fav');
  1674. }
  1675. }
  1676. }
  1677. );
  1678. $('a.tag_to_favorites').jConfirmAction({
  1679. question : string_tag_addtofav_confirm_sentence,
  1680. yesAnswer : string_tag_addtofav_confirm_yes,
  1681. cancelAnswer : string_tag_addtofav_confirm_no,
  1682. onYes: function(link){
  1683. $.getJSON(link.attr('href'), function(response){
  1684. if (response.status == 'mustbeconnected')
  1685. {
  1686. $(location).attr('href', url_index);
  1687. }
  1688. });
  1689. $('div.question').fadeOut();
  1690. return false;
  1691. },
  1692. onOpen: function(link){
  1693. var li = link.parents('li.element_tag');
  1694. li.find('a.tag_to_favorites').addClass('mustBeDisplayed');
  1695. },
  1696. onClose: function(link){
  1697. var li = link.parents('li.element_tag');
  1698. li.find('a.tag_to_favorites').removeClass('mustBeDisplayed');
  1699. li.find('a.element_tag').removeClass('element_tag_large_for_fav');
  1700. li.find('a.tag_to_favorites').hide();
  1701. }
  1702. });
  1703. /*
  1704. * Ajout dans un groupe de l'élément envoyé
  1705. */
  1706. $('a.added_element_add_to_group').live('click', function(){
  1707. var loader = $('div#added_element_to_group').find('img.loader');
  1708. loader.show();
  1709. $.getJSON($(this).attr('href'), function(response) {
  1710. loader.hide();
  1711. if (response.status == 'mustbeconnected')
  1712. {
  1713. $(location).attr('href', url_index);
  1714. }
  1715. if (response.status == 'success')
  1716. {
  1717. $('li#'+response.dom_id).html(response.html);
  1718. }
  1719. $('div#added_element_to_group').slideUp();
  1720. $('a#element_add_link').show();
  1721. });
  1722. return false;
  1723. });
  1724. $('div#added_element_to_group a.cancel').live('click', function(){
  1725. $('div#added_element_to_group').slideUp();
  1726. $('a#element_add_link').show();
  1727. return false;
  1728. });
  1729. /*
  1730. * Report / signalement d'un élément
  1731. */
  1732. $('a.element_report').jConfirmAction({
  1733. question : string_elementreport_confirm_sentence,
  1734. yesAnswer : string_elementreport_confirm_yes,
  1735. cancelAnswer : string_elementreport_confirm_no,
  1736. onYes: function(link){
  1737. $.getJSON(link.attr('href'), function(response){
  1738. if (response.status == 'mustbeconnected')
  1739. {
  1740. $(location).attr('href', url_index);
  1741. }
  1742. });
  1743. $('div.question').fadeOut();
  1744. return false;
  1745. },
  1746. onOpen: function(link){
  1747. },
  1748. onClose: function(link){
  1749. }
  1750. });
  1751. /*
  1752. * Vote sur element
  1753. */
  1754. $('li.element a.vote').live('click', function(){
  1755. var img = $(this).find('img');
  1756. var link = $(this);
  1757. img.attr('src', url_img_ajax_loader);
  1758. $.getJSON(link.attr('href'), function(response){
  1759. if (response.status == 'mustbeconnected')
  1760. {
  1761. $(location).attr('href', url_index);
  1762. }
  1763. if (response.status == 'success')
  1764. {
  1765. link.attr('href', response.data.a.href);
  1766. img.attr('src', response.data.img.src);
  1767. link.parents('td.right').find('li.score span.score').html(response.data.element.points);
  1768. }
  1769. });
  1770. return false;
  1771. });
  1772. // Enlever les ids du ElementSearch
  1773. $('div.more_filters a.new_comments, div.more_filters a.new_favorites, div.more_filters a.new_tags').live('click', function(){
  1774. $('img.elements_more_loader').show();
  1775. $('ul.elements').html('');
  1776. var link = $(this);
  1777. $.getJSON(link.attr('href'), function(response){
  1778. if (response.status == 'mustbeconnected')
  1779. {
  1780. $(location).attr('href', url_index);
  1781. }
  1782. if (response.status == 'success')
  1783. {
  1784. $('form[name="search"]').submit();
  1785. $('div.more_filters a.new_comments').hide();
  1786. $('div.more_filters a.new_favorites').hide();
  1787. $('div.more_filters a.new_tags').hide();
  1788. }
  1789. });
  1790. return false;
  1791. });
  1792. /*
  1793. *
  1794. * Proposition de tags sur un élément
  1795. *
  1796. */
  1797. // Ouverture du formulaire de modification
  1798. $('a.element_propose_tags').live('click', function(){
  1799. var link = $(this);
  1800. var li = link.parents('li.element');
  1801. li.find('img.element_loader').show();
  1802. $.getJSON($(this).attr('href'), function(response) {
  1803. if (response.status == 'mustbeconnected')
  1804. {
  1805. $(location).attr('href', url_index);
  1806. }
  1807. li.find('img.element_loader').hide();
  1808. if (response.status == 'success')
  1809. {
  1810. // On prépare le tagBox
  1811. var table = li.find('table:first');
  1812. li.find('div.tag_proposition').remove();
  1813. table.after(response.html);
  1814. // Pour le click sur l'input de saisie de tag
  1815. li.find('ul.tagbox li.input input[type="text"]').formDefaults();
  1816. var options = new Array();
  1817. options.form_name = response.form_name;
  1818. options.tag_init = response.tags;
  1819. ajax_query_timestamp = null;
  1820. $("#tags_prompt_list_"+response.form_name).tagBox(options);
  1821. // On rend ce formulaire ajaxFormable
  1822. $('form[name="'+response.form_name+'"] input[type="submit"]').live('click', function(){
  1823. li = $(this).parents('li.element');
  1824. li.find('img.element_loader').show();
  1825. });
  1826. $('form[name="'+response.form_name+'"]').ajaxForm(function(response){
  1827. if (response.status == 'mustbeconnected')
  1828. {
  1829. $(location).attr('href', url_index);
  1830. }
  1831. if (response.status == 'success')
  1832. {
  1833. li = $('li#'+response.dom_id);
  1834. li.find('img.element_loader').hide();
  1835. li.find('form')
  1836. li.find('div.tag_proposition').remove();
  1837. }
  1838. else if (response.status == 'error')
  1839. {
  1840. li.find('img.element_loader').hide();
  1841. li.find('ul.error_list').remove();
  1842. var ul_errors = $('<ul>').addClass('error_list');
  1843. for (i in response.errors)
  1844. {
  1845. ul_errors.append($('<li>').append(response.errors[i]));
  1846. }
  1847. li.find('div.tag_proposition div.tags_prompt').prepend(ul_errors);
  1848. }
  1849. });
  1850. }
  1851. });
  1852. return false;
  1853. });
  1854. // Annulation d'un formulaire de modification d'élément
  1855. $('div.tag_proposition input.cancel').live('click', function(){
  1856. $(this).parents('div.tag_proposition').slideUp();
  1857. });
  1858. // Ouvrir les propositions de tags de l'élément
  1859. $('a.element_view_propositions_link').live('click', function(){
  1860. var link = $(this);
  1861. li = link.parents('li.element');
  1862. li.find('img.element_loader').show();
  1863. $.getJSON($(this).attr('href'), function(response) {
  1864. if (response.status == 'mustbeconnected')
  1865. {
  1866. $(location).attr('href', url_index);
  1867. }
  1868. li.find('img.element_loader').hide();
  1869. if (response.status == 'success')
  1870. {
  1871. var table = li.find('table:first');
  1872. li.find('div.tags_proposition_view').remove();
  1873. table.after(response.html);
  1874. }
  1875. });
  1876. return false;
  1877. });
  1878. $('a.accept_tag_propotision').live('click', function(){
  1879. var link = $(this);
  1880. var li = link.parents('li.element');
  1881. li.find('img.element_loader').show();
  1882. $.getJSON($(this).attr('href'), function(response) {
  1883. if (response.status == 'mustbeconnected')
  1884. {
  1885. $(location).attr('href', url_index);
  1886. }
  1887. li.find('img.element_loader').hide();
  1888. if (response.status == 'success')
  1889. {
  1890. li.html(response.html);
  1891. }
  1892. });
  1893. return false;
  1894. });
  1895. //
  1896. $('a.refuse_tag_propositions').live('click', function(){
  1897. var link = $(this);
  1898. var li = link.parents('li.element');
  1899. li.find('img.element_loader').show();
  1900. $.getJSON($(this).attr('href'), function(response) {
  1901. if (response.status == 'mustbeconnected')
  1902. {
  1903. $(location).attr('href', url_index);
  1904. }
  1905. li.find('img.element_loader').hide();
  1906. if (response.status == 'success')
  1907. {
  1908. li.find('div.tags_proposition_view').remove();
  1909. }
  1910. });
  1911. return false;
  1912. });
  1913. /*
  1914. * Proposition de tag sur un élément FIN
  1915. */
  1916. /*
  1917. * Report / signalement d'un commentaire
  1918. */
  1919. $('a.comment_report').jConfirmAction({
  1920. question : string_commentreport_confirm_sentence,
  1921. yesAnswer : string_commentreport_confirm_yes,
  1922. cancelAnswer : string_commentreport_confirm_no,
  1923. onYes: function(link){
  1924. $.getJSON(link.attr('href'), function(response){
  1925. if (response.status == 'mustbeconnected')
  1926. {
  1927. $(location).attr('href', url_index);
  1928. }
  1929. });
  1930. $('div.question').fadeOut();
  1931. return false;
  1932. },
  1933. onOpen: function(link){
  1934. },
  1935. onClose: function(link){
  1936. }
  1937. });
  1938. /*
  1939. * reshare repartage
  1940. */
  1941. $('a.element_reshare').jConfirmAction({
  1942. question : string_elementreshare_confirm_sentence,
  1943. yesAnswer : string_elementreshare_confirm_yes,
  1944. cancelAnswer : string_elementreshare_confirm_no,
  1945. onYes: function(link){
  1946. $('div.question').fadeOut();
  1947. $.getJSON(link.attr('href'), function(response){
  1948. if (response.status == 'mustbeconnected')
  1949. {
  1950. $(location).attr('href', url_index);
  1951. }
  1952. // On affiche l'élément que si on voit que le formulaire est sur la page
  1953. // Sinon c'est qu'on est sur une page ou on a pas normalement la possibilité
  1954. // d'ajouetr un élément.
  1955. if ($('form[name="add"]').length)
  1956. {
  1957. element_add_proceed_json_response(response);
  1958. }
  1959. return false;
  1960. });
  1961. return false;
  1962. },
  1963. onOpen: function(link){
  1964. },
  1965. onClose: function(link){
  1966. }
  1967. });
  1968. /*
  1969. * Cloud tags
  1970. */
  1971. $('a#display_all_cloud_tag').click(function(){
  1972. $('ul#favorite_tags li').show();
  1973. $(this).hide();
  1974. });
  1975. $('input#cloud_tags_filter').keyup(function(){
  1976. var search_string = $(this).val();
  1977. $('ul#favorite_tags li a').removeClass('highlight');
  1978. if (search_string.length > 1)
  1979. {
  1980. $('ul#favorite_tags li a').each(function(){
  1981. if ($(this).text().toUpperCase().search(search_string.toUpperCase()) != -1)
  1982. {
  1983. $(this).addClass('highlight')
  1984. }
  1985. });
  1986. }
  1987. });
  1988. });
  1989. /*
  1990. * Ouverture d'une boite avec effet fade et centré
  1991. * code origine: form_add_open_dialog_for_new_tag
  1992. */
  1993. function open_popin_dialog(object_id)
  1994. {
  1995. // Effet fade-in du fond opaque
  1996. $('body').append($('<div>').attr('id', 'fade'));
  1997. //Apparition du fond - .css({'filter' : 'alpha(opacity=80)'}) pour corriger les bogues de IE
  1998. $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
  1999. $('#'+object_id).css({
  2000. position: 'absolute',
  2001. left: ($(window).width()
  2002. - $('#'+object_id).width())/2,
  2003. // top: ($(window).height()
  2004. // - $('#'+object_id).height())/2
  2005. top: '10%'
  2006. });
  2007. $('#'+object_id).show();
  2008. }