mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
parent
c6126b6be1
commit
399b716d82
@ -24,7 +24,7 @@
|
|||||||
alfresco-mdl-button
|
alfresco-mdl-button
|
||||||
[disabled]="!isOutcomeButtonEnabled(outcome)"
|
[disabled]="!isOutcomeButtonEnabled(outcome)"
|
||||||
[class.mdl-button--colored]="!outcome.isSystem"
|
[class.mdl-button--colored]="!outcome.isSystem"
|
||||||
[class.activiti-form-hide-button]="!isOutcomeButtonVisible(outcome)"
|
[class.activiti-form-hide-button]="!isOutcomeButtonVisible(outcome, form.readOnly)"
|
||||||
(click)="onOutcomeClicked(outcome, $event)">
|
(click)="onOutcomeClicked(outcome, $event)">
|
||||||
{{outcome.name}}
|
{{outcome.name}}
|
||||||
</button>
|
</button>
|
||||||
|
@ -101,35 +101,73 @@ describe('ActivitiForm', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not enable outcome button when model missing', () => {
|
it('should not enable outcome button when model missing', () => {
|
||||||
expect(formComponent.isOutcomeButtonVisible(null)).toBeFalsy();
|
expect(formComponent.isOutcomeButtonVisible(null, false)).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should enable custom outcome buttons', () => {
|
it('should enable custom outcome buttons', () => {
|
||||||
let formModel = new FormModel();
|
let formModel = new FormModel();
|
||||||
|
formComponent.form = formModel;
|
||||||
let outcome = new FormOutcomeModel(formModel, {id: 'action1', name: 'Action 1'});
|
let outcome = new FormOutcomeModel(formModel, {id: 'action1', name: 'Action 1'});
|
||||||
expect(formComponent.isOutcomeButtonVisible(outcome)).toBeTruthy();
|
expect(formComponent.isOutcomeButtonVisible(outcome, formComponent.form.readOnly)).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should allow controlling [complete] button visibility', () => {
|
it('should allow controlling [complete] button visibility', () => {
|
||||||
let formModel = new FormModel();
|
let formModel = new FormModel();
|
||||||
|
formComponent.form = formModel;
|
||||||
let outcome = new FormOutcomeModel(formModel, {id: '$save', name: FormOutcomeModel.SAVE_ACTION});
|
let outcome = new FormOutcomeModel(formModel, {id: '$save', name: FormOutcomeModel.SAVE_ACTION});
|
||||||
|
|
||||||
formComponent.showSaveButton = true;
|
formComponent.showSaveButton = true;
|
||||||
expect(formComponent.isOutcomeButtonVisible(outcome)).toBeTruthy();
|
expect(formComponent.isOutcomeButtonVisible(outcome, formComponent.form.readOnly)).toBeTruthy();
|
||||||
|
|
||||||
formComponent.showSaveButton = false;
|
formComponent.showSaveButton = false;
|
||||||
expect(formComponent.isOutcomeButtonVisible(outcome)).toBeFalsy();
|
expect(formComponent.isOutcomeButtonVisible(outcome, formComponent.form.readOnly)).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should show only [complete] button with readOnly form ', () => {
|
||||||
|
let formModel = new FormModel();
|
||||||
|
formModel.readOnly = true;
|
||||||
|
formComponent.form = formModel;
|
||||||
|
let outcome = new FormOutcomeModel(formModel, {id: '$complete', name: FormOutcomeModel.COMPLETE_ACTION});
|
||||||
|
|
||||||
|
formComponent.showCompleteButton = true;
|
||||||
|
expect(formComponent.isOutcomeButtonVisible(outcome, formComponent.form.readOnly)).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not show [save] button with readOnly form ', () => {
|
||||||
|
let formModel = new FormModel();
|
||||||
|
formModel.readOnly = true;
|
||||||
|
formComponent.form = formModel;
|
||||||
|
let outcome = new FormOutcomeModel(formModel, {id: '$save', name: FormOutcomeModel.SAVE_ACTION});
|
||||||
|
|
||||||
|
formComponent.showSaveButton = true;
|
||||||
|
expect(formComponent.isOutcomeButtonVisible(outcome, formComponent.form.readOnly)).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should show [custom-outcome] button with readOnly form and selected custom-outcome', () => {
|
||||||
|
let formModel = new FormModel({selectedOutcome: 'custom-outcome'});
|
||||||
|
formModel.readOnly = true;
|
||||||
|
formComponent.form = formModel;
|
||||||
|
let outcome = new FormOutcomeModel(formModel, {id: '$customoutome', name: 'custom-outcome'});
|
||||||
|
|
||||||
|
formComponent.showCompleteButton = true;
|
||||||
|
formComponent.showSaveButton = true;
|
||||||
|
expect(formComponent.isOutcomeButtonVisible(outcome, formComponent.form.readOnly)).toBeTruthy();
|
||||||
|
|
||||||
|
outcome = new FormOutcomeModel(formModel, {id: '$customoutome2', name: 'custom-outcome2'});
|
||||||
|
expect(formComponent.isOutcomeButtonVisible(outcome, formComponent.form.readOnly)).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should allow controlling [save] button visibility', () => {
|
it('should allow controlling [save] button visibility', () => {
|
||||||
let formModel = new FormModel();
|
let formModel = new FormModel();
|
||||||
|
formModel.readOnly = false;
|
||||||
|
formComponent.form = formModel;
|
||||||
let outcome = new FormOutcomeModel(formModel, {id: '$save', name: FormOutcomeModel.COMPLETE_ACTION});
|
let outcome = new FormOutcomeModel(formModel, {id: '$save', name: FormOutcomeModel.COMPLETE_ACTION});
|
||||||
|
|
||||||
formComponent.showCompleteButton = true;
|
formComponent.showCompleteButton = true;
|
||||||
expect(formComponent.isOutcomeButtonVisible(outcome)).toBeTruthy();
|
expect(formComponent.isOutcomeButtonVisible(outcome, formComponent.form.readOnly)).toBeTruthy();
|
||||||
|
|
||||||
formComponent.showCompleteButton = false;
|
formComponent.showCompleteButton = false;
|
||||||
expect(formComponent.isOutcomeButtonVisible(outcome)).toBeFalsy();
|
expect(formComponent.isOutcomeButtonVisible(outcome, formComponent.form.readOnly)).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should load form on refresh', () => {
|
it('should load form on refresh', () => {
|
||||||
|
@ -190,11 +190,14 @@ export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
isOutcomeButtonVisible(outcome: FormOutcomeModel): boolean {
|
isOutcomeButtonVisible(outcome: FormOutcomeModel, isFormReadOnly: boolean): boolean {
|
||||||
if (outcome && outcome.name) {
|
if (outcome && outcome.name) {
|
||||||
if (outcome.name === FormOutcomeModel.COMPLETE_ACTION) {
|
if (outcome.name === FormOutcomeModel.COMPLETE_ACTION) {
|
||||||
return this.showCompleteButton;
|
return this.showCompleteButton;
|
||||||
}
|
}
|
||||||
|
if (isFormReadOnly) {
|
||||||
|
return outcome.isSelected ;
|
||||||
|
}
|
||||||
if (outcome.name === FormOutcomeModel.SAVE_ACTION) {
|
if (outcome.name === FormOutcomeModel.SAVE_ACTION) {
|
||||||
return this.showSaveButton;
|
return this.showSaveButton;
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
alfresco-mdl-button
|
alfresco-mdl-button
|
||||||
[disabled]="!isOutcomeButtonEnabled(outcome)"
|
[disabled]="!isOutcomeButtonEnabled(outcome)"
|
||||||
[class.mdl-button--colored]="!outcome.isSystem"
|
[class.mdl-button--colored]="!outcome.isSystem"
|
||||||
[class.activiti-form-hide-button]="!isOutcomeButtonVisible(outcome)"
|
[class.activiti-form-hide-button]="!isOutcomeButtonVisible(outcome, form.readOnly)"
|
||||||
(click)="onOutcomeClicked(outcome, $event)">
|
(click)="onOutcomeClicked(outcome, $event)">
|
||||||
{{outcome.name}}
|
{{outcome.name}}
|
||||||
</button>
|
</button>
|
||||||
|
@ -133,14 +133,14 @@ export class ActivitiStartForm extends ActivitiForm implements AfterViewChecked,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @override */
|
/** @override */
|
||||||
isOutcomeButtonVisible(outcome: FormOutcomeModel): boolean {
|
isOutcomeButtonVisible(outcome: FormOutcomeModel, isFormReadOnly: boolean): boolean {
|
||||||
if (outcome && outcome.isSystem && ( outcome.name === FormOutcomeModel.SAVE_ACTION ||
|
if (outcome && outcome.isSystem && ( outcome.name === FormOutcomeModel.SAVE_ACTION ||
|
||||||
outcome.name === FormOutcomeModel.COMPLETE_ACTION )) {
|
outcome.name === FormOutcomeModel.COMPLETE_ACTION )) {
|
||||||
return false;
|
return false;
|
||||||
} else if (outcome && outcome.name === FormOutcomeModel.START_PROCESS_ACTION) {
|
} else if (outcome && outcome.name === FormOutcomeModel.START_PROCESS_ACTION) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return super.isOutcomeButtonVisible(outcome);
|
return super.isOutcomeButtonVisible(outcome, isFormReadOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @override */
|
/** @override */
|
||||||
|
@ -25,12 +25,14 @@ export class FormOutcomeModel extends FormWidgetModel {
|
|||||||
static START_PROCESS_ACTION: string = 'Start Process'; // Activiti 'Start Process' action name
|
static START_PROCESS_ACTION: string = 'Start Process'; // Activiti 'Start Process' action name
|
||||||
|
|
||||||
isSystem: boolean = false;
|
isSystem: boolean = false;
|
||||||
|
isSelected: boolean = false;
|
||||||
|
|
||||||
constructor(form: FormModel, json?: any) {
|
constructor(form: FormModel, json?: any) {
|
||||||
super(form, json);
|
super(form, json);
|
||||||
|
|
||||||
if (json) {
|
if (json) {
|
||||||
this.isSystem = json.isSystem ? true : false;
|
this.isSystem = json.isSystem ? true : false;
|
||||||
|
this.isSelected = form && json.name === form.selectedOutcome ? true : false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,7 @@ export class FormModel {
|
|||||||
fields: FormWidgetModel[] = [];
|
fields: FormWidgetModel[] = [];
|
||||||
outcomes: FormOutcomeModel[] = [];
|
outcomes: FormOutcomeModel[] = [];
|
||||||
customFieldTemplates: FormFieldTemplates = {};
|
customFieldTemplates: FormFieldTemplates = {};
|
||||||
|
readonly selectedOutcome: string;
|
||||||
|
|
||||||
values: FormValues = {};
|
values: FormValues = {};
|
||||||
|
|
||||||
@ -77,6 +78,7 @@ export class FormModel {
|
|||||||
this.taskName = json.taskName || json.name || FormModel.UNSET_TASK_NAME;
|
this.taskName = json.taskName || json.name || FormModel.UNSET_TASK_NAME;
|
||||||
this.processDefinitionId = json.processDefinitionId;
|
this.processDefinitionId = json.processDefinitionId;
|
||||||
this.customFieldTemplates = json.customFieldTemplates || {};
|
this.customFieldTemplates = json.customFieldTemplates || {};
|
||||||
|
this.selectedOutcome = json.selectedOutcome || {};
|
||||||
|
|
||||||
let tabCache: FormWidgetModelCache<TabModel> = {};
|
let tabCache: FormWidgetModelCache<TabModel> = {};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user