2008-08-09 05:54:55 +02:00
|
|
|
/**
|
|
|
|
* Javascript handlers for generic model admin.
|
|
|
|
*
|
|
|
|
* Most of the work being done here is intercepting clicks on form submits,
|
|
|
|
* and managing the loading and sequencing of data between the different panels of
|
|
|
|
* the CMS interface.
|
|
|
|
*
|
|
|
|
* @todo add live query to manage application of events to DOM refreshes
|
|
|
|
* @todo alias the $ function instead of literal jQuery
|
|
|
|
*/
|
2008-08-09 04:16:46 +02:00
|
|
|
jQuery(document).ready(function() {
|
|
|
|
|
2008-08-09 05:54:55 +02:00
|
|
|
/**
|
|
|
|
* GET a fragment of HTML to display in the right panel
|
|
|
|
*/
|
2008-08-09 04:16:46 +02:00
|
|
|
function showRecord(uri) {
|
|
|
|
jQuery.get(uri, function(result){
|
|
|
|
jQuery('#right').html(result);
|
2008-08-09 06:38:44 +02:00
|
|
|
jQuery('#SearchForm_holder').tabs();
|
|
|
|
|
|
|
|
// TODO/SAM: It seems a bit of a hack to have to list all the little updaters here.
|
|
|
|
// Is livequery a solution?
|
2008-08-09 05:54:55 +02:00
|
|
|
Behaviour.apply(); // refreshes ComplexTableField
|
2008-08-09 06:38:44 +02:00
|
|
|
jQuery('#right ul.tabstrip').tabs();
|
2008-08-09 04:16:46 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2008-08-09 05:54:55 +02:00
|
|
|
/**
|
|
|
|
* POST a hash of form submitted data to the given endpoint
|
|
|
|
*/
|
2008-08-09 04:16:46 +02:00
|
|
|
function saveRecord(uri, data) {
|
2008-08-09 05:54:55 +02:00
|
|
|
jQuery.post(uri, data, function(result){
|
|
|
|
jQuery('#right').html(result);
|
2008-08-09 06:38:44 +02:00
|
|
|
|
|
|
|
// TODO/SAM: It seems a bit of a hack to have to list all the little updaters here.
|
|
|
|
// Is livequery a solution?
|
2008-08-09 06:06:52 +02:00
|
|
|
Behaviour.apply(); // refreshes ComplexTableField
|
2008-08-09 06:38:44 +02:00
|
|
|
jQuery('#right ul.tabstrip').tabs();
|
2008-08-09 05:54:55 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a flattened array of data from each field
|
|
|
|
* of the given form
|
|
|
|
*/
|
|
|
|
function formData(scope) {
|
|
|
|
var data = {};
|
|
|
|
jQuery('*[name]', scope).each(function(){
|
|
|
|
var t = jQuery(this);
|
|
|
|
var val = (t.attr('type') == 'checkbox') ? (t.attr('checked') == true) ? 1 : 0 : t.val();
|
|
|
|
data[t.attr('name')] = val;
|
|
|
|
});
|
|
|
|
return data;
|
2008-08-09 04:16:46 +02:00
|
|
|
}
|
|
|
|
|
2008-08-09 05:54:55 +02:00
|
|
|
/**
|
|
|
|
* Find the selected data object and load its create form
|
|
|
|
*/
|
2008-08-09 04:16:46 +02:00
|
|
|
jQuery('#AddForm_holder form').submit(function(){
|
|
|
|
className = jQuery('select option:selected', this).val();
|
2008-08-09 05:54:55 +02:00
|
|
|
requestPath = jQuery(this).attr('action').replace('ManagedModelsSelect', className + '/add');
|
2008-08-09 04:16:46 +02:00
|
|
|
showRecord(requestPath);
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2008-08-09 05:54:55 +02:00
|
|
|
/**
|
|
|
|
* attach generic action handler to all forms displayed in the #right panel
|
|
|
|
*/
|
|
|
|
jQuery('#right .action').livequery('click', function(){
|
|
|
|
form = jQuery('#right form');
|
|
|
|
saveRecord(form.attr('action'), formData(form));
|
2008-08-09 04:16:46 +02:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2008-08-09 05:54:55 +02:00
|
|
|
/**
|
|
|
|
* Attach tabs plugin to the set of search filter forms
|
|
|
|
*/
|
2008-08-09 04:16:46 +02:00
|
|
|
jQuery('#SearchForm_holder').tabs();
|
|
|
|
|
2008-08-09 05:54:55 +02:00
|
|
|
/**
|
|
|
|
* Submits a search filter query and attaches event handlers
|
|
|
|
* to the response table
|
|
|
|
*
|
|
|
|
* @todo use livequery to manage ResultTable click handlers
|
|
|
|
*/
|
2008-08-09 04:16:46 +02:00
|
|
|
jQuery('.tab form').submit(function(){
|
|
|
|
form = jQuery(this);
|
2008-08-09 05:54:55 +02:00
|
|
|
data = formData(form);
|
2008-08-09 04:16:46 +02:00
|
|
|
jQuery.get(form.attr('action'), data, function(result){
|
|
|
|
jQuery('#ResultTable_holder').html(result);
|
|
|
|
jQuery('#ResultTable_holder td').click(function(){
|
|
|
|
td = jQuery(this);
|
2008-08-09 05:54:55 +02:00
|
|
|
showRecord(td.parent().attr('title'));
|
2008-08-09 04:16:46 +02:00
|
|
|
td.parent().parent().find('td').removeClass('active');
|
|
|
|
td.addClass('active').siblings().addClass('active');
|
|
|
|
}).hover(function(){
|
|
|
|
jQuery(this).addClass('over').siblings().addClass('over')
|
|
|
|
}, function(){
|
|
|
|
jQuery(this).removeClass('over').siblings().removeClass('over')
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|