Mercurial Hosting > nabble
diff src/nabble/view/web/template/UserPageNamespace.java @ 0:7ecd1a4ef557
add content
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 21 Mar 2019 19:15:52 -0600 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/nabble/view/web/template/UserPageNamespace.java Thu Mar 21 19:15:52 2019 -0600 @@ -0,0 +1,67 @@ +package nabble.view.web.template; + +import fschmidt.db.DbDatabase; +import nabble.model.ModelException; +import nabble.model.Person; +import nabble.model.User; +import nabble.naml.compiler.Command; +import nabble.naml.compiler.CommandSpec; +import nabble.naml.compiler.IPrintWriter; +import nabble.naml.compiler.Namespace; +import nabble.naml.compiler.ScopedInterpreter; +import nabble.view.web.user.UserEditorNamespace; + +import javax.servlet.ServletException; + + +@Namespace ( + name = "user_page", + global = true +) +public final class UserPageNamespace { + private UserNamespace userNs; + + public UserPageNamespace(Person person) { + this(new UserNamespace(person)); + } + + public UserPageNamespace(UserNamespace userNs) { + this.userNs = userNs; + } + + public UserNamespace userNamespace() { + return userNs; + } + + public User user() { + return userNs.user(); + } + + public static final CommandSpec page_user = CommandSpec.DO; + + @Command public void page_user(IPrintWriter out,ScopedInterpreter<UserNamespace> interp) { + out.print( interp.getArg(userNs,"do") ); + } + + public static final CommandSpec edit_page_user = CommandSpec.DO() + .optionalParameters("commit") + .build() + ; + + @Command public void edit_page_user(IPrintWriter out,ScopedInterpreter<UserEditorNamespace> interp) { + boolean commit = interp.getArgAsBoolean("commit",true); + DbDatabase db = user().getSite().getDb(); + db.beginTransaction(); + try { + userNs.refreshUser(); + interp.getArgString(new UserEditorNamespace(user()),"do"); + if( commit ) { + db.commitTransaction(); + userNs.refreshUser(); + } + } finally { + db.endTransaction(); + } + } + +}