Browse Source

Merge pull request #1469 from live627/perms-ux-overhaul

Permissions UX overhaul
Michael Eshom 10 years ago
parent
commit
fe74ee64be

+ 28 - 3
Sources/ManagePermissions.php

@@ -698,6 +698,7 @@ function ModifyMembergroup()
 
 	loadAllPermissions();
 	loadPermissionProfiles();
+	$context['hidden_perms'] = array();
 
 	if ($context['group']['id'] > 0)
 	{
@@ -800,11 +801,35 @@ function ModifyMembergroup()
 
 					if ($perm['has_own_any'])
 					{
-						$curPerm['any']['select'] = in_array($perm['id'] . '_any', $permissions[$permissionType]['allowed']) ? 'on' : (in_array($perm['id'] . '_any', $permissions[$permissionType]['denied']) ? 'denied' : 'off');
-						$curPerm['own']['select'] = in_array($perm['id'] . '_own', $permissions[$permissionType]['allowed']) ? 'on' : (in_array($perm['id'] . '_own', $permissions[$permissionType]['denied']) ? 'denied' : 'off');
+						$curPerm['any']['select'] = in_array($perm['id'] . '_any', $permissions[$permissionType]['allowed']) ? 'on' : (in_array($perm['id'] . '_any', $permissions[$permissionType]['denied']) ? 'deny' : 'off');
+						$curPerm['own']['select'] = in_array($perm['id'] . '_own', $permissions[$permissionType]['allowed']) ? 'on' : (in_array($perm['id'] . '_own', $permissions[$permissionType]['denied']) ? 'deny' : 'off');
 					}
 					else
-						$curPerm['select'] = in_array($perm['id'], $permissions[$permissionType]['denied']) ? 'denied' : (in_array($perm['id'], $permissions[$permissionType]['allowed']) ? 'on' : 'off');
+						$curPerm['select'] = in_array($perm['id'], $permissions[$permissionType]['denied']) ? 'deny' : (in_array($perm['id'], $permissions[$permissionType]['allowed']) ? 'on' : 'off');
+
+						// Keep the last value if it's hidden.
+						if ($perm['hidden'] || $permissionArray['hidden'])
+						{
+							if ($perm['has_own_any'])
+							{
+								$context['hidden_perms'][] = array(
+									$permissionType,
+									$perm['own']['id'],
+									$curPerm['own']['select'] == 'deny' && !empty($modSettings['permission_enable_deny']) ? 'deny' : $curPerm['own']['select'],
+								);
+								$context['hidden_perms'][] = array(
+									$permissionType,
+									$perm['any']['id'],
+									$curPerm['any']['select'] == 'deny' && !empty($modSettings['permission_enable_deny']) ? 'deny' : $curPerm['any']['select'],
+								);
+							}
+							else
+								$context['hidden_perms'][] = array(
+									$permissionType,
+									$perm['id'],
+									$curPerm['select'] == 'deny' && !empty($modSettings['permission_enable_deny']) ? 'deny' : $curPerm['select'],
+								);
+						}
 				}
 			}
 		}

+ 63 - 84
Themes/default/ManagePermissions.template.php

@@ -540,6 +540,10 @@ function template_modify_group()
 				<input type="submit" value="', $txt['permissions_commit'], '" class="button_submit">
 			</div>';
 
+	foreach ($context['hidden_perms'] as $hidden_perm)
+		echo '
+			<input type="hidden" name="perm[', $hidden_perm[0], '][', $hidden_perm[1], ']" value="', $hidden_perm[2], '">';
+
 	echo '
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
 			<input type="hidden" name="', $context['admin-mp_token_var'], '" value="', $context['admin-mp_token'], '">
@@ -582,129 +586,104 @@ function template_modify_group_display($type)
 				{
 					echo '
 							<tr class="catbg">
-								<th colspan="2" width="100%" align="left"><strong class="smalltext">', $permissionGroup['name'], '</strong></th>';
-					if (empty($modSettings['permission_enable_deny']) || $context['group']['id'] == -1)
+								<th width="10"></th>
+								<th', $context['group']['id'] == -1 ? ' colspan="2"' : '', ' class="smalltext">', $permissionGroup['name'], '</th>';
+
+					if ($context['group']['id'] != -1)
 						echo '
-								<th colspan="3" width="10"></th>';
-					else
+								<th align="center">', $txt['permissions_option_own'], '</th>
+								<th align="center">', $txt['permissions_option_any'], '</th>';
+
 						echo '
-								<th align="center"><div>', $txt['permissions_option_on'], '</div></th>
-								<th align="center"><div>', $txt['permissions_option_off'], '</div></th>
-								<th align="center"><div>', $txt['permissions_option_deny'], '</div></th>';
-					echo '
 							</tr>';
 				}
 			}
 
-			$alternate = false;
 			foreach ($permissionGroup['permissions'] as $permission)
 			{
-				// If it's hidden keep the last value.
-				if ($permission['hidden'] || $permissionGroup['hidden'])
-				{
-					echo '
-							<tr style="display: none;">
-								<td>';
-
-					if ($permission['has_own_any'])
-					{
-						// Guests can't have own permissions.
-						if ($context['group']['id'] != -1)
-							echo '
-									<input type="hidden" name="perm[', $permission_type['id'], '][', $permission['own']['id'], ']" value="', $permission['own']['select'] == 'denied' && !empty($modSettings['permission_enable_deny']) ? 'deny' : $permission['own']['select'], '">';
-
-						echo '
-									<input type="hidden" name="perm[', $permission_type['id'], '][', $permission['any']['id'], ']" value="', $permission['any']['select'] == 'denied' && !empty($modSettings['permission_enable_deny']) ? 'deny' : $permission['any']['select'], '">';
-					}
-					else
-						echo '
-									<input type="hidden" name="perm[', $permission_type['id'], '][', $permission['id'], ']" value="', $permission['select'] == 'denied' && !empty($modSettings['permission_enable_deny']) ? 'deny' : $permission['select'], '">';
-					echo '
-								</td>
-							</tr>';
-				}
-				else
+				if (!$permission['hidden'] && !$permissionGroup['hidden'])
 				{
 					echo '
-							<tr class="', $alternate ? 'windowbg' : 'windowbg2', '">
+							<tr>
 								<td width="10">
 									', $permission['show_help'] ? '<a href="' . $scripturl . '?action=helpadmin;help=permissionhelp_' . $permission['id'] . '" onclick="return reqOverlayDiv(this.href);" class="help"><img src="' . $settings['images_url'] . '/helptopics.png" alt="' . $txt['help'] . '"></a>' : '', '
-								</td>';
+								</td>
+								<td class="lefttext full_width">', $permission['name'], '</td><td>';
 
 					if ($permission['has_own_any'])
 					{
-						echo '
-								<td colspan="4" width="100%" align="left">', $permission['name'], '</td>
-							</tr><tr class="', $alternate ? 'windowbg' : 'windowbg2', '">';
-
 						// Guests can't do their own thing.
 						if ($context['group']['id'] != -1)
 						{
-							echo '
-								<td></td>
-								<td width="100%" class="smalltext" align="right">', $permission['own']['name'], ':</td>';
-
 							if (empty($modSettings['permission_enable_deny']))
 								echo '
-								<td colspan="3"><input type="checkbox" name="perm[', $permission_type['id'], '][', $permission['own']['id'], ']"', $permission['own']['select'] == 'on' ? ' checked' : '', ' value="on" id="', $permission['own']['id'], '_on" class="input_check" ', $disable_field, '/></td>';
+									<input type="checkbox" name="perm[', $permission_type['id'], '][', $permission['own']['id'], ']"', $permission['own']['select'] == 'on' ? ' checked="checked"' : '', ' value="on" id="', $permission['own']['id'], '_on" class="input_check" ', $disable_field, '/>';
 							else
+							{
 								echo '
-								<td width="10"><input type="radio" name="perm[', $permission_type['id'], '][', $permission['own']['id'], ']"', $permission['own']['select'] == 'on' ? ' checked' : '', ' value="on" id="', $permission['own']['id'], '_on" class="input_radio" ', $disable_field, '/></td>
-								<td width="10"><input type="radio" name="perm[', $permission_type['id'], '][', $permission['own']['id'], ']"', $permission['own']['select'] == 'off' ? ' checked' : '', ' value="off" class="input_radio" ', $disable_field, '/></td>
-								<td width="10"><input type="radio" name="perm[', $permission_type['id'], '][', $permission['own']['id'], ']"', $permission['own']['select'] == 'denied' ? ' checked' : '', ' value="deny" class="input_radio" ', $disable_field, '/></td>';
+									<select name="perm[', $permission_type['id'], '][', $permission['own']['id'], ']" ', $disable_field, '>';
 
+								foreach (array('on', 'off', 'deny') as $c)
+									echo '
+										<option ', $permission['own']['select'] == $c ? ' selected' : '', ' value="', $c, '">', $txt['permissions_option_' . $c], '</option>';
 							echo '
-							</tr><tr class="', $alternate ? 'windowbg' : 'windowbg2', '">';
-						}
+									</select>';
+							}
 
 						echo '
-								<td></td>
-								<td width="100%" class="smalltext" align="right">', $permission['any']['name'], ':</td>';
+								</td>
+								<td>';
+						}
 
 						if (empty($modSettings['permission_enable_deny']) || $context['group']['id'] == -1)
 							echo '
-								<td colspan="3"><input type="checkbox" name="perm[', $permission_type['id'], '][', $permission['any']['id'], ']"', $permission['any']['select'] == 'on' ? ' checked' : '', ' value="on" class="input_check" ', $disable_field, '/></td>';
+									<input type="checkbox" name="perm[', $permission_type['id'], '][', $permission['any']['id'], ']"', $permission['any']['select'] == 'on' ? ' checked="checked"' : '', ' value="on" class="input_check" ', $disable_field, '/>';
 						else
+						{
 							echo '
-								<td><input type="radio" name="perm[', $permission_type['id'], '][', $permission['any']['id'], ']"', $permission['any']['select'] == 'on' ? ' checked' : '', ' value="on" onclick="document.forms.permissionForm.', $permission['own']['id'], '_on.checked = true;" class="input_radio" ', $disable_field, '/></td>
-								<td><input type="radio" name="perm[', $permission_type['id'], '][', $permission['any']['id'], ']"', $permission['any']['select'] == 'off' ? ' checked' : '', ' value="off" class="input_radio" ', $disable_field, '/></td>
-								<td><input type="radio" name="perm[', $permission_type['id'], '][', $permission['any']['id'], ']"', $permission['any']['select']== 'denied' ? ' checked' : '', ' value="deny" id="', $permission['any']['id'], '_deny" onclick="window.smf_usedDeny = true;" class="input_radio" ', $disable_field, '/></td>';
+									<select name="perm[', $permission_type['id'], '][', $permission['any']['id'], ']" ', $disable_field, '>';
 
-						echo '
-							</tr>';
+							foreach (array('on', 'off', 'deny') as $c)
+								echo '
+										<option ', $permission['any']['select'] == $c ? ' selected' : '', ' value="', $c, '">', $txt['permissions_option_' . $c], '</option>';
+							echo '
+									</select>';
+						}
 					}
 					else
 					{
-						echo '
-								<td width="100%" align="left">', $permission['name'], '</td>';
+						if ($context['group']['id'] != -1)
+							echo '
+								</td>
+								<td>';
 
 						if (empty($modSettings['permission_enable_deny']) || $context['group']['id'] == -1)
 							echo '
-								<td><input type="checkbox" name="perm[', $permission_type['id'], '][', $permission['id'], ']"', $permission['select'] == 'on' ? ' checked' : '', ' value="on" class="input_check" ', $disable_field, '/></td>';
+									<input type="checkbox" name="perm[', $permission_type['id'], '][', $permission['id'], ']"', $permission['select'] == 'on' ? ' checked="checked"' : '', ' value="on" class="input_check" ', $disable_field, '/>';
 						else
+						{
 							echo '
-								<td><input type="radio" name="perm[', $permission_type['id'], '][', $permission['id'], ']"', $permission['select'] == 'on' ? ' checked' : '', ' value="on" class="input_radio" ', $disable_field, '/></td>
-								<td><input type="radio" name="perm[', $permission_type['id'], '][', $permission['id'], ']"', $permission['select'] == 'off' ? ' checked' : '', ' value="off" class="input_radio" ', $disable_field, '/></td>
-								<td><input type="radio" name="perm[', $permission_type['id'], '][', $permission['id'], ']"', $permission['select'] == 'denied' ? ' checked' : '', ' value="deny" onclick="window.smf_usedDeny = true;" class="input_radio" ', $disable_field, '/></td>';
+									<select name="perm[', $permission_type['id'], '][', $permission['id'], ']" ', $disable_field, '>';
 
-						echo '
-							</tr>';
+							foreach (array('on', 'off', 'deny') as $c)
+								echo '
+										<option ', $permission['select'] == $c ? ' selected' : '', ' value="', $c, '">', $txt['permissions_option_' . $c], '</option>';
+							echo '
+									</select>';
+						}
 					}
+					echo '
+								</td>
+							</tr>';
 				}
-				$alternate = !$alternate;
 			}
-
-			if (!$permissionGroup['hidden'] && $has_display_content)
-				echo '
-							<tr class="windowbg2">
-								<td colspan="5" width="100%"><!--separator--></td>
-							</tr>';
 		}
-	echo '
+		echo '
 						</table>';
 	}
+
 	echo '
-				<br class="clear">
+					<br class="clear">
 				</div>
 			</div>';
 }
@@ -770,9 +749,9 @@ function template_inline_permissions()
 
 	echo '
 											</fieldset>
-				
+
 											<a href="javascript:void(0);" onclick="document.getElementById(\'', $context['current_permission'], '\').style.display = \'block\'; document.getElementById(\'', $context['current_permission'], '_groups_link\').style.display = \'none\'; return false;" id="', $context['current_permission'], '_groups_link" style="display: none;">[ ', $txt['avatar_select_permission'], ' ]</a>
-									
+
 											<script><!-- // --><![CDATA[
 												document.getElementById("', $context['current_permission'], '").style.display = "none";
 												document.getElementById("', $context['current_permission'], '_groups_link").style.display = "";
@@ -811,7 +790,7 @@ function template_postmod_permissions()
 			echo '
 							<div class="information">', $txt['permissions_post_moderation_deny_note'], '</div>';
 
-		echo '		
+		echo '
 							<div class="padding">
 								<p class="smalltext" style="padding-left: 10px; padding-bottom: 10px; float: left;">
 									<strong>', $txt['permissions_post_moderation_legend'], ':</strong><br>
@@ -847,13 +826,13 @@ function template_postmod_permissions()
 										<th class="centercol" colspan="3">
 											', $txt['permissions_post_moderation_replies_any'], '
 										</th>';
-						
+
 		if ($modSettings['attachmentEnable'] == 1)
 			echo '
 										<th class="last_th centercol" colspan="3">
 											', $txt['permissions_post_moderation_attachments'], '
 										</th>';
-		
+
 		echo '
 									</tr>
 									<tr>
@@ -896,7 +875,7 @@ function template_postmod_permissions()
 										<td align="center" class="windowbg2"><input type="radio" name="new_topic[', $group['id'], ']" value="allow"', $group['new_topic'] == 'allow' ? ' checked' : '', ' class="input_radio"></td>
 										<td align="center" class="windowbg2"><input type="radio" name="new_topic[', $group['id'], ']" value="moderate"', $group['new_topic'] == 'moderate' ? ' checked' : '', ' class="input_radio"></td>
 										<td align="center" class="windowbg2"><input type="radio" name="new_topic[', $group['id'], ']" value="disallow"', $group['new_topic'] == 'disallow' ? ' checked' : '', ' class="input_radio"></td>';
-			
+
 				// Guests can't have "own" permissions
 				if ($group['id'] == '-1')
 				{
@@ -910,12 +889,12 @@ function template_postmod_permissions()
 										<td align="center" class="windowbg"><input type="radio" name="replies_own[', $group['id'], ']" value="moderate"', $group['replies_own'] == 'moderate' ? ' checked' : '', ' class="input_radio"></td>
 										<td align="center" class="windowbg"><input type="radio" name="replies_own[', $group['id'], ']" value="disallow"', $group['replies_own'] == 'disallow' ? ' checked' : '', ' class="input_radio"></td>';
 				}
-			
+
 				echo '
 										<td align="center" class="windowbg2"><input type="radio" name="replies_any[', $group['id'], ']" value="allow"', $group['replies_any'] == 'allow' ? ' checked' : '', ' class="input_radio"></td>
 										<td align="center" class="windowbg2"><input type="radio" name="replies_any[', $group['id'], ']" value="moderate"', $group['replies_any'] == 'moderate' ? ' checked' : '', ' class="input_radio"></td>
 										<td align="center" class="windowbg2"><input type="radio" name="replies_any[', $group['id'], ']" value="disallow"', $group['replies_any'] == 'disallow' ? ' checked' : '', ' class="input_radio"></td>';
-	
+
 				if ($modSettings['attachmentEnable'] == 1)
 				{
 					echo '
@@ -923,7 +902,7 @@ function template_postmod_permissions()
 										<td align="center" class="windowbg"><input type="radio" name="attachment[', $group['id'], ']" value="moderate"', $group['attachment'] == 'moderate' ? ' checked' : '', ' class="input_radio"></td>
 										<td align="center" class="windowbg"><input type="radio" name="attachment[', $group['id'], ']" value="disallow"', $group['attachment'] == 'disallow' ? ' checked' : '', ' class="input_radio"></td>';
 				}
-		
+
 				echo '
 									</tr>';
 		}

+ 11 - 16
Themes/default/css/admin.css

@@ -435,7 +435,7 @@ div.quick_tasks {
 #support_resources, #credits_sections {
 	margin: 16px 0 -24px 0;
 	border: none;
-	border-top: 1px solid #bbb;	
+	border-top: 1px solid #bbb;
 }
 #credits_logo {
 	position: absolute;
@@ -781,21 +781,6 @@ dl.settings dt.small_caption {
 dl.settings dd.small_caption {
 	width: 79%;
 }
-/* Styles for the manage permissions section.
-------------------------------------------------- */
-#permissionForm .table_grid {
-	width: 100%;
-}
-#permissionForm .table_grid img.icon {
-	vertical-align: top;
-	width: 16px;
-}
-dl.admin_permissions dt {
-	width: 35%;
-}
-dl.admin_permissions dd {
-	width: 64%;
-}
 
 /* Styles for the manage search section.
 ------------------------------------------------- */
@@ -865,6 +850,16 @@ table.table_grid.perm_grid {
 	margin: 0.2em;
 	width: 49%;
 }
+.perm_grid img {
+	vertical-align: middle;
+	width: 16px;
+}
+dl.admin_permissions dt {
+	width: 35%;
+}
+dl.admin_permissions dd {
+	width: 64%;
+}
 .permission_groups {
 	padding: 0;
 	margin: 0;

+ 1 - 1
Themes/default/css/index.css

@@ -2885,7 +2885,7 @@ dl.register_form dd {
 	vertical-align: middle;
 }
 
-tr.windowbg td, tr.windowbg2 td, tr.highlight2 td {
+tr.windowbg td, tr.windowbg2 td, tr.highlight2 td, .table_grid tr td {
 	padding: 4px 8px;
 }
 #credits p {

+ 2 - 0
Themes/default/languages/ManagePermissions.english.php

@@ -84,6 +84,8 @@ $txt['permissions_board_desc'] = '<strong>Note</strong>: changing these board pe
 $txt['permissions_commit'] = 'Save changes';
 $txt['permissions_on'] = 'in profile';
 $txt['permissions_local_for'] = 'Permissions for group';
+$txt['permissions_option_own'] = 'Own';
+$txt['permissions_option_any'] = 'Any';
 $txt['permissions_option_on'] = 'A';
 $txt['permissions_option_off'] = 'X';
 $txt['permissions_option_deny'] = 'D';