word edit: hierarchy navigation (parent and children)
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 24 May 2020 19:48:13 +0000 (21:48 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 6 Jun 2020 01:49:20 +0000 (03:49 +0200)
writer.plp

index 66dd2beb4038f3b0c3fb0ce8597ef42338b4bad6..73f6b9862a993f2308fdc69248bd0e78b439b44e 100644 (file)
@@ -43,6 +43,18 @@ ul.popup {
        background: rgba(0, 0, 0, .8);
        border: 1px solid #CCC;
 }
+
+section {
+       position: absolute;
+       top: 7ex;
+       right: 1em;
+}
+section > ul {
+       margin-top: 1ex;
+}
+section > ul strong, section form {
+       line-height: 2;
+}
 </style>
 
 <script>
@@ -155,6 +167,9 @@ elsif ($find) {
        $row = $db->select(word => '*', $find)->hash
                or Abort("Word not found", 404);
 }
+else {
+       $row = \%fields;
+}
 
 my $title = $row->{id} ? "entry <small>#$row->{id}</small>" : 'new entry';
 :>
@@ -184,3 +199,29 @@ for my $col (pairs @wordcols) {
        <input type="submit" value="New" formaction="/writer?copy=cat" />
 </p>
 </form>
+
+<:
+$row->{id} or exit;
+:>
+<section>
+<h2>Hierarchy</h2>
+
+<:
+say '<ul>';
+my $parents = $db->select(word => '*', {id => $row->{cat}});
+while (my $ref = $parents->hash) {
+       printf '<li><a href="/writer/%d">%s</a></li>', $ref->{id}, Entity($ref->{form});
+}
+say "<li><strong>$row->{form}</strong></li>";
+my $children = $db->select(word => '*', {cat => $row->{id}});
+while (my $ref = $children->hash) {
+       printf '<li><a href="/writer/%d">%s</a></li>', $ref->{id}, Entity($ref->{form});
+}
+:>
+<li><form action="/writer">
+       <input type="hidden" name="cat" value="<:= $row->{id} :>" />
+       <input type="hidden" name="lang" value="<:= $row->{lang} :>" />
+       <input type="submit" value="Add" />
+</form></li>
+</ul>
+</section>