TextBoxVariable.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { Variable, assignModelProperties, variableTypes } from './variable';
  2. export class TextBoxVariable implements Variable {
  3. query: string;
  4. current: any;
  5. options: any[];
  6. skipUrlSync: boolean;
  7. defaults = {
  8. type: 'textbox',
  9. name: '',
  10. hide: 2,
  11. label: '',
  12. query: '',
  13. current: {},
  14. options: [],
  15. skipUrlSync: false,
  16. };
  17. /** @ngInject */
  18. constructor(private model, private variableSrv) {
  19. assignModelProperties(this, model, this.defaults);
  20. }
  21. getSaveModel() {
  22. assignModelProperties(this.model, this, this.defaults);
  23. return this.model;
  24. }
  25. setValue(option) {
  26. this.variableSrv.setOptionAsCurrent(this, option);
  27. }
  28. updateOptions() {
  29. this.options = [{ text: this.query.trim(), value: this.query.trim() }];
  30. this.current = this.options[0];
  31. return Promise.resolve();
  32. }
  33. dependsOn(variable) {
  34. return false;
  35. }
  36. setValueFromUrl(urlValue) {
  37. this.query = urlValue;
  38. return this.variableSrv.setOptionFromUrl(this, urlValue);
  39. }
  40. getValueForUrl() {
  41. return this.current.value;
  42. }
  43. }
  44. variableTypes['textbox'] = {
  45. name: 'Text box',
  46. ctor: TextBoxVariable,
  47. description: 'Define a textbox variable, where users can enter any arbitrary string',
  48. };