getaddress-autocomplete-modal
Version:
GetAddress.io - Autocomplete modal plug-in
63 lines • 3.5 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { Debug } from "./Debug";
export default class SuggestionContainer {
constructor(client, modal, suggestion, attributeValues) {
this.client = client;
this.modal = modal;
this.suggestion = suggestion;
this.attributeValues = attributeValues;
this.container = document.createElement('DIV');
this.element = this.container;
this.build = () => {
this.container.className = this.attributeValues.suggestionContainerClassName;
const containerItem1 = document.createElement('DIV');
containerItem1.className = this.attributeValues.suggestionContainerItem1ClassName;
var locationIcon = document.createElement('i');
locationIcon.className = this.attributeValues.iconLocationClassName;
locationIcon.classList.add(this.attributeValues.iconClassName);
containerItem1.insertBefore(locationIcon, null);
const containerItem2 = document.createElement('DIV');
containerItem2.className = this.attributeValues.suggestionContainerItem2ClassName;
const addressLine = document.createElement('DIV');
addressLine.className = this.attributeValues.suggestionHtmlClassName;
addressLine.innerHTML = this.suggestion.address;
this.attributeValues.suggestionHtmlClassName;
if (this.attributeValues.suggestionAdditionalClassNames) {
for (const suggestionClassName of this.attributeValues.suggestionAdditionalClassNames) {
addressLine.classList.add(suggestionClassName);
}
}
containerItem2.insertBefore(addressLine, null);
this.container.insertBefore(containerItem2, null);
this.container.insertBefore(containerItem1, containerItem2);
this.container.addEventListener('click', this.handleClick);
};
this.handleClick = (e) => __awaiter(this, void 0, void 0, function* () {
Debug.Log(this.attributeValues, e);
const getResult = yield this.client.get(this.suggestion.id, {
remember: this.attributeValues.options.remember_last_search
});
if (!getResult.isSuccess) {
const failed = getResult.toFailed();
this.modal.dispatchSelectedFailed(this.suggestion.id, failed.status, failed.message);
return;
}
let success = getResult.toSuccess();
this.modal.dispatchSelected(this.suggestion.id, success.address);
this.modal.close();
});
this.destroy = () => {
this.container.removeEventListener('click', this.handleClick);
};
this.build();
}
}
//# sourceMappingURL=SuggestionContainer%20copy.js.map