51520441 |
1 | <% @header[("title", ["Member locations"])]; |
2 | |
3 | val admin = Group.inGroupName "location"; |
4 | |
5 | ref showNormal = true; |
6 | |
7 | if $"cmd" = "add" then |
8 | val parent = (case $"parent" of "" => NONE | parent => SOME (Web.stoi parent)); |
9 | val name = $"name"; |
10 | |
11 | if Location.alreadyExists (parent, name) then |
1fe415e0 |
12 | %><h3>That location already exists!</h3><% |
51520441 |
13 | else |
14 | val id = Location.addLocation (parent, $"name") |
1fe415e0 |
15 | %><h3>Location added</h3> |
51520441 |
16 | <% end |
17 | |
18 | elseif $"mod" <> "" then |
19 | Group.requireGroupName "location"; |
20 | showNormal := false; |
21 | val id = Web.stoi ($"mod"); |
22 | val loc = Location.lookupLocation id %> |
23 | |
1fe415e0 |
24 | <h3>Modify a location</h3> |
51520441 |
25 | |
add44c00 |
26 | <form action="location" method="post"> |
51520441 |
27 | <input type="hidden" name="save" value="<% id %>"> |
1fe415e0 |
28 | <table class="blanks"> |
29 | <tr> <td>Parent:</td> <td><select name="parent"> |
51520441 |
30 | <option value=""<% if #parent loc = NONE then %> selected<% end %>><None></option> |
31 | <% ref indent = 0; |
32 | foreach item in Location.locationTree (NONE, NONE) do |
33 | switch item of |
34 | Util.BEGIN => |
35 | indent := indent + 1 %> |
36 | <ul> |
37 | <% | Util.END => |
38 | indent := indent - 1 %> |
39 | </ul> |
40 | <% | Util.ITEM loc2 => %> |
41 | <option value="<% #id loc2 %>"<% if SOME (#id loc2) = #parent loc then %> selected<% end %>><% for i in 1 .. indent do %>-<% end %><% Web.html (#name loc2) %></option> |
42 | <% end |
43 | end %> |
44 | </select></td> </tr> |
1fe415e0 |
45 | <tr> <td>Name:</td> <td><input name="name" value="<% Web.html (#name loc) %>"></td> </tr> |
51520441 |
46 | <tr> <td><input type="submit" value="Save"></td> </tr> |
47 | </table> |
48 | </form> |
49 | |
50 | <% elseif $"save" <> "" then |
51 | Group.requireGroupName "location"; |
52 | val id = Web.stoi ($"save"); |
53 | val loc = Location.lookupLocation id; |
54 | Location.modLocation {loc with parent = (case $"parent" of "" => NONE | parent => SOME (Web.stoi parent)), |
55 | name = $"name"}; |
1fe415e0 |
56 | %><h3>Location saved</h3> |
51520441 |
57 | |
58 | <% elseif $"del" <> "" then |
59 | Group.requireGroupName "location"; |
60 | showNormal := false; |
61 | val id = Web.stoi ($"del"); |
62 | val loc = Location.lookupLocation id %> |
1fe415e0 |
63 | <h3>Are you sure you want to delete "<% Web.html (#name loc) %>"?</h3> |
51520441 |
64 | <a href="location?del2=<% id %>">Yes, delete "<% Web.html (#name loc) %>"!</a> |
65 | |
66 | <% elseif $"del2" <> "" then |
67 | Group.requireGroupName "location"; |
68 | val id = Web.stoi ($"del2"); |
69 | val loc = Location.lookupLocation id; |
70 | Location.deleteLocation id %> |
1fe415e0 |
71 | <h3>Deleted location "<% Web.html (#name loc) %>"</h3> |
51520441 |
72 | |
73 | <% elseif $"addLoc" <> "" then |
74 | Location.addToLocation {loc = Web.stoi ($"addLoc"), usr = Init.getUserId ()} |
1fe415e0 |
75 | %><h3>Added</h3> |
51520441 |
76 | |
77 | <% elseif $"remLoc" <> "" then |
78 | Location.removeFromLocation {loc = Web.stoi ($"remLoc"), usr = Init.getUserId ()} |
1fe415e0 |
79 | %><h3>Removed</h3> |
51520441 |
80 | |
81 | <% elseif $"id" <> "" then |
82 | showNormal := false; |
83 | val id = Web.stoi ($"id"); |
84 | val loc = Location.lookupLocation id %> |
85 | |
86 | <h2><b><% Web.html (#name loc) %></b></h2> |
87 | |
88 | <% switch #parent loc of |
89 | SOME par => |
90 | val ploc = Location.lookupLocation par; |
91 | %><b>Parent</b>: <a href="location?id=<% par %>"><% Web.html (#name ploc) %></a><% |
92 | end %> |
93 | |
1fe415e0 |
94 | <h3>Residents:</h3> |
51520441 |
95 | <% ref first = true; |
96 | foreach user in Location.residents id do |
97 | if first then |
98 | first := false |
99 | else |
100 | %>, <% |
101 | end; |
102 | %><a href="user?id=<% #id user %>"><% #name user %></a><% |
103 | end %> |
104 | |
1fe415e0 |
105 | <h3>Regions:</h3> |
51520441 |
106 | <% foreach loc in Location.subLocations (SOME id) do %> |
107 | <a href="location?id=<% #id loc %>"><% Web.html (#name loc) %></a><br> |
108 | <% end; |
109 | |
110 | end; |
111 | |
112 | if showNormal then %> |
113 | <ul> |
114 | <% foreach item in Location.locationTreeWithCounts (NONE, NONE) do |
115 | switch item of |
116 | Util.BEGIN => %> |
117 | <ul> |
118 | <% | Util.END => %> |
119 | </ul> |
120 | <% | Util.ITEM (num, loc) => %> |
121 | <li> <a href="location?id=<% #id loc %>"><% Web.html (#name loc) %></a> (<% num %>) |
122 | <a href="location?mod=<% #id loc %>">[Modify]</a> <a href="location?del=<% #id loc %>">[Delete]</a></li> |
123 | <% end |
124 | end %> |
125 | </ul> |
126 | |
1fe415e0 |
127 | <h3>Add a new location</h3> |
51520441 |
128 | |
add44c00 |
129 | <form action="location" method="post"> |
51520441 |
130 | <input type="hidden" name="cmd" value="add"> |
1fe415e0 |
131 | <table class="blanks"> |
132 | <tr> <td>Parent:</td> <td><select name="parent"> |
51520441 |
133 | <option value=""><None></option> |
134 | <% ref indent = 0; |
135 | foreach item in Location.locationTree (NONE, NONE) do |
136 | switch item of |
137 | Util.BEGIN => |
138 | indent := indent + 1 %> |
139 | <ul> |
140 | <% | Util.END => |
141 | indent := indent - 1 %> |
142 | </ul> |
143 | <% | Util.ITEM loc => %> |
144 | <option value="<% #id loc %>"><% for i in 1 .. indent do %>-<% end %><% Web.html (#name loc) %></option> |
145 | <% end |
146 | end %> |
147 | </select></td> </tr> |
1fe415e0 |
148 | <tr> <td>Name:</td> <td><input name="name"></td> </tr> |
51520441 |
149 | <tr> <td><input type="submit" value="Add"></td> </tr> |
150 | </table> |
151 | </form> |
152 | |
153 | <% val withUser = Location.locationTreeWithUser (NONE, NONE, Init.getUserId ()) %> |
154 | |
1fe415e0 |
155 | <h3>Add yourself to a location</h3> |
51520441 |
156 | |
157 | Adding yourself to a location automatically adds you to all more general loations. |
158 | |
add44c00 |
159 | <form action="location" method="post"> |
51520441 |
160 | <select name="addLoc"> |
161 | <% ref indent = 0; |
162 | foreach item in withUser do |
163 | switch item of |
164 | Util.BEGIN => |
165 | indent := indent + 1 %> |
166 | <ul> |
167 | <% | Util.END => |
168 | indent := indent - 1 %> |
169 | </ul> |
170 | <% | Util.ITEM (true, _) => |
171 | | Util.ITEM (false, loc) => %> |
172 | <option value="<% #id loc %>"><% for i in 1 .. indent do %>-<% end %><% Web.html (#name loc) %></option> |
173 | <% end |
174 | end %> |
175 | </select> <input type="submit" value="Add"> |
176 | </form> |
177 | |
1fe415e0 |
178 | <h3>Remove yourself from a location</h3> |
51520441 |
179 | |
add44c00 |
180 | <form action="location" method="post"> |
51520441 |
181 | <select name="remLoc"> |
182 | <% ref indent = 0; |
183 | foreach item in withUser do |
184 | switch item of |
185 | Util.BEGIN => |
186 | indent := indent + 1 %> |
187 | <ul> |
188 | <% | Util.END => |
189 | indent := indent - 1 %> |
190 | </ul> |
191 | <% | Util.ITEM (false, _) => |
192 | | Util.ITEM (true, loc) => %> |
193 | <option value="<% #id loc %>"><% for i in 1 .. indent do %>-<% end %><% Web.html (#name loc) %></option> |
194 | <% end |
195 | end %> |
196 | </select> <input type="submit" value="Remove"> |
197 | </form> |
198 | |
199 | |
200 | <% end %> |
201 | |
202 | <% @footer[] %> |