Commit 186f7e77fe0730358e5b9a1c9b92164a01ab4a95

Authored by Eric Fernandez
1 parent 732171ab8f
Exists in master

refactor agregar domicilio en modal

src/js/controller.js
... ... @@ -9,8 +9,9 @@ angular.module('focaModalDomicilio')
9 9 function($filter, $scope, $uibModalInstance, idCliente,focaModalDomicilioService) {
10 10  
11 11 $scope.buscar = function() {
12   - focaModalDomicilioService.getDomiciliosByIdCliente($scope.idCliente).then(
13   - function(res) {
  12 + focaModalDomicilioService
  13 + .getDomiciliosEntregaByIdCliente($scope.idCliente)
  14 + .then(function(res) {
14 15 $scope.domicilios = res.data;
15 16 $scope.search();
16 17 $scope.primerBusqueda = true;
... ... @@ -95,29 +96,47 @@ angular.module('focaModalDomicilio')
95 96 }
96 97 };
97 98  
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 99 $scope.agregarDomicilio= function() {
  100 + $scope.domicilio.valores = [];
107 101 $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]);
  102 + if($scope.domicilio.calle) {
  103 + $scope.domicilio.valores.push({
  104 + ID_ADAC_1: 1,
  105 + dato: $scope.domicilio.calle
  106 + });
112 107 }
113   - focaModalDomicilioService
114   - .guardarDomicilio($scope.domicilio)
115   - .then(function() {
116   - $scope.buscar();
  108 + if($scope.domicilio.numeroCalle) {
  109 + $scope.domicilio.valores.push({
  110 + ID_ADAC_1: 2,
  111 + dato: $scope.domicilio.numeroCalle
117 112 });
118   - $scope.ingreso = false;
119   - $scope.domicilio = {};
120   - $scope.contactos = [{}];
  113 + }
  114 + if($scope.domicilio.localidad) {
  115 + $scope.domicilio.valores.push({
  116 + ID_ADAC_1: 3,
  117 + dato: $scope.domicilio.localidad
  118 + });
  119 + }
  120 + if($scope.domicilio.provincia) {
  121 + $scope.domicilio.valores.push({
  122 + ID_ADAC_1: 4,
  123 + dato: $scope.domicilio.provincia
  124 + });
  125 + }
  126 + //domicilios de entrega corresponden al 1
  127 + focaModalDomicilioService
  128 + .obtenerUltimoPorNivelPadre(1)
  129 + .then(function(res) {
  130 + $scope.domicilio.nivel1 = 1;//domicilio de entrega corresponde 1
  131 + $scope.domicilio.nivel2 = res.data[0].ultimo + 1;
  132 + focaModalDomicilioService
  133 + .guardarDomicilio($scope.domicilio)
  134 + .then(function() {
  135 + $scope.buscar();
  136 + $scope.ingreso = false;
  137 + $scope.domicilio = {};
  138 + });
  139 + });
121 140 };
122 141  
123 142 function calcularPages(paginaActual) {
... ... @@ -4,16 +4,18 @@ angular.module(&#39;focaModalDomicilio&#39;)
4 4 'API_ENDPOINT',
5 5 function($http, API_ENDPOINT) {
6 6 return {
7   - getDomiciliosByIdCliente: function(id) {
8   - var idTipoDom = 2;//El tipo para nota de pedido es 2 (tipo de entrega)
  7 + getDomiciliosEntregaByIdCliente: function(id) {
9 8 return $http.get(API_ENDPOINT.URL +
10   - '/domicilio/tipo/' + idTipoDom + '/cliente/' + id);
  9 + '/domicilio/entrega/cliente/' + id);
11 10 },
12 11 guardarDomicilio: function(domicilio) {
13 12 return $http.post(API_ENDPOINT.URL + '/domicilio', {domicilio: domicilio});
14 13 },
15 14 guardarContacto: function(contacto) {
16 15 return $http.post(API_ENDPOINT.URL + '/contacto', {contacto: contacto});
  16 + },
  17 + obtenerUltimoPorNivelPadre: function(nivel1) {
  18 + return $http.get(API_ENDPOINT.URL + '/domicilio/ultimo/' + nivel1);
17 19 }
18 20 };
19 21 }
src/views/modal-domicilio.html
... ... @@ -17,28 +17,21 @@
17 17 <table ng-show="!ingreso" class="table table-striped table-sm">
18 18 <thead>
19 19 <tr>
20   - <th>Domicilio</th>
  20 + <th>Titulo</th>
  21 + <th>Calle</th>
21 22 <th>Localidad</th>
22 23 <th>Provincia</th>
23   - <th colspan="5" class="text-center">Contacto</th>
24 24 <th></th>
25 25 </tr>
26   - <tr>
27   - <th></th>
28   - <th></th>
29   - <th></th>
30   - <th>Tipo</th>
31   - <th>Contacto</th>
32   - </tr>
33 26 </thead>
34 27 <tbody>
35 28 <tr ng-show="currentPageDomicilios.length == 0 && primerBusqueda">
36   - <td colspan="6">
  29 + <td colspan="5">
37 30 No se encontraron resultados.
38 31 </td>
39 32 </tr>
40 33 <tr>
41   - <td colspan="5" ng-show="!ingreso">
  34 + <td colspan="4" ng-show="!ingreso">
42 35 <input
43 36 class="form-control form-control-sm"
44 37 type="text"
... ... @@ -66,11 +59,10 @@
66 59 <tr class="selectable"
67 60 ng-repeat="(key,domicilio) in currentPageDomicilios"
68 61 ng-click="select(domicilio)">
69   - <td ng-bind="domicilio.dom"></td>
70   - <td ng-bind="domicilio.loc"></td>
71   - <td ng-bind="domicilio.pci"></td>
72   - <td ng-bind="domicilio.contacto[0].tipo"></td>
73   - <td ng-bind="domicilio.contacto[0].contacto"></td>
  62 + <td ng-bind="domicilio.titulo"></td>
  63 + <td ng-bind="domicilio.Calle + ' ' + domicilio.Numero"></td>
  64 + <td ng-bind="domicilio.Localidad"></td>
  65 + <td ng-bind="domicilio.Provincia"></td>
74 66 <td>
75 67 <button
76 68 type="button"
... ... @@ -128,25 +120,35 @@
128 120 <option ng-value="2">Entrega</option>
129 121 </select>
130 122 </div>
131   - <div class="col-4">
132   - <label>Código Postal</label>
  123 + <div class="col-8">
  124 + <label>Titulo</label>
133 125 <input
134 126 type="text"
135 127 foca-focus="ingreso"
136 128 class="form-control"
137   - ng-model="domicilio.cpo"
  129 + ng-model="domicilio.titulo"
  130 + placeholder="Ingrese título"
  131 + ng-required="true"
  132 + />
  133 + </div>
  134 + <div class="col-9">
  135 + <label>Calle</label>
  136 + <input
  137 + type="text"
  138 + class="form-control"
  139 + ng-model="domicilio.calle"
  140 + placeholder="Ingrese calle"
138 141 ng-required="true"
139   - placeholder="Ingrese código postal"
140 142 />
141 143 </div>
142   - <div class="col-12">
143   - <label>Domicilio</label>
  144 + <div class="col-3">
  145 + <label>Nº</label>
144 146 <input
145 147 type="text"
146 148 class="form-control"
147   - ng-model="domicilio.dom"
  149 + ng-model="domicilio.numeroCalle"
  150 + placeholder="Ingrese Numero"
148 151 ng-required="true"
149   - placeholder="Ingrese domicilio"
150 152 />
151 153 </div>
152 154 <div class="col-6">
... ... @@ -154,9 +156,9 @@
154 156 <input
155 157 type="text"
156 158 class="form-control"
157   - ng-model="domicilio.loc"
158   - ng-required="true"
  159 + ng-model="domicilio.localidad"
159 160 placeholder="Ingrese localidad"
  161 + ng-required="true"
160 162 />
161 163 </div>
162 164 <div class="col-6">
... ... @@ -164,48 +166,11 @@
164 166 <input
165 167 type="text"
166 168 class="form-control"
167   - ng-model="domicilio.pci"
168   - ng-required="true"
  169 + ng-model="domicilio.provincia"
169 170 placeholder="Ingrese provincia"
  171 + ng-required="true"
170 172 />
171 173 </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 174 </div>
210 175 </form>
211 176 </div>