var App_AdminMemberSearch_Form = { chosenSavedSearchId: '', chooseAnySavedSearchMsg: 'Please, choose any saved search', initialize:function () { $('#btnSavedSearchSelected').click(function () { App_AdminMemberSearch_Form.doSearch(); }); $('[name="btnSavedSearchSave"]').click(App_AdminMemberSearch_Form.setSavedSearch); $('#btnSavedSearchDelete').click(function () { App_AdminMemberSearch_Form.deleteSavedSearch() }); $('#saved_search_id').change(function(){ App_AdminMemberSearch_Form.getSavedSearch() }); }, doSearch: function() { $('form#form_search_member [name="submit"]:first').click(); }, getSavedSearch: function() { App_AdminMemberSearch_Form.chosenSavedSearchId = $('#saved_search_id').val(); if (empty(App_AdminMemberSearch_Form.chosenSavedSearchId)) { return false; } $.ajax({ url: BASE_URL + '/' + CURR_PAGE, type: 'POST', data: {action:'getSavedSearch', id:App_AdminMemberSearch_Form.chosenSavedSearchId}, dataType: 'json', success: function (data) { if (!empty(data.formHtml)) { App_AdminMemberSearch_Form.setFormHtml(data.formHtml); } App_AdminMemberSearch_Form.setFormValues(data.data); return false; } }); return false; }, setFormHtml: function(formHtml) { $('#filter_form_content').html(formHtml); initMemberSearchForm(); $('#show').click(); }, setFormValues: function(data) { $('#form_search_member').deserialize(data, true); /* after deserialize we need to reset value of savedSearch select (because it was broken by deserialization) */ $('#saved_search_id').val(App_AdminMemberSearch_Form.chosenSavedSearchId); /* init upper select onchange function */ $('#form_search_member select[name=search_type]').change(); /* init multiselect disabling/enabling */ $('#form_search_member input[type="checkbox"][id^="all_"]').each(function(){ $(this).change(); }); }, setSavedSearch: function (msg) { if (!(!empty(msg) && is_string(msg))) { msg = 'Please enter the name for a new search:'; } var savedSearchName = prompt(msg, ''); if (null == savedSearchName) { /* admin press 'Cancel' */ return false; } if (empty(savedSearchName)) { /* admin entered empty name */ App_AdminMemberSearch_Form.setSavedSearch(); return false; } $.ajax({ url: BASE_URL + '/' + CURR_PAGE, type: 'POST', data: { action:'saveSearch', name:savedSearchName, formData:$('form#form_search_member').serialize() }, dataType: 'json', success: function (data) { if (data.ok) { App_AdminMemberSearch_Form.updateSavedSearchList(data.data); $("select#saved_search_id option").each(function () { this.selected = (this.text == savedSearchName); }); } else { App_AdminMemberSearch_Form.setSavedSearch(data.message); } return false; } }); return false; }, deleteSavedSearch: function() { if (empty($('#saved_search_id').val())) { alert(App_AdminMemberSearch_Form.chooseAnySavedSearchMsg); return false; } var result = confirm('Are you sure you would like to delete ' + $('#saved_search_id :selected').text() + '?'); if (!result) { return false; } $.ajax({ url: BASE_URL + '/' + CURR_PAGE, type: 'POST', data: {action:'deleteSearch', id:$('#saved_search_id').val()}, dataType: 'json', success: function (data) { App_AdminMemberSearch_Form.updateSavedSearchList(data); return false; } }); return false; }, updateSavedSearchList: function(data) { Form_Element_Select.setOptions( document.getElementById('form_saved_search').saved_search_id, data, '', 'Select Saved Search' ); } }