// 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');
$('#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();
+ }
}
});
$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 {
// 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]);
}
<?php
namespace wcf\data\user\group\option;
use wcf\data\AbstractDatabaseObjectAction;
+use wcf\system\cache\CacheHandler;
use wcf\system\WCF;
/**
/**
* Updates option values for given option id.
*/
- public function updateValue() {
+ public function updateValues() {
$option = current($this->objects);
// remove old values
}
WCF::getDB()->commitTransaction();
}
+
+ // clear cache
+ CacheHandler::getInstance()->clear(WCF_DIR.'cache/', 'cache.groups-*.php');
}
}