sou пре 7 година
родитељ
комит
3d1ec6cfcb

+ 13 - 6
lib/routes/admin.js

@@ -396,11 +396,6 @@ module.exports = function(crowi, app) {
     return res.redirect('/admin/notification#global-notification');
   };
 
-  // actions.globalNotification.remove = (req, res) => {
-  //   const notificationSettingId = req.params.id;
-  //   return res.redirect('/admin/notification#global-notification');
-  // };
-
   actions.search.buildIndex = function(req, res) {
     var search = crowi.getSearcher();
     if (!search) {
@@ -1166,7 +1161,19 @@ module.exports = function(crowi, app) {
     const id =req.query.id;
 
     try {
-      GlobalNotificationSetting.Parent.toggleIsEnabled(id);
+      await GlobalNotificationSetting.Parent.toggleIsEnabled(id);
+      return res.json(ApiResponse.success());
+    }
+    catch (err) {
+      return res.json(ApiResponse.error());
+    }
+  };
+
+  actions.api.removeGlobalNotification = async(req, res) => {
+    const id = req.query.id;
+
+    try {
+      await GlobalNotificationSetting.Parent.findOneAndRemove({_id: id});
       return res.json(ApiResponse.success());
     }
     catch (err) {

+ 1 - 1
lib/routes/index.js

@@ -111,7 +111,7 @@ module.exports = function(crowi, app) {
   app.post('/admin/global-notification/create', loginRequired(crowi, app) , middleware.adminRequired() , form.admin.notificationGlobal, admin.globalNotification.create);
   app.post('/_api/admin/global-notification/toggleIsEnabled', loginRequired(crowi, app) , middleware.adminRequired() , admin.api.toggleIsEnabledForGlobalNotification);
   app.post('/admin/global-notification/update', loginRequired(crowi, app) , middleware.adminRequired() , form.admin.notificationGlobal, admin.globalNotification.update);
-  // app.post('/admin/global-notification/remove', loginRequired(crowi, app) , middleware.adminRequired() , admin.globalNotification.remove);
+  app.post('/admin/global-notification/remove', loginRequired(crowi, app) , middleware.adminRequired() , admin.api.removeGlobalNotification);
 
   app.get('/admin/users'                , loginRequired(crowi, app) , middleware.adminRequired() , admin.user.index);
   app.post('/admin/user/invite'         , form.admin.userInvite ,  loginRequired(crowi, app) , middleware.adminRequired() , csrf, admin.user.invite);

+ 4 - 0
lib/views/admin/global-notification-detail.html

@@ -144,6 +144,10 @@
     $('.notify-to-option').addClass('d-none');
     $('#' + val + '-input').removeClass('d-none');
   });
+
+  $('button#global-notificatin-delete').submit(function() {
+    alert(123)
+  });
 </script>
 {% endblock content_main %}
 

+ 15 - 1
lib/views/admin/global-notification.html

@@ -18,6 +18,7 @@
     <th>Trigger Path (expression with <code>*</code> is supported)</th>
     <th>Trigger Events</th>
     <th>Notify To</th>
+    <th>Action</th>
   </thead>
   <tbody class="admin-notif-list">
     {% set detailPageUrl = '/admin/global-notification/detail' %}
@@ -42,6 +43,9 @@
         {% elseif globalNotif.__t == 'slack' %}<span data-toggle="tooltip" data-placement="top" title="Slack"><i class="fa fa-slack"></i> {{ globalNotif.slackChannels }}</span>
         {% endif %}
       </td>
+      <td class="unclickable">
+        <p class="btn btn-danger btn-delete">{{ t('Delete') }}</p>
+      </td>
     </tr>
     {% endfor %}
   </tbody>
@@ -53,8 +57,18 @@
     window.location = $target.data("href") + "/" + $target.data("updatepost-id");
   });
 
+  $(".unclickable > .btn-delete").click(function(event) {
+    var id = $(event.currentTarget).closest("tr").data("updatepost-id");
+    var $target = $(event.currentTarget).parent();
+    $.post('/admin/global-notification/remove?id=' + id, function(res) {
+      if (res.ok) {
+        $target.closest('tr').remove();
+      }
+    });
+  });
+
   $(".isEnabledToggle").on("change", function(event) {
-    var id = $(event.currentTarget).closest("tr").data("updatepost-id")
+    var id = $(event.currentTarget).closest("tr").data("updatepost-id");
     $.post('/_api/admin/global-notification/toggleIsEnabled?id=' + id, function(res) {
       if (res.ok) {
         // do something