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

GC-590: use switchery

* refactor event listener
Yuki Takei 7 лет назад
Родитель
Сommit
1e55f04684
1 измененных файлов с 3 добавлено и 4 удалено
  1. 3 4
      lib/views/admin/global-notification.html

+ 3 - 4
lib/views/admin/global-notification.html

@@ -25,7 +25,7 @@
     {% for globalNotif in globalNotifications %}
     {% for globalNotif in globalNotifications %}
     <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 align-middle">
       <td class="unclickable align-middle">
-        <input type="checkbox" class="js-switch" data-size="small" {% if globalNotif.isEnabled %}checked{% endif %} />
+        <input type="checkbox" class="js-switch" data-size="small" data-id="{{ globalNotif._id.toString() }}" {% if globalNotif.isEnabled %}checked{% endif %} />
         <!-- <label class="switch">
         <!-- <label class="switch">
           <input type="checkbox" class="isEnabledToggle" {% if globalNotif.isEnabled %}checked{% endif %}>
           <input type="checkbox" class="isEnabledToggle" {% if globalNotif.isEnabled %}checked{% endif %}>
           <span class="slider round"></span>
           <span class="slider round"></span>
@@ -87,9 +87,8 @@
   });
   });
 
 
   $(".js-switch").on("change", function(event) {
   $(".js-switch").on("change", function(event) {
-    var $targetRow = $(event.currentTarget).closest("tr");
-    var id = $targetRow.data("updatepost-id");
-    var isEnabled = !$targetRow.find(".js-switch").is(':checked');
+    var id = event.currentTarget.dataset.id;
+    var isEnabled = event.currentTarget.checked;
     $.post('/_api/admin/global-notification/toggleIsEnabled?id=' + id + '&isEnabled=' + isEnabled, function(res) {
     $.post('/_api/admin/global-notification/toggleIsEnabled?id=' + id + '&isEnabled=' + isEnabled, function(res) {
       if (res.ok) {
       if (res.ok) {
         // do nothing
         // do nothing