Merge pull request #299 from ajoneil/sapphire

---

Conflicts:
	forms/NumericField.php
This commit is contained in:
Ingo Schommer 2012-04-11 15:36:35 +02:00
commit 6cd91ff449
57 changed files with 136 additions and 135 deletions

View File

@ -122,7 +122,7 @@ class Controller extends RequestHandler implements TemplateGlobalProvider {
* @return SS_HTTPResponse The response that this controller produces, * @return SS_HTTPResponse The response that this controller produces,
* including HTTP headers such as redirection info * including HTTP headers such as redirection info
*/ */
function handleRequest(SS_HTTPRequest $request, DataModel $model = null) { function handleRequest(SS_HTTPRequest $request, DataModel $model) {
if(!$request) user_error("Controller::handleRequest() not passed a request!", E_USER_ERROR); if(!$request) user_error("Controller::handleRequest() not passed a request!", E_USER_ERROR);
$this->pushCurrent(); $this->pushCurrent();

View File

@ -699,6 +699,7 @@ function errorHandler($errno, $errstr, $errfile, $errline) {
case E_USER_NOTICE: case E_USER_NOTICE:
case E_DEPRECATED: case E_DEPRECATED:
case E_USER_DEPRECATED: case E_USER_DEPRECATED:
case E_STRICT:
Debug::noticeHandler($errno, $errstr, $errfile, $errline, null); Debug::noticeHandler($errno, $errstr, $errfile, $errline, null);
break; break;
} }

View File

@ -53,6 +53,10 @@ class DebugView extends Object {
E_USER_WARNING => array( E_USER_WARNING => array(
'title' => 'User Warning', 'title' => 'User Warning',
'class' => 'warning' 'class' => 'warning'
),
E_STRICT => array(
'title' => 'Strict Notice',
'class' => 'notice'
) )
); );

View File

@ -28,7 +28,7 @@ class AjaxUniqueTextField extends TextField {
parent::__construct($name, $title, $value); parent::__construct($name, $title, $value);
} }
function Field() { function Field($properties = array()) {
Requirements::javascript(THIRDPARTY_DIR . "/prototype/prototype.js"); Requirements::javascript(THIRDPARTY_DIR . "/prototype/prototype.js");
Requirements::javascript(THIRDPARTY_DIR . "/behaviour/behaviour.js"); Requirements::javascript(THIRDPARTY_DIR . "/behaviour/behaviour.js");
Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang'); Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');

View File

@ -133,11 +133,6 @@ class CheckboxSetField extends OptionsetField {
return $this->customise($properties)->renderWith($this->getTemplate()); return $this->customise($properties)->renderWith($this->getTemplate());
} }
function setDisabled($val) {
$this->disabled = $val;
return $this;
}
/** /**
* Default selections, regardless of the {@link setValue()} settings. * Default selections, regardless of the {@link setValue()} settings.
* Note: Items marked as disabled through {@link setDisabledItems()} can still be * Note: Items marked as disabled through {@link setDisabledItems()} can still be
@ -180,7 +175,7 @@ class CheckboxSetField extends OptionsetField {
* *
* @param DataObject $record The record to save into * @param DataObject $record The record to save into
*/ */
function saveInto(DataObject $record) { function saveInto(DataObjectInterface $record) {
$fieldname = $this->name; $fieldname = $this->name;
$relation = ($fieldname && $record && $record->hasMethod($fieldname)) ? $record->$fieldname() : null; $relation = ($fieldname && $record && $record->hasMethod($fieldname)) ? $record->$fieldname() : null;
if($fieldname && $record && $relation && $relation instanceof RelationList) { if($fieldname && $record && $relation && $relation instanceof RelationList) {

View File

@ -206,7 +206,7 @@ class ComplexTableField extends TableListField {
/** /**
* @return String * @return String
*/ */
function FieldHolder() { function FieldHolder($properties = array()) {
Requirements::javascript(THIRDPARTY_DIR . "/prototype/prototype.js"); Requirements::javascript(THIRDPARTY_DIR . "/prototype/prototype.js");
Requirements::javascript(THIRDPARTY_DIR . "/behaviour/behaviour.js"); Requirements::javascript(THIRDPARTY_DIR . "/behaviour/behaviour.js");
Requirements::javascript(THIRDPARTY_DIR . "/greybox/AmiJS.js"); Requirements::javascript(THIRDPARTY_DIR . "/greybox/AmiJS.js");

View File

@ -134,7 +134,7 @@ class CompositeField extends FormField {
); );
} }
public function Field() { public function Field($properties = array()) {
$content = ''; $content = '';
if($this->tag == 'fieldset' && $this->legend) { if($this->tag == 'fieldset' && $this->legend) {
@ -158,7 +158,7 @@ class CompositeField extends FormField {
/** /**
* Returns the fields nested inside another DIV * Returns the fields nested inside another DIV
*/ */
function FieldHolder() { function FieldHolder($properties = array()) {
$content = ''; $content = '';
if($this->tag == 'fieldset' && $this->legend) { if($this->tag == 'fieldset' && $this->legend) {

View File

@ -93,7 +93,7 @@ class ConfirmedPasswordField extends FormField {
$this->setValue($value); $this->setValue($value);
} }
function Field() { function Field($properties = array()) {
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery/jquery.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery/jquery.js');
Requirements::javascript(SAPPHIRE_DIR . '/javascript/ConfirmedPasswordField.js'); Requirements::javascript(SAPPHIRE_DIR . '/javascript/ConfirmedPasswordField.js');
Requirements::css(SAPPHIRE_DIR . '/css/ConfirmedPasswordField.css'); Requirements::css(SAPPHIRE_DIR . '/css/ConfirmedPasswordField.css');
@ -286,7 +286,7 @@ class ConfirmedPasswordField extends FormField {
* @param DataObject $record * @param DataObject $record
* @return bool * @return bool
*/ */
function saveInto(DataObject $record) { function saveInto(DataObjectInterface $record) {
if(!$this->isSaveable()) return false; if(!$this->isSaveable()) return false;
if(!($this->canBeEmpty && !$this->value)) { if(!($this->canBeEmpty && !$this->value)) {

View File

@ -6,7 +6,7 @@
*/ */
class CreditCardField extends TextField { class CreditCardField extends TextField {
function Field() { function Field($properties = array()) {
$parts = $this->value; $parts = $this->value;
if(!is_array($parts)) $parts = explode("\n", chunk_split($parts,4,"\n")); if(!is_array($parts)) $parts = explode("\n", chunk_split($parts,4,"\n"));
$parts = array_pad($parts, 4, ""); $parts = array_pad($parts, 4, "");

View File

@ -67,7 +67,7 @@ class CurrencyField_Readonly extends ReadonlyField{
/** /**
* overloaded to display the correctly formated value for this datatype * overloaded to display the correctly formated value for this datatype
*/ */
function Field() { function Field($properties = array()) {
if($this->value){ if($this->value){
$val = $this->dontEscape ? $this->value : Convert::raw2xml($this->value); $val = $this->dontEscape ? $this->value : Convert::raw2xml($this->value);
$val = _t('CurrencyField.CURRENCYSYMBOL', '$') . number_format(preg_replace('/[^0-9.]/',"",$val), 2); $val = _t('CurrencyField.CURRENCYSYMBOL', '$') . number_format(preg_replace('/[^0-9.]/',"",$val), 2);
@ -100,7 +100,7 @@ class CurrencyField_Disabled extends CurrencyField{
/** /**
* overloaded to display the correctly formated value for this datatype * overloaded to display the correctly formated value for this datatype
*/ */
function Field() { function Field($properties = array()) {
if($this->value){ if($this->value){
$val = $this->dontEscape ? $this->value : Convert::raw2xml($this->value); $val = $this->dontEscape ? $this->value : Convert::raw2xml($this->value);
$val = _t('CurrencyField.CURRENCYSYMBOL', '$') . number_format(preg_replace('/[^0-9.]/',"",$val), 2); $val = _t('CurrencyField.CURRENCYSYMBOL', '$') . number_format(preg_replace('/[^0-9.]/',"",$val), 2);

View File

@ -32,8 +32,8 @@ class DatalessField extends FormField {
* Returns the field's representation in the form. * Returns the field's representation in the form.
* For dataless fields, this defaults to $Field. * For dataless fields, this defaults to $Field.
*/ */
function FieldHolder() { function FieldHolder($properties = array()) {
return $this->Field(); return $this->Field($properties);
} }
/** /**

View File

@ -110,7 +110,7 @@ class DateField extends TextField {
parent::__construct($name, $title, $value); parent::__construct($name, $title, $value);
} }
function FieldHolder() { function FieldHolder($properties = array()) {
// TODO Replace with properly extensible view helper system // TODO Replace with properly extensible view helper system
$d = DateField_View_JQuery::create($this); $d = DateField_View_JQuery::create($this);
$d->onBeforeRender(); $d->onBeforeRender();
@ -120,7 +120,7 @@ class DateField extends TextField {
return $html; return $html;
} }
function Field() { function Field($properties = array()) {
$config = array( $config = array(
'showcalendar' => $this->getConfig('showcalendar'), 'showcalendar' => $this->getConfig('showcalendar'),
'isoDateformat' => $this->getConfig('dateformat'), 'isoDateformat' => $this->getConfig('dateformat'),
@ -425,7 +425,7 @@ class DateField_Disabled extends DateField {
protected $disabled = true; protected $disabled = true;
function Field() { function Field($properties = array()) {
if($this->valueObj) { if($this->valueObj) {
if($this->valueObj->isToday()) { if($this->valueObj->isToday()) {
$val = Convert::raw2xml($this->valueObj->toString($this->getConfig('dateformat')) . ' ('._t('DateField.TODAY','today').')'); $val = Convert::raw2xml($this->valueObj->toString($this->getConfig('dateformat')) . ' ('._t('DateField.TODAY','today').')');

View File

@ -74,17 +74,17 @@ class DatetimeField extends FormField {
return $this; return $this;
} }
function FieldHolder() { function FieldHolder($properties = array()) {
$config = array( $config = array(
'datetimeorder' => $this->getConfig('datetimeorder'), 'datetimeorder' => $this->getConfig('datetimeorder'),
); );
$config = array_filter($config); $config = array_filter($config);
$this->addExtraClass(Convert::raw2json($config)); $this->addExtraClass(Convert::raw2json($config));
return parent::FieldHolder(); return parent::FieldHolder($properties);
} }
function Field() { function Field($properties = array()) {
Requirements::css(SAPPHIRE_DIR . '/css/DatetimeField.css'); Requirements::css(SAPPHIRE_DIR . '/css/DatetimeField.css');
$tzField = ($this->getConfig('usertimezone')) ? $this->timezoneField->FieldHolder() : ''; $tzField = ($this->getConfig('usertimezone')) ? $this->timezoneField->FieldHolder() : '';
@ -287,7 +287,7 @@ class DatetimeField_Readonly extends DatetimeField {
protected $readonly = true; protected $readonly = true;
function Field() { function Field($properties = array()) {
$valDate = $this->dateField->dataValue(); $valDate = $this->dateField->dataValue();
$valTime = $this->timeField->dataValue(); $valTime = $this->timeField->dataValue();
if($valDate && $valTime) { if($valDate && $valTime) {

View File

@ -238,12 +238,4 @@ class DropdownField extends FormField {
$field->setReadonly(true); $field->setReadonly(true);
return $field; return $field;
} }
/**
* Set form being disabled
*/
function setDisabled($disabled = true) {
$this->disabled = $disabled;
return $this;
}
} }

View File

@ -92,7 +92,7 @@ class FieldGroup extends CompositeField {
* @todo Shouldn't use SmallFieldHolder() (very difficult to style), * @todo Shouldn't use SmallFieldHolder() (very difficult to style),
* it is easier to overwrite the <div class="field"> behaviour in a more specific class * it is easier to overwrite the <div class="field"> behaviour in a more specific class
*/ */
function Field() { function Field($properties = array()) {
$fs = $this->FieldList(); $fs = $this->FieldList();
$spaceZebra = isset($this->zebra) ? " fieldgroup-$this->zebra" : ''; $spaceZebra = isset($this->zebra) ? " fieldgroup-$this->zebra" : '';
$idAtt = isset($this->id) ? " id=\"{$this->id}\"" : ''; $idAtt = isset($this->id) ? " id=\"{$this->id}\"" : '';
@ -131,7 +131,7 @@ class FieldGroup extends CompositeField {
return $this; return $this;
} }
function FieldHolder() { function FieldHolder($properties = array()) {
$Title = $this->XML_val('Title'); $Title = $this->XML_val('Title');
$Message = $this->XML_val('Message'); $Message = $this->XML_val('Message');
$MessageType = $this->XML_val('MessageType'); $MessageType = $this->XML_val('MessageType');

View File

@ -123,7 +123,7 @@ class FileField extends FormField {
); );
} }
public function saveInto(DataObject $record) { public function saveInto(DataObjectInterface $record) {
if(!isset($_FILES[$this->name])) return false; if(!isset($_FILES[$this->name])) return false;
$fileClass = File::get_class_for_file_extension(pathinfo($_FILES[$this->name]['name'], PATHINFO_EXTENSION)); $fileClass = File::get_class_for_file_extension(pathinfo($_FILES[$this->name]['name'], PATHINFO_EXTENSION));

View File

@ -60,7 +60,7 @@ class FileIFrameField extends FileField {
/** /**
* @return string * @return string
*/ */
public function Field() { public function Field($properties = array()) {
Deprecation::notice('3.0', 'Use UploadField'); Deprecation::notice('3.0', 'Use UploadField');
Requirements::css(SAPPHIRE_DIR . '/thirdparty/jquery-ui-themes/smoothness/jquery-ui.css'); Requirements::css(SAPPHIRE_DIR . '/thirdparty/jquery-ui-themes/smoothness/jquery-ui.css');

View File

@ -70,8 +70,8 @@ class FormAction extends FormField {
return $this->customise($properties)->renderWith($this->getTemplate()); return $this->customise($properties)->renderWith($this->getTemplate());
} }
function FieldHolder() { function FieldHolder($properties = array()) {
return $this->Field(); return $this->Field($properties);
} }
public function Type() { public function Type() {

View File

@ -39,7 +39,7 @@
*/ */
class GroupedDropdownField extends DropdownField { class GroupedDropdownField extends DropdownField {
function Field() { function Field($properties = array()) {
$options = ''; $options = '';
foreach($this->getSource() as $value => $title) { foreach($this->getSource() as $value => $title) {
if(is_array($title)) { if(is_array($title)) {

View File

@ -64,8 +64,8 @@ class HasManyComplexTableField extends ComplexTableField {
} }
function FieldHolder() { function FieldHolder($properties = array()) {
$ret = parent::FieldHolder(); $ret = parent::FieldHolder($properties);
Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang'); Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
Requirements::javascript(SAPPHIRE_DIR . "/javascript/HasManyFileField.js"); Requirements::javascript(SAPPHIRE_DIR . "/javascript/HasManyFileField.js");
@ -87,7 +87,7 @@ class HasManyComplexTableField extends ComplexTableField {
return $this->controller->ID; return $this->controller->ID;
} }
function saveInto(DataObject $record) { function saveInto(DataObjectInterface $record) {
$fieldName = $this->name; $fieldName = $this->name;
$saveDest = $record->$fieldName(); $saveDest = $record->$fieldName();

View File

@ -47,7 +47,7 @@ class HasOneComplexTableField extends HasManyComplexTableField {
return $this->controller->{$this->joinField}; return $this->controller->{$this->joinField};
} }
function saveInto(DataObject $record) { function saveInto(DataObjectInterface $record) {
$fieldName = $this->name; $fieldName = $this->name;
$fieldNameID = $fieldName . 'ID'; $fieldNameID = $fieldName . 'ID';

View File

@ -8,8 +8,8 @@ class HiddenField extends FormField {
protected $template = 'HiddenField'; protected $template = 'HiddenField';
function FieldHolder() { function FieldHolder($properties = array()) {
return $this->Field(); return $this->Field($properties);
} }
function performReadonlyTransformation() { function performReadonlyTransformation() {

View File

@ -56,7 +56,7 @@ class HtmlEditorField extends TextareaField {
/** /**
* @return string * @return string
*/ */
function Field() { function Field($properties = array()) {
// mark up broken links // mark up broken links
$value = new SS_HTMLValue($this->value); $value = new SS_HTMLValue($this->value);
@ -96,7 +96,7 @@ class HtmlEditorField extends TextareaField {
); );
} }
public function saveInto($record) { public function saveInto(DataObjectInterface $record) {
if($record->escapeTypeForField($this->name) != 'xml') { if($record->escapeTypeForField($this->name) != 'xml') {
throw new Exception ( throw new Exception (
'HtmlEditorField->saveInto(): This field should save into a HTMLText or HTMLVarchar field.' 'HtmlEditorField->saveInto(): This field should save into a HTMLText or HTMLVarchar field.'
@ -221,7 +221,7 @@ class HtmlEditorField extends TextareaField {
* @subpackage fields-formattedinput * @subpackage fields-formattedinput
*/ */
class HtmlEditorField_Readonly extends ReadonlyField { class HtmlEditorField_Readonly extends ReadonlyField {
function Field() { function Field($properties = array()) {
$valforInput = $this->value ? Convert::raw2att($this->value) : ""; $valforInput = $this->value ? Convert::raw2att($this->value) : "";
return "<span class=\"readonly typography\" id=\"" . $this->id() . "\">" . ( $this->value && $this->value != '<p></p>' ? $this->value : '<i>(not set)</i>' ) . "</span><input type=\"hidden\" name=\"".$this->name."\" value=\"".$valforInput."\" />"; return "<span class=\"readonly typography\" id=\"" . $this->id() . "\">" . ( $this->value && $this->value != '<p></p>' ? $this->value : '<i>(not set)</i>' ) . "</span><input type=\"hidden\" name=\"".$this->name."\" value=\"".$valforInput."\" />";
} }

View File

@ -26,7 +26,7 @@ class ImageFormAction extends FormAction {
parent::__construct($action, $title, $form); parent::__construct($action, $title, $form);
} }
function Field() { function Field($properties = array()) {
Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js'); Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
Requirements::javascript(SAPPHIRE_DIR . '/javascript/ImageFormAction.js'); Requirements::javascript(SAPPHIRE_DIR . '/javascript/ImageFormAction.js');

View File

@ -27,7 +27,7 @@ class InlineFormAction extends FormField {
return new InlineFormAction_ReadOnly( $this->name, $this->title ); return new InlineFormAction_ReadOnly( $this->name, $this->title );
} }
function Field() { function Field($properties = array()) {
if($this->includeDefaultJS) { if($this->includeDefaultJS) {
Requirements::javascriptTemplate(SAPPHIRE_DIR . '/javascript/InlineFormAction.js',array('ID'=>$this->id())); Requirements::javascriptTemplate(SAPPHIRE_DIR . '/javascript/InlineFormAction.js',array('ID'=>$this->id()));
} }
@ -59,7 +59,7 @@ class InlineFormAction_ReadOnly extends FormField {
protected $readonly = true; protected $readonly = true;
function Field() { function Field($properties = array()) {
return "<input type=\"submit\" name=\"action_{$this->name}\" value=\"{$this->title}\" id=\"{$this->id()}\" disabled=\"disabled\" class=\"action disabled$this->extraClass\" />"; return "<input type=\"submit\" name=\"action_{$this->name}\" value=\"{$this->title}\" id=\"{$this->id()}\" disabled=\"disabled\" class=\"action disabled$this->extraClass\" />";
} }

View File

@ -169,7 +169,7 @@ class ListboxField extends DropdownField {
* *
* @param DataObject $record The record to save into * @param DataObject $record The record to save into
*/ */
function saveInto(DataObject $record) { function saveInto(DataObjectInterface $record) {
if($this->multiple) { if($this->multiple) {
$fieldname = $this->name; $fieldname = $this->name;
$relation = ($fieldname && $record && $record->hasMethod($fieldname)) ? $record->$fieldname() : null; $relation = ($fieldname && $record && $record->hasMethod($fieldname)) ? $record->$fieldname() : null;

View File

@ -27,12 +27,19 @@ class LiteralField extends DatalessField {
parent::__construct($name); parent::__construct($name);
} }
function FieldHolder() { function FieldHolder($properties = array()) {
return is_object($this->content) ? $this->content->forTemplate() : $this->content; if(is_object($this->content)) {
$obj = $this->content;
if($properties)
$obj = $obj->customise($properties);
return $obj->forTemplate();
} else {
return $this->content;
}
} }
function Field() { function Field($properties = array()) {
return $this->FieldHolder(); return $this->FieldHolder($properties);
} }
/** /**

View File

@ -12,7 +12,7 @@ class LookupField extends DropdownField {
/** /**
* Returns a readonly span containing the correct value. * Returns a readonly span containing the correct value.
*/ */
function Field() { function Field($properties = array()) {
$source = $this->getSource(); $source = $this->getSource();

View File

@ -5,7 +5,7 @@
*/ */
class MemberDatetimeOptionsetField extends OptionsetField { class MemberDatetimeOptionsetField extends OptionsetField {
function Field() { function Field($properties = array()) {
$options = ''; $options = '';
$odd = 0; $odd = 0;
$source = $this->getSource(); $source = $this->getSource();

View File

@ -43,7 +43,7 @@ class MoneyField extends FormField {
/** /**
* @return string * @return string
*/ */
function Field() { function Field($properties = array()) {
return "<div class=\"fieldgroup\">" . return "<div class=\"fieldgroup\">" .
"<div class=\"fieldgroupField\">" . $this->fieldCurrency->SmallFieldHolder() . "</div>" . "<div class=\"fieldgroupField\">" . $this->fieldCurrency->SmallFieldHolder() . "</div>" .
"<div class=\"fieldgroupField\">" . $this->fieldAmount->SmallFieldHolder() . "</div>" . "<div class=\"fieldgroupField\">" . $this->fieldAmount->SmallFieldHolder() . "</div>" .
@ -100,7 +100,7 @@ class MoneyField extends FormField {
* *
* (see @link MoneyFieldTest_CustomSetter_Object for more information) * (see @link MoneyFieldTest_CustomSetter_Object for more information)
*/ */
function saveInto($dataObject) { function saveInto(DataObjectInterface $dataObject) {
$fieldName = $this->name; $fieldName = $this->name;
if($dataObject->hasMethod("set$fieldName")) { if($dataObject->hasMethod("set$fieldName")) {
$dataObject->$fieldName = DBField::create_field('Money', array( $dataObject->$fieldName = DBField::create_field('Money', array(

View File

@ -76,7 +76,7 @@ class NullableField extends FormField {
* (non-PHPdoc) * (non-PHPdoc)
* @see sapphire/forms/FormField#Field() * @see sapphire/forms/FormField#Field()
*/ */
function Field() { function Field($properties = array()) {
if ( $this->isReadonly()) { if ( $this->isReadonly()) {
$nullableCheckbox = new CheckboxField_Readonly($this->getIsNullId()); $nullableCheckbox = new CheckboxField_Readonly($this->getIsNullId());
} else { } else {

View File

@ -26,7 +26,7 @@ class PhoneNumberField extends FormField {
parent::__construct($name, $title, $value); parent::__construct($name, $title, $value);
} }
public function Field() { public function Field($properties = array()) {
$fields = new FieldGroup( $this->name ); $fields = new FieldGroup( $this->name );
$fields->setID("{$this->name}_Holder"); $fields->setID("{$this->name}_Holder");
list($countryCode, $areaCode, $phoneNumber, $extension) = $this->parseValue(); list($countryCode, $areaCode, $phoneNumber, $extension) = $this->parseValue();
@ -103,8 +103,7 @@ class PhoneNumberField extends FormField {
return $parts; return $parts;
} }
public function saveInto( $record ) { public function saveInto(DataObjectInterface $record) {
list( $countryCode, $areaCode, $phoneNumber, $extension ) = $this->parseValue(); list( $countryCode, $areaCode, $phoneNumber, $extension ) = $this->parseValue();
$fieldName = $this->name; $fieldName = $this->name;

View File

@ -25,7 +25,7 @@ class PrintableTransformation_TabSet extends TabSet {
CompositeField::__construct($tabs); CompositeField::__construct($tabs);
} }
function FieldHolder() { function FieldHolder($properties = array()) {
// This gives us support for sub-tabs. // This gives us support for sub-tabs.
$tag = ($this->tabSet) ? "h2>" : "h1>"; $tag = ($this->tabSet) ? "h2>" : "h1>";

View File

@ -85,12 +85,14 @@ class SelectionGroup extends CompositeField {
return true; return true;
} }
function FieldHolder() { function FieldHolder($properties = array()) {
Requirements::javascript(THIRDPARTY_DIR .'/jquery/jquery.js'); Requirements::javascript(THIRDPARTY_DIR .'/jquery/jquery.js');
Requirements::javascript(SAPPHIRE_DIR . '/javascript/SelectionGroup.js'); Requirements::javascript(SAPPHIRE_DIR . '/javascript/SelectionGroup.js');
Requirements::css(SAPPHIRE_DIR . '/css/SelectionGroup.css'); Requirements::css(SAPPHIRE_DIR . '/css/SelectionGroup.css');
return $this->renderWith($this->template); $obj = $properties ? $this->customise($properties) : $this;
return $obj->renderWith($this->template);
} }
} }

View File

@ -78,7 +78,7 @@ class SimpleImageField extends FileField {
$this->getValidator()->setAllowedExtensions(array('jpg','gif','png')); $this->getValidator()->setAllowedExtensions(array('jpg','gif','png'));
} }
function Field() { function Field($properties = array()) {
if($this->form) $record = $this->form->getRecord(); if($this->form) $record = $this->form->getRecord();
$fieldName = $this->name; $fieldName = $this->name;
if(isset($record)&&$record) { if(isset($record)&&$record) {
@ -141,7 +141,7 @@ class SimpleImageField_Disabled extends FormField {
protected $readonly = true; protected $readonly = true;
function Field() { function Field($properties = array()) {
$record = $this->form->getRecord(); $record = $this->form->getRecord();
$fieldName = $this->name; $fieldName = $this->name;

View File

@ -69,7 +69,7 @@ class TabSet extends CompositeField {
* Returns a tab-strip and the associated tabs. * Returns a tab-strip and the associated tabs.
* The HTML is a standardised format, containing a &lt;ul; * The HTML is a standardised format, containing a &lt;ul;
*/ */
public function FieldHolder() { public function FieldHolder($properties = array()) {
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery/jquery.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery/jquery.js');
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-ui/jquery-ui.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-ui/jquery-ui.js');
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-cookie/jquery.cookie.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-cookie/jquery.cookie.js');
@ -80,7 +80,8 @@ class TabSet extends CompositeField {
Requirements::javascript(SAPPHIRE_DIR . '/javascript/TabSet.js'); Requirements::javascript(SAPPHIRE_DIR . '/javascript/TabSet.js');
return $this->renderWith($this->template); $obj = $properties ? $this->customise($properties) : $this;
return $obj->renderWith($this->template);
} }
/** /**

View File

@ -231,7 +231,7 @@ class TableField extends TableListField {
/** /**
* Saves the Dataobjects contained in the field * Saves the Dataobjects contained in the field
*/ */
function saveInto(DataObject $record) { function saveInto(DataObjectInterface $record) {
// CMS sometimes tries to set the value to one. // CMS sometimes tries to set the value to one.
if(is_array($this->value)){ if(is_array($this->value)){
$newFields = array(); $newFields = array();
@ -463,7 +463,7 @@ class TableField extends TableListField {
/** /**
* Sets the template to be rendered with * Sets the template to be rendered with
*/ */
function FieldHolder() { function FieldHolder($properties = array()) {
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery/jquery.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery/jquery.js');
Requirements::javascript(THIRDPARTY_DIR . "/prototype/prototype.js"); Requirements::javascript(THIRDPARTY_DIR . "/prototype/prototype.js");
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/behaviour/behaviour.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/behaviour/behaviour.js');
@ -472,7 +472,8 @@ class TableField extends TableListField {
Requirements::javascript(SAPPHIRE_DIR . '/javascript/TableField.js'); Requirements::javascript(SAPPHIRE_DIR . '/javascript/TableField.js');
Requirements::css(SAPPHIRE_DIR . '/css/TableListField.css'); Requirements::css(SAPPHIRE_DIR . '/css/TableListField.css');
return $this->renderWith($this->template); $obj = $properties ? $this->customise($properties) : $this;
return $obj->renderWith($this->template);
} }
function setTransformationConditions($conditions) { function setTransformationConditions($conditions) {

View File

@ -278,7 +278,7 @@ class TableListField extends FormField {
return new TableListField_ItemRequest($this, $request->param('ID')); return new TableListField_ItemRequest($this, $request->param('ID'));
} }
function FieldHolder() { function FieldHolder($properties = array()) {
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery/jquery.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery/jquery.js');
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/prototype/prototype.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/prototype/prototype.js');
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/behaviour/behaviour.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/behaviour/behaviour.js');
@ -299,7 +299,9 @@ class TableListField extends FormField {
}); });
JS JS
);} );}
return $this->renderWith($this->template);
$obj = $properties ? $this->customise($properties) : $this;
return $obj->renderWith($this->template);
} }
function Headings() { function Headings() {

View File

@ -63,13 +63,13 @@ class TimeField extends TextField {
parent::__construct($name,$title,$value); parent::__construct($name,$title,$value);
} }
function Field() { function Field($properties = array()) {
$config = array( $config = array(
'timeformat' => $this->getConfig('timeformat') 'timeformat' => $this->getConfig('timeformat')
); );
$config = array_filter($config); $config = array_filter($config);
$this->addExtraClass(Convert::raw2json($config)); $this->addExtraClass(Convert::raw2json($config));
return parent::Field(); return parent::Field($properties);
} }
function Type() { function Type() {
@ -206,7 +206,7 @@ class TimeField_Readonly extends TimeField {
protected $readonly = true; protected $readonly = true;
function Field() { function Field($properties = array()) {
if($this->valueObj) { if($this->valueObj) {
$val = Convert::raw2xml($this->valueObj->toString($this->getConfig('timeformat'))); $val = Convert::raw2xml($this->valueObj->toString($this->getConfig('timeformat')));
} else { } else {

View File

@ -22,12 +22,13 @@ class ToggleCompositeField extends CompositeField {
parent::__construct($children); parent::__construct($children);
} }
public function FieldHolder() { public function FieldHolder($properties = array()) {
Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/prototype/prototype.js"); Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/prototype/prototype.js");
Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/behaviour/behaviour.js"); Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/behaviour/behaviour.js");
Requirements::javascript(SAPPHIRE_DIR . "/javascript/ToggleCompositeField.js"); Requirements::javascript(SAPPHIRE_DIR . "/javascript/ToggleCompositeField.js");
return $this->renderWith($this->template); $obj = $properties ? $this->customise($properties) : $this;
return $obj->renderWith($this->template);
} }
/** /**

View File

@ -46,7 +46,7 @@ class ToggleField extends ReadonlyField {
parent::__construct($name, $title, $value); parent::__construct($name, $title, $value);
} }
function Field() { function Field($properties = array()) {
$content = ''; $content = '';
Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/prototype/prototype.js"); Requirements::javascript(SAPPHIRE_DIR . "/thirdparty/prototype/prototype.js");

View File

@ -78,7 +78,7 @@ class TreeMultiselectField extends TreeDropdownField {
* We overwrite the field attribute to add our hidden fields, as this * We overwrite the field attribute to add our hidden fields, as this
* formfield can contain multiple values. * formfield can contain multiple values.
*/ */
function Field() { function Field($properties = array()) {
Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang'); Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery/jquery.js'); Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery/jquery.js');
@ -132,7 +132,7 @@ class TreeMultiselectField extends TreeDropdownField {
* Calls function $record->onChange($items) before saving to the assummed * Calls function $record->onChange($items) before saving to the assummed
* Component set. * Component set.
*/ */
function saveInto(DataObject $record) { function saveInto(DataObjectInterface $record) {
// Detect whether this field has actually been updated // Detect whether this field has actually been updated
if($this->value !== 'unchanged') { if($this->value !== 'unchanged') {
$items = array(); $items = array();
@ -178,7 +178,7 @@ class TreeMultiselectField_Readonly extends TreeMultiselectField {
protected $readonly = true; protected $readonly = true;
function Field() { function Field($properties = array()) {
$titleArray = $itemIDs = array(); $titleArray = $itemIDs = array();
$titleList = $itemIDsList = ""; $titleList = $itemIDsList = "";
if($items = $this->getItems()) { if($items = $this->getItems()) {

View File

@ -310,7 +310,7 @@ class UploadField extends FileField {
); );
} }
public function Field() { public function Field($properties = array()) {
$record = $this->getRecord(); $record = $this->getRecord();
$name = $this->getName(); $name = $this->getName();

View File

@ -289,7 +289,7 @@ class GridField extends FormField {
* *
* @return string * @return string
*/ */
public function FieldHolder() { public function FieldHolder($properties = array()) {
Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css'); Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css');
Requirements::css(SAPPHIRE_DIR . '/css/GridField.css'); Requirements::css(SAPPHIRE_DIR . '/css/GridField.css');
@ -448,8 +448,8 @@ class GridField extends FormField {
); );
} }
public function Field() { public function Field($properties = array()) {
return $this->FieldHolder(); return $this->FieldHolder($properties);
} }
public function getAttributes() { public function getAttributes() {

View File

@ -596,7 +596,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
if(!array_key_exists($k, $customFields)) continue; if(!array_key_exists($k, $customFields)) continue;
$dbObj = ($v instanceof DBField) ? $v : $this->dbObject($k); $dbObj = ($v instanceof DBField) ? $v : $this->dbObject($k);
$isEmpty = ($isEmpty && !$dbObj->hasValue()); $isEmpty = ($isEmpty && !$dbObj->exists());
} }
} }
return $isEmpty; return $isEmpty;
@ -3346,7 +3346,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
function hasValue($field, $arguments = null, $cache = true) { function hasValue($field, $arguments = null, $cache = true) {
$obj = $this->dbObject($field); $obj = $this->dbObject($field);
if($obj) { if($obj) {
return $obj->hasValue(); return $obj->exists();
} else { } else {
return parent::hasValue($field, $arguments, $cache); return parent::hasValue($field, $arguments, $cache);
} }

View File

@ -177,6 +177,6 @@ interface CompositeDBField {
* *
* @return boolean * @return boolean
*/ */
function hasValue(); function exists();
} }

View File

@ -120,6 +120,7 @@ abstract class DBField extends ViewableData {
$this->value = $value; $this->value = $value;
} }
/** /**
* Determines if the field has a value which * Determines if the field has a value which
* is not considered to be 'null' in * is not considered to be 'null' in
@ -127,15 +128,8 @@ abstract class DBField extends ViewableData {
* *
* @return boolean * @return boolean
*/ */
function hasValue() {
return ($this->value);
}
/**
* @return bool
*/
public function exists() { public function exists() {
return $this->hasValue(); return ($this->value);
} }
/** /**
@ -167,7 +161,7 @@ abstract class DBField extends ViewableData {
* @param array $manipulation * @param array $manipulation
*/ */
function writeToManipulation(&$manipulation) { function writeToManipulation(&$manipulation) {
$manipulation['fields'][$this->name] = $this->hasValue() ? $this->prepValueForDB($this->value) : $this->nullValue(); $manipulation['fields'][$this->name] = $this->exists() ? $this->prepValueForDB($this->value) : $this->nullValue();
} }
/** /**

View File

@ -128,8 +128,8 @@ class HTMLText extends Text {
return ShortcodeParser::get_active()->parse($this->value); return ShortcodeParser::get_active()->parse($this->value);
} }
public function hasValue() { public function exists() {
return parent::hasValue() && $this->value != '<p></p>'; return parent::exists() && $this->value != '<p></p>';
} }
public function scaffoldFormField($title = null, $params = null) { public function scaffoldFormField($title = null, $params = null) {

View File

@ -14,8 +14,8 @@ class HTMLVarchar extends Varchar {
return ShortcodeParser::get_active()->parse($this->value); return ShortcodeParser::get_active()->parse($this->value);
} }
public function hasValue() { public function exists() {
return parent::hasValue() && $this->value != '<p></p>'; return parent::exists() && $this->value != '<p></p>';
} }
public function scaffoldFormField($title = null, $params = null) { public function scaffoldFormField($title = null, $params = null) {

View File

@ -102,7 +102,7 @@ class Money extends DBField implements CompositeDBField {
function setValue($value, $record = null, $markChanged = true) { function setValue($value, $record = null, $markChanged = true) {
// @todo Allow resetting value to NULL through Money $value field // @todo Allow resetting value to NULL through Money $value field
if ($value instanceof Money && $value->hasValue()) { if ($value instanceof Money && $value->exists()) {
$this->setCurrency($value->getCurrency(), $markChanged); $this->setCurrency($value->getCurrency(), $markChanged);
$this->setAmount($value->getAmount(), $markChanged); $this->setAmount($value->getAmount(), $markChanged);
if($markChanged) $this->isChanged = true; if($markChanged) $this->isChanged = true;
@ -190,7 +190,7 @@ class Money extends DBField implements CompositeDBField {
/** /**
* @return boolean * @return boolean
*/ */
function hasValue() { function exists() {
return ($this->getCurrency() && is_numeric($this->getAmount())); return ($this->getCurrency() && is_numeric($this->getAmount()));
} }

View File

@ -64,9 +64,9 @@ abstract class StringField extends DBField {
/** /**
* (non-PHPdoc) * (non-PHPdoc)
* @see core/model/fieldtypes/DBField#hasValue() * @see core/model/fieldtypes/DBField#exists()
*/ */
function hasValue() { function exists() {
return ($this->value || $this->value == '0') || ( !$this->nullifyEmpty && $this->value === ''); return ($this->value || $this->value == '0') || ( !$this->nullifyEmpty && $this->value === '');
} }

View File

@ -56,7 +56,7 @@ class Varchar extends StringField {
* Return the first letter of the string followed by a . * Return the first letter of the string followed by a .
*/ */
function Initial() { function Initial() {
if($this->hasValue()) return $this->value[0] . '.'; if($this->exists()) return $this->value[0] . '.';
} }
/** /**

View File

@ -70,7 +70,7 @@ class PermissionCheckboxSetField extends FormField {
return $this->hiddenPermissions; return $this->hiddenPermissions;
} }
function Field() { function Field($properties = array()) {
Requirements::css(SAPPHIRE_DIR . '/css/CheckboxSetField.css'); Requirements::css(SAPPHIRE_DIR . '/css/CheckboxSetField.css');
Requirements::javascript(SAPPHIRE_DIR . '/javascript/PermissionCheckboxSetField.js'); Requirements::javascript(SAPPHIRE_DIR . '/javascript/PermissionCheckboxSetField.js');
@ -215,7 +215,7 @@ class PermissionCheckboxSetField extends FormField {
* *
* @param DataObject $record * @param DataObject $record
*/ */
function saveInto(DataObject $record) { function saveInto(DataObjectInterface $record) {
$fieldname = $this->name; $fieldname = $this->name;
$managedClass = $this->managedClass; $managedClass = $this->managedClass;

View File

@ -157,42 +157,42 @@ class DBFieldTest extends SapphireTest {
$this->assertEquals("00:00:00", $time->getValue()); $this->assertEquals("00:00:00", $time->getValue());
} }
function testHasValue() { function testExists() {
$varcharField = new Varchar("testfield"); $varcharField = new Varchar("testfield");
$this->assertTrue($varcharField->getNullifyEmpty()); $this->assertTrue($varcharField->getNullifyEmpty());
$varcharField->setValue('abc'); $varcharField->setValue('abc');
$this->assertTrue($varcharField->hasValue()); $this->assertTrue($varcharField->exists());
$varcharField->setValue(''); $varcharField->setValue('');
$this->assertFalse($varcharField->hasValue()); $this->assertFalse($varcharField->exists());
$varcharField->setValue(null); $varcharField->setValue(null);
$this->assertFalse($varcharField->hasValue()); $this->assertFalse($varcharField->exists());
$varcharField = new Varchar("testfield", 50, array('nullifyEmpty'=>false)); $varcharField = new Varchar("testfield", 50, array('nullifyEmpty'=>false));
$this->assertFalse($varcharField->getNullifyEmpty()); $this->assertFalse($varcharField->getNullifyEmpty());
$varcharField->setValue('abc'); $varcharField->setValue('abc');
$this->assertTrue($varcharField->hasValue()); $this->assertTrue($varcharField->exists());
$varcharField->setValue(''); $varcharField->setValue('');
$this->assertTrue($varcharField->hasValue()); $this->assertTrue($varcharField->exists());
$varcharField->setValue(null); $varcharField->setValue(null);
$this->assertFalse($varcharField->hasValue()); $this->assertFalse($varcharField->exists());
$textField = new Text("testfield"); $textField = new Text("testfield");
$this->assertTrue($textField->getNullifyEmpty()); $this->assertTrue($textField->getNullifyEmpty());
$textField->setValue('abc'); $textField->setValue('abc');
$this->assertTrue($textField->hasValue()); $this->assertTrue($textField->exists());
$textField->setValue(''); $textField->setValue('');
$this->assertFalse($textField->hasValue()); $this->assertFalse($textField->exists());
$textField->setValue(null); $textField->setValue(null);
$this->assertFalse($textField->hasValue()); $this->assertFalse($textField->exists());
$textField = new Text("testfield", array('nullifyEmpty'=>false)); $textField = new Text("testfield", array('nullifyEmpty'=>false));
$this->assertFalse($textField->getNullifyEmpty()); $this->assertFalse($textField->getNullifyEmpty());
$textField->setValue('abc'); $textField->setValue('abc');
$this->assertTrue($textField->hasValue()); $this->assertTrue($textField->exists());
$textField->setValue(''); $textField->setValue('');
$this->assertTrue($textField->hasValue()); $this->assertTrue($textField->exists());
$textField->setValue(null); $textField->setValue(null);
$this->assertFalse($textField->hasValue()); $this->assertFalse($textField->exists());
} }
function testStringFieldsWithMultibyteData() { function testStringFieldsWithMultibyteData() {

View File

@ -207,23 +207,23 @@ class MoneyTest extends SapphireTest {
); );
} }
function testHasValue() { function testExists() {
$m1 = new Money(); $m1 = new Money();
$this->assertFalse($m1->hasValue()); $this->assertFalse($m1->exists());
$m2 = new Money(); $m2 = new Money();
$m2->setValue(array( $m2->setValue(array(
'Currency' => 'EUR', 'Currency' => 'EUR',
'Amount' => 3.44 'Amount' => 3.44
)); ));
$this->assertTrue($m2->hasValue()); $this->assertTrue($m2->exists());
$m3 = new Money(); $m3 = new Money();
$m3->setValue(array( $m3->setValue(array(
'Currency' => 'EUR', 'Currency' => 'EUR',
'Amount' => 0 'Amount' => 0
)); ));
$this->assertTrue($m3->hasValue()); $this->assertTrue($m3->exists());
} }
function testLoadIntoDataObject() { function testLoadIntoDataObject() {

View File

@ -269,16 +269,16 @@ class FalseOnlyPackrat extends Parser {
* @author Hamish Friedlander * @author Hamish Friedlander
*/ */
class ConservativePackrat extends Parser { class ConservativePackrat extends Parser {
function packhas( $key ) { function packhas( $key, $pos ) {
return isset( $this->packres[$key] ) && $this->packres[$key] !== NULL ; return isset( $this->packres[$key] ) && $this->packres[$key] !== NULL ;
} }
function packread( $key ) { function packread( $key, $pos ) {
$this->pos = $this->packpos[$key]; $this->pos = $this->packpos[$key];
return $this->packres[$key] ; return $this->packres[$key] ;
} }
function packwrite( $key, $res ) { function packwrite( $key, $pos, $res ) {
if ( isset( $this->packres[$key] ) ) { if ( isset( $this->packres[$key] ) ) {
$this->packres[$key] = $res ; $this->packres[$key] = $res ;
$this->packpos[$key] = $this->pos ; $this->packpos[$key] = $this->pos ;

View File

@ -719,7 +719,9 @@ class SSViewer {
if(isset($this->chosenTemplates['main'])) { if(isset($this->chosenTemplates['main'])) {
$template = $this->chosenTemplates['main']; $template = $this->chosenTemplates['main'];
} else { } else {
$template = $this->chosenTemplates[ reset($dummy = array_keys($this->chosenTemplates)) ]; $keys = array_keys($this->chosenTemplates);
$key = reset($keys);
$template = $this->chosenTemplates[$key];
} }
if(isset($_GET['debug_profile'])) Profiler::mark("SSViewer::process", " for $template"); if(isset($_GET['debug_profile'])) Profiler::mark("SSViewer::process", " for $template");