can edit and add an image to a post, still cant remove previously added images #issue #233

v1.18.x
Baris Soner Usakli 12 years ago
parent 928594fc7c
commit 54ba6efc93

@ -383,6 +383,18 @@
this.innerHTML = data.content; this.innerHTML = data.content;
$(this).fadeIn(250); $(this).fadeIn(250);
}); });
if(data.uploadedImages && data.uploadedImages.length) {
$('#images_'+data.pid).html('');
for(var i=0; i< data.uploadedImages.length; ++i) {
var img = $('<i class="icon-picture icon-1"></i><a href="' + data.uploadedImages[i].url +'"> '+data.uploadedImages[i].name+'</a><br/>');
$('#images_' + data.pid).append(img);
}
} else {
$('#images_'+data.pid).html('');
}
console.log('time to recreate images', data);
}); });
socket.on('api:posts.favourite', function(data) { socket.on('api:posts.favourite', function(data) {

@ -8,7 +8,8 @@ define(['taskbar'], function(taskbar) {
}; };
function createImageLabel(img, postImages) { function createImageLabel(img, postImages) {
var imageLabel = $('<div class="label label-primary"><span>'+ img.name +'</span></div>'); // var imageLabel = $('<div class="label label-primary"><span>'+ img.name +'</span></div>');
var imageLabel = $('<span class="label label-primary">' + img.name +'</span>');
var closeButton = $('<button class="close">&times;</button>'); var closeButton = $('<button class="close">&times;</button>');
closeButton.on('click', function(e) { closeButton.on('click', function(e) {

@ -55,7 +55,7 @@ var RDB = require('./redis.js'),
}); });
} }
PostTools.edit = function(uid, pid, title, content) { PostTools.edit = function(uid, pid, title, content, images) {
var success = function() { var success = function() {
posts.setPostField(pid, 'content', content); posts.setPostField(pid, 'content', content);
posts.setPostField(pid, 'edited', Date.now()); posts.setPostField(pid, 'edited', Date.now());
@ -66,6 +66,11 @@ var RDB = require('./redis.js'),
}); });
async.parallel([ async.parallel([
function(next) {
posts.uploadPostImages(pid, images, function(err, uploadedImages) {
next(err, uploadedImages);
});
},
function(next) { function(next) {
posts.getPostField(pid, 'tid', function(tid) { posts.getPostField(pid, 'tid', function(tid) {
PostTools.isMain(pid, tid, function(isMainPost) { PostTools.isMain(pid, tid, function(isMainPost) {
@ -76,7 +81,7 @@ var RDB = require('./redis.js'),
}); });
} }
next(null, tid); next(null, {tid:tid, isMainPost:isMainPost});
}); });
}); });
}, },
@ -84,10 +89,12 @@ var RDB = require('./redis.js'),
PostTools.toHTML(content, next); PostTools.toHTML(content, next);
} }
], function(err, results) { ], function(err, results) {
io.sockets.in('topic_' + results[0]).emit('event:post_edited', { io.sockets.in('topic_' + results[1].tid).emit('event:post_edited', {
pid: pid, pid: pid,
title: title, title: title,
content: results[1] isMainPost: results[1].isMainPost,
content: results[2],
uploadedImages:results[0]
}); });
}); });
}; };

@ -332,7 +332,7 @@ var RDB = require('./redis.js'),
async.parallel({ async.parallel({
uploadedImages: function(next) { uploadedImages: function(next) {
uploadPostImages(postData, images, function(err, uploadedImages) { Posts.uploadPostImages(postData.pid, images, function(err, uploadedImages) {
if(err) { if(err) {
winston.error('Uploading images failed!', err.stack); winston.error('Uploading images failed!', err.stack);
next(null, []); next(null, []);
@ -350,7 +350,6 @@ var RDB = require('./redis.js'),
} }
}, function(err, results) { }, function(err, results) {
postData.uploadedImages = results.uploadedImages; postData.uploadedImages = results.uploadedImages;
Posts.setPostField(pid, 'uploadedImages', JSON.stringify(postData.uploadedImages));
postData.content = results.content; postData.content = results.content;
callback(postData); callback(postData);
}); });
@ -366,7 +365,7 @@ var RDB = require('./redis.js'),
}); });
} }
function uploadPostImages(postData, images, callback) { Posts.uploadPostImages = function(pid, images, callback) {
var imgur = require('./imgur'); var imgur = require('./imgur');
imgur.setClientID(meta.config.imgurClientID); imgur.setClientID(meta.config.imgurClientID);
@ -394,6 +393,7 @@ var RDB = require('./redis.js'),
} else { } else {
async.each(images, uploadImage, function(err) { async.each(images, uploadImage, function(err) {
if(!err) { if(!err) {
Posts.setPostField(pid, 'uploadedImages', JSON.stringify(uploadedImages));
callback(null, uploadedImages); callback(null, uploadedImages);
} else { } else {
console.log(err); console.log(err);

@ -476,7 +476,7 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
posts.emitContentTooShortAlert(socket); posts.emitContentTooShortAlert(socket);
return; return;
} }
postTools.edit(uid, data.pid, data.title, data.content); postTools.edit(uid, data.pid, data.title, data.content, data.images);
}); });
socket.on('api:posts.delete', function(data) { socket.on('api:posts.delete', function(data) {

Loading…
Cancel
Save