silverstripe-reports/javascript/AssetTableField.js
Ingo Schommer c467c926fd ENHANCEMENT Converted AssetAdmin and AssetTableField javascript to jquery-concrete
MINOR Moved AssetAdmin->movemarked() logic to AssetTableField

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92829 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-11-21 03:20:11 +00:00

88 lines
2.2 KiB
JavaScript

(function($) {
$.concrete('ss', function($){
$('.AssetTableField').concrete({
onmatch: function() {
var self = this;
// search button
this.find('input#FileFilterButton').click(function(e) {
var btn = $(this);
$(this).addClass('loading');
self.refresh(function() {btn.removeClass('loading');});
return false;
});
// clear button
this.find('input#FileFilterClearButton').click(function(e) {
self.find('input#FileSearch').val('');
self.find('input#FileFilterButton').click();
return false;
});
// search field
this.find('input#FileSearch').keypress(function(e) {
if(e.keyCode == $.ui.keyCode.ENTER) {
self.find('input#FileFilterButton').click();
}
});
this._super();
},
refresh: function(callback) {
var self = this;
this.load(
this.attr('href'),
this.find(':input').serialize(),
function(response, status, xmlhttp) {
Behaviour.apply(self[0], true);
if(callback) callback.apply(arguments);
}
);
}
});
/**
* Checkboxes used to batch delete files
*/
$('.AssetTableField :checkbox').concrete({
onchange: function() {
var container = this.parents('.AssetTableField');
var input = container.find('input#deletemarked');
if(container.find(':input[name=Files\[\]]:checked').length) {
input.removeAttr('disabled');
} else {
input.attr('disabled', 'disabled');
}
}
})
/**
* Batch delete files marked by checkboxes in the table.
* Refreshes the form field afterwards via ajax.
*/
$('.AssetTableField input#deletemarked').concrete({
onmatch: function() {
this.attr('disabled', 'disabled');
this._super();
},
onclick: function(e) {
if(!confirm(ss.i18n._t('AssetTableField.REALLYDELETE'))) return false;
var container = this.parents('.AssetTableField');
var self = this;
this.addClass('loading');
$.post(
container.attr('href') + '/deletemarked',
this.parents('form').serialize(),
function(data, status) {
self.removeClass('loading');
container.refresh();
}
);
return false;
}
});
});
}(jQuery));