Advertisement
Guest User

Untitled

a guest
Apr 17th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function updatePhotosMessage(){
  2.     console.log('change is now');
  3.     var imageInput = document.getElementById('imageInput');
  4.     var count = imageInput.files.length;
  5.     if(count>0){
  6.         document.getElementById('imagesInfo').innerHTML = count + ' photos selected';  
  7.     } else {
  8.         document.getElementById('imagesInfo').innerHTML ='';
  9.     }  
  10. }
  11.  
  12.  
  13.  
  14.  
  15. function addPost(){
  16.     var id;
  17.     var title;
  18.     var text;
  19.     var imageInput;
  20.     id = $('#post_ID').val();
  21.     title = $('#postTitle').val();
  22.     text = $('#postText').val();
  23.     imageInput = document.getElementById('imageInput');
  24.     var call;
  25.     var callDone = function(post){
  26.         var post_ID = post.ID;
  27.         $('#post_ID').val(post_ID); // we store the ID in a hidden input in case the user presses back to edit
  28.         var imageData = new FormData(); // we can only upload the images using a formData
  29.         var left = imageInput.files.length;
  30.         for(var i = 0; i < imageInput.files.length; i++){
  31.             imageData = new FormData();
  32.             imageData.append('imageFile', imageInput.files[i]);
  33.             imageData.append('post_ID', post_ID);
  34.             imageData.append('index', i);
  35.             var upload = ImageManager.addImageToPost(imageData);
  36.             upload.done(function(image){
  37.                 left--;
  38.                
  39.                 $('#imagesInfo').html(left + ' photos left, please wait.');
  40.                 if(left==0){
  41.                     fn.load('menu/posts/selectPostCategory.html', renderCategoriesListForSelection('', post_ID));
  42.                     //fn.with(renderCategoriesListForSelection('', post_ID));
  43.                 }
  44.             });
  45.         }      
  46.        
  47.        
  48.     }
  49.     if(id){
  50.         // title, text, category_ID, post_ID
  51.         var postCall = PostsManager.requestPostByID(id);
  52.         postCall.done(function(post){
  53.             call = PostsManager.savePost(title, text, post.category_ID, id);
  54.             call.done(function(samePost){callDone(samePost)});
  55.         });
  56.     } else {
  57.         call = PostsManager.savePost(title, text, null);
  58.         call.done(function(post){callDone(post)});     
  59.     }
  60.     document.getElementById('imagesInfo').innerHTML = imageInput.files.length + ' photos selected';
  61. //  $('#imagesInfo').html(imageInput.files.length + ' photos selected');
  62.    
  63.    
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement