ajax delete

This commit is contained in:
James Campos 2012-06-10 15:07:12 -07:00
parent b6df3d60fc
commit 4150ca70f9
2 changed files with 72 additions and 4 deletions

View File

@ -3435,8 +3435,44 @@
return $.on(a, 'click', DeleteButton["delete"]);
},
"delete": function() {
$.x('preceding-sibling::input', this).checked = true;
return $.id('delPassword').nextElementSibling.click();
var data, id, m, pwd;
if (m = d.cookie.match(/4chan_pass=([^;]+)/)) {
pwd = decodeURIComponent(m[1]);
} else {
this.textContent = 'Error: no password found';
return;
}
DeleteButton.el = this;
$.off(this, 'click', DeleteButton["delete"]);
this.textContent = 'Deleting...';
id = $.x('preceding-sibling::input', this).name;
data = new FormData();
data.append(id, 'delete');
data.append('mode', 'usrdel');
return $.ajax("https://sys.4chan.org/" + g.BOARD + "/imgboard.php", {
onload: DeleteButton.load,
onerror: DeleteButton.error
}, {
type: 'post',
form: data,
pwd: pwd
});
},
load: function() {
var doc, msg, tc;
doc = d.implementation.createHTMLDocument('');
doc.documentElement.innerHTML = this.response;
if (doc.title === '4chan - Banned') {
tc = 'Banned!';
} else if (msg = doc.getElementById('errmsg')) {
tc = msg.textContent;
} else {
tc = 'Deleted';
}
return DeleteButton.el.textContent = tc;
},
error: function() {
return DeleteButton.el.textContent = 'Error';
}
};

View File

@ -2619,8 +2619,40 @@ DeleteButton =
$.add $('.postInfo', post.el), a
$.on a, 'click', DeleteButton.delete
delete: ->
$.x('preceding-sibling::input', @).checked = true
$.id('delPassword').nextElementSibling.click()
if m = d.cookie.match(/4chan_pass=([^;]+)/)
pwd = decodeURIComponent m[1]
else
@textContent = 'Error: no password found'
return
DeleteButton.el = @
$.off @, 'click', DeleteButton.delete
@textContent = 'Deleting...'
id = $.x('preceding-sibling::input', @).name
data = new FormData()
data.append id, 'delete'
data.append 'mode', 'usrdel'
$.ajax "https://sys.4chan.org/#{g.BOARD}/imgboard.php", {
onload: DeleteButton.load
onerror: DeleteButton.error
}, {
type: 'post'
form: data
pwd: pwd
}
load: ->
doc = d.implementation.createHTMLDocument ''
doc.documentElement.innerHTML = @response
if doc.title is '4chan - Banned' # Ban/warn check
tc = 'Banned!'
else if msg = doc.getElementById 'errmsg' # error!
tc = msg.textContent
else
tc = 'Deleted'
DeleteButton.el.textContent = tc
error: ->
DeleteButton.el.textContent = 'Error'
ReportButton =
init: ->