Fixed a few bugs if editing a single group option
authorAlexander Ebert <ebert@woltlab.com>
Tue, 21 Aug 2012 18:00:57 +0000 (20:00 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 21 Aug 2012 18:00:57 +0000 (20:00 +0200)
wcfsetup/install/files/acp/js/WCF.ACP.js
wcfsetup/install/files/lib/acp/form/UserGroupOptionForm.class.php
wcfsetup/install/files/lib/data/user/group/option/UserGroupOptionAction.class.php

index 3256d72c536b142099908a8f81aa590e8efc25b6..ddf4d01011d1cf0137fbbaf20f8824cb7b08d17d 100644 (file)
@@ -703,14 +703,22 @@ WCF.ACP.Options.Group = Class.extend({
                // collect default value
                if (this._canEditEveryone) {
                        var $container = $('#defaultValueContainer > dl');
-                       $values[$container.data('groupID')] = $container.find('textarea, input').val();
+                       
+                       var $value = this._getValue($container);
+                       if ($value !== null) {
+                               $values[$container.data('groupID')] = $value;
+                       }
                }
                
                // collect values from other groups
+               var self = this;
                $('#otherValueContainer > dl').each(function(index, container) {
                        var $container = $(container);
                        
-                       $values[$container.data('groupID')] = $container.find('textarea, input').val();
+                       var $value = self._getValue($container);
+                       if ($value !== null) {
+                               $values[$container.data('groupID')] = $value;
+                       }
                });
                
                var $form = $('#defaultValueContainer').parent('form');
@@ -723,6 +731,35 @@ WCF.ACP.Options.Group = Class.extend({
                $('#submitButton').attr('disable', 'disable');
                
                $form.submit();
+       },
+       
+       /**
+        * Returns the value of an input or textarea.
+        * 
+        * @param       jQuery          container
+        * @return      string
+        */
+       _getValue: function(container) {
+               var $textarea = container.find('textarea');
+               if ($textarea.length) {
+                       return $textarea.val();
+               }
+               else {
+                       var $input = container.find('input');
+                       if (!$input.length) {
+                               return null;
+                       }
+                       
+                       if ($input.attr('type') == 'checkbox') {
+                               if ($input.is(':checked')) {
+                                       return $input.val();
+                               }
+                               
+                               return null;
+                       }
+                       
+                       return $input.val();
+               }
        }
 });
 
index 86afe0035a8f3ebf6f1d4ed2c9b718665885e5ee..890cd96d6565575f157b21c547fe0d4861b09804 100644 (file)
@@ -171,19 +171,26 @@ class UserGroupOptionForm extends ACPForm {
                                $this->groupEveryone->groupID
                        ));
                        $row = $statement->fetchArray();
-                       $defaultValue = $row['optionValue'];
+                       $this->defaultValue = $row['optionValue'];
                }
                else {
                        if (!isset($this->values[$this->groupEveryone->groupID])) {
                                throw new IllegalLinkException();
                        }
                        
-                       $defaultValue = $this->values[$this->groupEveryone->groupID];
+                       $this->defaultValue = $this->values[$this->groupEveryone->groupID];
                }
                
                foreach ($this->values as $groupID => $optionValue) {
-                       if (!isset($this->groups[$groupID]) || (!$this->canEditEveryone && $groupID == $this->groupEveryone->groupID)) {
-                               throw new PermissionDeniedException();
+                       if (!isset($this->groups[$groupID])) {
+                               if ($groupID == $this->groupEveryone->groupID) {
+                                       if (!$this->canEditEveryone) {
+                                               throw new PermissionDeniedException();
+                                       }
+                               }
+                               else {
+                                       throw new PermissionDeniedException();
+                               }
                        }
                        
                        try {
@@ -195,7 +202,7 @@ class UserGroupOptionForm extends ACPForm {
                        
                        // check if not editing default value
                        if ($groupID != $this->groupEveryone->groupID) {
-                               $newValue = $this->optionType->merge($defaultValue, $optionValue);
+                               $newValue = $this->optionType->merge($this->defaultValue, $optionValue);
                                if ($newValue === null) {
                                        unset($this->values[$groupID]);
                                }
index 00f729de0c72c5417f71e500aa3ecd9818c35719..2a91145d72a89b33217e5910301cfdbd89ab1f5e 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 namespace wcf\data\user\group\option;
 use wcf\data\AbstractDatabaseObjectAction;
+use wcf\system\cache\CacheHandler;
 use wcf\system\WCF;
 
 /**
@@ -22,7 +23,7 @@ class UserGroupOptionAction extends AbstractDatabaseObjectAction {
        /**
         * Updates option values for given option id.
         */
-       public function updateValue() {
+       public function updateValues() {
                $option = current($this->objects);
                
                // remove old values
@@ -49,5 +50,8 @@ class UserGroupOptionAction extends AbstractDatabaseObjectAction {
                        }
                        WCF::getDB()->commitTransaction();
                }
+               
+               // clear cache
+               CacheHandler::getInstance()->clear(WCF_DIR.'cache/', 'cache.groups-*.php');
        }
 }