added fields from dadata on the profile edit page

remotes/origin/mitri4
Dmitriy Shesterkin 9 years ago
parent 6ae7fb09fa
commit f7c807a5d1
  1. 125
      project/templates/customer/profile/edit.html

@ -33,6 +33,17 @@
</div> </div>
{% if profile.is_ip %} {% if profile.is_ip %}
<div id="boss_fio" class="field">
<div class='profile_label'>
Индивидуальный предприниматель
</div>
<div class='long-input profile_field'>
<input id="searchAPI" maxlength="256" name="searchAPI" type="text">
<span class="help-text">Остальные необходимые поля заполнятся по найденным данным</span>
</div>
<div class="clear"></div>
</div>
<div id="boss_fio" class="field"> <div id="boss_fio" class="field">
<div class='profile_label'> <div class='profile_label'>
Фамилия, Имя, Отчество Фамилия, Имя, Отчество
@ -273,7 +284,7 @@
<div id="address" class="field"> <div id="address" class="field">
<div class="profile_label"> <div class="profile_label">
Файтический адрес{% if form.address.field.required %} <span class="required">*</span>{% endif %} Фактический адрес{% if form.address.field.required %} <span class="required">*</span>{% endif %}
</div> </div>
<div class="long-input profile_field"> <div class="long-input profile_field">
{{ form.address }} {{ form.address }}
@ -529,6 +540,117 @@
<script src="{{ STATIC_URL }}js/lib/jquery.suggestions.min.js"></script> <script src="{{ STATIC_URL }}js/lib/jquery.suggestions.min.js"></script>
<script>
var paramsType,
profileForm = $("#profile-form"),
profileSearch =$("#searchAPI", profileForm),
profileBossName = $("#id_boss_name", profileForm),
profileBossSurname =$("#id_boss_surname", profileForm),
profileBossMiddleName =$("#id_boss_midname", profileForm),
profileInn = $("#id_inn", profileForm),
profileKpp = $("#id_kpp", profileForm),
profileOqrn = $("#id_ogrn", profileForm),
profileAddress = $("#id_address", profileForm),
profileLegalAddress = $("#id_jur_address", profileForm),
profilePostalAddress = $("#id_real_address", profileForm),
profileInputs = [];
function getType() {
var False = false,
True = true,
isOrg = {{ profile.is_org }};
return isOrg ? "LEGAL" : "INDIVIDUAL";
}
function join(arr) {
var separator = arguments.length > 1 ? arguments[1] : ", ";
return arr.filter(function(n){return n}).join(separator);
}
function getPartOfPersonName(fullName, part) {
if (!fullName) return;
return fullName.split(' ')[part];
}
function showSuggestion(suggestion) {
var data = suggestion.data;
if (!data) return;
if (paramsType ==="LEGAL") {
if (data.name)
profileOrgName.val(join([data.opf && data.opf.short || "", data.name.short || data.name.full], " "));
if (data.name && data.name.full)
profileOrgFullName.val(join([data.opf && data.opf.full || "", data.name.full], " "));
if (data.address) {
profileAddress.val(data.address.value);
profileLegalAddress.val(data.address.value);
}
if (data.management) {
var management = data.management;
if (management.post) {profileBossTitle.val(data.management.post)}
if (management.name) {
var fullName = management.name;
profileBossSurname.val(getPartOfPersonName(fullName, 0));
profileBossName.val(getPartOfPersonName(fullName, 1));
profileBossMiddleName.val(getPartOfPersonName(fullName, 2));
}
}
} else {
if (data.name && data.name.full) {
var profileFullName = data.name.full;
profileBossSurname.val(getPartOfPersonName(profileFullName, 0));
profileBossName.val(getPartOfPersonName(profileFullName, 1));
profileBossMiddleName.val(getPartOfPersonName(profileFullName, 2));
}
if (data.address) {
var address = data.address.value;
profileAddress.val(address);
profileLegalAddress.val(address);
profilePostalAddress.val(address);
}
if (data.state && data.state.registration_date) {
profileRegDate.val((new Date(data.state.registration_date)).toLocaleDateString())
}
}
profileInn.val(data.inn);
profileKpp.val(data.kpp);
profileOqrn.val(data.ogrn);
}
paramsType = getType();
if (paramsType === "LEGAL") {
var profileOrgName = $('#id_name', profileForm),
profileOrgFullName = $('#id_full_name', profileForm),
profileBossTitle = $('#id_boss_title', profileForm);
profileInputs = [profileOrgName, profileOrgFullName, profileInn, profileKpp, profileOqrn]
} else {
var profileRegDate = $('#id_ip_reg_date', profileForm);
profileInputs = [profileSearch, profileInn, profileKpp, profileOqrn];
}
for (var index = profileInputs.length - 1; index >= 0; --index) {
profileInputs[index].suggestions({
token: "{{ dadata_api_key }}",
type: "PARTY",
params: {
type: paramsType
},
count: 5,
onSelect: showSuggestion
});
}
</script>
<script> <script>
var bankForm = $("#bank-account-edit-form"), var bankForm = $("#bank-account-edit-form"),
@ -558,4 +680,5 @@
} }
</script> </script>
{% endblock %} {% endblock %}

Loading…
Cancel
Save