2009-11-21 03:36:00 +01:00
|
|
|
(function($) {
|
2009-11-21 04:19:59 +01:00
|
|
|
$.concrete('ss', function($){
|
2009-11-21 03:37:41 +01:00
|
|
|
|
2009-11-21 04:19:59 +01:00
|
|
|
/**
|
|
|
|
* @class All forms in the right content panel should have closeable jQuery UI style titles.
|
|
|
|
* @name ss.contentPanel.form
|
|
|
|
*/
|
|
|
|
$('#contentPanel form').concrete(/** @lends ss.contentPanel.form */{
|
2009-11-21 03:38:31 +01:00
|
|
|
onmatch: function() {
|
|
|
|
// Style as title bar
|
|
|
|
this.find(':header:first').titlebar({
|
|
|
|
closeButton:true
|
|
|
|
});
|
|
|
|
// The close button should close the east panel of the layout
|
|
|
|
this.find(':header:first .ui-dialog-titlebar-close').bind('click', function(e) {
|
|
|
|
$('body.CMSMain').concrete('ss').MainLayout().close('east');
|
|
|
|
return false;
|
|
|
|
});
|
2009-11-21 04:19:59 +01:00
|
|
|
|
|
|
|
this._super();
|
2009-11-21 03:38:31 +01:00
|
|
|
}
|
2009-11-21 04:19:59 +01:00
|
|
|
});
|
2009-11-21 03:37:06 +01:00
|
|
|
|
2009-11-21 04:19:59 +01:00
|
|
|
/**
|
|
|
|
* @class Control the site tree filter.
|
|
|
|
* Toggles search form fields based on a dropdown selection,
|
|
|
|
* similar to "Smart Search" criteria in iTunes.
|
|
|
|
* @name ss.Form_SeachTreeForm
|
|
|
|
*/
|
|
|
|
$('#Form_SearchTreeForm').concrete(/** @lends ss.Form_SeachTreeForm */{
|
2009-11-21 03:38:31 +01:00
|
|
|
/**
|
|
|
|
* @type DOMElement
|
|
|
|
*/
|
|
|
|
SelectEl: null,
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 03:38:31 +01:00
|
|
|
onmatch: function() {
|
|
|
|
var self = this;
|
2009-11-21 03:37:06 +01:00
|
|
|
|
2009-11-21 03:38:31 +01:00
|
|
|
// only the first field should be visible by default
|
|
|
|
this.find('.field').not(':first').hide();
|
2009-11-21 03:37:06 +01:00
|
|
|
|
2009-11-21 03:38:31 +01:00
|
|
|
// generate the field dropdown
|
|
|
|
this.setSelectEl($('<select name="options" class="options"></select>')
|
|
|
|
.appendTo(this.find('fieldset:first'))
|
|
|
|
.bind('change', function(e) {self._addField(e);})
|
|
|
|
);
|
2009-11-21 03:38:23 +01:00
|
|
|
|
2009-11-21 03:38:31 +01:00
|
|
|
this._setOptions();
|
2009-11-21 03:37:06 +01:00
|
|
|
|
2009-11-21 04:19:59 +01:00
|
|
|
this._super();
|
|
|
|
},
|
|
|
|
|
2009-11-21 03:38:31 +01:00
|
|
|
_setOptions: function() {
|
|
|
|
var self = this;
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 03:38:31 +01:00
|
|
|
// reset existing elements
|
2009-11-21 04:19:59 +01:00
|
|
|
self.getSelectEl().find('option').remove();
|
|
|
|
|
2009-11-21 03:38:31 +01:00
|
|
|
// add default option
|
|
|
|
// TODO i18n
|
2009-11-21 04:19:59 +01:00
|
|
|
jQuery('<option value="0">Add Criteria</option>').appendTo(self.getSelectEl());
|
|
|
|
|
2009-11-21 03:38:31 +01:00
|
|
|
// populate dropdown values from existing fields
|
|
|
|
this.find('.field').each(function() {
|
2009-11-21 04:19:59 +01:00
|
|
|
$('<option />').appendTo(self.getSelectEl())
|
2009-11-21 03:38:31 +01:00
|
|
|
.val(this.id)
|
|
|
|
.text($(this).find('label').text());
|
|
|
|
});
|
|
|
|
},
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 03:38:31 +01:00
|
|
|
/**
|
|
|
|
* Filter tree based on selected criteria.
|
|
|
|
*/
|
2009-11-21 04:19:59 +01:00
|
|
|
onsubmit: function(e) {
|
2009-11-21 03:38:31 +01:00
|
|
|
var self = this;
|
|
|
|
var data = [];
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 03:38:31 +01:00
|
|
|
// convert from jQuery object literals to hash map
|
|
|
|
$(this.serializeArray()).each(function(i, el) {
|
|
|
|
data[el.name] = el.value;
|
|
|
|
});
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 03:38:31 +01:00
|
|
|
// Set new URL
|
|
|
|
$('#sitetree')[0].setCustomURL(this.attr('action') + '&action_getfilteredsubtree=1', data);
|
2009-11-21 03:37:06 +01:00
|
|
|
|
2009-11-21 03:38:31 +01:00
|
|
|
// Disable checkbox tree controls that currently don't work with search.
|
|
|
|
// @todo: Make them work together
|
|
|
|
if ($('#sitetree')[0].isDraggable) $('#sitetree')[0].stopBeingDraggable();
|
|
|
|
this.find('.checkboxAboveTree :checkbox').val(false).attr('disabled', true);
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 03:38:31 +01:00
|
|
|
// disable buttons to avoid multiple submission
|
|
|
|
//this.find(':submit').attr('disabled', true);
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 03:38:31 +01:00
|
|
|
this.find(':submit[name=action_getfilteredsubtree]').addClass('loading');
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 03:38:31 +01:00
|
|
|
this._reloadSitetree();
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 03:38:31 +01:00
|
|
|
return false;
|
|
|
|
},
|
2009-11-21 04:19:59 +01:00
|
|
|
|
|
|
|
onreset: function(e) {
|
2009-11-21 03:38:31 +01:00
|
|
|
this.find('.field').clearFields().not(':first').hide();
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 03:38:31 +01:00
|
|
|
// Reset URL to default
|
|
|
|
$('#sitetree')[0].clearCustomURL();
|
2009-11-21 03:37:06 +01:00
|
|
|
|
2009-11-21 03:38:31 +01:00
|
|
|
// Enable checkbox tree controls
|
|
|
|
this.find('.checkboxAboveTree :checkbox').attr('disabled', 'false');
|
2009-11-21 03:37:06 +01:00
|
|
|
|
2009-11-21 03:38:31 +01:00
|
|
|
// reset all options, some of the might be removed
|
|
|
|
this._setOptions();
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 03:38:31 +01:00
|
|
|
this._reloadSitetree();
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 03:38:31 +01:00
|
|
|
return false;
|
|
|
|
},
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 03:38:31 +01:00
|
|
|
_addField: function(e) {
|
|
|
|
var $select = $(e.target);
|
|
|
|
// show formfield matching the option
|
|
|
|
this.find('#' + $select.val()).show();
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 03:38:31 +01:00
|
|
|
// remove option from dropdown, each field should just exist once
|
|
|
|
this.find('option[value=' + $select.val() + ']').remove();
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 03:38:31 +01:00
|
|
|
// jump back to default entry
|
|
|
|
$select.val(0);
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 03:38:31 +01:00
|
|
|
return false;
|
|
|
|
},
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 03:38:31 +01:00
|
|
|
_reloadSitetree: function() {
|
|
|
|
var self = this;
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 03:38:31 +01:00
|
|
|
$('#sitetree')[0].reload({
|
|
|
|
onSuccess : function(response) {
|
|
|
|
self.find(':submit').attr('disabled', false).removeClass('loading');
|
|
|
|
self.find('.checkboxAboveTree :checkbox').attr('disabled', 'true');
|
|
|
|
statusMessage('Filtered tree','good');
|
|
|
|
},
|
|
|
|
onFailure : function(response) {
|
|
|
|
self.find(':submit').attr('disabled', false).removeClass('loading');
|
|
|
|
self.find('.checkboxAboveTree :checkbox').attr('disabled', 'true');
|
|
|
|
errorMessage('Could not filter site tree<br />' + response.responseText);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2009-11-21 04:19:59 +01:00
|
|
|
});
|
2009-11-21 04:15:32 +01:00
|
|
|
|
2009-11-21 04:19:59 +01:00
|
|
|
/**
|
|
|
|
* @class Simple form with a page type dropdown
|
|
|
|
* which creates a new page through #Form_EditForm and adds a new tree node.
|
|
|
|
* @name ss.reports_holder
|
|
|
|
*/
|
|
|
|
$('#Form_ReportForm').concrete(/** @lends ss.reports_holder */{
|
2009-11-21 04:15:55 +01:00
|
|
|
onmatch: function() {
|
|
|
|
var self = this;
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:15:55 +01:00
|
|
|
// integrate with sitetree selection changes
|
2009-11-21 04:19:59 +01:00
|
|
|
// TODO Only trigger when report is visible
|
2009-11-21 04:15:55 +01:00
|
|
|
jQuery('#sitetree').bind('selectionchanged', function(e, data) {
|
|
|
|
self.find(':input[name=ID]').val(data.node.getIdx());
|
|
|
|
self.trigger('submit');
|
|
|
|
});
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:15:55 +01:00
|
|
|
// move submit button to the top
|
|
|
|
this.find('#ReportClass').after(this.find('.Actions'));
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:15:55 +01:00
|
|
|
// links in results
|
|
|
|
this.find('ul a').bind('click', function(e) {
|
|
|
|
var $link = $(this);
|
|
|
|
$link.addClass('loading');
|
|
|
|
jQuery('#Form_EditForm').concrete('ss').loadForm(
|
|
|
|
$(this).attr('href'),
|
|
|
|
function(e) {
|
|
|
|
$link.removeClass('loading');
|
|
|
|
}
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2009-11-21 04:19:59 +01:00
|
|
|
this._super();
|
|
|
|
},
|
|
|
|
|
|
|
|
onsubmit: function(e) {
|
2009-11-21 04:15:55 +01:00
|
|
|
var self = this;
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:15:55 +01:00
|
|
|
// dont process if no report is selected
|
|
|
|
var reportClass = this.find(':input[name=ReportClass]').val();
|
|
|
|
if(!reportClass) return false;
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:15:55 +01:00
|
|
|
var button = this.find(':submit:first');
|
|
|
|
button.addClass('loading');
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:15:55 +01:00
|
|
|
jQuery.ajax({
|
|
|
|
url: this.attr('action'),
|
|
|
|
data: this.serializeArray(),
|
|
|
|
dataType: 'html',
|
|
|
|
success: function(data, status) {
|
|
|
|
// replace current form
|
|
|
|
self.replaceWith(data);
|
|
|
|
},
|
|
|
|
complete: function(xmlhttp, status) {
|
|
|
|
button.removeClass('loading');
|
|
|
|
}
|
|
|
|
});
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:16:09 +01:00
|
|
|
return false;
|
|
|
|
}
|
2009-11-21 04:19:59 +01:00
|
|
|
});
|
2009-11-21 04:16:09 +01:00
|
|
|
|
2009-11-21 04:19:59 +01:00
|
|
|
/**
|
|
|
|
* @class Simple form showing versions of a specific page.
|
|
|
|
* @name ss.Form_VersionsForm
|
|
|
|
* @requires ss.i18n
|
|
|
|
*/
|
|
|
|
$('#Form_VersionsForm').concrete(/** @lends ss.Form_VersionsForm */{
|
2009-11-21 04:16:09 +01:00
|
|
|
onmatch: function() {
|
|
|
|
var self = this;
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:16:09 +01:00
|
|
|
// set button to be available in form submit event later on
|
|
|
|
this.find(':submit').bind('click', function(e) {
|
|
|
|
self.data('_clickedButton', this);
|
|
|
|
});
|
|
|
|
|
2009-11-21 04:19:59 +01:00
|
|
|
this.bind('submit', function(e) {
|
|
|
|
return self._submit();
|
|
|
|
});
|
|
|
|
|
2009-11-21 04:16:09 +01:00
|
|
|
// integrate with sitetree selection changes
|
|
|
|
jQuery('#sitetree').bind('selectionchanged', function(e, data) {
|
|
|
|
self.find(':input[name=ID]').val(data.node.getIdx());
|
2009-11-21 04:17:06 +01:00
|
|
|
if(self.is(':visible')) self.trigger('submit');
|
2009-11-21 04:16:09 +01:00
|
|
|
});
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:16:09 +01:00
|
|
|
// refresh when field is selected
|
|
|
|
// TODO coupling
|
|
|
|
$('#treepanes').bind('accordionchange', function(e, ui) {
|
|
|
|
if($(ui.newContent).attr('id') == 'Form_VersionsForm') self.trigger('submit');
|
|
|
|
});
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:16:09 +01:00
|
|
|
// submit when 'show unpublished versions' checkbox is changed
|
|
|
|
this.find(':input[name=ShowUnpublished]').bind('change', function(e) {
|
|
|
|
// force the refresh button, not 'compare versions'
|
|
|
|
self.data('_clickedButton', self.find(':submit[name=action_versions]'));
|
|
|
|
self.trigger('submit');
|
|
|
|
});
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:16:09 +01:00
|
|
|
// move submit button to the top
|
|
|
|
this.find('#ReportClass').after(this.find('.Actions'));
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:16:09 +01:00
|
|
|
// links in results
|
|
|
|
this.find('td').bind('click', function(e) {
|
|
|
|
var td = $(this);
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:16:09 +01:00
|
|
|
// exclude checkboxes
|
|
|
|
if($(e.target).is(':input')) return true;
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:16:09 +01:00
|
|
|
var link = $(this).siblings('.versionlink').find('a').attr('href');
|
|
|
|
td.addClass('loading');
|
|
|
|
jQuery('#Form_EditForm').concrete('ss').loadForm(
|
|
|
|
link,
|
|
|
|
function(e) {
|
|
|
|
td.removeClass('loading');
|
|
|
|
}
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
});
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:16:09 +01:00
|
|
|
// compare versions action
|
|
|
|
this.find(':submit[name=action_compareversions]').bind('click', function(e) {
|
|
|
|
// validation: only allow selection of exactly two versions
|
|
|
|
var versions = self.find(':input[name=Versions[]]:checked');
|
|
|
|
if(versions.length != 2) {
|
|
|
|
alert(ss.i18n._t(
|
|
|
|
'CMSMain.VALIDATIONTWOVERSION',
|
|
|
|
'Please select two versions'
|
|
|
|
));
|
|
|
|
return false;
|
|
|
|
}
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:16:09 +01:00
|
|
|
// overloaded submission: refresh the right form instead
|
|
|
|
self.data('_clickedButton', this);
|
2009-11-21 04:19:59 +01:00
|
|
|
self._submit(true);
|
|
|
|
|
2009-11-21 04:16:09 +01:00
|
|
|
return false;
|
2009-11-21 04:19:59 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
this._super();
|
2009-11-21 04:16:09 +01:00
|
|
|
},
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:16:09 +01:00
|
|
|
/**
|
|
|
|
* @param {boolean} loadEditForm Determines if responses should show in current panel,
|
|
|
|
* or in the edit form (in the case of 'compare versions').
|
|
|
|
*/
|
2009-11-21 04:19:59 +01:00
|
|
|
_submit: function(loadEditForm) {
|
2009-11-21 04:16:09 +01:00
|
|
|
var self = this;
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:16:09 +01:00
|
|
|
// Don't submit with empty ID
|
|
|
|
if(!this.find(':input[name=ID]').val()) return false;
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:16:09 +01:00
|
|
|
var $button = (self.data('_clickedButton')) ? $(self.data('_clickedButton')) : this.find(':submit:first');
|
|
|
|
$button.addClass('loading');
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:16:09 +01:00
|
|
|
var data = this.serializeArray();
|
|
|
|
data.push({name:$button.attr('name'), value: $button.val()});
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:16:09 +01:00
|
|
|
if(loadEditForm) {
|
|
|
|
jQuery('#Form_EditForm').concrete('ss').loadForm(
|
|
|
|
this.attr('action'),
|
|
|
|
function(e) {
|
|
|
|
$button.removeClass('loading');
|
|
|
|
},
|
|
|
|
{data: data, type: 'POST'}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
jQuery.ajax({
|
|
|
|
url: this.attr('action'),
|
|
|
|
data: data,
|
|
|
|
dataType: 'html',
|
|
|
|
success: function(data, status) {
|
|
|
|
self.replaceWith(data);
|
|
|
|
},
|
|
|
|
complete: function(xmlhttp, status) {
|
|
|
|
$button.removeClass('loading');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2009-11-21 04:15:55 +01:00
|
|
|
return false;
|
|
|
|
}
|
2009-11-21 04:19:59 +01:00
|
|
|
});
|
2009-11-21 04:15:55 +01:00
|
|
|
});
|
2009-11-21 03:36:26 +01:00
|
|
|
})(jQuery);
|