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 07:57:44 +02:00
|
|
|
/**
|
|
|
|
* Stores a jQuery reference to the last submitted search form.
|
|
|
|
*/
|
|
|
|
__lastSearch = null;
|
2008-08-09 04:16:46 +02:00
|
|
|
|
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){
|
2008-08-09 08:18:32 +02:00
|
|
|
jQuery('#right #ModelAdminPanel').html(result);
|
2008-08-09 06:38:44 +02:00
|
|
|
jQuery('#SearchForm_holder').tabs();
|
|
|
|
|
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 08:18:32 +02:00
|
|
|
|
|
|
|
jQuery('#Form_EditForm_action_goBack').livequery('click', function() {
|
|
|
|
if(__lastSearch) __lastSearch.trigger('submit');
|
|
|
|
return false;
|
|
|
|
});
|
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){
|
2008-08-09 08:18:32 +02:00
|
|
|
jQuery('#right #ModelAdminPanel').html(result);
|
2008-08-11 02:14:48 +02:00
|
|
|
|
|
|
|
statusMessage("Saved");
|
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
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2008-08-11 02:21:44 +02:00
|
|
|
/**
|
|
|
|
* POST a hash of form submitted data to the given endpoint
|
|
|
|
*/
|
|
|
|
function deleteRecord(uri, data) {
|
|
|
|
jQuery.post(uri, data, function(result){
|
|
|
|
jQuery('#right #ModelAdminPanel').html(result);
|
|
|
|
|
|
|
|
statusMessage("Deleted");
|
|
|
|
|
|
|
|
// TODO/SAM: It seems a bit of a hack to have to list all the little updaters here.
|
|
|
|
// Is livequery a solution?
|
|
|
|
Behaviour.apply(); // refreshes ComplexTableField
|
|
|
|
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 07:00:42 +02:00
|
|
|
jQuery('#Form_ManagedModelsSelect').submit(function(){
|
2008-08-09 04:16:46 +02:00
|
|
|
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
|
|
|
|
*/
|
2008-08-11 02:21:44 +02:00
|
|
|
jQuery('#right #form_actions_right input[name=action_doSave]').livequery('click', function(){
|
|
|
|
var form = jQuery('#right form');
|
2008-08-09 09:03:24 +02:00
|
|
|
var formAction = form.attr('action') + '?' + jQuery(this).fieldSerialize();
|
|
|
|
saveRecord(formAction, formData(form));
|
2008-08-09 04:16:46 +02:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2008-08-11 02:21:44 +02:00
|
|
|
/**
|
|
|
|
* attach generic action handler to all forms displayed in the #right panel
|
|
|
|
*/
|
|
|
|
jQuery('#right #form_actions_right input[name=action_doDelete]').livequery('click', function(){
|
|
|
|
var confirmed = confirm("Do you really want to delete?");
|
|
|
|
if(!confirmed) return false;
|
|
|
|
|
|
|
|
var form = jQuery('#right form');
|
|
|
|
var formAction = form.attr('action') + '?' + jQuery(this).fieldSerialize();
|
|
|
|
deleteRecord(formAction, formData(form));
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2008-08-11 02:03:57 +02:00
|
|
|
jQuery('#right #ModelAdminPanel tbody td a').livequery('click', function(){
|
|
|
|
var el = jQuery(this);
|
|
|
|
showRecord(el.attr('href'));
|
|
|
|
//el.parent().parent().find('td').removeClass('active');
|
|
|
|
//el.addClass('active').siblings().addClass('active');
|
|
|
|
return false;
|
|
|
|
}).hover(function(){
|
|
|
|
jQuery(this).addClass('over').siblings().addClass('over')
|
|
|
|
}, function(){
|
|
|
|
jQuery(this).removeClass('over').siblings().removeClass('over')
|
|
|
|
});
|
|
|
|
|
2008-08-09 05:54:55 +02:00
|
|
|
/**
|
2008-08-09 07:57:44 +02:00
|
|
|
* Attach tabs plugin to the set of search filter and edit forms
|
2008-08-09 05:54:55 +02:00
|
|
|
*/
|
2008-08-09 07:57:44 +02:00
|
|
|
jQuery('ul.tabstrip').tabs();
|
2008-08-09 04:16:46 +02:00
|
|
|
|
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 07:00:42 +02:00
|
|
|
jQuery('#SearchForm_holder .tab form').submit(function(){
|
2008-08-09 07:57:44 +02:00
|
|
|
__lastSearch = jQuery(this);
|
|
|
|
|
2008-08-09 04:16:46 +02:00
|
|
|
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){
|
2008-08-09 08:18:32 +02:00
|
|
|
jQuery('#right #ModelAdminPanel').html(result);
|
2008-08-11 01:17:51 +02:00
|
|
|
|
|
|
|
Behaviour.apply();
|
2008-08-09 04:16:46 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2008-08-11 01:29:30 +02:00
|
|
|
/**
|
|
|
|
* Toggle import specifications
|
|
|
|
*/
|
|
|
|
jQuery('#Form_ImportForm_holder .spec .details').hide();
|
|
|
|
jQuery('#Form_ImportForm_holder .spec a.detailsLink').click(function() {
|
|
|
|
jQuery('#' + jQuery(this).attr('href').replace(/.*#/,'')).toggle();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2008-08-11 02:21:44 +02:00
|
|
|
jQuery('#SearchForm_holder button[name=action_clearsearch]').click(function(e) {
|
|
|
|
jQuery(this.form).clearForm();
|
2008-08-11 02:03:57 +02:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
jQuery('a.form_frontend_function.toggle_result_assembly').click(function(){
|
|
|
|
var toggleElement = jQuery(this).next();
|
2008-08-11 02:21:44 +02:00
|
|
|
toggleElement.toggle();
|
2008-08-11 02:03:57 +02:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
jQuery('a.form_frontend_function.tick_all_result_assembly').click(function(){
|
|
|
|
var resultAssembly = jQuery('div#ResultAssembly ul li input');
|
|
|
|
resultAssembly.attr('checked', 'checked');
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
jQuery('a.form_frontend_function.untick_all_result_assembly').click(function(){
|
|
|
|
var resultAssembly = jQuery('div#ResultAssembly ul li input');
|
|
|
|
resultAssembly.removeAttr('checked');
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2008-08-09 07:00:42 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @todo Terrible HACK, but thats the cms UI...
|
|
|
|
*/
|
|
|
|
function fixHeight_left() {
|
|
|
|
fitToParent('LeftPane');
|
|
|
|
fitToParent('Search_holder',12);
|
|
|
|
fitToParent('ResultTable_holder',12);
|
2008-08-09 08:29:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function prepareAjaxActions(actions, formName, tabName) {
|
|
|
|
// @todo HACK Overwrites LeftAndMain.js version of this method to avoid double form actions
|
|
|
|
// (by new jQuery and legacy prototype)
|
|
|
|
return false;
|
2008-08-09 07:00:42 +02:00
|
|
|
}
|