Просмотр исходного кода

getNotificationEvents, flash message for update

sou 7 лет назад
Родитель
Сommit
6dbba45f04
1 измененных файлов с 16 добавлено и 24 удалено
  1. 16 24
      lib/routes/admin.js

+ 16 - 24
lib/routes/admin.js

@@ -343,23 +343,13 @@ module.exports = function(crowi, app) {
       //   break;
       //   break;
       default:
       default:
         logger.error('GlobalNotificationSetting Type Error: undefined type');
         logger.error('GlobalNotificationSetting Type Error: undefined type');
-        req.flash('errorMessage', 'Error occurred in create a new global notification setting: undefined notification type');
-        break;
+        req.flash('errorMessage', 'Error occurred in creating a new global notification setting: undefined notification type');
+        return res.redirect('/admin/notification#global-notification');
     }
     }
 
 
-    let triggerEvents = [];
-    const triggerEventKeys = Object.keys(form).filter(key => key.match(/^triggerEvent/));
-    triggerEventKeys.forEach(key => {
-      if (form[key]) {
-        triggerEvents.push(form[key]);
-      }
-    });
-
-    if (setting) {
-      setting.triggerPath = form.triggerPath;
-      setting.triggerEvents = triggerEvents;
-      setting.save();
-    }
+    setting.triggerPath = form.triggerPath;
+    setting.triggerEvents = getNotificationEvents(form);
+    setting.save();
 
 
     return res.redirect('/admin/notification#global-notification');
     return res.redirect('/admin/notification#global-notification');
   };
   };
@@ -377,9 +367,18 @@ module.exports = function(crowi, app) {
       //   break;
       //   break;
       default:
       default:
         logger.error('GlobalNotificationSetting Type Error: undefined type');
         logger.error('GlobalNotificationSetting Type Error: undefined type');
-        break;
+        req.flash('errorMessage', 'Error occurred in updating the global notification setting: undefined notification type');
+        return res.redirect('/admin/notification#global-notification');
     }
     }
 
 
+    setting.triggerPath = form.triggerPath;
+    setting.triggerEvents = getNotificationEvents(form);
+    setting.save();
+
+    return res.redirect('/admin/notification#global-notification');
+  };
+
+  const getNotificationEvents = (form) => {
     let triggerEvents = [];
     let triggerEvents = [];
     const triggerEventKeys = Object.keys(form).filter(key => key.match(/^triggerEvent/));
     const triggerEventKeys = Object.keys(form).filter(key => key.match(/^triggerEvent/));
     triggerEventKeys.forEach(key => {
     triggerEventKeys.forEach(key => {
@@ -387,14 +386,7 @@ module.exports = function(crowi, app) {
         triggerEvents.push(form[key]);
         triggerEvents.push(form[key]);
       }
       }
     });
     });
-
-    if (setting) {
-      setting.triggerPath = form.triggerPath;
-      setting.triggerEvents = triggerEvents;
-      setting.save();
-    }
-
-    return res.redirect('/admin/notification#global-notification');
+    return triggerEvents;
   };
   };
 
 
   actions.search.buildIndex = function(req, res) {
   actions.search.buildIndex = function(req, res) {