define(['jquery', 'i18n', 'context'], function($, __, context){
/**
* Enable you to check if the login contained in the field identified by id is unique
* An ajax request is sent to the url with the login and a JSON response {"available": "true"}
* @param id
* @param url
* @return void
*/
function checkLogin(id, url){
var $login = $("input[id='" + id + "']");
if($login.length > 0){
$login.blur(function(){
var elt = $(this);
// trim value
var trimmedValue = elt.val().replace(/^\s+/g,'').replace(/\s+$/g,'');
var value = elt.val();
$('input#http_2_www_0_tao_0_lu_1_Ontologies_1_generis_0_rdf_3_login ~ div.form-error').remove();
if(trimmedValue === ''){
$('span.login-info').remove();
} else{
$.postJson(url,
{ login: value },
function(data){
$('span.login-info').remove();
if(data.available){
elt.after(" " + __('Login available') + "");
} else{
elt.after(" " + __('This Login is already in use') + "");
}
}
);
}
});
}
}
return {
checkLogin : checkLogin
};
});