Files
NodeBB/public/src/client/topic/diffs.js
Julian Lam 5d2e6f0e8e Squashed commit of the following:
commit 7bd46afad7033a466626826d3e29610f41328510
Author: Julian Lam <julian@nodebb.org>
Date:   Thu Mar 15 15:41:36 2018 -0400

    fixes #6363

commit 4b755d5801b2f6d70cea10516f88392708c72f61
Author: Julian Lam <julian@nodebb.org>
Date:   Thu Mar 15 15:24:12 2018 -0400

    fixes #6362

commit 6035e75453a08aee0fef7ff59d57dd5c1e8f4ac9
Author: Julian Lam <julian@nodebb.org>
Date:   Thu Mar 15 15:07:23 2018 -0400

    Fixes #6361
2018-03-15 15:42:20 -04:00

67 lines
1.7 KiB
JavaScript

'use strict';
define('forum/topic/diffs', ['benchpress', 'translator'], function (Benchpress, translator) {
var Diffs = {};
Diffs.open = function (pid) {
var localeStringOpts = { year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric' };
socket.emit('posts.getDiffs', { pid: pid }, function (err, timestamps) {
if (err) {
return app.alertError(err.message);
}
Benchpress.parse('partials/modals/post_history', {
diffs: timestamps.map(function (timestamp) {
return {
timestamp: timestamp,
pretty: new Date(timestamp).toLocaleString(config.userLang.replace('_', '-'), localeStringOpts),
};
}),
numDiffs: timestamps.length,
}, function (html) {
translator.translate(html, function (html) {
var modal = bootbox.dialog({
title: '[[topic:diffs.title]]',
message: html,
size: 'large',
});
if (!timestamps.length) {
return;
}
var selectEl = modal.find('select');
var postContainer = modal.find('ul.posts-list');
selectEl.on('change', function () {
Diffs.load(pid, this.value, postContainer);
});
modal.on('shown.bs.modal', function () {
Diffs.load(pid, selectEl.val(), postContainer);
});
});
});
});
};
Diffs.load = function (pid, since, postContainer) {
socket.emit('posts.showPostAt', { pid: pid, since: since }, function (err, data) {
if (err) {
return app.alertError(err.message);
}
data.deleted = !!parseInt(data.deleted, 10);
app.parseAndTranslate('partials/posts_list', 'posts', {
posts: [data],
}, function (html) {
postContainer.empty().append(html);
});
});
};
return Diffs;
});