API CHANGE Removed ThumbnailStripField class, as it was only used for the CMS image insertion logic (which was rewritten with a more powerful file selection based on GridField)

This commit is contained in:
Ingo Schommer 2012-02-10 17:58:04 +01:00
parent 490b87a0c5
commit c96e2ba7ca
4 changed files with 0 additions and 282 deletions

View File

@ -64,7 +64,6 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
'cmsmain.js',
array_merge(
array(
// CMS_DIR . '/javascript/ThumbnailStripField.js',
CMS_DIR . '/javascript/CMSMain.js',
CMS_DIR . '/javascript/CMSMain.EditForm.js',
CMS_DIR . '/javascript/CMSMain.AddForm.js',

View File

@ -1,194 +0,0 @@
<?php
/**
* Provides a strip of thumbnails showing all of the images in the system.
* It will be tied to a 'parent field' that will provide it with a filter by which to reduce the number
* of thumbnails displayed.
* @package cms
* @subpackage assets
*/
class ThumbnailStripField extends FormField {
protected $parentField;
protected $updateMethod;
/**
* If this is enabled, then ommitting a folderID when calling getimages will search ALL folders.
* This is the legacy behaviour.
*
* The new behaviour is to only search the root folder if a folderID is ommitted.
*
* @var boolean
*/
protected static $use_legacy_image_search = false;
/**
* setter for ThumbnailStripField::use_legacy_image_search
* @param boolean $enable
*/
public static function set_use_legacy_image_search($enable) {
self::$use_legacy_image_search = $enable;
}
/**
* getter for ThumbnailStripField::use_legacy_image_search
* @return boolean
*/
public static function get_use_legacy_image_search() {
return self::$use_legacy_image_search;
}
function __construct($name, $parentField, $updateMethod = "getimages") {
$this->parentField = $parentField;
$this->updateMethod = $updateMethod;
parent::__construct($name);
}
function ParentField() {
return $this->form->FormName() . '_' . $this->parentField;
}
function FieldHolder() {
Requirements::javascript(THIRDPARTY_DIR . '/prototype/prototype.js');
Requirements::javascript(THIRDPARTY_DIR . '/behaviour/behaviour.js');
Requirements::javascript(SAPPHIRE_DIR . '/javascript/prototype_improvements.js');
Requirements::javascript(CMS_DIR . '/javascript/ThumbnailStripField.js');
return $this->renderWith('ThumbnailStripField');
}
function UpdateMethod() {
return $this->updateMethod;
}
/**
* Populate the Thumbnail strip field, by looking for a folder,
* and the descendants of this folder.
*
* @see ThumbnailStripField::use_legacy_image_search
*/
function getimages() {
$result = '';
$images = null;
$whereSQL = '';
$folderID = isset($_GET['folderID']) ? (int) $_GET['folderID'] : 0;
$searchText = (isset($_GET['searchText']) && $_GET['searchText'] != 'undefined' && $_GET['searchText'] != 'null') ? Convert::raw2sql($_GET['searchText']) : '';
$folder = DataObject::get_by_id('Folder', (int) $_GET['folderID']);
if($folder) {
$folderList = $folder->getDescendantIDList();
array_unshift($folderList, $folder->ID);
$whereSQL = '"ParentID" IN (' . implode(', ', $folderList) . ')';
if($searchText) $whereSQL .= " AND \"Filename\" LIKE '%$searchText%'";
$images = DataObject::get('Image', $whereSQL, 'Title');
} else {
if (!self::$use_legacy_image_search) {
$whereSQL = "\"ParentID\" = 0";
} else {
$whereSQL = '';
// Prevent image search queries all images in the site initially when the page is loaded
if(empty($searchText)) $whereSQL = "\"ParentID\" = 0";
}
if($searchText) {
if (!empty($whereSQL)) $whereSQL .= " AND";
$whereSQL .= " \"Filename\" LIKE '%$searchText%'";
}
$images = DataObject::get('Image', $whereSQL, 'Title');
}
if($images) {
$result .= '<ul>';
foreach($images as $image) {
$thumbnail = $image->getFormattedImage('StripThumbnail');
if ($thumbnail instanceof Image_Cached) { //Hack here...
// Constrain the output image to a 600x600 square. This is passed to the destwidth/destheight in the class, which are then used to
// set width & height properties on the <img> tag inserted into the CMS. Resampling is done after save
$width = $image->Width;
$height = $image->Height;
if($width > 600) {
$height *= (600 / $width);
$width = 600;
}
if($height > 600) {
$width *= (600 / $height);
$height = 600;
}
$result .=
'<li>' .
'<a href="' . $image->Filename . '?r=' . rand(1,100000) . '" title="' . $image->Title . '">' .
'<img class="destwidth=' . round($width) . ',destheight=' . round($height) . '" src="'. $thumbnail->URL . '?r=' . rand(1,100000) . '" alt="' . $image->Title . '" />' .
'</a>' .
'</li>';
}
}
$result .= '</ul>';
}
else {
if($folder) {
$result = '<h2>' . _t('ThumbnailStripField.NOFOLDERIMAGESFOUND', 'No images found in') . ' ' . $folder->Title . '</h2>';
} else {
$result = '<h2>' . _t('ThumbnailStripField.NOIMAGESFOUND', 'No images found') . '</h2>';
}
}
return $result;
}
function getflash() {
$flashObjects = null;
$result = '';
$whereSQL = '';
$folderID = isset($_GET['folderID']) ? (int) $_GET['folderID'] : 0;
$searchText = (isset($_GET['searchText']) && $_GET['searchText'] != 'undefined' && $_GET['searchText'] != 'null') ? Convert::raw2sql($_GET['searchText']) : '';
$width = Image::$strip_thumbnail_width - 10;
$height = Image::$strip_thumbnail_height - 10;
$folder = DataObject::get_by_id("Folder", (int) $_GET['folderID']);
if($folder) {
$folderList = $folder->getDescendantIDList();
array_unshift($folderList, $folder->ID);
$whereSQL = "\"ParentID\" IN (" . implode(', ', $folderList) . ") AND \"Filename\" LIKE '%.swf'";
if($searchText) $whereSQL .= " AND \"Filename\" LIKE '%$searchText%'";
$flashObjects = DataObject::get('File', $whereSQL);
} else {
if($searchText) {
$flashObjects = DataObject::get('File', "\"Filename\" LIKE '%$searchText%' AND \"Filename\" LIKE '%.swf'");
}
}
if($flashObjects) {
$result .= '<ul>';
foreach($flashObjects as $flashObject) {
$result .= <<<HTML
<li>
<a href="$flashObject->URL" title="$flashObject->Title">
<img src="cms/images/flash_small.jpg" alt="spacer" />
<br />
$flashObject->Name
</a>
</li>
HTML;
}
$result .= '</ul>';
} else {
if($folder) {
$result = '<h2>' . _t('ThumbnailStripField.NOFOLDERFLASHFOUND', 'No flash files found in') . ' ' . $folder->Title . '</h2>';
} else {
$result = '<h2>' . _t('ThumbnailStripField.NOFLASHFOUND', 'No flash files found') . '</h2>';
}
}
return $result;
}
}

View File

@ -1,84 +0,0 @@
/**
* 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;
}
}

View File

@ -1,3 +0,0 @@
<div id="$Name" class="thumbnailstrip parent=$ParentField updatemethod=$updateMethod">
<h2><% _t('CHOOSEFOLDER','(Choose a folder or search above)') %></h2>
</div>