{include file='aclPermissions'}
{/if}
-{include file='aclPermissionJavaScript' containerID=$field->getPrefixedId()|concat:'Container' categoryName=$field->getCategoryName() objectID=$field->getObjectID() objectTypeID=$field->getObjectType()->objectTypeID}
+{include file='aclPermissionJavaScript' containerID=$field->getPrefixedId()|concat:'Container' categoryName=$field->getCategoryName() objectID=$field->getObjectID() objectTypeID=$field->getObjectType()->objectTypeID aclFormBuilderMode=true}
{/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});
+
+ var aclList = 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});
+
+ {if !$aclFormBuilderMode|empty}
+ require(['WoltLabSuite/Core/Form/Builder/Manager'], function(FormBuilderManager) {
+ FormBuilderManager.getField(
+ '{@$field->getDocument()->getId()}',
+ '{@$field->getPrefixedId()}'
+ ).setAclList(aclList);
+ });
+ {/if}
});
</script>
{include file='aclPermissions'}
{/if}
-{include file='aclPermissionJavaScript' containerID=$field->getPrefixedId()|concat:'Container' categoryName=$field->getCategoryName() objectID=$field->getObjectID() objectTypeID=$field->getObjectType()->objectTypeID}
+{include file='aclPermissionJavaScript' containerID=$field->getPrefixedId()|concat:'Container' categoryName=$field->getCategoryName() objectID=$field->getObjectID() objectTypeID=$field->getObjectType()->objectTypeID aclFormBuilderMode=true}
{/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});
+
+ var aclList = 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});
+
+ {if !$aclFormBuilderMode|empty}
+ require(['WoltLabSuite/Core/Form/Builder/Manager'], function(FormBuilderManager) {
+ FormBuilderManager.getField(
+ '{@$field->getDocument()->getId()}',
+ '{@$field->getPrefixedId()}'
+ ).setAclList(aclList);
+ });
+ {/if}
});
</script>
* ACL support for WCF
*
* @author Alexander Ebert
- * @copyright 2001-2019 WoltLab GmbH
+ * @copyright 2001-2020 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
*/
WCF.ACL.List = Class.extend({
}
}
}
+ },
+
+ /**
+ * Returns the ACL data stored for this list.
+ *
+ * @return object
+ * @since 5.2.3
+ */
+ getData: function() {
+ this._savePermissions();
+
+ return this._values;
}
});
}
--- /dev/null
+/**
+ * Data handler for a acl form builder field in an Ajax form.
+ *
+ * @author Matthias Schmidt
+ * @copyright 2001-2020 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module WoltLabSuite/Core/Form/Builder/Field/Acl
+ * @since 5.2.3
+ */
+define(['Core', './Field'], function(Core, FormBuilderField) {
+ "use strict";
+
+ /**
+ * @constructor
+ */
+ function FormBuilderFieldAcl(fieldId) {
+ this.init(fieldId);
+
+ this._aclList = null;
+ };
+ Core.inherit(FormBuilderFieldAcl, FormBuilderField, {
+ /**
+ * @see WoltLabSuite/Core/Form/Builder/Field/Field#_getData
+ */
+ _getData: function() {
+ var data = {};
+
+ data[this._fieldId] = this._aclList.getData();
+
+ return data;
+ },
+
+ /**
+ * @see WoltLabSuite/Core/Form/Builder/Field/Field#_readField
+ */
+ _readField: function() {
+ // does nothing
+ },
+
+ /**
+ * Sets the ACL list object used to extract the ACL values.
+ *
+ * @param {WCF.ACL.List} aclList
+ */
+ setAclList: function(aclList) {
+ this._aclList = aclList;
+ }
+ });
+
+ return FormBuilderFieldAcl;
+});
* of the registered forms.
*
* @author Matthias Schmidt
- * @copyright 2001-2019 WoltLab GmbH
+ * @copyright 2001-2020 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @module WoltLabSuite/Core/Form/Builder/Manager
* @since 5.2
});
},
+ /**
+ * Returns the registered form field with given id.
+ *
+ * @param {string} formId
+ * @return {WoltLabSuite/Core/Form/Builder/Field/Field}
+ * @since 5.2.3
+ */
+ getField: function(formId, fieldId) {
+ if (!this.hasField(formId, fieldId)) {
+ throw new Error("Unknown field with id '" + formId + "' for form with id '" + fieldId + "'.");
+ }
+
+ return _fields.get(formId).get(fieldId);
+ },
+
/**
* Returns the registered form with given id.
*
* using form builder, you do not need this method.
*
* @param integer $objectTypeID
+ * @param array|null $valuesSource array used to read the values from (if `null`, `$_POST['aclValues']` is used)
* @since 5.2
*/
- public function readValues($objectTypeID) {
+ public function readValues($objectTypeID, array $valuesSource = null) {
$this->__readValues[$objectTypeID] = [];
- if (isset($_POST['aclValues'])) {
+ if ($valuesSource === null && isset($_POST['aclValues'])) {
+ $valuesSource = $_POST['aclValues'];
+ }
+
+ if (isset($valuesSource)) {
$options = ACLOption::getOptions($objectTypeID)->getObjects();
foreach (['group', 'user'] as $type) {
- if (isset($_POST['aclValues'][$type])) {
+ if (isset($valuesSource[$type])) {
$this->__readValues[$objectTypeID][$type] = [];
- foreach ($_POST['aclValues'][$type] as $typeID => $optionData) {
+ foreach ($valuesSource[$type] as $typeID => $optionData) {
$this->__readValues[$objectTypeID][$type][$typeID] = [];
foreach ($optionData as $optionID => $optionValue) {
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditions->getParameters());
+ $objectTypeID = reset($options)->objectTypeID;
+
// add new values if given
- if (!isset($_POST['aclValues']) || !isset($_POST['aclValues'][$type])) {
- return;
+ $values = [];
+ if (isset($this->__readValues[$objectTypeID]) && isset($this->__readValues[$objectTypeID][$type])) {
+ $values = $this->__readValues[$objectTypeID][$type];
+ }
+ else if (isset($_POST['aclValues']) && isset($_POST['aclValues'][$type])) {
+ $values = $_POST['aclValues'][$type];
}
$sql = "INSERT INTO wcf".WCF_N."_acl_option_to_".$type."
(optionID, objectID, ".$type."ID, optionValue)
VALUES (?, ?, ?, ?)";
$statement = WCF::getDB()->prepareStatement($sql);
- $values =& $_POST['aclValues'][$type];
WCF::getDB()->beginTransaction();
foreach ($values as $typeID => $optionData) {
* Implementation of a form field for setting acl option values.
*
* @author Matthias Schmidt
- * @copyright 2001-2019 WoltLab GmbH
+ * @copyright 2001-2020 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package WoltLabSuite\Core\System\Form\Builder\Field\Acl
* @since 5.2
*/
protected $categoryName;
+ /**
+ * @inheritDoc
+ * @since 5.2.3
+ */
+ protected $javaScriptDataHandlerModule = 'WoltLabSuite/Core/Form/Builder/Field/Acl';
+
/**
* id of the edited object or `null` if no object is edited
* @var null|int
* @inheritDoc
*/
public function readValue() {
- ACLHandler::getInstance()->readValues($this->getObjectType()->objectTypeID);
+ $valueSource = $_POST;
+ if ($this->getDocument()->isAjax()) {
+ $valueSource = [];
+ if (
+ $this->getDocument()->hasRequestData($this->getPrefixedId())
+ && is_array($this->getDocument()->getRequestData($this->getPrefixedId()))
+ ) {
+ $valueSource = $this->getDocument()->getRequestData($this->getPrefixedId());
+ }
+ }
+
+ ACLHandler::getInstance()->readValues($this->getObjectType()->objectTypeID, $valueSource);
return $this;
}