2018-11-05 05:06:39 -05:00
|
|
|
/* eslint-disable
|
|
|
|
max-len,
|
|
|
|
no-return-assign,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-09-18 06:01:51 -04:00
|
|
|
import App from '../../../base'
|
2021-04-14 09:17:21 -04:00
|
|
|
const inputSuggestionsController = function ($scope, $element, $attrs, Keys) {
|
2020-05-19 05:02:56 -04:00
|
|
|
const ctrl = this
|
|
|
|
ctrl.showHint = false
|
|
|
|
ctrl.hasFocus = false
|
2021-04-14 09:17:21 -04:00
|
|
|
ctrl.handleFocus = function () {
|
2020-05-19 05:02:56 -04:00
|
|
|
ctrl.hasFocus = true
|
|
|
|
return (ctrl.suggestion = null)
|
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
ctrl.handleBlur = function () {
|
2018-11-05 05:06:39 -05:00
|
|
|
ctrl.showHint = false
|
|
|
|
ctrl.hasFocus = false
|
2020-05-19 05:02:56 -04:00
|
|
|
ctrl.suggestion = null
|
|
|
|
return ctrl.onBlur()
|
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
ctrl.handleKeyDown = function ($event) {
|
2020-05-19 05:02:56 -04:00
|
|
|
if (
|
|
|
|
($event.which === Keys.TAB || $event.which === Keys.ENTER) &&
|
|
|
|
ctrl.suggestion != null &&
|
|
|
|
ctrl.suggestion !== ''
|
|
|
|
) {
|
|
|
|
$event.preventDefault()
|
|
|
|
ctrl.localNgModel += ctrl.suggestion
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
ctrl.suggestion = null
|
|
|
|
return (ctrl.showHint = false)
|
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.$watch('$ctrl.localNgModel', function (newVal, oldVal) {
|
2020-05-19 05:02:56 -04:00
|
|
|
if (ctrl.hasFocus && newVal !== oldVal) {
|
2018-11-05 05:06:39 -05:00
|
|
|
ctrl.suggestion = null
|
2020-05-19 05:02:56 -04:00
|
|
|
ctrl.showHint = false
|
|
|
|
return ctrl
|
|
|
|
.getSuggestion({ userInput: newVal })
|
2021-04-14 09:17:21 -04:00
|
|
|
.then(function (suggestion) {
|
2020-05-19 05:02:56 -04:00
|
|
|
if (suggestion != null && newVal === ctrl.localNgModel) {
|
|
|
|
ctrl.showHint = true
|
|
|
|
return (ctrl.suggestion = suggestion.replace(newVal, ''))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(() => (ctrl.suggestion = null))
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
})
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default App.component('inputSuggestions', {
|
|
|
|
bindings: {
|
|
|
|
localNgModel: '=ngModel',
|
|
|
|
localNgModelOptions: '=?ngModelOptions',
|
|
|
|
getSuggestion: '&',
|
|
|
|
onBlur: '&?',
|
|
|
|
inputId: '@?',
|
|
|
|
inputName: '@?',
|
|
|
|
inputPlaceholder: '@?',
|
|
|
|
inputType: '@?',
|
2021-04-27 03:52:58 -04:00
|
|
|
inputRequired: '=?',
|
2020-05-19 05:02:56 -04:00
|
|
|
},
|
|
|
|
controller: inputSuggestionsController,
|
|
|
|
template: [
|
|
|
|
'<div class="input-suggestions">',
|
|
|
|
'<div class="form-control input-suggestions-shadow">',
|
|
|
|
'<span ng-bind="$ctrl.localNgModel"',
|
|
|
|
' class="input-suggestions-shadow-existing"',
|
|
|
|
' ng-show="$ctrl.showHint">',
|
|
|
|
'</span>',
|
|
|
|
'<span ng-bind="$ctrl.suggestion"',
|
|
|
|
' class="input-suggestions-shadow-suggested"',
|
|
|
|
' ng-show="$ctrl.showHint">',
|
|
|
|
'</span>',
|
|
|
|
'</div>',
|
|
|
|
'<input type="text"',
|
|
|
|
' class="form-control input-suggestions-main"',
|
|
|
|
' ng-focus="$ctrl.handleFocus()"',
|
|
|
|
' ng-keyDown="$ctrl.handleKeyDown($event)"',
|
|
|
|
' ng-blur="$ctrl.handleBlur()"',
|
|
|
|
' ng-model="$ctrl.localNgModel"',
|
|
|
|
' ng-model-options="$ctrl.localNgModelOptions"',
|
|
|
|
' ng-model-options="{ debounce: 50 }"',
|
|
|
|
' ng-attr-id="{{ ::$ctrl.inputId }}"',
|
|
|
|
' ng-attr-placeholder="{{ ::$ctrl.inputPlaceholder }}"',
|
|
|
|
' ng-attr-type="{{ ::$ctrl.inputType }}"',
|
|
|
|
' ng-attr-name="{{ ::$ctrl.inputName }}"',
|
2022-02-03 06:37:34 -05:00
|
|
|
' autofocus="::$ctrl.focusOnRender"',
|
2020-05-19 05:02:56 -04:00
|
|
|
' ng-required="::$ctrl.inputRequired">',
|
2021-04-27 03:52:58 -04:00
|
|
|
'</div>',
|
|
|
|
].join(''),
|
2018-11-05 05:06:39 -05:00
|
|
|
})
|