]> git.uio.no Git - usit-rt.git/blame - share/html/Articles/Article/Edit.html
Merge branch 'master' of git.uio.no:usit-rt
[usit-rt.git] / share / html / Articles / Article / Edit.html
CommitLineData
84fb5b46
MKG
1%# BEGIN BPS TAGGED BLOCK {{{
2%#
3%# COPYRIGHT:
4%#
320f0092 5%# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC
84fb5b46
MKG
6%# <sales@bestpractical.com>
7%#
8%# (Except where explicitly superseded by other copyright notices)
9%#
10%#
11%# LICENSE:
12%#
13%# This work is made available to you under the terms of Version 2 of
14%# the GNU General Public License. A copy of that license should have
15%# been provided with this software, but in any event can be snarfed
16%# from www.gnu.org.
17%#
18%# This work is distributed in the hope that it will be useful, but
19%# WITHOUT ANY WARRANTY; without even the implied warranty of
20%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21%# General Public License for more details.
22%#
23%# You should have received a copy of the GNU General Public License
24%# along with this program; if not, write to the Free Software
25%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26%# 02110-1301 or visit their web page on the internet at
27%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
28%#
29%#
30%# CONTRIBUTION SUBMISSION POLICY:
31%#
32%# (The following paragraph is not intended to limit the rights granted
33%# to you to modify and distribute this software under the terms of
34%# the GNU General Public License and is only of importance to you if
35%# you choose to contribute your changes and enhancements to the
36%# community by submitting them to Best Practical Solutions, LLC.)
37%#
38%# By intentionally submitting any modifications, corrections or
39%# derivatives to this work, or any other work intended for use with
40%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41%# you are the copyright holder for those contributions and you grant
42%# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43%# royalty-free, perpetual, license to use, copy, create derivative
44%# works based on those contributions, and sublicense and distribute
45%# those contributions and any derivatives thereof.
46%#
47%# END BPS TAGGED BLOCK }}}
48<& /Elements/Header, Title => $title &>
49<& /Elements/Tabs &>
50<& /Elements/ListActions, actions => \@results &>
51
52<form method="post" action="Edit.html" name="EditArticle" id="EditArticle" enctype="multipart/form-data">
53<input type="hidden" name="next" value="<%$ARGS{next}||''%>" />
54<input type="hidden" name="id" value="<%$id%>" />
55<table width="100%">
56<tr>
57<td><h2><&|/l&>Basics</&></h2></td>
58<td></td>
59</tr>
60<& Elements/EditBasics, ArticleObj => $ArticleObj,
61 EditClass =>$EditClass,
62 ClassObj => $ClassObj,
63 %ARGS ,
64 id => $id
65 &>
66
67<tr>
68<td><h2><&|/l&>Content</&></h2></td>
69<td></td>
70</tr>
71<& Elements/EditCustomFields, ArticleObj => $ArticleObj,
72 CFContent => \%CFContent,
73 ClassObj => $ClassObj,
74 %ARGS,
75 id =>$id,
76 &>
77
78<tr>
79<td><h2><&|/l&>Links</&></h2></td>
80<td></td>
81</tr>
82<& Elements/EditLinks, ArticleObj => $ArticleObj,
83 %ARGS,
84 id => $id
85 &>
86<tr>
87<td><h2><&|/l&>Topics</&></h2></td>
88<td></td>
89</tr>
90<tr>
91<td class="label"><&|/l&>Topics</&></td>
92<td>
93<& Elements/EditTopics, ArticleObj => $ArticleObj,
94 Classes => [$ArticleObj->Id ? $ArticleObj->ClassObj : $ClassObj],
95 OnlyThisClass => 1,
96 %ARGS,
97 id => $id
98 &>
99</td>
100</tr>
101</table>
102<& /Elements/Submit, Label => ($id eq 'new' ? loc('Create') : loc('Save Changes')), color => "#993333" &>
103</form>
104
105<%INIT>
106
107if ( exists $ARGS{'Topics'} ) {
108 $ARGS{'Topics'} =
109 ref( $ARGS{'Topics'} ) ? $ARGS{'Topics'} : [ $ARGS{'Topics'} ];
110}
111
112my @results;
113my $title;
114
115my $Entries = {};
116my $ArticleObj = RT::Article->new( $session{'CurrentUser'} );
117my $ClassObj = RT::Class->new( $session{'CurrentUser'} );
af59614d
MKG
118
119if ($Class) {
120 $ClassObj->Load($Class);
121 Abort(loc("'[_1]' isn't a valid class", $Class)) unless $ClassObj->Id;
122}
123
84fb5b46
MKG
124my %create_args;
125my %CFContent;
126my $EditClass = 1;
127if ( !$id ) {
128 $title = loc('Create a new article');
129 foreach my $arg ( sort keys %ARGS ) {
130 if ( $arg =~ /^Transaction-(\d+)$/ ) {
131 my $trans = RT::Transaction->new( $session{'CurrentUser'} );
132 $trans->Load($1);
133 $CFContent{ $ARGS{$arg} } .= "\n\n" if $CFContent{ $ARGS{$arg} };
134 $CFContent{ $ARGS{$arg} } .= $trans->Content;
135 }
136 }
137
84fb5b46
MKG
138 $EditClass = 0;
139 $id = 'new';
140}
141elsif ( $id eq 'new' ) {
142
143 if ( $ARGS{'RefersTo-new'} ) {
144 @{ $create_args{'RefersTo-new'} } =
145 split( /\s+/, $ARGS{'RefersTo-new'} );
146 }
147
148 if ( $ARGS{'new-RefersTo'} ) {
149 @{ $create_args{'new-RefersTo'} } =
150 split( /\s+/, $ARGS{'new-RefersTo'} );
151 }
152
af59614d
MKG
153 my %cfs = ProcessObjectCustomFieldUpdatesForCreate(
154 ARGSRef => \%ARGS,
155 ContextObject => $ClassObj,
156 );
84fb5b46
MKG
157
158 my $msg;
159 ( $id, $msg ) = $ArticleObj->Create(
160 Summary => $ARGS{'Summary'},
161 Name => $ARGS{'Name'},
162 Class => $ARGS{'Class'},
163 Topics => $ARGS{'Topics'},
af59614d
MKG
164 %create_args,
165 %cfs
84fb5b46
MKG
166 );
167 push( @results, $msg );
168 if ($id) {
169
170
171 $ArticleObj->Load($id);
172
173 $title = loc( 'Modify article #[_1]', $ArticleObj->Id );
174 delete $ARGS{id};
175
176 if ( $ARGS{next} ) {
177 $m->redirect($ARGS{next});
178 }
179 else {
180 MaybeRedirectForResults(
181 Actions => \@results,
182 Arguments => { id => $ArticleObj->id },
183 );
184 }
185 }
af59614d 186 else {
84fb5b46
MKG
187 $ArticleObj = RT::Article->new( $session{'CurrentUser'} );
188 $id = 'new';
189 $EditClass = 0;
190 $title = loc('Create a new article');
191 }
192}
193else {
194
195 $ArticleObj->Load($id);
196 unless ( $ArticleObj->id ) {
197 $m->comp( "/Elements/Error",
198 Why => loc("Unable to load article") );
199 }
200
201 my @attribs = qw(Name Summary Class);
202
203 @results = UpdateRecordObject(
204 AttributesRef => \@attribs,
205 Object => $ArticleObj,
206 ARGSRef => \%ARGS
207 );
208
209 my @cf_results = ProcessObjectCustomFieldUpdates(
210 Object => $ArticleObj,
211 ARGSRef => \%ARGS
212 );
213 @results = ( @results, @cf_results );
214
215 # Delete links that are gone gone gone.
216 foreach my $arg ( keys %ARGS ) {
217 if ( $arg =~ /DeleteLink-(.*?)-(RefersTo|MemberOf|RefersTo)-(.*)$/ ) {
218 my $base = $1;
219 my $type = $2;
220 my $target = $3;
221
222 my ( $val, $msg ) = $ArticleObj->DeleteLink(
223 Base => $base,
224 Type => $type,
225 Target => $target
226 );
227
228 push @results, $msg;
229
230 }
231
232 }
233
234 my @linktypes = qw(DependsOn MemberOf RefersTo );
235
236 foreach my $linktype (@linktypes) {
237
238 for my $luri ( split( / /, ( $ARGS{ $ArticleObj->Id . "-$linktype" } || '' )) ) {
239 $luri =~ s/\s*$//; # Strip trailing whitespace
240 my ( $val, $msg ) =
241 $ArticleObj->AddLink( Target => $luri, Type => $linktype );
242 push @results, $msg;
243 delete $ARGS{ $ArticleObj->Id . "-$linktype" } if $val;
244 }
245
246 for my $luri ( split( / /, ( $ARGS{ "$linktype-" . $ArticleObj->Id } || '' )) ) {
247 my ( $val, $msg ) =
248 $ArticleObj->AddLink( Base => $luri, Type => $linktype );
249 push @results, $msg;
250 delete $ARGS{ "$linktype-" . $ArticleObj->Id } if $val;
251 }
252
253 }
254
255 my %topics;
256 if ( $ARGS{'EditTopics'} ) {
257 $topics{$_}++ for @{ $ARGS{'Topics'} };
258 my $objTopics =
259 RT::ObjectTopics->new( $session{'CurrentUser'} );
260 $objTopics->LimitToObject($ArticleObj);
261 while ( my $t = $objTopics->Next ) {
262 $topics{ $t->Topic }--;
263 }
264 for my $id ( keys %topics ) {
265 if ( $topics{$id} > 0 ) {
266 my ( $val, $msg ) = $ArticleObj->AddTopic( Topic => $id );
267 push @results, $msg;
268 }
269 elsif ( $topics{$id} < 0 ) {
270 my ( $val, $msg ) = $ArticleObj->DeleteTopic( Topic => $id );
271 push @results, $msg;
272 }
273 }
274 }
275
276 $title = loc( 'Modify article #[_1]', $ArticleObj->Id );
277}
278
279# if they're working on an existing article
280if ( $ArticleObj->id ) {
281 unless ( $ArticleObj->CurrentUserHasRight('ShowArticle') ) {
282 $m->comp( "/Elements/Error",
283 Why => loc("No permission to view Article") );
284 }
285}
286
287</%INIT>
288
289
290<%ARGS>
291$id => undef
292$Class => undef
293</%ARGS>