mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
85 lines
2.7 KiB
JavaScript
85 lines
2.7 KiB
JavaScript
/**
|
|
* File: ThumbnailStripField.js
|
|
*/
|
|
|
|
/**
|
|
* Class: ThumbnailStripField
|
|
*/
|
|
ThumbnailStripField = Class.create();
|
|
// We do this instead of div.thumbnailstrip for efficiency. It means that ThumbnailStripField can only be used in the
|
|
// CMS toolbar
|
|
ThumbnailStripField.applyTo('#FolderImages');
|
|
ThumbnailStripField.applyTo('#Flash');
|
|
ThumbnailStripField.prototype = {
|
|
|
|
/**
|
|
* @var updateMethod string Specifies the Ajax-call for getting files
|
|
* (currently either "getimages" or "getflash"). This can be specified
|
|
* in the PHP-constructor of ThumbnailStripField and is passed to the client
|
|
* as a fake css-class.
|
|
*/
|
|
updateMethod: 'getimages',
|
|
|
|
initialize: function() {
|
|
var self = this;
|
|
|
|
try {
|
|
this.updateMethod = this.className.match(/updatemethod=([^ ]+)/)[1];
|
|
} catch(err) {}
|
|
|
|
if(this.className.match(/parent=([^ ]+)/)) {
|
|
// HACK: This is hard-coded to only work with TreeDropdownFields
|
|
var inputField = $(RegExp.$1), parentField = inputField.parentNode;
|
|
if(parentField) jQuery(parentField).bind('change', function() {
|
|
self.ajaxGetFiles(jQuery(inputField).val());
|
|
});
|
|
|
|
var searchField = $$('#' + this.updateMethod + 'Search input')[0];
|
|
var timeout = undefined;
|
|
|
|
if(searchField) {
|
|
Event.observe(searchField, 'keypress', function(event) {
|
|
if(timeout != undefined) clearTimeout(timeout);
|
|
|
|
timeout = setTimeout(function() {
|
|
var searchText = searchField.value;
|
|
var folderID = null;
|
|
if (parentField && parentField.inputTag)
|
|
folderID = parentField.inputTag.value
|
|
$('Flash').ajaxGetFiles(folderID, searchText);
|
|
$('FolderImages').ajaxGetFiles(folderID, searchText);
|
|
}, 500);
|
|
});
|
|
}
|
|
}
|
|
},
|
|
|
|
ajaxGetFiles: function(folderID, searchText, callback) {
|
|
if(!callback) callback = this.reapplyBehaviour.bind(this);
|
|
var securityID = ($('SecurityID') ? '&SecurityID=' + $('SecurityID').value : '');
|
|
this.innerHTML = '<h2>Loading...</h2>';
|
|
var ajaxURL = this.helperURLBase() + '&methodName=' + this.updateMethod + '&folderID=' + folderID + '&searchText=' + searchText + securityID + '&cacheKillerDate=' + parseInt((new Date()).getTime()) + '&cacheKillerRand=' + parseInt(10000 * Math.random());
|
|
|
|
jQuery(this).load(ajaxURL, callback);
|
|
},
|
|
|
|
reapplyBehaviour: function() {
|
|
Behaviour.apply(this);
|
|
},
|
|
|
|
helperURLBase: function() {
|
|
var fieldName = this.id;
|
|
var ownerForm = this.ownerForm();
|
|
var securityID = ($('SecurityID') ? '&SecurityID=' + $('SecurityID').value : '');
|
|
|
|
return ownerForm.action + '?action_callfieldmethod=1&fieldName=' + fieldName + '&ajax=1' + securityID;
|
|
},
|
|
|
|
ownerForm: function() {
|
|
var f =this.parentNode;
|
|
while(f && f.tagName.toLowerCase() != 'form') f = f.parentNode;
|
|
return f;
|
|
}
|
|
|
|
}
|