Lines 166-203
function update_category_code(category_code) {
Link Here
|
166 |
} |
166 |
} |
167 |
|
167 |
|
168 |
function select_user(borrowernumber, borrower) { |
168 |
function select_user(borrowernumber, borrower) { |
169 |
$('#guarantor_id').val(borrower.borrowernumber); |
169 |
let is_guarantor = $(`.guarantor-details[data-borrowernumber=${borrower.borrowernumber}]`).length; |
170 |
$('#guarantor_surname').val(borrower.surname); |
170 |
console.log("LEN: " + is_guarantor ); |
171 |
$('#guarantor_firstname').val(borrower.firstname); |
|
|
172 |
|
171 |
|
173 |
var fieldset = $('#guarantor_template').clone(); |
172 |
if ( is_guarantor ) { |
174 |
fieldset.removeAttr('id'); |
173 |
alert("Patron is already a guarantor for this patron"); |
175 |
|
|
|
176 |
var guarantor_id = $('#guarantor_id').val(); |
177 |
if ( guarantor_id ) { |
178 |
fieldset.find('.new_guarantor_id').first().val( guarantor_id ); |
179 |
fieldset.find('.new_guarantor_id_text').first().text( guarantor_id ); |
180 |
} else { |
174 |
} else { |
181 |
fieldset.find('.guarantor_id').first().hide(); |
175 |
$('#guarantor_id').val(borrower.borrowernumber); |
182 |
} |
176 |
$('#guarantor_surname').val(borrower.surname); |
183 |
$('#guarantor_id').val(""); |
177 |
$('#guarantor_firstname').val(borrower.firstname); |
|
|
178 |
|
179 |
var fieldset = $('#guarantor_template').clone(); |
180 |
fieldset.removeAttr('id'); |
181 |
|
182 |
var guarantor_id = $('#guarantor_id').val(); |
183 |
if ( guarantor_id ) { |
184 |
fieldset.find('.new_guarantor_id').first().val( guarantor_id ); |
185 |
fieldset.find('.new_guarantor_id_text').first().text( guarantor_id ); |
186 |
} else { |
187 |
fieldset.find('.guarantor_id').first().hide(); |
188 |
} |
189 |
$('#guarantor_id').val(""); |
184 |
|
190 |
|
185 |
var guarantor_surname = $('#guarantor_surname').val(); |
191 |
var guarantor_surname = $('#guarantor_surname').val(); |
186 |
fieldset.find('.new_guarantor_surname').first().val( guarantor_surname ); |
192 |
fieldset.find('.new_guarantor_surname').first().val( guarantor_surname ); |
187 |
fieldset.find('.new_guarantor_surname_text').first().text( guarantor_surname ); |
193 |
fieldset.find('.new_guarantor_surname_text').first().text( guarantor_surname ); |
188 |
$('#guarantor_surname').val(""); |
194 |
$('#guarantor_surname').val(""); |
189 |
|
195 |
|
190 |
var guarantor_firstname = $('#guarantor_firstname').val(); |
196 |
var guarantor_firstname = $('#guarantor_firstname').val(); |
191 |
fieldset.find('.new_guarantor_firstname').first().val( guarantor_firstname ); |
197 |
fieldset.find('.new_guarantor_firstname').first().val( guarantor_firstname ); |
192 |
fieldset.find('.new_guarantor_firstname_text').first().text( guarantor_firstname ); |
198 |
fieldset.find('.new_guarantor_firstname_text').first().text( guarantor_firstname ); |
193 |
$('#guarantor_firstname').val(""); |
199 |
$('#guarantor_firstname').val(""); |
194 |
|
200 |
|
195 |
var guarantor_relationship = $('#relationship').val(); |
201 |
var guarantor_relationship = $('#relationship').val(); |
196 |
fieldset.find('.new_guarantor_relationship').first().val( guarantor_relationship ); |
202 |
fieldset.find('.new_guarantor_relationship').first().val( guarantor_relationship ); |
197 |
$('#relationship').find('option:eq(0)').prop('selected', true);; |
203 |
$('#relationship').find('option:eq(0)').prop('selected', true); |
198 |
|
204 |
|
199 |
$('#guarantor_relationships').append( fieldset ); |
205 |
fieldset.find('.guarantor-details').first().attr( 'data-borrowernumber', borrower.borrowernumber ); |
200 |
fieldset.show(); |
206 |
console.log( fieldset.find('.guarantor-details').first().data() ); |
|
|
207 |
|
208 |
$('#guarantor_relationships').append( fieldset ); |
209 |
fieldset.show(); |
210 |
} |
201 |
|
211 |
|
202 |
return 0; |
212 |
return 0; |
203 |
} |
213 |
} |
204 |
- |
|
|