Commit 9f6a02e51e53017b482afa37e7842f517191a394
1 parent
d3d096b2a1
Exists in
master
and in
1 other branch
implementación agregar domicilio
Showing
4 changed files
with
195 additions
and
23 deletions
Show diff stats
index.html
src/js/controller.js
| ... | ... | @@ -8,13 +8,20 @@ angular.module('focaModalDomicilio') |
| 8 | 8 | 'focaModalDomicilioService', |
| 9 | 9 | function($filter, $scope, $uibModalInstance, idCliente,focaModalDomicilioService) { |
| 10 | 10 | |
| 11 | - focaModalDomicilioService.getDomiciliosByIdCliente(idCliente).then( | |
| 12 | - function(res) { | |
| 13 | - $scope.domicilios = res.data; | |
| 14 | - $scope.search(); | |
| 15 | - } | |
| 16 | - ); | |
| 17 | - | |
| 11 | + $scope.buscar = function() { | |
| 12 | + focaModalDomicilioService.getDomiciliosByIdCliente($scope.idCliente).then( | |
| 13 | + function(res) { | |
| 14 | + $scope.domicilios = res.data; | |
| 15 | + $scope.search(); | |
| 16 | + $scope.primerBusqueda = true; | |
| 17 | + } | |
| 18 | + ); | |
| 19 | + }; | |
| 20 | + $scope.idCliente = idCliente; | |
| 21 | + $scope.buscar(); | |
| 22 | + $scope.ingreso = false; | |
| 23 | + $scope.primerBusqueda = false; | |
| 24 | + $scope.contactos = [{}]; | |
| 18 | 25 | // pagination |
| 19 | 26 | $scope.numPerPage = 5; |
| 20 | 27 | $scope.currentPage = 1; |
| ... | ... | @@ -88,6 +95,31 @@ angular.module('focaModalDomicilio') |
| 88 | 95 | } |
| 89 | 96 | }; |
| 90 | 97 | |
| 98 | + $scope.agregarContacto = function() { | |
| 99 | + $scope.contactos.push({item: $scope.contactos[$scope.contactos.length]}); | |
| 100 | + }; | |
| 101 | + | |
| 102 | + $scope.quitarContacto = function(key) { | |
| 103 | + $scope.contactos.splice(key, 1); | |
| 104 | + }; | |
| 105 | + | |
| 106 | + $scope.agregarDomicilio= function() { | |
| 107 | + $scope.domicilio.idCliente = $scope.idCliente; | |
| 108 | + $scope.domicilio.idDomicilioTipo = 2; //siempre es tipo de entrega | |
| 109 | + for(var i = 0; i < $scope.contactos.length; i++) { | |
| 110 | + $scope.contactos[i].idCliente = idCliente; | |
| 111 | + focaModalDomicilioService.guardarContacto($scope.contactos[i]); | |
| 112 | + } | |
| 113 | + focaModalDomicilioService | |
| 114 | + .guardarDomicilio($scope.domicilio) | |
| 115 | + .then(function() { | |
| 116 | + $scope.buscar(); | |
| 117 | + }); | |
| 118 | + $scope.ingreso = false; | |
| 119 | + $scope.domicilio = {}; | |
| 120 | + $scope.contactos = [{}]; | |
| 121 | + }; | |
| 122 | + | |
| 91 | 123 | function calcularPages(paginaActual) { |
| 92 | 124 | var paginas = []; |
| 93 | 125 | paginas.push(paginaActual); |
| ... | ... | @@ -131,7 +163,7 @@ angular.module('focaModalDomicilio') |
| 131 | 163 | } |
| 132 | 164 | |
| 133 | 165 | function siguiente() { |
| 134 | - if ($scope.selectedDomicilio < $scope.currentPageDomicilios.length - 1 ) { | |
| 166 | + if ($scope.selectedDomicilio < $scope.currentPageDomicilios.length ) { | |
| 135 | 167 | $scope.selectedDomicilio++; |
| 136 | 168 | } else { |
| 137 | 169 | avanzarPagina(); |
src/js/service.js
| ... | ... | @@ -8,6 +8,12 @@ angular.module('focaModalDomicilio') |
| 8 | 8 | var idTipoDom = 2;//El tipo para nota de pedido es 2 (tipo de entrega) |
| 9 | 9 | return $http.get(API_ENDPOINT.URL + |
| 10 | 10 | '/domicilio/tipo/' + idTipoDom + '/cliente/' + id); |
| 11 | + }, | |
| 12 | + guardarDomicilio: function(domicilio) { | |
| 13 | + return $http.post(API_ENDPOINT.URL + '/domicilio', {domicilio: domicilio}); | |
| 14 | + }, | |
| 15 | + guardarContacto: function(contacto) { | |
| 16 | + return $http.post(API_ENDPOINT.URL + '/contacto', {contacto: contacto}); | |
| 11 | 17 | } |
| 12 | 18 | }; |
| 13 | 19 | } |
src/views/modal-domicilio.html
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | <h3 class="modal-title">Busqueda de Domicilios</h3> |
| 3 | 3 | </div> |
| 4 | 4 | <div class="modal-body" id="modal-body"> |
| 5 | - <div class="input-group mb-3"> | |
| 5 | + <div class="input-group mb-3" ng-show="!ingreso"> | |
| 6 | 6 | <input |
| 7 | 7 | type="text" |
| 8 | 8 | class="form-control" |
| ... | ... | @@ -14,7 +14,7 @@ |
| 14 | 14 | foca-focus="selectedDomicilio == -1" |
| 15 | 15 | ng-focus="selectedDomicilio = -1" |
| 16 | 16 | > |
| 17 | - <table class="table table-striped table-sm"> | |
| 17 | + <table ng-show="!ingreso" class="table table-striped table-sm"> | |
| 18 | 18 | <thead> |
| 19 | 19 | <tr> |
| 20 | 20 | <th>Domicilio</th> |
| ... | ... | @@ -27,31 +27,59 @@ |
| 27 | 27 | <th></th> |
| 28 | 28 | <th></th> |
| 29 | 29 | <th></th> |
| 30 | - <th>Nombre</th> | |
| 31 | - <th>Telefono 1</th> | |
| 32 | - <th>Telefono 2</th> | |
| 33 | - <th></th> | |
| 30 | + <th>Tipo</th> | |
| 31 | + <th>Contacto</th> | |
| 34 | 32 | </tr> |
| 35 | 33 | </thead> |
| 36 | 34 | <tbody> |
| 35 | + <tr ng-show="currentPageDomicilios.length == 0 && primerBusqueda"> | |
| 36 | + <td colspan="6"> | |
| 37 | + No se encontraron resultados. | |
| 38 | + </td> | |
| 39 | + </tr> | |
| 40 | + <tr> | |
| 41 | + <td colspan="5" ng-show="!ingreso"> | |
| 42 | + <input | |
| 43 | + class="form-control form-control-sm" | |
| 44 | + type="text" | |
| 45 | + placeholder="Selección manual" | |
| 46 | + readonly | |
| 47 | + ng-click="ingreso = !ingreso" | |
| 48 | + /> | |
| 49 | + </td> | |
| 50 | + <td colspan="1" ng-show="!ingreso"> | |
| 51 | + <button | |
| 52 | + type="button" | |
| 53 | + class="btn btn-sm p-1 float-right" | |
| 54 | + ng-class="{ | |
| 55 | + 'btn-secondary': selectedDomicilio != 0, | |
| 56 | + 'btn-primary': selectedDomicilio == 0 | |
| 57 | + }" | |
| 58 | + foca-focus="selectedDomicilio == 0" | |
| 59 | + ng-keydown="itemDomicilio($event.keyCode)" | |
| 60 | + ng-click="ingreso = !ingreso" | |
| 61 | + > | |
| 62 | + <i class="fa fa-arrow-right" aria-hidden="true"></i> | |
| 63 | + </button> | |
| 64 | + </td> | |
| 65 | + </tr> | |
| 37 | 66 | <tr class="selectable" |
| 38 | 67 | ng-repeat="(key,domicilio) in currentPageDomicilios" |
| 39 | 68 | ng-click="select(domicilio)"> |
| 40 | 69 | <td ng-bind="domicilio.dom"></td> |
| 41 | 70 | <td ng-bind="domicilio.loc"></td> |
| 42 | 71 | <td ng-bind="domicilio.pci"></td> |
| 43 | - <td ng-bind="domicilio.contacto[0].nombre"></td> | |
| 44 | - <td ng-bind="domicilio.contacto[0].telefono1"></td> | |
| 45 | - <td ng-bind="domicilio.contacto[0].telefono2"></td> | |
| 72 | + <td ng-bind="domicilio.contacto[0].tipo"></td> | |
| 73 | + <td ng-bind="domicilio.contacto[0].contacto"></td> | |
| 46 | 74 | <td> |
| 47 | 75 | <button |
| 48 | 76 | type="button" |
| 49 | 77 | class="btn p-2 float-right" |
| 50 | 78 | ng-class="{ |
| 51 | - 'btn-secondary': selectedDomicilio != key, | |
| 52 | - 'btn-primary': selectedDomicilio == key | |
| 79 | + 'btn-secondary': selectedDomicilio != key + 1, | |
| 80 | + 'btn-primary': selectedDomicilio == key + 1 | |
| 53 | 81 | }" |
| 54 | - foca-focus="selectedDomicilio == {{key}}" | |
| 82 | + foca-focus="selectedDomicilio == {{key + 1}}" | |
| 55 | 83 | ng-keydown="itemDomicilio($event.keyCode)" |
| 56 | 84 | > |
| 57 | 85 | <i class="fa fa-arrow-right" aria-hidden="true"></i> |
| ... | ... | @@ -60,7 +88,7 @@ |
| 60 | 88 | </tr> |
| 61 | 89 | </tbody> |
| 62 | 90 | </table> |
| 63 | - <nav> | |
| 91 | + <nav ng-show="currentPageDomicilios.length > 0 && !ingreso"> | |
| 64 | 92 | <ul class="pagination justify-content-end"> |
| 65 | 93 | <li class="page-item" ng-class="{'disabled': currentPage == 1}"> |
| 66 | 94 | <a class="page-link" href="#" ng-click="selectPage(currentPage - 1)"> |
| ... | ... | @@ -89,7 +117,113 @@ |
| 89 | 117 | </ul> |
| 90 | 118 | </nav> |
| 91 | 119 | </div> |
| 120 | + <form name="formDomicilio" ng-show="ingreso"> | |
| 121 | + <div class="row"> | |
| 122 | + <div class="col-4"> | |
| 123 | + <label>Tipo</label> | |
| 124 | + <select | |
| 125 | + class="form-control" | |
| 126 | + ng-disabled="true" | |
| 127 | + > | |
| 128 | + <option ng-value="2">Entrega</option> | |
| 129 | + </select> | |
| 130 | + </div> | |
| 131 | + <div class="col-4"> | |
| 132 | + <label>Código Postal</label> | |
| 133 | + <input | |
| 134 | + type="text" | |
| 135 | + foca-focus="ingreso" | |
| 136 | + class="form-control" | |
| 137 | + ng-model="domicilio.cpo" | |
| 138 | + ng-required="true" | |
| 139 | + placeholder="Ingrese código postal" | |
| 140 | + /> | |
| 141 | + </div> | |
| 142 | + <div class="col-12"> | |
| 143 | + <label>Domicilio</label> | |
| 144 | + <input | |
| 145 | + type="text" | |
| 146 | + class="form-control" | |
| 147 | + ng-model="domicilio.dom" | |
| 148 | + ng-required="true" | |
| 149 | + placeholder="Ingrese domicilio" | |
| 150 | + /> | |
| 151 | + </div> | |
| 152 | + <div class="col-6"> | |
| 153 | + <label>Localidad</label> | |
| 154 | + <input | |
| 155 | + type="text" | |
| 156 | + class="form-control" | |
| 157 | + ng-model="domicilio.loc" | |
| 158 | + ng-required="true" | |
| 159 | + placeholder="Ingrese localidad" | |
| 160 | + /> | |
| 161 | + </div> | |
| 162 | + <div class="col-6"> | |
| 163 | + <label>Provincia</label> | |
| 164 | + <input | |
| 165 | + type="text" | |
| 166 | + class="form-control" | |
| 167 | + ng-model="domicilio.pci" | |
| 168 | + ng-required="true" | |
| 169 | + placeholder="Ingrese provincia" | |
| 170 | + /> | |
| 171 | + </div> | |
| 172 | + <label class="col-12">Ingrese Contactos</label> | |
| 173 | + <div class="col-12 form-row mb-1" ng-repeat="(key, contacto) in contactos"> | |
| 174 | + <div class="col-3"> | |
| 175 | + <select class="form-control" ng-model="contacto.tipo" ng-required="true"> | |
| 176 | + <option ng-value="0">Teléfono Móvil</option> | |
| 177 | + <option ng-value="1">Teléfono Fijo</option> | |
| 178 | + <option ng-value="2">Fax</option> | |
| 179 | + <option ng-value="3">Email</option> | |
| 180 | + </select> | |
| 181 | + </div> | |
| 182 | + <div class="col-7"> | |
| 183 | + <input | |
| 184 | + type="text" | |
| 185 | + class="form-control" | |
| 186 | + ng-model="contacto.contacto" | |
| 187 | + placeholder="Ingrese contacto" | |
| 188 | + ng-required="true" | |
| 189 | + > | |
| 190 | + </div> | |
| 191 | + <div class="col-1"> | |
| 192 | + <button | |
| 193 | + type="button" | |
| 194 | + class="form-control" | |
| 195 | + ng-click="quitarContacto(key)" | |
| 196 | + ng-disabled="contactos.length === 1" | |
| 197 | + ><i class="fa fa-minus" aria-hidden="true"></i> | |
| 198 | + </button> | |
| 199 | + </div> | |
| 200 | + <div class="col-1"> | |
| 201 | + <button | |
| 202 | + type="button" | |
| 203 | + class="form-control" | |
| 204 | + ng-click="agregarContacto()" | |
| 205 | + ><i class="fa fa-plus" aria-hidden="true"></i> | |
| 206 | + </button> | |
| 207 | + </div> | |
| 208 | + </div> | |
| 209 | + </div> | |
| 210 | + </form> | |
| 92 | 211 | </div> |
| 93 | 212 | <div class="modal-footer"> |
| 94 | - <button class="btn btn-secondary" type="button" ng-click="cancel()">Seleccionar otro cliente</button> | |
| 213 | + <button ng-show="!ingreso" class="btn btn-secondary" type="button" ng-click="cancel()">Seleccionar otro cliente</button> | |
| 214 | + <button | |
| 215 | + ng-show="ingreso" | |
| 216 | + class="btn btn-secondary" | |
| 217 | + type="button" | |
| 218 | + ng-click="ingreso = !ingreso; domicilio = {}; contactos = [{}]" | |
| 219 | + >Cancelar | |
| 220 | + </button> | |
| 221 | + <button | |
| 222 | + ng-show="ingreso" | |
| 223 | + class="btn btn-primary" | |
| 224 | + type="button" | |
| 225 | + ng-click="agregarDomicilio()" | |
| 226 | + ng-disabled="!formDomicilio.$valid" | |
| 227 | + >Agregar domicilio | |
| 228 | + </button> | |
| 95 | 229 | </div> |