diff --git a/code/UserDefinedForm.php b/code/UserDefinedForm.php index 78d60e4..3c6ea2d 100755 --- a/code/UserDefinedForm.php +++ b/code/UserDefinedForm.php @@ -223,7 +223,7 @@ class UserDefinedForm_Controller extends Page_Controller { } // Is this Field Show by Default - if(!$field->ShowOnLoad) { + if(!$field->ShowOnLoad()) { $defaults .= "$(\"#" . $field->Name . "\").hide();\n"; } @@ -251,37 +251,35 @@ class UserDefinedForm_Controller extends Page_Controller { } // show or hide? - $view = (isset($dependency['Display']) && $dependency['Display'] == "Show") ? "show" : "hide"; + $view = (isset($dependency['Display']) && $dependency['Display'] == "Hide") ? "hide" : "show"; $opposite = ($view == "show") ? "hide" : "show"; // what action do we need to keep track of $Action = ($formFieldWatch->ClassName == "EditableTextField") ? "keyup" : "change"; + // is this field a special option field + $checkboxField = false; + if(in_array($formFieldWatch->ClassName, array('EditableCheckboxGroupField', 'EditableCheckbox'))) { + $checkboxField = true; + } + // and what should we evaluate switch($dependency['ConditionOption']) { case 'IsNotBlank': - $expression = '$(this).val() != ""'; - if(is_a($formFieldWatch, 'EditableCheckboxGroupField')) { - $expression = '$(this).attr("checked")'; - } + $expression = ($checkboxField) ? '$(this).attr("checked")' :'$(this).val() != ""'; + break; case 'IsBlank': - $expression = '$(this).val() == ""'; - if(is_a($formFieldWatch, 'EditableCheckboxGroupField')) { - $expression = '!($(this).attr("checked"))'; - } + $expression = ($checkboxField) ? '!($(this).attr("checked"))' : '$(this).val() == ""'; + break; case 'HasValue': - $expression = '$(this).val() == "'. $dependency['Value'] .'"'; - if(is_a($formFieldWatch, 'EditableCheckboxGroupField')) { - $expression = '$(this).attr("checked")'; - } + $expression = ($checkboxField) ? '$(this).attr("checked")' : '$(this).val() == "'. $dependency['Value'] .'"'; + break; default: - $expression = '$(this).val() != "'. $dependency['Value'] .'"'; - if(is_a($formFieldWatch, 'EditableCheckboxGroupField')) { - $expression = '!($(this).attr("checked"))'; - } + $expression = ($checkboxField) ? '!($(this).attr("checked"))' : '$(this).val() != "'. $dependency['Value'] .'"'; + break; } // put it all together @@ -536,7 +534,7 @@ class UserDefinedForm_EmailRecipient extends DataObject { ); if($this->Form()) { - $validEmailFields = DataObject::get("EditableFormField", "ParentID = '$this->FormID'"); + $validEmailFields = DataObject::get("EditableEmailField", "ParentID = '$this->FormID'"); if($validEmailFields) { $validEmailFields = $validEmailFields->toDropdownMap('ID', 'Title'); diff --git a/code/editor/EditableCheckbox.php b/code/editor/EditableCheckbox.php index 11d1c32..ddf9148 100755 --- a/code/editor/EditableCheckbox.php +++ b/code/editor/EditableCheckbox.php @@ -7,21 +7,24 @@ */ class EditableCheckbox extends EditableFormField { - static $singular_name = 'Checkbox'; + static $singular_name = 'Checkbox Field'; static $plural_name = 'Checkboxes'; - public function ExtraOptions() { - $fields = new FieldSet( - new CheckboxField("Fields[$this->ID][CustomSettings][Default]", _t('EditableFormField.CHECKEDBYDEFAULT', 'Checked by Default?'), $this->getSetting('Default')) - ); - $fields->merge(parent::ExtraOptions()); - return $fields; + public function getFieldConfiguration() { + $options = parent::getFieldConfiguration(); + $options->push(new CheckboxField("Fields[$this->ID][CustomSettings][Default]", _t('EditableFormField.CHECKEDBYDEFAULT', 'Checked by Default?'), $this->getSetting('Default'))); + return $options; } public function getFormField() { return new CheckboxField( $this->Name, $this->Title, $this->getSetting('Default')); } + + public function getValueFromData($data) { + $value = (isset($data[$this->Name])) ? $data[$this->Name] : false; + return ($value) ? _t('EditableFormField.YES', 'Yes') : _t('EditableFormField.NO', 'No'); + } } ?> \ No newline at end of file diff --git a/code/editor/EditableCheckboxGroupField.php b/code/editor/EditableCheckboxGroupField.php index c21f390..d67d626 100755 --- a/code/editor/EditableCheckboxGroupField.php +++ b/code/editor/EditableCheckboxGroupField.php @@ -8,9 +8,9 @@ */ class EditableCheckboxGroupField extends EditableMultipleOptionField { - static $singular_name = "Checkbox group"; + static $singular_name = "Checkbox Group"; - static $plural_name = "Checkbox groups"; + static $plural_name = "Checkbox Groups"; function getFormField() { $optionSet = $this->Options(); diff --git a/code/editor/EditableDateField.php b/code/editor/EditableDateField.php index cab9a53..a906ac4 100755 --- a/code/editor/EditableDateField.php +++ b/code/editor/EditableDateField.php @@ -8,19 +8,18 @@ */ class EditableDateField extends EditableFormField { - static $singular_name = 'Date field'; + static $singular_name = 'Date Field'; - static $plural_name = 'Date fields'; + static $plural_name = 'Date Fields'; function populateFromPostData($data) { $fieldPrefix = 'Default-'; - if( empty( $data['Default'] ) && !empty( $data[$fieldPrefix.'Year'] ) && !empty( $data[$fieldPrefix.'Month'] ) && !empty( $data[$fieldPrefix.'Day'] ) ) - $data['Default'] = $data['Year'] . '-' . $data['Month'] . '-' . $data['Day']; - - // Debug::show( $data ); - - parent::populateFromPostData( $data ); + if(empty($data['Default']) && !empty($data[$fieldPrefix.'Year']) && !empty($data[$fieldPrefix.'Month']) && !empty($data[$fieldPrefix.'Day'])) { + $data['Default'] = $data['Year'] . '-' . $data['Month'] . '-' . $data['Day']; + } + + parent::populateFromPostData($data); } /** diff --git a/code/editor/EditableDropdown.php b/code/editor/EditableDropdown.php index efe03d2..0efc32e 100755 --- a/code/editor/EditableDropdown.php +++ b/code/editor/EditableDropdown.php @@ -8,7 +8,7 @@ */ class EditableDropdown extends EditableMultipleOptionField { - static $singular_name = 'Dropdown'; + static $singular_name = 'Dropdown Field'; static $plural_name = 'Dropdowns'; diff --git a/code/editor/EditableEmailField.php b/code/editor/EditableEmailField.php index 5bd3fca..65a447d 100755 --- a/code/editor/EditableEmailField.php +++ b/code/editor/EditableEmailField.php @@ -8,9 +8,9 @@ */ class EditableEmailField extends EditableFormField { - static $singular_name = 'Email field'; + static $singular_name = 'Email Field'; - static $plural_name = 'Email fields'; + static $plural_name = 'Email Fields'; function getFormField() { return new EmailField($this->Name, $this->Title); diff --git a/code/editor/EditableFileField.php b/code/editor/EditableFileField.php index cd4255b..42df7a0 100755 --- a/code/editor/EditableFileField.php +++ b/code/editor/EditableFileField.php @@ -23,9 +23,9 @@ class EditableFileField extends EditableFormField { */ public static $allowed_extensions = array(); - static $singular_name = 'File field'; + static $singular_name = 'File Upload Field'; - static $plural_names = 'File fields'; + static $plural_names = 'File Fields'; public function getFormField() { return new FileField($this->Name, $this->Title); diff --git a/code/editor/EditableFormField.php b/code/editor/EditableFormField.php index 0347b34..8890a42 100755 --- a/code/editor/EditableFormField.php +++ b/code/editor/EditableFormField.php @@ -16,10 +16,8 @@ class EditableFormField extends DataObject { "Sort" => "Int", "Required" => "Boolean", "CanDelete" => "Boolean", - "CustomParameter" => "Varchar", "CustomErrorMessage" => "Varchar(255)", "CustomRules" => "Text", - "ShowOnLoad" => "Boolean", "CustomSettings" => "Text" ); @@ -74,6 +72,10 @@ class EditableFormField extends DataObject { return $this->class; } + function ShowOnLoad() { + return ($this->getSetting('ShowOnLoad') == "Show") ? true : false; + } + /** * To prevent having tables for each fields minor settings we store it as * a serialized array in the database. @@ -126,7 +128,7 @@ class EditableFormField extends DataObject { * * @return bool */ - public function hasAddableOptions() { + public function getHasAddableOptions() { return false; } @@ -157,12 +159,6 @@ class EditableFormField extends DataObject { $output = new DataObjectSet(); $fields = $this->Parent()->Fields(); - // add the default add - $output->push(new ArrayData(array( - 'Name' => $this->Name(), - 'AddableOption' => true, - 'Fields' => $fields - ))); // check for existing ones if($this->CustomRules) { $rules = unserialize($this->CustomRules); @@ -206,7 +202,7 @@ class EditableFormField extends DataObject { return "ID}][Title]\"$readOnlyAttr />"; } - + /** * Return the base name for this form field in the * form builder @@ -275,35 +271,27 @@ class EditableFormField extends DataObject { $this->write(); } - function ExtraOptions() { - - $baseName = "Fields[$this->ID]"; - $extraOptions = new FieldSet(); - - // Is this field required - if(!$this->Parent()->hasMethod('hideExtraOption')){ - $extraOptions->push(new CheckboxField($baseName . "[Required]", _t('EditableFormField.REQUIRED', 'Required?'), $this->Required)); - } - elseif(!$this->Parent()->hideExtraOption('Required')){ - $extraOptions->push(new CheckboxField($baseName . "[Required]", _t('EditableFormField.REQUIRED', 'Required?'), $this->Required)); - } - - if($this->Parent()->hasMethod('getExtraOptionsForField')) { - $extraFields = $this->Parent()->getExtraOptionsForField($this); - - foreach($extraFields as $extraField) { - $extraOptions->push($extraField); - } - } - - if($this->readonly) { - $extraOptions = $extraOptions->makeReadonly(); - } - - // custom error messaging - $extraOptions->push(new TextField($baseName.'[CustomErrorMessage]', _t('EditableFormField.CUSTOMERROR','Custom Error Message'), $this->CustomErrorMessage)); - - return $extraOptions; + /** + * Implement custom field Configuration on this field. Includes such things as + * settings and options of a given editable form field + * + * @return FieldSet + */ + public function getFieldConfiguration() { + return new FieldSet(); + } + + /** + * Append custom validation fields to the default 'Validation' + * section in the editable options view + * + * @return FieldSet + */ + public function getFieldValidationOptions() { + return new FieldSet( + new CheckboxField("Fields[$this->ID][Required]", _t('EditableFormField.REQUIRED', 'Is this field Required?'), $this->Required), + new TextField("Fields[$this->ID][CustomErrorMessage]", _t('EditableFormField.CUSTOMERROR','Custom Error Message'), $this->CustomErrorMessage) + ); } /** @@ -320,21 +308,21 @@ class EditableFormField extends DataObject { return true; } - function prepopulate( $value ) { - $this->prepopulateFromMap( $this->parsePrepopulateValue( $value ) ); + function prepopulate($value) { + $this->prepopulateFromMap($this->parsePrepopulateValue($value)); } - protected function parsePrepopulateValue( $value ) { - $paramList = explode( ',', $value ); + protected function parsePrepopulateValue($value) { + $paramList = explode(',', $value); $paramMap = array(); - foreach( $paramList as $param ) { + foreach($paramList as $param) { - if( preg_match( '/([^=]+)=(.+)/', $param, $match ) ) { - if( isset( $paramMap[$match[1]] ) && is_array( $paramMap[$match[1]] ) ) { + if(preg_match( '/([^=]+)=(.+)/', $param, $match)) { + if(isset($paramMap[$match[1]]) && is_array($paramMap[$match[1]])) { $paramMap[$match[1]][] = $match[2]; - } else if( isset( $paramMap[$match[1]] ) ) { - $paramMap[$match[1]] = array( $paramMap[$match[1]] ); + } else if(isset( $paramMap[$match[1]])) { + $paramMap[$match[1]] = array($paramMap[$match[1]]); $paramMap[$match[1]][] = $match[2]; } else { $paramMap[$match[1]] = $match[2]; @@ -344,7 +332,7 @@ class EditableFormField extends DataObject { return $paramMap; } - protected function prepopulateFromMap( $paramMap ) { + protected function prepopulateFromMap($paramMap) { foreach($paramMap as $field => $fieldValue) { if(!is_array($fieldValue)) { $this->$field = $fieldValue; @@ -355,11 +343,7 @@ class EditableFormField extends DataObject { function Type() { return $this->class; } - - function CustomParameter() { - return $this->CustomParameter; - } - + /** * Return the validation information related to this field. This is * interrupted as a JSON object for validate plugin and used in the diff --git a/code/editor/EditableFormHeading.php b/code/editor/EditableFormHeading.php index baaa0ba..27e5844 100755 --- a/code/editor/EditableFormHeading.php +++ b/code/editor/EditableFormHeading.php @@ -6,21 +6,21 @@ */ class EditableFormHeading extends EditableFormField { - static $singular_name = 'Form heading'; + static $singular_name = 'Heading'; - static $plural_name = 'Form headings'; + static $plural_name = 'Headings'; - function ExtraOptions() { + function getFieldConfiguration() { $levels = array('1' => '1','2' => '2','3' => '3','4' => '4','5' => '5','6' => '6'); $level = ($this->getSetting('Level')) ? $this->getSetting('Level') : 3; - $extraFields = new FieldSet( - new DropdownField("Fields[$this->ID][CustomSettings][Level]", _t('EditableFormHeading.LEVEL', 'Select Heading Level'), $levels, $level) - ); + + $options = parent::getFieldConfiguration(); + $options->push(new DropdownField("Fields[$this->ID][CustomSettings][Level]", _t('EditableFormHeading.LEVEL', 'Select Heading Level'), $levels, $level)); if($this->readonly) { - $extraFields = $extraFields->makeReadonly(); + $extraFields = $options->makeReadonly(); } - return $extraFields; + return $options; } function getFormField() { @@ -33,5 +33,9 @@ class EditableFormHeading extends EditableFormField { function showInReports() { return false; } + + function getFieldValidationOptions() { + return false; + } } ?> \ No newline at end of file diff --git a/code/editor/EditableLiteralField.php b/code/editor/EditableLiteralField.php index 9903f92..1a0990a 100644 --- a/code/editor/EditableLiteralField.php +++ b/code/editor/EditableLiteralField.php @@ -13,14 +13,10 @@ class EditableLiteralField extends EditableFormField { static $plural_name = 'HTML Blocks'; - function ExtraOptions() { - // eventually replace hard-coded "Fields"? - $baseName = "Fields[$this->ID]"; - - $extraFields = new FieldSet(); - $extraFields->push(new TextareaField($baseName . "[CustomSettings][Content]", "Text", 4, 20, $this->getSetting('Content'))); - - return $extraFields; + function getFieldOptions() { + return new FieldSet( + new TextareaField("Fields[$this->ID]" . "[CustomSettings][Content]", "HTML", 4, 20, $this->getSetting('Content')) + ); } function getFormField() { diff --git a/code/editor/EditableMemberListField.php b/code/editor/EditableMemberListField.php index 2f58f4c..8c60393 100644 --- a/code/editor/EditableMemberListField.php +++ b/code/editor/EditableMemberListField.php @@ -6,11 +6,11 @@ */ class EditableMemberListField extends EditableFormField { - static $singular_name = 'Member list field'; + static $singular_name = 'Member List Field'; - static $plural_name = 'Member list fields'; + static $plural_name = 'Member List Fields'; - function ExtraOptions() { + function getFieldConfiguration() { $groupID = ($this->getSetting('GroupID')) ? $this->getSetting('GroupID') : 0; $groups = DataObject::get("Group"); if($groups) $groups = $groups->toDropdownMap('ID', 'Title'); @@ -21,6 +21,7 @@ class EditableMemberListField extends EditableFormField { return $fields; } + function getFormField() { return ($this->getSetting('GroupID')) ? new DropdownField( $this->Name, $this->Title, Member::mapInGroups($this->getSetting('GroupID'))) : false; } diff --git a/code/editor/EditableMultipleOptionField.php b/code/editor/EditableMultipleOptionField.php index f432577..9146789 100644 --- a/code/editor/EditableMultipleOptionField.php +++ b/code/editor/EditableMultipleOptionField.php @@ -90,7 +90,7 @@ class EditableMultipleOptionField extends EditableFormField { * * @return bool */ - public function hasAddableOptions() { + public function getHasAddableOptions() { return true; } diff --git a/code/editor/FieldEditor.php b/code/editor/FieldEditor.php index c38524b..8020bcc 100755 --- a/code/editor/FieldEditor.php +++ b/code/editor/FieldEditor.php @@ -62,10 +62,11 @@ class FieldEditor extends FormField { if($fields) { array_shift($fields); // get rid of subclass 0 + asort($fields); // get in order $output = new DataObjectSet(); foreach($fields as $field => $title) { // get the nice title and strip out field - $niceTitle = trim(str_ireplace("Field", "", eval("return $title::\$singular_name;"))); + $niceTitle = trim(eval("return $title::\$singular_name;")); if($niceTitle) { $output->push(new ArrayData(array( 'ClassName' => $field, @@ -180,8 +181,7 @@ class FieldEditor extends FormField { public function addoptionfield() { // passed via the ajax $parent = (isset($_REQUEST['Parent'])) ? $_REQUEST['Parent'] : false; - $text = (isset($_REQUEST['Text'])) ? $_REQUEST['Text'] : ""; - + // work out the sort by getting the sort of the last field in the form +1 if($parent) { $sql_parent = Convert::raw2sql($parent); @@ -194,7 +194,6 @@ class FieldEditor extends FormField { $object->ParentID = $parent; $object->Sort = $sort; $object->Name = 'option' . $object->ID; - $object->Title = $text; $object->write(); return $object->EditSegment(); } diff --git a/css/FieldEditor.css b/css/FieldEditor.css index a9d50b2..b87be96 100755 --- a/css/FieldEditor.css +++ b/css/FieldEditor.css @@ -28,6 +28,7 @@ margin: 7px 0 0 4px; font-size: 11px; } + /* Options / Settings Area ---------------------------------------- */ .FormOptions { @@ -76,7 +77,7 @@ #Fields_fields .EditableFormField .delete { background: url(../../cms/images/delete.gif) no-repeat top left; } - + #Fields_fields .EditableFormField input { width: 250px; margin-left: 0px; @@ -123,6 +124,35 @@ float: left; display: block; } + #Fields_fields .EditableFormField a.addableOption, + #Fields_fields .EditableFormField a.addCondition { + background: url(../../cms/images/add.gif) no-repeat top left; + padding: 1px 0 2px 20px; + font-size: 12px; + width: auto; + margin-left: 3px; + } + /* Field Options Group */ + #Fields_fields .fieldOptionsGroup { + padding: 4px 8px 8px 8px; + margin: 5px; + border: 1px solid #bbb; + } + #Fields_fields .fieldOptionsGroup legend { + font-size: 15px; + padding: 0 4px; + } + /* Field Lengths */ + #Fields_fields .EditableFormField .fieldgroupField { + float: left; + } + #Fields_fields .EditableFormField .fieldgroupField label { + float: left; + padding: 0 4px; + } + #Fields_fields .EditableFormField .fieldgroupField input { + width: 80px; + } #Fields_fields .EditableFormField .middleColumn { background: none; } diff --git a/javascript/UserForm.js b/javascript/UserForm.js index 37171d6..89d4027 100644 --- a/javascript/UserForm.js +++ b/javascript/UserForm.js @@ -59,9 +59,9 @@ //update the internal lists var name = $("#Fields_fields li.EditableFormField:last").attr("id").split(' '); - //$("#Fields_fields select.fieldOption").each(function(i, domElement) { - // $(domElement).append(""); - //}); + $("#Fields_fields select.fieldOption").each(function(i, domElement) { + $(domElement).append(""); + }); }, // error creating new field @@ -146,16 +146,12 @@ var options = $(this).parent("li"); var action = $("#Form_EditForm").attr("action") + '/field/Fields/addoptionfield'; var parent = $(this).attr("rel"); - var text = $(this).parents("li").children(".text").val(); - - // clear input - $(this).parents("li").children(".text").val(""); //send ajax request to the page $.ajax({ type: "GET", url: action, - data: 'Parent='+ parent +"&Text="+ text, + data: 'Parent='+ parent, // create a new field success: function(msg){ @@ -177,8 +173,8 @@ */ $(".EditableFormField .deleteOption").livequery('click', function() { // pass the deleted status onto the element - $(this).parents("li").children("[type=text]").attr("value", "field-node-deleted"); - $(this).parents("li").hide(); + $(this).parent("li").children("[type=text]").attr("value", "field-node-deleted"); + $(this).parent("li").hide(); // Give the user some feedback statusMessage(ss.i18n._t('UserForms.REMOVINGOPTION', 'Removed Option')); @@ -260,29 +256,32 @@ // Give the user some feedback statusMessage(ss.i18n._t('UserForms.ADDINGNEWRULE', 'Adding New Rule')); - // get the parent li which to duplicate - var parent = $(this).parent("li"); - var grandParent = parent.parent("ul"); - var newCondition = parent.clone(); - // remove add icon - newCondition.find(".addCondition").hide(); - newCondition.find("a.hidden").removeClass("hidden"); + // get the fields li which to duplicate + var currentRules = $(this).parent("li").parent("ul"); + var defaultRule = currentRules.children("li.hidden:first"); + var newRule = defaultRule.clone(); - newCondition.children(".customRuleField").each(function(i, domElement) { - // go through and fix names. We need to insert an id number into the middle of them at least - $(domElement).val($(parent).find("select").eq(i).val()); + newRule.children(".customRuleField").each(function(i, domElement) { var currentName = domElement.name.split("]["); currentName[3] = currentName[2]; - currentName[2] = grandParent.children().size() + 1; + currentName[2] = currentRules.children().size() + 1; domElement.name = currentName.join("]["); }); - grandParent.append(newCondition); + // remove hidden tag + newRule.removeClass("hidden"); - // clear fields - parent.each(function(i, domElement) { - $(domElement).find(".customRuleField").val(""); + // update the fields dropdown + newRule.children("select.fieldOption").empty(); + + $("#Fields_fields li.EditableFormField").each(function (i, domElement) { + var name = $(this).attr("id").split(' '); + newRule.children("select.fieldOption").append(""); }); + + // append to the list + currentRules.append(newRule); + return false; }); }); diff --git a/templates/EditableFormField.ss b/templates/EditableFormField.ss index ee7a8bf..e849437 100755 --- a/templates/EditableFormField.ss +++ b/templates/EditableFormField.ss @@ -26,51 +26,100 @@ <% if showExtraOptions %>
<% end_if %> - \ No newline at end of file diff --git a/templates/Includes/CustomRule.ss b/templates/Includes/CustomRule.ss index 406dae2..87872d0 100644 --- a/templates/Includes/CustomRule.ss +++ b/templates/Includes/CustomRule.ss @@ -1,10 +1,10 @@ -