summaryrefslogtreecommitdiff
path: root/rt/webrt/Admin/Elements/ModifyKeyword
blob: 4b01c3692c993784517b6e03fd37bae71c9e2835 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<FORM METHOD="get" ACTION="<%$RT::WebPath%>/Admin/Keywords/Modify.html">
[<%$title |n %>]<BR>

<INPUT TYPE="hidden" NAME="id" VALUE="<% $id %>">
Keyword <INPUT NAME="Name" VALUE="<% $Keyword->Name %>"><BR>

Parent <SELECT NAME="Parent">
	      <OPTION VALUE=""<% defined($Keyword->Parent) ? '' : ' SELECTED' %>>-</OPTION>
%while ( $parent = $parents->Next ) {
	      <OPTION VALUE="<% $parent->id %>"<% defined($Keyword->Parent) && $parent->id == $Keyword->Parent ? ' SELECTED' : '' %>><% $parent->Name %></OPTION>
%}
</SELECT>


Kids <FONT SIZE="-2">(separate by
<INPUT TYPE="radio" NAME="delim" VALUE="n"<% $delim eq 'n' ? ' CHECKED' : '' %>>
line or
<INPUT TYPE="radio" NAME="delim" VALUE="s"<% $delim eq 's' ? ' CHECKED' : '' %>>
whitespace)</FONT><BR>

<TEXTAREA NAME="Kids" ROWS=4><% $kidstring %></TEXTAREA>
<BR>

<& /Elements/Submit, Label => $submit &>
</FORM>

<%INIT>

my $Keyword = new RT::Keyword($session{CurrentUser});
my ($title, $submit, %kids, $kid);

if ( $Create ) {
    $title = "Create a new Keyword";
    $submit = "Create";
    $id = "new";
    %kids = ();
    $Parent = ''; #silence 
} elsif ( $id eq 'new' ) {
    $id = $Keyword->Create( Name => $Name, Parent => $Parent )
      or Abort("can't create keyword Name=>$Name, Parent=>$Parent");
} else {
    $Keyword->Load($id) || Abort("Can't load keyword id $id");
    #foreach my $field ( grep eval "defined(\$$_)", qw( Name Parent )) {
    #  eval "\$Keyword->Set(\$field=>\$$field); #sigh
    #}
    $Keyword->SetName($Name) if defined($Name);
    $Keyword->SetParent($Parent) if defined($Parent);
}

$title = "Modify the Keyword <B>". $Keyword->Name. "</B>";
$submit = "Modify";

my $kids = new RT::Keywords($session{CurrentUser});
$kids->Limit( FIELD => 'Parent', VALUE => $id, OPERATOR => '=' );
$kids{$kid->Name} = $kid while $kid = $kids->Next;

if ( defined($Kids) ) {
    my %newkids;
    if ( $delim eq 'n' ) {
	%newkids = map { $_=>1 } split(/\n/, $Kids);
    } elsif ( $delim eq 's' ) {
	%newkids = map { $_=>1 } split(' ', $Kids);
    } else {
	Abort("'$delim' isn't a valid keyword delimiter.");
    }
    foreach ( grep { ! defined($newkids{$_}) } keys %kids ) {
	$kids{$_}->Delete;
	delete $kids{$_};
    }
    foreach ( grep { ! defined($kids{$_}) } keys %newkids ) {
	$kids{$_} = new RT::Keyword($session{CurrentUser});
	$kids{$_}->Create( Name => $_, Parent => $id )
	  or Abort("can't create keyword Name=>$_, Parent=>$id");
    }

}


my $parent;
my $parents = new RT::Keywords($session{CurrentUser});
$parents->UnLimit;

$delim = ( grep /\s/, keys %kids ) ? 'n' : 's';
my $kidstring = join("\n", keys %kids);

</%INIT>

<%ARGS>
$id => undef
$Create => undef
$Name => undef
$Parent => undef
$Kids => undef
$delim => undef
</%ARGS>