Last active
September 8, 2020 02:22
-
-
Save cagartner/728119e821b1304f031692e533685116 to your computer and use it in GitHub Desktop.
Bagisto Admin Traduzido para pt_BR
This file contains hidden or 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
import Vue from 'vue'; | |
import VeeValidate from 'vee-validate'; | |
import messagesPtBR from 'vee-validate/dist/locale/pt_BR'; | |
import './bootstrap'; | |
window.Vue = Vue; | |
window.VeeValidate = VeeValidate; | |
Vue.use(VeeValidate, { | |
events: 'input|change|blur', | |
dictionary: { | |
pt_BR: { messages: messagesPtBR } | |
} | |
}); | |
Vue.prototype.$http = axios | |
window.eventBus = new Vue(); | |
$(document).ready(function () { | |
Vue.config.ignoredElements = [ | |
'option-wrapper', | |
'group-form', | |
'group-list' | |
]; | |
var app = new Vue({ | |
el: "#app", | |
data: { | |
modalIds: {} | |
}, | |
mounted() { | |
this.addServerErrors(); | |
this.addFlashMessages(); | |
}, | |
methods: { | |
onSubmit: function (e) { | |
this.toggleButtonDisable(true); | |
if(typeof tinyMCE !== 'undefined') | |
tinyMCE.triggerSave(); | |
this.$validator.validateAll().then(result => { | |
if (result) { | |
e.target.submit(); | |
} else { | |
this.toggleButtonDisable(false); | |
eventBus.$emit('onFormError') | |
} | |
}); | |
}, | |
toggleButtonDisable (value) { | |
var buttons = document.getElementsByTagName("button"); | |
for (var i = 0; i < buttons.length; i++) { | |
buttons[i].disabled = value; | |
} | |
}, | |
addServerErrors(scope = null) { | |
for (var key in serverErrors) { | |
var inputNames = []; | |
key.split('.').forEach(function(chunk, index) { | |
if(index) { | |
inputNames.push('[' + chunk + ']') | |
} else { | |
inputNames.push(chunk) | |
} | |
}) | |
var inputName = inputNames.join(''); | |
const field = this.$validator.fields.find({ | |
name: inputName, | |
scope: scope | |
}); | |
if (field) { | |
this.$validator.errors.add({ | |
id: field.id, | |
field: inputName, | |
msg: serverErrors[key][0], | |
scope: scope | |
}); | |
} | |
} | |
}, | |
addFlashMessages() { | |
if (typeof flashMessages == 'undefined') { | |
return; | |
}; | |
const flashes = this.$refs.flashes; | |
flashMessages.forEach(function(flash) { | |
flashes.addFlash(flash); | |
}, this); | |
}, | |
showModal(id) { | |
this.$set(this.modalIds, id, true); | |
} | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment