Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
then((cvms: ChoiceViewModel[]) => {
// if unchanged return
if (cvms.length === this.currentOptions.length && every(cvms, (c, i) => c.equals(this.currentOptions[i]))) {
return;
}
this.model.choices = cvms;
this.currentOptions = cvms;
if (this.isConditionalChoices) {
// need to reset control to find the selected options
if (this.model.entryType === Ro.EntryType.MultipleConditionalChoices) {
this.control.reset(this.model.selectedMultiChoices);
} else {
this.control.reset(this.model.selectedChoice);
}
}
}).
catch(() => {
private doPrompt = (field: Ro.IField, id: string, searchTerm: string | null, setupPrompt: (map: Ro.PromptMap) => void, objectValues: () => Dictionary, digest?: string | null) => {
const promptMap = field.getPromptMap() as Ro.PromptMap; // not null
promptMap.setMembers(objectValues);
setupPrompt(promptMap);
const addEmptyOption = field.entryType() !== Ro.EntryType.AutoComplete && field.extensions().optional();
return this.repLoader.retrieve(promptMap, Ro.PromptRepresentation, digest).then((p: Ro.PromptRepresentation) => p.choices(addEmptyOption));
}
this.returnType = 'string';
}
if (propertyRep instanceof Ro.PropertyMember) {
const isPassword = propertyRep.extensions().dataType() === 'password';
const value = propertyRep.value();
this.returnType = propertyRep.extensions().returnType()!;
if (propertyRep.isScalar()) {
this.type = 'scalar';
Helpers.setScalarValueInView(this, propertyRep, value);
const remoteMask = propertyRep.extensions().mask();
const localFilter = mask.toLocalFilter(remoteMask, propertyRep.extensions().format()!);
if (propertyRep.entryType() === Ro.EntryType.Choices) {
const currentChoice = new ChoiceViewModel(value, id);
const choicesMap = propertyRep.choices()!;
const choices = map(choicesMap, (v, n) => new ChoiceViewModel(v, id, n));
const choice = find(choices, c => c.valuesEqual(currentChoice));
if (choice) {
this.value = choice.name;
this.formattedValue = choice.name;
}
} else if (isPassword) {
this.formattedValue = Msg.obscuredText;
} else {
this.formattedValue = localFilter.filter(this.value);
}
} else {
// is reference
private setupReference(value: Ro.Value, rep: Ro.IHasExtensions) {
if (value.isNull()) {
this.reference = '';
this.value = this.description;
this.formattedValue = '';
this.refType = 'null';
} else {
this.reference = value!.link()!.href();
this.value = value.toString();
this.formattedValue = value.toString();
this.refType = rep.extensions().notNavigable() ? 'notNavigable' : 'navigable';
}
if (this.entryType === Ro.EntryType.FreeForm) {
this.description = this.description || Msg.dropPrompt;
}
}
private setField(field: Ro.IField, fieldEntry: string) {
if (field instanceof Ro.PropertyMember && field.disabledReason()) {
return this.returnResult('', `${field.extensions().friendlyName()} ${Usermessages.isNotModifiable}`);
}
const entryType = field.entryType();
switch (entryType) {
case Ro.EntryType.FreeForm:
return this.handleFreeForm(field, fieldEntry);
case Ro.EntryType.AutoComplete:
return this.handleAutoComplete(field, fieldEntry);
case Ro.EntryType.Choices:
return this.handleChoices(field, fieldEntry);
case Ro.EntryType.MultipleChoices:
return this.handleChoices(field, fieldEntry);
case Ro.EntryType.ConditionalChoices:
return this.handleConditionalChoices(field, false, fieldEntry);
case Ro.EntryType.MultipleConditionalChoices:
return this.handleConditionalChoices(field, false, fieldEntry);
default:
return this.returnResult('', Usermessages.invalidCase);
}
}
private setupChoice(newValue: Ro.Value) {
const propertyRep = this.propertyRep;
if (this.entryType === Ro.EntryType.Choices) {
const choices = propertyRep.choices()!;
this.setupChoices(choices);
if (this.optional) {
const emptyChoice = new ChoiceViewModel(new Ro.Value(''), this.id);
this.choices = concat([emptyChoice], this.choices);
}
const currentChoice = new ChoiceViewModel(newValue, this.id);
this.selectedChoice = find(this.choices, c => c.valuesEqual(currentChoice)) || null;
} else if (!propertyRep.isScalar()) {
this.selectedChoice = new ChoiceViewModel(newValue, this.id);
}
}
set property(value: PropertyViewModel) {
this.prop = value;
if (this.propertyEntryType === Ro.EntryType.FreeForm) {
this.dragAndDrop.setDropZoneId(this.propertyPaneId);
}
}