diff options
-rw-r--r-- | cljssss-g.clj | 17 | ||||
-rw-r--r-- | index.st | 13 | ||||
-rw-r--r-- | public/feed-list.js | 45 |
3 files changed, 70 insertions, 5 deletions
diff --git a/cljssss-g.clj b/cljssss-g.clj index 02c5eeb..79ff25a 100644 --- a/cljssss-g.clj +++ b/cljssss-g.clj @@ -272,6 +272,21 @@ to merely being replaced with a div element)?" "xhtml_content_p" (not (nil? xhtml-content)) "xhtml_content" xhtml-content})))))) +(defn show-entry-xml [entry] + (with-db + (sql/with-query-results + [{link :link, title :title}] + [(str "SELECT entry.link, entry.title, entry.id" + " FROM entry, feed_entry_link, user_feed_link" + " WHERE entry.id = ?") + entry] + (str "<?xml version='1.0'?>" + "<response>" + "<uri>" link "</uri>" + "<title>" title "</title>" + "<content>" (escape-xml (entry-xhtml-content entry)) "</content>" + "</response>")))) + (defmacro with-session "Rebind Compojure's magic lexical variables as vars." [& body] @@ -313,6 +328,8 @@ to merely being replaced with a div element)?" (and (params :feed) (Integer/parseInt (params :feed))) (Integer/parseInt entry-id-string))))) + (GET "/entry-xml" + (with-session (show-entry-xml (params :id)))) (GET "*" (serve-file path)) (ANY "*" @@ -1,4 +1,7 @@ -$header(title=title)$ +$header_start(title=title)$ +<script src="/yui3/build/yui/yui-min.js" type="text/javascript"></script> +<script src="/feed-list.js" type="text/javascript"></script> +$header_end()$ <h1 class="title">$title$</h1> @@ -27,15 +30,15 @@ $if(entries)$ $entries:{entry | $if(entry.active_p)$ $! FIXME: Show content inline if possible. !$ - <li class="full-entry"> - <a id="entry-$entry.id$" href="$entry.link$"><h3>$entry.title$</h3></a> + <li class="full-entry" id="entry-$entry.id$-container"> + <a class="entry-link" id="entry-$entry.id$" href="$entry.link$"><h3>$entry.title$</h3></a> $if(xhtml_content_p)$ <div class="entry-content">$xhtml_content$</div> $endif$ </li> $else$ - <li class="partial-entry"> - <a id="entry-$entry.id$" href="/entries/$entry.id$?feed=$active_feed_id$#entry-$entry.id$">$entry.title$</a> + <li class="partial-entry" id="entry-$entry.id$-container"> + <a class="entry-link" id="entry-$entry.id$" href="/entries/$entry.id$?feed=$active_feed_id$#entry-$entry.id$">$entry.title$</a> </li> $endif$ }$ diff --git a/public/feed-list.js b/public/feed-list.js new file mode 100644 index 0000000..cce8911 --- /dev/null +++ b/public/feed-list.js @@ -0,0 +1,45 @@ +YUI({base: "/yui3/build/", timeout: 10000}).use("io-base", function(Y) { + function successHandler(entry_id) { + function updateEntry(id, response) { + var elem = Y.Node.get("#entry-" + entry_id + "-container"); + var xml = response.responseXML.documentElement; + var uri = xml.getElementsByTagName('uri')[0].firstChild.nodeValue; + var title = xml.getElementsByTagName('title')[0].firstChild.nodeValue; + var content = xml.getElementsByTagName('content')[0].firstChild.nodeValue; + elem.set("innerHTML", '<a href="' + uri + '"><h3>' + title + '</h3></a>' + + '<div class="entry-content">' + content + '</div>'); + } + + return updateEntry; + } + + function failureHandler(entry_id) { + function updateEntry(id, response) { + var elem = Y.Node.get("#entry-" + entry_id + "-container"); + // FIXME + alert ("No content."); + } + + return updateEntry; + } + + function getEntry(event) { + event.preventDefault(); + var id_string = this.get('id'); + var id = id_string.slice(6); + var queryURI = '/entry-xml?id=' + id; + Y.log("Querying server for entry: " + id, "info", "cljssss^g"); + var request = Y.io(queryURI, { + method: "GET", + on: { + success: successHandler(id), + failure: failureHandler(id) + }}); + } + +// Y.on("click", getEntry, ".entry-link"); + Y.Node.all(".entry-link").each(function(elem, key) { + Y.on("click", getEntry, elem, elem); + }); + +}); |