Commit d17ed373 authored by Carsten  Rose's avatar Carsten Rose
Browse files

F7112: fabric: configure default color - fixes #7112.

parent 5654038f
Pipeline #1034 passed with stage
in 1 minute and 50 seconds
......@@ -3128,15 +3128,19 @@ Type: editor
Type: annotate
^^^^^^^^^^^^^^
The `Formelement`.type=`annotate` is a simple grafic editor which can be used to annotate images. All modifications to
a image is saved into a JSON fabric.js data string. The current `FormElement` value is the JSON fabric.js data string.
The `Formelement`.type=`annotate` is a simple grafic editor which, for example, can be used to annotate images. All modifications to
an image are saved as a JSON fabric.js data string in the current FormElement column.
An image, specified by `FormElement.parameter`: imageSource={{pathFileName}}, will be displayed in the background. On
form load both, the image and an optional already given JSON fabric.js data string, will be displayed. The original image
file is not modified.
form load, both, the image and an optional already given JSON fabric.js data string, will be displayed. The image is SIP
protected and will be loaded on demand.
The original image file is not modified. The user drawings are stored in the fabric.js data string.
* *FormElement.parameter*:
* *imageSource* ={{pathFileName2}} - Background image.
* *imageSource* ={{pathFileName2}} - Background image. E.g. `fileadmin/images/scan.jpg`.
* *defaultPenColor* = <rgb hex value> - Pen default color, after loading the fabric element. Default is '0000FF' (blue).
By using the the `FormElement` `annotate`, the JS code `fabric.min.js` and `qfq.fabric.min.js` has to be included.
See setup-css-js_.
......
......@@ -637,7 +637,7 @@ abstract class AbstractBuildForm {
// Fill STORE_LDAP
$fe = $this->prepareFillStoreFireLdap($fe);
// for Upload FormElements, it's necessary to precalculate an optional given 'slaveId'.
// for Upload FormElements, it's necessary to pre-calculate an optional given 'slaveId'.
if ($fe[FE_TYPE] === FE_TYPE_UPLOAD) {
Support::setIfNotSet($fe, FE_SLAVE_ID);
$slaveId = Support::falseEmptyToZero($this->evaluate->parse($fe[FE_SLAVE_ID]));
......@@ -3080,11 +3080,13 @@ abstract class AbstractBuildForm {
// $htmlImage = Support::wrapTag('<img ' . $attributeImage . '>', '', false);
// $attributeFabric = Support::doAttribute('id', 'fabric');
$attributeFabric = Support::doAttribute('class', FABRIC_CSS_CLASS);
$attributeFabric .= Support::doAttribute('data-background-image', $this->fileToSipUrl($formElement[FE_IMAGE_SOURCE]));
$attributeFabric .= Support::doAttribute('data-control-name', $formElement[FE_HTML_ID]);
$attributeFabric .= Support::doAttribute('data-buttons', 'typo3conf/ext/qfq/Resources/Public/Json/fabric.buttons.json');
$attributeFabric .= Support::doAttribute('data-emojis', 'typo3conf/ext/qfq/Resources/Public/Json/qfq.emoji.json');
$attributeFabric .= Support::doAttribute('data-fabric-color', HelperFormElement::penColorToHex($formElement));
$attributeFabric .= $this->getAttributeFeMode($formElement[FE_MODE]);
$htmlFabric = Support::wrapTag('<div ' . $attributeFabric . ' >', '', false);
......
......@@ -18,7 +18,7 @@ const QFQ_TEMP_FILE_PATTERN = 'qfq.split.XXXXX';
const QFQ_TEMP_SOURCE = '.temp.source';
const MAX_LENGTH_IPV6 = 45;
const LENGTH_HEX_COLOR = 6; // 'ffeedd'
const SESSION_LIFETIME_SECONDS = 86400;
const SESSION_NAME = 'qfq';
const SESSION_FE_USER_UID = 'feUserUid';
......@@ -1005,6 +1005,7 @@ const FE_IMPORT_TYPE_ODS = 'ods';
const FE_IMPORT_TYPE_CSV = 'csv';
const FE_IMAGE_SOURCE = 'imageSource'; // Image source for a fabric element
const FE_DEFAULT_PEN_COLOR = 'defaultPenColor'; // Default pen color for a fabric element
const FE_SQL_VALIDATE = 'sqlValidate'; // Action: Query to validate form load
const FE_EXPECT_RECORDS = 'expectRecords'; // Action: expected number of rows of FE_SQL_VALIDATE
const FE_MESSAGE_FAIL = 'messageFail'; // Action: Message to display, if FE_SQL_VALIDATE fails.
......
......@@ -419,4 +419,29 @@ EOF;
public static function tgGetMaxLength($maxLength) {
return (empty($maxLength)) ? FE_TEMPLATE_GROUP_DEFAULT_MAX_LENGTH : $maxLength;
}
/**
* Converts a string of '00ff00' and returns a string of '{"red": 0, "green": 255, "blue": 0}'.
*
* @param array $formElement
* @return string
* @throws UserFormException
*/
public static function penColorToHex(array $formElement) {
if (empty($formElement[FE_DEFAULT_PEN_COLOR])) {
return '';
}
if (strlen($formElement[FE_DEFAULT_PEN_COLOR]) != LENGTH_HEX_COLOR) {
throw new UserFormException("Invalid Format for " . FE_DEFAULT_PEN_COLOR .
". Expect like '#ffdd00', got: '" . $formElement[FE_DEFAULT_PEN_COLOR] . "'", ERROR_INVALID_OR_MISSING_PARAMETER);
}
$rgb['red'] = hexdec($formElement[FE_DEFAULT_PEN_COLOR][0] . $formElement[FE_DEFAULT_PEN_COLOR][1]);
$rgb['green'] = hexdec($formElement[FE_DEFAULT_PEN_COLOR][2] . $formElement[FE_DEFAULT_PEN_COLOR][3]);
$rgb['blue'] = hexdec($formElement[FE_DEFAULT_PEN_COLOR][4] . $formElement[FE_DEFAULT_PEN_COLOR][5]);
return json_encode($rgb);
}
}
\ No newline at end of file
......@@ -1362,9 +1362,11 @@ class Support {
static function handleEscapeSpaceComment($str) {
$str = trim($str);
if ($str == '') {
return '';
}
// Skip comments.
if (substr($str, 0, 1) == '#') {
if ($str[0] == '#') {
$str = ''; // It's necessary to create an empty entry - E.g. Form.title will not exist if is a comment, but later processing expects that there is an string.
} else {
switch (substr($str, 0, 2)) {
......
......@@ -189,6 +189,43 @@ class HelperFormElementTest extends TestCase {
$this->assertEquals('10', $result, "Expect Default");
}
public function testPenColorToHex() {
$result = HelperFormElement::penColorToHex([FE_DEFAULT_PEN_COLOR => '']);
$this->assertEquals('', $result, "Expect empty string");
$result = HelperFormElement::penColorToHex([FE_DEFAULT_PEN_COLOR => '000000']);
$this->assertEquals('{"red":0,"green":0,"blue":0}', $result, "Expect black");
$result = HelperFormElement::penColorToHex([FE_DEFAULT_PEN_COLOR => 'ffffff']);
$this->assertEquals('{"red":255,"green":255,"blue":255}', $result, "Expect white");
$result = HelperFormElement::penColorToHex([FE_DEFAULT_PEN_COLOR => '123456']);
$this->assertEquals('{"red":18,"green":52,"blue":86}', $result, "Expect white");
}
/**
* @expectedException \qfq\UserFormException
*
*/
public function testtestPenColorToHexException1() {
// too short
HelperFormElement::penColorToHex([FE_DEFAULT_PEN_COLOR => '12345']);
}
/**
* @expectedException \qfq\UserFormException
*
*/
public function testtestPenColorToHexException2() {
// too long
HelperFormElement::penColorToHex([FE_DEFAULT_PEN_COLOR => '1234567']);
}
// public function testExplodeTemplateGroupElements() {
// $formElements = array();
//
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment