#00AF33
Official Code Helper
19529
0
1
Nov 19, 2012 14:18:28 GMT -8
Todge
**
17,324
January 2004
todge
|
Post by Todge on Sept 1, 2015 15:37:12 GMT -8
I am trying to create a button to delete a post, but I cannot fathom out how...
I can move the 'controls' cell and it works fine, but I then get an error pop up when switching pages, if I try to clone the 'controls' cell the post-options are missing, and if I try to create a new button exactly the same as the existing one, it does nothing.
So, is there a function I can call on to attach to my own button that will delete the post?
Thank you to anyone who can help.
|
|
inherit
Official Code Helper
65613
0
1
Oct 22, 2024 1:56:19 GMT -8
Chris
"'Oops' is the sound we make when we improve"
9,022
December 2005
horace
RedBassett's Mini-Profile
|
Post by Chris on Sept 1, 2015 20:04:21 GMT -8
Hi Todge, you can attach a click event to your button/link/whatever like so (ripped directly from PB source)...
$('#mybutton').on('click',[327], function deletePost(event){ var listMan = proboards.listManagers[pb.data("lm_id")]; var postMan = proboards.postManager; var post_ids_array = event.data proboards.confirm_dialog('posts', 'delete', post_ids_array, function(data) { // If a redirect_url is set, then that means the thread was deleted if(typeof data['redirect_url'] != 'undefined') { // Redirect to that url window.location = data['redirect_url']; } // Else refresh the list else { postMan.unselect_all(); // clear search cache and trigger re-search listMan.research();
// Update selection listMan.selected_ids = []; listMan.selected_items = {}; } }) });
I'm assuming you know at event attach time the ID or IDs of the posts that is to be deleted (e.g. [327] in the given code example) but if not you could probably reference a variable at runtime to gather that info. If you have not completely hidden the standard post list UI (which I am assuming you have done thus the need for a button) then you could access listManager's get_selections() method for the posts selected by the user instead.
Since this can potentially generate THREE ajax calls (one to get the dialog contents, one to do the actual delete and one to refresh the post list) it might be wise to ask someone on PB admin team for a blessing or curse although it seems clear cut to me: user initiated button click with no ambiguous motive as to what the click will do.
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Sept 1, 2015 23:09:12 GMT -8
...and I heard a voice like a thousand angels ringing from the Heavens. It came and brought peace to my soul. That is what I envisioned while reading Eton's sorcery above.
|
|
#00AF33
Official Code Helper
19529
0
1
Nov 19, 2012 14:18:28 GMT -8
Todge
**
17,324
January 2004
todge
|
Post by Todge on Sept 2, 2015 7:30:18 GMT -8
Thank you Chris, I knew there must be a way, but could I find it??? Yup, I already have the post ID, thank you... Refreshing the post list is a waste of time, as the posts themselves have already been removed while restructuring the page, so I'd just remove the cell pertaining to that post. Brian, Brian, VS Admin (or one of the other red peeps), would it be OK for me to do this? Thanks in advance.
|
|
#eb7100
33409
0
1
Nov 24, 2024 4:27:37 GMT -8
Brian
48,130
November 2004
smashmaster3
|
Post by Brian on Sept 2, 2015 8:40:55 GMT -8
Tim says you're good to go using that particular click binding.
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Sept 2, 2015 9:47:17 GMT -8
Thank you Chris, I knew there must be a way, but could I find it??? Yup, I already have the post ID, thank you... Refreshing the post list is a waste of time, as the posts themselves have already been removed while restructuring the page, so I'd just remove the cell pertaining to that post. Brian, Brian, VS Admin (or one of the other red peeps), would it be OK for me to do this? Thanks in advance. Tag you're it.
|
|
#00AF33
Official Code Helper
19529
0
1
Nov 19, 2012 14:18:28 GMT -8
Todge
**
17,324
January 2004
todge
|
Post by Todge on Sept 3, 2015 11:42:32 GMT -8
Tim says you're good to go using that particular click binding. Seems I tagged you twice, sorry about that, Tim was meant to be there as well, and thank you. I'll get straight on it.
|
|