silverstripe-cms/javascript/AssetAdmin.js

74 lines
1.7 KiB
JavaScript

/**
* File: AssetAdmin.js
*/
(function($) {
/**
* Delete selected folders through "batch actions" tab.
*/
$(document).ready(function() {
$('#Form_BatchActionsForm').entwine('ss').register(
// TODO Hardcoding of base URL
'admin/assets/batchactions/delete',
function(ids) {
var confirmed = confirm(
ss.i18n.sprintf(
ss.i18n._t('AssetAdmin.BATCHACTIONSDELETECONFIRM'),
ids.length
)
);
return (confirmed) ? ids : false;
}
);
});
$.entwine('ss', function($){
$('#Form_EditForm_File .ss-gridfield-item').entwine({
onclick: function(e) {
var grid = this.closest('fieldset.ss-gridfield');
if(this.data('class') == 'Folder') {
var url = grid.data('urlFolderTemplate').replace('%s', this.data('id'));
$('.cms-container').loadPanel(url);
e.preventDefault();
}
}
});
/**
* Class: #Form_SyncForm
*/
$('#Form_SyncForm').entwine({
/**
* Function: onsubmit
*
* Parameters:
* (Event) e
*/
onsubmit: function(e) {
var button = jQuery(this).find(':submit:first');
button.addClass('loading');
$.ajax({
url: jQuery(this).attr('action'),
data: this.serializeArray(),
success: function() {
button.removeClass('loading');
// reload current form and tree
var currNode = $('.cms-tree')[0].firstSelected();
if(currNode) {
var url = $(currNode).find('a').attr('href');
$('.cms-content').loadForm(url);
}
$('.cms-tree')[0].setCustomURL('admin/assets/getsubtree');
$('.cms-tree')[0].reload({onSuccess: function() {
// TODO Reset current tree node
}});
}
});
return false;
}
});
});
}(jQuery));