global-notification.html 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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" data-id="{{ globalNotif._id.toString() }}" {% if globalNotif.isEnabled %}checked{% endif %} />
  27. </td>
  28. <td>
  29. {{ globalNotif.triggerPath }}
  30. </td>
  31. <td style="max-width: 200px;">
  32. {% for event in globalNotif.triggerEvents %}
  33. {{ tags[event] | safe }}
  34. {% endfor %}
  35. </td>
  36. <td>
  37. {% if globalNotif.__t == 'mail' %}<span data-toggle="tooltip" data-placement="top" title="Email"><i class="ti-email"></i> {{ globalNotif.toEmail }}</span>
  38. {% elseif globalNotif.__t == 'slack' %}<span data-toggle="tooltip" data-placement="top" title="Slack"><i class="fa fa-slack"></i> {{ globalNotif.slackChannels }}</span>
  39. {% endif %}
  40. </td>
  41. <td class="unclickable">
  42. <p class="btn btn-danger btn-delete">{{ t('Delete') }}</p>
  43. </td>
  44. </tr>
  45. {% endfor %}
  46. </tbody>
  47. </table>
  48. <script>
  49. $(".clickable-row > :not('.unclickable')").click(function(event) {
  50. var $target = $(event.currentTarget).parent();
  51. window.location = $target.data("href") + "/" + $target.data("updatepost-id");
  52. });
  53. $(".unclickable > .btn-delete").click(function(event) {
  54. var $targetRow = $(event.currentTarget).closest("tr");
  55. var id = $targetRow.data("updatepost-id");
  56. $.post('/admin/global-notification/' + id + '/remove', function(res) {
  57. if (res.ok) {
  58. $targetRow.closest('tr').remove();
  59. $('.admin-notification > .row > .col-md-9').prepend(
  60. '<div class=\"alert alert-success\">Successfully Deleted</div>'
  61. );
  62. $message = $('.admin-notification > .row > .col-md-9 > .alert.alert-success');
  63. setTimeout(function()
  64. {
  65. $message.fadeOut({
  66. complete: function() {
  67. $message.remove();
  68. }
  69. });
  70. }, 2000);
  71. }
  72. else {
  73. $('.admin-notification > .row > .col-md-9').prepend(
  74. '<div class=\"alert alert-danger\">Error occurred in deleting global notifcation setting.</div>'
  75. );
  76. location.reload();
  77. }
  78. });
  79. });
  80. $(".js-switch").on("change", function(event) {
  81. var id = event.currentTarget.dataset.id;
  82. var isEnabled = event.currentTarget.checked;
  83. $.post('/_api/admin/global-notification/toggleIsEnabled?id=' + id + '&isEnabled=' + isEnabled, function(res) {
  84. if (res.ok) {
  85. // do nothing
  86. }
  87. else {
  88. $('.admin-notification > .row > .col-md-9').prepend(
  89. '<div class=\"alert alert-danger\">Error occurred in deleting global notifcation setting.</div>'
  90. );
  91. location.reload();
  92. }
  93. });
  94. });
  95. </script>