purplecat (
purplecat) wrote in
dw_dev_training2013-03-27 06:18 pm
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
![[site community profile]](https://www.dreamwidth.org/img/comm_staff.png)
Identifying community administrators in jquery.postform.js
I've been adding a stickies module to the entry post and edit pages as part of my work on Bug 2152 (multiple stickies). I had this set up so that if the user posts to a community all the sticky options quietly vanished and a little message appeared saying you couldn't sticky entries in communities. Unfortunately, as
fu pointed out, administrators can sticky entries in communities.
My problem is I have no idea how to identify a community administrator from jquery.postform.js (which is where I'm controlling this from). Is that possible? If not is there an obvious work around?
If the worst comes to the worst I can always have the message direct people to Organise->Manage Accounts->Display but that wouldn't be optimal.
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
My problem is I have no idea how to identify a community administrator from jquery.postform.js (which is where I'm controlling this from). Is that possible? If not is there an obvious work around?
If the worst comes to the worst I can always have the message direct people to Organise->Manage Accounts->Display but that wouldn't be optimal.
no subject
(Disclaimer: not looking at the code.)
no subject
Is that what you had in mind.
My concern about that route is that its somewhat convoluted and I'm not entirely clear what the best way to encode the information in module-journal.tt so that jquery.postform.js could pick it up - I'm pretty new to both Template Toolkit and jQuery. Pointers would be welcomed.
no subject
So (looking at the code now) Entry.pm loads up @journallist and then it only gets used in module-journal.tt to populate that dropdown. So we have some freedom there. :) Unfortunately, module-journal.tt ends up calling form.select, which means it's calling LJ::html_select(), which is like 500 years old and not very flexible. We'll just make the HTML by hand; it's not that bad in TT.
(Ok, even though I have the code in front of me, I don't have beta features set up so I can't test this. Fingers crossed.)
In Entry.pm, we'll create a more limited hash for @journallist:
my @postables = $u->posting_access_list;
my @journallist;
# add in the user's journal
push @journallist, { label => "", value => $u->user, administrator => 1 };
foreach my $postable ( @postables ) {
push @journallist, { label => $postable->user, value => $postable->user, administrator => $u->can_manage( $postable ) ? "1" : "0" };
}
then in module-journal.tt we replace the section in
[%- IF journallist.size > 1 %]
to<select name="usejournal" class="select" id="usejournal>
[% FOREACH journal = journallist %]
<option value="[%- journal.value | html %]" data-administrator="[%- journal.administrator %]">[%- journal.label | html %]</option>
[% END %]
</select>
...which should generate us the same select form as we had before, except we now have data-administrator values for each one. Then we should be able to check the value for the data attribute of the selected option in jquery using something like
var has_admin = $("#usejournal :selected").data("administrator");
And that might work? It's worth a try.
(Hmm, it's possible that you could also leave the current
@journallist
in Entry.pm and just do thecan_manage
in the TT, but I feel like this is cleaner...)no subject