2
0
sou 7 жил өмнө
parent
commit
0997a6899f

+ 16 - 0
lib/routes/admin.js

@@ -1130,6 +1130,22 @@ module.exports = function(crowi, app) {
     });
     });
   };
   };
 
 
+  actions.api.toggleIsEnabledForGlobalNotification = async(req, res) => {
+    const id =req.query.id;
+    let setting;
+
+    try {
+      setting= await GlobalNotificationSetting.Parent.findOne({_id: id});
+      setting.isEnabled = !setting.isEnabled;
+      setting.save();
+
+      return res.json(ApiResponse.success());
+    }
+    catch (err) {
+      return res.json(ApiResponse.error());
+    }
+  };
+
   /**
   /**
    * save settings, update config cache, and response json
    * save settings, update config cache, and response json
    *
    *

+ 1 - 0
lib/routes/index.js

@@ -109,6 +109,7 @@ module.exports = function(crowi, app) {
   app.get('/admin/global-notification/detail', loginRequired(crowi, app) , middleware.adminRequired() , admin.globalNotification.detail);
   app.get('/admin/global-notification/detail', loginRequired(crowi, app) , middleware.adminRequired() , admin.globalNotification.detail);
   app.get('/admin/global-notification/detail/:id', loginRequired(crowi, app) , middleware.adminRequired() , admin.globalNotification.detail);
   app.get('/admin/global-notification/detail/:id', loginRequired(crowi, app) , middleware.adminRequired() , admin.globalNotification.detail);
   app.post('/admin/global-notification/create', loginRequired(crowi, app) , middleware.adminRequired() , form.admin.notificationGlobal, admin.globalNotification.create);
   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/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.globalNotification.remove);
 
 

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

@@ -55,7 +55,7 @@
     <tr class="clickable-row" data-href="{{ detailPageUrl }}" data-updatepost-id="{{ globalNotif._id.toString() }}">
     <tr class="clickable-row" data-href="{{ detailPageUrl }}" data-updatepost-id="{{ globalNotif._id.toString() }}">
       <td class="unclickable">
       <td class="unclickable">
         <label class="switch">
         <label class="switch">
-          <input type="checkbox">
+          <input type="checkbox" class="isEnabledToggle">
           <span class="slider round"></span>
           <span class="slider round"></span>
         </label>
         </label>
       </td>
       </td>
@@ -150,4 +150,13 @@ input:checked + .slider:before {
   $(".clickable-row > :not('.unclickable')").click(function(event) {
   $(".clickable-row > :not('.unclickable')").click(function(event) {
     window.location = $(event.currentTarget).parent().data("href")
     window.location = $(event.currentTarget).parent().data("href")
   });
   });
+
+  $(".isEnabledToggle").on("change", event => {
+    var id = $(event.currentTarget).closest("tr").data("updatepost-id")
+    $.post('/_api/admin/global-notification/toggleIsEnabled?id=' + id, function(res) {
+      if (res.ok) {
+        // alert(id, ': suucess')
+      }
+    });
+  });
 </script>
 </script>