mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
#440 basic dropdown widget
This commit is contained in:
parent
b0b7a7130c
commit
591f053d9b
@ -0,0 +1,7 @@
|
|||||||
|
.dropdown-widget {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-widget > select {
|
||||||
|
width: 100%;
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
<select>
|
<div class="dropdown-widget">
|
||||||
<option value="1">One</option>
|
<select [(ngModel)]="field.value">
|
||||||
<option value="2">Two</option>
|
<option *ngFor="let opt of field.options" [value]="opt.id">{{opt.name}}</option>
|
||||||
</select>
|
</select>
|
||||||
|
</div>
|
||||||
|
@ -24,7 +24,8 @@ declare var componentHandler;
|
|||||||
@Component({
|
@Component({
|
||||||
moduleId: __moduleName,
|
moduleId: __moduleName,
|
||||||
selector: 'dropdown-widget',
|
selector: 'dropdown-widget',
|
||||||
templateUrl: './dropdown.widget.html'
|
templateUrl: './dropdown.widget.html',
|
||||||
|
styleUrls: ['./dropdown.widget.css']
|
||||||
})
|
})
|
||||||
export class DropdownWidget extends WidgetComponent {
|
export class DropdownWidget extends WidgetComponent {
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
export interface FormValues {
|
export interface FormValues {
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
@ -39,14 +38,24 @@ export class FormWidgetModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface FormFieldOption {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
export class FormFieldModel extends FormWidgetModel {
|
export class FormFieldModel extends FormWidgetModel {
|
||||||
|
|
||||||
|
private _fieldType: string;
|
||||||
private _id: string;
|
private _id: string;
|
||||||
private _name: string;
|
private _name: string;
|
||||||
private _type: string;
|
private _type: string;
|
||||||
private _value: string;
|
private _value: string;
|
||||||
private _tab: string;
|
private _tab: string;
|
||||||
|
|
||||||
|
get fieldType(): string {
|
||||||
|
return this._fieldType;
|
||||||
|
}
|
||||||
|
|
||||||
get id(): string {
|
get id(): string {
|
||||||
return this._id;
|
return this._id;
|
||||||
}
|
}
|
||||||
@ -65,7 +74,7 @@ export class FormFieldModel extends FormWidgetModel {
|
|||||||
|
|
||||||
set value(v: any) {
|
set value(v: any) {
|
||||||
this._value = v;
|
this._value = v;
|
||||||
this.form.values[this._id] = v;
|
this.updateForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
get tab(): string {
|
get tab(): string {
|
||||||
@ -73,20 +82,58 @@ export class FormFieldModel extends FormWidgetModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
colspan: number = 1;
|
colspan: number = 1;
|
||||||
|
options: FormFieldOption[] = [];
|
||||||
|
|
||||||
constructor(form: FormModel, json?: any) {
|
constructor(form: FormModel, json?: any) {
|
||||||
super(form, json);
|
super(form, json);
|
||||||
|
|
||||||
if (json) {
|
if (json) {
|
||||||
|
this._fieldType = json.fieldType;
|
||||||
this._id = json.id;
|
this._id = json.id;
|
||||||
this._name = json.name;
|
this._name = json.name;
|
||||||
this._type = json.type;
|
this._type = json.type;
|
||||||
this._value = json.value;
|
|
||||||
this._tab = json.tab;
|
this._tab = json.tab;
|
||||||
this.colspan = <number> json.colspan;
|
this.colspan = <number> json.colspan;
|
||||||
|
this.options = <FormFieldOption[]> json.options || [];
|
||||||
|
|
||||||
// update form values
|
this._value = this.parseValue(json);
|
||||||
form.values[json.id] = json.value;
|
this.updateForm();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private parseValue(json: any): any {
|
||||||
|
let value = json.value;
|
||||||
|
|
||||||
|
/*
|
||||||
|
This is needed due to Activiti reading dropdown values as string
|
||||||
|
but saving back as object: { id: <id>, name: <name> }
|
||||||
|
*/
|
||||||
|
// TODO: needs review
|
||||||
|
if (json.fieldType === 'RestFieldRepresentation') {
|
||||||
|
if (value === '') {
|
||||||
|
value = 'empty';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private updateForm() {
|
||||||
|
/*
|
||||||
|
This is needed due to Activiti reading dropdown values as string
|
||||||
|
but saving back as object: { id: <id>, name: <name> }
|
||||||
|
*/
|
||||||
|
if (this.fieldType === 'RestFieldRepresentation') {
|
||||||
|
if (this.value === 'empty' || this.value === '') {
|
||||||
|
this.form.values[this.id] = {};
|
||||||
|
} else {
|
||||||
|
let entry: FormFieldOption[] = this.options.filter(opt => opt.id === this.value);
|
||||||
|
if (entry.length > 0) {
|
||||||
|
this.form.values[this.id] = entry[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.form.values[this.id] = this.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user