2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* SimpleImageField provides an easy way of uploading images to Image has_one relationships.
|
|
|
|
* Unlike ImageField, it doesn't use an iframe.
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-files
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class SimpleImageField extends FileField {
|
|
|
|
|
2008-04-06 06:05:23 +02:00
|
|
|
function Field() {
|
|
|
|
$record = $this->form->getRecord();
|
|
|
|
$fieldName = $this->name;
|
|
|
|
if($record) {
|
|
|
|
$imageField = $record->$fieldName();
|
|
|
|
} else {
|
|
|
|
$imageField = "";
|
|
|
|
}
|
|
|
|
|
2008-04-09 13:15:02 +02:00
|
|
|
$html = "<div class=\"simpleimage\">";
|
|
|
|
$html .= $this->createTag("input",
|
|
|
|
array(
|
|
|
|
"type" => "file",
|
|
|
|
"name" => $this->name,
|
|
|
|
"id" => $this->id(),
|
|
|
|
"tabindex" => $this->getTabIndex()
|
|
|
|
)
|
2008-05-09 04:38:09 +02:00
|
|
|
);
|
2008-04-09 13:15:02 +02:00
|
|
|
$html .= $this->createTag("input",
|
|
|
|
array(
|
|
|
|
"type" => "hidden",
|
|
|
|
"name" => "MAX_FILE_SIZE",
|
|
|
|
"value" => $this->getAllowedMaxFileSize(),
|
|
|
|
"tabindex" => $this->getTabIndex()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
if($imageField && $imageField->exists()) {
|
|
|
|
if($imageField->hasMethod('Thumbnail') && $imageField->Thumbnail()) {
|
|
|
|
$html .= "<img src=\"".$imageField->Thumbnail()->URL()."\" />";
|
|
|
|
} else if($imageField->CMSThumbnail()) {
|
|
|
|
$html .= "<img src=\"".$imageField->CMSThumbnail()->URL()."\" />";
|
|
|
|
}
|
2008-04-06 06:05:23 +02:00
|
|
|
}
|
|
|
|
|
2008-04-09 13:15:02 +02:00
|
|
|
$html .= "</div>";
|
|
|
|
|
|
|
|
return $html;
|
2008-04-06 06:05:23 +02:00
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a readonly version of this field
|
|
|
|
*/
|
|
|
|
function performReadonlyTransformation() {
|
|
|
|
$field = new SimpleImageField_Disabled($this->name, $this->title, $this->value);
|
|
|
|
$field->setForm($this->form);
|
2008-08-12 04:58:48 +02:00
|
|
|
$field->setReadonly(true);
|
2007-07-19 12:40:28 +02:00
|
|
|
return $field;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-10 01:34:18 +01:00
|
|
|
/**
|
|
|
|
* Disabled version of {@link SimpleImageField}.
|
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-files
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
class SimpleImageField_Disabled extends FormField {
|
|
|
|
|
|
|
|
function Field() {
|
|
|
|
$record = $this->form->getRecord();
|
|
|
|
$fieldName = $this->name;
|
|
|
|
if($record) $imageField = $record->$fieldName();
|
|
|
|
|
|
|
|
$field = "<div class=\"simpleimage\">";
|
|
|
|
if($imageField && $imageField->exists()) {
|
|
|
|
if($imageField->hasMethod('Thumbnail')) $field .= "<img src=\"".$imageField->Thumbnail()->URL()."\" />";
|
|
|
|
elseif($imageField->CMSThumbnail()) $field .= "<img src=\"".$imageField->CMSThumbnail()->URL()."\" />";
|
|
|
|
else {} // This shouldn't be called but it sometimes is for some reason, so we don't do anything
|
|
|
|
}else{
|
2007-10-25 04:47:45 +02:00
|
|
|
$field .= "<label>" . _t('SimpleImageField.NOUPLOAD', 'No Image Uploaded') . "</label>";
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
$field .= "</div>";
|
|
|
|
return $field;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|