Allow deleting of a component group. Closes #286

This commit is contained in:
James Brooks 2015-01-05 15:21:09 +00:00 committed by James Brooks
parent 0d326de0b2
commit 2af867b863
7 changed files with 35 additions and 7 deletions

View File

@ -1,5 +1,4 @@
$(function() {
// Ajax Setup
$.ajaxPrefilter(function(options, originalOptions, jqXHR) {
var token;
@ -28,6 +27,20 @@ $(function() {
$form.find(':submit').prop('disabled', true);
});
// Mock the DELETE form requests.
$('[data-method]').not(".disabled").append(function() {
var methodForm = "\n";
methodForm += "<form action='" + $(this).attr('href') + "' method='POST' style='display:none'>\n";
methodForm += " <input type='hidden' name='_method' value='" + $(this).attr('data-method') + "'>\n";
if ($(this).attr('data-token')) {
methodForm += "<input type='hidden' name='_token' value='" + $(this).attr('data-token') + "'>\n";
}
methodForm += "</form>\n";
return methodForm;
})
.removeAttr('href')
.attr('onclick', ' if ($(this).hasClass(\'confirm-action\')) { if(confirm("Are you sure you want to do this?")) { $(this).find("form").submit(); } } else { $(this).find("form").submit(); }');
// Messenger config
Messenger.options = {
extraClasses: 'messenger-fixed messenger-on-top',

View File

@ -26,8 +26,9 @@ Route::group(['before' => 'auth', 'prefix' => 'dashboard', 'namespace' => 'Cache
'as' => 'dashboard.components.groups.add',
'uses' => 'DashComponentController@showAddComponentGroup',
]);
Route::delete('groups/{component_group}/delete', 'DashComponentController@deleteComponentGroupAction');
Route::post('groups/add', 'DashComponentController@postAddComponentGroup');
Route::get('{component}/delete', 'DashComponentController@deleteComponentAction');
Route::delete('{component}/delete', 'DashComponentController@deleteComponentAction');
Route::get('{component}/edit', 'DashComponentController@showEditComponent');
Route::post('{component}/edit', 'DashComponentController@updateComponentAction');
});
@ -43,7 +44,7 @@ Route::group(['before' => 'auth', 'prefix' => 'dashboard', 'namespace' => 'Cache
'uses' => 'DashIncidentController@showAddIncident',
]);
Route::post('add', 'DashIncidentController@createIncidentAction');
Route::get('{incident}/delete', 'DashIncidentController@deleteIncidentAction');
Route::delete('{incident}/delete', 'DashIncidentController@deleteIncidentAction');
Route::get('{incident}/edit', 'DashIncidentController@showEditIncidentAction');
Route::post('{incident}/edit', 'DashIncidentController@editIncidentAction');
Route::get('template', [

View File

@ -23,8 +23,7 @@
<strong>{{ $group->name }}</strong>
</div>
<div class='col-md-4 text-right'>
<a href='#' class='btn btn-default'>{{ trans('forms.edit') }}</a>
<a href='#' class='btn btn-danger'>{{ trans('forms.delete') }}</a>
<a href='/dashboard/components/groups/{{ $group->id }}/delete' class='btn btn-danger confirm-action' data-method='DELETE'>{{ trans('forms.delete') }}</a>
</div>
</div>
@empty

View File

@ -33,7 +33,7 @@
</div>
<div class='col-md-4 text-right'>
<a href='/dashboard/components/{{ $component->id }}/edit' class='btn btn-default'>{{ trans('forms.edit') }}</a>
<a href='/dashboard/components/{{ $component->id }}/delete' class='btn btn-danger'>{{ trans('forms.delete') }}</a>
<a href='/dashboard/components/{{ $component->id }}/delete' class='btn btn-danger confirm-action' data-method='DELETE'>{{ trans('forms.delete') }}</a>
</div>
<input type='hidden' rel='order' name='component[{{ $component->id }}]' value='{{ $component->order }}' />
</div>

View File

@ -29,7 +29,7 @@
</div>
<div class="col-md-6 text-right">
<a href="/dashboard/incidents/{{ $incident->id }}/edit" class="btn btn-default">{{ trans('forms.edit') }}</a>
<a href="/dashboard/incidents/{{ $incident->id }}/delete" class="btn btn-danger">{{ trans('forms.delete') }}</a>
<a href="/dashboard/incidents/{{ $incident->id }}/delete" class="btn btn-danger confirm-action" data-method='DELETE'>{{ trans('forms.delete') }}</a>
</div>
</div>
@endforeach

View File

@ -144,6 +144,20 @@ class DashComponentController extends Controller
return Redirect::back();
}
/**
* Deletes a given component group.
*
* @param \CachetHQ\Cachet\Models\ComponentGroup $group
*
* @return \Illuminate\Http\RedirectResponse
*/
public function deleteComponentGroupAction(ComponentGroup $group)
{
$group->delete();
return Redirect::back();
}
/**
* Shows the add component group view.
*

View File

@ -38,6 +38,7 @@ class RoutingServiceProvider extends ServiceProvider
protected function registerBindings()
{
$this->app->router->model('component', 'CachetHQ\Cachet\Models\Component');
$this->app->router->model('component_group', 'CachetHQ\Cachet\Models\ComponentGroup');
$this->app->router->model('incident', 'CachetHQ\Cachet\Models\Incident');
$this->app->router->model('incident_template', 'CachetHQ\Cachet\Models\IncidentTemplate');
$this->app->router->model('setting', 'CachetHQ\Cachet\Models\Setting');