Fixes multiple issues with initial ACL options
authorMatthias Schmidt <gravatronics@live.com>
Thu, 8 Aug 2013 10:40:06 +0000 (12:40 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Thu, 8 Aug 2013 10:40:06 +0000 (12:40 +0200)
com.woltlab.wcf/templates/aclPermissionJavaScript.tpl
wcfsetup/install/files/acp/templates/aclPermissionJavaScript.tpl
wcfsetup/install/files/js/WCF.ACL.js

index 8ad5b55c53a1c06cd99cc66f5a5c0c1a445e943a..756e38df73c387884ba06dc325c96266e7d919f4 100644 (file)
@@ -1,3 +1,6 @@
+{if $categoryName|isset && $categoryName|substr:-2 == '.*'}
+       {assign var='__categoryNameStart' value=$categoryName|substr:0:-1}
+{/if}
 <script data-relocate="true">
        //<![CDATA[
        $(function() {
@@ -5,13 +8,17 @@
                        var initialPermissions = { 
                                returnValues: {
                                        options: {
-                                               {implode from=$aclValues[$objectTypeID][options] key='__optionID' item='__optionData'}
-                                                       {@$__optionID}: {
-                                                               categoryName: '{@$__optionData[categoryName]|encodeJS}',
-                                                               label: '{@$__optionData[label]|encodeJS}',
-                                                               optionName: '{@$__optionData[optionName]|encodeJS}'
-                                                       }
-                                               {/implode}
+                                               {foreach from=$aclValues[$objectTypeID][options] key='__optionID' item='__optionData'}
+                                                       {assign var='__optionCategoryName' value=$__optionData[categoryName]}
+                                                       
+                                                       {if !$categoryName|isset || ($__categoryNameStart|isset && $__optionCategoryName|strpos:$__categoryNameStart === 0) || (!$__categoryNameStart|isset && $__optionCategoryName == $categoryName)}
+                                                               {@$__optionID}: {
+                                                                       categoryName: '{@$__optionData[categoryName]|encodeJS}',
+                                                                       label: '{@$__optionData[label]|encodeJS}',
+                                                                       optionName: '{@$__optionData[optionName]|encodeJS}'
+                                                               },
+                                                       {/if}
+                                               {/foreach}
                                        },
                                        categories: {
                                                {implode from=$aclValues[$objectTypeID][categories] key='__category' item='__categoryName'}
                                        user: {
                                                {if $aclValues[$objectTypeID][user]|isset}
                                                        option: {
-                                                               {implode from=$aclValues[$objectTypeID][user][option] key='__userID' item='__optionData'}
-                                                                       {@$__userID}: {
-                                                                               {implode from=$__optionData key='__optionID' item='__optionValue'}
-                                                                                       {@$__optionID}: {@$__optionValue}
-                                                                               {/implode}
-                                                                       }
-                                                               {/implode}
+                                                               {foreach from=$aclValues[$objectTypeID][user][option] key='__userID' item='__optionData'}
+                                                                       {hascontent}
+                                                                               {@$__userID}: {
+                                                                                       {content}
+                                                                                               {foreach from=$__optionData key='__optionID' item='__optionValue'}
+                                                                                                       {assign var='__optionCategoryName' value=$aclValues[$objectTypeID][options][$__optionID][categoryName]}
+                                                                                                       
+                                                                                                       {if !$categoryName|isset || ($__categoryNameStart|isset && $__optionCategoryName|strpos:$__categoryNameStart === 0) || (!$__categoryNameStart|isset && $__optionCategoryName == $categoryName)}
+                                                                                                               {@$__optionID}: {@$__optionValue},
+                                                                                                       {/if}
+                                                                                               {/foreach}
+                                                                                       {/content}
+                                                                               },
+                                                                       {/hascontent}
+                                                               {/foreach}
                                                        },
-                                                       label: {
-                                                               {implode from=$aclValues[$objectTypeID][user][label] key='__userID' item='__label'}
-                                                                       {@$__userID}: '{@$__label|encodeJS}'
-                                                               {/implode}
-                                                       }
+                                                       label: { }
                                                {/if}
                                        },
                                        group: {
                                                {if $aclValues[$objectTypeID][group]|isset}
                                                        option: {
-                                                               {implode from=$aclValues[$objectTypeID][group][option] key='__groupID' item='__optionData'}
-                                                                       {@$__groupID}: {
-                                                                               {implode from=$__optionData key='__optionID' item='__optionValue'}
-                                                                                       {@$__optionID}: {@$__optionValue}
-                                                                               {/implode}
-                                                                       }
-                                                               {/implode}
+                                                               {foreach from=$aclValues[$objectTypeID][group][option] key='__groupID' item='__optionData'}
+                                                                       {hascontent}
+                                                                               {@$__groupID}: {
+                                                                                       {content}
+                                                                                               {foreach from=$__optionData key='__optionID' item='__optionValue'}
+                                                                                                       {assign var='__optionCategoryName' value=$aclValues[$objectTypeID][options][$__optionID][categoryName]}
+                                                                                                       
+                                                                                                       {if !$categoryName|isset || ($__categoryNameStart|isset && $__optionCategoryName|strpos:$__categoryNameStart === 0) || (!$__categoryNameStart|isset && $__optionCategoryName == $categoryName)}
+                                                                                                               {@$__optionID}: {@$__optionValue},
+                                                                                                       {/if}
+                                                                                               {/foreach}
+                                                                                       {/content}
+                                                                               },
+                                                                       {/hascontent}
+                                                               {/foreach}
                                                        },
-                                                       label: {
-                                                               {implode from=$aclValues[$objectTypeID][group][label] key='__groupID' item='__label'}
-                                                                       {@$__groupID}: '{@$__label|encodeJS}'
-                                                               {/implode}
-                                                       }
+                                                       label: { }
                                                {/if}
                                        }
                                }
                        };
+                       
+                       {if $aclValues[$objectTypeID][user]|isset}
+                               {foreach from=$aclValues[$objectTypeID][user][label] key='__userID' item='__label'}
+                                       if (initialPermissions.returnValues.user.option[{@$__userID}]) {
+                                               initialPermissions.returnValues.user.label[{@$__userID}] = '{@$__label|encodeJS}';
+                                       }
+                               {/foreach}
+                       {/if}
+                       
+                       {if $aclValues[$objectTypeID][group]|isset}
+                               {foreach from=$aclValues[$objectTypeID][group][label] key='__groupID' item='__label'}
+                                       if (initialPermissions.returnValues.group.option[{@$__groupID}]) {
+                                               initialPermissions.returnValues.group.label[{@$__groupID}] = '{@$__label|encodeJS}';
+                                       }
+                               {/foreach}
+                       {/if}
                {/if}
                new {if $aclListClassName|isset}{@$aclListClassName}{else}WCF.ACL.List{/if}($('#{@$containerID}'), {@$objectTypeID}, {if $categoryName|isset}'{@$categoryName}'{else}null{/if}, {if $objectID|isset}{@$objectID}{else}0{/if}, {if !$includeUserGroups|isset || $includeUserGroups}true{else}false{/if}{if $aclValues[$objectTypeID]|isset}, initialPermissions{/if});
        });
        //]]>
-</script>
\ No newline at end of file
+</script>
index 8ad5b55c53a1c06cd99cc66f5a5c0c1a445e943a..756e38df73c387884ba06dc325c96266e7d919f4 100644 (file)
@@ -1,3 +1,6 @@
+{if $categoryName|isset && $categoryName|substr:-2 == '.*'}
+       {assign var='__categoryNameStart' value=$categoryName|substr:0:-1}
+{/if}
 <script data-relocate="true">
        //<![CDATA[
        $(function() {
@@ -5,13 +8,17 @@
                        var initialPermissions = { 
                                returnValues: {
                                        options: {
-                                               {implode from=$aclValues[$objectTypeID][options] key='__optionID' item='__optionData'}
-                                                       {@$__optionID}: {
-                                                               categoryName: '{@$__optionData[categoryName]|encodeJS}',
-                                                               label: '{@$__optionData[label]|encodeJS}',
-                                                               optionName: '{@$__optionData[optionName]|encodeJS}'
-                                                       }
-                                               {/implode}
+                                               {foreach from=$aclValues[$objectTypeID][options] key='__optionID' item='__optionData'}
+                                                       {assign var='__optionCategoryName' value=$__optionData[categoryName]}
+                                                       
+                                                       {if !$categoryName|isset || ($__categoryNameStart|isset && $__optionCategoryName|strpos:$__categoryNameStart === 0) || (!$__categoryNameStart|isset && $__optionCategoryName == $categoryName)}
+                                                               {@$__optionID}: {
+                                                                       categoryName: '{@$__optionData[categoryName]|encodeJS}',
+                                                                       label: '{@$__optionData[label]|encodeJS}',
+                                                                       optionName: '{@$__optionData[optionName]|encodeJS}'
+                                                               },
+                                                       {/if}
+                                               {/foreach}
                                        },
                                        categories: {
                                                {implode from=$aclValues[$objectTypeID][categories] key='__category' item='__categoryName'}
                                        user: {
                                                {if $aclValues[$objectTypeID][user]|isset}
                                                        option: {
-                                                               {implode from=$aclValues[$objectTypeID][user][option] key='__userID' item='__optionData'}
-                                                                       {@$__userID}: {
-                                                                               {implode from=$__optionData key='__optionID' item='__optionValue'}
-                                                                                       {@$__optionID}: {@$__optionValue}
-                                                                               {/implode}
-                                                                       }
-                                                               {/implode}
+                                                               {foreach from=$aclValues[$objectTypeID][user][option] key='__userID' item='__optionData'}
+                                                                       {hascontent}
+                                                                               {@$__userID}: {
+                                                                                       {content}
+                                                                                               {foreach from=$__optionData key='__optionID' item='__optionValue'}
+                                                                                                       {assign var='__optionCategoryName' value=$aclValues[$objectTypeID][options][$__optionID][categoryName]}
+                                                                                                       
+                                                                                                       {if !$categoryName|isset || ($__categoryNameStart|isset && $__optionCategoryName|strpos:$__categoryNameStart === 0) || (!$__categoryNameStart|isset && $__optionCategoryName == $categoryName)}
+                                                                                                               {@$__optionID}: {@$__optionValue},
+                                                                                                       {/if}
+                                                                                               {/foreach}
+                                                                                       {/content}
+                                                                               },
+                                                                       {/hascontent}
+                                                               {/foreach}
                                                        },
-                                                       label: {
-                                                               {implode from=$aclValues[$objectTypeID][user][label] key='__userID' item='__label'}
-                                                                       {@$__userID}: '{@$__label|encodeJS}'
-                                                               {/implode}
-                                                       }
+                                                       label: { }
                                                {/if}
                                        },
                                        group: {
                                                {if $aclValues[$objectTypeID][group]|isset}
                                                        option: {
-                                                               {implode from=$aclValues[$objectTypeID][group][option] key='__groupID' item='__optionData'}
-                                                                       {@$__groupID}: {
-                                                                               {implode from=$__optionData key='__optionID' item='__optionValue'}
-                                                                                       {@$__optionID}: {@$__optionValue}
-                                                                               {/implode}
-                                                                       }
-                                                               {/implode}
+                                                               {foreach from=$aclValues[$objectTypeID][group][option] key='__groupID' item='__optionData'}
+                                                                       {hascontent}
+                                                                               {@$__groupID}: {
+                                                                                       {content}
+                                                                                               {foreach from=$__optionData key='__optionID' item='__optionValue'}
+                                                                                                       {assign var='__optionCategoryName' value=$aclValues[$objectTypeID][options][$__optionID][categoryName]}
+                                                                                                       
+                                                                                                       {if !$categoryName|isset || ($__categoryNameStart|isset && $__optionCategoryName|strpos:$__categoryNameStart === 0) || (!$__categoryNameStart|isset && $__optionCategoryName == $categoryName)}
+                                                                                                               {@$__optionID}: {@$__optionValue},
+                                                                                                       {/if}
+                                                                                               {/foreach}
+                                                                                       {/content}
+                                                                               },
+                                                                       {/hascontent}
+                                                               {/foreach}
                                                        },
-                                                       label: {
-                                                               {implode from=$aclValues[$objectTypeID][group][label] key='__groupID' item='__label'}
-                                                                       {@$__groupID}: '{@$__label|encodeJS}'
-                                                               {/implode}
-                                                       }
+                                                       label: { }
                                                {/if}
                                        }
                                }
                        };
+                       
+                       {if $aclValues[$objectTypeID][user]|isset}
+                               {foreach from=$aclValues[$objectTypeID][user][label] key='__userID' item='__label'}
+                                       if (initialPermissions.returnValues.user.option[{@$__userID}]) {
+                                               initialPermissions.returnValues.user.label[{@$__userID}] = '{@$__label|encodeJS}';
+                                       }
+                               {/foreach}
+                       {/if}
+                       
+                       {if $aclValues[$objectTypeID][group]|isset}
+                               {foreach from=$aclValues[$objectTypeID][group][label] key='__groupID' item='__label'}
+                                       if (initialPermissions.returnValues.group.option[{@$__groupID}]) {
+                                               initialPermissions.returnValues.group.label[{@$__groupID}] = '{@$__label|encodeJS}';
+                                       }
+                               {/foreach}
+                       {/if}
                {/if}
                new {if $aclListClassName|isset}{@$aclListClassName}{else}WCF.ACL.List{/if}($('#{@$containerID}'), {@$objectTypeID}, {if $categoryName|isset}'{@$categoryName}'{else}null{/if}, {if $objectID|isset}{@$objectID}{else}0{/if}, {if !$includeUserGroups|isset || $includeUserGroups}true{else}false{/if}{if $aclValues[$objectTypeID]|isset}, initialPermissions{/if});
        });
        //]]>
-</script>
\ No newline at end of file
+</script>
index fc6d89d4f7bfa4b98a43d771cb6dba9abf1935ba..ece0440a7946a8a1b3be9d86fc3061b5f3a545d5 100644 (file)
@@ -1,7 +1,7 @@
 /**
  * Namespace for ACL
  */
-WCF.ACL = {};
+WCF.ACL = { };
 
 /**
  * ACL support for WCF
@@ -84,6 +84,10 @@ WCF.ACL.List = Class.extend({
                if (includeUserGroups === undefined) {
                        includeUserGroups = true;
                }
+               this._values = {
+                       group: { },
+                       user: { }
+               };
                
                this._proxy = new WCF.Action.Proxy({
                        showLoadingOverlay: false,
@@ -422,13 +426,13 @@ WCF.ACL.List = Class.extend({
                });
                if ($type == 'deny') {
                        if (this._containerElements.denyAll !== null) {
-                               if ($allChecked) this._containerElements.denyAll.prop('checked', true)
+                               if ($allChecked) this._containerElements.denyAll.prop('checked', true);
                                else this._containerElements.denyAll.prop('checked', false);
                        }
                }
                else {
                        if (this._containerElements.grantAll !== null) {
-                               if ($allChecked) this._containerElements.grantAll.prop('checked', true)
+                               if ($allChecked) this._containerElements.grantAll.prop('checked', true);
                                else this._containerElements.grantAll.prop('checked', false);
                        }
                }
@@ -525,9 +529,16 @@ WCF.ACL.List = Class.extend({
        _savePermissions: function() {
                // get active object
                var $activeObject = this._containerElements.aclList.find('li.active');
+               if (!$activeObject.length) {
+                       return;
+               }
+               
                var $objectID = $activeObject.data('objectID');
                var $type = $activeObject.data('type');
                
+               // clear old values
+               this._values[$type][$objectID] = { };
+               
                var self = this;
                this._containerElements.permissionList.find("input[type='checkbox']").each(function(index, checkbox) {
                        var $checkbox = $(checkbox);
@@ -536,10 +547,6 @@ WCF.ACL.List = Class.extend({
                                var $optionID = $checkbox.data('optionID');
                                
                                if ($checkbox.is(':checked')) {
-                                       if (!self._values[$type][$objectID]) {
-                                               self._values[$type][$objectID] = { };
-                                       }
-                                       
                                        // store value
                                        self._values[$type][$objectID][$optionID] = $optionValue;