incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gert Cuykens <gert.cuyk...@gmail.com>
Subject generate _update body using _show function
Date Sun, 25 Sep 2011 23:33:06 GMT
Can you call a show function inside a update function to generate a update body?
Example
{
 "updates":{
  "post":"function(doc,req){
   for(i in req.form)doc[i]=req.form[i]
   return [doc,{'headers':{'Content-Type':'text/html'},
                'body':'\
<label>adress:</label>  <input name=\"adress\"
value=\"'+doc.adress+'\"/><br/>\\n\
<label>city:</label>    <input name=\"city\"
value=\"'+doc.city+'\"/><br/>\\n\
<label>country:</label> <input name=\"country\"
value=\"'+doc.country+'\"/><br/>\\n\
<label>phone:</label>   <input name=\"phone\"
value=\"'+doc.phone+'\"/><br/>\\n\
<label>email:</label>   <input name=\"email\"
value=\"'+doc.email+'\"/><br/>\\n\
<input name=\"_id\"  value=\"'+doc._id+'\"  type=\"hidden\"/>\\n\
<input name=\"_rev\" value=\"'+doc._rev+'\" type=\"hidden\"/>\\n\
<img id=\"picture\" src=\"/users/'+doc._id+'/picture.png\"/>'
   }]
  }"
 },
 "shows":{
  "html":"function(doc,req){
   return {headers:{'Content-Type':'text/html'},
           body:'\
<label>adress:</label>  <input name=\"adress\"
value=\"'+doc.adress+'\"/><br/>\\n\
<label>city:</label>    <input name=\"city\"
value=\"'+doc.city+'\"/><br/>\\n\
<label>country:</label> <input name=\"country\"
value=\"'+doc.country+'\"/><br/>\\n\
<label>phone:</label>   <input name=\"phone\"
value=\"'+doc.phone+'\"/><br/>\\n\
<label>email:</label>   <input name=\"email\"
value=\"'+doc.email+'\"/><br/>\\n\
<input name=\"_id\"  value=\"'+doc._id+'\"  type=\"hidden\"/>\\n\
<input name=\"_rev\" value=\"'+doc._rev+'\" type=\"hidden\"/>\\n\
<img id=\"picture\" src=\"/users/'+doc._id+'/picture.png\"/>'
   }
  }"
 }
}

Mime
View raw message