Permalink
Browse files

update vendor/couchapp with less logging and some bug fixes, plus bet…

…ter adminParty handler
  • Loading branch information...
1 parent 822e105 commit c8f05b6de261c2e7531c14c978a4ed414608ac41 @jchris committed Jun 5, 2010
@@ -44,7 +44,7 @@
var localFormDoc = {};
opts = opts || {};
opts.fields = opts.fields || [];
-
+
// turn the form into deep json
// field names like 'author-email' get turned into json like
// {"author":{"email":"quentin@example.com"}}
@@ -108,6 +108,7 @@
if (opts.id) {
db.openDoc(opts.id, {
+ attachPrevRev : opts.attachPrevRev,
success: function(doc) {
if (opts.onLoad) {opts.onLoad(doc);}
localFormDoc = doc;
@@ -23,7 +23,7 @@ function $$(node) {
};
$.forIn = forIn;
function funViaString(fun) {
- if (fun && fun.match && fun.match(/function/)) {
+ if (fun && fun.match && fun.match(/^function/)) {
eval("var f = "+fun);
if (typeof f == "function") {
return function() {
@@ -102,15 +102,15 @@ function $$(node) {
});
if (events._init) {
- $.log("ev _init", elem);
+ // $.log("ev _init", elem);
elem.trigger("_init", args);
}
if (app && events._changes) {
$("body").bind("evently.changes."+app.db.name, function() {
// we want to unbind this function when the element is deleted.
// maybe jquery 1.4.2 has this covered?
- $.log('changes', elem);
+ // $.log('changes', elem);
elem.trigger("_changes");
});
followChanges(app);
@@ -152,7 +152,7 @@ function $$(node) {
};
$.fn.replace = function(elem) {
- $.log("Replace", this)
+ // $.log("Replace", this)
$(this).empty().append(elem);
};
@@ -164,6 +164,9 @@ function $$(node) {
function renderElement(me, h, args, qrun, arun) {
// if there's a query object we run the query,
// and then call the data function with the response.
+ if (h.before && (!qrun || !arun)) {
+ funViaString(h.before).apply(me, args);
+ }
if (h.async && !arun) {
runAsync(me, h, args)
} else if (h.query && !qrun) {
@@ -174,10 +177,10 @@ function $$(node) {
// $.log(me, h, args, qrun)
// otherwise we just render the template with the current args
var selectors = runIfFun(me, h.selectors, args);
- var act = h.render || "replace";
+ var act = (h.render || "replace").replace(/\s/g,"");
var app = $$(me).app;
if (h.mustache) {
- $.log("rendering", h.mustache)
+ // $.log("rendering", h.mustache)
var newElem = mustachioed(me, h, args);
me[act](newElem);
}
@@ -195,7 +198,8 @@ function $$(node) {
});
}
if (h.after) {
- funViaString(h.after).apply(me, args);
+ runIfFun(me, h.after, args);
+ // funViaString(h.after).apply(me, args);
}
}
};
@@ -233,7 +237,7 @@ function $$(node) {
if (qType == "newRows") {
q.success = function(resp) {
- $.log("runQuery newRows success", resp.rows.length, me, resp)
+ // $.log("runQuery newRows success", resp.rows.length, me, resp)
resp.rows.reverse().forEach(function(row) {
renderElement(me, h, [row].concat($.argsToArray(args)), true)
});
@@ -246,7 +250,7 @@ function $$(node) {
renderElement(me, h, [resp].concat($.argsToArray(args)), true);
userSuccess && userSuccess(resp);
};
- $.log(app)
+ // $.log(app)
app.view(viewName, q);
}
}
@@ -65,9 +65,9 @@
var pathSpec, path_params, params = {}, param_name, param;
for (var i=0; i < $.pathbinder.paths.length; i++) {
pathSpec = $.pathbinder.paths[i];
- $.log("pathSpec", pathSpec);
+ // $.log("pathSpec", pathSpec);
if ((path_params = pathSpec.matcher.exec(path)) !== null) {
- $.log("path_params", path_params);
+ // $.log("path_params", path_params);
path_params.shift();
for (var j=0; j < path_params.length; j++) {
param_name = pathSpec.param_names[j];
@@ -141,7 +141,7 @@
$.fn.pathbinder = function(name, path) {
var self = $(this);
var pathSpec = makePathSpec(path, function(params) {
- // $.log("path cb", name, path, self)
+ $.log("path cb", name, path, self)
self.trigger(name, [params]);
});
self.bind(name, function(ev, params) {
@@ -1,13 +1,17 @@
-var scripts = [
+
+function couchapp_load(scripts) {
+ document.write(scripts.map(function(s) {
+ return '<script src="'+s+'"></script>';
+ }).join(''));
+};
+
+couchapp_load([
+ "/_utils/script/sha1.js",
"/_utils/script/json2.js",
"/_utils/script/jquery.js",
"/_utils/script/jquery.couch.js",
"vendor/couchapp/jquery.couch.app.js",
"vendor/couchapp/jquery.couch.app.util.js",
"vendor/couchapp/jquery.mustache.js",
"vendor/couchapp/jquery.evently.js"
-];
-
-document.write(scripts.map(function(s) {
- return '<script src="'+s+'"></script>';
-}).join(''));
+]);
@@ -0,0 +1,22 @@
+## Starting the Document this code challenge
+
+I need help on this code. I only have so many hours in the day. Please be liberal about patching and hacking (and sharing code!) so we can all benefit.
+
+Docs patches are deeply appreciated. For now you can just stick Markdown files in the Docs directory.
+
+# Evently
+
+These are some vendor Evently widgets that are running on the CouchApp system.
+
+## Account
+ This is how you signup, login and logout without worry about the code.
+ Todo, we could have this work against remote APIs like that Facebook stuff or whatever.
+
+
+## Profile
+ Use this to load the local users profile for the logged in user. Useful if you're going to be posting new messages. Most applications end up customizing `profile.profileReady` to render the primary data-entry form. This gets you benefits like refreshing on login / logout, etc, automatically.
+
+
+## Docs
+ This needs to be moved to it's own app.
+ I have this vision of a docs app designed for offline editing, that involves each Markdown paragraph being it's own document, with automatic use of Bespin for code samples. Any help on this would be thanked much.
@@ -1,3 +0,0 @@
-function() {
- alert("Admin party! Fix this in Futon before proceeding.");
-}
@@ -0,0 +1 @@
+<p><strong>Admin party, everyone is admin!</strong> Fix this in <a href="/_utils/index.html">Futon</a> before proceeding.</p>
@@ -1,6 +1,8 @@
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(),
@@ -10,13 +12,10 @@ function() {
}, widget = $(this);
// setup gravatar_url
- if (typeof hex_md5 == "undefined") {
- alert("creating a profile requires md5.js to be loaded in the page");
- return;
+ if (md5) {
+ newProfile.gravatar_url = 'http://www.gravatar.com/avatar/'+md5.hex(newProfile.email || newProfile.rand)+'.jpg?s=40&d=identicon';
}
- newProfile.gravatar_url = 'http://www.gravatar.com/avatar/'+hex_md5(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;
@@ -1,7 +1,3 @@
function(e, p) {
- return {
- nickname : p.nickname,
- name : p.name,
- avatar_url : p.gravatar_url
- };
+ return p
}
@@ -1,5 +1,5 @@
<div class="avatar">
- {{#avatar_url}}<img src="{{avatar_url}}"/>{{/avatar_url}}
+ {{#gravatar_url}}<img src="{{gravatar_url}}"/>{{/gravatar_url}}
<div class="name">
{{nickname}}
</div>
Oops, something went wrong.

0 comments on commit c8f05b6

Please sign in to comment.