2010-05-08 04:45:05 +02:00
|
|
|
/**
|
|
|
|
* File: ThumbnailStripField.js
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class: ThumbnailStripField
|
|
|
|
*/
|
2007-07-19 12:40:05 +02:00
|
|
|
ThumbnailStripField = Class.create();
|
|
|
|
// We do this instead of div.thumbnailstrip for efficiency. It means that ThumbnailStripField can only be used in the
|
|
|
|
// CMS toolbar
|
2009-06-15 05:19:44 +02:00
|
|
|
ThumbnailStripField.applyTo('#FolderImages');
|
2007-07-19 12:40:05 +02:00
|
|
|
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.
|
|
|
|
*/
|
2008-11-13 05:55:23 +01:00
|
|
|
updateMethod: 'getimages',
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
initialize: function() {
|
|
|
|
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 parentField = $(RegExp.$1).parentNode;
|
|
|
|
if(parentField) {
|
|
|
|
parentField.observeMethod('Change', this.ajaxGetFiles.bind(this));
|
|
|
|
}
|
2008-11-13 05:55:23 +01:00
|
|
|
|
2008-11-13 06:37:10 +01:00
|
|
|
var searchField = $$('#' + this.updateMethod + 'Search input')[0];
|
2008-11-13 05:55:23 +01:00
|
|
|
var timeout = undefined;
|
|
|
|
|
|
|
|
if(searchField) {
|
|
|
|
Event.observe(searchField, 'keypress', function(event) {
|
|
|
|
if(timeout != undefined) clearTimeout(timeout);
|
|
|
|
|
|
|
|
timeout = setTimeout(function() {
|
|
|
|
var searchText = searchField.value;
|
|
|
|
|
2008-11-13 06:37:10 +01:00
|
|
|
$('Flash').ajaxGetFiles(null, searchText);
|
2009-07-02 01:34:39 +02:00
|
|
|
$('FolderImages').ajaxGetFiles(null, searchText);
|
2008-11-13 05:55:23 +01:00
|
|
|
}, 500);
|
|
|
|
});
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-11-13 05:55:23 +01:00
|
|
|
ajaxGetFiles: function(folderID, searchText, callback) {
|
2007-09-16 04:21:47 +02:00
|
|
|
if(!callback) callback = this.reapplyBehaviour.bind(this);
|
2008-11-13 05:55:23 +01:00
|
|
|
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());
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
new Ajax.Updater(this, ajaxURL, {
|
|
|
|
method : 'get',
|
2007-09-16 04:21:47 +02:00
|
|
|
onComplete : callback,
|
2007-07-19 12:40:05 +02:00
|
|
|
onFailure : function(response) { errorMessage("Error getting files", response); }
|
2007-09-16 04:21:47 +02:00
|
|
|
});
|
2007-07-19 12:40:05 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
reapplyBehaviour: function() {
|
|
|
|
Behaviour.apply(this);
|
|
|
|
},
|
|
|
|
|
|
|
|
helperURLBase: function() {
|
2008-11-13 05:55:23 +01:00
|
|
|
var fieldName = this.id;
|
|
|
|
var ownerForm = this.ownerForm();
|
|
|
|
var securityID = ($('SecurityID') ? '&SecurityID=' + $('SecurityID').value : '');
|
2007-07-19 12:40:05 +02:00
|
|
|
|
2008-11-13 05:55:23 +01:00
|
|
|
return ownerForm.action + '?action_callfieldmethod=1&fieldName=' + fieldName + '&ajax=1' + securityID;
|
2007-07-19 12:40:05 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
ownerForm: function() {
|
|
|
|
var f =this.parentNode;
|
|
|
|
while(f && f.tagName.toLowerCase() != 'form') f = f.parentNode;
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2007-11-07 05:50:09 +01:00
|
|
|
}
|