silverstripe-subsites/javascript/LeftAndMain_Subsites.js

186 lines
4.8 KiB
JavaScript
Raw Normal View History

/*jslint browser: true, nomen: true*/
/*global $, window, jQuery*/
BUG: Modifying the module to work with SS 3.0 Replaced deprecated DataObjectDecorator with DataExtension Fixed hard crashes in the cms Updated to support new LeftAndMain template structure Made the subsites model admin functional Moved the LeftAndMain_Menu template up a directory so it overrides the core Fixed some errors caused by changes to the framework Re-organized the code folder Fixed permission issue causing to default to first subsite regardless if it is the default or not Fixed crashes on the subsite virtual page when creating/editing Removed toDropdownMap() calls replacing with map() Fixed the URLSegment field on subsites Fixed error when detecting subsite for a domain Improved styles on the subsite dropdown Updated LeftAndMain_Subsites.js to work with jQuery entwine Started porting the SubsitesTreeDropdownField.js to use jQuery entwine and work with the new TreeDropdownField.js Fixed issue causing crash when viewing a page who is linked to by a subsite virtual page Removed unused methods on SubsitesTreeDropdownField.js Re-added classes that were moved Fixed hard crash after saving caused by the many_many definition on SiteTreeSubsites Replaced deprecated DataObjectSet creation with ArrayList Compatibility fixes with SS 3.0 beta 2 Fixed crash in cms caused by no parameter being passed to the SubsiteReportWrapper constructor Proper fix for report wrapper Removed table list field in favor of a basic grid field Fixed updateCMSFields() for file subsites Migrated translations to yml Fixed issue causing the current page to not get cleared when changing subsites in the cms Fixed virtual page icon Fixed language files issue
2012-03-25 18:35:01 +02:00
(function($) {
'use strict';
2012-07-10 15:43:53 +02:00
$.entwine('ss', function($) {
$('#SubsitesSelect').entwine({
onadd:function(){
this.on('change', function(){
window.location.search=$.query.set('SubsiteID', $(this).val());
});
}
});
$('.cms-container').entwine({
SubsiteCurrentXHR: null,
/**
* LeftAndMain does not give us possibility to parallel-fetch a PJAX fragment.
* We provide our own fetcher that bypasses the history - that's because we
* don't want to load a panel, but rather just a subsite dropdown.
*/
subsiteFetchPjaxFragment: function(url, pjaxFragment) {
// Make sure only one subsite XHR request is ongoing.
if(this.getSubsiteCurrentXHR()){
this.getSubsiteCurrentXHR().abort();
}
var self = this,
xhr,
headers = {},
baseUrl = $('base').attr('href');
url = $.path.isAbsoluteUrl(url) ? url : $.path.makeUrlAbsolute(url, baseUrl);
headers['X-Pjax'] = pjaxFragment;
xhr = $.ajax({
headers: headers,
url: url,
complete: function() {
self.setSubsiteCurrentXHR(null);
},
success: function(data, status, xhr) {
self.handleAjaxResponse(data, status, xhr, null);
}
});
this.setSubsiteCurrentXHR(xhr);
}
});
/*
* Reload subsites dropdown when links are processed
*/
$('.cms-container .cms-menu-list li a').entwine({
onclick: function(e) {
$('.cms-container').subsiteFetchPjaxFragment('admin/subsites/', 'SubsiteList');
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) {
$('.cms-container').subsiteFetchPjaxFragment('admin/subsites/', 'SubsiteList');
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) {
$('.cms-container').subsiteFetchPjaxFragment('admin/subsites/', 'SubsiteList');
this._super(e);
}
2012-07-10 15:43:53 +02:00
});
// Subsite tab of Group editor
$('#Form_ItemEditForm_AccessAllSubsites').entwine({
BUG: Modifying the module to work with SS 3.0 Replaced deprecated DataObjectDecorator with DataExtension Fixed hard crashes in the cms Updated to support new LeftAndMain template structure Made the subsites model admin functional Moved the LeftAndMain_Menu template up a directory so it overrides the core Fixed some errors caused by changes to the framework Re-organized the code folder Fixed permission issue causing to default to first subsite regardless if it is the default or not Fixed crashes on the subsite virtual page when creating/editing Removed toDropdownMap() calls replacing with map() Fixed the URLSegment field on subsites Fixed error when detecting subsite for a domain Improved styles on the subsite dropdown Updated LeftAndMain_Subsites.js to work with jQuery entwine Started porting the SubsitesTreeDropdownField.js to use jQuery entwine and work with the new TreeDropdownField.js Fixed issue causing crash when viewing a page who is linked to by a subsite virtual page Removed unused methods on SubsitesTreeDropdownField.js Re-added classes that were moved Fixed hard crash after saving caused by the many_many definition on SiteTreeSubsites Replaced deprecated DataObjectSet creation with ArrayList Compatibility fixes with SS 3.0 beta 2 Fixed crash in cms caused by no parameter being passed to the SubsiteReportWrapper constructor Proper fix for report wrapper Removed table list field in favor of a basic grid field Fixed updateCMSFields() for file subsites Migrated translations to yml Fixed issue causing the current page to not get cleared when changing subsites in the cms Fixed virtual page icon Fixed language files issue
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() {
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({
getChangeTrackerOptions: function() {
this.ChangeTrackerOptions.ignoreFieldSelector+=', input[name=IsSubsite]';
}
});
/**
* 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) {
jQuery('#PageTypeBlacklist').toggle();
e.stopPropagation();
return false;
});
2012-07-10 15:43:53 +02: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
});
$.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');
if (!subsiteId) {
return;
}
// Inject the SubsiteID into internal links.
$(doc).find('a').each(function() {
var href = $(this).attr('href');
if (!href.match(/^http:\/\//)) {
$(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() {
if (!$(this).attr('action').match(/^http:\/\//)) {
$(doc).find('form').append('<input type=hidden name="SubsiteID" value="' + subsiteId + '" >');
}
});
}
});
});
}(jQuery));