mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
can edit and add an image to a post, still cant remove previously added images #issue #233
This commit is contained in:
@@ -383,6 +383,18 @@
|
||||
this.innerHTML = data.content;
|
||||
$(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) {
|
||||
|
||||
@@ -8,7 +8,8 @@ define(['taskbar'], function(taskbar) {
|
||||
};
|
||||
|
||||
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">×</button>');
|
||||
|
||||
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() {
|
||||
posts.setPostField(pid, 'content', content);
|
||||
posts.setPostField(pid, 'edited', Date.now());
|
||||
@@ -66,6 +66,11 @@ var RDB = require('./redis.js'),
|
||||
});
|
||||
|
||||
async.parallel([
|
||||
function(next) {
|
||||
posts.uploadPostImages(pid, images, function(err, uploadedImages) {
|
||||
next(err, uploadedImages);
|
||||
});
|
||||
},
|
||||
function(next) {
|
||||
posts.getPostField(pid, 'tid', function(tid) {
|
||||
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);
|
||||
}
|
||||
], 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,
|
||||
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({
|
||||
uploadedImages: function(next) {
|
||||
uploadPostImages(postData, images, function(err, uploadedImages) {
|
||||
Posts.uploadPostImages(postData.pid, images, function(err, uploadedImages) {
|
||||
if(err) {
|
||||
winston.error('Uploading images failed!', err.stack);
|
||||
next(null, []);
|
||||
@@ -350,7 +350,6 @@ var RDB = require('./redis.js'),
|
||||
}
|
||||
}, function(err, results) {
|
||||
postData.uploadedImages = results.uploadedImages;
|
||||
Posts.setPostField(pid, 'uploadedImages', JSON.stringify(postData.uploadedImages));
|
||||
postData.content = results.content;
|
||||
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');
|
||||
imgur.setClientID(meta.config.imgurClientID);
|
||||
|
||||
@@ -394,6 +393,7 @@ var RDB = require('./redis.js'),
|
||||
} else {
|
||||
async.each(images, uploadImage, function(err) {
|
||||
if(!err) {
|
||||
Posts.setPostField(pid, 'uploadedImages', JSON.stringify(uploadedImages));
|
||||
callback(null, uploadedImages);
|
||||
} else {
|
||||
console.log(err);
|
||||
|
||||
@@ -476,7 +476,7 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
|
||||
posts.emitContentTooShortAlert(socket);
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user