-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #166 from BitBagCommerce/OPSRC-645/Adding_modals_t…
…o_wishlist_actions Opsrc 645/Adding modals to wishlist actions
- Loading branch information
Showing
11 changed files
with
269 additions
and
142 deletions.
There are no files selected for viewing
115 changes: 0 additions & 115 deletions
115
src/Resources/assets/shop/js/addAnotherWishlistModal.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { WishlistModal } from './wishlistModal'; | ||
|
||
const editWishlistBtns = document.querySelectorAll('[data-wishlist-edit-id]'); | ||
const wishlistFormName = 'edit_wishlist'; | ||
|
||
const setWishlistModal = () => { | ||
editWishlistBtns.forEach(btn => { | ||
btn.addEventListener('click', () => { | ||
new WishlistModal( | ||
{ | ||
headerTitle: 'Choose new name for your wishlist', | ||
wishlistFormName: wishlistFormName, | ||
wishlistBodyContent: ` | ||
<input type="text" id="${wishlistFormName}_name" name="${wishlistFormName}_name[name]" required="required" class="wishlist-confirmation-modal__body--input" data-bb-target="input"> | ||
<div class="ui red pointing label validation-error hidden" data-bb-target="error">Please enter wishlist name.</div> | ||
` | ||
}, | ||
{ | ||
cancelAction: () => {}, | ||
performAction: async () => { | ||
const form = document.querySelector(`#${wishlistFormName}`); | ||
const formValue = form.querySelector(`#${wishlistFormName}_name`); | ||
|
||
const wishlistId = btn.dataset.wishlistEditId; | ||
const url = `/wishlists/${wishlistId}/edit`; | ||
const formData = new FormData(form); | ||
const csrfToken = document.querySelector("[data-bb-csrf]").dataset.bbCsrf; | ||
|
||
const headers = new Headers({ | ||
'X-CSRF-TOKEN': csrfToken | ||
}); | ||
|
||
const requestConfig = { | ||
method: 'POST', | ||
headers: headers, | ||
body: formData | ||
} | ||
|
||
try { | ||
const response = await fetch(url, requestConfig); | ||
const data = await response.json(); | ||
|
||
} catch (error) { | ||
console.error(error); | ||
} finally { | ||
location.reload(); | ||
} | ||
}, | ||
} | ||
).init(); | ||
}); | ||
}) | ||
}; | ||
|
||
const turnOnListener = () => { | ||
if (!editWishlistBtns) { | ||
return; | ||
} | ||
|
||
setWishlistModal(); | ||
}; | ||
|
||
turnOnListener(); |
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,59 @@ | ||
import { WishlistModal } from './wishlistModal'; | ||
|
||
const removeWishlistBtns = document.querySelectorAll('[data-wishlist-remove-id]'); | ||
const wishlistFormName = 'remove_wishlist'; | ||
|
||
const setWishlistModal = () => { | ||
removeWishlistBtns.forEach(btn => { | ||
btn.addEventListener('click', () => { | ||
new WishlistModal( | ||
{ | ||
headerTitle: 'Remove wishlist', | ||
wishlistFormName: wishlistFormName, | ||
wishlistBodyContent: 'Are you sure?' | ||
}, | ||
{ | ||
cancelAction: () => {}, | ||
performAction: async () => { | ||
const form = document.querySelector(`#${wishlistFormName}`); | ||
|
||
const wishlistId = btn.dataset.wishlistRemoveId; | ||
const url = `/wishlists/${wishlistId}/remove`; | ||
const formData = new FormData(form); | ||
const csrfToken = document.querySelector("[data-bb-csrf]").dataset.bbCsrf; | ||
|
||
const headers = new Headers({ | ||
'X-CSRF-TOKEN': csrfToken | ||
}); | ||
|
||
const requestConfig = { | ||
method: 'POST', | ||
headers: headers, | ||
body: formData | ||
} | ||
|
||
try { | ||
const response = await fetch(url, requestConfig); | ||
const data = await response.json(); | ||
|
||
} catch (error) { | ||
console.error(error); | ||
} finally { | ||
location.reload(); | ||
} | ||
}, | ||
} | ||
).init(); | ||
}); | ||
}) | ||
}; | ||
|
||
const turnOnListener = () => { | ||
if (!removeWishlistBtns) { | ||
return; | ||
} | ||
|
||
setWishlistModal(); | ||
}; | ||
|
||
turnOnListener(); |
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
Oops, something went wrong.