Fixing multiple upload problem by removing anonymous save function out of an iterated...
authorBryan <btbonval@gmail.com>
Thu, 19 Dec 2013 23:06:26 +0000 (18:06 -0500)
committerBryan <btbonval@gmail.com>
Thu, 19 Dec 2013 23:06:26 +0000 (18:06 -0500)
karmaworld/templates/partial/filepicker.html

index edad6464339e60974b4fa4f983080908a3c9cf34..615b95d8813ce95fcbe7d7089123f3c2e18debdb 100644 (file)
         });
         
         document.getElementById('save-btn').style.display = 'inline';
+      }
 
-        $('#save-btn').on('click', function(e){
-          e.stopPropagation();
-          $('#forms_container .inline-form').each(function(i,el){
-              console.log("inline form " + i + "el: " + el);
-              var name, tags, fpurl, course;
-              name = $(el).find('.intext').val();
-              fp_file = $(el).find('.fpurl').val();
-              tags = $(el).find('.taggit-tags').val();
-              course = $(el).find('.course_id').val();
-              csrf = $(el).find('.csrf').val();
-              mimetype = $(el).find('.mimetype').val();
+      $('#save-btn').on('click', function(e){
+        e.stopPropagation();
+        $('#forms_container .inline-form').each(function(i,el){
+            console.log("inline form " + i + "el: " + el);
+            var name, tags, fpurl, course;
+            name = $(el).find('.intext').val();
+            fp_file = $(el).find('.fpurl').val();
+            tags = $(el).find('.taggit-tags').val();
+            course = $(el).find('.course_id').val();
+            csrf = $(el).find('.csrf').val();
+            mimetype = $(el).find('.mimetype').val();
 
-              $.post('{% url 'upload_post' %}', {
-                'name': name,
-                'fp_file': fp_file,
-                'tags': tags,
-                'course': course,
-                'csrfmiddlewaretoken': csrf,
-                'mimetype': mimetype
-              }, function(data){
-                if (data === 'success') {
-                  // For multiple uploads, we may end up clearing and re-
-                  //  writing this multiple times, but show the same list
-                  //  each time.
-                  $('#uploaded_files').empty();
-                  for (var i=0; i < uploaded_files.length; i++) {
-                    $('#uploaded_files').append($('<li>', {text: uploaded_files[i]}));
-                  }
-                  $('#success').show();
-                  document.getElementById('save-btn').style.display = 'none';
-                  $('#forms_container .inline-form').remove();
-                  _gat._getTracker()._trackEvent('upload', 'upload form submitted');
-                  setTimeout(function(){
-                    location.reload(true);
-                  }, 15000);
+            $.post('{% url 'upload_post' %}', {
+              'name': name,
+              'fp_file': fp_file,
+              'tags': tags,
+              'course': course,
+              'csrfmiddlewaretoken': csrf,
+              'mimetype': mimetype
+            }, function(data){
+              if (data === 'success') {
+                // For multiple uploads, we may end up clearing and re-
+                //  writing this multiple times, but show the same list
+                //  each time.
+                $('#uploaded_files').empty();
+                for (var i=0; i < uploaded_files.length; i++) {
+                  $('#uploaded_files').append($('<li>', {text: uploaded_files[i]}));
                 }
-              });
-              // Add the name we've just uploaded to the list
-              uploaded_files.push(name);
-          });
+                $('#success').show();
+                document.getElementById('save-btn').style.display = 'none';
+                $('#forms_container .inline-form').remove();
+                _gat._getTracker()._trackEvent('upload', 'upload form submitted');
+                setTimeout(function(){
+                  location.reload(true);
+                }, 15000);
+              }
+            });
+            // Add the name we've just uploaded to the list
+            uploaded_files.push(name);
         });
-
-      };
+      });
       
       var fileup = document.getElementById('filepicker-file-upload');
       fileup.onchange = function(event){