Permalink
Browse files

Adds result listing for resolved tracks before adding

  • Loading branch information...
1 parent f64dacc commit 039b306836e397b3357829545c9a369167355215 lennart committed Jun 2, 2010
View
@@ -1 +1 @@
-.couchapprc.DS_Store
+.couchapprc.DS_Store*.swp
@@ -0,0 +1,12 @@
+function(e, r) {
+ console.debug("Add Results to Dom-Element for List ID:");
+ console.dir(r);
+ var results = r.response.results
+ $(results).each(function(idx, result) {
+ console.debug("Result #"+result.sid);
+ var w = $$("#"+result.sid);
+ w.data = result;
+ w.listId = r.listId;
+ });
+ console.debug("Adding Results done");
+}
@@ -0,0 +1,12 @@
+function(e,p) {
+ console.debug("Take a look at the final response.");
+ console.dir(p.response);
+
+ var li = $(this).parents("li");
+ var list_id = li.attr("data-id");
+ console.debug("List id here: "+ list_id);
+ return {
+ results: p.response.results,
+ listId: list_id
+ };
+}
@@ -0,0 +1,13 @@
+<ul>
+ {{#results}}
+ <li id="{{{sid}}}">
+ <span>{{artist}}</span> - <span>{{track}}</span>
+ </li>
+ {{/results}}
+ {{^results}}
+ No Results yet, sorry
+ {{/results}}
+</ul>
+<form>
+ <input type="submit" value="Add">
+</form>
@@ -0,0 +1,20 @@
+function() {
+ var widget = $(this);
+ var app = $$(this).app;
+ var trackResult = $$(this);
+ var newTrack = trackResult.data;
+ newTrack.type = "track";
+ newTrack.created_at = new Date();
+ newTrack.authorProfile = $$("#profile").profile;
+ app.db.openDoc(trackResult.listId, {
+ success : function(list) {
+ list.tracks = list.tracks || [];
+ list.tracks.push(newTrack);
+ app.db.saveDoc(list, {
+ success : function() {
+ $("#"+trackResult.listId+"").trigger("_init");
+ }
+ });
+ }
+ });
+}
@@ -0,0 +1,6 @@
+function(doc) {
+ if (doc.type == "list") {
+ emit(doc.created_at, doc)
+ }
+}
+
@@ -0,0 +1,6 @@
+function(doc) {
+ if (doc.type == "list") {
+ emit(doc.title, doc)
+ }
+}
+
@@ -0,0 +1,7 @@
+function(doc) {
+ if (doc.type == "list" && doc.tracks.length > 0) {
+ for (var i = 0; i < doc.tracks.length; i++) {
+ emit([doc._id, doc.tracks[i].created_at], doc.tracks[i]);
+ };
+ }
+}

0 comments on commit 039b306

Please sign in to comment.