muzich.js 69KB

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