PageSourceSearch

https://artparis.fr/static/js/public_gui/masters/gallerist_zone/TextRealtimeSetter.js

js artparis.fr collected 2026-09-26 06:17:35 UTC 2,871 bytes, 102 lines download raw bytes

1AP.GalleristZone.TextRealtimeSetter = new JS.Class(AP.GalleristZone.RealtimeSetter, {
2
3	extend: {
4		EMAIL_REGEXP: null
5	},
6
7	field_name:null,
8
9	initialize: function($observed, model, validity_selector) {
10		if ($observed.length == 0) return; // the field does not exist in the page
11		if (null == AP.GalleristZone.TextRealtimeSetter.EMAIL_REGEXP) {
12			AP.GalleristZone.TextRealtimeSetter.EMAIL_REGEXP = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
13		}
14		if (null == AP.GalleristZone.TextRealtimeSetter.MOBPHONE_REGEXP) {
15			AP.GalleristZone.TextRealtimeSetter.MOBPHONE_REGEXP = /^(\+|00)[0-9]{1,3}[0-9]{4,14}(?:x.+)?$/;
16		}
17		if ('undefined' == typeof validity_selector) {
18			validity_selector = 'input[type=text][name],textarea[name],input[type=file] ';
19		}
20		if ( ! $observed.is(validity_selector)) {
21			throw "AP.GalleristZone.TextRealtimeSetter.initialize() : unexpected $observed";
22		}
23		this.field_name = $observed.attr('name');
24		this.callSuper($observed, model);
25	},
26
27	fillView : function() {
28		var v = this.model.properties[this.field_name];
29		//console.log(this.$observed, propvalue);
30		if (v == 0) v = '';
31		this.$observed.val(v);
32	},
33
34	setObservers : function() {
35		var me = this;
36		this.$observed.keyup(function() {
37			me.schedulePersistancy();
38		})
39		.bind('keyup change', function() {
40			me.unmarkError();
41			me.schedulePersistancy();
42		});
43	},
44
45	isEmail: function() {
46		return this.field_name.match(/mail/);
47	},
48	
49	isMobile: function() {
50		return this.field_name.match(/phone/);
51	},
52
53	persist: function() {
54		var val = this.$observed.val();
55		if (this.isEmail()) {
56			if ( ! val.match(AP.GalleristZone.TextRealtimeSetter.EMAIL_REGEXP)
57					&& ! val.match(/@localhost$/)) { // @localhost : testing in virtual machine
58				return;
59			}
60		}
61		if (! this.model.persist(this.field_name,  val)) {
62			this.fillView(); // reverting user input
63		}
64	},
65
66	markError: function() {
67		this.$observed.addClass('error_on_field');
68	},
69
70	unmarkError: function() {
71		if(!this.$observed.hasClass('error_on_length')){
72			this.$observed.removeClass('error_on_field');
73			this.$observed.css('background', '');
74		}
75	},
76
77	check : function() {
78		var me = this;
79		var result = { ok : true };
80		var val = this.$observed.val();
81		result.ok = result.ok && '' != val;
82		if (this.isEmail()) {
83			result.ok = result.ok && (
84					val.match(AP.GalleristZone.TextRealtimeSetter.EMAIL_REGEXP)
85					|| val.match(/@localhost$/) // @localhost : testing in virtual machine
86			);
87		}
88		if (this.isMobile()) {
89			result.ok = result.ok && (
90					val.match(AP.GalleristZone.TextRealtimeSetter.MOBPHONE_REGEXP)
91			);
92		}
93		if ( ! result.ok) {
94			if (this.i_manage_error_marking_myself) {
95				this.markError();
96			}
97			result.message = this.field_name+' : empty';
98		}
99		return result;
100	}
101});
102

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.