Make the hide/unhide actions a checkbox in the project settings

Also use proper bootstrap layout for the project settings form.
This commit is contained in:
Eelco Dolstra 2013-02-21 01:45:39 +01:00
parent 3924780eac
commit 9c7b416f8b
3 changed files with 70 additions and 79 deletions

View file

@ -60,32 +60,6 @@ sub submit : Chained('project') PathPart Args(0) {
} }
sub hide : Chained('project') PathPart Args(0) {
my ($self, $c) = @_;
requireProjectOwner($c, $c->stash->{project});
txn_do($c->model('DB')->schema, sub {
$c->stash->{project}->update({ hidden => 1, enabled => 0 });
});
$c->res->redirect($c->uri_for("/"));
}
sub unhide : Chained('project') PathPart Args(0) {
my ($self, $c) = @_;
requireProjectOwner($c, $c->stash->{project});
txn_do($c->model('DB')->schema, sub {
$c->stash->{project}->update({ hidden => 0 });
});
$c->res->redirect($c->uri_for("/"));
}
sub requireMayCreateProjects { sub requireMayCreateProjects {
my ($c) = @_; my ($c) = @_;
@ -187,7 +161,8 @@ sub updateProject {
, displayname => $displayName , displayname => $displayName
, description => trim($c->request->params->{description}) , description => trim($c->request->params->{description})
, homepage => trim($c->request->params->{homepage}) , homepage => trim($c->request->params->{homepage})
, enabled => trim($c->request->params->{enabled}) eq "1" ? 1 : 0 , enabled => defined $c->request->params->{enabled} ? 1 : 0
, hidden => defined $c->request->params->{visible} ? 0 : 1
, owner => $owner , owner => $owner
}); });
} }

View file

@ -1,56 +1,77 @@
[% WRAPPER layout.tt title=(create ? "New project" : "Editing project $project.name") %] [% WRAPPER layout.tt title=(create ? "New project" : "Editing project $project.name") %]
[% PROCESS common.tt %] [% PROCESS common.tt %]
<form action="[% IF create %][% c.uri_for('/create-project/submit') %][% ELSE %][% c.uri_for('/project' project.name 'submit') %][% END %]" method="post"> <form class="form-horizontal" action="[% IF create %][% c.uri_for('/create-project/submit') %][% ELSE %][% c.uri_for('/project' project.name 'submit') %][% END %]" method="post">
<table class="layoutTable"> <fieldset>
<tr>
<th>Identifier:</th>
<td><tt>[% INCLUDE editString param="name" value=project.name %]</tt></td>
</tr>
<tr>
<th>Display name:</th>
<td>[% INCLUDE editString param="displayname" value=project.displayname %]</td>
</tr>
<tr>
<th>Description:</th>
<td>[% INCLUDE editString param="description" value=project.description %]</td>
</tr>
<tr>
<th>Homepage:</th>
<td>
[% INCLUDE editString param="homepage" value=project.homepage %]
</td>
</tr>
<tr>
<th>Owner:</th>
<td><tt>[% INCLUDE editString param="owner" value=(project.owner.username || c.user.username) %]</tt></td>
</tr>
<tr>
<th>Enabled:</th>
<td>
[% INCLUDE renderSelection param="enabled" curValue=project.enabled radiobuttons=1 options={"1" = "Yes", "0" = "No"} %]
</td>
</tr>
</table>
<div class="form-actions"> <div class="control-group">
<button type="submit" class="btn btn-primary"> <div class="controls">
<i class="icon-ok icon-white"></i> <label class="checkbox">
[%IF create %]Create[% ELSE %]Apply changes[% END %] <input type="checkbox" name="enabled" value="enabled" [% IF project.enabled; 'checked="checked"'; END %]></input>Enabled
</button> </label>
[% IF !create %] </div>
<button id="delete-project" type="submit" class="btn btn-danger" name="submit" value="delete"> <div class="controls">
<i class="icon-trash icon-white"></i> <label class="checkbox">
Delete this project <input type="checkbox" name="visible" value="visible" [% IF !project.hidden; 'checked="checked"'; END %]></input>Visible in the list of projects
</label>
</div>
</div>
<div class="control-group">
<label class="control-label">Identifier</label>
<div class="controls">
<input type="text" class="span3" name="name" [% HTML.attributes(value => project.name) %]></input>
</div>
</div>
<div class="control-group">
<label class="control-label">Display name</label>
<div class="controls">
<input type="text" class="span3" name="displayname" [% HTML.attributes(value => project.displayname) %]></input>
</div>
</div>
<div class="control-group">
<label class="control-label">Description</label>
<div class="controls">
<input type="text" class="span3" name="description" [% HTML.attributes(value => project.description) %]></input>
</div>
</div>
<div class="control-group">
<label class="control-label">Homepage</label>
<div class="controls">
<input type="text" class="span3" name="homepage" [% HTML.attributes(value => project.homepage) %]></input>
</div>
</div>
<div class="control-group">
<label class="control-label">Owner</label>
<div class="controls">
<input type="text" class="span3" name="owner" [% HTML.attributes(value => project.owner.username || c.user.username) %]></input>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">
<i class="icon-ok icon-white"></i>
[%IF create %]Create[% ELSE %]Apply changes[% END %]
</button> </button>
<script type="text/javascript"> [% IF !create %]
$("#delete-project").click(function() { <button id="delete-project" type="submit" class="btn btn-danger" name="submit" value="delete">
return confirm("Are you sure you want to delete this project?"); <i class="icon-trash icon-white"></i>
}); Delete this project
</script> </button>
[% END %] <script type="text/javascript">
</div> $("#delete-project").click(function() {
return confirm("Are you sure you want to delete this project?");
});
</script>
[% END %]
</div>
</fieldset>
</form> </form>

View file

@ -52,11 +52,6 @@
[% IF c.user_exists %] [% IF c.user_exists %]
<li class="divider"></li> <li class="divider"></li>
[% INCLUDE menuItem uri = c.uri_for('/project' project.name 'edit') title="Edit" %] [% INCLUDE menuItem uri = c.uri_for('/project' project.name 'edit') title="Edit" %]
[% IF project.hidden %]
[% INCLUDE menuItem uri = c.uri_for('/project' project.name 'unhide') title = "Unhide" %]
[% ELSE %]
[% INCLUDE menuItem uri = c.uri_for('/project' project.name 'hide') title = "Hide" %]
[% END %]
[% INCLUDE menuItem uri = c.uri_for(c.controller('Project').action_for('create_jobset'), [project.name]) title = "Create jobset" %] [% INCLUDE menuItem uri = c.uri_for(c.controller('Project').action_for('create_jobset'), [project.name]) title = "Create jobset" %]
[% END %] [% END %]
[% END %] [% END %]