Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2011-11-23 16:09:06
- faltik
- New Member
- From: Czech Rep.
- Registered: 2009-12-03
- Posts: 7
User-specific sections with section-specific categories using jQuery
Ok so here’s a bummer:
With help from Redbot in this thread (and ofcourse, his excellent plugin bot_wtc), I figured out two solutions how to partially solve my problem – Restricting user privs just to certain sections without the need of adding dozens new lines for every user/group each time new section/category is created. Thing is, both of them have some disadvantages.
I’d like to add that I’m just simple graphic designer without no jQuery experience whatsoever, so If I’m doing something wrong, feel free to correct me. Anyway, here’s what I’ve put together after some googling etc.:
Solution #1, using .remove()
<script type="text/javascript">
$(document).ready(function() {
$('body.some_group #section option').remove(); // removing all sections for some_group
$('body.some_user #section').append('<option value="section1">Section title</option>'); // allowing some_user to see and pick section1
$('body.some_user #section').append('<option value="section2">Section title</option>'); // allowing some_user to see and pick section2
});
</script>
On the first look, this one gets the work done. Problem is when you want to edit already published article – the drop down menu resets each time user is accessing Write tab (whether it is a new article or not), adds new values independently on sections and then picks the first one, which in most cases won’t be the same section in which article was before. And unfortunately, I found this very irritating to my clients.
Solution #2, using .hide()
<script type="text/javascript">
$(document).ready(function() {
$('#section option[value="section1"]').hide(); // in this case, I have to hide every section manually
$('#section option[value="section2"]').hide();
$('#section option[value="section3"]').hide();
$('body.some_user #section option[value="section1"]').show; // allowing some_user to see and pick section1
$('body.some_user #section option[value="section2"]').show; // allowing some_user to see and pick section2
});
</script>
First disadvantage of this one is that I have to hide every single section manually first, but that’s a thing I can live with. But the biggest problem is… it just refuses to work in IE >_<
In addition, I want my categories to change according to what section has been chosen. Again, I can use both solutions, but with the same result:
#1 using .remove()
$("#section").change(function () {
if ($('#section option[value="section1"]:selected').length)
$('#category-1 option').remove(), // removing all categories first to prevent duplicating
$('#category-1').append('<option value="category1">Category title</option>');
});
#2 using .hide() – I’ve actually found this by looking through bot_wtc code
$("#section").change(function(){
var value = $("#section").val();
if (value=="section1"){
$('#category-1 option').hide();
$('#category-1 option[value="category1"]').show();
}
}).change();
So, is there any way to get it working, whether it will be by using .remove() solution (and always automaticly choose right section when editing an article), or .hide() (and make it work in IE?).
Many thanks for future advices and yes, I feel bad for my lack of experience.
Last edited by faltik (2011-11-23 21:04:19)
Offline