This repository has been archived by the owner on Sep 28, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JSON serializer/desirializer for CouchDB dcument forms.
Add user profile creation.
- Loading branch information
Showing
14 changed files
with
532 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
relax/containers/webjourney/_attachments/javascripts/webjourney/profile.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
PROFILE_RULES = { | ||
"displayName-formatted": { | ||
required : true | ||
} | ||
}; | ||
|
||
function alertError(status, error, reason){ | ||
alert("[" + status + ":" + error + "] " + reason); | ||
} | ||
|
||
function onSubmitUpdateProfile(e){ | ||
var f = jQuery("form#update_profile"); | ||
e.preventDefault(); | ||
var doc = f.serializeJson(); | ||
if( f.valid() ){ | ||
f.nowLoading({message: "Updating your profile ..."}); | ||
Site.CouchApp.db.saveDoc(doc, { | ||
success: function(resp){ | ||
alert("OK"); | ||
f.find("input[name='_rev']").val(doc._rev); | ||
f.nowLoading("clear"); | ||
}, | ||
error: function(status, error, reason){ | ||
alertError(status, error, reason); | ||
f.nowLoading("clear"); | ||
} | ||
}); | ||
} | ||
return false; | ||
} | ||
|
||
function onSubmitCreateProfile(e){ | ||
var f = jQuery("form#create_profile"); | ||
e.preventDefault(); | ||
var doc = f.serializeJson(); | ||
if( f.valid() ){ | ||
f.nowLoading({message: "Submitting your profile ..."}); | ||
Site.CouchApp.db.saveDoc(doc, { | ||
success: function(resp){ | ||
f.nowLoading({message: "Building your page ..."}); | ||
Site.go(Site.CouchApp.showPath("profile", doc._id)); | ||
}, | ||
error: function(status, error, reason){ | ||
alertError(status, error, reason); | ||
f.nowLoading("clear"); | ||
} | ||
}); | ||
} | ||
return false; | ||
} | ||
|
||
|
||
$.CouchApp(function(app){ | ||
var f = jQuery("form#create_profile"); | ||
f.validate(PROFILE_RULES); | ||
f.submit(onSubmitCreateProfile); | ||
|
||
f = jQuery("form#update_profile"); | ||
f.validate(PROFILE_RULES); | ||
f.submit(onSubmitUpdateProfile); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,3 @@ | ||
function html_escape(s){ | ||
return s.toString().replace(/&/g, "&"). | ||
replace(/\"/g, """). | ||
replace(/\'/g, "'"). | ||
replace(/</g, "<"). | ||
replace(/>/g, ">"); | ||
} | ||
|
||
function h(s){ | ||
return html_escape(s); | ||
} | ||
|
||
function json_escape(s){ | ||
return s.toString().relace(/&/g, "\\u0026"). | ||
replace(/</g, "\\u003c"). | ||
replace(/>/g, "\\u003e"); | ||
} | ||
|
||
function j(s){ | ||
return json_escape(s); | ||
function clearButton(selector){ | ||
return '<button type="button" onclick=\'jQuery(' + h(toJSON(selector)) + ').clear()\'>Clear</button>'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"type" : "Person", | ||
"displayName" : { | ||
"formatted" : "Your Name" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
function(doc, req) { | ||
// !code vendor/couchapp/path.js | ||
// !code lib/helpers/securityToken.js | ||
// !code lib/helpers/util.js | ||
// !code vendor/crayon/lib/escape.js | ||
// !code vendor/crayon/lib/template.js | ||
// !code vendor/crayon/lib/error.js | ||
// !code vendor/crayon/lib/form.js | ||
|
||
// !json models.profile | ||
// !json templates.site | ||
// !json templates.profile | ||
|
||
var bindings = { | ||
request : req, | ||
current_user : req.userCtx, | ||
assetPath : assetPath(), | ||
site: { | ||
title: "Profile", | ||
javascripts: [ | ||
"profile.js" | ||
] | ||
} | ||
}; | ||
|
||
|
||
if(doc && doc.type == "Person"){ | ||
bindings["profile"] = doc; | ||
return render(templates.site.header, bindings) + | ||
render(templates.profile.main, bindings) + | ||
render(templates.site.footer, bindings); | ||
}else if(req.docId){ | ||
var userid = req.docId.split(":"); | ||
var domain = userid[0], username = userid[1]; | ||
if( domain == req.headers["Host"] || domain == req.headers["X-Forwarded-Host"] ){ | ||
if( username == req.userCtx.name ){ | ||
bindings["profile"] = models.profile; | ||
bindings["profile"]["_id"] = req.docId; | ||
return render(templates.site.header, bindings) + | ||
render(templates.profile.not_found, bindings) + | ||
render(templates.site.footer, bindings); | ||
}else{ | ||
// TODO HTML rendering | ||
return render_error(FORBIDDEN); | ||
} | ||
}else{ | ||
// TODO HTML rendering | ||
return render_error(NOT_FOUND); | ||
} | ||
}else{ | ||
// TODO HTML rendering | ||
return render_error(NOT_FOUND); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<%= hidden_field(profile, "type") %> | ||
<%= hidden_field(profile, "_id") %> | ||
<%= hidden_field(profile, "_rev") %> | ||
<fieldset> | ||
<div> | ||
<label for="displayName-formatted">Display Name<em>*</em></label> | ||
<div> | ||
<%= text_field(profile, "displayName-formatted", {class: "required"} )%> | ||
</div> | ||
</div> | ||
<div> | ||
<label for="birthday-year">Birthday</label> | ||
<div> | ||
<%= date_select(profile, "birthday", { | ||
"include_blank" : true | ||
}) %> | ||
<%= clearButton("select[name='birthday-year']") %> | ||
</div> | ||
</div> | ||
<div> | ||
<label for="gender">Gender</label> | ||
<div> | ||
<%= radio_button(profile, "gender", "male") %> Male | ||
<%= radio_button(profile, "gender", "female") %> Female | ||
<%= clearButton("input[name='gender']") %> | ||
</div> | ||
</div> | ||
<div> | ||
<label for="aboutMe">About Me</label> | ||
<div> | ||
<%= text_area(profile, "aboutMe", {rows: 8, cols:80})%> | ||
</div> | ||
<p class="note">Markdown format is available.</p> | ||
</div> | ||
</fieldset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<div id="main"> | ||
<div class="ui-widget ui-widget-content ui-corner-all gadget"> | ||
<div class="ui-widget ui-state-default ui-widget-header ui-corner-all gadget-title-bar"> | ||
<div class="gadget-title-bar-label"> | ||
<span>Update Your Profile</span> | ||
</div> | ||
</div> | ||
<div class="ui-widget gadget-body"> | ||
<div class="gadget-embedded-content"> | ||
<div id="profile_editor"> | ||
<div class="sform"> | ||
<form id="update_profile" method="POST" action="#create_profile"> | ||
<p class="legend"> | ||
<strong>Note:</strong> | ||
You can update your own profile. | ||
Required fields are marked as <em>*</em>. | ||
</p> | ||
<%= render(templates.profile.form, {profile: profile}) %> | ||
<div class="buttonrow"> | ||
<button type="submit">Update</button> | ||
</div> | ||
</form> | ||
</div> | ||
</div><!-- register --> | ||
</div><!-- tabs --> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
Oops, something went wrong.