From e1a555a1f4444780ee0aae01a330fe4c62939ee8 Mon Sep 17 00:00:00 2001 From: Meleeman01 Date: Mon, 20 May 2019 04:52:41 -0500 Subject: [PATCH 1/4] fixed bug where hitting cancel doesn't revert changes --- laravel/resources/js/admin.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/laravel/resources/js/admin.js b/laravel/resources/js/admin.js index ae2db9bf..b547e448 100644 --- a/laravel/resources/js/admin.js +++ b/laravel/resources/js/admin.js @@ -38,7 +38,15 @@ $(document).ready(function() }); - + //A variable here to store previous form data. + var prevData = []; + $('.user-roles input').each(function() + { + if($(this).prop('checked')) + { + prevData.push($(this).value()); + } + }); // Display save / cancel buttons when changing user roles $('.user-roles input').on('change', function() @@ -88,6 +96,21 @@ $(document).ready(function() { $('.user-role').value($('.user-role').data('role')); $('.buttons').attr('style', false); + + //pull data array from earlier and assign the values based on prevData + $('.user-roles input').each(function(self) + { + self = $(this); + self.prop('checked',false); + + prevData.forEach(function(el) + { + if (self.value() === el) + { + self.prop('checked',true); + } + }); + }); }); $('.save-upload').on('click', function() From fc422842a0231c213510c1f4fd4cf4573abfb417 Mon Sep 17 00:00:00 2001 From: Meleeman01 Date: Mon, 20 May 2019 05:35:34 -0500 Subject: [PATCH 2/4] small edit to prevData to save previous form data on save-roles --- laravel/resources/js/admin.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/laravel/resources/js/admin.js b/laravel/resources/js/admin.js index b547e448..eeb2888a 100644 --- a/laravel/resources/js/admin.js +++ b/laravel/resources/js/admin.js @@ -68,6 +68,7 @@ $(document).ready(function() $('.save-roles').on('click', function() { + prevData = []; var user = $('.user-id').value(); var role = $('.user-role').value(); var csrf = $('.csrf-token').value(); @@ -82,6 +83,7 @@ $(document).ready(function() if($(this).prop('checked')) { data.roles.push($(this).value()); + prevData.push($(this).value()); } }); From 4b6df33d8526517d893f000cc155f7ef781cbf54 Mon Sep 17 00:00:00 2001 From: Meleeman01 Date: Sat, 22 Jun 2019 22:07:11 -0500 Subject: [PATCH 3/4] removed extraneous code --- laravel/resources/js/admin.js | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/laravel/resources/js/admin.js b/laravel/resources/js/admin.js index eeb2888a..01f32c50 100644 --- a/laravel/resources/js/admin.js +++ b/laravel/resources/js/admin.js @@ -38,16 +38,6 @@ $(document).ready(function() }); - //A variable here to store previous form data. - var prevData = []; - $('.user-roles input').each(function() - { - if($(this).prop('checked')) - { - prevData.push($(this).value()); - } - }); - // Display save / cancel buttons when changing user roles $('.user-roles input').on('change', function() { @@ -68,7 +58,6 @@ $(document).ready(function() $('.save-roles').on('click', function() { - prevData = []; var user = $('.user-id').value(); var role = $('.user-role').value(); var csrf = $('.csrf-token').value(); @@ -96,23 +85,7 @@ $(document).ready(function() $('.cancel-roles').on('click', function() { - $('.user-role').value($('.user-role').data('role')); - $('.buttons').attr('style', false); - - //pull data array from earlier and assign the values based on prevData - $('.user-roles input').each(function(self) - { - self = $(this); - self.prop('checked',false); - - prevData.forEach(function(el) - { - if (self.value() === el) - { - self.prop('checked',true); - } - }); - }); + window.history.back(); }); $('.save-upload').on('click', function() From 10483c6adc59a62a79e0429d2a1fc70a235dda64 Mon Sep 17 00:00:00 2001 From: Meleeman01 Date: Sat, 20 Jul 2019 00:11:15 -0500 Subject: [PATCH 4/4] removed an unncessary line of code --- laravel/resources/js/admin.js | 1 - 1 file changed, 1 deletion(-) diff --git a/laravel/resources/js/admin.js b/laravel/resources/js/admin.js index 01f32c50..825d0392 100644 --- a/laravel/resources/js/admin.js +++ b/laravel/resources/js/admin.js @@ -72,7 +72,6 @@ $(document).ready(function() if($(this).prop('checked')) { data.roles.push($(this).value()); - prevData.push($(this).value()); } });