From 82736d878073b748666801430d1dd75897feeabb Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 5 Jun 2013 10:18:29 -0400 Subject: [PATCH] editing of posts using new post window --- public/src/modules/composer.js | 15 ++++++++++++--- src/websockets.js | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/public/src/modules/composer.js b/public/src/modules/composer.js index 69cfba3350..f482542b2f 100644 --- a/public/src/modules/composer.js +++ b/public/src/modules/composer.js @@ -43,14 +43,14 @@ define(function() { socket.on('api:composer.push', function(threadData) { var uuid = utils.generateUUID(), btnEl = document.createElement('li'); - btnEl.innerHTML = '' + threadData.title + ''; + btnEl.innerHTML = '' + (!threadData.cid ? (threadData.title || '') : 'New Topic') + ''; btnEl.setAttribute('data-uuid', uuid); composer.listEl.appendChild(btnEl); composer.posts[uuid] = { tid: threadData.tid, cid: threadData.cid, pid: threadData.pid, - title: threadData.tid ? threadData.title : '', + title: threadData.title || '', body: threadData.body || '' }; composer.active++; @@ -170,6 +170,7 @@ define(function() { titleEl.value = 'Replying to: ' + post_data.title; titleEl.readonly = true; } else if (post_data.pid > 0) { + console.log(post_data); titleEl.value = 'Editing: ' + post_data.title; titleEl.readonly = true; } else { @@ -180,6 +181,8 @@ define(function() { // Highlight the button $('.posts-bar li').removeClass('active'); composer.btnContainer.querySelector('[data-uuid="' + post_uuid + '"]').className += ' active'; + + // } composer.post = function(post_uuid) { @@ -198,7 +201,7 @@ define(function() { } // Still here? Let's post. - if (postData.tid === 0 || postData.cid) { + if (parseInt(postData.cid) > 0) { socket.emit('api:topics.post', { 'title' : titleEl.value, 'content' : bodyEl.value, @@ -209,6 +212,12 @@ define(function() { 'topic_id' : postData.tid, 'content' : bodyEl.value }); + } else if (parseInt(postData.pid) > 0) { + socket.emit('api:posts.edit', { + pid: postData.pid, + content: bodyEl.value, + title: titleEl.value + }); } composer.discard(post_uuid); diff --git a/src/websockets.js b/src/websockets.js index 3700a1cc59..3f254b7a27 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -319,7 +319,7 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }), tid: 0, cid: data.cid, username: username, - title: 'New Topic' + title: undefined }); }); } else if (parseInt(data.pid) > 0) {