X-Git-Url: http://git.onelab.eu/?p=myops.git;a=blobdiff_plain;f=web%2Fquery%2Fvendor%2Fcouchapp%2Fevently%2Fprofile%2FnoProfile%2Fselectors%2Fform%2Fsubmit.js;fp=web%2Fquery%2Fvendor%2Fcouchapp%2Fevently%2Fprofile%2FnoProfile%2Fselectors%2Fform%2Fsubmit.js;h=2f21530d41cc4e9412ef4684acfc250b92f2a72b;hp=0000000000000000000000000000000000000000;hb=85070b3d456667f238051af1a2f1f2a0c12300ab;hpb=607f0e13927eb18075c375fa9ba5527da4fcbb44 diff --git a/web/query/vendor/couchapp/evently/profile/noProfile/selectors/form/submit.js b/web/query/vendor/couchapp/evently/profile/noProfile/selectors/form/submit.js new file mode 100644 index 0000000..2f21530 --- /dev/null +++ b/web/query/vendor/couchapp/evently/profile/noProfile/selectors/form/submit.js @@ -0,0 +1,36 @@ +function() { + var md5 = $$(this).app.require("vendor/couchapp/lib/md5"); + + // TODO this can be cleaned up with docForm? + // it still needs the workflow to edit an existing profile + var name = $("input[name=userCtxName]",this).val(); + var newProfile = { + rand : Math.random().toString(), + nickname : $("input[name=nickname]",this).val(), + email : $("input[name=email]",this).val(), + url : $("input[name=url]",this).val() + }, widget = $(this); + + // setup gravatar_url + if (md5) { + newProfile.gravatar_url = 'http://www.gravatar.com/avatar/'+md5.hex(newProfile.email || newProfile.rand)+'.jpg?s=40&d=identicon'; + } + + // store the user profile on the user account document + $.couch.userDb(function(db) { + var userDocId = "org.couchdb.user:"+name; + db.openDoc(userDocId, { + success : function(userDoc) { + userDoc["couch.app.profile"] = newProfile; + db.saveDoc(userDoc, { + success : function() { + newProfile.name = userDoc.name; + $$(widget).profile = newProfile; + widget.trigger("profileReady", [newProfile]); + } + }); + } + }); + }); + return false; +} \ No newline at end of file