Skip to content

Commit

Permalink
added setting delete button
Browse files Browse the repository at this point in the history
  • Loading branch information
Simonas Šerlinskas committed Sep 5, 2016
1 parent 760e287 commit f962940
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 39 deletions.
9 changes: 3 additions & 6 deletions Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,14 @@ public function updateValueAction(Request $request)
* Setting delete action
*
* @param Request $request
* @param $id
*
* @return JsonResponse
*/
public function deleteAction(Request $request, $id)
public function deleteAction(Request $request)
{
try {
/** @var Repository $repo */
$repo = $this->get($this->getParameter('ongr_settings.repo'));

$repo->remove($id);
$manager = $this->get('ongr_settings.settings_manager');
$manager->delete($request->get('name'));

return new JsonResponse(['error' => false]);
} catch (\Exception $e) {
Expand Down
16 changes: 2 additions & 14 deletions Resources/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,7 @@ ongr_settings_settings_update_value:
expose: true

ongr_settings_settings_delete:
path: /settings/delete/{id}
path: /settings/delete
defaults: { _controller: ONGRSettingsBundle:Settings:delete }
options:
expose: true

#ongr_settings_profiles_fallback:
# path: /profiles/{url}
# defaults: { _controller: ONGRSettingsBundle:Profiles:list, url: null }
# requirements:
# url: .*

#ongr_settings_fallback:
# path: /settings/{url}
# defaults: { _controller: ONGRSettingsBundle:Settings:list, url: null }
# requirements:
# url: .*
expose: true
38 changes: 23 additions & 15 deletions Resources/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ $(document).ready(function () {
"targets": 4,
"data": null,
"orderable": false,
"defaultContent": '<a class="edit btn btn-primary btn-xs" data-toggle="modal" data-target="#setting-edit">Edit</a>&nbsp;<a class="delete btn btn-danger btn-xs" data-toggle="modal" data-target="#setting-delete">Delete</a>'
"render": function ( data, type, row ) {
return '<a class="edit btn btn-primary btn-xs" data-toggle="modal" data-target="#setting-edit">Edit</a>&nbsp;<a class="delete delete-setting btn btn-danger btn-xs" data-name="'+row['name']+'">Delete</a>'
}
} ]
} );

Expand Down Expand Up @@ -184,18 +186,24 @@ $(document).ready(function () {
})
} );

// $('#setting_delete_submit').on('click', function () {
// var id = $(this).attr('rel');
// $.ajax({
// url: "./settings/delete/"+id,
// success: function (data) {
// if (data.error) {
// alert(data.message);
// } else {
// table.ajax.reload();
// $('.modal').modal('hide');
// }
// }
// });
// });
$('#settings tbody').on( 'click', 'a.delete-setting', function (e) {
e.preventDefault();

var name = $(this).data('name');
$.confirm({
text: "Are you sure you want to delete "+name+" setting?",
title: "Confirmation required",
confirm: function(button) {
$.post(Routing.generate('ongr_settings_settings_delete'), {name: name}, function(data) {
if (data.error == false) {
table.ajax.reload();
}
});
},
confirmButton: "Yes, delete it",
cancelButton: "No",
confirmButtonClass: "btn-danger",
dialogClass: "modal-dialog modal-lg"
});
});
});
2 changes: 1 addition & 1 deletion Resources/public/script.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Resources/views/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.12/css/dataTables.bootstrap.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/2.5.1/jquery-confirm.min.css">
<link href="{{ asset('bundles/ongrsettings/style.css') }}" type="text/css" rel="stylesheet">
{% endblock %}
<script src="https://use.fontawesome.com/df9d1609ee.js"></script>
Expand Down Expand Up @@ -40,11 +41,11 @@
{% block javascripts %}
<script src="{{ asset('bundles/fosjsrouting/js/router.js') }}"></script>
<script src="{{ path('fos_js_routing_js', { callback: 'fos.Router.setData' }) }}"></script>

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.12/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.12/js/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/2.5.1/jquery-confirm.min.js"></script>
<script type="text/javascript" src="{{ asset('bundles/ongrsettings/script.js') }}"></script>
{% endblock %}
</body>
Expand Down
9 changes: 7 additions & 2 deletions Service/SettingsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,17 @@ public function update($name, $data = [])
*
* @param string $name
*
* @throws \LogicException
* @return array
*/
public function delete($name)
{
$setting = $this->repo->findOneBy(['name' => $name]);
return $this->repo->remove($setting->getId());
if ($this->has($name)) {
$setting = $this->repo->findOneBy(['name' => $name]);
return $this->repo->remove($setting->getId());
}

throw new \LogicException(sprintf('Setting with name %s doesn\'t exist.', $name));
}

/**
Expand Down

0 comments on commit f962940

Please sign in to comment.