Browse Source

Remodelage js du formulaire d'ajout, de façon a ce que même a l'étape 1 on puisse

Sevajol Bastien 12 years ago
parent
commit
a85e1dd06d

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

921
       return $response;
921
       return $response;
922
     }
922
     }
923
     
923
     
924
+    $url =  null;
925
+    if (count(($element_add_values = $request->get('element_add'))))
926
+    {
927
+      $url = $element_add_values['url'];
928
+    }
929
+    
924
     // On vérifie la tête de l'url quand même
930
     // On vérifie la tête de l'url quand même
925
-    if (filter_var($request->get('url'), FILTER_VALIDATE_URL) === false)
931
+    if (filter_var($url, FILTER_VALIDATE_URL) === false)
926
     {
932
     {
927
       return $this->jsonResponse(array(
933
       return $this->jsonResponse(array(
928
         'status' => 'error',
934
         'status' => 'error',
934
     
940
     
935
     // On construit l'élèment qui va nous permettre de travailler avec l'api
941
     // On construit l'élèment qui va nous permettre de travailler avec l'api
936
     $element = new Element();
942
     $element = new Element();
937
-    $element->setUrl($request->get('url'));
943
+    $element->setUrl($url);
938
     
944
     
939
     $factory = new ElementManager($element, $this->getEntityManager(), $this->container);
945
     $factory = new ElementManager($element, $this->getEntityManager(), $this->container);
940
     $factory->proceedFill($this->getUser());
946
     $factory->proceedFill($this->getUser());

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

1
 {% form_theme form 'MuzichCoreBundle:Form:errors.html.twig' %}
1
 {% form_theme form 'MuzichCoreBundle:Form:errors.html.twig' %}
2
 
2
 
3
 {{ form_errors(form) }}
3
 {{ form_errors(form) }}
4
+<input type="hidden" id="form_add_step" value="1" />
4
 
5
 
5
 <div id="form_add_first_part">
6
 <div id="form_add_first_part">
6
 
7
 
13
       'type': 'URL'
14
       'type': 'URL'
14
     }) }}
15
     }) }}
15
 
16
 
16
-    <a href="#" id="form_add_check_url" class="button">
17
-      {{ 'home.check_url'|trans({}, 'navigationui') }}
18
-    </a>
17
+    <input class="button" type="submit" value="{{ 'home.check_url'|trans({}, 'navigationui') }}" />
19
 
18
 
20
   </div>
19
   </div>
21
     
20
     

+ 1 - 0
src/Muzich/CoreBundle/Resources/views/layout.html.twig View File

67
     url_element_new_get = "{{ path('element_new_get') }}";
67
     url_element_new_get = "{{ path('element_new_get') }}";
68
     url_global_search = "{{ path('global_search') }}";
68
     url_global_search = "{{ path('global_search') }}";
69
     url_datas_api = "{{ path('element_retrieve_api_datas') }}";
69
     url_datas_api = "{{ path('element_retrieve_api_datas') }}";
70
+    url_element_add = "{{ path('element_add') }}";
70
     
71
     
71
     url_img_ajax_loader = "{{ asset('/bundles/muzichcore/img/ajax-loader.gif') }}";
72
     url_img_ajax_loader = "{{ asset('/bundles/muzichcore/img/ajax-loader.gif') }}";
72
   </script>
73
   </script>

+ 3 - 1
src/Muzich/HomeBundle/Resources/views/Home/index.html.twig View File

32
       &lt;&lt; {{ 'home.add_element_box.close'|trans({}, 'navigationui') }}
32
       &lt;&lt; {{ 'home.add_element_box.close'|trans({}, 'navigationui') }}
33
     </a>
33
     </a>
34
     
34
     
35
-    <form novalidate name="{{ add_form_name }}" action="{{ path('element_add') }}" method="post" {{ form_enctype(add_form) }}>
35
+    <form novalidate name="{{ add_form_name }}" 
36
+      action="{{ path('element_retrieve_api_datas') }}" method="post" {{ form_enctype(add_form) }}
37
+    >
36
 
38
 
37
       {% include "MuzichCoreBundle:Element:form.add.html.twig" with { 
39
       {% include "MuzichCoreBundle:Element:form.add.html.twig" with { 
38
         'form'          : add_form, 
40
         'form'          : add_form, 

+ 166 - 77
web/bundles/muzichcore/js/muzich.js View File

1167
 
1167
 
1168
   // Ajout d'un element #ajouter (première partie)
1168
   // Ajout d'un element #ajouter (première partie)
1169
   
1169
   
1170
-  // Click sur "ajouter" (l'url)
1171
-  $('a#form_add_check_url').click(function(){
1172
-    
1173
-    // On fait tourner notre gif loader
1174
-    $('img#form_add_loader').show();
1175
-    
1176
-    $.ajax({
1177
-      type: 'POST',
1178
-      url: url_datas_api,
1179
-      data: {'url':$('input#element_add_url').val()},
1180
-      success: function(response){
1181
-        
1182
-        if (response.status == 'mustbeconnected')
1183
-        {
1184
-          $(location).attr('href', url_index);
1185
-        }
1170
+//  // Click sur "ajouter" (l'url)
1171
+//  $('a#form_add_check_url').click(function(){
1172
+//    
1173
+//    // On fait tourner notre gif loader
1174
+//    $('img#form_add_loader').show();
1175
+//    
1176
+//    $.ajax({
1177
+//      type: 'POST',
1178
+//      url: url_datas_api,
1179
+//      data: {'url':$('input#element_add_url').val()},
1180
+//      success: function(response){
1181
+//        
1182
+//        if (response.status == 'mustbeconnected')
1183
+//        {
1184
+//          $(location).attr('href', url_index);
1185
+//        }
1186
+//
1187
+//        if (response.status == 'success')
1188
+//        {
1189
+//          // On cache notre gif loader.
1190
+//          $('img#form_add_loader').hide();
1191
+//          
1192
+//          // On commence par renseigner les champs si on a du concret
1193
+//          // name
1194
+//          if (response.name)
1195
+//          {
1196
+//            $('input#element_add_name').val(response.name);
1197
+//          }
1198
+//          
1199
+//          // thumb
1200
+//          $('div#form_add_thumb img').attr('src', '/bundles/muzichcore/img/nothumb.png');
1201
+//          if (response.thumb)
1202
+//          {
1203
+//            $('div#form_add_thumb img').attr('src', response.thumb);
1204
+//          }
1205
+//          
1206
+//          // Proposition de tags
1207
+//          if (response.tags)
1208
+//          {
1209
+//            $('ul#form_add_prop_tags li').remove();
1210
+//            $('ul#form_add_prop_tags').show();
1211
+//            $('ul#form_add_prop_tags_text').show();
1212
+//            
1213
+//            for (tags_index = 0; tags_index < response.tags.length; tags_index++)
1214
+//            {
1215
+//              var tag = response.tags[tags_index];
1216
+//              var tag_id = '';
1217
+//              var tag_name = tag.original_name;
1218
+//              // Si il y a des équivalent en base.
1219
+//              if (tag.like_found)
1220
+//              {
1221
+//                tag_id = tag.like.id;
1222
+//                tag_name = tag.like.name;
1223
+//              }
1224
+//                
1225
+//              // On aura plus qu'a vérifie le href pour savoir si c'est une demande d'ajout de tags =)
1226
+//              $('ul#form_add_prop_tags').append(
1227
+//                '<li>'+
1228
+//                  '<a href="#'+tag_id+'" class="form_add_prop_tag">'+
1229
+//                    tag_name+
1230
+//                  '</a>'+
1231
+//                '</li>'
1232
+//              );
1233
+//            }
1234
+//          }
1235
+//          
1236
+//          // On a plus qu'a afficher les champs
1237
+//          $('div#form_add_second_part').slideDown();
1238
+//          $('div#form_add_first_part').slideUp();
1239
+//          form_add_hide_errors();
1240
+//        }
1241
+//        else if (response.status == 'error')
1242
+//        {
1243
+//          form_add_display_errors(response.errors);
1244
+//          $('#form_add_loader').hide();
1245
+//          return false;
1246
+//        }
1247
+//      },
1248
+//      dataType: 'json'
1249
+//    });
1250
+//    
1251
+//  });
1252
+  
1253
+  function element_add_proceed_data_apis(response)
1254
+  {
1255
+    if (response.status == 'mustbeconnected')
1256
+    {
1257
+      $(location).attr('href', url_index);
1258
+    }
1186
 
1259
 
1187
-        if (response.status == 'success')
1260
+    if (response.status == 'success')
1261
+    {
1262
+      // On cache notre gif loader.
1263
+      $('img#form_add_loader').hide();
1264
+
1265
+      // On commence par renseigner les champs si on a du concret
1266
+      // name
1267
+      if (response.name)
1268
+      {
1269
+        $('input#element_add_name').val(response.name);
1270
+      }
1271
+
1272
+      // thumb
1273
+      $('div#form_add_thumb img').attr('src', '/bundles/muzichcore/img/nothumb.png');
1274
+      if (response.thumb)
1275
+      {
1276
+        $('div#form_add_thumb img').attr('src', response.thumb);
1277
+      }
1278
+
1279
+      // Proposition de tags
1280
+      if (response.tags)
1281
+      {
1282
+        $('ul#form_add_prop_tags li').remove();
1283
+        $('ul#form_add_prop_tags').show();
1284
+        $('ul#form_add_prop_tags_text').show();
1285
+
1286
+        for (tags_index = 0; tags_index < response.tags.length; tags_index++)
1188
         {
1287
         {
1189
-          // On cache notre gif loader.
1190
-          $('img#form_add_loader').hide();
1191
-          
1192
-          // On commence par renseigner les champs si on a du concret
1193
-          // name
1194
-          if (response.name)
1195
-          {
1196
-            $('input#element_add_name').val(response.name);
1197
-          }
1198
-          
1199
-          // thumb
1200
-          $('div#form_add_thumb img').attr('src', '/bundles/muzichcore/img/nothumb.png');
1201
-          if (response.thumb)
1202
-          {
1203
-            $('div#form_add_thumb img').attr('src', response.thumb);
1204
-          }
1205
-          
1206
-          // Proposition de tags
1207
-          if (response.tags)
1288
+          var tag = response.tags[tags_index];
1289
+          var tag_id = '';
1290
+          var tag_name = tag.original_name;
1291
+          // Si il y a des équivalent en base.
1292
+          if (tag.like_found)
1208
           {
1293
           {
1209
-            $('ul#form_add_prop_tags li').remove();
1210
-            $('ul#form_add_prop_tags').show();
1211
-            $('ul#form_add_prop_tags_text').show();
1212
-            
1213
-            for (tags_index = 0; tags_index < response.tags.length; tags_index++)
1214
-            {
1215
-              var tag = response.tags[tags_index];
1216
-              var tag_id = '';
1217
-              var tag_name = tag.original_name;
1218
-              // Si il y a des équivalent en base.
1219
-              if (tag.like_found)
1220
-              {
1221
-                tag_id = tag.like.id;
1222
-                tag_name = tag.like.name;
1223
-              }
1224
-                
1225
-              // On aura plus qu'a vérifie le href pour savoir si c'est une demande d'ajout de tags =)
1226
-              $('ul#form_add_prop_tags').append(
1227
-                '<li>'+
1228
-                  '<a href="#'+tag_id+'" class="form_add_prop_tag">'+
1229
-                    tag_name+
1230
-                  '</a>'+
1231
-                '</li>'
1232
-              );
1233
-            }
1294
+            tag_id = tag.like.id;
1295
+            tag_name = tag.like.name;
1234
           }
1296
           }
1235
-          
1236
-          // On a plus qu'a afficher les champs
1237
-          $('div#form_add_second_part').slideDown();
1238
-          $('div#form_add_first_part').slideUp();
1239
-          form_add_hide_errors();
1240
-        }
1241
-        else if (response.status == 'error')
1242
-        {
1243
-          form_add_display_errors(response.errors);
1244
-          $('#form_add_loader').hide();
1245
-          return false;
1297
+
1298
+          // On aura plus qu'a vérifie le href pour savoir si c'est une demande d'ajout de tags =)
1299
+          $('ul#form_add_prop_tags').append(
1300
+            '<li>'+
1301
+              '<a href="#'+tag_id+'" class="form_add_prop_tag">'+
1302
+                tag_name+
1303
+              '</a>'+
1304
+            '</li>'
1305
+          );
1246
         }
1306
         }
1247
-      },
1248
-      dataType: 'json'
1249
-    });
1307
+      }
1308
+
1309
+      return true;
1310
+    }
1311
+    else if (response.status == 'error')
1312
+    {
1313
+      return false;
1314
+    }
1250
     
1315
     
1251
-  });
1316
+    return true;
1317
+  }
1252
   
1318
   
1253
   /*
1319
   /*
1254
    * Formulaire d'ajout: click sur proposition de tags du a une api
1320
    * Formulaire d'ajout: click sur proposition de tags du a une api
1293
     
1359
     
1294
     $('form[name="add"] img.tag_loader').hide();
1360
     $('form[name="add"] img.tag_loader').hide();
1295
     
1361
     
1296
-    if (element_add_proceed_json_response(response))
1362
+    // Si on en est a la promière étape la réponse sera des données récupérés auprès
1363
+    // des apis
1364
+    if ($('input#form_add_step').val() == '1')
1365
+    {
1366
+      if (element_add_proceed_data_apis(response))
1367
+      {
1368
+        // On a plus qu'a afficher les champs
1369
+        $('div#form_add_second_part').slideDown();
1370
+        $('div#form_add_first_part').slideUp();
1371
+        form_add_hide_errors();
1372
+        $('#form_add_loader').hide();
1373
+        $('input#form_add_step').val('2');
1374
+        $('form[name="add"]').attr('action', url_element_add);
1375
+      }
1376
+      else
1377
+      {
1378
+        form_add_display_errors(response.errors);
1379
+        $('#form_add_loader').hide();
1380
+      }
1381
+    }
1382
+    else if ($('input#form_add_step').val() == '2')
1297
     { 
1383
     { 
1384
+      if (element_add_proceed_json_response(response))
1385
+      {
1298
       form_add_reinit();
1386
       form_add_reinit();
1387
+      }
1299
     }
1388
     }
1300
 
1389
 
1301
     
1390
     

+ 2 - 0
web/bundles/muzichhome/js/home.js View File

5
      $('#element_add_box').slideDown("slow");
5
      $('#element_add_box').slideDown("slow");
6
      $('#element_add_link').hide();
6
      $('#element_add_link').hide();
7
      $('form[name="search"]').slideUp();
7
      $('form[name="search"]').slideUp();
8
+     // Au cas ou firefox garde la valeur step 2:
9
+        $('input#form_add_step').val('1');
8
      return false;
10
      return false;
9
    });   
11
    });   
10
    
12