2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* File: ModelAdmin.js
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
(function($) {
|
|
|
|
$.entwine('ss', function($){
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Search form
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class: #ModelClassSelector select
|
|
|
|
*
|
|
|
|
* If a dropdown is used to choose between the classes, it is handled by this code
|
|
|
|
*/
|
|
|
|
$('#ModelClassSelector select').entwine({
|
|
|
|
onmatch: function() {
|
|
|
|
// Initialise the form by calling this onchange event straight away
|
|
|
|
this.change();
|
|
|
|
|
|
|
|
this._super();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function: onchange
|
|
|
|
*
|
|
|
|
* Set up an onchange function to show the applicable form and hide all others
|
|
|
|
*/
|
|
|
|
onchange: function(e) {
|
2011-12-02 10:53:59 +01:00
|
|
|
var self = this;
|
2011-03-23 10:51:00 +01:00
|
|
|
this.find('option').each(function() {
|
2011-12-02 10:53:59 +01:00
|
|
|
var val = $(this).attr('value');
|
|
|
|
$('#' + val)[(val == $(self).val()) ? 'show' : 'hide']();
|
2011-03-23 10:51:00 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class: #SearchForm_holder form
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
$('#SearchForm_holder form').entwine({
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function: onsubmit
|
|
|
|
*/
|
|
|
|
onsubmit: function(e) {
|
|
|
|
// Import forms are processed without ajax
|
|
|
|
if(this.attr('id').match(/^Form_ImportForm/)) return true;
|
|
|
|
|
2011-04-15 01:25:47 +02:00
|
|
|
$('.cms-editor-dialogs').closeRightPanel();
|
2011-03-23 10:51:00 +01:00
|
|
|
|
|
|
|
this.trigger('beforeSubmit');
|
|
|
|
|
|
|
|
var btn = $(this[0].clickedButton);
|
|
|
|
btn.addClass('loading');
|
|
|
|
|
2011-06-08 01:35:56 +02:00
|
|
|
$('.cms-content').loadForm(
|
2011-03-23 10:51:00 +01:00
|
|
|
this.attr('action'),
|
2011-06-08 01:35:56 +02:00
|
|
|
null,
|
2011-03-23 10:51:00 +01:00
|
|
|
function() {
|
|
|
|
btn.removeClass('loading');
|
|
|
|
},
|
|
|
|
{data: this.serialize()}
|
|
|
|
);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class: a.form_frontend_function.toggle_result_assembly
|
|
|
|
*
|
|
|
|
* Column selection in search form
|
|
|
|
*/
|
|
|
|
$('a.form_frontend_function.toggle_result_assembly').entwine({
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function: onclick
|
|
|
|
*/
|
|
|
|
onclick: function(e) {
|
|
|
|
var toggleElement = $(this).next();
|
|
|
|
toggleElement.toggle();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class: a.form_frontend_function.tick_all_result_assembly
|
|
|
|
*/
|
|
|
|
$('a.form_frontend_function.tick_all_result_assembly').entwine({
|
|
|
|
/**
|
|
|
|
* Function: onclick
|
|
|
|
*/
|
|
|
|
onclick: function(e) {
|
|
|
|
var resultAssembly = $(this).prevAll('div#ResultAssembly').find('ul li input');
|
|
|
|
resultAssembly.attr('checked', 'checked');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('a.form_frontend_function.untick_all_result_assembly').entwine({
|
|
|
|
onclick: function(e) {
|
|
|
|
var resultAssembly = $(this).prevAll('div#ResultAssembly').find('ul li input');
|
|
|
|
resultAssembly.removeAttr('checked');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class: .resultsTable tbody td
|
|
|
|
*
|
|
|
|
* Table record handler for search result record
|
|
|
|
*/
|
|
|
|
$('.resultsTable tbody td').entwine({
|
|
|
|
/**
|
|
|
|
* Function: onclick
|
|
|
|
*/
|
|
|
|
onclick: function(e) {
|
|
|
|
var firstLink = this.find('a[href]');
|
|
|
|
if(!firstLink) return;
|
2011-06-08 01:35:56 +02:00
|
|
|
|
2011-12-14 16:13:13 +01:00
|
|
|
if(window.History.enabled) {
|
2011-12-15 12:16:54 +01:00
|
|
|
$('.cms-container').loadPanel(firstLink.attr('href'), '', {selector: '.cms-content-fields form:first'});
|
2011-12-14 16:13:13 +01:00
|
|
|
return false;
|
|
|
|
}
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class: #Form_ManagedModelsSelect
|
|
|
|
*
|
|
|
|
* Add object button
|
|
|
|
*/
|
|
|
|
$('#Form_ManagedModelsSelect').entwine({
|
|
|
|
/**
|
|
|
|
* Function: onsubmit
|
|
|
|
*/
|
|
|
|
onsubmit: function(e) {
|
|
|
|
className = $('select option:selected', this).val();
|
|
|
|
requestPath = this.attr('action').replace('ManagedModelsSelect', className + '/add');
|
|
|
|
var $button = $(':submit', this);
|
2011-06-08 01:35:56 +02:00
|
|
|
$('.cms-content').loadForm(
|
2011-03-23 10:51:00 +01:00
|
|
|
requestPath,
|
2011-06-08 01:35:56 +02:00
|
|
|
null,
|
2011-03-23 10:51:00 +01:00
|
|
|
function() {
|
|
|
|
$button.removeClass('loading');
|
|
|
|
$button = null;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
2011-03-31 10:52:29 +02:00
|
|
|
* Class: .cms-edit-form input[name=action_doDelete]
|
2011-03-23 10:51:00 +01:00
|
|
|
*
|
|
|
|
* RHS panel Delete button
|
|
|
|
*/
|
2011-03-31 10:52:29 +02:00
|
|
|
$('.cms-edit-form input[name=action_doDelete]').entwine({
|
2011-03-23 10:51:00 +01:00
|
|
|
// Function: onclick
|
|
|
|
onclick: function(e) {
|
|
|
|
if(!confirm(ss.i18n._t('ModelAdmin.REALLYDELETE', 'Really delete?'))) {
|
|
|
|
this.removeClass('loading');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class: .importSpec
|
|
|
|
*
|
|
|
|
* Toggle import specifications
|
|
|
|
*/
|
|
|
|
$('.importSpec').entwine({
|
|
|
|
onmatch: function() {
|
|
|
|
this.hide();
|
|
|
|
this.find('a.detailsLink').click(function() {
|
|
|
|
$('#' + $(this).attr('href').replace(/.*#/,'')).toggle();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
this._super();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-04-15 01:25:47 +02:00
|
|
|
$('.cms-editor-dialogs').entwine({
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* Close TinyMCE image, link or flash panel.
|
|
|
|
* this function is called everytime a new search, back or add new DataObject are clicked
|
|
|
|
**/
|
|
|
|
closeRightPanel: function(){
|
2011-04-15 01:25:47 +02:00
|
|
|
if($('.cms-editor-dialogs').is(':visible')) {
|
|
|
|
$('.cms-editor-dialogs').hide();
|
2012-02-08 21:32:25 +01:00
|
|
|
$('#Form_EditorToolbarMediaForm').hide();
|
2011-03-23 10:51:00 +01:00
|
|
|
$('#Form_EditorToolbarLinkForm').hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})(jQuery);
|