Use grouped select field for role selection

This commit is contained in:
Stefan Parviainen 2015-01-01 15:54:16 +01:00
parent 686b6ee118
commit 85e76773a0
8 changed files with 28 additions and 48 deletions

View File

@ -800,38 +800,18 @@ function get_role_perms($role) {
} }
/** /**
* @brief Creates a HTML select field with all available roles. * @brief Returns a list or roles, grouped by type
* *
* @param string $current The current role * @param string $current The current role
* @return string Returns the complete HTML code for this privacy-role-select field. * @return string Returns an array of roles, grouped by type
*/ */
function role_selector($current) { function get_roles() {
if(! $current)
$current = 'custom';
$roles = array( $roles = array(
'social' => array( t('Social Networking'), t('Social Networking') => array('social' => t('Mostly Public'), 'social_restricted' => t('Restricted'), 'social_private' => t('Private')),
array('social' => t('Mostly Public'), 'social_restricted' => t('Restricted'), 'social_private' => t('Private'))), t('Community Forum') => array('forum' => t('Mostly Public'), 'forum_restricted' => t('Restricted'), 'forum_private' => t('Private')),
'forum' => array( t('Community Forum'), t('Feed Republish') => array('feed' => t('Mostly Public'), 'feed_restricted' => t('Restricted')),
array('forum' => t('Mostly Public'), 'forum_restricted' => t('Restricted'), 'forum_private' => t('Private'))), t('Special Purpose') => array('soapbox' => t('Celebrity/Soapbox'), 'repository' => t('Group Repository')),
'feed' => array( t('Feed Republish'), t('Other') => array('custom' => t('Custom/Expert Mode')));
array('feed' => t('Mostly Public'), 'feed_restricted' => t('Restricted'))),
'special' => array( t('Special Purpose'),
array('soapbox' => t('Celebrity/Soapbox'), 'repository' => t('Group Repository'))),
'other' => array( t('Other'),
array('custom' => t('Custom/Expert Mode'))));
$o = '<select name="permissions_role" id="privacy-role-select">'; return $roles;
foreach($roles as $k => $v) {
$o .= '<optgroup label="'. htmlspecialchars($v[0]) . '">';
foreach($v[1] as $kk => $vv) {
$selected = (($kk === $current) ? ' selected="selected"' : '');
$o .= '<option value="' . $kk . '"' . $selected . '>' . htmlspecialchars($vv) . '</option>';
}
$o .= '</optgroup>';
}
$o .= '</select>';
return $o;
} }

View File

@ -115,11 +115,8 @@ function new_channel_content(&$a) {
'$nick_desc' => t('Your nickname will be used to create an easily remembered channel address (like an email address) which you can share with others.'), '$nick_desc' => t('Your nickname will be used to create an easily remembered channel address (like an email address) which you can share with others.'),
'$label_import' => t('Or <a href="import">import an existing channel</a> from another location'), '$label_import' => t('Or <a href="import">import an existing channel</a> from another location'),
'$name' => $name, '$name' => $name,
'$label_role' => t('Channel Type'), '$help_role' => t('Please choose a channel type (such as social networking or community forum) and privacy requirements so we can select the best permissions for you'),
'$questionmark' => t('?'), '$role' => array('permissions_role' , t('Channel Type'), ($privacy_role) ? $privacy_role : 'social', '<a href="help/roles" target="_blank">'.t('Read more about roles').'</a>',get_roles()),
'$what_is_role' => t('What is this?'),
'$help_role' => t('Please choose a channel type (such as social networking or community forum) and privacy requirements so we can select the best permissions for you'),
'$role_select' => role_selector(($privacy_role) ? $privacy_role : 'social'),
'$nickname' => $nickname, '$nickname' => $nickname,
'$submit' => t('Create') '$submit' => t('Create')
)); ));

View File

@ -1042,9 +1042,7 @@ function settings_content(&$a) {
'$aclselect' => populate_acl($perm_defaults,false), '$aclselect' => populate_acl($perm_defaults,false),
'$suggestme' => $suggestme, '$suggestme' => $suggestme,
'$group_select' => $group_select, '$group_select' => $group_select,
'$role_lbl' => t('Channel permissions category:'), '$role' => array('permissions_role' , t('Channel permissions category:'), $permissions_role, '', get_roles()),
'$role_select' => role_selector($permissions_role),
'$profile_in_dir' => $profile_in_dir, '$profile_in_dir' => $profile_in_dir,
'$hide_friends' => $hide_friends, '$hide_friends' => $hide_friends,

View File

@ -1,5 +1,5 @@
$(document).ready(function() { $(document).ready(function() {
// $("#privacy-role-select").sSelect(); // $("#id_permissions_role").sSelect();
$("#newchannel-name").blur(function() { $("#newchannel-name").blur(function() {
$("#name-spinner").spin('small'); $("#name-spinner").spin('small');
var zreg_name = $("#newchannel-name").val(); var zreg_name = $("#newchannel-name").val();

View File

@ -8,8 +8,8 @@ $(document).ready(function() {
'transition' : 'elastic' 'transition' : 'elastic'
}); });
$("#privacy-role-select").change(function() { $("#id_permissions_role").change(function() {
var role = $("#privacy-role-select").val(); var role = $("#id_permissions_role").val();
if(role == 'custom') if(role == 'custom')
$('#advanced-perm').show(); $('#advanced-perm').show();
else else

View File

@ -5,10 +5,7 @@
<div id="newchannel-desc" class="descriptive-paragraph">{{$desc}}</div> <div id="newchannel-desc" class="descriptive-paragraph">{{$desc}}</div>
<div id="newchannel-role-help" class="descriptive-paragraph">{{$help_role}}</div> <div id="newchannel-role-help" class="descriptive-paragraph">{{$help_role}}</div>
{{include file="field_select_grouped.tpl" field=$role}}
<label for="newchannel-role" id="label-newchannel-role" class="newchannel-label" >{{$label_role}}</label>
{{$role_select}}
<div class="newchannel-role-morehelp"><a href="help/roles" title="{{$what_is_role}}" target="_blank">{{$questionmark}}</a></div>
<div id="newchannel-role-end" class="newchannel-field-end"></div> <div id="newchannel-role-end" class="newchannel-field-end"></div>

View File

@ -0,0 +1,11 @@
{{* TODO: Make id configurabel *}}
<select id='timezone_select' name='timezone'>
{{foreach $continents as $continent => $cities}}
<optgroup label="{{$continent}}">
{{foreach $cities as $city => $value}}
<option value='{{$value}}' {{if $value == $selected}}selected='selected'{{/if}}>{{$city}}</option>
{{/foreach}}
</optgroup>
{{/foreach}}
</select>

View File

@ -22,10 +22,7 @@
<h3 class="settings-heading">{{$h_prv}}</h3> <h3 class="settings-heading">{{$h_prv}}</h3>
<div class="field custom"> {{include file="field_select_grouped.tpl" field=$role}}
<label for="privacy-role-select">{{$role_lbl}}</label>
{{$role_select}}
</div>
<div id="advanced-perm" style="display:{{if $permissions_set}}none{{else}}block{{/if}};"> <div id="advanced-perm" style="display:{{if $permissions_set}}none{{else}}block{{/if}};">
{{include file="field_checkbox.tpl" field=$hide_presence}} {{include file="field_checkbox.tpl" field=$hide_presence}}