with this structure :
<user>
<id>0100007f664e8bad000000f69dd0d652</id>
<login>nicolas</login>
<password>cococo</password>
<name>maisonneuve</name>
<firstname>nicolas</firstname>
<role>user</role>
<email>[EMAIL PROTECTED]</email>
<entreprise>paris5</entreprise>
</user>
in the create action, at the end of the submit, i have to check if the login is already used or not.
i cant create a validation rule despit of the update action (in update action, the login check will be always true and a validation error will be created)
so i make a avalon XMLDBcomponent with the hasResult(Xpath)
and update the file.js with this source code;
but how tell to the user the invalide login error (with validate rule it's easy but with this way i don't know how do)
or can we create a dynamic validatation rule
thank in advance
cocoon.load("resource://org/apache/cocoon/woody/flow/javascript/woody.js") ;
cocoon.load("flow/xmldb.js") ;var display_pipeline = "account-display" ; var sucess_pipeline = "account-sucess" ; var collectionDB = "xmldb:xindice://localhost:8080/db/user" ; var documentID; var document; var action;
function account(form) {
action=cocoon.parameters["action"];
if (action=="update") {
// bind the form with the document with the ID
documentID=cocoon.parameters["documentID"];
document = loadDocument(documentID,collectionDB);
}// shows the form to the user until is validated successfully form.show(display_pipeline, formHandler);
// bind the form's data back to the document form.save(document);
// save the DOM-tree
if (action=="update")
updateDocument(document, documentID,collectionDB);
if (action=="create")
addDocument(document, documentID,collectionDB)cocoon.sendPage(sucess_pipeline);
form.finish();
}
function formHandler(form) {
var model = form.getModel();
if (verify(model))
return true;
else
return false;}
function verify(model) {
// create a ID if the id is null
if (model.id == null)
{
xmldb.setCollection(collectionDB);
model.id=xmldb.generateID();}
// init the user role if it is null
if (model.role ==null)
{
model.role="user";
}
if (action=="create")
{
var results=xmldb.hasResults("//user[login='"+model.login+"' and password='"+model.password+"'");
return (!results);
}
else return true;
}
_________________________________________________________________
MSN Messenger 6 http://g.msn.fr/FR1001/866 : ajoutez une image � votre pseudo pour dialoguer avec vos amis
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
