| 1293 |
dpurdie |
1 |
###############################################################################
|
|
|
2 |
# Codestriker: Copyright (c) 2001, 2002 David Sitsky. All rights reserved.
|
|
|
3 |
# sits@users.sourceforge.net
|
|
|
4 |
#
|
|
|
5 |
# This program is free software; you can redistribute it and modify it under
|
|
|
6 |
# the terms of the GPL.
|
|
|
7 |
|
|
|
8 |
# Action object for displaying the create topic form.
|
|
|
9 |
|
|
|
10 |
package Codestriker::Action::CreateTopic;
|
|
|
11 |
|
|
|
12 |
use strict;
|
|
|
13 |
use Codestriker::Http::Cookie;
|
|
|
14 |
use Codestriker::Model::Project;
|
|
|
15 |
|
|
|
16 |
# Create an appropriate form for creating a new topic.
|
|
|
17 |
sub process($$$) {
|
|
|
18 |
my ($type, $http_input, $http_response) = @_;
|
|
|
19 |
|
|
|
20 |
my $query = $http_response->get_query();
|
|
|
21 |
my $obsoletes = $http_input->get('obsoletes');
|
|
|
22 |
$http_response->generate_header(topic_title=>"Create New Topic",
|
|
|
23 |
reload=>0, cache=>1);
|
|
|
24 |
|
|
|
25 |
# Obtain a URL builder object.
|
|
|
26 |
my $url_builder = Codestriker::Http::UrlBuilder->new($query);
|
|
|
27 |
|
|
|
28 |
# Create the hash for the template variables.
|
|
|
29 |
my $vars = {};
|
|
|
30 |
$vars->{'error_message'} = "";
|
|
|
31 |
$vars->{'topic_text'} = "";
|
|
|
32 |
$vars->{'topic_file'} = "";
|
|
|
33 |
$vars->{'topic_description'} = "";
|
|
|
34 |
$vars->{'topic_title'} = $http_input->get('topic_title');
|
|
|
35 |
$vars->{'bug_ids'} = $http_input->get('bug_ids');
|
|
|
36 |
$vars->{'feedback'} = $http_input->get('feedback');
|
|
|
37 |
$vars->{'default_to_head'} = "";
|
|
|
38 |
|
|
|
39 |
# Indicate where the documentation directory and generate the search
|
|
|
40 |
# url.
|
|
|
41 |
$vars->{'doc_url'} = $url_builder->doc_url();
|
|
|
42 |
$vars->{'search_url'} = $url_builder->search_url();
|
|
|
43 |
|
|
|
44 |
# Retrieve the email, reviewers, cc, repository and projectid from
|
|
|
45 |
# the cookie.
|
|
|
46 |
$vars->{'email'} =
|
|
|
47 |
Codestriker::Http::Cookie->get_property($query, 'email');
|
|
|
48 |
$vars->{'reviewers'} =
|
|
|
49 |
Codestriker::Http::Cookie->get_property($query, 'reviewers');
|
|
|
50 |
$vars->{'cc'} =
|
|
|
51 |
Codestriker::Http::Cookie->get_property($query, 'cc');
|
|
|
52 |
$vars->{'default_repository'} =
|
|
|
53 |
Codestriker::Http::Cookie->get_property($query, 'repository');
|
|
|
54 |
$vars->{'default_projectid'} =
|
|
|
55 |
Codestriker::Http::Cookie->get_property($query, 'projectid');
|
|
|
56 |
|
|
|
57 |
# Set the default repository to select.
|
|
|
58 |
if (! (defined $vars->{'default_repository'}) ||
|
|
|
59 |
$vars->{'default_repository'} eq "") {
|
|
|
60 |
if ($#Codestriker::valid_repository_names != -1) {
|
|
|
61 |
# Choose the first repository as the default selection.
|
|
|
62 |
$vars->{'default_repository'} =
|
|
|
63 |
$Codestriker::valid_repository_names[0];
|
|
|
64 |
}
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
# Indicate the list of valid repositories which can be choosen.
|
|
|
68 |
$vars->{'repositories'} = \@Codestriker::valid_repository_names;
|
|
|
69 |
|
|
|
70 |
# Read the list of projects available to make that choice available
|
|
|
71 |
# when a topic is created.
|
|
|
72 |
my @projects = Codestriker::Model::Project->list('Open');
|
|
|
73 |
$vars->{'projects'} = \@projects;
|
|
|
74 |
|
|
|
75 |
# If this create topic action obsoletes some topics, then get their
|
|
|
76 |
# details now. For now, don't check if a topic is stale with the
|
|
|
77 |
# version parameter.
|
|
|
78 |
$vars->{'obsoletes'} = $obsoletes;
|
|
|
79 |
if ($type->set_obsoleted_topics_parameter($vars, $url_builder) == -1) {
|
|
|
80 |
$http_response->error("Obsoleted topic no longer exists.");
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
my $template = Codestriker::Http::Template->new("createtopic");
|
|
|
84 |
$template->process($vars);
|
|
|
85 |
|
|
|
86 |
$http_response->generate_footer();
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
# Set the obsoleted_topics parameter correctly into $vars. Return -1 if
|
|
|
90 |
# there was a failure.
|
|
|
91 |
sub set_obsoleted_topics_parameter {
|
|
|
92 |
my ($type, $vars, $url_builder) = @_;
|
|
|
93 |
|
|
|
94 |
my $obsoletes = $vars->{'obsoletes'};
|
|
|
95 |
my @obsoleted_topics = ();
|
|
|
96 |
if (defined $obsoletes and $obsoletes ne '') {
|
|
|
97 |
my @topics = split ',', $obsoletes;
|
|
|
98 |
for (my $i = 0; $i <= $#topics; $i+=2) {
|
|
|
99 |
my $topicid = $topics[$i];
|
|
|
100 |
if (Codestriker::Model::Topic::exists($topicid) == 0) {
|
|
|
101 |
return -1;
|
|
|
102 |
}
|
|
|
103 |
my $topic = Codestriker::Model::Topic->new($topicid);
|
|
|
104 |
my $obsoleted_topic = {};
|
|
|
105 |
$obsoleted_topic->{title} = $topic->{title};
|
|
|
106 |
$obsoleted_topic->{view_url} =
|
|
|
107 |
$url_builder->view_url($topicid, -1);
|
|
|
108 |
push @obsoleted_topics, $obsoleted_topic;
|
|
|
109 |
}
|
|
|
110 |
}
|
|
|
111 |
$vars->{'obsoleted_topics'} = \@obsoleted_topics;
|
|
|
112 |
return 0;
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
1;
|