2017-05-29 07:24:48 +02:00
|
|
|
import $ from 'jquery';
|
2016-01-26 05:28:36 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Behaviour for the CMS Content Toolbar.
|
|
|
|
* Applies to tools on top-level views i.e. '/admin/pages' and '/admin/assets' and
|
|
|
|
* their corresponding tools in the SiteTree panel.
|
|
|
|
* An example is 'bulk actions' on the Pages view.
|
|
|
|
*/
|
|
|
|
$.entwine('ss', function ($) {
|
|
|
|
|
2017-12-06 05:06:15 +01:00
|
|
|
const VIEW_TYPE_TREE = 'treeview';
|
|
|
|
const VIEW_TYPE_LIST = 'listview';
|
|
|
|
|
2016-01-26 05:28:36 +01:00
|
|
|
// Faux three column layout
|
|
|
|
$('.cms-content-header-info').entwine({
|
|
|
|
'from .cms-panel': {
|
|
|
|
// Keep the header info's width synced with the TreeView panel's width.
|
|
|
|
ontoggle: function (e) {
|
|
|
|
var $treeViewPanel = this.closest('.cms-content').find(e.target);
|
|
|
|
|
|
|
|
if ($treeViewPanel.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.parent()[$treeViewPanel.hasClass('collapsed') ? 'addClass' : 'removeClass']('collapsed');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-12-06 05:06:15 +01:00
|
|
|
/**
|
|
|
|
* Override super's `onadd` to modify url base the previously select view
|
|
|
|
* type.
|
|
|
|
*
|
|
|
|
* See $('.cms .cms-panel-link') in LeftAndMain.js
|
|
|
|
*/
|
|
|
|
$('.cms-panel-deferred.cms-content-view').entwine({
|
|
|
|
onadd: function() {
|
2017-12-07 04:24:01 +01:00
|
|
|
if(this.data('no-ajax')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var viewType = localStorage.getItem('ss.pages-view-type') || VIEW_TYPE_TREE;
|
|
|
|
if(this.closest('.cms-content-tools').length > 0) {
|
|
|
|
// Always use treeview when in page edit mode
|
|
|
|
viewType = VIEW_TYPE_TREE;
|
|
|
|
}
|
2017-12-06 05:06:15 +01:00
|
|
|
const url = this.data(`url-${viewType}`);
|
|
|
|
this.data('deferredNoCache', viewType === VIEW_TYPE_LIST);
|
2017-12-12 03:04:21 +01:00
|
|
|
this.data('url', url + location.search);
|
2017-12-06 05:06:15 +01:00
|
|
|
this._super();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-10-21 05:15:34 +02:00
|
|
|
// Customise tree / list view pjax tab loading
|
|
|
|
// See $('.cms .cms-panel-link') in LeftAndMain.js
|
2017-12-06 05:06:15 +01:00
|
|
|
$('.cms .page-view-link').entwine({
|
2016-10-21 05:15:34 +02:00
|
|
|
onclick: function(e){
|
2017-12-06 05:06:15 +01:00
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
const viewType = $(this).data('view');
|
|
|
|
const $contentView = this.closest('.cms-content-view');
|
|
|
|
var url = $contentView.data(`url-${viewType}`);
|
|
|
|
const isContentViewInSidebar = $contentView.closest('.cms-content-tools').length !== 0;
|
2016-10-26 03:01:13 +02:00
|
|
|
|
2017-12-06 05:06:15 +01:00
|
|
|
localStorage.setItem('ss.pages-view-type', viewType);
|
|
|
|
if(isContentViewInSidebar && viewType === VIEW_TYPE_LIST) {
|
2017-12-07 04:24:01 +01:00
|
|
|
window.location = $contentView.data('url-listviewroot');
|
2017-12-06 05:06:15 +01:00
|
|
|
return;
|
|
|
|
}
|
2016-10-26 03:01:13 +02:00
|
|
|
|
2017-12-12 03:04:21 +01:00
|
|
|
$contentView.data('url', url + location.search);
|
2017-12-06 05:06:15 +01:00
|
|
|
$contentView.redraw();
|
2016-10-21 05:15:34 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-12-07 04:24:01 +01:00
|
|
|
$('.cms .cms-clear-filter').entwine({
|
2017-12-13 06:16:34 +01:00
|
|
|
onclick: function(e) {
|
2017-12-07 04:24:01 +01:00
|
|
|
e.preventDefault();
|
2017-12-13 06:16:34 +01:00
|
|
|
window.location = $(this).prop('href');
|
2017-12-07 04:24:01 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-10-21 05:15:34 +02:00
|
|
|
|
2016-01-26 05:28:36 +01:00
|
|
|
$('.cms-content-toolbar').entwine({
|
|
|
|
|
|
|
|
onmatch: function () {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this._super();
|
|
|
|
|
|
|
|
// Initialise the buttons
|
|
|
|
$.each(this.find('.cms-actions-buttons-row .tool-button'), function () {
|
|
|
|
var $button = $(this),
|
|
|
|
toolId = $button.data('toolid'),
|
|
|
|
isActive = $button.hasClass('active');
|
|
|
|
|
|
|
|
// We don't care about tools that don't have a related 'action'.
|
|
|
|
if (toolId !== void 0) {
|
|
|
|
// Set the tool to its closed state.
|
|
|
|
$button.data('active', false).removeClass('active');
|
|
|
|
$('#' + toolId).hide();
|
|
|
|
|
|
|
|
self.bindActionButtonEvents($button);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onunmatch: function () {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this._super();
|
|
|
|
|
|
|
|
$.each(this.find('.cms-actions-buttons-row .tool-button'), function () {
|
|
|
|
var $button = $(this);
|
|
|
|
self.unbindActionButtonEvents($button);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @func bindActionButtonEvents
|
|
|
|
* @param {object} $button
|
|
|
|
* @desc Add event handlers in the '.cmsContentToolbar' namespace.
|
|
|
|
*/
|
|
|
|
bindActionButtonEvents: function ($button) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
$button.on('click.cmsContentToolbar', function (e) {
|
|
|
|
self.showHideTool($button);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @func unbindActionButtonEvents
|
|
|
|
* @param {object} $button
|
|
|
|
* @desc Remove all event handlers in the '.cmsContentToolbar' namespace.
|
|
|
|
*/
|
|
|
|
unbindActionButtonEvents: function ($button) {
|
|
|
|
$button.off('.cmsContentToolbar');
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @func showTool
|
|
|
|
* @param {object} $button
|
|
|
|
* @desc Show a tool in the tools row. Hides all other tools.
|
|
|
|
*/
|
|
|
|
showHideTool: function ($button) {
|
|
|
|
var isActive = $button.data('active'),
|
|
|
|
toolId = $button.data('toolid'),
|
|
|
|
$action = $('#' + toolId);
|
|
|
|
|
|
|
|
// Hide all tools except the one passed as a param,
|
|
|
|
// which gets handled separately.
|
|
|
|
$.each(this.find('.cms-actions-buttons-row .tool-button'), function () {
|
|
|
|
var $currentButton = $(this),
|
|
|
|
$currentAction = $('#' + $currentButton.data('toolid'));
|
|
|
|
|
|
|
|
if ($currentButton.data('toolid') !== toolId) {
|
|
|
|
$currentAction.hide();
|
|
|
|
$currentButton.data('active', false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$button[isActive ? 'removeClass' : 'addClass']('active');
|
|
|
|
$action[isActive ? 'hide' : 'show']();
|
|
|
|
$button.data('active', !isActive);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|