1BX.namespace("BX.UI"); 2 3if(typeof BX.UI.EntityValidator === "undefined") 4{ 5 BX.UI.EntityValidator = function() 6 { 7 this._settings = {}; 8 this._editor = null; 9 this._data = null; 10 }; 11 BX.UI.EntityValidator.prototype = 12 { 13 initialize: function(settings) 14 { 15 this._settings = settings ? settings : {}; 16 this._editor = BX.prop.get(this._settings, "editor", null); 17 this._data = BX.prop.getObject(this._settings, "data", {}); 18 19 this.doInitialize(); 20 }, 21 doInitialize: function() 22 { 23 }, 24 release: function() 25 { 26 }, 27 getData: function() 28 { 29 return this._data; 30 }, 31 getDataStringParam: function(name, defaultValue) 32 { 33 return BX.prop.getString(this._data, name, defaultValue); 34 }, 35 getErrorMessage: function() 36 { 37 return BX.prop.getString(this._settings, "message", ""); 38 }, 39 validate: function(result) 40 { 41 return true; 42 }, 43 processControlChange: function(control) 44 { 45 } 46 }; 47} 48 49if(typeof BX.UI.EntityPersonValidator === "undefined") 50{ 51 BX.UI.EntityPersonValidator = function() 52 { 53 BX.UI.EntityPersonValidator.superclass.constructor.apply(this); 54 }; 55 56 BX.extend(BX.UI.EntityPersonValidator, BX.UI.EntityValidator); 57 58 BX.UI.EntityPersonValidator.prototype.doInitialize = function() 59 { 60 this._nameField = this._editor.getControlById( 61 this.getDataStringParam("nameField", "") 62 ); 63 if(this._nameField) 64 { 65 this._nameField.addValidator(this); 66 } 67 68 this._lastNameField = this._editor.getControlById( 69 this.getDataStringParam("lastNameField", "") 70 ); 71 if(this._lastNameField) 72 { 73 this._lastNameField.addValidator(this); 74 } 75 }; 76 BX.UI.EntityPersonValidator.prototype.release = function() 77 { 78 if(this._nameField) 79 { 80 this._nameField.removeValidator(this); 81 } 82 83 if(this._lastNameField) 84 { 85 this._lastNameField.removeValidator(this); 86 } 87 }; 88 BX.UI.EntityPersonValidator.prototype.validate = function(result) 89 { 90 var isNameActive = this._nameField.isActive(); 91 var isLastNameActive = this._lastNameField.isActive(); 92 93 if(!isNameActive && !isLastNameActive) 94 { 95 return true; 96 } 97 98 var name = isNameActive ? this._nameField.getRuntimeValue() : this._nameField.getValue(); 99 var lastName = isLastNameActive ? this._lastNameField.getRuntimeValue() : this._lastNameField.getValue(); 100 101 if(name !== "" || lastName !== "") 102 { 103 return true; 104 } 105 106 if(name === "" && isNameActive) 107 { 108 result.addError(BX.UI.EntityValidationError.create({ field: this._nameField })); 109 this._nameField.showError(this.getErrorMessage()); 110 } 111 112 if(lastName === "" && isLastNameActive) 113 { 114 result.addError(BX.UI.EntityValidationError.create({ field: this._lastNameField })); 115 this._lastNameField.showError(this.getErrorMessage()); 116 } 117 118 return false; 119 }; 120 BX.UI.EntityPersonValidator.prototype.processFieldChange = function(field) 121 { 122 if(field !== this._nameField && field !== this._lastNameField) 123 { 124 return; 125 } 126 127 if(this._nameField) 128 { 129 this._nameField.clearError(); 130 } 131 132 if(this._lastNameField) 133 { 134 this._lastNameField.clearError(); 135 } 136 }; 137 BX.UI.EntityPersonValidator.create = function(settings) 138 { 139 var self = new BX.UI.EntityPersonValidator(); 140 self.initialize(settings); 141 return self; 142 }; 143} 144 145if(typeof BX.UI.EntityValidationError === "undefined") 146{ 147 BX.UI.EntityValidationError = function() 148 { 149 this._settings = {}; 150 this._field = null; 151 this._message = ""; 152 }; 153 BX.UI.EntityValidationError.prototype = 154 { 155 initialize: function(settings) 156 { 157 this._settings = settings ? settings : {}; 158 this._field = BX.prop.get(this._settings, "field", null); 159 this._message = BX.prop.getString(this._settings, "message", ""); 160 }, 161 getField: function() 162 { 163 return this._field; 164 }, 165 getMessage: function() 166 { 167 return this._message; 168 } 169 }; 170 BX.UI.EntityValidationError.create = function(settings) 171 { 172 var self = new BX.UI.EntityValidationError(); 173 self.initialize(settings); 174 return self; 175 }; 176} 177 178if(typeof BX.UI.EntityValidationResult === "undefined") 179{ 180 BX.UI.EntityValidationResult = function() 181 { 182 this._settings = {}; 183 this._errors = []; 184 }; 185 BX.UI.EntityValidationResult.prototype = 186 { 187 initialize: function(settings) 188 { 189 this._settings = settings ? settings : {}; 190 },
191 getStatus: function() 192 { 193 return this._errors.length === 0; 194 }, 195 addError: function(error) 196 { 197 this._errors.push(error); 198 }, 199 getErrors: function() 200 { 201 return this._errors; 202 }, 203 addResult: function(result) 204 { 205 var errors = result.getErrors(); 206 for(var i = 0, length = errors.length; i < length; i++) 207 { 208 this._errors.push(errors[i]); 209 } 210 }, 211 getTopmostField: function() 212 { 213 var field = null; 214 var top = null; 215 for(var i = 0, length = this._errors.length; i < length; i++) 216 { 217 var currentField = this._errors[i].getField(); 218 if(!field) 219 { 220 field = currentField; 221 top = currentField.getPosition()["top"]; 222 continue; 223 224 } 225 var pos = currentField.getPosition(); 226 if(!pos) 227 { 228 continue; 229 } 230 231 var currentFieldTop = currentField.getPosition()["top"]; 232 if(currentFieldTop < top) 233 { 234 field = currentField; 235 top = currentFieldTop; 236 } 237 } 238 239 return field; 240 } 241 }; 242 BX.UI.EntityValidationResult.create = function(settings) 243 { 244 var self = new BX.UI.EntityValidationResult(); 245 self.initialize(settings); 246 return self; 247 }; 248} 249if(typeof BX.UI.EntityAsyncValidator === "undefined") 250{ 251 BX.UI.EntityAsyncValidator = function() 252 { 253 this.promisesList = []; 254 this.isValid = true; 255 }; 256 BX.UI.EntityAsyncValidator.prototype = 257 { 258 addResult: function(validationResult) 259 { 260 if (validationResult instanceof Promise || validationResult instanceof BX.Promise) 261 { 262 this.promisesList.push(validationResult); 263 } 264 else 265 { 266 this.isValid = (this.isValid && validationResult); 267 } 268 }, 269 validate: function() 270 { 271 if (this.promisesList.length) 272 { 273 return Promise.all(this.promisesList); 274 } 275 276 return this.isValid; 277 } 278 }; 279 BX.UI.EntityAsyncValidator.create = function() 280 { 281 return new BX.UI.EntityAsyncValidator(); 282 }; 283} 284 285if(typeof BX.UI.EntityTrackingSourceValidator === "undefined") 286{ 287 BX.UI.EntityTrackingSourceValidator = function() 288 { 289 BX.UI.EntityTrackingSourceValidator.superclass.constructor.apply(this); 290 }; 291 292 BX.extend(BX.UI.EntityTrackingSourceValidator, BX.UI.EntityValidator); 293 294 BX.UI.EntityTrackingSourceValidator.prototype.doInitialize = function() 295 { 296 this._trackingSourceField = this._editor.getControlById( 297 this.getDataStringParam("fieldName", "") 298 ); 299 if(this._trackingSourceField) 300 { 301 this._trackingSourceField.addValidator(this); 302 } 303 }; 304 BX.UI.EntityTrackingSourceValidator.prototype.release = function() 305 { 306 if(this._trackingSourceField) 307 { 308 this._trackingSourceField.removeValidator(this); 309 } 310 }; 311 BX.UI.EntityTrackingSourceValidator.prototype.validate = function(result) 312 { 313 var isActive = this._trackingSourceField.isActive(); 314 var value = ""; 315 var select; 316 317 if(!isActive 318 || !(this._trackingSourceField.isRequired() 319 || this._trackingSourceField.isRequiredByAttribute())) 320 { 321 return true; 322 } 323 324 if (isActive) 325 { 326 if (this._trackingSourceField.hasOwnProperty("_innerWrapper") 327 && BX.Type.isDomNode(this._trackingSourceField["_innerWrapper"])) 328 { 329 select = this._trackingSourceField["_innerWrapper"].querySelector( 330 "select[name=" + this._trackingSourceField.getId().replace(/["\\]/g, '\\$&') + "]" 331 ); 332 if (select) 333 { 334 value = select.value; 335 } 336 } 337 } 338 else 339 { 340 value = this._trackingSourceField.getValue(); 341 } 342 343 if(value !== "") 344 { 345 return true; 346 } 347 348 if(value === "" && isActive) 349 { 350 result.addError(BX.UI.EntityValidationError.create({ field: this._trackingSourceField })); 351 this._trackingSourceField.showError(this._trackingSourceField.getMessage("requiredFieldError")); 352 } 353 354 return false; 355 }; 356 BX.UI.EntityTrackingSourceValidator.prototype.processFieldChange = function(field) 357 { 358 if(field !== this._trackingSourceField) 359 { 360 return; 361 } 362 363 if(this._trackingSourceField) 364 { 365 this._trackingSourceField.clearError(); 366 } 367 }; 368 BX.UI.EntityTrackingSourceValidator.create = function(settings) 369 { 370 var self = new BX.UI.EntityTrackingSourceValidator(); 371 self.initialize(settings); 372 return self; 373 }; 374}
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.