Consistent UX for the single option form
authorAlexander Ebert <ebert@woltlab.com>
Mon, 8 Apr 2019 09:24:01 +0000 (11:24 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 8 Apr 2019 09:24:01 +0000 (11:24 +0200)
wcfsetup/install/files/acp/templates/userGroupAdd.tpl
wcfsetup/install/files/acp/templates/userGroupOption.tpl
wcfsetup/install/files/lib/acp/form/UserGroupOptionForm.class.php

index 94e8fd5e73c242b6914527e6834c7f0350f1996e..41d201d9d250920dc21cd4db81acc2ec00f1196d 100644 (file)
                                        });
                                });
                        {elseif $ownerGroupID}
-                               var input = elBySel('input[name="values[admin.user.accessibleGroups][]"][value="{$ownerGroupID}"]');
+                               var input = elBySel('input[name="values[admin.user.accessibleGroups][]"][value="{@$ownerGroupID}"]');
                                if (input) {
                                        elRemove(input.closest('label'));
                                }
index 3e5f28dc4c4a419af3bb0dfd85b421de527d09fd..e9989a1c997a31f0b5d5960c03977e0a06d59ca3 100644 (file)
                                elHide(bbcodeHtml);
                        });
                });
+               
+               {if $ownerGroupID}
+                       {if $userGroupOption->optionName === 'admin.user.accessibleGroups'}
+                               elBySelAll('dl[data-group-id]', container, function(dl) {
+                                       var groupId = parseInt(elData(dl, 'group-id'), 10);
+                                       console.log("Group", groupId);
+                                       
+                                       elBySelAll('input[name="values[' + groupId + '][]"', undefined, function(input) {
+                                               if (groupId === {@$ownerGroupID}) {
+                                                       var shadow = elCreate('input');
+                                                       shadow.type = 'hidden';
+                                                       shadow.name = input.name;
+                                                       shadow.value = input.value;
+                                                       
+                                                       input.parentNode.appendChild(shadow);
+                                                       
+                                                       input.disabled = true;
+                                               }
+                                               else {
+                                                       if (parseInt(input.value, 10) === {@$ownerGroupID}) {
+                                                               elRemove(input.closest('label'));
+                                                       }
+                                               }
+                                       });
+                               });
+                       {elseif $userGroupOption->optionName|in_array:$ownerGroupPermissions}
+                               elBySelAll('input[name="values[{@$ownerGroupID}]"]', undefined, function (input) {
+                                       if (input.value === '1') {
+                                               input.checked = true;
+                                       }
+                                       else {
+                                               input.disabled = true;
+                                       }
+                               });
+                       {/if}
+               {/if}
        })();
 </script>
 
                
                {foreach from=$groups item=group}
                        <dl data-group-id="{@$group->groupID}">
-                               <dt>{if VISITOR_USE_TINY_BUILD && $guestGroupID == $group->groupID && $userGroupOption->excludedInTinyBuild}<span class="icon icon16 fa-bolt red jsTooltip" title="{lang}wcf.acp.group.excludedInTinyBuild{/lang}"></span> {/if}<label for="userGroupOption{@$group->groupID}">{lang}{$group->groupName}{/lang}</label></dt>
+                               <dt>
+                                       {if VISITOR_USE_TINY_BUILD && $guestGroupID == $group->groupID && $userGroupOption->excludedInTinyBuild}<span class="icon icon16 fa-bolt red jsTooltip" title="{lang}wcf.acp.group.excludedInTinyBuild{/lang}"></span> {/if}
+                                       {if $ownerGroupID == $group->groupID && $userGroupOption->optionName|in_array:$ownerGroupPermissions}<span class="icon icon16 fa-shield jsTooltip" title="{lang}wcf.acp.group.ownerGroupPermission{/lang}"></span> {/if}
+                                       <label for="userGroupOption{@$group->groupID}">{lang}{$group->groupName}{/lang}</label>
+                               </dt>
                                <dd>
                                        {@$formElements[$group->groupID]}
                                        
index 39d0981b27a4b2c8f7fa22fd7f94678177052fe9..c24562e2899dc53f4a87fc78fa74ba3736a47b2e 100644 (file)
@@ -251,7 +251,7 @@ class UserGroupOptionForm extends AbstractForm {
        public function assignVariables() {
                parent::assignVariables();
                
-               $everyoneGroupID = $guestGroupID = $userGroupID = 0;
+               $everyoneGroupID = $guestGroupID = $ownerGroupID = $userGroupID = 0;
                foreach ($this->groups as $group) {
                        if ($group->groupType == UserGroup::EVERYONE) {
                                $everyoneGroupID = $group->groupID;
@@ -259,11 +259,20 @@ class UserGroupOptionForm extends AbstractForm {
                        else if ($group->groupType == UserGroup::GUESTS) {
                                $guestGroupID = $group->groupID;
                        }
+                       else if ($group->groupType == UserGroup::OWNER) {
+                               $ownerGroupID = $group->groupID;
+                       }
                        else if ($group->groupType == UserGroup::USERS) {
                                $userGroupID = $group->groupID;
                        }
                }
                
+               $ownerGroupPermissions = [];
+               if ($ownerGroupID) {
+                       $ownerGroupPermissions = UserGroup::getOwnerPermissions();
+                       $ownerGroupPermissions[] = 'admin.user.accessibleGroups';
+               }
+               
                WCF::getTPL()->assign([
                        'formElements' => $this->formElements,
                        'groups' => $this->groups,
@@ -272,7 +281,9 @@ class UserGroupOptionForm extends AbstractForm {
                        'values' => $this->values,
                        'everyoneGroupID' => $everyoneGroupID,
                        'guestGroupID' => $guestGroupID,
-                       'userGroupID' => $userGroupID
+                       'userGroupID' => $userGroupID,
+                       'ownerGroupID' => $ownerGroupID,
+                       'ownerGroupPermissions' => $ownerGroupPermissions,
                ]);
        }