|
@@ -7,20 +7,12 @@
|
|
|
import { ValidatorFn, AsyncValidatorFn } from '@angular/forms';
|
|
|
import { ValueTransformer } from './../interfaces';
|
|
|
|
|
|
-// ---------------------------------------------------------------------------------------------------------------------
|
|
|
-// Types & Interfaces
|
|
|
-
|
|
|
-interface Option {
|
|
|
- label: string;
|
|
|
- value: string;
|
|
|
-}
|
|
|
-
|
|
|
-interface BasicFieldMetaData {
|
|
|
+interface SimpleFieldMetaData {
|
|
|
name: string; // The FormControl name
|
|
|
origin?: string; // Location in API-returned model - defaults to name
|
|
|
type?: string; // The component type e.g. BasicInput, Checkbutton, Timepicker, etc
|
|
|
label?: string; // The field label - defaults to unCamelCased name if not supplied
|
|
|
- value?: string; // The field value - defaults to empty string if not supplied
|
|
|
+ value?: any; // The field value - defaults to empty string if not supplied
|
|
|
placeholder?: string; // Optional placeholder text
|
|
|
class?: string | Array<string>; // CSS classes to apply
|
|
|
id?: string; // CSS id to apply
|
|
@@ -30,37 +22,42 @@ interface BasicFieldMetaData {
|
|
|
valFailureMsgs?: StringMap; // Validation failure messages - display appropriate message if validation fails
|
|
|
}
|
|
|
|
|
|
-interface OptionsFieldMetaData extends BasicFieldMetaData {
|
|
|
- options: Option[]; // Array of Options - for select, radio-button-group and other 'multiple-choice' types
|
|
|
+interface Option {
|
|
|
+ label: string;
|
|
|
+ value: string;
|
|
|
}
|
|
|
|
|
|
-interface DropdownModifiedInputFieldMetaData extends BasicFieldMetaData {
|
|
|
+interface OptionsFieldMetaData extends SimpleFieldMetaData {
|
|
|
+ options: Option[]; // Array of Options - for select, radio-button-group and other 'multiple-choice' types
|
|
|
+}
|
|
|
+interface DropdownModifiedInputFieldMetaData extends SimpleFieldMetaData {
|
|
|
modifiers: string[];
|
|
|
transform: ValueTransformer;
|
|
|
}
|
|
|
|
|
|
-interface TimePickerFieldMetaData extends BasicFieldMetaData {
|
|
|
+interface TimePickerFieldMetaData extends SimpleFieldMetaData {
|
|
|
// To add...
|
|
|
}
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
|
// Form Field MetaData Models
|
|
|
+// ---------------------------------------------------------------------------------------------------------------------
|
|
|
+// Base Implementations
|
|
|
|
|
|
-class BasicField
|
|
|
-{
|
|
|
- type: string = 'Basicinput';
|
|
|
+class SimpleField {
|
|
|
+ type = 'text';
|
|
|
name: string;
|
|
|
origin?: string;
|
|
|
label?: string;
|
|
|
- value: string = '';
|
|
|
- placeholder: string = '';
|
|
|
+ value;
|
|
|
+ placeholder = '';
|
|
|
class?: string | Array<string>;
|
|
|
isDisabled?: boolean;
|
|
|
validators: Array<ValidatorFn> = [];
|
|
|
asyncValidators: Array<AsyncValidatorFn> = [];
|
|
|
valFailureMsgs: StringMap = {};
|
|
|
|
|
|
- constructor(meta: BasicFieldMetaData) {
|
|
|
+ constructor(meta: SimpleFieldMetaData) {
|
|
|
Object.assign(this, meta);
|
|
|
if (!this.origin) {
|
|
|
// If origin is not supplied it's the same as the name
|
|
@@ -74,18 +71,50 @@ class BasicField
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-class OptionsField extends BasicField
|
|
|
-{
|
|
|
- type: string = 'OptionsField';
|
|
|
+class OptionsField extends SimpleField {
|
|
|
options: Option[];
|
|
|
constructor(meta: OptionsFieldMetaData) {
|
|
|
super(meta);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-class DropdownModifiedInputField extends BasicField
|
|
|
-{
|
|
|
- type: string = 'DropdownModifiedInput';
|
|
|
+// ---------------------------------------------------------------------------------------------------------------------
|
|
|
+// Concrete Implmemntations (suuplied for convenience)
|
|
|
+
|
|
|
+class TextField extends SimpleField {
|
|
|
+ type = 'Text';
|
|
|
+}
|
|
|
+
|
|
|
+class TextareaField extends SimpleField {
|
|
|
+ type = 'Textarea';
|
|
|
+}
|
|
|
+
|
|
|
+class PasswordField extends SimpleField {
|
|
|
+ type = 'Password';
|
|
|
+}
|
|
|
+
|
|
|
+class SelectField extends OptionsField {
|
|
|
+ type = 'Select';
|
|
|
+}
|
|
|
+
|
|
|
+class RadioField extends OptionsField {
|
|
|
+ type = 'Radio';
|
|
|
+}
|
|
|
+
|
|
|
+// ---------------------------------------------------------------------------------------------------------------------
|
|
|
+// Custom Form Component Models
|
|
|
+
|
|
|
+class CheckbuttonField extends SimpleField {
|
|
|
+ type = 'Checkbutton';
|
|
|
+}
|
|
|
+
|
|
|
+class CheckbuttonGroup extends SimpleField {
|
|
|
+ value: (string | boolean)[];
|
|
|
+ type = 'CheckbuttonGroup';
|
|
|
+}
|
|
|
+
|
|
|
+class DropdownModifiedInputField extends SimpleField {
|
|
|
+ type = 'DropdownModifiedInput';
|
|
|
modifiers: string[];
|
|
|
transform: ValueTransformer;
|
|
|
constructor(meta: DropdownModifiedInputFieldMetaData) {
|
|
@@ -93,18 +122,25 @@ class DropdownModifiedInputField extends BasicField
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-class TimePickerField extends BasicField
|
|
|
-{
|
|
|
+// ---------------------------------------------------------------------------------------------------------------------
|
|
|
+// Kendo Form Component Models
|
|
|
+
|
|
|
+class TimePickerField extends SimpleField {
|
|
|
// To add...
|
|
|
constructor(meta: TimePickerFieldMetaData) {
|
|
|
super(meta);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// ---------------------------------------------------------------------------------------------------------------------
|
|
|
+// ---------------------------------------------------------------------------------------------------------------------
|
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
|
// Exports
|
|
|
|
|
|
-export { BasicField, OptionsField, DropdownModifiedInputField, TimePickerField };
|
|
|
+export {
|
|
|
+ TextField, TextareaField, PasswordField, SelectField, RadioField,
|
|
|
+ CheckbuttonField, CheckbuttonGroup, DropdownModifiedInputField, TimePickerField
|
|
|
+};
|
|
|
|
|
|
|
|
|
/* *********************************************************************************************************************
|
|
@@ -127,7 +163,7 @@ for (field in model) {
|
|
|
if (field in overrides) {
|
|
|
Object.assign(modeledMeta, FieldFactory(model, overrides[field])); // FieldFactory returns a new field model of the specified type
|
|
|
} else {
|
|
|
- Object.assign(modeledMeta, new BasicField(field)); // Defaults to basic text field
|
|
|
+ Object.assign(modeledMeta, new SimpleField(field)); // Defaults to basic text field
|
|
|
}
|
|
|
}
|
|
|
|