0
|
1 package nabble.view.web.template;
|
|
2
|
|
3 import fschmidt.db.DbDatabase;
|
|
4 import nabble.model.ModelException;
|
|
5 import nabble.model.Person;
|
|
6 import nabble.model.User;
|
|
7 import nabble.naml.compiler.Command;
|
|
8 import nabble.naml.compiler.CommandSpec;
|
|
9 import nabble.naml.compiler.IPrintWriter;
|
|
10 import nabble.naml.compiler.Namespace;
|
|
11 import nabble.naml.compiler.ScopedInterpreter;
|
|
12 import nabble.view.web.user.UserEditorNamespace;
|
|
13
|
|
14 import javax.servlet.ServletException;
|
|
15
|
|
16
|
|
17 @Namespace (
|
|
18 name = "user_page",
|
|
19 global = true
|
|
20 )
|
|
21 public final class UserPageNamespace {
|
|
22 private UserNamespace userNs;
|
|
23
|
|
24 public UserPageNamespace(Person person) {
|
|
25 this(new UserNamespace(person));
|
|
26 }
|
|
27
|
|
28 public UserPageNamespace(UserNamespace userNs) {
|
|
29 this.userNs = userNs;
|
|
30 }
|
|
31
|
|
32 public UserNamespace userNamespace() {
|
|
33 return userNs;
|
|
34 }
|
|
35
|
|
36 public User user() {
|
|
37 return userNs.user();
|
|
38 }
|
|
39
|
|
40 public static final CommandSpec page_user = CommandSpec.DO;
|
|
41
|
|
42 @Command public void page_user(IPrintWriter out,ScopedInterpreter<UserNamespace> interp) {
|
|
43 out.print( interp.getArg(userNs,"do") );
|
|
44 }
|
|
45
|
|
46 public static final CommandSpec edit_page_user = CommandSpec.DO()
|
|
47 .optionalParameters("commit")
|
|
48 .build()
|
|
49 ;
|
|
50
|
|
51 @Command public void edit_page_user(IPrintWriter out,ScopedInterpreter<UserEditorNamespace> interp) {
|
|
52 boolean commit = interp.getArgAsBoolean("commit",true);
|
|
53 DbDatabase db = user().getSite().getDb();
|
|
54 db.beginTransaction();
|
|
55 try {
|
|
56 userNs.refreshUser();
|
|
57 interp.getArgString(new UserEditorNamespace(user()),"do");
|
|
58 if( commit ) {
|
|
59 db.commitTransaction();
|
|
60 userNs.refreshUser();
|
|
61 }
|
|
62 } finally {
|
|
63 db.endTransaction();
|
|
64 }
|
|
65 }
|
|
66
|
|
67 }
|