Переглянути джерело

update and fixed form checkbox logic and notify to input logic

sou 7 роки тому
батько
коміт
c9b9162c6a

+ 1 - 0
lib/form/admin/notificationGlobal.js

@@ -4,6 +4,7 @@ const form = require('express-form');
 const field = form.field;
 const field = form.field;
 
 
 module.exports = form(
 module.exports = form(
+  field('notificationGlobal[id]').trim(),
   field('notificationGlobal[triggerPath]').trim(),
   field('notificationGlobal[triggerPath]').trim(),
   field('notificationGlobal[notifyToType]').trim(),
   field('notificationGlobal[notifyToType]').trim(),
   field('notificationGlobal[toEmail]').trim(),
   field('notificationGlobal[toEmail]').trim(),

+ 32 - 8
lib/routes/admin.js

@@ -363,18 +363,42 @@ module.exports = function(crowi, app) {
     return res.redirect('/admin/notification#global-notification');
     return res.redirect('/admin/notification#global-notification');
   };
   };
 
 
-  actions.globalNotification.update = (req, res) => {
-    const notificationSettingId = req.params.id;
-    const renderVars = {
-    };
-    return res.render('admin/global-notification-detail', renderVars);
+  actions.globalNotification.update = async(req, res) => {
+    const form = req.form.notificationGlobal;
+    const setting = await GlobalNotificationSetting.Parent.findOne({_id: form.id});
+
+    switch (form.notifyToType) {
+      case 'mail':
+        setting.toEmail = form.toEmail;
+        break;
+      // case 'slack':
+      //   setting.slackChannels = form.slackChannels;
+      //   break;
+      default:
+        logger.error('GlobalNotificationSetting Type Error: undefined type');
+        break;
+    }
+
+    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();
+    }
+
+    return res.redirect('/admin/notification#global-notification');
   };
   };
 
 
   // actions.globalNotification.remove = (req, res) => {
   // actions.globalNotification.remove = (req, res) => {
   //   const notificationSettingId = req.params.id;
   //   const notificationSettingId = req.params.id;
-  //   const renderVars = {
-  //   };
-  //   return res.render('admin/global-notification-detail', renderVars);
+  //   return res.redirect('/admin/notification#global-notification');
   // };
   // };
 
 
   actions.search.buildIndex = function(req, res) {
   actions.search.buildIndex = function(req, res) {

+ 22 - 11
lib/views/admin/global-notification-detail.html

@@ -37,8 +37,13 @@
         通知設定一覧に戻る
         通知設定一覧に戻る
       </a>
       </a>
 
 
+      {% if setting %}
+        {% set actionPath = '/admin/global-notification/update' %}
+      {% else %}
+        {% set actionPath = '/admin/global-notification/create' %}
+      {% endif %}
       <div class="m-t-20 form-box col-md-11">
       <div class="m-t-20 form-box col-md-11">
-        <form action="/admin/global-notification/create" method="post" class="form-horizontal" role="form">
+        <form action="{{ actionPath }}" method="post" class="form-horizontal" role="form">
           <legend>通知設定詳細</legend>
           <legend>通知設定詳細</legend>
 
 
           <fieldset class="col-sm-offset-1 col-sm-4">
           <fieldset class="col-sm-offset-1 col-sm-4">
@@ -63,52 +68,58 @@
               </div> -->
               </div> -->
             </div>
             </div>
 
 
-            <div class="form-group notify-to-option d-none" id="mail-input">
+            <div class="form-group notify-to-option {% if setting.__t != 'mail' %}d-none{% endif %}" id="mail-input">
               <label for="notificationGlobal[toEmail]"class="control-label">Email</label><br />
               <label for="notificationGlobal[toEmail]"class="control-label">Email</label><br />
               <input class="form-control" type="text" name="notificationGlobal[toEmail]" value="{{ setting.toEmail || '' }}">
               <input class="form-control" type="text" name="notificationGlobal[toEmail]" value="{{ setting.toEmail || '' }}">
             </div>
             </div>
 
 
-            <div class="form-group notify-to-option d-none" id="slack-input">
+            <!-- <div class="form-group notify-to-option {% if setting.__t != 'slack' %}d-none{% endif %}" id="slack-input">
               <label for="notificationGlobal[slackChannels]"class="control-label">Slack Channels</label><br />
               <label for="notificationGlobal[slackChannels]"class="control-label">Slack Channels</label><br />
               <input class="form-control" type="text" name="notificationGlobal[slackChannels]" value="{{ setting.slackChannels || '' }}">
               <input class="form-control" type="text" name="notificationGlobal[slackChannels]" value="{{ setting.slackChannels || '' }}">
-            </div>
+            </div> -->
           </fieldset>
           </fieldset>
 
 
           <fieldset class="col-sm-offset-1 col-sm-4">
           <fieldset class="col-sm-offset-1 col-sm-4">
             <div class="form-group">
             <div class="form-group">
               <label for="triggerEvent"class="control-label">トリガーイベント</label><br />
               <label for="triggerEvent"class="control-label">トリガーイベント</label><br />
               <div class="checkbox checkbox-info">
               <div class="checkbox checkbox-info">
-                <input type="checkbox" id="trigger-event-pageCreate" name="notificationGlobal[triggerEvent:pageCreate]" value="pageCreate" {% if setting.triggerEvents.indexOf('pageCreate') != -1 %}checked{% endif %} />
+                <input type="checkbox" id="trigger-event-pageCreate" name="notificationGlobal[triggerEvent:pageCreate]" value="pageCreate"
+                  {% if setting && (setting.triggerEvents.indexOf('pageCreate') != -1) %}checked{% endif %} />
                 <label for="trigger-event-pageCreate">
                 <label for="trigger-event-pageCreate">
                   <span class="label label-info"><i class="icon-doc"></i> CREATE</span> - When New Page is Created
                   <span class="label label-info"><i class="icon-doc"></i> CREATE</span> - When New Page is Created
                 </label>
                 </label>
               </div>
               </div>
               <div class="checkbox checkbox-info">
               <div class="checkbox checkbox-info">
-                <input type="checkbox" id="trigger-event-pageEdit" name="notificationGlobal[triggerEvent:pageEdit]" value="pageEdit" {% if setting.triggerEvents.indexOf('pageEdit') != -1 %}checked{% endif %} />
+                <input type="checkbox" id="trigger-event-pageEdit" name="notificationGlobal[triggerEvent:pageEdit]" value="pageEdit"
+                  {% if setting && (setting.triggerEvents.indexOf('pageEdit') != -1) %}checked{% endif %} />
                 <label for="trigger-event-pageEdit">
                 <label for="trigger-event-pageEdit">
                   <span class="label label-info"><i class="icon-doc"></i> EDIT</span> - When Page is Edited
                   <span class="label label-info"><i class="icon-doc"></i> EDIT</span> - When Page is Edited
                 </label>
                 </label>
               </div>
               </div>
               <div class="checkbox checkbox-info">
               <div class="checkbox checkbox-info">
-                <input type="checkbox" id="trigger-event-pageDelete" name="notificationGlobal[triggerEvent:pageDelete]" value="pageDelete" {% if setting.triggerEvents.indexOf('pageDelete') != -1 %}checked{% endif %} />
+                <input type="checkbox" id="trigger-event-pageDelete" name="notificationGlobal[triggerEvent:pageDelete]" value="pageDelete"
+                  {% if setting && (setting.triggerEvents.indexOf('pageDelete') != -1) %}checked{% endif %} />
                 <label for="trigger-event-pageDelete">
                 <label for="trigger-event-pageDelete">
                   <span class="label label-info"><i class="icon-doc"></i> DELETE</span> - When is Deleted
                   <span class="label label-info"><i class="icon-doc"></i> DELETE</span> - When is Deleted
                 </label>
                 </label>
               </div>
               </div>
               <div class="checkbox checkbox-info">
               <div class="checkbox checkbox-info">
-                <input type="checkbox" id="trigger-event-pageMove" name="notificationGlobal[triggerEvent:pageMove]" value="pageMove" {% if setting.triggerEvents.indexOf('pageMove') != -1 %}checked{% endif %} />
+                <input type="checkbox" id="trigger-event-pageMove" name="notificationGlobal[triggerEvent:pageMove]" value="pageMove"
+                  {% if setting && (setting.triggerEvents.indexOf('pageMove') != -1) %}checked{% endif %} />
                 <label for="trigger-event-pageMove">
                 <label for="trigger-event-pageMove">
                   <span class="label label-info"><i class="icon-doc"></i> MOVE</span> - When Page is Moved (Renamed)
                   <span class="label label-info"><i class="icon-doc"></i> MOVE</span> - When Page is Moved (Renamed)
                 </label>
                 </label>
               </div>
               </div>
               <div class="checkbox checkbox-info">
               <div class="checkbox checkbox-info">
-                  <input type="checkbox" id="trigger-event-pageLike" name="notificationGlobal[triggerEvent:pageLike]" value="pageLike" {% if setting.triggerEvents.indexOf('pageLike') != -1 %}checked{% endif %} />
+                  <input type="checkbox" id="trigger-event-pageLike" name="notificationGlobal[triggerEvent:pageLike]" value="pageLike"
+                    {% if setting && (setting.triggerEvents.indexOf('pageLike') != -1) %}checked{% endif %} />
                   <label for="trigger-event-pageLike">
                   <label for="trigger-event-pageLike">
                     <span class="label label-info"><i class="icon-doc"></i> LIKE</span> - When Someone Likes Page
                     <span class="label label-info"><i class="icon-doc"></i> LIKE</span> - When Someone Likes Page
                   </label>
                   </label>
                 </div>
                 </div>
               <div class="checkbox checkbox-info">
               <div class="checkbox checkbox-info">
-                <input type="checkbox" id="trigger-event-comment" name="notificationGlobal[triggerEvent:comment]" value="comment" {% if setting.triggerEvents.indexOf('comment') != -1 %}checked{% endif %} />
+                <input type="checkbox" id="trigger-event-comment" name="notificationGlobal[triggerEvent:comment]" value="comment"
+                  {% if setting && (setting.triggerEvents.indexOf('comment') != -1) %}checked{% endif %} />
                 <label for="trigger-event-comment">
                 <label for="trigger-event-comment">
                   <span class="label label-info"><i class="icon-fw icon-bubbles"></i> POST</span> - When Someone Comments on Page
                   <span class="label label-info"><i class="icon-fw icon-bubbles"></i> POST</span> - When Someone Comments on Page
                 </label>
                 </label>
@@ -117,7 +128,7 @@
           </fieldset>
           </fieldset>
 
 
           <div class="col-sm-offset-5 col-sm-12 m-t-20">
           <div class="col-sm-offset-5 col-sm-12 m-t-20">
-            <input type="hidden" name="notificationGlobal[id]" value="">
+            <input type="hidden" name="notificationGlobal[id]" value="{{ setting.id }}">
             <input type="hidden" name="_csrf" value="{{ csrf() }}">
             <input type="hidden" name="_csrf" value="{{ csrf() }}">
             <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
             <button type="submit" class="btn btn-primary">{{ t('Update') }}</button>
           </div>
           </div>