Skip to content

Instantly share code, notes, and snippets.

@willianantunes
Created August 11, 2018 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willianantunes/a1aa97d63bf3a4fb89d39cccabe20125 to your computer and use it in GitHub Desktop.
Save willianantunes/a1aa97d63bf3a4fb89d39cccabe20125 to your computer and use it in GitHub Desktop.
class SampleJasmineController {
constructor(serviceUrl) {
let $ = document.querySelector.bind(document);
this._service = new SampleJasmineService(serviceUrl);
this._message = $('p.message');
this._btnSubmit = $('form input[type=submit]');
this._inputSample = $('form input[name=sampleJasmine]');
}
search(event) {
event.preventDefault();
this.disableForm();
this.includeMessage('Avaliando...');
return this._service
.consult(this._inputSample.value)
.then(result => this.includeMessage(result.message))
.catch(error => this.includeMessage(error.message))
.finally(() => this.enableForm());
}
enableForm() {
this._btnSubmit.disabled = false;
this._inputSample.disabled = false;
}
disableForm() {
this._btnSubmit.disabled = true;
this._inputSample.disabled = true;
}
includeMessage(message) {
this._message.style.display = 'block';
this._message.innerText = message;
}
cleanMessage(event) {
this._message.style.display = 'none';
this._message.innerText = null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment