list.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. if (!hasPermission("list")) {
  3. die("Not enough permissions.");
  4. }
  5. $type = "";
  6. if (isset($_GET['type']))
  7. $type = $_GET['type'];
  8. else
  9. die("No type specified.");
  10. ?>
  11. <div class="row">
  12. <div class="col-lg-12">
  13. <h1 class="page-header"><?php echo "List $type"; ?></h1>
  14. </div>
  15. <!-- /.col-lg-12 -->
  16. </div>
  17. <form id="new">
  18. <div class="input-group">
  19. <span class="input-group-addon" id="name-addon">Name</span>
  20. <input name="name" id="name" type="text" class="form-control" placeholder="New entry name" aria-describedby="name-addon">
  21. <span class="input-group-btn">
  22. <button class="btn btn-primary" type="button">Add new entry <span class="fa fa-plus"></span></button>
  23. </span>
  24. </div>
  25. </form>
  26. <div class="panel panel-default">
  27. <div class="panel-heading">List of entries</div>
  28. <div class="panel-body table-panel">
  29. <table class="list table table-striped table-bordered table-hover dataTable no-footer"><thead><tr><th>Name</th><th>Actions</th></tr></thead>
  30. <tbody>
  31. </tbody>
  32. </table>
  33. </div>
  34. </div>
  35. <script type="text/javascript">
  36. function refreshTable() {
  37. $.get("actions/getList.php?type=<?php echo $type ?>", function(data) {
  38. $(".list tbody").html(data);
  39. });
  40. $(".list tbody").sortable({ opacity: 0.6, cursor: 'move', update: function() {
  41. var order = $(this).sortable("serialize");
  42. $.post("actions/updateListOrder.php?type=<?php echo $type ?>", order, function(theResponse){
  43. display_message(theResponse);
  44. });
  45. }}).disableSelection();
  46. }
  47. $(document).ready(function(){
  48. refreshTable();
  49. $(function() {
  50. $("#new button").click(function(){
  51. $.post("actions/new.php?type=<?php echo $type ?>", $("#new").serialize(), function(theResponse){
  52. display_message(theResponse);
  53. refreshTable();
  54. });
  55. refreshTable();
  56. });
  57. $(".list").on('click', '.delete-confirm', function(){
  58. var deleteUID = parseInt($(this).attr("data"), 10);
  59. $('#delete-modal-' + deleteUID).modal('hide');
  60. $('body').removeClass('modal-open');
  61. $('.modal-backdrop').remove();
  62. $.get("actions/delete.php?type=<?php echo $type ?>", {uid: deleteUID}, function(theResponse) {
  63. display_message(theResponse);
  64. });
  65. refreshTable();
  66. });
  67. });
  68. });
  69. </script>