Skip to content

Commit b47a237

Browse files
committed
Adding ability to edit boards more robustly
1 parent cdb7dde commit b47a237

File tree

4 files changed

+87
-1
lines changed

4 files changed

+87
-1
lines changed

public/less/master_mixins.less

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,6 @@ input[type="color"]:focus,
590590
div.labels {
591591
margin-left: 25px;
592592
display: block;
593-
border-bottom: 1px solid lighten(@grey, 10%);
594593
div {
595594
display: block;
596595
&.subject {

src/controllers/Forum/Core_BoardController.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,55 @@ public function postAdd()
8080
return $this->redirect(null, $board->name.' has been submitted.');
8181
}
8282
}
83+
84+
public function getEdit($boardId)
85+
{
86+
// Make sure they can access this whole area
87+
$this->checkPermission('FORUM_ADMIN');
88+
89+
$board = Forum_Board::find($boardId);
90+
91+
$boards = Forum_Board::where('uniqueId', '!=', $boardId)->orderBy('name', 'asc')->get()->toSelectArray('Select a parent board');
92+
$categories = $this->arrayToSelect(Forum_Category::orderBy('position', 'asc')->get(), 'id', 'name', 'Select Category');
93+
$types = $this->arrayToSelect(Forum_Board_Type::orderBy('name', 'asc')->get(), 'id', 'name', 'Select Board Type');
94+
95+
// Set the template
96+
$this->setViewData('board', $board);
97+
$this->setViewData('boards', $boards);
98+
$this->setViewData('categories', $categories);
99+
$this->setViewData('types', $types);
100+
101+
}
102+
103+
public function postEdit($boardId)
104+
{
105+
// Handle any form data
106+
$input = Input::all();
107+
108+
if ($input != null) {
109+
$board = Forum_Board::find($boardId);
110+
$board->name = $input['name'];
111+
$board->forum_category_id = (isset($input['forum_category_id']) && $input['forum_category_id'] != null ? $input['forum_category_id'] : null);
112+
$board->forum_board_type_id = (isset($input['forum_board_type_id']) && $input['forum_board_type_id'] != 0 ? $input['forum_board_type_id'] : null);
113+
$board->parent_id = (isset($input['parent_id']) && strlen($input['parent_id']) == 10 ? $input['parent_id'] : null);
114+
$board->keyName = Str::slug($input['name']);
115+
$board->description = $input['description'];
116+
117+
if ($board->parent_id != null) {
118+
$parent = Forum_Board::find($board->parent_id);
119+
$childrenCount = $parent->children->count();
120+
121+
$board->position = $childrenCount + 1;
122+
} else {
123+
$category = Forum_Category::find($board->forum_category_id);
124+
$boardCount = $category->boards->count();
125+
126+
$board->position = $boardCount + 1;
127+
}
128+
129+
$this->checkErrorsSave($board);
130+
131+
return $this->redirect(null, $board->name.' has been updated.');
132+
}
133+
}
83134
}

src/views/forum/admin/boards.blade.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
</td>
2727
<td>
2828
<div class="btn-group">
29+
{{ HTML::link('forum/board/edit/'. $board->id, 'Edit', array('class' => 'btn btn-xs btn-primary')) }}
2930
{{ HTML::link('forum/admin/delete-board/'. $board->id, 'Delete', array('class' => 'confirm-remove btn btn-xs btn-danger')) }}
3031
</div>
3132
</td>
@@ -60,6 +61,7 @@
6061
</td>
6162
<td>
6263
<div class="btn-group">
64+
{{ HTML::link('forum/board/edit/'. $child->id, 'Edit', array('class' => 'btn btn-xs btn-primary')) }}
6365
{{ HTML::link('forum/admin/delete-board/'. $child->id, 'Delete', array('class' => 'confirm-remove btn btn-xs btn-danger')) }}
6466
</div>
6567
</td>

src/views/forum/board/edit.blade.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{{ bForm::open() }}
2+
<div class="row">
3+
<small>
4+
<ul class="breadcrumb">
5+
<li>{{ HTML::link('forum', 'Forums') }}</li>
6+
<li>{{ HTML::link('forum/category/view/'. $board->category->id, $board->category->name) }}</li>
7+
<li class="active">Edit Board</li>
8+
</ul>
9+
</small>
10+
<div class="col-md-offset-3 col-md-6">
11+
<div class="panel panel-default">
12+
<div class="panel-heading">Add new forum board</div>
13+
<div class="panel-body">
14+
{{ bForm::select('forum_category_id', $categories, $board->forum_category_id, array(), 'Category') }}
15+
{{ bForm::text('name', $board->name, array('placeholder' => 'Name'), 'Name') }}
16+
{{ bForm::select('forum_board_type_id', $types, $board->forum_board_type_id, array('onChange' => 'isChild(this)'), 'Type') }}
17+
{{ bForm::select('parent_id', $boards, $board->parent_id, array('id' => 'child', 'style' => 'display: none;'), 'Parent') }}
18+
{{ bForm::textarea('description', $board->description, array('placeholder' => 'Description'), 'Description') }}
19+
{{ bForm::submit('Update Board') }}
20+
</div>
21+
</div>
22+
</div>
23+
</div>
24+
</div>
25+
{{ bForm::close() }}
26+
<script type="text/javascript">
27+
function isChild(object) {
28+
if ($(object).val() == 2) {
29+
$('#child').css('display', 'inline');
30+
} else {
31+
$('#child').css('display', 'none');
32+
}
33+
}
34+
</script>

0 commit comments

Comments
 (0)