Skip to content

Commit

Permalink
drag and dropp intial commit
Browse files Browse the repository at this point in the history
removed commented code

test case for drag and drop added
  • Loading branch information
rajatkhurana-adobe committed Oct 20, 2023
1 parent 069b503 commit 6f2ba76
Show file tree
Hide file tree
Showing 22 changed files with 1,225 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ private FormConstants() {
/** The resource type for file input v1 */
public static final String RT_FD_FORM_FILE_INPUT_V1 = RT_FD_FORM_PREFIX + "fileinput/v1/fileinput";

/** The resource type for file input v2 */
public static final String RT_FD_FORM_FILE_INPUT_V2 = RT_FD_FORM_PREFIX + "fileinput/v2/fileinput";

/** The resource type for check box group v1 */
public static final String RT_FD_FORM_CHECKBOX_GROUP_V1 = RT_FD_FORM_PREFIX + "checkboxgroup/v1/checkboxgroup";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.apache.sling.api.SlingHttpServletRequest;
Expand All @@ -27,6 +28,7 @@
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy;
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;
import org.jetbrains.annotations.NotNull;

import com.adobe.cq.export.json.ComponentExporter;
import com.adobe.cq.export.json.ExporterConstants;
Expand All @@ -38,14 +40,19 @@
adaptables = { SlingHttpServletRequest.class, Resource.class },
adapters = { FileInput.class,
ComponentExporter.class },
resourceType = { FormConstants.RT_FD_FORM_FILE_INPUT_V1 })
resourceType = { FormConstants.RT_FD_FORM_FILE_INPUT_V2 })
@Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION)
public class FileInputImpl extends AbstractFieldImpl implements FileInput {

private static final String FILE_INPUT_DRAG_DROP_TEXT = "fileInputDragDropText";

@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "multiSelection")
@Default(booleanValues = false)
protected boolean multiSelection;

@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "fileInputDragDropText")
protected String fileInputDragDropText;

@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "maxFileSize")
protected String maxFileSize;

Expand All @@ -56,6 +63,10 @@ public class FileInputImpl extends AbstractFieldImpl implements FileInput {
@Default(values = FileInput.DEFAULT_BUTTON_TEXT)
protected String buttonText;

public String getFileInputDragDropText() {
return fileInputDragDropText;
}

@Override
public Integer getMinItems() {
return minItems;
Expand Down Expand Up @@ -102,4 +113,11 @@ public List<String> getAccept() {
.map(Arrays::asList)
.orElse(Collections.emptyList());
}

@Override
public @NotNull Map<String, Object> getProperties() {
Map<String, Object> customProperties = super.getProperties();
customProperties.put(FILE_INPUT_DRAG_DROP_TEXT, getFileInputDragDropText());
return customProperties;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
jcr:primaryType="cq:Component"
jcr:title="Adaptive Form File Attachment"
jcr:description="Add a button to upload one or more files as form attachment."
sling:resourceSuperType="core/fd/components/form/fileinput/v1/fileinput"
sling:resourceSuperType="core/fd/components/form/fileinput/v2/fileinput"
componentGroup="Core Components Examples - Adaptive Form"/>
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
jcr:title="File Attachment"
buttonText="Attach"
fieldType="file-input"
fileInputDragDropText="Drag and drop to Upload"
accept="[audio/*, video/*, image/*, text/*, application/pdf]">
</jcr:root>
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
cssProcessor="[default:none,min:none]"
jsProcessor="[default:none,min:none]"
categories="[core.forms.components.runtime.all]"
embed="[core.forms.components.runtime.base,core.forms.components.container.v2.runtime,core.forms.components.datePicker.v1.runtime,core.forms.components.textinput.v1.runtime,core.forms.components.numberinput.v1.runtime,core.forms.components.panelcontainer.v1.runtime,core.forms.components.radiobutton.v1.runtime,core.forms.components.text.v1.runtime,core.forms.components.checkboxgroup.v1.runtime,core.forms.components.button.v1.runtime,core.forms.components.image.v1.runtime,core.forms.components.dropdown.v1.runtime,core.forms.components.fileinput.v1.runtime,core.forms.components.accordion.v1.runtime,core.forms.components.tabs.v1.runtime,core.forms.components.wizard.v1.runtime,core.forms.components.verticaltabs.v1.runtime,core.forms.components.recaptcha.v1.runtime,core.forms.components.checkbox.v1.runtime,core.forms.components.fragment.v1.runtime,core.forms.components.switch.v1.runtime,core.forms.components.termsandconditions.v1.runtime]"/>
embed="[core.forms.components.runtime.base,core.forms.components.container.v2.runtime,core.forms.components.datePicker.v1.runtime,core.forms.components.textinput.v1.runtime,core.forms.components.numberinput.v1.runtime,core.forms.components.panelcontainer.v1.runtime,core.forms.components.radiobutton.v1.runtime,core.forms.components.text.v1.runtime,core.forms.components.checkboxgroup.v1.runtime,core.forms.components.button.v1.runtime,core.forms.components.image.v1.runtime,core.forms.components.dropdown.v1.runtime,core.forms.components.fileinput.v2.runtime,core.forms.components.accordion.v1.runtime,core.forms.components.tabs.v1.runtime,core.forms.components.wizard.v1.runtime,core.forms.components.verticaltabs.v1.runtime,core.forms.components.recaptcha.v1.runtime,core.forms.components.checkbox.v1.runtime,core.forms.components.fragment.v1.runtime,core.forms.components.switch.v1.runtime,core.forms.components.termsandconditions.v1.runtime]"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="nt:unstructured">
<fileinput/>
</jcr:root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
cq:icon="attach"
jcr:primaryType="cq:Component"
jcr:title="Adaptive Form File Attachment (v2)"
jcr:description="Add a button to upload one or more files as form attachment."
sling:resourceSuperType="core/fd/components/form/base/v1/base"
componentGroup=".core-adaptiveform"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<!--
Copyright 2022 Adobe
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
Adaptive Form File Input (v2)
====
Adaptive Form File input field component written in HTL.

## Features

* Drag and drop support
* Custom icon for drag and drop
* Provides the following type of input:
* file
* Custom constraint messages for the above types
* Styles

### Use Object
The Form File component uses the `com.adobe.cq.forms.core.components.models.form.FileInput` Sling Model for its Use-object.

### Edit Dialog Properties
The following properties are written to JCR for this Form File component and are expected to be available as `Resource` properties:

1. `./jcr:title` - defines the label to use for this field
2. `./hideTitle` - if set to `true`, the label of this field will be hidden
3. `./name` - defines the name of the field, which will be submitted with the form data
4. `./default` - defines the default value of the field
5. `./description` - defines a help message that can be rendered in the field as a hint for the user
6. `./required` - if set to `true`, this field will be marked as required, not allowing the form to be submitted until the field has a value
7. `./requiredMessage` - defines the message displayed as tooltip when submitting the form if the value is left empty
8. `./readOnly` - if set to `true`, the filed will be read only
9. `./multiSelection` - if set to `true`, the filed will allow to add multiple files in single selection or multiple selections
10. `./minItems` - if value is selected/provided this will check for minimum number of files that can be attached
11. `./maxItems` - if value is selected/provided this will check for maximum number of files that can be attached
12. `./maxFileSize` - if value is selected/provided this will check for maximum file size allowed
13. `./accept` - defines the type of files accepted to upload
14. `./showComment` - if set to `true`, comments can be added to attachment
15. `./minItemsMessage` - defines the message displayed as tooltip when submitting the form if less than allowed minimum files uploaded
16. `./maxItemsMessage` - defines the message displayed as tooltip when submitting the form if more than allowed maximum files uploaded
17. `./maxFileSizeMessage` - defines the message displayed as tooltip when submitting the form if the uploaded file size is greater than allowed
18. `./acceptMessage` - defines the message displayed as tooltip when submitting the form if the uploaded file type is not allowed

## Client Libraries
The component provides a `core.forms.components.fileinput.v2.runtime` client library category that contains the Javascript runtime for the component.
It should be added to a relevant site client library using the `embed` property.

It also provides a `core.forms.components.fileinput.v2.editor` editor client library category that includes
JavaScript handling for dialog interaction. It is already included by its edit dialog.

## BEM Description
```
BLOCK cmp-adaptiveform-fileinput
ELEMENT cmp-adaptiveform-fileinput__label
ELEMENT cmp-adaptiveform-fileinput__label-container
ELEMENT cmp-adaptiveform-fileinput__widget
ELEMENT cmp-adaptiveform-fileinput__questionmark
ELEMENT cmp-adaptiveform-fileinput__shortdescription
ELEMENT cmp-adaptiveform-fileinput__longdescription
ELEMENT cmp-adaptiveform-fileinput__filelist
ELEMENT cmp-adaptiveform-fileinput__fileitem
ELEMENT cmp-adaptiveform-fileinput__filename
ELEMENT cmp-adaptiveform-fileinput__filedelete
ELEMENT cmp-adaptiveform-fileinput__widgetlabel
```

### Note
By placing the class names `cmp-adaptiveform-fileinput__label` and `cmp-adaptiveform-fileinput__questionmark` within the `cmp-adaptiveform-fileinput__label-container` class, you create a logical grouping of the label and question mark elements. This approach simplifies the process of maintaining a consistent styling for both elements.

## JavaScript Data Attribute Bindings


The following attributes must be added for the initialization of the file-input component in the form view:
1. `data-cmp-is="adaptiveFormFileInput"`
2. `data-cmp-adaptiveformcontainer-path="${formstructparser.formContainerPath}"`


## Information
* **Vendor**: Adobe
* **Version**: v2
* **Compatibility**: Cloud
* **Status**: production-ready

Loading

0 comments on commit 6f2ba76

Please sign in to comment.