global-notification.html 4.8 KB

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