Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function updatePhotosMessage(){
- console.log('change is now');
- var imageInput = document.getElementById('imageInput');
- var count = imageInput.files.length;
- if(count>0){
- document.getElementById('imagesInfo').innerHTML = count + ' photos selected';
- } else {
- document.getElementById('imagesInfo').innerHTML ='';
- }
- }
- function addPost(){
- var id;
- var title;
- var text;
- var imageInput;
- id = $('#post_ID').val();
- title = $('#postTitle').val();
- text = $('#postText').val();
- imageInput = document.getElementById('imageInput');
- var call;
- var callDone = function(post){
- var post_ID = post.ID;
- $('#post_ID').val(post_ID); // we store the ID in a hidden input in case the user presses back to edit
- var imageData = new FormData(); // we can only upload the images using a formData
- var left = imageInput.files.length;
- for(var i = 0; i < imageInput.files.length; i++){
- imageData = new FormData();
- imageData.append('imageFile', imageInput.files[i]);
- imageData.append('post_ID', post_ID);
- imageData.append('index', i);
- var upload = ImageManager.addImageToPost(imageData);
- upload.done(function(image){
- left--;
- $('#imagesInfo').html(left + ' photos left, please wait.');
- if(left==0){
- fn.load('menu/posts/selectPostCategory.html', renderCategoriesListForSelection('', post_ID));
- //fn.with(renderCategoriesListForSelection('', post_ID));
- }
- });
- }
- }
- if(id){
- // title, text, category_ID, post_ID
- var postCall = PostsManager.requestPostByID(id);
- postCall.done(function(post){
- call = PostsManager.savePost(title, text, post.category_ID, id);
- call.done(function(samePost){callDone(samePost)});
- });
- } else {
- call = PostsManager.savePost(title, text, null);
- call.done(function(post){callDone(post)});
- }
- document.getElementById('imagesInfo').innerHTML = imageInput.files.length + ' photos selected';
- // $('#imagesInfo').html(imageInput.files.length + ' photos selected');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement