| 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 |
| 12 | %><h3>That location already exists!</h3><% |
| 13 | else |
| 14 | val id = Location.addLocation (parent, $"name") |
| 15 | %><h3>Location added</h3> |
| 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 | |
| 24 | <h3>Modify a location</h3> |
| 25 | |
| 26 | <form action="location" method="post"> |
| 27 | <input type="hidden" name="save" value="<% id %>"> |
| 28 | <table class="blanks"> |
| 29 | <tr> <td>Parent:</td> <td><select name="parent"> |
| 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> |
| 45 | <tr> <td>Name:</td> <td><input name="name" required="required" value="<% Web.html (#name loc) %>"></td> </tr> |
| 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"}; |
| 56 | %><h3>Location saved</h3> |
| 57 | |
| 58 | <% elseif $"del" <> "" then |
| 59 | Group.requireGroupName "location"; |
| 60 | showNormal := false; |
| 61 | val id = Web.stoi ($"del"); |
| 62 | val loc = Location.lookupLocation id %> |
| 63 | <h3>Are you sure you want to delete "<% Web.html (#name loc) %>"?</h3> |
| 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 %> |
| 71 | <h3>Deleted location "<% Web.html (#name loc) %>"</h3> |
| 72 | |
| 73 | <% elseif $"addLoc" <> "" then |
| 74 | Location.addToLocation {loc = Web.stoi ($"addLoc"), usr = Init.getUserId ()} |
| 75 | %><h3>Added</h3> |
| 76 | |
| 77 | <% elseif $"remLoc" <> "" then |
| 78 | Location.removeFromLocation {loc = Web.stoi ($"remLoc"), usr = Init.getUserId ()} |
| 79 | %><h3>Removed</h3> |
| 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 | |
| 94 | <h3>Residents:</h3> |
| 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 | |
| 105 | <h3>Regions:</h3> |
| 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 | |
| 113 | <h3>Add a new location</h3> |
| 114 | |
| 115 | <form action="location" method="post"> |
| 116 | <input type="hidden" name="cmd" value="add"> |
| 117 | <table class="blanks"> |
| 118 | <tr> <td>Parent:</td> <td><select name="parent"> |
| 119 | <option value=""><None></option> |
| 120 | <% ref indent = 0; |
| 121 | foreach item in Location.locationTree (NONE, NONE) do |
| 122 | switch item of |
| 123 | Util.BEGIN => |
| 124 | indent := indent + 1 %> |
| 125 | <ul> |
| 126 | <% | Util.END => |
| 127 | indent := indent - 1 %> |
| 128 | </ul> |
| 129 | <% | Util.ITEM loc => %> |
| 130 | <option value="<% #id loc %>"><% for i in 1 .. indent do %>-<% end %><% Web.html (#name loc) %></option> |
| 131 | <% end |
| 132 | end %> |
| 133 | </select></td> </tr> |
| 134 | <tr> <td>Name:</td> <td><input name="name" required="required"></td> </tr> |
| 135 | <tr> <td><input type="submit" value="Add"></td> </tr> |
| 136 | </table> |
| 137 | </form> |
| 138 | |
| 139 | <% val withUser = Location.locationTreeWithUser (NONE, NONE, Init.getUserId ()) %> |
| 140 | |
| 141 | <h3>Add yourself to a location</h3> |
| 142 | |
| 143 | Adding yourself to a location automatically adds you to all more general loations. |
| 144 | |
| 145 | <form action="location" method="post"> |
| 146 | <select name="addLoc"> |
| 147 | <% ref indent = 0; |
| 148 | foreach item in withUser do |
| 149 | switch item of |
| 150 | Util.BEGIN => |
| 151 | indent := indent + 1 %> |
| 152 | <ul> |
| 153 | <% | Util.END => |
| 154 | indent := indent - 1 %> |
| 155 | </ul> |
| 156 | <% | Util.ITEM (true, _) => |
| 157 | | Util.ITEM (false, loc) => %> |
| 158 | <option value="<% #id loc %>"><% for i in 1 .. indent do %>-<% end %><% Web.html (#name loc) %></option> |
| 159 | <% end |
| 160 | end %> |
| 161 | </select> <input type="submit" value="Add"> |
| 162 | </form> |
| 163 | |
| 164 | <h3>Remove yourself from a location</h3> |
| 165 | |
| 166 | <form action="location" method="post"> |
| 167 | <select name="remLoc"> |
| 168 | <% ref indent = 0; |
| 169 | foreach item in withUser do |
| 170 | switch item of |
| 171 | Util.BEGIN => |
| 172 | indent := indent + 1 %> |
| 173 | <ul> |
| 174 | <% | Util.END => |
| 175 | indent := indent - 1 %> |
| 176 | </ul> |
| 177 | <% | Util.ITEM (false, _) => |
| 178 | | Util.ITEM (true, loc) => %> |
| 179 | <option value="<% #id loc %>"><% for i in 1 .. indent do %>-<% end %><% Web.html (#name loc) %></option> |
| 180 | <% end |
| 181 | end %> |
| 182 | </select> <input type="submit" value="Remove"> |
| 183 | </form> |
| 184 | |
| 185 | |
| 186 | <% if showNormal then %> |
| 187 | <ul> |
| 188 | <% foreach item in Location.locationTreeWithCounts (NONE, NONE) do |
| 189 | switch item of |
| 190 | Util.BEGIN => %> |
| 191 | <ul> |
| 192 | <% | Util.END => %> |
| 193 | </ul> |
| 194 | <% | Util.ITEM (num, loc) => %> |
| 195 | <li> <a href="location?id=<% #id loc %>"><% Web.html (#name loc) %></a> (<% num %>) |
| 196 | <a href="location?mod=<% #id loc %>">[Modify]</a> <a href="location?del=<% #id loc %>">[Delete]</a></li> |
| 197 | <% end |
| 198 | end %> |
| 199 | </ul> |
| 200 | |
| 201 | |
| 202 | |
| 203 | <% end %> |
| 204 | |
| 205 | <% @footer[] %> |