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 the can_manage in the TT, but I feel like this is cleaner...)
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...)