Expose "Mark this post as the correct answer"
-
is there any way that "Mark this post as the correct answer" from the Q&A plugin can be moved out of the dropdown it sits in, and placed inside the post itself? I'd like to do this so that the process is simplified - it's currently buried, which isn't very intuitive if you do not know where to look.
Thanks
-
In the Q&A plugin, it basically makes a call to
socket.emit('plugins.QandA.toggleSolved({ tid });
, so your theme can be updated to expose the control, and you can wire it up that way.That's the bulk of it, really. The plugin also calls
alerts.alert
andajaxify.refresh
, but you can also do those on your own:function toggleSolved() { var tid = ajaxify.data.tid; socket.emit('plugins.QandA.toggleSolved', { tid: tid }, function (err, data) { if (err) { return alertType('error', err); } alertType('success', data.isSolved ? '[[qanda:thread.alert.solved]]' : '[[qanda:thread.alert.unsolved]]'); ajaxify.refresh(); }); }
-
It's funny you ask because last night I discovered Carnegie Mellon University's "Foundations of Software Engineering" course uses a fork of NodeBB for a term project... one of the tasks looks to be adding the "toggle solved" button to the UI
... but they're not using the Q&A plugin so I feel safe sharing this particular answer
-
@julian thinking about this it might be quicker to call the function directly using some jQuery and triggering off an element ID? However, I expect there to be multiple values that need to be passed along with the function, so maybe this isn't such a good idea
-
@julian thought so thanks
Edit - actually, looking at this function, I can't see why it can't be invoked by jQuery?
function markPostAsAnswer() { var tid = ajaxify.data.tid; var pid = $(this).parents('[data-pid]').attr('data-pid'); socket.emit('plugins.QandA.toggleSolved', { tid: tid, pid: pid }, function (err, data) { if (err) { return alertType('error', err); } alertType('success', data.isSolved ? '[[qanda:post.alert.correct_answer]]' : '[[qanda:thread.alert.unsolved]]'); ajaxify.refresh(); }); }