PageSourceSearch

https://app.nefiks.si/angular/scripts/directives/formFieldDir.js?v=20201107

js nefiks.si collected 2026-10-01 13:06:38 UTC 12,797 bytes, 357 lines download raw bytes

1'use strict';
2
3angular.module('nefiksApp')
4	.directive('formField', function() {
5		return {
6            restrict: 'A',
7            scope: {
8    			placeholder: '@',
9    			label: '@',
10    			fieldName: '@',
11    			ngModel: '=',
12    			ngModelObj: '=',
13    			error: '=',
14    			addDivClass: '@',
15    			onEscape: '&',
16    			onEnter: '&',
17    			disabled: '=',
18    			focusProp: '=',
19    			ckProps: '='
20    		},
21    		controller: function($scope) {
22            },
23            template: function($element, attrs) {
24            	var tmp = '';
25            	
26            	tmp += '<div class="';
27            	if(!attrs.hasOwnProperty('nonFloating')) {
28            		tmp += 'floating-label-form-group ';
29            	}
30            	tmp += 'form-group ';
31            	if(!!attrs.addDivClass) {
32            		tmp += attrs.addDivClass;
33            	}
34            	tmp += '" ng-class="{\'has-error\': !!error}"';
35            	if(!!attrs.sliding) {
36            		tmp += ' sliding-label'
37            	}
38            	tmp += '>';
39            	
40            	if(!!attrs.labelDiv) {
41            		tmp += '<div ng-if="!!label" class="label-div">{{label}}</div>';
42            	} else {
43            		tmp += '<label ng-if="!!label">{{label}}</label>';
44            	}
45            	tmp += '<div ng-if="!!error" class="alert-message">{{error}}</div>';
46            	if('area' == attrs.type) {
47            		tmp += '<textarea placeholder="{{placeholder||label}}" class="form-control" name="{{fieldName}}" ';
48            		if(!!attrs.ngModelProp) {
49	            		tmp += 'ng-model="ngModelObj[\''+attrs.ngModelProp+'\']" ';
50	            	} else {
51	            		tmp += 'ng-model="ngModel" ';
52	            	}
53            		if(!!attrs.rows) {
54            			tmp += ' rows="'+attrs.rows+'"';
55            		}
56            		if(!!attrs.focusProp) {
57            			tmp += ' focus-me focus-prop="focusProp"';
58            			if(!!attrs.focusSelect) {
59            				tmp += ' select-also="true"';
60            			}
61            		}
62            		if(!!attrs.ck) {
63            			tmp += ' ck-editor ck-props="ckProps"'
64            		}
65            		tmp += '></textarea>';
66            	} else {
67	            		tmp += '<input type="';
68		            	if('date' == attrs.type) {
69		            		tmp += 'date';
70		            	} else {
71		            		tmp += (!!attrs.password?'password':'text');
72		            	}
73		            	tmp += '" placeholder="{{placeholder||label}}" class="form-control" name="{{fieldName}}" ';
74		            	if(!!attrs.ngModelProp) {
75		            		tmp += 'ng-model="ngModelObj[\''+attrs.ngModelProp+'\']" ';
76		            	} else {
77		            		tmp += 'ng-model="ngModel" ';
78		            	}
79		            	if(!!attrs.disabled) {
80		            		tmp += ' ng-disabled="disabled"';
81		            	}
82		            	if(!!attrs.asDate) {
83		            		tmp += ' ang-date-picker';
84		            	}
85		            	if(!!attrs.focusProp) {
86	            			tmp += ' focus-me focus-prop="focusProp"';
87	            			if(!!attrs.focusSelect) {
88	            				tmp += ' select-also="true"';
89	            			}
90	            		}
91		            	tmp += '/>';
92            	}
93            	if(!!attrs.after) {
94            		tmp += '<span>'+attrs.after+'</span>';
95            	}
96            	//tmp += '<button type="button" class="btn btn-default"><span class="glyphicon glyphicon-info-sign"></span></button>';
97            	//tmp += '<div class="info-container">Info</div>';
98            	tmp += '</div>';
99            	
100            	return tmp;
101            },
102            link: function($scope, $element, attrs) {
103            	if(!$scope.autoComplete) {
104            		if(!!$scope.onEnter) {
105            			$element.find('input').bind('keypress', function($event) {
106            				if($event.keyCode == 13) {
107            					$scope.$apply($scope.onEnter());
108            					$event.preventDefault();
109            				}
110            			});
111            		}
112            		if(!!$scope.onEscape) {
113            			$element.find('input').bind('keyup', function($event) {
114            				if($event.keyCode == 27) {
115            					$scope.$apply($scope.onEscape());
116            					$event.preventDefault();
117            				}
118            			});
119            		}
120            	}
121            }
122        };
123	}).directive('ffAutoComplete', function() {
124		return {
125            restrict: 'A',
126            scope: {
127				placeholder: '@',
128				label: '@',
129				fieldName: '@',
130				ngModel: '=',
131				ngModelObj: '=',
132				error: '=',
133				addDivClass: '@',
134				searchFn: '&', //On autocomplete
135				selectFn: '&', //On autocomplete
136				searchResults: '=', //On autocomplete
137				searchResultField: '@', //On autocomplete
138				searchShowField: '@', //On autocomplete
139				onEscape: '&',
140				onEnter: '&',
141				disabled: '='
142    		},
143    		controller: function($scope) {
144    			$scope.selectedIndex = -1;
145    			$scope.onKeyDown = function($event) {
146    				if(!$scope.searchResults) {
147    					$scope.selectedIndex = -1;
148    					return;
149    				}
150    				if($event.keyCode == 38) { //Up arrow
151    					$scope.selectedIndex = ($scope.selectedIndex-1)%$scope.searchResults.length;
152    					$event.preventDefault();
153    				} else if($event.keyCode == 40) { //Down arrow
154    					$scope.selectedIndex = ($scope.selectedIndex+1)%$scope.searchResults.length;
155    					$event.preventDefault();
156    				} else if($event.keyCode == 13) { //Enter pressed
157    					$scope.onSelect($scope.searchResults[$scope.selectedIndex]);
158    					$event.preventDefault();
159    				}
160    			};
161    			
162    			var lastSearch = null;
163    			$scope.onKeyUp = function($event) {
164    				if(!!$scope.searchFn && lastSearch!=$event.target.value) {
165    					$scope.searchFn({sq: $event.target.value});
166    				}
167    				lastSearch=$event.target.value;
168    			};
169    			
170    			$scope.prev = {model:null};
171    			$scope.onSelect = function(obj) {
172    				if(!!$scope.ngModelProp) {
173        				$scope.ngModelObj[$scope.ngModelProp] = obj[$scope.searchResultField||$scope.searchShowField];
174        				lastSearch = $scope.ngModelObj[$scope.ngModelProp]; //So search does not get triggered
175    				} else {
176        				$scope.ngModel = obj[$scope.searchResultField||$scope.searchShowField];
177        				lastSearch = $scope.ngModel; //So search does not get triggered
178    				}
179    				$scope.searchResults = [];
180					if(!!$scope.selectFn) {
181						$scope.selectFn({obj: obj});
182					}
183    			};
184            },
185            template: function($element, attrs) {
186            	var tmp = '';
187            	
188            	tmp += '<div class="';
189            	if(!attrs.hasOwnProperty('nonFloating')) {
190            		tmp += 'floating-label-form-group ';
191            	}
192            	tmp += 'form-group ';
193            	if(!!attrs.addDivClass) {
194            		tmp += attrs.addDivClass;
195            	}
196            	tmp += '" ng-class="{\'has-error\': !!error}">';
197            	tmp += '<label ng-if="!!label">{{label}}</label>';
198            	tmp += '<div ng-if="!!error" class="alert-message">{{error}}</div>';
199            	
200        		tmp += '<input type="';
201            	if('date' == attrs.type) {
202            		tmp += 'date';
203            	} else {
204            		tmp += (attrs.fieldName=='password'?'password':'text');
205            	}
206            	tmp += '" placeholder="{{placeholder}}" class="form-control" name="{{fieldName}}" ';
207            	if(!!attrs.ngModelProp) {
208            		tmp += 'ng-model="ngModelObj[\''+attrs.ngModelProp+'\']" ';
209            	} else {
210            		tmp += 'ng-model="ngModel" ';
211            	}
212            	if(!!attrs.disabled) {
213            		tmp += 'ng-disabled="disabled" ';
214            	}
215            	tmp += 'ng-keydown="onKeyDown($event)" ng-keyup="onKeyUp($event)">';
216            	tmp += '<div ng-show="!!searchShowField" class=\"ac-results\">';
217            	tmp += '<div class=\"ac-result\" ng-class="{selected: $index==selectedIndex}" ng-repeat="r in searchResults" ng-click="onSelect(r)">';
218            	tmp += '{{r[searchShowField]}}';
219            	tmp += '</div>';
220            	tmp += '</div>'; //End ac-results
221            	
222            	if(!!attrs.after) {
223            		tmp += '<span>'+attrs.after+'</span>';
224            	}
225            	tmp += '</div>';
226            	return tmp;
227            },
228            link: function($scope, $element, attrs) {
229            	var watchExpr = 'ngModel';
230            	if(!!attrs.ngModelProp) {
231            		watchExpr = 'ngModelObj[\''+attrs.ngModelProp+'\']';
232            	}
233            	$scope.$watch(watchExpr, function(newValue) {
234            		/*
235            		if(!!$scope.searchFn && $scope.prev.model!=newValue) {
236            			$scope.searchFn({sq: newValue});
237            		}
238            		$scope.prev.model = newValue;
239            		*/
240            	});
241            }
242        };
243	}).directive('formFieldIcon', function() {
244		return {
245            restrict: 'A',
246            scope: {
247    			placeholder: '@',
248    			label: '@',
249    			fieldName: '@',
250    			ngModel: '=',
251    			error: '=',
252    			addDivClass: '@',
253    			iconClass: '@',
254    			searchFn: '&', //On autocomplete
255    			selectFn: '&', //On autocomplete
256    			searchResults: '=', //On autocomplete
257    			searchResultField: '@', //On autocomplete
258    			onEscape: '&',
259    			onEnter: '&'
260    		},
261    		controller: function($scope) {
262    			$scope.acSearchFn = function(sq) {
263    				if(!!$scope.searchFn) {
264    					$scope.searchFn({sq: sq});
265    				}
266    			};
267    			$scope.acSelectFn = function(obj) {
268    				if(!!$scope.selectFn) {
269    					$scope.selectFn({obj: obj});
270    				}
271    			};
272            },
273            template: function($element, attrs) {
274            	var tmp = '';
275            	
276            	tmp += '<div class="form-group with-icon ';
277            	if(!!attrs.addDivClass) {
278            		tmp += attrs.addDivClass;
279            	}
280            	tmp += '" ng-class="{\'has-error\': !!error}">';
281            	tmp += '<div ng-if="!!error" class="alert-message">{{error}}</div>';
282            	tmp += '<i class="icon {{iconClass}}" title="{{label||placeholder}}"></i> ';
283	    		if(!!attrs.autoComplete) {
284	        		tmp += '<span ff-auto-complete search-fn="acSearchFn(sq)" select-fn="acSelectFn(obj)" placeholder="{{placeholder}}" name="{{fieldName}}" ng-model="ngModel" results="searchResults" text-field="{{searchResultField}}"></span>';
285	        	} else {
286	        		tmp += '<input type="';
287	            	if('date' == attrs.type) {
288	            		tmp += 'date';
289	            	} else {
290	            		tmp += (attrs.fieldName=='password'?'password':'text');
291	            	}
292	            	tmp += '" placeholder="{{placeholder}}" class="form-control" name="{{fieldName}}" ng-model="ngModel"';
293	            	if(!!attrs.asDate) {
294	            		tmp += ' ang-date-picker';
295	            	}
296	            	tmp += '>';
297	        	}
298	    		if(!!attrs.after) {
299            		tmp += '<span>'+attrs.after+'</span>';
300            	}
301            	tmp += '</div>';
302            	
303            	return tmp;
304            },
305            link: function($scope, $element, attrs) {
306            	if(!attrs.autoComplete) {
307            		if(!!$scope.onEnter) {
308            			$element.find('input').bind('keypress', function($event) {
309            				if($event.keyCode == 13) {
310            					$scope.$apply($scope.onEnter());
311            					$event.preventDefault();
312            				}
313            			});
314            		}
315            		if(!!$scope.onEscape) {
316            			$element.find('input').bind('keyup', function($event) {
317            				if($event.keyCode == 27) {
318            					$scope.$apply($scope.onEscape());
319            					$event.preventDefault();
320            				}
321            			});
322            		}
323            	}
324            	if(!!attrs.asDate) {
325            		$element.find('i.icon').bind('click', function() {
326            			$element.find('input').focus();
327            		});
328            	}
329            }
330        };
331	}).directive('formFieldCheck', function() {
332		return {
333            restrict: 'A',
334            scope: {
335    			label: '@',
336    			checkId: '@',
337    			ngModel: '=',
338    			error: '=',
339    			disabled: '=',
340    			bolded: '@'
341    		},
342    		replace: 'true',
343    		controller: function($scope) {
344            },
345            template: function($element, attrs) {
346            	var tmp = '';
347            	
348            	tmp += '<div class="checkbox" ng-class="{\'has-error\': !!error}">';
349            	tmp += '<div ng-if="!!error" class="alert-message">{{error}}</div>';
350            	tmp += '<input type="checkbox" id="{{checkId}}" ng-model="ngModel" ng-value="true"/>';
351            	tmp += '<label for="{{checkId}}"><span class="label" ng-bind-html="'+(!!attrs.bolded?'\'<b>
351\'+label+\'</b>\'':'label')+'"></span></label>';            	
352            	tmp += '</div>';
353            	
354            	return tmp;
355            }
356        };
357	});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.