global-notification.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <a href="/admin/global-notification/new">
  2. <p class="btn btn-default">通知設定の追加</p>
  3. </a>
  4. <h2>通知設定一覧</h2>
  5. {% set tags = {
  6. pageCreate: '<span class="label label-info" data-toggle="tooltip" data-placement="top" title="Page Create"><i class="icon-doc"></i> CREATE</span>',
  7. pageEdit: '<span class="label label-info" data-toggle="tooltip" data-placement="top" title="Page Edit"><i class="icon-doc"></i> EDIT</span>',
  8. pageDelete: '<span class="label label-info" data-toggle="tooltip" data-placement="top" title="Page Delte"><i class="icon-doc"></i> DELETE</span>',
  9. pageMove: '<span class="label label-info" data-toggle="tooltip" data-placement="top" title="Page Move"><i class="icon-doc"></i> MOVE</span>',
  10. pageLike: '<span class="label label-info" data-toggle="tooltip" data-placement="top" title="Page Like"><i class="icon-doc"></i> LIKE</span>',
  11. comment: '<span class="label label-info" data-toggle="tooltip" data-placement="top" title="New Comment"><i class="icon-fw icon-bubbles"></i> POST</span>'
  12. } %}
  13. <table class="table table-bordered">
  14. <thead>
  15. <th>ON/OFF</th>
  16. <th>Trigger Path (expression with <code>*</code> is supported)</th>
  17. <th>Trigger Events</th>
  18. <th>Notify To</th>
  19. <th>Action</th>
  20. </thead>
  21. <tbody class="admin-notif-list">
  22. {% set detailPageUrl = '/admin/global-notification' %}
  23. {% for globalNotif in globalNotifications %}
  24. <tr class="clickable-row" data-href="{{ detailPageUrl }}" data-updatepost-id="{{ globalNotif._id.toString() }}">
  25. <td class="unclickable align-middle">
  26. <input type="checkbox" class="js-switch" data-size="small" {% if globalNotif.isEnabled %}checked{% endif %} />
  27. <!-- <label class="switch">
  28. <input type="checkbox" class="isEnabledToggle" {% if globalNotif.isEnabled %}checked{% endif %}>
  29. <span class="slider round"></span>
  30. </label> -->
  31. </td>
  32. <td>
  33. {{ globalNotif.triggerPath }}
  34. </td>
  35. <td style="max-width: 200px;">
  36. {% for event in globalNotif.triggerEvents %}
  37. {{ tags[event] | safe }}
  38. {% endfor %}
  39. </td>
  40. <td>
  41. {% if globalNotif.__t == 'mail' %}<span data-toggle="tooltip" data-placement="top" title="Email"><i class="ti-email"></i> {{ globalNotif.toEmail }}</span>
  42. {% elseif globalNotif.__t == 'slack' %}<span data-toggle="tooltip" data-placement="top" title="Slack"><i class="fa fa-slack"></i> {{ globalNotif.slackChannels }}</span>
  43. {% endif %}
  44. </td>
  45. <td class="unclickable">
  46. <p class="btn btn-danger btn-delete">{{ t('Delete') }}</p>
  47. </td>
  48. </tr>
  49. {% endfor %}
  50. </tbody>
  51. </table>
  52. <script>
  53. $(".clickable-row > :not('.unclickable')").click(function(event) {
  54. var $target = $(event.currentTarget).parent();
  55. window.location = $target.data("href") + "/" + $target.data("updatepost-id");
  56. });
  57. $(".unclickable > .btn-delete").click(function(event) {
  58. var $targetRow = $(event.currentTarget).closest("tr");
  59. var id = $targetRow.data("updatepost-id");
  60. $.post('/admin/global-notification/' + id + '/remove', function(res) {
  61. if (res.ok) {
  62. $targetRow.closest('tr').remove();
  63. $('.admin-notification > .row > .col-md-9').prepend(
  64. '<div class=\"alert alert-success\">Successfully Deleted</div>'
  65. );
  66. $message = $('.admin-notification > .row > .col-md-9 > .alert.alert-success');
  67. setTimeout(function()
  68. {
  69. $message.fadeOut({
  70. complete: function() {
  71. $message.remove();
  72. }
  73. });
  74. }, 2000);
  75. }
  76. else {
  77. $('.admin-notification > .row > .col-md-9').prepend(
  78. '<div class=\"alert alert-danger\">Error occurred in deleting global notifcation setting.</div>'
  79. );
  80. location.reload();
  81. }
  82. });
  83. });
  84. $(".js-switch").on("change", function(event) {
  85. var $targetRow = $(event.currentTarget).closest("tr");
  86. var id = $targetRow.data("updatepost-id");
  87. var isEnabled = !$targetRow.find(".js-switch").is(':checked');
  88. $.post('/_api/admin/global-notification/toggleIsEnabled?id=' + id + '&isEnabled=' + isEnabled, function(res) {
  89. if (res.ok) {
  90. // do nothing
  91. }
  92. else {
  93. $('.admin-notification > .row > .col-md-9').prepend(
  94. '<div class=\"alert alert-danger\">Error occurred in deleting global notifcation setting.</div>'
  95. );
  96. location.reload();
  97. }
  98. });
  99. });
  100. </script>