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($) {
|
2010-04-13 07:55:56 +02:00
|
|
|
$.entwine('ss', function($){
|
2009-11-21 04:19:59 +01:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Search form
|
|
|
|
//////////////////////////////////////////////////////////////////
|
2008-09-13 06:45:30 +02:00
|
|
|
|
2009-11-21 04:19:59 +01:00
|
|
|
/**
|
|
|
|
* If a dropdown is used to choose between the classes, it is handled by this code
|
|
|
|
*/
|
2010-04-13 07:55:56 +02:00
|
|
|
$('#ModelClassSelector select').entwine({
|
2009-11-21 04:19:59 +01:00
|
|
|
onmatch: function() {
|
|
|
|
// Initialise the form by calling this onchange event straight away
|
|
|
|
this.change();
|
|
|
|
|
|
|
|
this._super();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set up an onchange function to show the applicable form and hide all others
|
|
|
|
*/
|
|
|
|
onchange: function(e) {
|
|
|
|
this.find('option').each(function() {
|
|
|
|
var $form = $('#'+this.val());
|
|
|
|
if(this.val() == this.val()) $form.show();
|
2009-11-21 04:17:34 +01:00
|
|
|
else $form.hide();
|
|
|
|
});
|
2009-11-21 04:19:59 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
/**
|
|
|
|
* Submits a search filter query and attaches event handlers
|
|
|
|
* to the response table, excluding the import form because
|
|
|
|
* file ($_FILES) submission doesn't work using AJAX
|
|
|
|
*
|
|
|
|
* Note: This is used for Form_CreateForm and all Form_SearchForm_* variations
|
|
|
|
*/
|
2010-04-13 07:55:56 +02:00
|
|
|
$('#SearchForm_holder form').entwine({
|
2009-11-21 04:19:59 +01:00
|
|
|
onsubmit: function(e) {
|
2009-11-21 04:17:34 +01:00
|
|
|
// Import forms are processed without ajax
|
2009-11-21 04:19:59 +01:00
|
|
|
if(this.is('#Form_ImportForm')) return true;
|
|
|
|
|
|
|
|
this.trigger('beforeSubmit');
|
2009-11-21 04:17:34 +01:00
|
|
|
|
2009-11-21 04:19:59 +01:00
|
|
|
var btn = $(this[0].clickedButton);
|
2009-11-21 04:17:44 +01:00
|
|
|
btn.addClass('loading');
|
|
|
|
|
2009-11-21 04:19:59 +01:00
|
|
|
$('#Form_EditForm').loadForm(
|
|
|
|
this.attr('action'),
|
2009-11-21 04:17:44 +01:00
|
|
|
function() {
|
|
|
|
btn.removeClass('loading');
|
|
|
|
},
|
2009-11-21 04:19:59 +01:00
|
|
|
{data: this.serialize()}
|
2009-11-21 04:17:34 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
return false;
|
2009-11-21 04:19:59 +01:00
|
|
|
}
|
|
|
|
});
|
2008-09-12 01:18:21 +02:00
|
|
|
|
2009-11-21 04:19:59 +01:00
|
|
|
/**
|
|
|
|
* Column selection in search form
|
|
|
|
*/
|
2010-04-13 07:55:56 +02:00
|
|
|
$('a.form_frontend_function.toggle_result_assembly').entwine({
|
2009-11-21 04:19:59 +01:00
|
|
|
onclick: function(e) {
|
|
|
|
var toggleElement = $(this).next();
|
|
|
|
toggleElement.toggle();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2008-09-12 01:18:21 +02:00
|
|
|
|
2010-04-13 07:55:56 +02:00
|
|
|
$('a.form_frontend_function.tick_all_result_assembly').entwine({
|
2009-11-21 04:19:59 +01:00
|
|
|
onclick: function(e) {
|
|
|
|
var resultAssembly = $(this).prevAll('div#ResultAssembly').find('ul li input');
|
|
|
|
resultAssembly.attr('checked', 'checked');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2008-09-12 01:18:21 +02:00
|
|
|
|
2010-04-13 07:55:56 +02:00
|
|
|
$('a.form_frontend_function.untick_all_result_assembly').entwine({
|
2009-11-21 04:19:59 +01:00
|
|
|
onclick: function(e) {
|
|
|
|
var resultAssembly = $(this).prevAll('div#ResultAssembly').find('ul li input');
|
|
|
|
resultAssembly.removeAttr('checked');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2008-11-18 00:03:39 +01:00
|
|
|
|
2009-11-21 04:19:59 +01:00
|
|
|
/**
|
|
|
|
* Table record handler for search result record
|
|
|
|
*/
|
2010-04-13 07:55:56 +02:00
|
|
|
$('.resultsTable tbody td').entwine({
|
2009-11-21 04:19:59 +01:00
|
|
|
onclick: function(e) {
|
|
|
|
var firstLink = this.find('a[href]');
|
2009-11-21 04:17:49 +01:00
|
|
|
if(!firstLink) return;
|
2009-11-21 04:19:59 +01:00
|
|
|
$('#Form_EditForm').loadForm(firstLink.attr('href'));
|
2009-11-21 04:17:34 +01:00
|
|
|
return false;
|
2009-11-21 04:19:59 +01:00
|
|
|
}
|
|
|
|
});
|
2008-09-12 01:18:21 +02:00
|
|
|
|
2009-11-21 04:19:59 +01:00
|
|
|
/**
|
|
|
|
* Add object button
|
|
|
|
*/
|
2010-04-13 07:55:56 +02:00
|
|
|
$('#Form_ManagedModelsSelect').entwine({
|
2009-11-21 04:19:59 +01:00
|
|
|
onsubmit: function(e) {
|
2009-11-21 04:17:34 +01:00
|
|
|
className = $('select option:selected', this).val();
|
2009-11-21 04:19:59 +01:00
|
|
|
requestPath = this.attr('action').replace('ManagedModelsSelect', className + '/add');
|
2009-11-21 04:17:34 +01:00
|
|
|
var $button = $(':submit', this);
|
2009-11-21 04:19:59 +01:00
|
|
|
$('#Form_EditForm').loadForm(
|
2009-11-21 04:17:34 +01:00
|
|
|
requestPath,
|
|
|
|
function() {
|
|
|
|
$button.removeClass('loading');
|
|
|
|
$button = null;
|
|
|
|
}
|
|
|
|
);
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:17:34 +01:00
|
|
|
return false;
|
2009-11-21 04:19:59 +01:00
|
|
|
}
|
|
|
|
});
|
2008-08-09 04:16:46 +02:00
|
|
|
|
2009-11-21 04:19:59 +01:00
|
|
|
/**
|
|
|
|
* RHS panel Delete button
|
|
|
|
*/
|
2010-04-13 07:55:56 +02:00
|
|
|
$('#Form_EditForm input[name=action_doDelete]').entwine({
|
2009-11-21 04:19:59 +01:00
|
|
|
onclick: function(e) {
|
|
|
|
if(!confirm(ss.i18n._t('ModelAdmin.REALLYDELETE', 'Really delete?'))) {
|
|
|
|
this.removeClass('loading');
|
2009-11-21 04:17:34 +01:00
|
|
|
return false;
|
2009-11-21 04:17:13 +01:00
|
|
|
}
|
2009-11-21 04:19:59 +01:00
|
|
|
}
|
|
|
|
});
|
2008-09-12 03:50:08 +02:00
|
|
|
|
2009-11-21 04:19:59 +01:00
|
|
|
/**
|
|
|
|
* Toggle import specifications
|
|
|
|
*/
|
2010-04-13 07:55:56 +02:00
|
|
|
$('.importSpec').entwine({
|
2009-11-21 04:19:59 +01:00
|
|
|
onmatch: function() {
|
|
|
|
this.hide();
|
|
|
|
this.find('a.detailsLink').click(function() {
|
|
|
|
$('#' + $(this).attr('href').replace(/.*#/,'')).toggle();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
this._super();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2009-11-21 04:17:34 +01:00
|
|
|
});
|
2009-11-21 03:37:30 +01:00
|
|
|
})(jQuery);
|