diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/core/group-user.model.ts b/ng2-components/ng2-activiti-form/src/components/widgets/core/group-user.model.ts new file mode 100644 index 0000000000..dd3769c367 --- /dev/null +++ b/ng2-components/ng2-activiti-form/src/components/widgets/core/group-user.model.ts @@ -0,0 +1,26 @@ +/*! + * @license + * Copyright 2016 Alfresco Software, Ltd. + * + * 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. + */ + +export class GroupUserModel { + + company: string; + email: string; + firstName: string; + id: string; + lastName: string; + +} diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/core/group.model.ts b/ng2-components/ng2-activiti-form/src/components/widgets/core/group.model.ts new file mode 100644 index 0000000000..de701aec0a --- /dev/null +++ b/ng2-components/ng2-activiti-form/src/components/widgets/core/group.model.ts @@ -0,0 +1,26 @@ +/*! + * @license + * Copyright 2016 Alfresco Software, Ltd. + * + * 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. + */ + +export class GroupModel { + + externalId: string; + groups: any; + id: string; + name: string; + status: string; + +} diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/functional-group/functional-group.widget.css b/ng2-components/ng2-activiti-form/src/components/widgets/functional-group/functional-group.widget.css index 95e76bb511..6533c16189 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/functional-group/functional-group.widget.css +++ b/ng2-components/ng2-activiti-form/src/components/widgets/functional-group/functional-group.widget.css @@ -1,3 +1,29 @@ .functional-group-widget { width: 100%; } + +.functional-group-widget--autocomplete { + background-color: #fff; + position: absolute; + z-index: 5; + color: #555; + margin: -15px 0 0 0; +} + +.functional-group-widget--autocomplete > ul { + list-style-type: none; + position: static; + + height: auto; + width: auto; + min-width: 124px; + padding: 8px 0; + margin: 0; + + box-shadow: 0 2px 2px 0 rgba(0,0,0,.14),0 3px 1px -2px rgba(0,0,0,.2),0 1px 5px 0 rgba(0,0,0,.12); + border-radius: 2px; +} + +.functional-group-widget--autocomplete > ul > li { + opacity: 1; +} diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/functional-group/functional-group.widget.html b/ng2-components/ng2-activiti-form/src/components/widgets/functional-group/functional-group.widget.html index 6939b86bd8..7a9bf8f2a5 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/functional-group/functional-group.widget.html +++ b/ng2-components/ng2-activiti-form/src/components/widgets/functional-group/functional-group.widget.html @@ -4,6 +4,18 @@ [attr.id]="field.id" [(ngModel)]="value" (ngModelChange)="checkVisibility(field)" + (keyup)="onKeyUp($event)" + (blur)="onBlur()" [disabled]="field.readOnly"> + +
diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/functional-group/functional-group.widget.ts b/ng2-components/ng2-activiti-form/src/components/widgets/functional-group/functional-group.widget.ts index 9988a6c0d4..37a40337b0 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/functional-group/functional-group.widget.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/functional-group/functional-group.widget.ts @@ -17,6 +17,8 @@ import { Component, OnInit } from '@angular/core'; import { WidgetComponent } from './../widget.component'; +import { FormService } from '../../../services/form.service'; +import { GroupModel } from './../core/group.model'; declare let __moduleName: string; declare var componentHandler; @@ -30,15 +32,66 @@ declare var componentHandler; export class FunctionalGroupWidget extends WidgetComponent implements OnInit { value: string; + popupVisible: boolean = false; + groups: GroupModel[] = []; + minTermLength: number = 1; - constructor() { + constructor(private formService: FormService) { super(); } + // TODO: investigate, called 2 times + // https://github.com/angular/angular/issues/6782 ngOnInit() { let group = this.field.value; if (group) { this.value = group.name; } } + + onKeyUp(event: KeyboardEvent) { + if (this.value && this.value.length >= this.minTermLength) { + this.formService.getWorkflowGroups(this.value) + .subscribe((result: GroupModel[]) => { + this.groups = result || []; + this.popupVisible = this.groups.length > 0; + }); + } else { + this.popupVisible = false; + } + + } + + onBlur() { + setTimeout(() => { + this.flushValue(); + }, 200); + } + + flushValue() { + this.popupVisible = false; + + let option = this.groups.find(item => item.name.toLocaleLowerCase() === this.value.toLocaleLowerCase()); + + if (option) { + this.field.value = option; + this.value = option.name; + } else { + this.field.value = null; + this.value = null; + } + + this.field.updateForm(); + } + + // TODO: still causes onBlur execution + onItemClick(item: GroupModel, event: Event) { + if (item) { + this.field.value = item; + this.value = item.name; + } + if (event) { + event.preventDefault(); + } + } } diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.ts b/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.ts index 2eaeae6db2..8ed39cc2ef 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/typeahead/typeahead.widget.ts @@ -97,6 +97,7 @@ export class TypeaheadWidget extends WidgetComponent implements OnInit { this.field.updateForm(); } + // TODO: still causes onBlur execution onItemClick(item: FormFieldOption, event: Event) { if (item) { this.field.value = item.id; diff --git a/ng2-components/ng2-activiti-form/src/services/form.service.ts b/ng2-components/ng2-activiti-form/src/services/form.service.ts index cd26ce0ca2..34040c5b1b 100644 --- a/ng2-components/ng2-activiti-form/src/services/form.service.ts +++ b/ng2-components/ng2-activiti-form/src/services/form.service.ts @@ -17,10 +17,11 @@ import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Rx'; -import { AlfrescoAuthenticationService } from 'ng2-alfresco-core'; +import { AlfrescoApiService } from 'ng2-alfresco-core'; import { FormValues } from './../components/widgets/core/index'; import { FormDefinitionModel } from '../models/form-definition.model'; import { EcmModelService } from './ecm-model.service'; +import { GroupModel } from './../components/widgets/core/group.model'; @Injectable() export class FormService { @@ -28,15 +29,15 @@ export class FormService { static UNKNOWN_ERROR_MESSAGE: string = 'Unknown error'; static GENERIC_ERROR_MESSAGE: string = 'Server error'; - constructor(private authService: AlfrescoAuthenticationService, - private ecmModelService: EcmModelService) { + constructor(private ecmModelService: EcmModelService, + private apiService: AlfrescoApiService) { } /** * Create a Form with a fields for each metadata properties * @returns {Observable