Conditions | 7 |
Total Lines | 115 |
Code Lines | 41 |
Lines | 10 |
Ratio | 8.7 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /* |
||
98 | async function businessDocViewSave() |
||
99 | { |
||
100 | $("#btn-document-save").prop("disabled", true); |
||
101 | |||
102 | var tipoPago = await cargarTipoPago(); |
||
103 | var datosPago = JSON.parse(tipoPago); |
||
104 | var ncfTipoPagoCliente = $("#formEditFacturaProveedor select[name=ncftipopago]").val(); |
||
105 | var readOnlySelects = ($("#formPurchaseDocumentLine #doc_idestado").val() === '11'); |
||
106 | let selectOptionsPagos = ""; |
||
107 | View Code Duplication | $.each(datosPago.pagos, function(i, value) { |
|
108 | let defaultSelected = ((value.codigo === '04' && ncfTipoPagoCliente === '') || ncfTipoPagoCliente === value.codigo) ? 'selected' : ''; |
||
109 | let noSelected = ($("#formPurchaseDocumentLine #doc_idestado").val() === '11' && defaultSelected !== 'selected') ? ' disabled' : ''; |
||
110 | selectOptionsPagos += '<option value="'+value.codigo+'"'+defaultSelected+noSelected+'>'+value.descripcion+'</option>'; |
||
111 | }); |
||
112 | |||
113 | var tipoMovimiento = await cargarTipoMovimiento(); |
||
114 | var datosMovimiento = JSON.parse(tipoMovimiento); |
||
115 | |||
116 | let selectOptionsMovimientos = ""; |
||
117 | View Code Duplication | $.each(datosMovimiento.movimientos, function (i, value) { |
|
118 | let defaultSelected = (value.codigo === '09') ? 'selected' : ''; |
||
119 | let noSelected = ($("#formPurchaseDocumentLine #doc_idestado").val() === '11' && defaultSelected !== 'selected') ? ' disabled' : ''; |
||
120 | selectOptionsMovimientos += '<option value="'+value.codigo+'"'+defaultSelected+noSelected+'>'+value.descripcion+'</option>'; |
||
121 | }); |
||
122 | |||
123 | let message = '<div class="form-content">\n' + |
||
124 | ' <form class="form" role="form">\n' + |
||
125 | ' <div class="form-group">\n' + |
||
126 | ' <label for="ncftipopago">Tipo de Pago</label>\n' + |
||
127 | ' <select class="custom-select" id="ncftipopago" name="ncftipopago"'+readOnlySelects+'>\n' + |
||
128 | selectOptionsPagos + |
||
129 | ' </select>\n' + |
||
130 | ' </div>\n' + |
||
131 | ' <div class="form-group">\n' + |
||
132 | ' <label for="ncftipomovimiento">Tipo de Movimiento</label>\n' + |
||
133 | ' <select class="custom-select" id="ncftipomovimiento" name="ncftipomovimiento"'+readOnlySelects+'>\n' + |
||
134 | selectOptionsMovimientos + |
||
135 | ' </select>\n' + |
||
136 | ' </div>\n' + |
||
137 | ' </form>\n' + |
||
138 | ' </div>'; |
||
139 | |||
140 | executeModal( |
||
141 | 'completeNCFData', |
||
142 | 'Complete la información faltante', |
||
143 | message, |
||
144 | 'default', |
||
145 | 'saveBussinessDocument' |
||
146 | ); |
||
147 | |||
148 | // bootbox.dialog({ |
||
149 | // title: "Complete la información faltante", |
||
150 | // message: '<div class="form-content">\n' + |
||
151 | // ' <form class="form" role="form">\n' + |
||
152 | // ' <div class="form-group">\n' + |
||
153 | // ' <label for="ncftipopago">Tipo de Pago</label>\n' + |
||
154 | // ' <select class="custom-select" id="ncftipopago" name="ncftipopago"'+readOnlySelects+'>\n' + |
||
155 | // selectOptionsPagos + |
||
156 | // ' </select>\n' + |
||
157 | // ' </div>\n' + |
||
158 | // ' <div class="form-group">\n' + |
||
159 | // ' <label for="ncftipomovimiento">Tipo de Movimiento</label>\n' + |
||
160 | // ' <select class="custom-select" id="ncftipomovimiento" name="ncftipomovimiento"'+readOnlySelects+'>\n' + |
||
161 | // selectOptionsMovimientos + |
||
162 | // ' </select>\n' + |
||
163 | // ' </div>\n' + |
||
164 | // ' </form>\n' + |
||
165 | // ' </div>', |
||
166 | // buttons: [ |
||
167 | // { |
||
168 | // label: "Guardar", |
||
169 | // className: "btn btn-primary", |
||
170 | // callback: function() { |
||
171 | // var data = {}; |
||
172 | // $.each($("#" + businessDocViewFormName).serializeArray(), function (key, value) { |
||
173 | // data[value.name] = value.value; |
||
174 | // }); |
||
175 | // data['ncftipopago'] = $('form #ncftipopago').val(); |
||
176 | // data['ncftipomovimiento'] = $('form #ncftipomovimiento').val(); |
||
177 | // data.action = "save-document"; |
||
178 | // data.lines = getGridData(); |
||
179 | // |
||
180 | // $.ajax({ |
||
181 | // type: "POST", |
||
182 | // url: businessDocViewUrl, |
||
183 | // dataType: "text", |
||
184 | // data: data, |
||
185 | // success: function (results) { |
||
186 | // if (results.substring(0, 3) === "OK:") { |
||
187 | // $("#" + businessDocViewFormName + " :input[name=\"action\"]").val('save-ok'); |
||
188 | // $("#" + businessDocViewFormName).attr('action', results.substring(3)).submit(); |
||
189 | // } else { |
||
190 | // alert(results); |
||
191 | // $("#" + businessDocViewFormName + " :input[name=\"multireqtoken\"]").val(randomString(20)); |
||
192 | // } |
||
193 | // }, |
||
194 | // error: function (msg) { |
||
195 | // alert(msg.status + " " + msg.responseText); |
||
196 | // } |
||
197 | // }); |
||
198 | // |
||
199 | // } |
||
200 | // }, |
||
201 | // { |
||
202 | // label: "Cancelar", |
||
203 | // className: "btn btn-danger", |
||
204 | // callback: function() { |
||
205 | // return true; |
||
206 | // } |
||
207 | // } |
||
208 | // ], |
||
209 | // }); |
||
210 | |||
211 | $("#btn-document-save").prop("disabled", false); |
||
212 | } |
||
213 | |||
227 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.