Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

83 lines (70 sloc) 3.614 kb
<lift:surround with="default" at="content">
<div class="lift:comet?type=LongTime"></div>
<p>Here's the Lift CometActor code:</p>
<style type="text/css">
/* <![CDATA[ */
.comment {
/* font-lock-comment-face */
color: #b22222;
}
.comment-delimiter {
/* font-lock-comment-delimiter-face */
color: #b22222;
}
.constant {
/* font-lock-constant-face */
color: #5f9ea0;
}
.function-name {
/* font-lock-function-name-face */
color: #0000ff;
}
.keyword {
/* font-lock-keyword-face */
color: #a020f0;
}
.type {
/* font-lock-type-face */
color: #228b22;
}
.variable-name {
/* font-lock-variable-name-face */
color: #b8860b;
}
/* ]]> */
</style>
<pre>
<span class="comment-delimiter">// </span><span class="comment">A CometActor that keeps the user updated
</span><span class="keyword">class</span> <span class="type">LongTime</span> <span class="keyword">extends</span> <span class="type">CometActor</span> {
<span class="keyword">private</span> <span class="keyword">var</span> <span class="variable-name">url</span>: <span class="type">Box[String]</span> = Empty
<span class="keyword">private</span> <span class="keyword">var</span> <span class="variable-name">progress</span>: <span class="type">Int </span>= 0
<span class="comment-delimiter">// </span><span class="comment">a CometActor that has not been displayed for
</span> <span class="comment-delimiter">// </span><span class="comment">2 minutes is destroyed
</span> <span class="keyword">override</span> <span class="keyword">def</span> <span class="function-name">lifespan</span>: <span class="type">Box[TimeSpan]</span> = Full(2 minutes)
<span class="comment-delimiter">// </span><span class="comment">get messages from the ThingBuilder
</span> <span class="keyword">override</span> <span class="keyword">def</span> <span class="function-name">highPriority</span> = {
<span class="keyword">case</span> <span class="type">BuildStatus</span>(<span class="variable-name">p</span>, <span class="type">Empty</span>) =&gt;
<span class="keyword">this</span>.progress = p
reRender(<span class="constant">false</span>)
<span class="keyword">case</span> <span class="type">BuildStatus</span>(<span class="variable-name">_</span>, <span class="type">Full</span>(<span class="variable-name">u</span>)) =&gt;
url = Full(u)
progress = 100
reRender(<span class="constant">false</span>)
partialUpdate(RedirectTo(u))
}
<span class="comment-delimiter">// </span><span class="comment">start the job
</span> <span class="keyword">override</span> <span class="keyword">def</span> <span class="function-name">localSetup</span>() {
ThingBuilder ! <span class="keyword">this</span>
<span class="keyword">super</span>.localSetup()
}
<span class="comment-delimiter">// </span><span class="comment">display the progress or a link to the result
</span> <span class="keyword">def</span> <span class="function-name">render</span> =
url <span class="keyword">match</span> {
<span class="keyword">case</span> <span class="type">Full</span>(<span class="variable-name">where</span>) =&gt;
&lt;span&gt;Your job is complete. &lt;a href={where}&gt;Click Me&lt;/a&gt;&lt;/span&gt;
<span class="keyword">case</span> <span class="variable-name">_</span> =&gt;
&lt;span&gt;We're working on your job... it's {progress}% complete&lt;/span&gt;
}
}
</pre>
</lift:surround>
Jump to Line
Something went wrong with that request. Please try again.