Signed-off-by: Elizabeth Danzberger <lizzy7128@tutanota.de>pull/47290/head
parent
95fff6bc72
commit
79d005e11f
@ -0,0 +1,68 @@ |
||||
<!-- |
||||
- SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors |
||||
- SPDX-License-Identifier: AGPL-3.0-or-later |
||||
--> |
||||
|
||||
<template> |
||||
<div class="template-field__checkbox"> |
||||
<NcCheckboxRadioSwitch :id="fieldId" |
||||
:checked.sync="value" |
||||
type="switch" |
||||
@update:checked="input"> |
||||
{{ fieldLabel }} |
||||
</NcCheckboxRadioSwitch> |
||||
</div> |
||||
</template> |
||||
|
||||
<script lang="ts"> |
||||
import { defineComponent } from 'vue' |
||||
import { NcCheckboxRadioSwitch } from '@nextcloud/vue' |
||||
|
||||
export default defineComponent({ |
||||
name: 'TemplateCheckboxField', |
||||
|
||||
components: { |
||||
NcCheckboxRadioSwitch, |
||||
}, |
||||
|
||||
props: { |
||||
field: { |
||||
type: Object, |
||||
default: () => {}, |
||||
}, |
||||
}, |
||||
|
||||
data() { |
||||
return { |
||||
value: this.field.checked ?? false, |
||||
} |
||||
}, |
||||
|
||||
computed: { |
||||
fieldLabel() { |
||||
const label = this.field.name ?? this.field.alias ?? 'Unknown field' |
||||
|
||||
return label.charAt(0).toUpperCase() + label.slice(1) |
||||
}, |
||||
fieldId() { |
||||
return 'checkbox-field' + this.field.index |
||||
}, |
||||
}, |
||||
|
||||
methods: { |
||||
input() { |
||||
this.$emit('input', { |
||||
index: this.field.index, |
||||
property: 'checked', |
||||
value: this.value, |
||||
}) |
||||
}, |
||||
}, |
||||
}) |
||||
</script> |
||||
|
||||
<style lang="scss" scoped> |
||||
.template-field__checkbox { |
||||
margin: 20px 0; |
||||
} |
||||
</style> |
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1 @@ |
||||
5159-5159.js.license |
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@ |
||||
6113-6113.js.license |
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,32 @@ |
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
/** |
||||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors |
||||
* SPDX-License-Identifier: AGPL-3.0-or-later |
||||
*/ |
||||
|
||||
namespace OCP\Files\Template; |
||||
|
||||
use OCP\Files\Template\Fields\CheckBoxField; |
||||
use OCP\Files\Template\Fields\RichTextField; |
||||
|
||||
/** |
||||
* @since 30.0.0 |
||||
*/ |
||||
class FieldFactory { |
||||
/** |
||||
* @since 30.0.0 |
||||
*/ |
||||
public static function createField( |
||||
string $index, |
||||
FieldType $type |
||||
): Field { |
||||
return match ($type) { |
||||
FieldType::RichText => new RichTextField($index, $type), |
||||
FieldType::CheckBox => new CheckBoxField($index, $type), |
||||
default => throw new InvalidFieldTypeException(), |
||||
}; |
||||
} |
||||
} |
||||
@ -0,0 +1,47 @@ |
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
/** |
||||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors |
||||
* SPDX-License-Identifier: AGPL-3.0-or-later |
||||
*/ |
||||
|
||||
namespace OCP\Files\Template\Fields; |
||||
|
||||
use OCP\Files\Template\Field; |
||||
use OCP\Files\Template\FieldType; |
||||
|
||||
/** |
||||
* @since 30.0.0 |
||||
*/ |
||||
class CheckBoxField extends Field { |
||||
private bool $checked = false; |
||||
|
||||
/** |
||||
* @since 30.0.0 |
||||
*/ |
||||
public function __construct(string $index, FieldType $type) { |
||||
parent::__construct($index, $type); |
||||
} |
||||
|
||||
/** |
||||
* @since 30.0.0 |
||||
*/ |
||||
public function setValue(mixed $value): void { |
||||
if (!is_bool($value)) { |
||||
throw new \Exception('Invalid value for checkbox field type'); |
||||
} |
||||
|
||||
$this->checked = $value; |
||||
} |
||||
|
||||
/** |
||||
* @since 30.0.0 |
||||
*/ |
||||
public function jsonSerialize(): array { |
||||
$jsonProperties = parent::jsonSerialize(); |
||||
|
||||
return array_merge($jsonProperties, ['checked' => $this->checked]); |
||||
} |
||||
} |
||||
@ -0,0 +1,47 @@ |
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
/** |
||||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors |
||||
* SPDX-License-Identifier: AGPL-3.0-or-later |
||||
*/ |
||||
|
||||
namespace OCP\Files\Template\Fields; |
||||
|
||||
use OCP\Files\Template\Field; |
||||
use OCP\Files\Template\FieldType; |
||||
|
||||
/** |
||||
* @since 30.0.0 |
||||
*/ |
||||
class RichTextField extends Field { |
||||
private string $content = ''; |
||||
|
||||
/** |
||||
* @since 30.0.0 |
||||
*/ |
||||
public function __construct(string $index, FieldType $type) { |
||||
parent::__construct($index, $type); |
||||
} |
||||
|
||||
/** |
||||
* @since 30.0.0 |
||||
*/ |
||||
public function setValue(mixed $value): void { |
||||
if (!is_string($value)) { |
||||
throw new \Exception('Invalid value for rich-text field type'); |
||||
} |
||||
|
||||
$this->content = $value; |
||||
} |
||||
|
||||
/** |
||||
* @since 30.0.0 |
||||
*/ |
||||
public function jsonSerialize(): array { |
||||
$jsonProperties = parent::jsonSerialize(); |
||||
|
||||
return array_merge($jsonProperties, ['content' => $this->content]); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue