|
|
@@ -1,7 +1,8 @@
|
|
|
import _ from 'lodash';
|
|
|
import coreModule from '../../core_module';
|
|
|
+import { ISCEService, IQService } from 'angular';
|
|
|
|
|
|
-function typeaheadMatcher(this: any, item) {
|
|
|
+function typeaheadMatcher(this: any, item: string) {
|
|
|
let str = this.query;
|
|
|
if (str === '') {
|
|
|
return true;
|
|
|
@@ -16,8 +17,8 @@ function typeaheadMatcher(this: any, item) {
|
|
|
}
|
|
|
|
|
|
export class FormDropdownCtrl {
|
|
|
- inputElement: any;
|
|
|
- linkElement: any;
|
|
|
+ inputElement: JQLite;
|
|
|
+ linkElement: JQLite;
|
|
|
model: any;
|
|
|
display: any;
|
|
|
text: any;
|
|
|
@@ -37,7 +38,13 @@ export class FormDropdownCtrl {
|
|
|
debounce: number;
|
|
|
|
|
|
/** @ngInject */
|
|
|
- constructor(private $scope, $element, private $sce, private templateSrv, private $q) {
|
|
|
+ constructor(
|
|
|
+ private $scope: any,
|
|
|
+ $element: JQLite,
|
|
|
+ private $sce: ISCEService,
|
|
|
+ private templateSrv: any,
|
|
|
+ private $q: IQService
|
|
|
+ ) {
|
|
|
this.inputElement = $element.find('input').first();
|
|
|
this.linkElement = $element.find('a').first();
|
|
|
this.linkMode = true;
|
|
|
@@ -99,7 +106,7 @@ export class FormDropdownCtrl {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- getOptionsInternal(query) {
|
|
|
+ getOptionsInternal(query: string) {
|
|
|
const result = this.getOptions({ $query: query });
|
|
|
if (this.isPromiseLike(result)) {
|
|
|
return result;
|
|
|
@@ -107,7 +114,7 @@ export class FormDropdownCtrl {
|
|
|
return this.$q.when(result);
|
|
|
}
|
|
|
|
|
|
- isPromiseLike(obj) {
|
|
|
+ isPromiseLike(obj: any) {
|
|
|
return obj && typeof obj.then === 'function';
|
|
|
}
|
|
|
|
|
|
@@ -117,7 +124,7 @@ export class FormDropdownCtrl {
|
|
|
} else {
|
|
|
// if we have text use it
|
|
|
if (this.lookupText) {
|
|
|
- this.getOptionsInternal('').then(options => {
|
|
|
+ this.getOptionsInternal('').then((options: any) => {
|
|
|
const item = _.find(options, { value: this.model });
|
|
|
this.updateDisplay(item ? item.text : this.model);
|
|
|
});
|
|
|
@@ -127,12 +134,12 @@ export class FormDropdownCtrl {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- typeaheadSource(query, callback) {
|
|
|
- this.getOptionsInternal(query).then(options => {
|
|
|
+ typeaheadSource(query: string, callback: (res: any) => void) {
|
|
|
+ this.getOptionsInternal(query).then((options: any) => {
|
|
|
this.optionCache = options;
|
|
|
|
|
|
// extract texts
|
|
|
- const optionTexts = _.map(options, op => {
|
|
|
+ const optionTexts = _.map(options, (op: any) => {
|
|
|
return _.escape(op.text);
|
|
|
});
|
|
|
|
|
|
@@ -147,7 +154,7 @@ export class FormDropdownCtrl {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- typeaheadUpdater(text) {
|
|
|
+ typeaheadUpdater(text: string) {
|
|
|
if (text === this.text) {
|
|
|
clearTimeout(this.cancelBlur);
|
|
|
this.inputElement.focus();
|
|
|
@@ -159,7 +166,7 @@ export class FormDropdownCtrl {
|
|
|
return text;
|
|
|
}
|
|
|
|
|
|
- switchToLink(fromClick) {
|
|
|
+ switchToLink(fromClick: boolean) {
|
|
|
if (this.linkMode && !fromClick) {
|
|
|
return;
|
|
|
}
|
|
|
@@ -178,7 +185,7 @@ export class FormDropdownCtrl {
|
|
|
this.cancelBlur = setTimeout(this.switchToLink.bind(this), 200);
|
|
|
}
|
|
|
|
|
|
- updateValue(text) {
|
|
|
+ updateValue(text: string) {
|
|
|
text = _.unescape(text);
|
|
|
|
|
|
if (text === '' || this.text === text) {
|
|
|
@@ -214,7 +221,7 @@ export class FormDropdownCtrl {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- updateDisplay(text) {
|
|
|
+ updateDisplay(text: string) {
|
|
|
this.text = text;
|
|
|
this.display = this.$sce.trustAsHtml(this.templateSrv.highlightVariablesAsHtml(text));
|
|
|
}
|