Add scripts to create myops-getqueryview:
[myops.git] / web / query / vendor / couchapp / evently / profile / noProfile / selectors / form / submit.js
1 function() {
2   var md5 = $$(this).app.require("vendor/couchapp/lib/md5");
3   
4   // TODO this can be cleaned up with docForm?
5   // it still needs the workflow to edit an existing profile
6   var name = $("input[name=userCtxName]",this).val();
7   var newProfile = {
8     rand : Math.random().toString(), 
9     nickname : $("input[name=nickname]",this).val(),
10     email : $("input[name=email]",this).val(),
11     url : $("input[name=url]",this).val()
12   }, widget = $(this);
13
14   // setup gravatar_url
15   if (md5) {
16     newProfile.gravatar_url = 'http://www.gravatar.com/avatar/'+md5.hex(newProfile.email || newProfile.rand)+'.jpg?s=40&d=identicon';    
17   }
18
19   // store the user profile on the user account document
20   $.couch.userDb(function(db) {
21     var userDocId = "org.couchdb.user:"+name;
22     db.openDoc(userDocId, {
23       success : function(userDoc) {
24         userDoc["couch.app.profile"] = newProfile;
25         db.saveDoc(userDoc, {
26           success : function() {
27             newProfile.name = userDoc.name;
28             $$(widget).profile = newProfile;
29             widget.trigger("profileReady", [newProfile]);
30           }
31         });
32       }
33     });
34   });
35   return false;
36 }