Browse Source

Evolution #89: odifier / Supprimer ses éléments

bastien 13 years ago
parent
commit
7ac181452e

+ 2 - 0
app/Resources/translations/userui.fr.yml View File

@@ -52,6 +52,8 @@ element_edit:
52 52
     name:     Lien
53 53
   name:
54 54
     name:     Nom
55
+  submit:
56
+    value:    Mettre à jour
55 57
     
56 58
 tags_filter:
57 59
   help:       Pour ne pas filtrer avec des tags, supprimez les tous de la liste.

+ 3 - 3
src/Muzich/CoreBundle/Controller/CoreController.php View File

@@ -221,9 +221,9 @@ class CoreController extends Controller
221 221
             'search_tags_id'   => $search_object->getTags(),
222 222
             'user'             => $this->getUser(),
223 223
             'add_form'         => $add_form->createView(),
224
-            'add_form_name'    => $add_form->getName(),
224
+            'add_form_name'    => 'add',
225 225
             'search_form'      => $search_form->createView(),
226
-            'search_form_name' => $search_form->getName(),
226
+            'search_form_name' => 'search',
227 227
             'elements'         => $search_object->getElements($this->getDoctrine(), $this->getUserId()),
228 228
             'more_count'       => $this->container->getParameter('search_default_count')*2
229 229
           ));
@@ -249,7 +249,7 @@ class CoreController extends Controller
249 249
             'following'     => $this->getUser()->isFollowingGroupByQuery($this->getDoctrine(), $group->getId()),
250 250
             'user'          => $this->getUser(),
251 251
             'add_form'      => (isset($add_form)) ? $add_form->createView() : null,
252
-            'add_form_name' => (isset($add_form)) ? $add_form->getName() : null,
252
+            'add_form_name' => (isset($add_form)) ? 'add' : null,
253 253
             'more_count'    => null,
254 254
             'more_route'    => 'show_group_more'
255 255
           ));

+ 70 - 8
src/Muzich/CoreBundle/Controller/ElementController.php View File

@@ -3,15 +3,23 @@
3 3
 namespace Muzich\CoreBundle\Controller;
4 4
 
5 5
 use Muzich\CoreBundle\lib\Controller;
6
+use Muzich\CoreBundle\ElementFactory\ElementManager;
6 7
 
7 8
 class ElementController extends Controller
8 9
 {
9 10
   
10 11
   /**
11
-   * 
12
+   *
13
+   * @param type $element_id
14
+   * @return Muzich\CoreBundle\Entity\Element 
12 15
    */
13
-  public function editAction($element_id)
16
+  protected function checkExistingAndOwned($element_id)
14 17
   {
18
+    if (!$this->getRequest()->isXmlHttpRequest())
19
+    {
20
+      $this->createNotFoundException();
21
+    }
22
+    
15 23
     if (!($element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
16 24
       ->findOneById($element_id)))
17 25
     {
@@ -23,8 +31,18 @@ class ElementController extends Controller
23 31
       $this->createNotFoundException();
24 32
     }
25 33
     
34
+    return $element;
35
+  }
36
+  
37
+  /**
38
+   * 
39
+   */
40
+  public function editAction($element_id)
41
+  {
42
+    $element = $this->checkExistingAndOwned($element_id);
43
+    
26 44
     $element_tags = $element->getTags();
27
-    $element->setTags(array());
45
+    $element->setTags($element->getTagsIdsJson());
28 46
     $form = $this->getAddForm($element);
29 47
     
30 48
     $search_tags = array();
@@ -35,23 +53,67 @@ class ElementController extends Controller
35 53
     
36 54
     $html = $this->render('MuzichCoreBundle:Element:element.edit.html.twig', array(
37 55
       'form'        => $form->createView(),
38
-      'form_name'   => $form->getName(),
56
+      'form_name'   => 'element_'.$element->getId(),
39 57
       'element_id'  => $element->getId(),
40 58
       'search_tags' => $search_tags
41 59
     ))->getContent();
42 60
     
43 61
     return $this->jsonResponse(array(
44
-      'status' => 'success',
45
-      'html'   => $html
62
+      'status'    => 'success',
63
+      'form_name' => 'element_'.$element->getId(),
64
+      'tags'      => $search_tags,
65
+      'html'      => $html
46 66
     ));
47 67
   }
48 68
   
49 69
   /**
50 70
    *
51 71
    */
52
-  public function updateAction()
72
+  public function updateAction($element_id)
53 73
   {
54
-    return array();
74
+    $element = $this->checkExistingAndOwned($element_id);
75
+    // Si il y a un groupe on le retire pour le bind
76
+    $group = $element->getGroup();
77
+    $element->setGroup(null);
78
+    $form = $this->getAddForm($element);
79
+    $form->bindRequest($this->getRequest());
80
+    
81
+    $errors = array();
82
+    $html = '';
83
+    if ($form->isValid())
84
+    {
85
+      $status = 'success';
86
+      $em = $this->getDoctrine()->getEntityManager();
87
+      $factory = new ElementManager($element, $em, $this->container);
88
+      $factory->proceedFill($this->getUser());
89
+      // Si il y avais un groupe on le remet
90
+      $element->setGroup($group);
91
+      $em->persist($element);
92
+      $em->flush();
93
+      
94
+      // Récupération du li
95
+      $html = $this->render('MuzichCoreBundle:SearchElement:element.html.twig', array(
96
+        'element'     => $element
97
+      ))->getContent();
98
+    }
99
+    else
100
+    {
101
+      $status = 'error';
102
+      // Récupération des erreurs
103
+      $validator = $this->container->get('validator');
104
+      $errorList = $validator->validate($form);
105
+      
106
+      foreach ($errorList as $error)
107
+      {
108
+        $errors[] = $error->getMessage();
109
+      }
110
+    }
111
+    
112
+    return $this->jsonResponse(array(
113
+      'status'  => $status,
114
+      'html'    => $html,
115
+      'errors'  => $errors
116
+    ));
55 117
   }
56 118
   
57 119
 }

+ 10 - 0
src/Muzich/CoreBundle/Entity/Element.php View File

@@ -221,6 +221,16 @@ class Element
221 221
     return $this->tags;
222 222
   }
223 223
   
224
+  public function getTagsIdsJson()
225
+  {
226
+    $ids = array();
227
+    foreach ($this->getTags() as $tag)
228
+    {
229
+      $ids[] = $tag->getId();
230
+    }
231
+    return json_encode($ids);
232
+  }
233
+  
224 234
   public function setTags($tags)
225 235
   {
226 236
     $this->tags = $tags;

+ 3 - 1
src/Muzich/CoreBundle/Form/Element/ElementAddForm.php View File

@@ -8,13 +8,15 @@ use Symfony\Component\Form\FormBuilder;
8 8
 class ElementAddForm extends AbstractType
9 9
 {
10 10
   public function buildForm(FormBuilder $builder, array $options)
11
-  {
11
+  {    
12 12
     $builder->add('name', 'text', array(
13 13
       'required' => true,
14
+      'error_bubbling' => true
14 15
     ));
15 16
     
16 17
     $builder->add('url', 'text', array(
17 18
       'required' => true,
19
+      'error_bubbling' => true
18 20
     ));
19 21
         
20 22
     $builder->add('tags', 'hidden');    

+ 1 - 1
src/Muzich/CoreBundle/Resources/views/Element/element.edit.html.twig View File

@@ -5,5 +5,5 @@
5 5
     'form_name'     : form_name
6 6
   } %}
7 7
 
8
-  <input type="submit" />
8
+  <input type="submit" value="{{ 'element_edit.submit.value'|trans({}, 'userui') }}" />
9 9
 </form>

+ 4 - 2
src/Muzich/CoreBundle/Resources/views/Element/form.add.html.twig View File

@@ -16,8 +16,10 @@
16 16
   {{ form_widget(form.name) }}
17 17
 </div>
18 18
 
19
-  {% include "MuzichCoreBundle:Tag:tagsPrompt.html.twig" with { 'form_name': form_name } %}
19
+  {% include "MuzichCoreBundle:Tag:tagsPrompt.html.twig" with { 
20
+    'form_name'     : form_name
21
+  } %}
20 22
 
21
-  {{ form_row(form.tags) }}
23
+  {{ form_widget(form.tags, { 'attr': {'class': 'tagBox_tags_ids'} }) }}
22 24
 
23 25
 {{ form_row(form._token) }}

+ 4 - 2
src/Muzich/CoreBundle/Resources/views/Element/form.edit.html.twig View File

@@ -14,8 +14,10 @@
14 14
   {{ form_widget(form.name) }}
15 15
 </div>
16 16
 
17
-  {% include "MuzichCoreBundle:Tag:tagsPrompt.html.twig" with { 'form_name': form_name } %}
17
+  {% include "MuzichCoreBundle:Tag:tagsPrompt.html.twig" with { 
18
+    'form_name'     : form_name
19
+  } %}
18 20
 
19
-  {{ form_row(form.tags) }}
21
+  {{ form_widget(form.tags, { 'attr': {'class': 'tagBox_tags_ids'} }) }}
20 22
 
21 23
 {{ form_row(form._token) }}

+ 1 - 79
src/Muzich/CoreBundle/Resources/views/SearchElement/default.html.twig View File

@@ -22,85 +22,7 @@
22 22
   {% endif %}
23 23
 {% endif %}" id="element_{{ element.id }}">
24 24
              
25
-        {% if element.getCountFavorite %}
26
-          <a class="favorite_link" href="{{ path('favorite_remove', { 'id': element.id, 'token': user.personalHash }) }}" >
27
-            <img src="{{ asset('bundles/muzichcore/img/favorite.png') }}" title="{{ 'element.favorite.remove'|trans({}, 'elements') }}" alt="{{ 'element.favorite.remove'|trans({}, 'elements') }}"/>
28
-          </a>
29
-        {% else %}
30
-          <a class="favorite_link" href="{{ path('favorite_add', { 'id': element.id, 'token': user.personalHash }) }}" >
31
-            <img src="{{ asset('bundles/muzichcore/img/favorite_bw.png') }}" title="{{ 'element.favorite.add'|trans({}, 'elements') }}" alt="{{ 'element.favorite.add'|trans({}, 'elements') }}" />
32
-          </a>
33
-        {% endif %}
34
-        
35
-        <span class="element_name">
36
-          {{ element.name }}
37
-        </span> 
38
-        
39
-        {% autoescape false %}
40
-          {% if element.group and no_group_name is not defined%}
41
-            {{ 'element.name.whoandgroup'|trans({
42
-              '%owner_url%'  : path('show_user', {'slug': element.owner.slug}),
43
-              '%owner_name%' : element.owner.name,
44
-              '%group_url%'  : path('show_group', {'slug': element.group.slug}),
45
-              '%group_name%' : element.group.name
46
-            }, 'elements') }}
47
-          {% else %}
48
-            {{ 'element.name.who'|trans({
49
-              '%owner_url%'  : path('show_user', {'slug': element.owner.slug}),
50
-              '%owner_name%' : element.owner.name
51
-            }, 'elements') }}
52
-          {% endif %}
53
-        {% endautoescape %}
54
-        
55
-        
56
-        <a title="{{ 'element.link'|trans({}, 'elements') }}" class="element_link" href="{{ element.url }}" target="_blank">
57
-          <img src="{{ asset('bundles/muzichcore/img/1324917097_link.png') }}" alt="link" />
58
-        </a>
59
-          
60
-        {% if app.user.id == element.owner.id %}
61
-          <a title="{{ 'element.edit.link'|trans({}, 'elements') }}" class="element_edit_link" 
62
-             href="{{ path('element_edit', {'element_id' : element.id})  }}" style="display: none;"
63
-          >
64
-            <img src="{{ asset('bundles/muzichcore/img/1327151338_desktop.png') }}" alt="edit" />
65
-          </a>
66
-        {% endif %}
67
-            
68
-        {% if element.embed %}
69
-          {% autoescape false %}
70
-            <div id="embed_{{ element.id }}" class="element_embed" style="display: none;">
71
-              {{ element.embed }}
72
-            </div>
73
-          {% endautoescape %}
74
-        {% endif %}
75
-        
76
-        <div>
77
-
78
-          {% if element.embed %}
79
-            <a href="#" class="element_open element_embed_close_link" style="display: none;">
80
-              {{ 'element.show.close_embed'|trans({}, 'elements') }}
81
-            </a>
82
-            <a href="#" class="element_open element_embed_open_link">
83
-              {{ 'element.show.open_embed'|trans({}, 'elements') }}
84
-            </a>
85
-          {% else %}
86
-            <a href="{{ element.url }}" class="element_open" target="_blank">
87
-              {{ 'element.show.open_link'|trans({}, 'elements') }}
88
-            </a>
89
-          {% endif %}
90
-        
91
-          {% if element.tags|length %}
92
-          <ul class="element_tags">
93
-            {% for tag in element.tags %} 
94
-              <li class="element_tag">
95
-                {{ tag.name }}
96
-              </li>
97
-            {% endfor %} 
98
-          </ul>
99
-          {% else %}
100
-          <br />
101
-          {% endif %}
102
-          
103
-        </div>
25
+        {% include "MuzichCoreBundle:SearchElement:element.html.twig" %}
104 26
 
105 27
       </li>
106 28
     {% endfor %} 

+ 83 - 0
src/Muzich/CoreBundle/Resources/views/SearchElement/element.html.twig View File

@@ -0,0 +1,83 @@
1
+{% if element.getCountFavorite %}
2
+  <a class="favorite_link" href="{{ path('favorite_remove', { 'id': element.id, 'token': app.user.personalHash }) }}" >
3
+    <img src="{{ asset('bundles/muzichcore/img/favorite.png') }}" title="{{ 'element.favorite.remove'|trans({}, 'elements') }}" alt="{{ 'element.favorite.remove'|trans({}, 'elements') }}"/>
4
+  </a>
5
+{% else %}
6
+  <a class="favorite_link" href="{{ path('favorite_add', { 'id': element.id, 'token': app.user.personalHash }) }}" >
7
+    <img src="{{ asset('bundles/muzichcore/img/favorite_bw.png') }}" title="{{ 'element.favorite.add'|trans({}, 'elements') }}" alt="{{ 'element.favorite.add'|trans({}, 'elements') }}" />
8
+  </a>
9
+{% endif %}
10
+
11
+<span class="element_name">
12
+  {{ element.name }}
13
+</span> 
14
+
15
+{% autoescape false %}
16
+  {% if element.group and no_group_name is not defined%}
17
+    {{ 'element.name.whoandgroup'|trans({
18
+      '%owner_url%'  : path('show_user', {'slug': element.owner.slug}),
19
+      '%owner_name%' : element.owner.name,
20
+      '%group_url%'  : path('show_group', {'slug': element.group.slug}),
21
+      '%group_name%' : element.group.name
22
+    }, 'elements') }}
23
+  {% else %}
24
+    {{ 'element.name.who'|trans({
25
+      '%owner_url%'  : path('show_user', {'slug': element.owner.slug}),
26
+      '%owner_name%' : element.owner.name
27
+    }, 'elements') }}
28
+  {% endif %}
29
+{% endautoescape %}
30
+
31
+
32
+<a title="{{ 'element.link'|trans({}, 'elements') }}" class="element_link" href="{{ element.url }}" target="_blank">
33
+  <img src="{{ asset('bundles/muzichcore/img/1324917097_link.png') }}" alt="link" />
34
+</a>
35
+
36
+{% if app.user.id == element.owner.id %}
37
+  <a title="{{ 'element.edit.link'|trans({}, 'elements') }}" class="element_edit_link" 
38
+     href="{{ path('element_edit', {'element_id' : element.id})  }}" style="display: none;"
39
+  >
40
+    <img src="{{ asset('bundles/muzichcore/img/1327151338_desktop.png') }}" alt="edit" />
41
+  </a>
42
+{% endif %}
43
+
44
+<div class="loader">
45
+  <img class="element_loader" style="display: none;" src="{{ asset('/bundles/muzichcore/img/ajax-loader.gif') }}" alt="loading"/>
46
+</div>
47
+  
48
+{% if element.embed %}
49
+  {% autoescape false %}
50
+    <div id="embed_{{ element.id }}" class="element_embed" style="display: none;">
51
+      {{ element.embed }}
52
+    </div>
53
+  {% endautoescape %}
54
+{% endif %}
55
+
56
+<div>
57
+
58
+  {% if element.embed %}
59
+    <a href="#" class="element_open element_embed_close_link" style="display: none;">
60
+      {{ 'element.show.close_embed'|trans({}, 'elements') }}
61
+    </a>
62
+    <a href="#" class="element_open element_embed_open_link">
63
+      {{ 'element.show.open_embed'|trans({}, 'elements') }}
64
+    </a>
65
+  {% else %}
66
+    <a href="{{ element.url }}" class="element_open" target="_blank">
67
+      {{ 'element.show.open_link'|trans({}, 'elements') }}
68
+    </a>
69
+  {% endif %}
70
+
71
+  {% if element.tags|length %}
72
+  <ul class="element_tags">
73
+    {% for tag in element.tags %} 
74
+      <li class="element_tag">
75
+        {{ tag.name }}
76
+      </li>
77
+    {% endfor %} 
78
+  </ul>
79
+  {% else %}
80
+  <br />
81
+  {% endif %}
82
+
83
+</div>

+ 4 - 2
src/Muzich/CoreBundle/Resources/views/SearchElement/form.html.twig View File

@@ -7,7 +7,9 @@
7 7
     {{ form_widget(search_form.network) }}
8 8
   </div>
9 9
   
10
-  {% include "MuzichCoreBundle:Tag:tagsPrompt.html.twig" with { 'form_name': form_name } %}
10
+  {% include "MuzichCoreBundle:Tag:tagsPrompt.html.twig" with { 
11
+    'form_name'     : form_name
12
+  } %}
11 13
   
12
-  {{ form_row(search_form.tags) }}
14
+  {{ form_widget(search_form.tags, { 'attr': {'class': 'tagBox_tags_ids'} }) }}
13 15
   {{ form_row(search_form._token) }}

+ 1 - 1
src/Muzich/CoreBundle/Resources/views/Tag/tagFavoritesForm.html.twig View File

@@ -7,7 +7,7 @@
7 7
     'search_tags' : favorite_tags_id
8 8
   } %}
9 9
   
10
-  {{ form_row(form.tags) }}
10
+  {{ form_widget(form.tags, { 'attr': {'class': 'tagBox_tags_ids'} }) }}
11 11
 
12 12
   {{ form_row(form._token) }}
13 13
 

+ 4 - 235
src/Muzich/CoreBundle/Resources/views/Tag/tagsPrompt.html.twig View File

@@ -11,8 +11,9 @@
11 11
     {% endif %}
12 12
   {% endif %}
13 13
   
14
-   <input class="tags_prompt_list" id="tags_prompt_list_{{ form_name }}" name="tags" value=""> 
14
+   <input class="tags_prompt_list" name="tags" value=""> 
15 15
    <input id="tags_selected_tag_{{ form_name }}" type="hidden" value="" />
16
+   <input class="tag_text_help" type="hidden" value="{{ 'tags.inputtext.help'|trans({}, 'userui') }}"/>
16 17
    <div id="search_tag_{{ form_name }}" class="search_tag_list" style="display: none;">
17 18
      <span class="info"></span>
18 19
      <div class="tag_loader_div">
@@ -32,246 +33,14 @@
32 33
     {% endfor %}
33 34
   {% endif %}
34 35
   
35
-  tag_text_help = "{{ 'tags.inputtext.help'|trans({}, 'userui') }}";
36 36
   var options = new Array();
37 37
   options.form_name  = "{{ form_name }}";
38 38
   options.tag_init   = taginit;
39 39
   
40
-  ajax_query_timestamp = null;
41
-  
42
-  $("#tags_prompt_list_{{ form_name }}").tagBox(options);
40
+  // tags_prompt_list_
41
+  $("div#tags_prompt_{{ form_name }} input.tags_prompt_list").tagBox(options);
43 42
   
44 43
   // On détruit la variable taginit
45 44
   delete taginit;
46
-  
47
-  // I've hacked the jQuery UI autocomplete render function
48
-  // to highlight part of the matched string
49
-  $.ui.autocomplete.prototype._renderItem = function( ul, item) {
50
-      var sstr = $.trim(this.term);
51
-      var re = new RegExp(sstr, "i") ;
52
-      var t = item.label.replace(re,"<strong>" + sstr + "</strong>");
53
-      return $( "<li></li>" )
54
-          .data( "item.autocomplete", item )
55
-          .append( "<a>" + t + "</a>" )
56
-          .appendTo( ul );
57
-  };
58
-  
59
-  ////////////////////////
60
-    
61
-  // Les deux clicks ci-dessous permettent de faire disparaitre
62
-  // la div de tags lorsque l'on clique ailleurs
63
-  $('html').click(function() {
64
-    if ($("#search_tag_{{ form_name }}").is(':visible'))
65
-    {
66
-      $("#search_tag_{{ form_name }}").hide();
67
-    }
68
-  });
69
-  
70
-  $("#search_tag_{{ form_name }}").click(function(event){
71
-    event.stopPropagation();
72
-  });
73
-  
74
-  function autocomplete_tag(input, form_name)
75
-  {
76
-    // Il doit y avoir au moin un caractère
77
-    if (input.val().length > 0) 
78
-    {
79
-
80
-      // on met en variable l'input
81
-      inputTag = input;
82
-
83
-      // On récupére la div de tags
84
-      divtags = $("#search_tag_"+form_name);
85
-
86
-      // Si la fenêtre de tags est caché
87
-      if (!divtags.is(':visible'))
88
-      {
89
-        // On la replace
90
-        position = input.position();
91
-        divtags.css('left', Math.round(position.left) + 5);
92
-        divtags.css('top', Math.round(position.top) + 28);
93
-        // Et on l'affiche
94
-        divtags.show();
95
-      }
96
-      // On affiche le loader
97
-      $('#tag_loader_'+form_name).show();
98
-      // On cache la liste de tags
99
-      search_tag_list = divtags.find('ul.search_tag_list');
100
-      // On supprime les anciens li
101
-      search_tag_list.find('li').remove();
102
-      search_tag_list.hide();
103
-      // Et on affiche une info
104
-      span_info = divtags.find('span.info');
105
-      span_info.show();
106
-      span_info.text("Recherche des tags correspondants à \""+input.val()+"\" ...");
107
-
108
-      // C'est en fonction du nb de resultats qu'il sera affiché
109
-      divtags.find('a.more').hide();
110
-
111
-      // On récupère le timestamp pour reconnaitre la dernière requête effectué
112
-      ajax_query_timestamp = new Date().getTime();
113
-
114
-      // Récupération des tags correspondants
115
-      $.getJSON('/app_dev.php/fr/search/tag/'+input.val()+'/'+ajax_query_timestamp, function(data) {
116
-        // Ce contrôle permet de ne pas continuer si une requete
117
-        // ajax a été faite depuis.
118
-        if (data.timestamp == ajax_query_timestamp)
119
-        {
120
-          status = data.status;
121
-          tags   = data.data;
122
-
123
-          // Si on spécifie une erreur
124
-          if (status == 'error')
125
-          {
126
-            // On l'affiche a l'utilisateur
127
-            span_info.text(data.error);
128
-          }
129
-          // Si c'est un succés
130
-          else if (status == 'success')
131
-          {
132
-            if (tags.length > 0)
133
-            {
134
-              more = false;
135
-              // Pour chaque tags retournés
136
-              for (i in tags)
137
-              {
138
-                var tag_name = tags[i]['name'];
139
-                var tag_id = tags[i]['id'];
140
-                // On construit un li
141
-                var sstr = $.trim(input.val());
142
-                var re = new RegExp(sstr, "i") ;
143
-                var t_string = tag_name.replace(re,"<strong>" + sstr + "</strong>");
144
-                
145
-                li_tag = 
146
-                  $('<li>').append(
147
-                    $('<a>').attr('href','#'+tag_id+'#'+tag_name)
148
-                    // qui réagit quand on clique dessus
149
-                    .click(function(e){
150
-                      // On récupère le nom du tag
151
-                      name = $(this).attr('href').substr(1,$(this).attr('href').length);
152
-                      name = name.substr(strpos(name, '#')+1, name.length);
153
-                                            
154
-                      id = $(this).attr('href').substr(1,$(this).attr('href').length);
155
-                      id = str_replace(name, '', id);
156
-                      id = str_replace('#', '', id);
157
-                                            
158
-                      $('input#tags_selected_tag_'+form_name).val(id);
159
-                      inputTag.val(name);
160
-                      // Et on execute l'évènement selectTag de l'input
161
-                      inputTag.trigger("selectTag");
162
-                      // On cache la liste puisque le choix vient d'être fait
163
-                      divtags.hide();
164
-                      inputTag.val(tag_text_help); 
165
-                      return false;
166
-                    })
167
-                    .append(t_string)
168
-                );
169
-
170
-                // Si on depasse les 30 tags
171
-                if (i > 30)
172
-                {
173
-                  more = true;
174
-                  // On le cache
175
-                  li_tag.hide();
176
-                }
177
-
178
-                // On ajout ce li a la liste
179
-                search_tag_list.append(li_tag);
180
-              } 
181
-
182
-              if (more)
183
-              {
184
-                divtags.find('a.more').show();
185
-              }
186
-
187
-              // On cache l'info
188
-              span_info.hide();
189
-              // Et on affiche la liste
190
-              search_tag_list.show();
191
-            }
192
-            else
193
-            {
194
-              span_info.text("Aucun tag de trouvé pour \""+inputTag.val()+"\"");
195
-            }
196
-            
197
-          }
198
-
199
-          // On cache le loader
200
-          $('#tag_loader_'+form_name).hide();
201
-        }
202
-      });
203
-      
204
-    }
205
-  }
206
-  
207
-  
208
-
209
-  last_keypress = 0;
210
-  
211
-  function check_timelaps_and_search(input, form_name, time_id, timed, info)
212
-  {
213
-    if (!timed)
214
-    {
215
-      // C'est une nouvelle touche (pas redirigé) on lui donne un id
216
-      // et on met a jour l'id de la dernière pressé
217
-      last_keypress = new Date().getTime(); 
218
-      var this_time_id = last_keypress;
219
-    }
220
-    else
221
-    {
222
-      // Si elle a été redirigé, on met son id dans cette variable
223
-      var this_time_id = time_id;
224
-    }
225
-    
226
-    // C'est une touche redirigé dans le temps qui a été suivit d'une autre touche
227
-    if (time_id != last_keypress && timed)
228
-    {
229
-      // elle disparait
230
-    }
231
-    else
232
-    {
233
-      //
234
-      if ((new Date().getTime() - last_keypress) < 600 || timed == false)
235
-      {
236
-        // Si elle vient d'être tapé (timed == false) elle doit attendre (au cas ou une autre touche soit tapé)
237
-        // Si c'est une redirigé qui n'a pas été remplacé par une nouvelle lettre
238
-        // elle doit attendre au cas ou soit pressé.
239
-        setTimeout(function(){check_timelaps_and_search(input, form_name, this_time_id, true, info)}, 700);
240
-      }
241
-      else
242
-      {
243
-        // il n'y a plus a attendre, on envoie la demande de tag.
244
-        autocomplete_tag(input, '{{ form_name }}');
245
-      }
246
-    }
247
-  }
248
-
249
-  // Autocompletion de tags
250
-  $("#tags_prompt_{{ form_name }} ul.tagbox li.input input").keypress(function(e){
251
-    
252
-    var code = (e.keyCode ? e.keyCode : e.which);
253
-
254
-    if ((e.which !== 0 && e.charCode !== 0) || (code == 8 || code == 46))
255
-    {
256
-      check_timelaps_and_search($(this), '{{ form_name }}', new Date().getTime(), false, $(this).val());
257
-    }
258
-     
259
-  });
260
-  
261
-  // Un click sur ce lien affiche tout les tags cachés de la liste
262
-  $('div.search_tag_list a.more').click(function(){
263
-    jQuery.each( $(this).parent('div').find('ul.search_tag_list li') , function(){
264
-      $(this).show();
265
-    });
266
-    return false;
267
-  });
268
-  
269
-  /////////////////////////////////
270
-  
271
-
272
-  
273
-  $('#tags_prompt_{{ form_name }} input[type="text"]').val(tag_text_help);
274
-  $('#tags_prompt_{{ form_name }} input[type="text"]').formDefaults();
275
-  
276 45
     
277 46
 </script>

+ 1 - 1
src/Muzich/GroupBundle/Controller/DefaultController.php View File

@@ -137,7 +137,7 @@ class DefaultController extends Controller
137 137
     return array(
138 138
       'group'     => $group,
139 139
       'form'      => $form->createView()  ,
140
-      'form_name' => $form->getName()      
140
+      'form_name' => 'group'      
141 141
     );
142 142
   }
143 143
   

+ 4 - 2
src/Muzich/GroupBundle/Resources/views/Form/form.html.twig View File

@@ -22,8 +22,10 @@
22 22
   {{ form_widget(form.open) }}
23 23
 </div>
24 24
 
25
-{% include "MuzichCoreBundle:Tag:tagsPrompt.html.twig" with { 'form_name': form_name } %}
25
+{% include "MuzichCoreBundle:Tag:tagsPrompt.html.twig" with { 
26
+  'form_name'     : form_name
27
+} %}
26 28
 
27
-{{ form_row(form.tags) }}
29
+{{ fform_widget(form.tags, { 'attr': {'class': 'tagBox_tags_ids'} }) }}
28 30
 
29 31
 {{ form_rest(form) }}

+ 2 - 2
src/Muzich/HomeBundle/Controller/HomeController.php View File

@@ -32,9 +32,9 @@ class HomeController extends Controller
32 32
       'search_tags_id'   => $search_object->getTags(),
33 33
       'user'             => $this->getUser(),
34 34
       'add_form'         => $add_form->createView(),
35
-      'add_form_name'    => $add_form->getName(),
35
+      'add_form_name'    => 'add',
36 36
       'search_form'      => $search_form->createView(),
37
-      'search_form_name' => $search_form->getName(),
37
+      'search_form_name' => 'search',
38 38
       'elements'         => $search_object->getElements($this->getDoctrine(), $this->getUserId()),
39 39
       'more_count'       => ($count)?$count+$this->container->getParameter('search_default_count'):$this->container->getParameter('search_default_count')*2
40 40
     );

+ 1 - 1
src/Muzich/HomeBundle/Controller/ShowController.php View File

@@ -63,7 +63,7 @@ class ShowController extends Controller
63 63
       'following'     => $this->getUser()->isFollowingGroupByQuery($this->getDoctrine(), $group->getId()),
64 64
       'user'          => $this->getUser(),
65 65
       'add_form'      => (isset($add_form)) ? $add_form->createView() : null,
66
-      'add_form_name' => (isset($add_form)) ? $add_form->getName() : null,
66
+      'add_form_name' => (isset($add_form)) ? 'add' : null,
67 67
       'more_count'    => ($count)?$count+$this->container->getParameter('search_default_count'):$this->container->getParameter('search_default_count')*2,
68 68
       'more_route'    => 'show_group_more'
69 69
     );

+ 2 - 2
web/bundles/muzichcore/css/main.css View File

@@ -503,12 +503,12 @@ ul.tagbox input[type="text"]:FOCUS
503 503
   );
504 504
 }
505 505
 
506
-div.tag_loader_div
506
+div.tag_loader_div, div.loader
507 507
 {
508 508
   text-align: center;
509 509
 }
510 510
 
511
-.tag_loader
511
+.tag_loader, element_loader
512 512
 {
513 513
   margin-left: auto;
514 514
   marin-right: auto;

+ 277 - 14
web/bundles/muzichcore/js/muzich.js View File

@@ -227,16 +227,6 @@ $(document).ready(function(){
227 227
       }
228 228
     }
229 229
   );
230
-
231
- // Ouverture du formulaire de modification
232
- $('a.element_edit_link').live('click', function(){
233
-   link = $(this);
234
-   $.getJSON($(this).attr('href'), function(response) {
235
-     li = link.parent('li.element');
236
-     li.html(response.html);
237
-   });
238
-   return false;
239
- });
240 230
    
241 231
    // Plus d'éléments
242 232
    last_id = null;
@@ -271,13 +261,13 @@ $(document).ready(function(){
271 261
   tag_box_input_value = $('ul.tagbox input[type="text"]').val();
272 262
    
273 263
   // Filtre et affichage éléments ajax
274
-  $('form[name="element_search_form"] input[type="submit"]').click(function(){
264
+  $('form[name="search"] input[type="submit"]').click(function(){
275 265
     $('ul.elements').html('');
276 266
     $('div.no_elements').hide();
277 267
     $('img.elements_more_loader').show();
278 268
   });
279 269
   
280
-  $('form[name="element_search_form"]').ajaxForm(function(response) { 
270
+  $('form[name="search"]').ajaxForm(function(response) { 
281 271
     
282 272
     $('ul.elements').html(response.html);
283 273
     
@@ -300,7 +290,280 @@ $(document).ready(function(){
300 290
      $('ul.tagbox input[type="text"]').val(tag_box_input_value);
301 291
     
302 292
   }); 
293
+  
294
+  
295
+
296
+ // Ouverture du formulaire de modification
297
+  $('a.element_edit_link').live('click', function(){
298
+    
299
+    link = $(this);
300
+    li = link.parent('li.element');
301
+    div_loader = li.find('div.loader');
302
+    li.html(div_loader);
303
+    li.find('img.element_loader').show();
304
+    
305
+    $.getJSON($(this).attr('href'), function(response) {
306
+      
307
+      // On prépare le tagBox
308
+      li.html(response.html);
309
+     
310
+      var options = new Array();
311
+      options.form_name  = response.form_name;
312
+      options.tag_init   = response.tags;
313
+
314
+      ajax_query_timestamp = null;
315
+      
316
+      $("#tags_prompt_list_"+response.form_name).tagBox(options);
317
+      
318
+      // On rend ce formulaire ajaxFormable
319
+      $('form[name="'+response.form_name+'"] input[type="submit"]').live('click', function(){
320
+        li.prepend(div_loader);
321
+        li.find('img.element_loader').show();
322
+      });
323
+      $('form[name="'+response.form_name+'"]').ajaxForm(function(response){
324
+        
325
+        if (response.status == 'success')
326
+        {
327
+          li.html(response.html);
328
+        }
329
+        else if (response.status == 'error')
330
+        {
331
+          li.find('img.element_loader').hide();
332
+          li.find('ul.error_list').remove();
333
+          ul_errors = $('<ul>').addClass('error_list');
334
+          
335
+          for (i in response.errors)
336
+          {
337
+            ul_errors.append($('<li>').append(response.errors[i]));
338
+          }
339
+          
340
+          li.prepend(ul_errors);
341
+        }
342
+      });
343
+      
344
+    });
345
+    return false;
346
+  });
347
+ 
348
+  ////////////////// TAG PROMPT ///////////////
349
+ 
350
+  ajax_query_timestamp = null;
351
+  tag_text_help = $('input.tag_text_help').val();
352
+ 
353
+  // Les deux clicks ci-dessous permettent de faire disparaitre
354
+  // la div de tags lorsque l'on clique ailleurs
355
+  $('html').click(function() {
356
+    if ($("div.search_tag_list").is(':visible'))
357
+    {
358
+      $("div.search_tag_list").hide();
359
+    }
360
+  });
361
+
362
+  $("div.search_tag_list").live('click', function(event){
363
+    event.stopPropagation();
364
+  });
365
+
366
+  function autocomplete_tag(input, form_name)
367
+  {
368
+    // Il doit y avoir au moin un caractère
369
+    if (input.val().length > 0) 
370
+    {
371
+
372
+      // on met en variable l'input
373
+      inputTag = input;
374
+      
375
+      // On récupére la div de tags
376
+      divtags = $("#search_tag_"+form_name);
377
+
378
+      // Si la fenêtre de tags est caché
379
+      if (!divtags.is(':visible'))
380
+      {
381
+        // On la replace
382
+        position = input.position();
383
+        divtags.css('left', Math.round(position.left) + 5);
384
+        divtags.css('top', Math.round(position.top) + 28);
385
+        // Et on l'affiche
386
+        divtags.show();
387
+      }
388
+      // On affiche le loader
389
+      $('#tag_loader_'+form_name).show();
390
+      // On cache la liste de tags
391
+      search_tag_list = divtags.find('ul.search_tag_list');
392
+      // On supprime les anciens li
393
+      search_tag_list.find('li').remove();
394
+      search_tag_list.hide();
395
+      // Et on affiche une info
396
+      span_info = divtags.find('span.info');
397
+      span_info.show();
398
+      span_info.text("Recherche des tags correspondants à \""+input.val()+"\" ...");
399
+
400
+      // C'est en fonction du nb de resultats qu'il sera affiché
401
+      divtags.find('a.more').hide();
402
+
403
+      // On récupère le timestamp pour reconnaitre la dernière requête effectué
404
+      ajax_query_timestamp = new Date().getTime();
405
+
406
+      // Récupération des tags correspondants
407
+      $.getJSON('/app_dev.php/fr/search/tag/'+input.val()+'/'+ajax_query_timestamp, function(data) {
408
+        // Ce contrôle permet de ne pas continuer si une requete
409
+        // ajax a été faite depuis.
410
+        if (data.timestamp == ajax_query_timestamp)
411
+        {
412
+          status = data.status;
413
+          tags   = data.data;
414
+
415
+          // Si on spécifie une erreur
416
+          if (status == 'error')
417
+          {
418
+            // On l'affiche a l'utilisateur
419
+            span_info.text(data.error);
420
+          }
421
+          // Si c'est un succés
422
+          else if (status == 'success')
423
+          {
424
+            if (tags.length > 0)
425
+            {
426
+              more = false;
427
+              // Pour chaque tags retournés
428
+              for (i in tags)
429
+              {
430
+                var tag_name = tags[i]['name'];
431
+                var tag_id = tags[i]['id'];
432
+                // On construit un li
433
+                var sstr = $.trim(input.val());
434
+                var re = new RegExp(sstr, "i") ;
435
+                var t_string = tag_name.replace(re,"<strong>" + sstr + "</strong>");
436
+                
437
+                li_tag = 
438
+                  $('<li>').append(
439
+                    $('<a>').attr('href','#'+tag_id+'#'+tag_name)
440
+                    // qui réagit quand on clique dessus
441
+                    .click(function(e){
442
+                      // On récupère le nom du tag
443
+                      name = $(this).attr('href').substr(1,$(this).attr('href').length);
444
+                      name = name.substr(strpos(name, '#')+1, name.length);
445
+                                            
446
+                      id = $(this).attr('href').substr(1,$(this).attr('href').length);
447
+                      id = str_replace(name, '', id);
448
+                      id = str_replace('#', '', id);
449
+                                            
450
+                      $('input#tags_selected_tag_'+form_name).val(id);
451
+                      inputTag.val(name);
452
+                      // Et on execute l'évènement selectTag de l'input
453
+                      inputTag.trigger("selectTag");
454
+                      // On cache la liste puisque le choix vient d'être fait
455
+                      divtags.hide();
456
+                      inputTag.val(tag_text_help); 
457
+                      return false;
458
+                    })
459
+                    .append(t_string)
460
+                );
461
+
462
+                // Si on depasse les 30 tags
463
+                if (i > 30)
464
+                {
465
+                  more = true;
466
+                  // On le cache
467
+                  li_tag.hide();
468
+                }
469
+
470
+                // On ajout ce li a la liste
471
+                search_tag_list.append(li_tag);
472
+              } 
473
+
474
+              if (more)
475
+              {
476
+                divtags.find('a.more').show();
477
+              }
478
+
479
+              // On cache l'info
480
+              span_info.hide();
481
+              // Et on affiche la liste
482
+              search_tag_list.show();
483
+            }
484
+            else
485
+            {
486
+              span_info.text("Aucun tag de trouvé pour \""+inputTag.val()+"\"");
487
+            }
488
+            
489
+          }
490
+
491
+          // On cache le loader
492
+          $('#tag_loader_'+form_name).hide();
493
+        }
494
+      });
495
+      
496
+    }
497
+  }
498
+ 
499
+ 
500
+  last_keypress = 0;
501
+  
502
+  function check_timelaps_and_search(input, form_name, time_id, timed, info)
503
+  {
504
+    if (!timed)
505
+    {
506
+      // C'est une nouvelle touche (pas redirigé) on lui donne un id
507
+      // et on met a jour l'id de la dernière pressé
508
+      last_keypress = new Date().getTime(); 
509
+      var this_time_id = last_keypress;
510
+    }
511
+    else
512
+    {
513
+      // Si elle a été redirigé, on met son id dans cette variable
514
+      var this_time_id = time_id;
515
+    }
516
+    
517
+    // C'est une touche redirigé dans le temps qui a été suivit d'une autre touche
518
+    if (time_id != last_keypress && timed)
519
+    {
520
+      // elle disparait
521
+    }
522
+    else
523
+    {
524
+      //
525
+      if ((new Date().getTime() - last_keypress) < 600 || timed == false)
526
+      {
527
+        // Si elle vient d'être tapé (timed == false) elle doit attendre (au cas ou une autre touche soit tapé)
528
+        // Si c'est une redirigé qui n'a pas été remplacé par une nouvelle lettre
529
+        // elle doit attendre au cas ou soit pressé.
530
+        setTimeout(function(){check_timelaps_and_search(input, form_name, this_time_id, true, info)}, 700);
531
+      }
532
+      else
533
+      {
534
+        // il n'y a plus a attendre, on envoie la demande de tag.
535
+        autocomplete_tag(input, form_name);
536
+      }
537
+    }
538
+  }
539
+  
540
+  // Autocompletion de tags
541
+  $("div.tags_prompt ul.tagbox li.input input").live('keypress', function(e){
542
+    
543
+    var form_name = $(this).parent('li').parent('ul.tagbox')
544
+      .parent('div.tags_prompt').parent('form').attr('name')
545
+    ;
546
+    var code = (e.keyCode ? e.keyCode : e.which);
547
+
548
+    if ((e.which !== 0 && e.charCode !== 0) || (code == 8 || code == 46))
549
+    {
550
+      check_timelaps_and_search($(this), form_name, new Date().getTime(), false, $(this).val());
551
+    }
552
+     
553
+  });
554
+  
555
+  // Un click sur ce lien affiche tout les tags cachés de la liste
556
+  $('div.search_tag_list a.more').live('click', function(){
557
+    jQuery.each( $(this).parent('div').find('ul.search_tag_list li') , function(){
558
+      $(this).show();
559
+    });
560
+    return false;
561
+  });
562
+  
563
+  $('ul.tagbox li.input input[type="text"]').val(tag_text_help);
564
+  $('ul.tagbox li.input input[type="text"]').formDefaults();
565
+ 
566
+  ////////////////// FIN TAG PROMPT ///////////////
567
+
303 568
    
304 569
  });
305
- 
306
- 

+ 5 - 26
web/js/tags/jquery.tagBox.js View File

@@ -64,21 +64,6 @@
64 64
           input = $(this);
65 65
           inputId = $('input#tags_selected_tag_'+options.form_name);
66 66
           
67
-          // Ici il faut faire un ajax q pour connaitre l'id, on a que le string
68
-          // ajax loader gif
69
-          //$('#tag_loader_'+options.form_name).css('display', 'block');
70
-          // On bloque le submit le temps de la validation du tag
71
-          //$('form[name="'+options.form_name+'"] input[type="submit"]').attr('disabled', 'disabled');
72
-//          $.getJSON('/app_dev.php/fr/search/tagid/'+$(this).val(), function(data) {
73
-//            if (isInteger(data))
74
-//            {
75
-//              self.addTag(input.val(), data, options.form_name, false);
76
-//              input.val("");
77
-//              $('#tag_loader_'+options.form_name).css('display', 'none');
78
-//              $('form[name="'+options.form_name+'"] input[type="submit"]').removeAttr('disabled');
79
-//            }
80
-//          });
81
-
82 67
           self.addTag(input.val(), inputId.val(), options.form_name, false);
83 68
         });
84 69
         
@@ -97,13 +82,7 @@
97 82
         self.tagbox.append(self.inputHolder);
98 83
         self.inputHolder.append(self.tagInput);
99 84
         self.tagInput.autoGrowInput();
100
-        
101
-        // On désactive l'ajout de tags basé sur le contenu du input
102
-        // ona notre propre système (taginit)
103
-        //for(tag in tags) {
104
-        //    self.addTag(tags[tag], findKeyWithValue(values, tags[tag]), options.form_name, true);
105
-        //}
106
-        
85
+                
107 86
         if (options.tag_init.length)
108 87
         {
109 88
           for(i in options.tag_init) {
@@ -140,7 +119,7 @@
140 119
             // si on force, on ne touche pas l'inpu (il contient déjà ces valeurs)
141 120
             if (!force)
142 121
             {
143
-              var input_tags = $('input#'+form_name+'_tags');
122
+              var input_tags = $('form[name="'+form_name+'"] input.tagBox_tags_ids');
144 123
               if (input_tags.length)
145 124
               {
146 125
                 // array des ids de tags
@@ -148,7 +127,7 @@
148 127
                 if (!inArray(input_values, id))
149 128
                 {
150 129
                   input_values[input_values.length] = parseInt(id);
151
-                  $('input#'+form_name+'_tags').val(array2json(input_values));
130
+                  input_tags.val(array2json(input_values));
152 131
                 }
153 132
               }
154 133
             }
@@ -166,7 +145,7 @@
166 145
             this.tags.splice(index, 1);
167 146
             this.updateInput();
168 147
             
169
-            input_tags = $('input#'+form_name+'_tags');
148
+            input_tags = $('form[name="'+form_name+'"] input.tagBox_tags_ids');
170 149
             if (input_tags.length)
171 150
             {
172 151
               // array des ids de tags
@@ -178,7 +157,7 @@
178 157
                   delete input_values[i];
179 158
                 }
180 159
               }
181
-              $('input#'+form_name+'_tags').val(array2json(input_values));
160
+              input_tags.val(array2json(input_values));
182 161
             }
183 162
             
184 163
             // Suppression tu tableau js