Skip to content

Commit d2bba23

Browse files
committed
Refactored .vue files for implemente axios and change forms
- Changed 'main.vue' for remove 'title' property in bus event; - Changed 'table.vue' for remove 'title' property in bus event; - Refactored 'form.vue' for fix bug in edit and create methods; - Changed 'addresses.vue' for add full address of API URI.
1 parent 01c1f1c commit d2bba23

File tree

7 files changed

+1567
-208
lines changed

7 files changed

+1567
-208
lines changed

public/build/js/app-ca2d71f22b.js

Lines changed: 1150 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/rev-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"css/app.css": "css/app-ad87f36536.css",
33
"css/vendor.css": "css/vendor-0634183a17.css",
4-
"js/app.js": "js/app-66e2a3f00e.js"
4+
"js/app.js": "js/app-ca2d71f22b.js"
55
}

public/js/app.js

Lines changed: 348 additions & 177 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/assets/js/app/users/addresses.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
if (this.userid === obj.userid && this.addresses.length === 0) {
1212
this.isSearching = true
1313
this.$http
14-
.get(`api/endereco/${obj.userid}`)
14+
.get(`http://localhost/api/endereco/${obj.userid}`)
1515
.then(res => {
16-
this.addresses = res.body.addresses
16+
this.addresses = res.data.addresses
1717
this.isSearching = false
1818
})
1919

resources/assets/js/app/users/form.vue

Lines changed: 62 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,50 @@
44
props: ['token'],
55
data () {
66
return {
7-
user: {
8-
id: 0,
7+
fillUser: {
8+
id: '',
99
name: '',
1010
email: '',
1111
created_at: '',
1212
updated_at: ''
1313
},
14-
modalTitle : '',
14+
newUser: {
15+
name: '',
16+
email: '',
17+
password: ''
18+
},
1519
isEditing: false,
1620
}
1721
},
1822
computed: {
1923
action () {
2024
if (this.isEditing) {
21-
return `/usuarios/atualizar/${this.user.id}`
25+
return `/usuarios/atualizar/${this.fillUser.id}`
2226
} else {
2327
return `/usuarios/criar`
2428
}
2529
},
2630
},
2731
mounted () {
28-
const userFormModal = jQuery(this.$refs.userFormModal)
32+
const editUserModal = jQuery(this.$refs.editUserModal)
33+
const newUserModal = jQuery(this.$refs.newUserModal)
2934
3035
bus.$on('open-form', (obj) => {
31-
if (obj.user !== undefined){
36+
if (obj !== undefined){
3237
this.isEditing = true
33-
this.user = obj.user
34-
this.modalTitle = obj.title
38+
this.fillUser = obj.user
39+
editUserModal.modal('show')
3540
} else {
3641
this.isEditing = false
37-
this.modalTitle = obj.title
42+
this.newUser.name = ''
43+
this.newUser.email = ''
44+
this.newUser.password = ''
45+
newUserModal.modal('show')
3846
}
39-
40-
userFormModal.modal('show')
4147
})
4248
43-
userFormModal.on('hidden.bs.modal', () => {
49+
editUserModal.on('hidden.bs.modal', () => {
4450
this.isEditing = false
45-
this.user.id = 0
46-
this.user.name = ''
47-
this.user.email = ''
48-
this.user.created_at = ''
49-
this.user.updated_at = ''
50-
this.modalTitle = ''
5151
})
5252
}
5353
}
@@ -56,29 +56,67 @@
5656
<template>
5757
<div>
5858
<!-- /.modal -->
59-
<div ref="userFormModal" class="modal fade" tabindex="-1" role="dialog">
59+
<div ref="editUserModal" class="modal fade" tabindex="-1" role="dialog">
60+
<!-- /.modal-dialog -->
61+
<div class="modal-dialog" role="document">
62+
<!-- /.modal-content -->
63+
<div class="modal-content">
64+
<div class="modal-header">
65+
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
66+
<h4 class="modal-title"><i class="fa fa-fw fa-user"></i>Alterar Usuário</h4>
67+
</div>
68+
<div class="modal-body">
69+
<form method="post" :action="action">
70+
<input id="_token" name="_token" type="hidden" :value="token">
71+
<div class="form-group">
72+
<label for="name" class="control-label">Nome</label>
73+
<input id="name" name="name" type="text" class="form-control" v-model="fillUser.name">
74+
</div>
75+
<div class="form-group">
76+
<label for="email" class="control-label">E-mail</label>
77+
<input id="email" name="email" type="email" class="form-control" v-model="fillUser.email">
78+
</div>
79+
<div class="form-group">
80+
<label for="password" class="control-label">Senha</label>
81+
<input id="password" name="password" type="password" class="form-control" v-model="fillUser.password">
82+
</div>
83+
<div class="modal-footer">
84+
<button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
85+
<button type="submit" class="btn btn-primary">Alterar</button>
86+
</div>
87+
</form>
88+
</div>
89+
</div>
90+
<!-- /.modal-content -->
91+
</div>
92+
<!-- /.modal-dialog -->
93+
</div>
94+
<!-- /.modal -->
95+
96+
<!-- /.modal -->
97+
<div ref="newUserModal" class="modal fade" tabindex="-1" role="dialog">
6098
<!-- /.modal-dialog -->
6199
<div class="modal-dialog" role="document">
62100
<!-- /.modal-content -->
63101
<div class="modal-content">
64102
<div class="modal-header">
65103
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
66-
<h4 class="modal-title"><i class="fa fa-fw fa-user"></i>{{ modalTitle }}</h4>
104+
<h4 class="modal-title"><i class="fa fa-fw fa-user"></i>Criar Novo Usuário</h4>
67105
</div>
68106
<div class="modal-body">
69-
<form ref="userForm" method="post" :action="action">
107+
<form method="post" :action="action">
70108
<input id="_token" name="_token" type="hidden" :value="token">
71109
<div class="form-group">
72110
<label for="name" class="control-label">Nome</label>
73-
<input id="name" name="name" type="text" class="form-control" v-model="user.name">
111+
<input id="name" name="name" type="text" class="form-control" v-model="newUser.name">
74112
</div>
75113
<div class="form-group">
76114
<label for="email" class="control-label">E-mail</label>
77-
<input id="email" name="email" type="email" class="form-control" v-model="user.email">
115+
<input id="email" name="email" type="email" class="form-control" v-model="newUser.email">
78116
</div>
79117
<div class="form-group">
80118
<label for="password" class="control-label">Senha</label>
81-
<input id="password" name="password" type="password" class="form-control" v-model="user.password">
119+
<input id="password" name="password" type="password" class="form-control" v-model="newUser.password">
82120
</div>
83121
<div class="modal-footer">
84122
<button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>

resources/assets/js/app/users/main.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
methods: {
1212
form (){
13-
bus.$emit('open-form', { title: 'Criar Novo Usuário' })
13+
bus.$emit('open-form')
1414
}
1515
}
1616
}

resources/assets/js/app/users/table.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
this.details = []
3535
} else {
3636
this.details = this.users.map(user => {
37-
bus.$emit('get-addresses', {userid: user.id})
37+
bus.$emit('get-addresses', { userid: user.id })
3838
return user.id
3939
})
4040
}
@@ -45,14 +45,14 @@
4545
this.details.splice(index, 1)
4646
} else {
4747
this.details.push(id)
48-
bus.$emit('get-addresses', {userid: id})
48+
bus.$emit('get-addresses', { userid: id })
4949
}
5050
},
5151
formatDate (date) {
5252
return moment(date).format('DD/MM/YYYY')
5353
},
5454
edit (user) {
55-
bus.$emit('open-form', { user: user, title: 'Editar Usuário'})
55+
bus.$emit('open-form', { user: user })
5656
},
5757
remove (id) {
5858
const confirm = window.confirm('Tem Certeza da Exclusão?')

0 commit comments

Comments
 (0)