2011-08-19 02:32:31 +02:00
|
|
|
(function($) {
|
|
|
|
/**
|
|
|
|
* File: CMSPageHistoryController.js
|
2016-01-06 00:42:07 +01:00
|
|
|
*
|
|
|
|
* Handles related interactions between the version selection form on the
|
2011-08-19 02:32:31 +02:00
|
|
|
* left hand side of the panel and the version displaying on the right
|
|
|
|
* hand side.
|
|
|
|
*/
|
|
|
|
|
|
|
|
$.entwine('ss', function($){
|
2013-05-13 06:24:00 +02:00
|
|
|
|
2011-08-19 02:32:31 +02:00
|
|
|
/**
|
|
|
|
* Class: #Form_VersionsForm
|
|
|
|
*
|
|
|
|
* The left hand side version selection form is the main interface for
|
|
|
|
* users to select a version to view, or to compare two versions
|
|
|
|
*/
|
|
|
|
$('#Form_VersionsForm').entwine({
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
onmatch: function() {
|
|
|
|
this._super();
|
|
|
|
},
|
2012-05-14 01:43:55 +02:00
|
|
|
onunmatch: function() {
|
|
|
|
this._super();
|
|
|
|
},
|
2011-08-19 02:32:31 +02:00
|
|
|
/**
|
|
|
|
* Function: submit.
|
|
|
|
*
|
|
|
|
* Submits either the compare versions form or the view single form
|
|
|
|
* display based on whether we have two or 1 option selected
|
2011-08-30 00:26:40 +02:00
|
|
|
*
|
|
|
|
* Todo:
|
2016-01-06 00:42:07 +01:00
|
|
|
* Handle coupling to admin url
|
2011-08-19 02:32:31 +02:00
|
|
|
*/
|
|
|
|
onsubmit: function(e, d) {
|
2011-12-17 05:17:55 +01:00
|
|
|
e.preventDefault();
|
|
|
|
|
2011-08-19 02:32:31 +02:00
|
|
|
var id, self = this;
|
2011-12-17 05:17:55 +01:00
|
|
|
|
2011-08-19 02:32:31 +02:00
|
|
|
id = this.find(':input[name=ID]').val();
|
|
|
|
|
|
|
|
if(!id) return false;
|
|
|
|
|
2012-02-16 18:06:48 +01:00
|
|
|
var button, url, selected, to, from, compare, data;
|
2011-08-19 02:32:31 +02:00
|
|
|
|
|
|
|
compare = (this.find(":input[name=CompareMode]").is(":checked"));
|
|
|
|
selected = this.find("table input[type=checkbox]").filter(":checked");
|
2011-12-17 05:17:55 +01:00
|
|
|
|
2011-08-19 02:32:31 +02:00
|
|
|
if(compare) {
|
|
|
|
if(selected.length != 2) return false;
|
|
|
|
|
|
|
|
to = selected.eq(0).val();
|
|
|
|
from = selected.eq(1).val();
|
|
|
|
button = this.find(':submit[name=action_doCompare]');
|
2012-02-16 18:06:48 +01:00
|
|
|
url = ss.i18n.sprintf(this.data('linkTmplCompare'), id,from,to);
|
2011-08-19 02:32:31 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
to = selected.eq(0).val();
|
|
|
|
button = this.find(':submit[name=action_doShowVersion]');
|
2012-02-16 18:06:48 +01:00
|
|
|
url = ss.i18n.sprintf(this.data('linkTmplShow'), id,to);
|
2011-08-19 02:32:31 +02:00
|
|
|
}
|
2011-12-17 05:17:55 +01:00
|
|
|
|
2012-06-15 12:50:54 +02:00
|
|
|
$('.cms-container').loadPanel(url, '', {pjax: 'CurrentForm'});
|
2011-08-19 02:32:31 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-05-13 06:24:00 +02:00
|
|
|
/**
|
|
|
|
* Class: :input[name=ShowUnpublished]
|
|
|
|
*
|
|
|
|
* Used for toggling whether to show or hide unpublished versions.
|
|
|
|
*/
|
|
|
|
$('#Form_VersionsForm input[name=ShowUnpublished]').entwine({
|
|
|
|
onmatch: function() {
|
|
|
|
this.toggle();
|
|
|
|
this._super();
|
|
|
|
},
|
|
|
|
onunmatch: function() {
|
|
|
|
this._super();
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Event: :input[name=ShowUnpublished] change
|
|
|
|
*
|
|
|
|
* Changing the show unpublished checkbox toggles whether to show
|
|
|
|
* or hide the unpublished versions. Because those rows may be being
|
|
|
|
* compared this also ensures those rows are unselected.
|
|
|
|
*/
|
|
|
|
onchange: function() {
|
|
|
|
this.toggle();
|
|
|
|
},
|
|
|
|
toggle: function() {
|
|
|
|
var self = $(this);
|
|
|
|
var form = self.parents('form');
|
|
|
|
|
|
|
|
if(self.attr('checked')) {
|
|
|
|
form.find('tr[data-published=false]').show();
|
|
|
|
} else {
|
|
|
|
form.find("tr[data-published=false]").hide()._unselect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-08-19 02:32:31 +02:00
|
|
|
/**
|
|
|
|
* Class: #Form_VersionsForm tr
|
|
|
|
*
|
|
|
|
* An individual row in the versions form. Selecting the row updates
|
|
|
|
* the edit form depending on whether we're showing individual version
|
|
|
|
* information or displaying comparsion.
|
|
|
|
*/
|
|
|
|
$("#Form_VersionsForm tbody tr").entwine({
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function: onclick
|
|
|
|
*
|
|
|
|
* Selects or deselects the row (if in compare mode). Will trigger
|
|
|
|
* an update of the edit form if either selected (in single mode)
|
|
|
|
* or if this is the second row selected (in compare mode)
|
2016-01-06 00:42:07 +01:00
|
|
|
*/
|
2011-08-19 02:32:31 +02:00
|
|
|
onclick: function(e) {
|
|
|
|
var compare, selected;
|
|
|
|
|
|
|
|
// compare mode
|
2015-06-16 00:49:19 +02:00
|
|
|
compare = this.parents("form").find(':input[name=CompareMode]').attr("checked");
|
2011-08-19 02:32:31 +02:00
|
|
|
selected = this.siblings(".active");
|
|
|
|
|
|
|
|
if(compare && this.hasClass('active')) {
|
|
|
|
this._unselect();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if(compare) {
|
|
|
|
// check if we have already selected more than two.
|
|
|
|
if(selected.length > 1) {
|
2014-01-14 01:40:06 +01:00
|
|
|
return alert(ss.i18n._t('ONLYSELECTTWO', 'You can only compare two versions at this time.'));
|
2011-08-19 02:32:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this._select();
|
|
|
|
|
|
|
|
// if this is the second selected then we can compare.
|
|
|
|
if(selected.length == 1) {
|
|
|
|
this.parents('form').submit();
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this._select();
|
|
|
|
selected._unselect();
|
|
|
|
|
|
|
|
this.parents("form").submit();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2016-01-06 00:42:07 +01:00
|
|
|
* Function: _unselect()
|
2011-08-19 02:32:31 +02:00
|
|
|
*
|
2016-01-06 00:42:07 +01:00
|
|
|
* Unselects the row from the form selection.
|
2011-08-19 02:32:31 +02:00
|
|
|
*/
|
|
|
|
_unselect: function() {
|
|
|
|
this.removeClass('active');
|
|
|
|
this.find(":input[type=checkbox]").attr("checked", false);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function: _select()
|
|
|
|
*
|
|
|
|
* Selects the currently matched row in the form selection
|
|
|
|
*/
|
|
|
|
_select: function() {
|
|
|
|
this.addClass('active');
|
|
|
|
this.find(":input[type=checkbox]").attr("checked", true);
|
|
|
|
}
|
|
|
|
|
2015-06-16 00:49:19 +02:00
|
|
|
});
|
2011-08-19 02:32:31 +02:00
|
|
|
});
|
2012-05-14 01:43:55 +02:00
|
|
|
})(jQuery);
|