@@ -17,15 +17,21 @@ angular.module('angular-advanced-searchbox', [])
17
17
scope : {
18
18
model : '=ngModel' ,
19
19
parameters : '=' ,
20
- placeholder : '@'
20
+ parametersLabel : '@' ,
21
+ parametersDisplayLimit : '=' ,
22
+ placeholder : '@' ,
23
+ searchThrottleTime : '='
21
24
} ,
22
25
replace : true ,
23
26
templateUrl : 'angular-advanced-searchbox.html' ,
24
27
controller : [
25
28
'$scope' , '$attrs' , '$element' , '$timeout' , '$filter' ,
26
29
function ( $scope , $attrs , $element , $timeout , $filter ) {
27
30
31
+ $scope . parametersLabel = $scope . parametersLabel || 'Parameter Suggestions' ;
32
+ $scope . parametersDisplayLimit = $scope . parametersDisplayLimit || 8 ;
28
33
$scope . placeholder = $scope . placeholder || 'Search ...' ;
34
+ $scope . searchThrottleTime = $scope . searchThrottleTime || 1000 ;
29
35
$scope . searchParams = [ ] ;
30
36
$scope . searchQuery = '' ;
31
37
$scope . setSearchFocus = false ;
@@ -70,21 +76,28 @@ angular.module('angular-advanced-searchbox', [])
70
76
updateModel ( 'change' , 'query' , query ) ;
71
77
} ;
72
78
73
- $scope . enterEditMode = function ( index ) {
79
+ $scope . enterEditMode = function ( e , index ) {
80
+ if ( e !== undefined )
81
+ e . stopPropagation ( ) ;
82
+
74
83
if ( index === undefined )
75
84
return ;
76
85
77
86
var searchParam = $scope . searchParams [ index ] ;
78
87
searchParam . editMode = true ;
88
+
89
+ $scope . $emit ( 'advanced-searchbox:enteredEditMode' , searchParam ) ;
79
90
} ;
80
91
81
- $scope . leaveEditMode = function ( index ) {
92
+ $scope . leaveEditMode = function ( e , index ) {
82
93
if ( index === undefined )
83
94
return ;
84
95
85
96
var searchParam = $scope . searchParams [ index ] ;
86
97
searchParam . editMode = false ;
87
98
99
+ $scope . $emit ( 'advanced-searchbox:leavedEditMode' , searchParam ) ;
100
+
88
101
// remove empty search params
89
102
if ( ! searchParam . value )
90
103
$scope . removeSearchParam ( index ) ;
@@ -139,25 +152,25 @@ angular.module('angular-advanced-searchbox', [])
139
152
140
153
$scope . editPrevious = function ( currentIndex ) {
141
154
if ( currentIndex !== undefined )
142
- $scope . leaveEditMode ( currentIndex ) ;
155
+ $scope . leaveEditMode ( undefined , currentIndex ) ;
143
156
144
157
//TODO: check if index == 0 -> what then?
145
158
if ( currentIndex > 0 ) {
146
- $scope . enterEditMode ( currentIndex - 1 ) ;
159
+ $scope . enterEditMode ( undefined , currentIndex - 1 ) ;
147
160
} else if ( $scope . searchParams . length > 0 ) {
148
- $scope . enterEditMode ( $scope . searchParams . length - 1 ) ;
161
+ $scope . enterEditMode ( undefined , $scope . searchParams . length - 1 ) ;
149
162
}
150
163
} ;
151
164
152
165
$scope . editNext = function ( currentIndex ) {
153
166
if ( currentIndex === undefined )
154
167
return ;
155
168
156
- $scope . leaveEditMode ( currentIndex ) ;
169
+ $scope . leaveEditMode ( undefined , currentIndex ) ;
157
170
158
171
//TODO: check if index == array length - 1 -> what then?
159
172
if ( currentIndex < $scope . searchParams . length - 1 ) {
160
- $scope . enterEditMode ( currentIndex + 1 ) ;
173
+ $scope . enterEditMode ( undefined , currentIndex + 1 ) ;
161
174
} else {
162
175
$scope . setSearchFocus = true ;
163
176
}
@@ -171,8 +184,10 @@ angular.module('angular-advanced-searchbox', [])
171
184
var cursorPosition = getCurrentCaretPosition ( e . target ) ;
172
185
173
186
if ( e . which == 8 ) { // backspace
174
- if ( cursorPosition === 0 )
187
+ if ( cursorPosition === 0 ) {
188
+ e . preventDefault ( ) ;
175
189
$scope . editPrevious ( searchParamIndex ) ;
190
+ }
176
191
177
192
} else if ( e . which == 9 ) { // tab
178
193
if ( e . shiftKey ) {
@@ -236,7 +251,10 @@ angular.module('angular-advanced-searchbox', [])
236
251
} ) ;
237
252
238
253
changeBuffer . length = 0 ;
239
- } , 500 ) ;
254
+
255
+ $scope . $emit ( 'advanced-searchbox:modelUpdated' , $scope . model ) ;
256
+
257
+ } , $scope . searchThrottleTime ) ;
240
258
}
241
259
242
260
function getCurrentCaretPosition ( input ) {
@@ -329,7 +347,7 @@ angular.module('angular-advanced-searchbox').run(['$templateCache', function($te
329
347
'use strict' ;
330
348
331
349
$templateCache . put ( 'angular-advanced-searchbox.html' ,
332
- "<div class=advancedSearchBox ng-class={active:focus} ng-init=\"focus = false\" ng-click=\"!focus ? setSearchFocus = true : null\"><span ng-show=\"searchParams.length < 1 && searchQuery.length === 0\" class=\"search-icon glyphicon glyphicon-search\"></span> <a ng-href=\"\" ng-show=\"searchParams.length > 0 || searchQuery.length > 0\" ng-click=removeAll() role=button><span class=\"remove-all-icon glyphicon glyphicon-trash\"></span></a><div><div class=search-parameter ng-repeat=\"searchParam in searchParams\"><a ng-href=\"\" ng-click=removeSearchParam($index) role=button><span class=\"remove glyphicon glyphicon-trash\"></span></a><div class=key>{{searchParam.name}}:</div><div class=value><span ng-if=!searchParam.editMode ng-click=enterEditMode($index)>{{searchParam.value}}</span> <input name=value nit-auto-size-input nit-set-focus=searchParam.editMode ng-keydown=\"keydown($event, $index)\" ng-blur=leaveEditMode($index) ng-if=searchParam.editMode ng-change=searchParamValueChanged(searchParam) ng-model=searchParam.value placeholder=\"{{searchParam.placeholder}}\"></div></div><input name=searchbox class=search-parameter-input nit-auto-size-input nit-set-focus=setSearchFocus ng-keydown=keydown($event) placeholder={{placeholder}} ng-focus=\"focus = true\" ng-blur=\"focus = false\" typeahead-on-select=\"typeaheadOnSelect($item, $model, $label)\" typeahead=\"parameter as parameter.name for parameter in parameters | filter:isUnsedParameter | filter:{name:$viewValue} | limitTo:8\" ng-change=searchQueryChanged(searchQuery) ng-model=\"searchQuery\"></div><div class=search-parameter-suggestions ng-show=\"parameters && focus\"><span class=title>Parameter Suggestions:</span> <span class=search-parameter ng-repeat=\"param in parameters | filter:isUnsedParameter | limitTo:8\" ng-mousedown=addSearchParam(param)>{{param.name}}</span></div></div>"
350
+ "<div class=advancedSearchBox ng-class={active:focus} ng-init=\"focus = false\" ng-click=\"!focus ? setSearchFocus = true : null\"><span ng-show=\"searchParams.length < 1 && searchQuery.length === 0\" class=\"search-icon glyphicon glyphicon-search\"></span> <a ng-href=\"\" ng-show=\"searchParams.length > 0 || searchQuery.length > 0\" ng-click=removeAll() role=button><span class=\"remove-all-icon glyphicon glyphicon-trash\"></span></a><div><div class=search-parameter ng-repeat=\"searchParam in searchParams\"><a ng-href=\"\" ng-click=removeSearchParam($index) role=button><span class=\"remove glyphicon glyphicon-trash\"></span></a><div class=key ng-click=\"enterEditMode($event, $index)\">{{searchParam.name}}:</div><div class=value><span ng-if=!searchParam.editMode ng-click=\"enterEditMode($event, $index)\">{{searchParam.value}}</span> <input name=value nit-auto-size-input nit-set-focus=searchParam.editMode ng-keydown=\"keydown($event, $index)\" ng-blur=\"leaveEditMode($event, $index)\" ng-if=searchParam.editMode ng-change=searchParamValueChanged(searchParam) ng-model=searchParam.value placeholder=\"{{searchParam.placeholder}}\"></div></div><input name=searchbox class=search-parameter-input nit-auto-size-input nit-set-focus=setSearchFocus ng-keydown=keydown($event) placeholder={{placeholder}} ng-focus=\"focus = true\" ng-blur=\"focus = false\" typeahead-on-select=\"typeaheadOnSelect($item, $model, $label)\" typeahead=\"parameter as parameter.name for parameter in parameters | filter:isUnsedParameter | filter:{name:$viewValue} | limitTo:parametersDisplayLimit\" ng-change=searchQueryChanged(searchQuery) ng-model=\"searchQuery\"></div><div class=search-parameter-suggestions ng-show=\"parameters && focus\"><span class=title>{{parametersLabel}}:</span> <span class=search-parameter ng-repeat=\"param in parameters | filter:isUnsedParameter | limitTo:parametersDisplayLimit\" ng-mousedown=addSearchParam(param)>{{param.name}}</span></div></div>"
333
351
) ;
334
352
335
353
} ] ) ;
0 commit comments