var App_AdminVolunteerMember_Form = { availablePositions: {}, liaisonPosition: '', initialize: function(options) { if (!empty(options.positions)) { this.availablePositions = options.positions; } if (!empty(options.liaisonPosition)) { this.liaisonPosition = options.liaisonPosition; } this.initAutocomplete(); }, initAutocomplete: function() { var obj = this; $("#member").autocomplete(CURR_PAGE_FULL + "?action=showMember", { width:300, selectFirst:true, max:100 }); $("#member").result(function (event, data, formatted) { if (data) { $("#id_parent").val(data[1]); if (1 == data[2] && 2 == data[3]) { /* data[2] - id of member misc status, 1 - status is active */ obj.setAllPositions(); } else { obj.setPositionsWithoutLiaison(); } } }); }, setPositions: function(positions) { var selectedOption = $('#type').val(); var select = $('#type'); var options = null; if (select.prop) { options = select.prop('options'); } else { options = select.attr('options'); } $('option', select).remove(); $.each(positions, function (val, text) { options[options.length] = new Option(text, val); }); select.val(selectedOption); }, setAllPositions: function() { this.setPositions(this.availablePositions); }, setPositionsWithoutLiaison: function() { var positions = {}; $.each(this.availablePositions, function (val, text) { positions[val] = text; }); var obj = this; $.each(positions, function(val, text) { if (val == obj.liaisonPosition) { delete positions[val]; } }); this.setPositions(positions); } } var App_AdminVolunteerMember_List = { initialize: function() { this.initGroupPositionsSelect(); }, initGroupPositionsSelect: function() { $('[id^="position-"]').change(function(){ var memberId = str_replace('position-', '', $(this).attr('id')); var select = $(this); $.post( BASE_URL + '/' + CURR_PAGE_FULL, {action: 'setPosition', memberId: memberId, position: $(this).val()}, function(data){ select.empty(); $(data).each(function(val, option) { var appendOption = $('').attr('value', option.value).text(option.title); if (option.selected) { appendOption.attr('selected', 'selected'); } select.append(appendOption); }); }, 'json' ); }); } }