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-09-13 06:45:30 +02:00
|
|
|
(function($) {
|
|
|
|
$(document).ready(function() {
|
2008-09-12 01:18:21 +02:00
|
|
|
/**
|
|
|
|
* Attach tabs plugin to the set of search filter and edit forms
|
|
|
|
*/
|
2008-09-13 08:19:17 +02:00
|
|
|
$('ul.tabstrip').livequery(function() {
|
|
|
|
$(this).tabs();
|
|
|
|
});
|
2008-09-13 06:45:30 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Highlight buttons on click
|
|
|
|
*/
|
2008-09-13 08:19:17 +02:00
|
|
|
$('input[type=submit]').livequery('click', function() {
|
2008-09-13 06:45:30 +02:00
|
|
|
$(this).addClass('loading');
|
|
|
|
});
|
2008-09-12 01:18:21 +02:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Search form
|
|
|
|
//////////////////////////////////////////////////////////////////
|
2008-09-13 06:45:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If a dropdown is used to choose between the classes, it is handled by this code
|
|
|
|
*/
|
|
|
|
$('#ModelClassSelector select')
|
|
|
|
// Set up an onchange function to show the applicable form and hide all others
|
|
|
|
.change(function() {
|
|
|
|
var $selector = $(this);
|
|
|
|
$('option', this).each(function() {
|
|
|
|
var $form = $('#'+$(this).val());
|
|
|
|
if($selector.val() == $(this).val()) $form.show();
|
|
|
|
else $form.hide();
|
|
|
|
});
|
|
|
|
})
|
|
|
|
// Initialise the form by calling this onchange event straight away
|
|
|
|
.change();
|
2008-09-12 01:18:21 +02:00
|
|
|
|
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
|
|
|
/**
|
2008-09-12 01:18:21 +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 05:54:55 +02:00
|
|
|
*/
|
2008-09-13 06:45:30 +02:00
|
|
|
$('#SearchForm_holder .tab form').submit(function () {
|
|
|
|
var $form = $(this);
|
|
|
|
$('#ModelAdminPanel').load($(this).attr('action'), $(this).formToArray(), standardStatusHandler(function(result) {
|
|
|
|
__lastSearch = $form;
|
|
|
|
$('#form_actions_right').remove();
|
|
|
|
Behaviour.apply();
|
|
|
|
// Remove the loading indicators from the buttons
|
|
|
|
$('input[type=submit]', $form).removeClass('loading');
|
|
|
|
},
|
|
|
|
// Failure handler - we should still remove loading indicator
|
|
|
|
function () {
|
|
|
|
$('input[type=submit]', $form).removeClass('loading');
|
|
|
|
}));
|
|
|
|
return false;
|
2008-09-12 01:18:21 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear search button
|
|
|
|
*/
|
2008-09-13 06:45:30 +02:00
|
|
|
$('#SearchForm_holder button[name=action_clearsearch]').click(function(e) {
|
|
|
|
$(this.form).clearForm();
|
2008-09-12 01:18:21 +02:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Column selection in search form
|
|
|
|
*/
|
2008-09-13 06:45:30 +02:00
|
|
|
$('a.form_frontend_function.toggle_result_assembly').click(function(){
|
|
|
|
var toggleElement = $(this).next();
|
2008-09-12 01:18:21 +02:00
|
|
|
toggleElement.toggle();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2008-09-13 06:45:30 +02:00
|
|
|
$('a.form_frontend_function.tick_all_result_assembly').click(function(){
|
|
|
|
var resultAssembly = $('div#ResultAssembly ul li input');
|
2008-09-12 01:18:21 +02:00
|
|
|
resultAssembly.attr('checked', 'checked');
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2008-09-13 06:45:30 +02:00
|
|
|
$('a.form_frontend_function.untick_all_result_assembly').click(function(){
|
|
|
|
var resultAssembly = $('div#ResultAssembly ul li input');
|
2008-09-12 01:18:21 +02:00
|
|
|
resultAssembly.removeAttr('checked');
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Results list
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Table record handler for search result record
|
2008-09-13 08:19:17 +02:00
|
|
|
* @todo: Shouldn't this be part of TableListField?
|
2008-09-12 01:18:21 +02:00
|
|
|
*/
|
2008-09-13 06:45:30 +02:00
|
|
|
$('#right #Form_ResultsForm tbody td a')
|
2008-09-12 01:18:21 +02:00
|
|
|
.livequery('click', function(){
|
2008-09-13 06:45:30 +02:00
|
|
|
$(this).parent().parent().addClass('loading');
|
|
|
|
var el = $(this);
|
2008-09-13 08:19:17 +02:00
|
|
|
$('#ModelAdminPanel').fn('loadForm', el.attr('href'));
|
2008-09-12 01:18:21 +02:00
|
|
|
return false;
|
2008-09-13 08:19:17 +02:00
|
|
|
});
|
|
|
|
/* this isn't being used currently; the real hover code is part of TableListField
|
2008-09-12 01:18:21 +02:00
|
|
|
.hover(
|
|
|
|
function(){
|
2008-09-13 06:45:30 +02:00
|
|
|
$(this).addClass('over').siblings().addClass('over')
|
2008-09-12 01:18:21 +02:00
|
|
|
},
|
|
|
|
function(){
|
2008-09-13 06:45:30 +02:00
|
|
|
$(this).removeClass('over').siblings().removeClass('over')
|
2008-09-12 01:18:21 +02:00
|
|
|
}
|
|
|
|
);
|
2008-09-13 08:19:17 +02:00
|
|
|
*/
|
2008-08-09 08:18:32 +02:00
|
|
|
|
2008-09-12 01:18:21 +02:00
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// RHS detail form
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RHS panel Back button
|
|
|
|
*/
|
2008-09-13 06:45:30 +02:00
|
|
|
$('#Form_EditForm_action_goBack').livequery('click', function() {
|
2008-08-09 08:18:32 +02:00
|
|
|
if(__lastSearch) __lastSearch.trigger('submit');
|
|
|
|
return false;
|
|
|
|
});
|
2008-08-09 04:16:46 +02:00
|
|
|
|
2008-08-09 05:54:55 +02:00
|
|
|
/**
|
2008-09-12 01:18:21 +02:00
|
|
|
* RHS panel Save button
|
2008-08-09 05:54:55 +02:00
|
|
|
*/
|
2008-09-13 06:45:30 +02:00
|
|
|
$('#right #form_actions_right input[name=action_doSave]').livequery('click', function(){
|
|
|
|
var form = $('#right form');
|
|
|
|
var formAction = form.attr('action') + '?' + $(this).fieldSerialize();
|
2008-09-12 01:18:21 +02:00
|
|
|
|
|
|
|
// Post the data to save
|
2008-09-13 08:19:17 +02:00
|
|
|
$.post(formAction, form.formToArray(), function(result){
|
2008-09-13 06:45:30 +02:00
|
|
|
$('#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 05:54:55 +02:00
|
|
|
});
|
2008-09-12 01:18:21 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
2008-08-09 05:54:55 +02:00
|
|
|
|
2008-08-11 02:21:44 +02:00
|
|
|
/**
|
2008-09-12 01:18:21 +02:00
|
|
|
* RHS panel Delete button
|
2008-08-11 02:21:44 +02:00
|
|
|
*/
|
2008-09-13 06:45:30 +02:00
|
|
|
$('#right #form_actions_right input[name=action_doDelete]').livequery('click', function(){
|
2008-09-12 01:18:21 +02:00
|
|
|
var confirmed = confirm("Do you really want to delete?");
|
|
|
|
if(!confirmed) return false;
|
2008-09-13 08:19:17 +02:00
|
|
|
|
2008-09-13 06:45:30 +02:00
|
|
|
var form = $('#right form');
|
|
|
|
var formAction = form.attr('action') + '?' + $(this).fieldSerialize();
|
2008-09-12 01:18:21 +02:00
|
|
|
|
|
|
|
// The POST actually handles the delete
|
2008-09-13 08:19:17 +02:00
|
|
|
$.post(formAction, form.formToArray(), function(result){
|
2008-09-12 01:18:21 +02:00
|
|
|
// On success, the panel is refreshed and a status message shown.
|
2008-09-13 06:45:30 +02:00
|
|
|
$('#right #ModelAdminPanel').html(result);
|
2008-08-11 02:21:44 +02:00
|
|
|
|
|
|
|
statusMessage("Deleted");
|
2008-09-13 06:45:30 +02:00
|
|
|
$('#form_actions_right').remove();
|
2008-09-13 08:19:17 +02:00
|
|
|
|
|
|
|
// To do - convert everything to jQuery so that this isn't needed
|
2008-08-11 02:21:44 +02:00
|
|
|
Behaviour.apply(); // refreshes ComplexTableField
|
|
|
|
});
|
2008-09-12 01:18:21 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Import/Add form
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
2008-08-09 05:54:55 +02:00
|
|
|
/**
|
2008-09-12 01:18:21 +02:00
|
|
|
* Add object button
|
2008-08-09 05:54:55 +02:00
|
|
|
*/
|
2008-09-13 06:45:30 +02:00
|
|
|
$('#Form_ManagedModelsSelect').submit(function(){
|
|
|
|
className = $('select option:selected', this).val();
|
|
|
|
requestPath = $(this).attr('action').replace('ManagedModelsSelect', className + '/add');
|
2008-09-13 08:19:17 +02:00
|
|
|
$('#ModelAdminPanel').fn('loadForm', requestPath);
|
2008-09-18 23:25:49 +02:00
|
|
|
$('#form_actions_right').remove();
|
2008-08-09 04:16:46 +02:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2008-08-09 05:54:55 +02:00
|
|
|
/**
|
2008-09-12 01:18:21 +02:00
|
|
|
* Toggle import specifications
|
2008-08-11 02:21:44 +02:00
|
|
|
*/
|
2008-09-13 06:45:30 +02:00
|
|
|
$('#Form_ImportForm_holder .spec .details').hide();
|
|
|
|
$('#Form_ImportForm_holder .spec a.detailsLink').click(function() {
|
|
|
|
$('#' + $(this).attr('href').replace(/.*#/,'')).toggle();
|
2008-08-11 02:03:57 +02:00
|
|
|
return false;
|
|
|
|
});
|
2008-09-12 01:18:21 +02:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Helper functions
|
|
|
|
//////////////////////////////////////////////////////////////////
|
2008-08-09 04:16:46 +02:00
|
|
|
|
2008-09-13 08:19:17 +02:00
|
|
|
$('#ModelAdminPanel').fn({
|
|
|
|
/**
|
|
|
|
* Load a detail editing form into the main edit panel
|
|
|
|
* @todo Convert everything to jQuery so that the built-in load method can be used with this instead
|
|
|
|
*/
|
|
|
|
loadForm: function(url) {
|
|
|
|
$('#right #ModelAdminPanel').load(url, standardStatusHandler(function(result) {
|
|
|
|
Behaviour.apply(); // refreshes ComplexTableField
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
});
|
2008-09-12 03:50:08 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Standard SilverStripe status handler for ajax responses
|
|
|
|
* It will generate a status message out of the response, and only call the callback for successful responses
|
|
|
|
*
|
|
|
|
* To use:
|
|
|
|
* Instead of passing your callback function as:
|
|
|
|
* function(response) { ... }
|
|
|
|
*
|
|
|
|
* Pass it as this:
|
|
|
|
* standardStatusHandler(function(response) { ... })
|
|
|
|
*/
|
2008-09-13 06:45:30 +02:00
|
|
|
function standardStatusHandler(callback, failureCallback) {
|
2008-09-12 03:50:08 +02:00
|
|
|
return function(response, status, xhr) {
|
2008-09-13 06:45:30 +02:00
|
|
|
// If the response is takne from $.ajax's complete handler, then swap the variables around
|
|
|
|
if(response.status) {
|
|
|
|
xhr = response;
|
|
|
|
response = xhr.responseText;
|
|
|
|
}
|
|
|
|
|
2008-09-12 03:50:08 +02:00
|
|
|
if(status == 'success') {
|
|
|
|
statusMessage(xhr.statusText, "good");
|
2008-09-13 06:45:30 +02:00
|
|
|
$(this).each(callback, [response, status, xhr]);
|
2008-09-12 03:50:08 +02:00
|
|
|
} else {
|
|
|
|
statusMessage(xhr.statusText, "bad");
|
2008-09-13 06:45:30 +02:00
|
|
|
if(failureCallback) $(this).each(failureCallback, [response, status, xhr]);
|
2008-09-12 03:50:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-13 06:45:30 +02:00
|
|
|
})
|
|
|
|
})(jQuery);
|
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
|
|
|
}
|