-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The previous store credit JS did a lot more than it needed to, and recreated much of the work that we could get for free from rails-ujs. We were already specifying remote: true, but weren't using that functionality and instead were performing the AJAX explicitly. This commit replaces the existing JS and relies on CSS for display , and jquery-ujs for submitting via AJAX. The user-facing behaviour should be identical. The resulting code has very little to do with store credits, we should consider at a future date looking through our inline edits in the admin and possibly consolidating them.
- Loading branch information
Showing
4 changed files
with
52 additions
and
64 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
backend/app/assets/javascripts/spree/backend/store_credits.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Spree.ready(function() { | ||
$('.store-credit-memo-row').each(function() { | ||
var row = this; | ||
var field = row.querySelector('[name="store_credit[memo]"]') | ||
var textDisplay = row.querySelector('.store-credit-memo-text') | ||
|
||
$(row).on('ajax:success', function(event, data) { | ||
row.classList.remove('editing'); | ||
field.defaultValue = field.value; | ||
textDisplay.textContent = field.value; | ||
|
||
show_flash('success', data.message); | ||
}).on('ajax:error', function(event, xhr, status, error) { | ||
show_flash('error', xhr.responseJSON.message); | ||
}); | ||
|
||
row.querySelector('.edit-memo').addEventListener('click', function() { | ||
row.classList.add('editing'); | ||
}); | ||
|
||
row.querySelector('.cancel-memo').addEventListener('click', function() { | ||
row.classList.remove('editing'); | ||
}); | ||
}); | ||
}); |
40 changes: 0 additions & 40 deletions
40
backend/app/assets/javascripts/spree/backend/store_credits.js.coffee
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters