Skip to content

Commit

Permalink
add rename page logic
Browse files Browse the repository at this point in the history
  • Loading branch information
yuki-kimoto committed May 19, 2017
1 parent 9cc7536 commit 5e30609
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions templates/wiki.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
else {
if ($op eq 'create') {

my $title = param('title');
my $update_title = param('update-title');
my $original_title = param('original-title');
my $content = param('content');
my $commit_message = param('commit-message');

Expand All @@ -70,7 +71,7 @@
my $validation = $vc->validation;

# Title
if (!length $title) {
if (!length $update_title) {
$validation->add_failed(title => 'Page title is empty.');
}
elsif ($title =~ /^_/) {
Expand All @@ -80,11 +81,18 @@
}

if (!length $commit_message) {
$commit_message = "Updated $title";
$commit_message = "Updated $update_title";
}

if ($validation->is_valid) {
$api->create_wiki_page($user_id, $project_id, $title, $content, $commit_message);
# Rename and update page
if (defined $original_title && length $original_title && $update_title ne $original_title) {
$api->rename_and_update_wiki_page($user_id, $project_id, $original_title, $update_title, $content, $commit_message);
}
# Create or update page
else {
$api->create_wiki_page($user_id, $project_id, $update_title, $content, $commit_message);
}

$self->redirect_to("/$user_id/$project_id/wiki/$title");
return;
Expand Down Expand Up @@ -332,8 +340,7 @@
<%= hidden_field 'original-title' => $title %>
<label>
<div class="wiki-edit-form-title">
% param(title => $title);
%= text_field 'title', placeholder => 'Title';
%= text_field 'update-title' => $title, placeholder => 'Title';
</div>
</label>
<div class="wiki-add-comment">
Expand Down

0 comments on commit 5e30609

Please sign in to comment.