summaryrefslogtreecommitdiff
path: root/rt/webrt/Admin/Elements/ModifyKeywordSelect
blob: 470e6292972546c2471971b7ebceebd9f30ffc97 (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
  <FORM NAME="ModifyKeywordSelect" METHOD=POST ACTION="<%$RT::WebPath%>/Admin/KeywordSelects/Modify.html">

    [<%$title |n %>]
    <BR>
      
      <INPUT TYPE="hidden" NAME="id" VALUE="<% $id %>">
	Keyword 
	<SELECT NAME="Parent">
	  
%while ( $parent = $parents->Next ) {
	  
	  <OPTION VALUE="<% $parent->id %>" <% defined($KeywordSelect->Parent) && $parent->id == $KeywordSelect->Parent ? ' SELECTED' : '' %>><% $parent->Name %></OPTION>
	  
% }
	  
	</SELECT>
	<BR>
	  Object 
	  <SELECT NAME="ObjectType">
	    <OPTION SELECTED>Ticket</OPTION>
	  </SELECT>
	  <BR>
	    
<SCRIPT>
function addOption(text, value, defaultselected, selected) {
  var option = new Option(text, value, defaultselected, selected )
  var length = document.ModifyKeywordSelect.ObjectValue.length;
  document.ModifyKeywordSelect.ObjectValue.options[length] = option
}
function ChangeObjectValue(what) {
  Value = what.options[what.selectedIndex].value
  if ( Value == "(none)" ) {
    document.ModifyKeywordSelect.ObjectValue.options.length = 0
    addOption("(n/a)", "", false, false)
  }
  if ( Value == "Queue" ) {
    document.ModifyKeywordSelect.ObjectValue.options.length = 0
%foreach $queue ( keys %queues ) {
    addOption("<% $queues{$queue} %>", "<% $queue %>", false, <% $queue == $KeywordSelect->ObjectValue ? 'true' : 'false' %> )
%}
  }
}
</SCRIPT>
	    
	    Limit to <SELECT NAME="ObjectField" onChange="ChangeObjectValue(this)">
	      <OPTION VALUE="" <% $KeywordSelect->ObjectField ? '' : ' SELECTED' %>>(none)</OPTION>
	      <OPTION VALUE="Queue" <% $KeywordSelect->ObjectField eq 'Queue' ? ' SELECTED' : '' %>>Queue</OPTION>
	    </SELECT> 
	    <SELECT NAME="ObjectValue">
	      <OPTION VALUE="<% $KeywordSelect->ObjectValue %>">
		<% $KeywordSelect->ObjectField ? $queues{$KeywordSelect->ObjectValue} : "(n/a)" %></OPTION>
	    </SELECT><BR>
	      <INPUT TYPE="hidden" NAME="SingleMagic" VALUE="1">
		<INPUT TYPE="checkbox" NAME="Single" VALUE="1" <% $KeywordSelect->Single ? ' CHECKED' : '' %>>Allow single selection only<BR>
		    Limit to <INPUT TYPE="text" NAME="Generations" SIZE="2" VALUE="<% $KeywordSelect->Generations %>"> generations (0 = no limit)<BR>
			<& /Elements/Submit, Label => $submit &>

</FORM>

<%INIT>


my $KeywordSelect = new RT::KeywordSelect($session{CurrentUser});
  
my($title, $submit);
  
if ( $Create ) {
      $title = "Create a new KeywordSelect";
      $submit = "Create";
      $id = "new";
} else {
    if  ( $id eq 'new' ) {
	$id = $KeywordSelect->Create (
				      Parent      => $Parent,
				      ObjectType  => $ObjectType,
				      ObjectField => $ObjectField,
				      ObjectValue => $ObjectValue,
				      Single      => $Single,
				      Generations => $Generations,
				     ) or Abort "can't create KeywordSelect";
    } else {
	$KeywordSelect->Load($id) || Abort("Can't load keyword id $id");
	#false laziness
	$KeywordSelect->SetParent($Parent) if defined($Parent);
	$KeywordSelect->SetObjectType($ObjectType) if defined($ObjectType);
	$KeywordSelect->SetObjectField($ObjectField) if defined($ObjectField);
	$KeywordSelect->SetObjectValue($ObjectValue) if defined($ObjectValue);
	$KeywordSelect->SetSingle($Single) if defined($SingleMagic);
	$KeywordSelect->SetGenerations($Generations) if defined($Generations);
    }
    $title = "Modify the KeywordSelect <B>". $KeywordSelect->KeywordObj->Name. "</B>";
    $submit = "Modify";
    
}
  
  my $parents = new RT::Keywords($session{CurrentUser});
  $parents->UnLimit;
  my $parent;

my $queues = new RT::Queues($session{CurrentUser});
$queues->UnLimit;

my %queues;
my $queue;
$queues{$queue->id} = $queue->Name while $queue = $queues->Next;

</%INIT>

<%ARGS>
$id => undef
$Create => undef
$Parent => undef
$ObjectType => undef
$ObjectField => undef
$ObjectValue => undef
$Single => undef
$SingleMagic => undef
$Generations => undef
</%ARGS>