Add a cooldown to post deletion. Close #586

This commit is contained in:
Nicolas Stepien 2012-07-12 17:19:50 +02:00
parent 420f655a51
commit e60c01bd78
3 changed files with 78 additions and 7 deletions

View File

@ -4115,21 +4115,37 @@
return true; return true;
} }
}); });
return Menu.addEntry({ Menu.addEntry({
el: div, el: div,
open: function(post) { open: function(post) {
return !post.isArchived; var node, seconds;
if (post.isArchived) {
return false;
}
node = div.firstChild;
if (seconds = DeleteLink.cooldown[post.ID]) {
node.textContent = "Delete (" + seconds + ")";
DeleteLink.cooldown.el = node;
} else {
node.textContent = 'Delete';
delete DeleteLink.cooldown.el;
}
return true;
}, },
children: children children: children
}); });
return $.on(d, 'QRPostSuccessful', this.cooldown.start);
}, },
"delete": function() { "delete": function() {
var board, form, id, m, menu, pwd, self; var board, form, id, m, menu, pwd, self;
menu = $.id('menu');
id = menu.dataset.id;
if (DeleteLink.cooldown[id]) {
return;
}
$.off(this, 'click', DeleteLink["delete"]); $.off(this, 'click', DeleteLink["delete"]);
this.textContent = 'Deleting...'; this.textContent = 'Deleting...';
pwd = (m = d.cookie.match(/4chan_pass=([^;]+)/)) ? decodeURIComponent(m[1]) : $.id('delPassword').value; pwd = (m = d.cookie.match(/4chan_pass=([^;]+)/)) ? decodeURIComponent(m[1]) : $.id('delPassword').value;
menu = $.id('menu');
id = menu.dataset.id;
board = $('a[title="Highlight this post"]', $.id(menu.dataset.rootid)).pathname.split('/')[1]; board = $('a[title="Highlight this post"]', $.id(menu.dataset.rootid)).pathname.split('/')[1];
self = this; self = this;
form = { form = {
@ -4166,6 +4182,31 @@
error: function(self) { error: function(self) {
self.textContent = 'Connection error, please retry.'; self.textContent = 'Connection error, please retry.';
return $.on(self, 'click', DeleteLink["delete"]); return $.on(self, 'click', DeleteLink["delete"]);
},
cooldown: {
start: function(e) {
return DeleteLink.cooldown.count(e.detail.postID, 30);
},
count: function(postID, seconds) {
var el;
if (!((0 <= seconds && seconds <= 30))) {
return;
}
setTimeout(DeleteLink.cooldown.count, 1000, postID, seconds - 1);
el = DeleteLink.cooldown.el;
if (seconds === 0) {
if (el != null) {
el.textContent = 'Delete';
}
delete DeleteLink.cooldown[postID];
delete DeleteLink.cooldown.el;
return;
}
if (el != null) {
el.textContent = "Delete (" + seconds + ")";
}
return DeleteLink.cooldown[postID] = seconds;
}
} }
}; };

View File

@ -1,6 +1,7 @@
master master
- Mayhem - Mayhem
Divide the Delete Link in the Menu into a Post and Image deletion links. Divide the Delete Link in the Menu into a Post and Image deletion links.
The Delete Links in the Menu now have a cooldown.
2.34.1 2.34.1
- Mayhem - Mayhem

View File

@ -3268,10 +3268,26 @@ DeleteLink =
Menu.addEntry Menu.addEntry
el: div el: div
open: (post) -> !post.isArchived open: (post) ->
if post.isArchived
return false
node = div.firstChild
if seconds = DeleteLink.cooldown[post.ID]
node.textContent = "Delete (#{seconds})"
DeleteLink.cooldown.el = node
else
node.textContent = 'Delete'
delete DeleteLink.cooldown.el
true
children: children children: children
$.on d, 'QRPostSuccessful', @cooldown.start
delete: -> delete: ->
menu = $.id 'menu'
{id} = menu.dataset
return if DeleteLink.cooldown[id]
$.off @, 'click', DeleteLink.delete $.off @, 'click', DeleteLink.delete
@textContent = 'Deleting...' @textContent = 'Deleting...'
@ -3281,8 +3297,6 @@ DeleteLink =
else else
$.id('delPassword').value $.id('delPassword').value
menu = $.id 'menu'
id = menu.dataset.id
board = $('a[title="Highlight this post"]', board = $('a[title="Highlight this post"]',
$.id menu.dataset.rootid).pathname.split('/')[1] $.id menu.dataset.rootid).pathname.split('/')[1]
self = @ self = @
@ -3314,6 +3328,21 @@ DeleteLink =
self.textContent = 'Connection error, please retry.' self.textContent = 'Connection error, please retry.'
$.on self, 'click', DeleteLink.delete $.on self, 'click', DeleteLink.delete
cooldown:
start: (e) ->
DeleteLink.cooldown.count e.detail.postID, 30
count: (postID, seconds) ->
return unless 0 <= seconds <= 30
setTimeout DeleteLink.cooldown.count, 1000, postID, seconds-1
{el} = DeleteLink.cooldown
if seconds is 0
el?.textContent = 'Delete'
delete DeleteLink.cooldown[postID]
delete DeleteLink.cooldown.el
return
el?.textContent = "Delete (#{seconds})"
DeleteLink.cooldown[postID] = seconds
ReportLink = ReportLink =
init: -> init: ->
a = $.el 'a', a = $.el 'a',