You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
129 lines
4.8 KiB
129 lines
4.8 KiB
/* Dependencies:
|
|
PROFILE_FILTERS['edit_url']
|
|
*/
|
|
|
|
|
|
// view
|
|
$(document).ready(function() {
|
|
var $profile = $('#profile');
|
|
var $profile_info = $('.info', $profile);
|
|
var $profile_org_boss_info = $('.org-boss-info', $profile);
|
|
var $profile_accounts = $('.accounts', $profile);
|
|
var $profile_contacts = $('.contacts', $profile);
|
|
|
|
var $filters_form = $('#profile-filters-form');
|
|
var $filters_info = $('.info', $filters_form);
|
|
var $filters_org_boss_info = $('.org-boss-info', $filters_form);
|
|
var $filters_accounts = $('.accounts', $filters_form);
|
|
var $filters_contacts = $('.contacts', $filters_form);
|
|
|
|
// save the list of permanently disabled filters (having set attr 'disabled')
|
|
var $always_disabled_filters = $(':input:disabled', $filters_form);
|
|
|
|
// init profile blocks and fields
|
|
$(':input', $filters_form).each(function() {
|
|
var el = $(this);
|
|
var field_id = '#' + el.prop('name').substring('show_'.length);
|
|
el.is(':checked') ? $(field_id, $profile).show() : $(field_id, $profile).hide();
|
|
});
|
|
|
|
// init profile accounts
|
|
$('[id^=account]', $profile_accounts).hide();
|
|
var account_id = '#account_' + $('input[name=bank_account]:checked', $filters_accounts).val();
|
|
$(account_id, $profile_accounts).show();
|
|
|
|
// init filter blocks
|
|
_toggle_filters($('#id_show_profile_type:input', $filters_form), $filters_info);
|
|
_toggle_filters($('#id_show_org_boss_title_and_fio:input', $filters_form), $filters_org_boss_info);
|
|
_toggle_filters($('#id_show_bank_account:input', $filters_form), $filters_accounts);
|
|
_toggle_filters($('#id_show_contact_info:input', $filters_form), $filters_contacts);
|
|
|
|
// on click show/hide filter info block
|
|
$('#id_show_profile_type:input', $filters_form).click(function() {
|
|
var el = $(this);
|
|
_toggle_filters(el, $filters_info);
|
|
el.is(':checked') ? $($profile_info).show() : $($profile_info).hide();
|
|
});
|
|
|
|
// on click show/hide filter org-boss-info block
|
|
$('#id_show_org_boss_title_and_fio:input', $filters_form).click(function() {
|
|
var el = $(this);
|
|
_toggle_filters(el, $filters_org_boss_info);
|
|
el.is(':checked') ? $($profile_org_boss_info).show() : $($profile_org_boss_info).hide();
|
|
});
|
|
|
|
// on click show/hide filter accounts block
|
|
$('#id_show_bank_account:input', $filters_form).click(function() {
|
|
var el = $(this);
|
|
_toggle_filters(el, $filters_accounts);
|
|
if (el.is(':checked')) {
|
|
var account_id = '#account_' + $('input[name=bank_account]:checked', $filters_accounts).val();
|
|
$(account_id, $profile_accounts).show();
|
|
}
|
|
else
|
|
$('[id^=account_]', $profile_accounts).hide();
|
|
});
|
|
|
|
// on click show/hide filter contacts block
|
|
$('#id_show_contact_info:input', $filters_form).click(function() {
|
|
var el = $(this);
|
|
_toggle_filters(el, $filters_contacts);
|
|
el.is(':checked') ? $($profile_contacts).show() : $($profile_contacts).hide();
|
|
});
|
|
|
|
// on click show/hide profile fields
|
|
$(':input', $filters_form).click(function() {
|
|
var el = $(this);
|
|
var field_id = '#' + el.prop('name').substring('show_'.length);
|
|
el.is(':checked') ? $(field_id, $profile).show() : $(field_id, $profile).hide();
|
|
});
|
|
|
|
// on click show/hide profile accounts
|
|
$('input[name=bank_account]', $filters_form).click(function() {
|
|
var el = $(this);
|
|
var curr_acc = $('[id^=account_]:visible', $profile_accounts);
|
|
var new_acc = $('#account_' + el.val(), $profile_accounts);
|
|
if (new_acc.prop('id') !== curr_acc.prop('id')) {
|
|
curr_acc.hide();
|
|
new_acc.show();
|
|
}
|
|
});
|
|
|
|
// dialogs
|
|
var email_form = $('#email-profile-form');
|
|
|
|
email_form.dialog({
|
|
modal: true,
|
|
autoOpen: false
|
|
});
|
|
|
|
$('button[name=close-form]', email_form).click(function() {
|
|
email_form.dialog('close');
|
|
return false;
|
|
});
|
|
|
|
email_form.submit(function() {
|
|
$.post(PROFILE_FILTERS['edit_url'], $filters_form.serialize()); // save current filters
|
|
});
|
|
|
|
$('input[name=email-pdf]', $filters_form).click(function() {
|
|
email_form.dialog('open');
|
|
return false;
|
|
});
|
|
|
|
// ---
|
|
|
|
function _toggle_filters(el, dest) {
|
|
if (el.is(':checked')) {
|
|
$(':input', dest).not(el).not($always_disabled_filters).removeAttr('disabled');
|
|
$(':input:hidden', dest).not(el).not($always_disabled_filters).remove();
|
|
}
|
|
else {
|
|
// disable sub-filters
|
|
$(':input', dest).not(el).not($always_disabled_filters).prop('disabled', true);
|
|
// keep checked sub-filters: duplicate as hidden input
|
|
$(':input:visible:disabled:checked', dest).not(el).not($always_disabled_filters)
|
|
.clone().hide().removeAttr('disabled').appendTo(dest);
|
|
}
|
|
}
|
|
});
|
|
|