1 #HTTP_HEADER{Content-Type: text/javascript; charset=#CHARSET}
4 Gestion des listes de documents :
5 - Choix des modes d'affichage (grand, case, liste courte)
6 - Gestion du tri par glisser-déposer
7 - Rechargement du conteneur des listes quand l'une d'elle est vidée
10 - Conteneur principal : .portfolios
11 - Listes : .liste_items.documents
12 - Listes ordonnables : .liste_items.documents.ordonner_rang_lien\[data-lien\]
16 /* Choix du mode affichage des documents (grand, en case, en liste courte) */
17 function choix_affichages_documents() {
18 $('.portfolios h3:not(:has(.affichages))').each(function () {
20 var liste = titre.next('.liste_items.documents');
21 var identifiant = liste.data('cookie-affichage');
24 "<div class='affichages'>"
25 +
"<span class='icone grand on' title='<:medias:affichage_documents_en_grand|attribut_html:>'></span>"
26 +
"<span class='icone cases' title='<:medias:affichage_documents_en_cases|attribut_html:>'></span>"
27 +
"<span class='icone liste' title='<:medias:affichage_documents_en_liste_compacte|attribut_html:>'></span>"
31 var changer_affichage_documents = function (me, bouton, classe) {
32 $(me).parent().find('.icone').removeClass('on').end().end().addClass('on');
33 var liste = $(me).parents('h3').next('.liste_items.documents');
34 liste.removeClass('documents_cases').removeClass('documents_liste');
36 liste.addClass(classe);
39 Cookies.set('affichage-' + identifiant, bouton);
42 liste.trigger('affichage.documents.change', {
47 'identifiant': identifiant
52 titre.find('.affichages
> .grand').click(function () {
53 changer_affichage_documents(this, 'grand', null);
56 titre.find('.affichages
> .cases').click(function () {
57 changer_affichage_documents(this, 'cases', 'documents_cases');
60 titre.find('.affichages
> .liste').click(function () {
61 changer_affichage_documents(this, 'liste', 'documents_liste');
65 var defaut = Cookies.get('affichage-' + identifiant);
67 titre.find('.affichages
> .' + defaut).trigger('click');
69 liste.trigger('affichage.documents.charge', {
71 'identifiant': identifiant,
78 /* Gestion du tri des listes de documents et de leur enregistrement */
79 function ordonner_listes_documents() {
81 $(
".liste_items.documents.ordonner_rang_lien[data-lien]").find('
> .sortable').each(function () {
82 // détruire / recréer le sortable à chaque appel ajax
83 if ($(this).has('.ui-sortable').length) {
84 $(this).sortable('destroy');
86 // pas de tri possible s'il n'y a qu'un seul élément.
87 if ($(this).find('
> .item').length <
2) {
88 $(this).find('.deplacer-document').hide();
89 return true; // continue
91 $(this).find('.deplacer-document').show();
94 /*axis:
"y",*/ /* minidoc a un affichage en case */
96 placeholder:
"ui-state-highlight deplacer-document-placeholder",
97 cancel: 'img.croix_centre_image',
98 start: function(event, ui) {
99 ui.item.addClass('document-en-mouvement');
101 stop: function(event, ui) {
102 ui.item.removeClass('document-en-mouvement');
104 update: function (event, ui) {
107 var liste = items.sortable('toArray');
110 $.each(liste, function(i, id) {
112 ordre.push( id.substring(
3) ); // doc123 =
> 123
116 // l'objet lié est indiqué dans l'attribut data-lien sur la liste
117 var lien = items.parents(
".liste_items.documents").data(
"lien").split(
"/");
118 var objet_lie = lien[
0];
119 var id_objet_lie = lien[
1];
120 var action = '[(#VAL{ordonner_liens_documents}|generer_url_action{
"",
1})]';
122 objet_source: 'document',
123 objet_lie: objet_lie,
124 id_objet_lie: id_objet_lie,
128 item.animateLoading();
135 }).done(function(data) {
137 var couleur_origine = item.css('background-color');
138 var couleur_erreur = $(
"<div class='remove'></div>").css('background-color');
139 var couleur_succes = $(
"<div class='append'></div>").css('background-color');
140 item.endLoading(true);
142 if (data.errors.length) {
143 items.sortable('cancel');
144 item.css({backgroundColor: couleur_erreur}).animate({backgroundColor: couleur_origine}, 'normal', function(){
145 item.css({backgroundColor: ''});
148 item.css({backgroundColor: couleur_succes}).animate({backgroundColor: couleur_origine}, 'normal', function(){
149 item.css({backgroundColor: ''});
151 items.parent().find('.tout_desordonner').show();
156 // bouton
"désordonner"
157 if ($(this).parent().find('.deplacer-document[data-rang!=
0]').length) {
158 $(this).parent().find('.tout_desordonner').show();
160 $(this).parent().find('.tout_desordonner').hide();
166 /* Recharger le conteneur des listes de documents si l'une d'elle est vide */
167 function check_reload_page(){
169 $('.portfolios').each(function(){
170 $(this).find('.liste-items.documents').each(function() {
171 if ($(this).length && !$(this).find('.item').length) {
172 $(this).parents('.portfolios').ajaxReload();
174 return false; // break each
179 jQuery('#navigation .box.info').ajaxReload();
183 /* Initialisation et relance en cas de chargement ajax */
186 if (!$.js_portfolio_documents_charge) {
187 $.js_portfolio_documents_charge = true;
188 onAjaxLoad(check_reload_page);
189 choix_affichages_documents();
190 onAjaxLoad(choix_affichages_documents);
191 ordonner_listes_documents();
192 onAjaxLoad(ordonner_listes_documents);