diff --git a/public/language/en_GB/error.json b/public/language/en_GB/error.json index a159a0e42c..cfbebc4c0a 100644 --- a/public/language/en_GB/error.json +++ b/public/language/en_GB/error.json @@ -50,6 +50,13 @@ "topic-locked": "Topic Locked", "post-edit-duration-expired": "You are only allowed to edit posts for %1 second(s) after posting", + "post-edit-duration-expired-minutes": "You are only allowed to edit posts for %1 minute(s) after posting", + "post-edit-duration-expired-minutes-seconds": "You are only allowed to edit posts for %1 minute(s) %2 second(s) after posting", + "post-edit-duration-expired-hours": "You are only allowed to edit posts for %1 hour(s) after posting", + "post-edit-duration-expired-hours-minutes": "You are only allowed to edit posts for %1 hour(s) %2 minute(s) after posting", + "post-edit-duration-expired-days": "You are only allowed to edit posts for %1 day(s) after posting", + "post-edit-duration-expired-days-hours": "You are only allowed to edit posts for %1 day(s) %2 hour(s) after posting", + "content-too-short": "Please enter a longer post. Posts should contain at least %1 character(s).", "content-too-long": "Please enter a shorter post. Posts can't be longer than %1 character(s).", diff --git a/public/src/client/topic/postTools.js b/public/src/client/topic/postTools.js index d1961a29a6..98b6ef1470 100644 --- a/public/src/client/topic/postTools.js +++ b/public/src/client/topic/postTools.js @@ -168,6 +168,37 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator postContainer.on('click', '[component="post/edit"]', function() { var btn = $(this); + + var timestamp = parseInt(getData(btn, 'data-timestamp'), 10); + var postEditDuration = parseInt(ajaxify.data.postEditDuration, 10); + if (postEditDuration && Date.now() - timestamp > postEditDuration * 1000) { + var numDays = Math.floor(postEditDuration / 86400); + var numHours = Math.floor((postEditDuration % 86400) / 3600); + var numMinutes = Math.floor(((postEditDuration % 86400) % 3600) / 60); + var numSeconds = ((postEditDuration % 86400) % 3600) % 60; + var msg = '[[error:post-edit-duration-expired, ' + postEditDuration + ']]'; + if (numDays) { + if (numHours) { + msg = '[[error:post-edit-duration-expired-days-hours, ' + numDays + ', ' + numHours + ']]'; + } else { + msg = '[[error:post-edit-duration-expired-days, ' + numDays + ']]'; + } + } else if (numHours) { + if (numMinutes) { + msg = '[[error:post-edit-duration-expired-hours-minutes, ' + numHours + ', ' + numMinutes + ']]'; + } else { + msg = '[[error:post-edit-duration-expired-hours, ' + numHours + ']]'; + } + } else if (numMinutes) { + if (numSeconds) { + msg = '[[error:post-edit-duration-expired-minutes-seconds, ' + numMinutes + ', ' + numSeconds + ']]'; + } else { + msg = '[[error:post-edit-duration-expired-minutes, ' + numMinutes + ']]'; + } + } + return app.alertError(msg); + } + $(window).trigger('action:composer.post.edit', { pid: getData(btn, 'data-pid') }); diff --git a/src/controllers/topics.js b/src/controllers/topics.js index 74604c0085..750622b4b4 100644 --- a/src/controllers/topics.js +++ b/src/controllers/topics.js @@ -264,6 +264,7 @@ topicsController.get = function(req, res, callback) { data['downvote:disabled'] = parseInt(meta.config['downvote:disabled'], 10) === 1; data['feeds:disableRSS'] = parseInt(meta.config['feeds:disableRSS'], 10) === 1; data.bookmarkThreshold = parseInt(meta.config.bookmarkThreshold, 10) || 5; + data.postEditDuration = parseInt(meta.config.postEditDuration, 10); data.scrollToMyPost = settings.scrollToMyPost; data.rssFeedUrl = nconf.get('relative_path') + '/topic/' + data.tid + '.rss'; data.pagination = pagination.create(currentPage, pageCount); diff --git a/src/views/partials/data/topic.tpl b/src/views/partials/data/topic.tpl index d7fd1deb50..ea6fea2a3c 100644 --- a/src/views/partials/data/topic.tpl +++ b/src/views/partials/data/topic.tpl @@ -1 +1 @@ -data-index="{posts.index}" data-pid="{posts.pid}" data-uid="{posts.uid}" data-username="{posts.user.username}" data-userslug="{posts.user.userslug}" itemscope itemtype="http://schema.org/Comment" \ No newline at end of file +data-index="{posts.index}" data-pid="{posts.pid}" data-uid="{posts.uid}" data-timestamp="{posts.timestamp}" data-username="{posts.user.username}" data-userslug="{posts.user.userslug}" itemscope itemtype="http://schema.org/Comment" \ No newline at end of file