},
methods: {
- resetUrlAccount() {
- let hash = window.location.hash
- let fullUrl = window.location.origin+window.location.pathname
- if(hash)
- history.pushState("", "", fullUrl);
- },
saveCart(data) {
let root = this;
axios.post('/ajax/cart', data)
closeCart() {
document.body.classList.remove('cart-open');
},
- //next code is for login and account page
+
+ /**
+ *
+ * The following functions are used for login,register and account page
+ *
+ */
+ resetUrlAccount() {
+ // Remove hash to url if exist to prevent to stay in same tab
+ // It used in account page when we navigate between different tab
+ let hash = window.location.hash,
+ fullUrl = window.location.origin+window.location.pathname
+
+ if(hash)
+ history.pushState("", "", fullUrl);
+ },
toggleType(el) {
this.type[el] = this.type[el] === "password" ? "text" : "password"
},
- removeErrors() {
+ removeErrorsForm() {
let errors = document.querySelector('.form-errors'),
errorInput = document.querySelectorAll('.error')
errorInput[i].classList.remove('error');
}
},
- checkEmailExist() {
- let root = this,
- data = {
- email: root.email_signin
- }
-
- axios.post('/ajax/check_email_exist', data)
- .then(function (response) {
- //do the verification before to set validateEmail true
- root.validateEmail = true
- if (response.data.length > 0) {
- root.emailExist = true
- }
- })
- .catch(function (error) {
- console.log('error', error)
- })
- },
errorHandling(data, root){
if (data.response) {
let errors = data.response.data.errors
root.errorsForm = errors
- root.removeErrors()
+ root.removeErrorsForm()
for (let k in errors) {
if(k.indexOf('.')){
}
}
},
+ checkEmailExist() {
+ let root = this,
+ data = {
+ email: root.email_signin
+ }
+
+ axios.post('/ajax/check_email_exist', data)
+ .then(function (response) {
+ root.validateEmail = true
+ if (response.data.length > 0) {
+ root.emailExist = true
+ }
+ })
+ .catch(function (error) {
+ root.errorHandling(error, root)
+ }
+ )
+ },
signin() {
let root = this,
form = document.getElementById('signin-form'),
axios.post('/ajax/signin', data)
.then(function (response) {
- //
-
- let lastVisitedUrl = document.querySelector('[name="previous-url"]').getAttribute('content');
- let homeUrl = window.location.origin;
+ let lastVisitedUrl = document.querySelector('[name="previous-url"]').getAttribute('content'),
+ homeUrl = window.location.origin;
if(lastVisitedUrl){
if(lastVisitedUrl.includes('pm-instrumentation')){
})
.catch(function (error) {
root.errorHandling(error, root)
- })
+ }
+ )
},
signup() {
let root = this,
axios.post('/ajax/signup', data)
.then(function (response) {
- //
- root.removeErrors()
+
+ root.validateForm = true
+
+ // Reset form
+ root.email_signin = ''
+ root.errorsForm = {}
+ root.removeErrorsForm()
form.reset()
window.scrollTo({
top: 0,
behavior: "smooth"
})
- root.validateForm = true
- root.email_signin = ''
- root.errorsForm = {}
})
.catch(function (error) {
root.errorHandling(error, root)
- })
+ }
+ )
},
- activeTab(tab){
+ activeTab(tab) {
this.tab = tab
this.errorsForm = {}
+ this.removeErrorsForm()
this.resetUrlAccount()
- this.removeErrors()
},
- getUser(){
+ getUser() {
let root = this
+
axios.post('/ajax/getuser')
.then(function (response) {
//
root.user = response.data['user']
root.addresses = JSON.parse(root.user.address)
-
root.default_billing_address = 'billing'+response.data['address_billing']
root.default_delivery_address = 'delivery'+response.data['address_delivery']
})
.catch(function (error) {
-
- })
+ }
+ )
},
- addAddressToForm(event){
+ addAddressToForm(event) {
let newAddress = {
'billing_address': '0',
'delivery_address': '0'
this.addresses.push(newAddress)
- //disabled click at most once
+ // Disabled the click to add address at most once
let target = event.target
target.setAttribute('disabled', 'disabled')
- setTimeout(function (){
+ // Scrolling even the new address form
+ setTimeout(function () {
let forms = document.querySelector('.form-portal').parentElement.parentElement.lastChild
let top = forms.offsetTop - 60;
behavior: "smooth"
})
- //enabled click after scroll is happened
+ // Enabled the click to add address after scroll is happened
target.removeAttribute('disabled')
}, 150)
},
- update(id){
+ update(id) {
let root = this,
form = document.getElementById(id),
data = new FormData(form)
axios.post('/ajax/update', data)
.then(function (response) {
//
- root.removeErrors()
+ root.removeErrorsForm()
root.validateForm = true
root.form[id] = response.data
})
.catch(function (error) {
root.errorHandling(error, root)
- })
+ }
+ )
},
- updateAddress(id){
+ updateAddress(id) {
let root = this,
form = document.getElementById(id),
data = new FormData(form)
axios.post('/ajax/updateAddress', data)
.then(function (response) {
- //
- root.removeErrors()
+ root.removeErrorsForm()
root.validateForm = true
})
.catch(function (error) {
root.errorHandling(error, root)
- })
+ }
+ )
},
- deleteAddress(index, form){
+ deleteAddress(index, form) {
let root = this,
form_ = document.getElementById(form),
data = {
})
.catch(function (error) {
- })
-
+ }
+ )
}
},
+ /**
+ * The following block of code is used for to close "modal confirm update/register"
+ * with escape key of keyboard or by clicking outside the modal
+ *
+ * Custom directive "close-outside"
+ *
+ * Eg. <div v-close-outside></div>
+ */
directives: {
'close-outside': {
twoWay: true,
}
});
-/**
- * The following block of code is used for to close "modal confirm update/register"
- * with escape key of keyboard or by clicking outside the modal
- */
-
-/**
- * end of block
- */
-
document.addEventListener('scroll', function () {
checkScroll();
}, {passive: true});