service templates - move to blade - deprecate remove_service_template

This commit is contained in:
Anthony F McInerney
2020-10-17 19:49:07 +01:00
parent aa8cf04021
commit 857bde274a
5 changed files with 27 additions and 42 deletions
@@ -152,7 +152,21 @@ class ServiceTemplateController extends Controller
return redirect()->route('services.templates.index');
}
/**
* Remove the specified resource from storage.
*
* @param \App\Models\ServiceTemplate $serviceTemplate
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response|\Illuminate\View\View
*/
public function remove(ServiceTemplate $serviceTemplate)
{
Service::where('service_template_id', $serviceTemplate)->delete();
Toastr::success(__('Service Template :name removed', ['name' => $serviceTemplate->name]));
return redirect()->route('services.templates.index');
}
/**
* Remove the specified resource from storage.
*
+1
View File
@@ -5,6 +5,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use LibreNMS\Interfaces\Models\Keyable;
use Permissions;
class ServiceTemplate extends Model implements Keyable
{
+1 -1
View File
@@ -43,7 +43,7 @@ class ServiceTemplatePolicy
/**
* Determine whether the user can view any services template.
*
* @param \App\User $user
* @param \App\Models\User $user
* @return mixed
*/
public function viewAny(User $user)
@@ -1,28 +0,0 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2016 Aaron Daniels <[email protected]>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
if (! Auth::user()->hasGlobalAdmin()) {
exit('ERROR: You need to be admin');
}
$id = $vars['id'];
if (is_numeric($id)) {
if (remove_service_template($id)) {
$status = ['status' =>0, 'message' => 'Service Template: <i>' . $id . ', has been removed from Services.</i>'];
} else {
$status = ['status' =>1, 'message' => 'Service Template: <i>' . $id . ', has NOT been removed from Services.</i>'];
}
}
header('Content-Type: application/json');
echo _json_encode($status);
@@ -52,7 +52,7 @@
<i
class="fa fa-plus" aria-hidden="true"></i></button>
<button type="button" title="@lang('Remove Services for this Service Template')" class="btn btn-warning btn-sm" aria-label="@lang('Apply')"
onclick="remove_st(this, '{{ $service_template->id }}')">
onclick="remove_st(this, '{{ $service_template->name }}', '{{ route('services.templates.remove', $service_template->id) }}')">
<i
class="fa fa-minus" aria-hidden="true"></i></button>
<a type="button" title="@lang('edit Service Template')" class="btn btn-primary btn-sm" aria-label="@lang('Edit')"
@@ -98,24 +98,22 @@
}
}
function remove_st(button, id) {
var index = button.parentNode.parentNode.rowIndex;
if (confirm('@lang('Are you sure you want to remove all Services created by ')' + name + '?')) {
$.ajax({
type: 'POST',
url: 'ajax_form.php',
data: { type: "remove-service-template", id: id },
dataType: "json",
success: function(data){
if(data['status'] == 'ok') {
toastr.success(data['message']);
} else {
toastr.error(data['message']);
}
url: url,
type: 'DELETE',
success: function (msg) {
document.getElementById("manage-services-table").deleteRow(index);
toastr.success(msg);
},
error:function(){
toastr.error('No Services were removed for this Service Template');
error: function () {
toastr.error('@lang('No Services for this Service Template were deleted')');
}
});
}
return false;
}
function delete_st(button, id) {
var index = button.parentNode.parentNode.rowIndex;