1/** 2 * Controller used in views using Intake 3 */ 4angular.module('irk') 5 .controller('IntakeControllerMixin', function ($scope, toaster, i18n) { 6 7 /** Json version of RestIntakeGroupMap class */ 8 $scope.gidGroupMap = null; 9 /** Map<intakeField.id, field> */ 10 $scope.fieldIdMap = {}; 11 12 $scope.tooltipContent = { 13 title: '', 14 subtitle: '' 15 }; 16 i18n.get('interfejs.irk.shared.intake.TytulTooltipa').then(function(value) { 17 $scope.tooltipContent.title = value; 18 }); 19 i18n.get('interfejs.irk.shared.intake.PodtytulTooltipa').then(function(value) { 20 $scope.tooltipContent.subtitle = value; 21 }); 22 23 $scope.updateGroup = function(groupMap) { 24 if(!groupMap.valid) { 25 toaster.pop('error', $scope.tooltipContent.title, $scope.tooltipContent.subtitle); 26 } 27 $scope.gidGroupMap = groupMap.gidGroupMap; 28 $scope.fieldIdMap = {}; 29 for(var gid in $scope.gidGroupMap) { 30 var oidGroupMap = $scope.gidGroupMap[gid]; 31 for(var oid in oidGroupMap) { 32 var group = oidGroupMap[oid]; 33 var fieldMap = group.fieldMap; 34 for(var fieldName in fieldMap) { 35 var field = fieldMap[fieldName]; 36 $scope.fieldIdMap[field.key] = field; 37 } 38 } 39 } 40 }; 41 42 $scope.removeGroup = function(intakeGroup) { 43 for(var group in $scope.gidGroupMap) { 44 for(var key in $scope.gidGroupMap[group]) { 45 if($scope.gidGroupMap[group][key].fieldMap == intakeGroup) { 46 delete $scope.gidGroupMap[group][key]; 47 } 48 } 49 } 50 }; 51 52 }).directive('intakeValidate', function() { 53 return { 54 restrict: 'A', 55 require: 'ngModel', 56 57 link: function(scope, _elem, _attr, ctrl) { 58 scope.$watch('intakeField', function() { 59 if(typeof scope.intakeField !== 'undefined') { 60 var value = angular.copy(scope.intakeField.value); 61 var valid = scope.intakeField.valid; 62 ctrl.$setValidity('intakeValidate', valid); 63 return value; 64 } 65 return undefined; 66 }); 67 } 68 }; 69 }).directive('stepValidate', function() { 70 return { 71 restrict: 'A', 72 require: 'ngModel', 73 74 link: function(scope, _elem, attr, ctrl) { 75 if(scope.step) { 76 //dodanie implementacji validatora "step" z angularjs 1.6 77 ctrl.$validators["step"] = function(value) { 78 if(value == null || Number.isNaN(value)) { 79 return true; 80 } 81 return isValidForStep(value, scope.min || 0, scope.step); 82 }; 83 scope.$watch(attr["ngModel"], function(value) { 84 //zaÅadowanie wartoÅci modelu w przypadku zaokrÄ glenia 85 //wywoÅanego zbyt duÅ¼Ä liczbÄ miejsc po przecinku 86 if(value != null) { 87 ctrl.$render(); 88 } 89 }); 90 } 91 } 92 }; 93 }).directive('intakeInput', function(i18n) { 94 return { 95 restrict: 'E', 96 require: '^form', 97 scope: { 98 selectValues: '=selectValues', 99 intakeField: '=intakeField', 100 label: '@label', 101 i18n: '@i18n', 102 enableInitCap: '@enableInitCap', 103 pattern: '@pattern', 104 required: '@required', 105 min: '@min', 106 max: '@max', 107 step: '@step', 108 keyExtender: '@keyExtender' 109 }, 110 link: function(scope, _element, attrs, formCtrl) { 111 if(attrs.pattern) { 112 var match = attrs.pattern.match(/^\/(.*?)\/([gimy]*)$/); 113 scope.parsedPattern = new RegExp(match[1], match[2]); 114 } 115 scope.form = formCtrl; 116 scope.datePicker = undefined; 117 scope.fieldRequired = attrs.required; 118 scope.$watch('intakeField', function() { 119 if(!angular.isUndefined(scope.intakeField)) { 120 if(angular.isUndefined(attrs.required)) { 121 scope.fieldRequired = scope.intakeField.required; 122 } 123 if(scope.intakeField.message && scope.intakeField.message.length > 0) { 124 i18n.get(scope.intakeField.message).then(function(value) { 125 scope.messageI18n = value; 126 }); 127 } 128 else { 129 scope.messageI18n = null; 130 } 131 if(scope.intakeField.key) { 132 scope.intakeKey = scope.intakeField.key; 133 if(scope.keyExtender) { 134 scope.intakeKey = scope.intakeKey + '_' + scope.keyExtender; 135 } 136 } 137 if(scope.intakeField.id) { 138 scope.intakeId = scope.intakeField.id; 139 if(scope.keyExtender) { 140 scope.intakeId = scope.intakeId + '_' + scope.keyExtender; 141 } 142 } 143 // Ustawienie wartoÅci domyÅlnej pól wielowartoÅciowych, 144 // ponieważ gdy nie majÄ wartoÅci to nie pokazujÄ siÄ w 145 // widoku. 146 if(scope.intakeField.multiValued && (!scope.intakeField.value || !scope.intakeField.value.length)) { 147 scope.intakeField.value = [null]; 148 } 149 } 150 }); 151 scope.usunWartosc = function(intakeField, index) { 152 if(typeof intakeField.value == 'undefined' || intakeField.value == null) { 153 return; 154 } 155 intakeField.value.splice(index, 1); 156 }; 157 scope.dodajWartosc = function(intakeField) { 158 if(typeof intakeField.value == 'undefined' || intakeField.value == null) { 159 intakeField.value = []; 160 } 161 intakeField.value.push(''); 162 }; 163 scope.isMultiValuedInvalid = function() { 164 var formElement = scope.form[scope.intakeKey]; 165 if(formElement) {
166 return formElement.$invalid; 167 } 168 return !scope.intakeField.valid; 169 }; 170 scope.togglePassword = function() { 171 var passwordField = document.getElementById(scope.intakeId); 172 var eyeIcon = document.getElementById(scope.intakeId + "-eye-icon"); 173 if(passwordField.type === "password") { 174 passwordField.type = "text"; 175 eyeIcon.classList.remove("glyphicon-eye-close"); 176 eyeIcon.classList.add("glyphicon-eye-open"); 177 } else { 178 passwordField.type = "password"; 179 eyeIcon.classList.remove("glyphicon-eye-open"); 180 eyeIcon.classList.add("glyphicon-eye-close"); 181 } 182 }; 183 if(attrs.type == 'boolean') { 184 i18n.get('interfejs.irk.shared.Yes').then(function(value) { 185 scope.yes = value; 186 }); 187 i18n.get('interfejs.irk.shared.No').then(function(value) { 188 scope.no = value; 189 }); 190 } 191 else if(attrs.type == 'date') { 192 scope.open = function($event) { 193 $event.preventDefault(); 194 $event.stopPropagation(); 195 196 scope.opened = true; 197 }; 198 199 scope.dateChange = function(_$event) { 200 if(!angular.isUndefined(scope.datePicker) && scope.datePicker != null) { 201 scope.intakeField.value = moment(scope.datePicker).format('DD.MM.YYYY'); 202 } 203 else { 204 scope.intakeField.value = undefined; 205 } 206 } 207 208 scope.$watch('intakeField', function() { 209 if(!angular.isUndefined(scope.intakeField)) { 210 if(!angular.isUndefined(scope.intakeField.value) && scope.intakeField.value != null && scope.intakeField.value != '') { 211 scope.datePicker = moment(scope.intakeField.value, "DD.MM.YYYY").toDate(); 212 } 213 else { 214 scope.datePicker = undefined; 215 } 216 } 217 }) 218 219 scope.dateOptions = { 220 formatYear: 'yy', 221 startingDay: 1 222 }; 223 } 224 else if(attrs.type == 'typeahead') { 225 var stopWatchIntake = scope.$watch('intakeField.value', function(value) { 226 if(!angular.isUndefined(value)) { 227 var stopWatchSelectValues = scope.$watch('selectValues', function(selectValues) { 228 if(!angular.isUndefined(selectValues)) { 229 var last = scope.selectValues.length-1; 230 var stopWatchLabel = scope.$watch('selectValues['+last+'].label', function(label) { 231 var found = undefined; 232 selectValues.forEach(function(option) { 233 if(option.value == value) { 234 found = option; 235 return; 236 } 237 }); 238 scope.typeaheadValue = angular.copy(found); 239 stopWatchSelectValues(); 240 stopWatchIntake(); 241 }); 242 } 243 }); 244 } 245 }); 246 scope.typeaheadChange = function() { 247 if(angular.isUndefined(scope.typeaheadValue)) { 248 return; 249 } 250 if(scope.typeaheadValue.value) { 251 scope.intakeField.value = scope.typeaheadValue.value; 252 } 253 else { 254 scope.intakeField.value = scope.typeaheadValue; 255 } 256 } 257 } 258 else if(attrs.type == 'number') {
259 var updateValue = function() { 260 if(scope.step) { 261 scope.intakeField.value = parseFloat(scope.intakeField.value); 262 } 263 else { 264 scope.intakeField.value = parseInt(scope.intakeField.value, 10); 265 } 266 } 267 scope.$watch('intakeField', updateValue); 268 updateValue(); 269 } 270 else if(attrs.type == 'number-select') { 271 var parsedValue = parseInt(scope.intakeField.value, 10); 272 scope.intakeField.value = isNaN(parsedValue) ? null : parsedValue; 273 scope.$watchGroup(['min', 'max'], function() { 274 var selectNumbers = []; 275 for(var i = parseInt(scope.min); i <= parseInt(scope.max); ++i) { 276 selectNumbers.push(i); 277 } 278 scope.selectNumbers = selectNumbers; 279 }); 280 } 281 282 scope.getContentUrl = function() { 283 switch(attrs.type) { 284 case 'hidden': 285 return '../../content/script/irk/mixins/intake/intakeControllerMixin/intakeInputHidden.html' 286 case 'password': 287 return '../../content/script/irk/mixins/intake/intakeControllerMixin/intakeInputPassword.html' 288 case 'password-toggleable': 289 return '../../content/script/irk/mixins/intake/intakeControllerMixin/intakeInputPasswordToggleable.html' 290 case 'date': 291 return '../../content/script/irk/mixins/intake/intakeControllerMixin/intakeInputDate.html' 292 case 'email': 293 return '../../content/script/irk/mixins/intake/intakeControllerMixin/intakeInputEmail.html' 294 case 'select': 295 return '../../content/script/irk/mixins/intake/intakeControllerMixin/intakeInputSelect.html' 296 case 'typeahead': 297 return '../../content/script/irk/mixins/intake/intakeControllerMixin/intakeInputTypeahead.html' 298 case 'boolean': 299 return '../../content/script/irk/mixins/intake/intakeControllerMixin/intakeInputBoolean.html' 300 case 'checkbox': 301 return '../../content/script/irk/mixins/intake/intakeControllerMixin/intakeInputCheckbox.html' 302 case 'checkbox-block': 303 return '../../content/script/irk/mixins/intake/intakeControllerMixin/intakeInputCheckboxBlock.html' 304 case 'textarea': 305 return '../../content/script/irk/mixins/intake/intakeControllerMixin/intakeInputTextarea.html' 306 case 'number': 307 return '../../content/script/irk/mixins/intake/intakeControllerMixin/intakeInputNumber.html' 308 case 'number-select': 309 return '../../content/script/irk/mixins/intake/intakeControllerMixin/intakeInputNumberSelect.html' 310 default: 311 return '../../content/script/irk/mixins/intake/intakeControllerMixin/intakeInputText.html' 312 } 313 }; 314 }, 315 template: '<div ng-include="getContentUrl()"></div>' 316 }; 317 });
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.