2013-08-22 03:02:46 +02:00
|
|
|
/*jslint browser: true, nomen: true*/
|
|
|
|
/*global $, window, jQuery*/
|
|
|
|
|
2012-03-25 18:35:01 +02:00
|
|
|
(function($) {
|
2013-08-22 03:02:46 +02:00
|
|
|
'use strict';
|
2012-07-10 15:43:53 +02:00
|
|
|
$.entwine('ss', function($) {
|
2013-08-22 03:02:46 +02:00
|
|
|
|
|
|
|
$('#SubsitesSelect').entwine({
|
|
|
|
onadd:function(){
|
|
|
|
this.on('change', function(){
|
|
|
|
window.location.search=$.query.set('SubsiteID', $(this).val());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reload subsites dropdown when links are processed
|
|
|
|
*/
|
|
|
|
$('.cms-container .cms-menu-list li a').entwine({
|
|
|
|
onclick: function(e) {
|
2013-08-22 05:02:25 +02:00
|
|
|
$('.cms-container').loadFragment('SubsiteXHRController', 'SubsiteList');
|
2013-08-22 03:02:46 +02:00
|
|
|
this._super(e);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reload subsites dropdown when the admin area reloads (for deleting sites)
|
|
|
|
*/
|
|
|
|
$('.cms-container .SubsiteAdmin .cms-edit-form fieldset.ss-gridfield').entwine({
|
|
|
|
onreload: function(e) {
|
2013-08-22 05:02:25 +02:00
|
|
|
$('.cms-container').loadFragment('SubsiteXHRController', 'SubsiteList');
|
2013-08-22 03:02:46 +02:00
|
|
|
this._super(e);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reload subsites dropdown when subsites are added or names are modified
|
|
|
|
*/
|
|
|
|
$('.cms-container .cms-content-fields .subsite-model').entwine({
|
|
|
|
onadd: function(e) {
|
2013-08-22 05:02:25 +02:00
|
|
|
$('.cms-container').loadFragment('SubsiteXHRController', 'SubsiteList');
|
2013-08-22 03:02:46 +02:00
|
|
|
this._super(e);
|
|
|
|
}
|
2012-07-10 15:43:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Subsite tab of Group editor
|
|
|
|
$('#Form_ItemEditForm_AccessAllSubsites').entwine({
|
2012-03-25 18:35:01 +02:00
|
|
|
/**
|
|
|
|
* Constructor: onmatch
|
|
|
|
*/
|
|
|
|
onmatch: function () {
|
2012-07-10 15:43:53 +02:00
|
|
|
this.showHideSubsiteList();
|
|
|
|
|
|
|
|
var ref=this;
|
|
|
|
$('#Form_ItemEditForm_AccessAllSubsites input').change(function() {
|
2012-07-11 15:32:10 +02:00
|
|
|
ref.showHideSubsiteList();
|
|
|
|
});
|
2012-07-10 15:43:53 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
showHideSubsiteList: function () {
|
|
|
|
$('#Form_ItemEditForm_Subsites').parent().parent().css('display', ($('#Form_ItemEditForm_AccessAllSubsites_1').is(':checked') ? 'none':''));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.cms-edit-form').entwine({
|
FIX: Ensure that ChangeTrackerOptions doesn't get overriden
From @hafriedlander:
Hi. Sorry, I was going to have a look at this on the back of that issue @chillu raised but you beat me to it. There's a couple of edge cases that aren't obvious that come from ChangeTrackerOptions being an object, and might need an Entwine API extension to fix nicely.
Objects in entwine properties are a bit dangerous, because javascript always passes them by reference instead of cloning them. Entwine also doesn't clone them when using them as default values.
The result is that this patch will repeatedly add that selector to the result every time getChangeTrackerOptions is called, so it'll be there once the first time it's called, twice the second, etc.
The right fix at the moment would look like:
```php
$('.cms-edit-form').entwine({
getChangeTrackerOptions: function() {
// Figure out if we're still returning the default value
var isDefault = (this.entwineData('ChangeTrackerOptions') === undefined);
// Get the current options
var opts = this._super();
if (isDefault) {
// If it is the default then...
// clone the object (so we don't modify the original),
var opts = $.extend({}, opts);
// modify it,
opts.ignoreFieldSelector +=', input[name=IsSubsite]';
// then set the clone as the value on this element
// (so next call to this method gets this same clone)
this.setChangeTrackerOptions(opts);
}
return opts;
});
```
This is super ugly though, non-obvious, and could maybe be handled better in the entwine layer.
See https://github.com/silverstripe/silverstripe-subsites/pull/125
2013-11-19 16:24:48 +01:00
|
|
|
/**
|
|
|
|
* TODO: Fix with Entwine API extension. See https://github.com/silverstripe/silverstripe-subsites/pull/125
|
|
|
|
*/
|
2012-07-10 15:43:53 +02:00
|
|
|
getChangeTrackerOptions: function() {
|
FIX: Ensure that ChangeTrackerOptions doesn't get overriden
From @hafriedlander:
Hi. Sorry, I was going to have a look at this on the back of that issue @chillu raised but you beat me to it. There's a couple of edge cases that aren't obvious that come from ChangeTrackerOptions being an object, and might need an Entwine API extension to fix nicely.
Objects in entwine properties are a bit dangerous, because javascript always passes them by reference instead of cloning them. Entwine also doesn't clone them when using them as default values.
The result is that this patch will repeatedly add that selector to the result every time getChangeTrackerOptions is called, so it'll be there once the first time it's called, twice the second, etc.
The right fix at the moment would look like:
```php
$('.cms-edit-form').entwine({
getChangeTrackerOptions: function() {
// Figure out if we're still returning the default value
var isDefault = (this.entwineData('ChangeTrackerOptions') === undefined);
// Get the current options
var opts = this._super();
if (isDefault) {
// If it is the default then...
// clone the object (so we don't modify the original),
var opts = $.extend({}, opts);
// modify it,
opts.ignoreFieldSelector +=', input[name=IsSubsite]';
// then set the clone as the value on this element
// (so next call to this method gets this same clone)
this.setChangeTrackerOptions(opts);
}
return opts;
});
```
This is super ugly though, non-obvious, and could maybe be handled better in the entwine layer.
See https://github.com/silverstripe/silverstripe-subsites/pull/125
2013-11-19 16:24:48 +01:00
|
|
|
// Figure out if we're still returning the default value
|
|
|
|
var isDefault = (this.entwineData('ChangeTrackerOptions') === undefined);
|
|
|
|
// Get the current options
|
|
|
|
var opts = this._super();
|
|
|
|
|
|
|
|
if (isDefault) {
|
|
|
|
// If it is the default then...
|
|
|
|
// clone the object (so we don't modify the original),
|
|
|
|
var opts = $.extend({}, opts);
|
|
|
|
// modify it,
|
|
|
|
opts.ignoreFieldSelector +=', input[name=IsSubsite]';
|
|
|
|
// then set the clone as the value on this element
|
|
|
|
// (so next call to this method gets this same clone)
|
|
|
|
this.setChangeTrackerOptions(opts);
|
|
|
|
}
|
|
|
|
|
|
|
|
return opts;
|
2012-07-10 15:43:53 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Binding a visibility toggle anchor to a longer list of checkboxes.
|
|
|
|
* Hidden by default, unless either the toggle checkbox, or any of the
|
|
|
|
* actual value checkboxes are selected.
|
|
|
|
*/
|
|
|
|
$('#PageTypeBlacklist').entwine({
|
|
|
|
onmatch: function() {
|
|
|
|
var hasLimits=Boolean($('#PageTypeBlacklist').find('input:checked').length);
|
|
|
|
jQuery('#PageTypeBlacklist').toggle(hasLimits);
|
|
|
|
|
|
|
|
|
|
|
|
//Bind listener
|
|
|
|
$('a#PageTypeBlacklistToggle').click(function(e) {
|
2012-07-11 15:32:10 +02:00
|
|
|
jQuery('#PageTypeBlacklist').toggle();
|
|
|
|
e.stopPropagation();
|
|
|
|
return false;
|
|
|
|
});
|
2012-07-10 15:43:53 +02:00
|
|
|
}
|
|
|
|
});
|
2007-08-16 08:38:29 +02:00
|
|
|
|
2013-01-03 17:38:51 +01:00
|
|
|
$('.cms-edit-form input[name=action_copytosubsite]').entwine({
|
|
|
|
onclick: function(e) {
|
|
|
|
var form = this.closest('form');
|
|
|
|
form.trigger('submit', [this]);
|
|
|
|
}
|
|
|
|
});
|
2007-10-12 00:15:40 +02:00
|
|
|
|
2012-07-10 15:43:53 +02:00
|
|
|
});
|
2013-05-26 03:18:52 +02:00
|
|
|
|
|
|
|
$.entwine('ss.preview', function($){
|
|
|
|
|
|
|
|
$('.cms-preview').entwine({
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update links and forms with GET/POST SubsiteID param, so we remaing on the current subsite.
|
|
|
|
* The initial link for the iframe comes from SiteTreeSubsites::alternatePreviewLink.
|
|
|
|
*
|
|
|
|
* This is done so we can use the CMS domain for displaying previews so we prevent single-origin
|
|
|
|
* violations and SSL cert problems that come up when iframing content from a different URL.
|
|
|
|
*/
|
|
|
|
onafterIframeAdjustedForPreview: function(event, doc) {
|
|
|
|
var subsiteId = $(doc).find('meta[name=x-subsite-id]').attr('content');
|
|
|
|
|
2013-08-22 03:02:46 +02:00
|
|
|
if (!subsiteId) {
|
|
|
|
return;
|
|
|
|
}
|
2013-05-26 03:18:52 +02:00
|
|
|
|
|
|
|
// Inject the SubsiteID into internal links.
|
|
|
|
$(doc).find('a').each(function() {
|
|
|
|
var href = $(this).attr('href');
|
|
|
|
|
2014-03-27 05:11:50 +01:00
|
|
|
if (typeof href!=='undefined' && !href.match(/^http:\/\//)) {
|
2013-05-26 03:18:52 +02:00
|
|
|
|
|
|
|
$(this).attr('href', $.path.addSearchParams(href, {
|
|
|
|
'SubsiteID': subsiteId
|
|
|
|
}));
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Inject the SubsiteID as a hidden input into all forms submitting to the local site.
|
|
|
|
$(doc).find('form').each(function() {
|
2014-03-27 05:11:50 +01:00
|
|
|
var action = $(this).attr('action');
|
2013-05-26 03:18:52 +02:00
|
|
|
|
2014-03-27 05:11:50 +01:00
|
|
|
if (typeof action!=='undefined' && !action.match(/^http:\/\//)) {
|
|
|
|
$(this).append('<input type=hidden name="SubsiteID" value="' + subsiteId + '" >');
|
2013-05-26 03:18:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2013-08-22 03:02:46 +02:00
|
|
|
}(jQuery));
|