Starting ...|]
+ addScriptRemote "http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"
+ toWidgetBody $(juliusFile $ juliusTemplate "longpolling")
+ [whamlet|
config|]
+
+{- Called by client to poll for a new webapp status display.
+ -
+ - Should block until the status has changed, and then return a div
+ - containing the new status, which will be inserted into the calling page.
+ -}
+getPollR :: Handler RepHtml
+getPollR = do
+ webapp <- getYesod
+ time <- show <$> liftIO getCurrentTime
+ hamletToRepHtml $(hamletFile $ hamletTemplate "poll")
getConfigR :: Handler RepHtml
getConfigR = defaultLayout $ do
diff --git a/Utility/Yesod.hs b/Utility/Yesod.hs
index 05f684490a..a0dd3bdd2f 100644
--- a/Utility/Yesod.hs
+++ b/Utility/Yesod.hs
@@ -16,3 +16,7 @@ template f = "templates" > f
{- A hamlet template file. -}
hamletTemplate :: FilePath -> FilePath
hamletTemplate f = template f ++ ".hamlet"
+
+{- A julius template file. -}
+juliusTemplate :: FilePath -> FilePath
+juliusTemplate f = template f ++ ".julius"
diff --git a/templates/default-layout.hamlet b/templates/default-layout.hamlet
index e07addc8e0..bd16969f93 100644
--- a/templates/default-layout.hamlet
+++ b/templates/default-layout.hamlet
@@ -3,7 +3,6 @@ $doctype 5
#{baseTitle webapp} #{pageTitle page}
-
^{pageHead page}
$maybe msg <- mmsg
diff --git a/templates/longpolling.julius b/templates/longpolling.julius
new file mode 100644
index 0000000000..38ecbc77d2
--- /dev/null
+++ b/templates/longpolling.julius
@@ -0,0 +1,25 @@
+// Uses long-polling to update a div with id=poll.
+// The PollR route should return a new div, also with id=poll.
+
+(function( $ ) {
+
+$.LongPoll = (function() {
+ return {
+ send : function() {
+ $.ajax({
+ 'url': '@{PollR}',
+ 'dataType': 'html',
+ 'success': function(data, status, jqxhr) {
+ $('#poll').replaceWith(data);
+ setTimeout($.LongPoll.send, 3000);
+ },
+ });
+ }
+ }
+}());
+
+$(document).bind('ready.app', function() {
+ setTimeout($.LongPoll.send, 40);
+});
+
+})( jQuery );
diff --git a/templates/poll.hamlet b/templates/poll.hamlet
new file mode 100644
index 0000000000..fcdd705b65
--- /dev/null
+++ b/templates/poll.hamlet
@@ -0,0 +1,2 @@
+
+ polled at #{time}