// todo: make this more Prototype-ish: // * new function syntax // * maybe objectify this all // default search when the window loads Event.observe(window, 'load', function() { ajax_search_fellowships(); $('status').hide(); $('search_keywords').focus(); }); function ajax_search_fellowships() { ajax_get_fellowships(true); } function ajax_sort_results(sort_item) { if( sort_item != $F('search_order_by') && $F('search_order_by') != '') { var new_sort_item = true; } if( $F('search_order_asc_desc') == 'desc' || new_sort_item ) { $('search_order_asc_desc').value = 'asc'; } else { $('search_order_asc_desc').value = 'desc'; } $('search_order_by').value = sort_item; ajax_get_fellowships(false); } // uses 'get' because it doesn't change any data function ajax_get_fellowships(highlight_option) { new Ajax.Updater('results','http://www.college.columbia.edu/students/fellowships/catalog/ajax/get_search_results.php', { parameters: { keywords: $F('search_keywords'), year: $F('search_year'), discipline: $F('search_discipline'), order_by: $F('search_order_by'), order_asc_desc: $F('search_order_asc_desc'), session_id: $F('session_id')}, method:'get', onComplete:function() { if(highlight_option) { new Effect.Highlight('results', {duration: 0.5}); } } }); } // uses 'get' because it doesn't change any data function ajax_edit_fellowship(fellowship_id, session_id) { if(! fellowship_id) { var fellowship_id = ''; } var url = 'http://www.college.columbia.edu/students/fellowships/catalog/ajax/edit_fellowship_details.php'; new Ajax.Updater('results',url, { parameters: { fellowship_id: fellowship_id, session_id: session_id}, method:'get', onComplete:function() { new Effect.Highlight('results', {duration: 0.5}); } }); } // uses 'get' because it doesn't change any data function ajax_get_fellowship(fellowship_id, session_id) { if(! fellowship_id) { var fellowship_id = ''; } var url = 'http://www.college.columbia.edu/students/fellowships/catalog/ajax/get_fellowship_details.php'; new Ajax.Updater('results',url, { parameters: { fellowship_id: fellowship_id, session_id: session_id}, method:'get', onComplete:function() { new Effect.Highlight('results', {duration: 0.5}); } }); } // uses 'post' because it changes data function ajax_save_fellowship(fellowship_id, session_id) { if(! fellowship_id) { fellowship_id = ''; } var url = 'http://www.college.columbia.edu/students/fellowships/catalog/ajax/save_fellowship_details.php'; // debug new Ajax.Updater('results', url, { parameters: { fellowship_id: fellowship_id, session_id: session_id, name: $F('name'), years: $F('years').join(','), deadline: $F('deadline'), disciplines: $F('disciplines').join(','), geographic: $F('geographic'), contact: $F('contact'), description: $F('description'), application_url: $F('application_url') }, method:'post', onComplete:function() { show_status('Saved fellowship.'); } }); } // uses 'get' because it doesn't change any data function ajax_get_last_id() { text = new Ajax.Request('http://www.college.columbia.edu/students/fellowships/catalog/ajax/get_last_fellowship_id.php', { method: 'get', onComplete: function(transport) { $('last_id').value = transport.responseText; } }); } // uses 'post' because it changes data function ajax_delete_fellowship(fellowship_id, session_id) { confirmation = confirm('Are you sure you want to delete this fellowship?'); if(! confirmation) return false; if(! fellowship_id) { fellowship_id = ''; } var url = 'http://www.college.columbia.edu/students/fellowships/catalog/ajax/delete_fellowship.php'; new Ajax.Updater('results',url, { parameters: { fellowship_id: fellowship_id, session_id: session_id }, method:'post', onComplete:function() { ajax_search_fellowships(); show_status('Deleted fellowship.'); } }); } function show_status(message) { $('status').update(message); Effect.Appear('status', { queue:'front' }); Effect.Fade('status', { delay: 3, queue:'end' }); }