X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=web%2Fhtdocs%2Fdetails%2Fedit.mc;h=1d789f0655d32243c2513428d59e5a9c50a1c287;hb=8625486cd778ef83c03fb5d5541b1485dfc02de7;hp=7f16a1bd18dba6ca9a91838a2bdf039672a3d3be;hpb=8895c1ba1ef653c59711bf5050394d61410fc38f;p=irspy-moved-to-github.git
diff --git a/web/htdocs/details/edit.mc b/web/htdocs/details/edit.mc
index 7f16a1b..1d789f0 100644
--- a/web/htdocs/details/edit.mc
+++ b/web/htdocs/details/edit.mc
@@ -1,5 +1,24 @@
-%# $Id: edit.mc,v 1.16 2006-11-16 17:14:46 mike Exp $
+%# $Id: edit.mc,v 1.20 2006-11-17 22:39:17 mike Exp $
+<%doc>
+Since this form is used in many different situations, some care is
+merited in considering the possibilities:
+
+New? Copy ID? Situation
+--------------------------------------------------------------------------
+Y Blank form for adding a new target.
+Y New target submitted successfully.
+Y Partial new target submitted, requiring more
+
+ Y Existing target to be edited.
+ Y Existing target has been updated.
+
+ Y Y Existing target to be copied.
+ Y New or copied target rejected due to duplicate ID.
+--------------------------------------------------------------------------
+%doc>
<%args>
+$new => undef
+$copy => undef
$id => undef
%args>
<%perl>
@@ -8,31 +27,38 @@ my $conn = new ZOOM::Connection("localhost:3313/IR-Explain---1", 0,
elementSetName => "zeerex");
my $rec = '
\n";
# Existing record
my $query = 'rec.id="' . cql_quote($id) . '"';
my $rs = $conn->search(new ZOOM::Query::CQL($query));
- my $n = $rs->size();
- if ($n == 0) {
- $id = undef;
- } else {
+ if ($rs->size() > 0) {
$rec = $rs->record(0);
+ } else {
+ $id = undef;
}
} else {
# New record
- print "New record
\n";
my $host = $r->param("host");
my $port = $r->param("port");
my $dbname = $r->param("dbname");
if (!defined $host || $host eq "" ||
!defined $port || $port eq "" ||
!defined $dbname || $dbname eq "") {
- print qq[
You must specify host, port and database name
\n]; + print qq[+You must specify host, port and database name.
\n]; $r->param(update => 0); + } else { + my $query = cql_target($host, $port, $dbname); + my $rs = $conn->search(new ZOOM::Query::CQL($query)); + if ($rs->size() > 0) { + my $fakeid = xml_encode(uri_escape("$host:$port/$dbname")); + print qq[+There is already +a record +for this host, port and database name. +
\n]; + } } - - my $query = cql_target($host, $port, $dbname); } my $xc = irspy_xpath_context($rec); @@ -74,7 +100,7 @@ my @fields = my $nchanges = 0; my $update = $r->param("update"); -if (defined $update) { + # Update record with submitted data my %fieldsByKey = map { ( $_->[0], $_) } @fields; my %data; @@ -82,8 +108,10 @@ if (defined $update) { next if grep { $key eq $_ } qw(id update new copy); $data{$key} = $r->param($key); } + my $mynchanges = modify_xml_document($xc, \%fieldsByKey, \%data); - $nchanges = modify_xml_document($xc, \%fieldsByKey, \%data); +if ($update) { + $nchanges = $mynchanges; if ($nchanges) { ### Set e:metaInfo/e:dateModified } @@ -93,7 +121,7 @@ if (defined $update) {
- The record has been <% $r->param("new") ? "created" : "updated" %>.
+ The record has been <% $new ? "created" : "updated" %>.
Changed <% $nchanges %> field<% $nchanges == 1 ? "" : "s" %>.