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 =<<
>>;
}
{
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;
}
}
}