2007-07-19 12:40:28 +02:00
|
|
|
UniqueFormField = Class.create();
|
|
|
|
UniqueFormField.prototype = {
|
|
|
|
validate: function() {
|
|
|
|
// check that the value is not in use, and matches the pattern
|
|
|
|
var suggested = this.value;
|
|
|
|
|
2008-09-23 00:50:13 +02:00
|
|
|
if( this.restrictedValues[suggested] || suggested == null ) {
|
|
|
|
suggested = this.suggestNewValue();
|
2008-10-03 02:47:08 +02:00
|
|
|
statusMessage(ss.i18n.sprintf(
|
2009-03-10 23:08:52 +01:00
|
|
|
ss.i18n._t('UNIQUEFIELD.SUGGESTED', "Changed value to '%s' : %s"),
|
2008-10-03 02:47:08 +02:00
|
|
|
suggested,
|
|
|
|
this.restrictedMessage
|
|
|
|
));
|
2008-09-23 00:50:13 +02:00
|
|
|
this.value = suggested;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
suggestNewValue: function() {
|
|
|
|
var parts = this.value.match( /(.*)(\d+)$/ );
|
|
|
|
var prefix = '';
|
|
|
|
var count = 1;
|
|
|
|
|
|
|
|
|
|
|
|
if( parts )
|
|
|
|
prefix = parts[1];
|
|
|
|
else
|
|
|
|
prefix = this.value;
|
|
|
|
|
|
|
|
if( prefix.charAt(prefix.length-1) != ' ' )
|
|
|
|
prefix = prefix + ' ';
|
|
|
|
|
|
|
|
var suggested = prefix + count;
|
|
|
|
|
|
|
|
while( this.restrictedValues[suggested] )
|
|
|
|
suggested = prefix + (++count);
|
|
|
|
|
|
|
|
return suggested;
|
|
|
|
}
|
|
|
|
}
|