Created
October 24, 2011 13:23
-
-
Save d6y/1309016 to your computer and use it in GitHub Desktop.
Unsubscribe redo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Unsubscribe { | |
/* A menu for Lift's Sitemap which maps /unsubscribe/{uuid} to two | |
functions: 1) given a uuid, lookup a Subscription instance | |
2) given a Subscription instance, create the link address... */ | |
val menu = Menu.param[Subscription]("Unsubscribed", "Unsubscribed", | |
uuid => Subscription.find(By(Subscription.uuid, uuid)), | |
s => s.uuid ) / "unsubscribed" >> Hidden | |
/* The Loc(ation) part of the menu is what we're going to work with... */ | |
lazy val loc: Loc[Subscription] = menu.toLoc | |
/* Turn HTML element with id="undo" into a link, by deleting the current record and | |
creating a link that when clicked will re-create the subscription in the database... */ | |
def render = "#undo" #> loc.currentValue.map { s => | |
s.delete_! | |
SHtml.link("/resubscribed", () => s.duplicate, Text("undo") ) | |
} | |
// the duplicate method copies the fields of s into a new DB row. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment