|
4 | 4 | props: ['token'], |
5 | 5 | data () { |
6 | 6 | return { |
7 | | - user: { |
8 | | - id: 0, |
| 7 | + fillUser: { |
| 8 | + id: '', |
9 | 9 | name: '', |
10 | 10 | email: '', |
11 | 11 | created_at: '', |
12 | 12 | updated_at: '' |
13 | 13 | }, |
14 | | - modalTitle : '', |
| 14 | + newUser: { |
| 15 | + name: '', |
| 16 | + email: '', |
| 17 | + password: '' |
| 18 | + }, |
15 | 19 | isEditing: false, |
16 | 20 | } |
17 | 21 | }, |
18 | 22 | computed: { |
19 | 23 | action () { |
20 | 24 | if (this.isEditing) { |
21 | | - return `/usuarios/atualizar/${this.user.id}` |
| 25 | + return `/usuarios/atualizar/${this.fillUser.id}` |
22 | 26 | } else { |
23 | 27 | return `/usuarios/criar` |
24 | 28 | } |
25 | 29 | }, |
26 | 30 | }, |
27 | 31 | mounted () { |
28 | | - const userFormModal = jQuery(this.$refs.userFormModal) |
| 32 | + const editUserModal = jQuery(this.$refs.editUserModal) |
| 33 | + const newUserModal = jQuery(this.$refs.newUserModal) |
29 | 34 |
|
30 | 35 | bus.$on('open-form', (obj) => { |
31 | | - if (obj.user !== undefined){ |
| 36 | + if (obj !== undefined){ |
32 | 37 | this.isEditing = true |
33 | | - this.user = obj.user |
34 | | - this.modalTitle = obj.title |
| 38 | + this.fillUser = obj.user |
| 39 | + editUserModal.modal('show') |
35 | 40 | } else { |
36 | 41 | this.isEditing = false |
37 | | - this.modalTitle = obj.title |
| 42 | + this.newUser.name = '' |
| 43 | + this.newUser.email = '' |
| 44 | + this.newUser.password = '' |
| 45 | + newUserModal.modal('show') |
38 | 46 | } |
39 | | -
|
40 | | - userFormModal.modal('show') |
41 | 47 | }) |
42 | 48 |
|
43 | | - userFormModal.on('hidden.bs.modal', () => { |
| 49 | + editUserModal.on('hidden.bs.modal', () => { |
44 | 50 | 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 = '' |
51 | 51 | }) |
52 | 52 | } |
53 | 53 | } |
|
56 | 56 | <template> |
57 | 57 | <div> |
58 | 58 | <!-- /.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">×</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"> |
60 | 98 | <!-- /.modal-dialog --> |
61 | 99 | <div class="modal-dialog" role="document"> |
62 | 100 | <!-- /.modal-content --> |
63 | 101 | <div class="modal-content"> |
64 | 102 | <div class="modal-header"> |
65 | 103 | <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</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> |
67 | 105 | </div> |
68 | 106 | <div class="modal-body"> |
69 | | - <form ref="userForm" method="post" :action="action"> |
| 107 | + <form method="post" :action="action"> |
70 | 108 | <input id="_token" name="_token" type="hidden" :value="token"> |
71 | 109 | <div class="form-group"> |
72 | 110 | <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"> |
74 | 112 | </div> |
75 | 113 | <div class="form-group"> |
76 | 114 | <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"> |
78 | 116 | </div> |
79 | 117 | <div class="form-group"> |
80 | 118 | <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"> |
82 | 120 | </div> |
83 | 121 | <div class="modal-footer"> |
84 | 122 | <button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button> |
|
0 commit comments