Skip to content

Instantly share code, notes, and snippets.

@MikeGrace
Created December 1, 2010 02:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MikeGrace/722849 to your computer and use it in GitHub Desktop.
Save MikeGrace/722849 to your computer and use it in GitHub Desktop.
ruleset a60x447 {
meta {
name "persistant-trail-test"
description <<
persistant-trail-test
>>
author "Mike Grace"
logging on
}
rule page_loaded {
select when pageview "example\.com"
pre {
savedName = ent:userName || "";
}
if (savedName neq "") then {
notify("Hello #{savedName}!!","Welcome back!") with sticky = true;
}
notfired {
raise explicit event name_not_saved_yet;
}
}
rule name_not_saved_yet {
select when explicit name_not_saved_yet
pre {
form =<<
<div id="name-form">
<h2>Hi! I'm a Kynetx app and I don't believe we've met before. What's your name?</h2>
<p>Name: <input id="user-name" type="text" /> <button id="name-submit">Submit</button></p>
</div>
>>;
}
{
append("body", form);
emit <|
$K("#name-submit").click(function() {
var userName = $K("input#user-name").val();
app = KOBJ.get_application("a60x447");
app.raise_event("save_name", {"userName":userName});
});
|>;
}
}
rule save_name {
select when web save_name
pre {
userName = event:param("userName");
}
{
notify("Thank you #{userName}.","I will now remember your name") with sticky = true;
notify("Note:","Reload the page and run the app again to see the the awesomeness!") with sticky = true and delay = 5;
emit <|
$K("#name-form").fadeOut();
|>;
}
fired {
set ent:userName userName;
}
}
rule clear_saved_name {
select when pageview "yahoo\.com"
pre {
userName = ent:userName;
}
if (userName neq "") then {
notify("The saved name is now cleared","Goodbye #{userName}") with sticky = true;
}
fired {
clear ent:userName;
} else {
raise explicit event no_name_to_clear;
}
}
rule no_name_to_clear {
select when explicit no_name_to_clear
{
notify("Sorry","There is no saved name to clear from my memory") with sticky = true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment