Skip to content

Commit

Permalink
Omg it's kind of working
Browse files Browse the repository at this point in the history
  • Loading branch information
lennart committed May 16, 2010
1 parent 3f73da6 commit e95cb00
Show file tree
Hide file tree
Showing 24 changed files with 620 additions and 187 deletions.
4 changes: 2 additions & 2 deletions _attachments/index.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<title>Taskr</title>
<title>laPlaya</title>
<link rel="stylesheet" href="style/main.css" type="text/css">
</head>
<body>
<div id="header">
<div id="account"></div>
<h1><a href="#/">Taskr</a> <span id="current-path"></span></h1>
<h1><a href="#/">laPlaya</a> <span id="current-path"></span></h1>
</div>
<div id="content">
<div id="sidebar">
Expand Down
17 changes: 15 additions & 2 deletions _attachments/style/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,24 @@ div#profile {
font-size:0.78em;
}

#tasks li div.replies li {
#tasks li ul.replies li {
font-size:0.84em;
background:none;
border:1px solid #fff;
}

#tasks li div.replies {
#tasks li ul.replies {
margin:2px;
}

#tasks li ul.replies li.unresolved {
border: 1px solid red;
}

#tasks li ul.replies li.resolved {
border: 1px solid green;
}

div.avatar {
padding:2px;
padding-bottom:0;
Expand All @@ -129,3 +137,8 @@ div.avatar img {
height : 40px;
}

.replies div.avatar img {
width : 25px;
height : 25px;
}

3 changes: 0 additions & 3 deletions evently/replies/_init/mustache.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
<ul class="replies">

</ul>
<p>Leave a reply:</p>
<form>
<textarea name="body" cols="80" rows="3"></textarea>
Expand Down
14 changes: 1 addition & 13 deletions evently/replies/_init/selectors/form/submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ function() {
var li = $(this).parents("li");
var app = $$(this).app;
var task_id = li.attr("data-id");
// todo extract to model layer?

var qid = Playdar.Util.generate_uuid();
Playdar.client.register_results_handler(function(response, lastPoll) {
console.log('Polling ' + response.qid);
Expand All @@ -25,17 +25,5 @@ function() {
},qid);
var query = texta.val().split(/ - /);
Playdar.client.resolve(query[0],query[1],null,qid);
/*var newReply = {
reply_to : task_id,
body : texta.val(),
type : "reply",
created_at : new Date(),
authorProfile : $$("#profile").profile
};
app.db.saveDoc(newReply, {
success : function() {q
texta.val('');
}
});*/
return false;
}
16 changes: 0 additions & 16 deletions evently/replies/_init/selectors/ul/_changes/data.js

This file was deleted.

2 changes: 1 addition & 1 deletion evently/tasks/recent/selectors/ul/_changes/mustache.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<span class="date">{{created_at}}</span>
</div>
<div class="clear"></div>
<div class="replies"></div>
<ul class="replies"></ul>
<div class="reply"></div>
<div class="clear">&nbsp;</div>
</li>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
function() {
var li = $(this).parents("li");
var app = $$(this).app;
$("div.tracks",li).evently(app.ddoc.evently.replies, app);
return false;
var li = $(this).parents("li");
var app = $$(this).app;
$("div.tracks",li).evently(app.ddoc.evently.replies, app);
return false;
}

Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
function() {
var li = $(this).parents("li");
var task_id = li.attr("data-id");
var app = $$(this).app;
app.db.openDoc(task_id, {
success : function(doc) {
doc.state = "done";
doc.done_by = $("#account").attr("data-name");
doc.done_at = new Date();
app.db.saveDoc(doc, {
success : function() {
li.addClass("done");
li.slideUp("slow");
}
});
}
});
return false;
}
var li = $(this).parents("li");
var task_id = li.attr("data-id");
var app = $$(this).app;
app.db.openDoc(task_id, {
success: function(doc) {
doc.state = "done";
doc.done_by = $("#account").attr("data-name");
doc.done_at = new Date();
app.db.saveDoc(doc, {
success: function() {
li.addClass("done");
li.slideUp("slow");
}
});
}
});
return false;
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
function() {
var li = $(this).parents("li");
var app = $$(this).app;
$("div.replies",li).evently(app.ddoc.evently.replies, app);
return false;
}
var li = $(this).parents("li");
var app = $$(this).app;
$("div.replies", li).evently(app.ddoc.evently.replies, app);
return false;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
function(r) {
var v = r.value;
var app = $$(this).app;

var qid = v.qid;
Playdar.client.register_results_handler(function(response, lastPoll) {
console.log('Polling ' + response.qid);
if (lastPoll) {
// Take a look at the final response.
console.dir(response);
var newTrack = $.extend(v, response);
app.db.saveDoc(newTrack, { success : function() {
if (response.solved) {
$("#"+r.id).html("resolved");
} else {
$("#"+r.id).html("unresolved");
}
}
});
}

},qid);
Playdar.client.resolve(v.query.artist,v.query.track,null,qid);
return {
avatar_url : v.authorProfile && v.authorProfile.gravatar_url,
body : $.linkify($.mustache.escape(r.value.body)),
name : v.authorProfile && v.authorProfile.name,
name_uri : v.authorProfile && encodeURIComponent(v.authorProfile.name),
futon_path : "/_utils/document.html?"+[app.db.name,r.id].map(encodeURIComponent).join('/'),
id : encodeURIComponent(r.id),
solved : v.solved
// todo this should be handled in dom-land / evently
// we can use this id as a handle for automatically updating non-top rows
// based on changes from documents
};
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<li data-id="{{{id}}}" {{#state}}class="{{state}}"{{/state}}>
<div class="avatar">
<li data-id="{{{id}}}" {{#solved}}class="resolved"{{/solved}}{{^solved}}class="unresolved"{{/solved}}>
<div class="avatar" >
<img src="{{{avatar_url}}}"/>
<br/>
<a class="name" href="#/users/{{{name_uri}}}">{{name}}</a>
Expand All @@ -9,4 +9,4 @@
<a target="_blank" href="{{{futon_path}}}">&#8618;</a>
</div>
<div class="clear"></div>
</li>
</li>
73 changes: 65 additions & 8 deletions vendor/couchapp/_attachments/jquery.couch.app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@
this.view = function(view, opts) {
db.view(name+'/'+view, opts);
};
this.list = function(list, view, opts) {
db.list(name+'/'+list, view, opts);
};
}

$.couch.app = $.couch.app || function(appFun) {

$.couch.app = $.couch.app || function(appFun, opts) {
opts = opts || {};
$(function() {
var dbname = document.location.href.split('/')[3];
var dname = unescape(document.location.href).split('/')[5];
var dbname = opts.db || document.location.href.split('/')[3];
var dname = opts.design || unescape(document.location.href).split('/')[5];
var db = $.couch.db(dbname);
var design = new Design(db, dname);

Expand All @@ -47,8 +51,13 @@
function formToDeepJSON(form, fields, doc) {
form = $(form);
opts.fields.forEach(function(field) {
var val = form.find("[name="+field+"]").val();
if (!val) {return;}
var element = form.find("[name="+field+"]");
if (element.attr('type') === 'checkbox') {
var val = element.attr('checked');
} else {
var val = element.val();
if (!val) return;
}
var parts = field.split('-');
var frontObj = doc, frontName = parts.shift();
while (parts.length > 0) {
Expand Down Expand Up @@ -87,9 +96,14 @@
frontName = parts.shift();
}
if (frontObj && frontObj[frontName]) {
form.find("[name="+field+"]").val(frontObj[frontName]);
var element = form.find("[name="+field+"]");
if (element.attr('type') === 'checkbox') {
element.attr('checked', frontObj[frontName]);
} else {
element.val(frontObj[frontName]);
}
}
});
});
}

if (opts.id) {
Expand Down Expand Up @@ -172,6 +186,7 @@
db : db,
design : design,
view : design.view,
list : design.list,
docForm : docForm,
req : mockReq
}, $.couch.app.app);
Expand Down Expand Up @@ -233,3 +248,45 @@
// legacy support. $.CouchApp is deprecated, please use $.couch.app
$.CouchApp = $.couch.app;
})(jQuery);

// JavaScript 1.6 compatibility functions that are missing from IE7/IE8

if (!Array.prototype.forEach)
{
Array.prototype.forEach = function(fun /*, thisp*/)
{
var len = this.length >>> 0;
if (typeof fun != "function")
throw new TypeError();

var thisp = arguments[1];
for (var i = 0; i < len; i++)
{
if (i in this)
fun.call(thisp, this[i], i, this);
}
};
}

if (!Array.prototype.indexOf)
{
Array.prototype.indexOf = function(elt)
{
var len = this.length >>> 0;

var from = Number(arguments[1]) || 0;
from = (from < 0)
? Math.ceil(from)
: Math.floor(from);
if (from < 0)
from += len;

for (; from < len; from++)
{
if (from in this &&
this[from] === elt)
return from;
}
return -1;
};
}
Loading

0 comments on commit e95cb00

Please sign in to comment.