APICHANGE: changed ExtraOptions() to getFieldOptions() and getFieldValidationOptions(). MINOR: fixed layout of userforms in the cms. MINOR: updated checkbox field to respond with Yes and No rather then 0 and 1. MINOR: changed behaviour or email field selector to only get email field values in popup.

This commit is contained in:
Will Rossiter 2009-05-06 03:34:40 +00:00
parent cf35c706e4
commit 626f09be39
17 changed files with 243 additions and 182 deletions

View File

@ -223,7 +223,7 @@ class UserDefinedForm_Controller extends Page_Controller {
} }
// Is this Field Show by Default // Is this Field Show by Default
if(!$field->ShowOnLoad) { if(!$field->ShowOnLoad()) {
$defaults .= "$(\"#" . $field->Name . "\").hide();\n"; $defaults .= "$(\"#" . $field->Name . "\").hide();\n";
} }
@ -251,37 +251,35 @@ class UserDefinedForm_Controller extends Page_Controller {
} }
// show or hide? // 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"; $opposite = ($view == "show") ? "hide" : "show";
// what action do we need to keep track of // what action do we need to keep track of
$Action = ($formFieldWatch->ClassName == "EditableTextField") ? "keyup" : "change"; $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 // and what should we evaluate
switch($dependency['ConditionOption']) { switch($dependency['ConditionOption']) {
case 'IsNotBlank': case 'IsNotBlank':
$expression = '$(this).val() != ""'; $expression = ($checkboxField) ? '$(this).attr("checked")' :'$(this).val() != ""';
if(is_a($formFieldWatch, 'EditableCheckboxGroupField')) {
$expression = '$(this).attr("checked")';
}
break; break;
case 'IsBlank': case 'IsBlank':
$expression = '$(this).val() == ""'; $expression = ($checkboxField) ? '!($(this).attr("checked"))' : '$(this).val() == ""';
if(is_a($formFieldWatch, 'EditableCheckboxGroupField')) {
$expression = '!($(this).attr("checked"))';
}
break; break;
case 'HasValue': case 'HasValue':
$expression = '$(this).val() == "'. $dependency['Value'] .'"'; $expression = ($checkboxField) ? '$(this).attr("checked")' : '$(this).val() == "'. $dependency['Value'] .'"';
if(is_a($formFieldWatch, 'EditableCheckboxGroupField')) {
$expression = '$(this).attr("checked")';
}
break; break;
default: default:
$expression = '$(this).val() != "'. $dependency['Value'] .'"'; $expression = ($checkboxField) ? '!($(this).attr("checked"))' : '$(this).val() != "'. $dependency['Value'] .'"';
if(is_a($formFieldWatch, 'EditableCheckboxGroupField')) {
$expression = '!($(this).attr("checked"))';
}
break; break;
} }
// put it all together // put it all together
@ -536,7 +534,7 @@ class UserDefinedForm_EmailRecipient extends DataObject {
); );
if($this->Form()) { if($this->Form()) {
$validEmailFields = DataObject::get("EditableFormField", "ParentID = '$this->FormID'"); $validEmailFields = DataObject::get("EditableEmailField", "ParentID = '$this->FormID'");
if($validEmailFields) { if($validEmailFields) {
$validEmailFields = $validEmailFields->toDropdownMap('ID', 'Title'); $validEmailFields = $validEmailFields->toDropdownMap('ID', 'Title');

View File

@ -7,21 +7,24 @@
*/ */
class EditableCheckbox extends EditableFormField { class EditableCheckbox extends EditableFormField {
static $singular_name = 'Checkbox'; static $singular_name = 'Checkbox Field';
static $plural_name = 'Checkboxes'; static $plural_name = 'Checkboxes';
public function ExtraOptions() { public function getFieldConfiguration() {
$fields = new FieldSet( $options = parent::getFieldConfiguration();
new CheckboxField("Fields[$this->ID][CustomSettings][Default]", _t('EditableFormField.CHECKEDBYDEFAULT', 'Checked by Default?'), $this->getSetting('Default')) $options->push(new CheckboxField("Fields[$this->ID][CustomSettings][Default]", _t('EditableFormField.CHECKEDBYDEFAULT', 'Checked by Default?'), $this->getSetting('Default')));
); return $options;
$fields->merge(parent::ExtraOptions());
return $fields;
} }
public function getFormField() { public function getFormField() {
return new CheckboxField( $this->Name, $this->Title, $this->getSetting('Default')); 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');
}
} }
?> ?>

View File

@ -8,9 +8,9 @@
*/ */
class EditableCheckboxGroupField extends EditableMultipleOptionField { 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() { function getFormField() {
$optionSet = $this->Options(); $optionSet = $this->Options();

View File

@ -8,19 +8,18 @@
*/ */
class EditableDateField extends EditableFormField { 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) { function populateFromPostData($data) {
$fieldPrefix = 'Default-'; $fieldPrefix = 'Default-';
if( empty( $data['Default'] ) && !empty( $data[$fieldPrefix.'Year'] ) && !empty( $data[$fieldPrefix.'Month'] ) && !empty( $data[$fieldPrefix.'Day'] ) ) if(empty($data['Default']) && !empty($data[$fieldPrefix.'Year']) && !empty($data[$fieldPrefix.'Month']) && !empty($data[$fieldPrefix.'Day'])) {
$data['Default'] = $data['Year'] . '-' . $data['Month'] . '-' . $data['Day']; $data['Default'] = $data['Year'] . '-' . $data['Month'] . '-' . $data['Day'];
}
// Debug::show( $data );
parent::populateFromPostData($data);
parent::populateFromPostData( $data );
} }
/** /**

View File

@ -8,7 +8,7 @@
*/ */
class EditableDropdown extends EditableMultipleOptionField { class EditableDropdown extends EditableMultipleOptionField {
static $singular_name = 'Dropdown'; static $singular_name = 'Dropdown Field';
static $plural_name = 'Dropdowns'; static $plural_name = 'Dropdowns';

View File

@ -8,9 +8,9 @@
*/ */
class EditableEmailField extends EditableFormField { 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() { function getFormField() {
return new EmailField($this->Name, $this->Title); return new EmailField($this->Name, $this->Title);

View File

@ -23,9 +23,9 @@ class EditableFileField extends EditableFormField {
*/ */
public static $allowed_extensions = array(); 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() { public function getFormField() {
return new FileField($this->Name, $this->Title); return new FileField($this->Name, $this->Title);

View File

@ -16,10 +16,8 @@ class EditableFormField extends DataObject {
"Sort" => "Int", "Sort" => "Int",
"Required" => "Boolean", "Required" => "Boolean",
"CanDelete" => "Boolean", "CanDelete" => "Boolean",
"CustomParameter" => "Varchar",
"CustomErrorMessage" => "Varchar(255)", "CustomErrorMessage" => "Varchar(255)",
"CustomRules" => "Text", "CustomRules" => "Text",
"ShowOnLoad" => "Boolean",
"CustomSettings" => "Text" "CustomSettings" => "Text"
); );
@ -74,6 +72,10 @@ class EditableFormField extends DataObject {
return $this->class; 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 * To prevent having tables for each fields minor settings we store it as
* a serialized array in the database. * a serialized array in the database.
@ -126,7 +128,7 @@ class EditableFormField extends DataObject {
* *
* @return bool * @return bool
*/ */
public function hasAddableOptions() { public function getHasAddableOptions() {
return false; return false;
} }
@ -157,12 +159,6 @@ class EditableFormField extends DataObject {
$output = new DataObjectSet(); $output = new DataObjectSet();
$fields = $this->Parent()->Fields(); $fields = $this->Parent()->Fields();
// add the default add
$output->push(new ArrayData(array(
'Name' => $this->Name(),
'AddableOption' => true,
'Fields' => $fields
)));
// check for existing ones // check for existing ones
if($this->CustomRules) { if($this->CustomRules) {
$rules = unserialize($this->CustomRules); $rules = unserialize($this->CustomRules);
@ -206,7 +202,7 @@ class EditableFormField extends DataObject {
return "<input type=\"text\" class=\"text\" title=\"("._t('EditableFormField.ENTERQUESTION', 'Enter Question').")\" value=\"$titleAttr\" name=\"Fields[{$this->ID}][Title]\"$readOnlyAttr />"; return "<input type=\"text\" class=\"text\" title=\"("._t('EditableFormField.ENTERQUESTION', 'Enter Question').")\" value=\"$titleAttr\" name=\"Fields[{$this->ID}][Title]\"$readOnlyAttr />";
} }
/** /**
* Return the base name for this form field in the * Return the base name for this form field in the
* form builder * form builder
@ -275,35 +271,27 @@ class EditableFormField extends DataObject {
$this->write(); $this->write();
} }
function ExtraOptions() { /**
* Implement custom field Configuration on this field. Includes such things as
$baseName = "Fields[$this->ID]"; * settings and options of a given editable form field
$extraOptions = new FieldSet(); *
* @return FieldSet
// Is this field required */
if(!$this->Parent()->hasMethod('hideExtraOption')){ public function getFieldConfiguration() {
$extraOptions->push(new CheckboxField($baseName . "[Required]", _t('EditableFormField.REQUIRED', 'Required?'), $this->Required)); return new FieldSet();
} }
elseif(!$this->Parent()->hideExtraOption('Required')){
$extraOptions->push(new CheckboxField($baseName . "[Required]", _t('EditableFormField.REQUIRED', 'Required?'), $this->Required)); /**
} * Append custom validation fields to the default 'Validation'
* section in the editable options view
if($this->Parent()->hasMethod('getExtraOptionsForField')) { *
$extraFields = $this->Parent()->getExtraOptionsForField($this); * @return FieldSet
*/
foreach($extraFields as $extraField) { public function getFieldValidationOptions() {
$extraOptions->push($extraField); 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)
);
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;
} }
/** /**
@ -320,21 +308,21 @@ class EditableFormField extends DataObject {
return true; return true;
} }
function prepopulate( $value ) { function prepopulate($value) {
$this->prepopulateFromMap( $this->parsePrepopulateValue( $value ) ); $this->prepopulateFromMap($this->parsePrepopulateValue($value));
} }
protected function parsePrepopulateValue( $value ) { protected function parsePrepopulateValue($value) {
$paramList = explode( ',', $value ); $paramList = explode(',', $value);
$paramMap = array(); $paramMap = array();
foreach( $paramList as $param ) { foreach($paramList as $param) {
if( preg_match( '/([^=]+)=(.+)/', $param, $match ) ) { if(preg_match( '/([^=]+)=(.+)/', $param, $match)) {
if( isset( $paramMap[$match[1]] ) && is_array( $paramMap[$match[1]] ) ) { if(isset($paramMap[$match[1]]) && is_array($paramMap[$match[1]])) {
$paramMap[$match[1]][] = $match[2]; $paramMap[$match[1]][] = $match[2];
} else if( isset( $paramMap[$match[1]] ) ) { } else if(isset( $paramMap[$match[1]])) {
$paramMap[$match[1]] = array( $paramMap[$match[1]] ); $paramMap[$match[1]] = array($paramMap[$match[1]]);
$paramMap[$match[1]][] = $match[2]; $paramMap[$match[1]][] = $match[2];
} else { } else {
$paramMap[$match[1]] = $match[2]; $paramMap[$match[1]] = $match[2];
@ -344,7 +332,7 @@ class EditableFormField extends DataObject {
return $paramMap; return $paramMap;
} }
protected function prepopulateFromMap( $paramMap ) { protected function prepopulateFromMap($paramMap) {
foreach($paramMap as $field => $fieldValue) { foreach($paramMap as $field => $fieldValue) {
if(!is_array($fieldValue)) { if(!is_array($fieldValue)) {
$this->$field = $fieldValue; $this->$field = $fieldValue;
@ -355,11 +343,7 @@ class EditableFormField extends DataObject {
function Type() { function Type() {
return $this->class; return $this->class;
} }
function CustomParameter() {
return $this->CustomParameter;
}
/** /**
* Return the validation information related to this field. This is * Return the validation information related to this field. This is
* interrupted as a JSON object for validate plugin and used in the * interrupted as a JSON object for validate plugin and used in the

View File

@ -6,21 +6,21 @@
*/ */
class EditableFormHeading extends EditableFormField { 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'); $levels = array('1' => '1','2' => '2','3' => '3','4' => '4','5' => '5','6' => '6');
$level = ($this->getSetting('Level')) ? $this->getSetting('Level') : 3; $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) { if($this->readonly) {
$extraFields = $extraFields->makeReadonly(); $extraFields = $options->makeReadonly();
} }
return $extraFields; return $options;
} }
function getFormField() { function getFormField() {
@ -33,5 +33,9 @@ class EditableFormHeading extends EditableFormField {
function showInReports() { function showInReports() {
return false; return false;
} }
function getFieldValidationOptions() {
return false;
}
} }
?> ?>

View File

@ -13,14 +13,10 @@ class EditableLiteralField extends EditableFormField {
static $plural_name = 'HTML Blocks'; static $plural_name = 'HTML Blocks';
function ExtraOptions() { function getFieldOptions() {
// eventually replace hard-coded "Fields"? return new FieldSet(
$baseName = "Fields[$this->ID]"; new TextareaField("Fields[$this->ID]" . "[CustomSettings][Content]", "HTML", 4, 20, $this->getSetting('Content'))
);
$extraFields = new FieldSet();
$extraFields->push(new TextareaField($baseName . "[CustomSettings][Content]", "Text", 4, 20, $this->getSetting('Content')));
return $extraFields;
} }
function getFormField() { function getFormField() {

View File

@ -6,11 +6,11 @@
*/ */
class EditableMemberListField extends EditableFormField { 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; $groupID = ($this->getSetting('GroupID')) ? $this->getSetting('GroupID') : 0;
$groups = DataObject::get("Group"); $groups = DataObject::get("Group");
if($groups) $groups = $groups->toDropdownMap('ID', 'Title'); if($groups) $groups = $groups->toDropdownMap('ID', 'Title');
@ -21,6 +21,7 @@ class EditableMemberListField extends EditableFormField {
return $fields; return $fields;
} }
function getFormField() { function getFormField() {
return ($this->getSetting('GroupID')) ? new DropdownField( $this->Name, $this->Title, Member::mapInGroups($this->getSetting('GroupID'))) : false; return ($this->getSetting('GroupID')) ? new DropdownField( $this->Name, $this->Title, Member::mapInGroups($this->getSetting('GroupID'))) : false;
} }

View File

@ -90,7 +90,7 @@ class EditableMultipleOptionField extends EditableFormField {
* *
* @return bool * @return bool
*/ */
public function hasAddableOptions() { public function getHasAddableOptions() {
return true; return true;
} }

View File

@ -62,10 +62,11 @@ class FieldEditor extends FormField {
if($fields) { if($fields) {
array_shift($fields); // get rid of subclass 0 array_shift($fields); // get rid of subclass 0
asort($fields); // get in order
$output = new DataObjectSet(); $output = new DataObjectSet();
foreach($fields as $field => $title) { foreach($fields as $field => $title) {
// get the nice title and strip out field // 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) { if($niceTitle) {
$output->push(new ArrayData(array( $output->push(new ArrayData(array(
'ClassName' => $field, 'ClassName' => $field,
@ -180,8 +181,7 @@ class FieldEditor extends FormField {
public function addoptionfield() { public function addoptionfield() {
// passed via the ajax // passed via the ajax
$parent = (isset($_REQUEST['Parent'])) ? $_REQUEST['Parent'] : false; $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 // work out the sort by getting the sort of the last field in the form +1
if($parent) { if($parent) {
$sql_parent = Convert::raw2sql($parent); $sql_parent = Convert::raw2sql($parent);
@ -194,7 +194,6 @@ class FieldEditor extends FormField {
$object->ParentID = $parent; $object->ParentID = $parent;
$object->Sort = $sort; $object->Sort = $sort;
$object->Name = 'option' . $object->ID; $object->Name = 'option' . $object->ID;
$object->Title = $text;
$object->write(); $object->write();
return $object->EditSegment(); return $object->EditSegment();
} }

View File

@ -28,6 +28,7 @@
margin: 7px 0 0 4px; margin: 7px 0 0 4px;
font-size: 11px; font-size: 11px;
} }
/* Options / Settings Area /* Options / Settings Area
---------------------------------------- */ ---------------------------------------- */
.FormOptions { .FormOptions {
@ -76,7 +77,7 @@
#Fields_fields .EditableFormField .delete { #Fields_fields .EditableFormField .delete {
background: url(../../cms/images/delete.gif) no-repeat top left; background: url(../../cms/images/delete.gif) no-repeat top left;
} }
#Fields_fields .EditableFormField input { #Fields_fields .EditableFormField input {
width: 250px; width: 250px;
margin-left: 0px; margin-left: 0px;
@ -123,6 +124,35 @@
float: left; float: left;
display: block; 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 { #Fields_fields .EditableFormField .middleColumn {
background: none; background: none;
} }

View File

@ -59,9 +59,9 @@
//update the internal lists //update the internal lists
var name = $("#Fields_fields li.EditableFormField:last").attr("id").split(' '); var name = $("#Fields_fields li.EditableFormField:last").attr("id").split(' ');
//$("#Fields_fields select.fieldOption").each(function(i, domElement) { $("#Fields_fields select.fieldOption").each(function(i, domElement) {
// $(domElement).append("<option='"+ name[2] +"'>New "+ name[2] + "</option>"); $(domElement).append("<option='"+ name[2] +"'>New "+ name[2] + "</option>");
//}); });
}, },
// error creating new field // error creating new field
@ -146,16 +146,12 @@
var options = $(this).parent("li"); var options = $(this).parent("li");
var action = $("#Form_EditForm").attr("action") + '/field/Fields/addoptionfield'; var action = $("#Form_EditForm").attr("action") + '/field/Fields/addoptionfield';
var parent = $(this).attr("rel"); 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 //send ajax request to the page
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: action, url: action,
data: 'Parent='+ parent +"&Text="+ text, data: 'Parent='+ parent,
// create a new field // create a new field
success: function(msg){ success: function(msg){
@ -177,8 +173,8 @@
*/ */
$(".EditableFormField .deleteOption").livequery('click', function() { $(".EditableFormField .deleteOption").livequery('click', function() {
// pass the deleted status onto the element // pass the deleted status onto the element
$(this).parents("li").children("[type=text]").attr("value", "field-node-deleted"); $(this).parent("li").children("[type=text]").attr("value", "field-node-deleted");
$(this).parents("li").hide(); $(this).parent("li").hide();
// Give the user some feedback // Give the user some feedback
statusMessage(ss.i18n._t('UserForms.REMOVINGOPTION', 'Removed Option')); statusMessage(ss.i18n._t('UserForms.REMOVINGOPTION', 'Removed Option'));
@ -260,29 +256,32 @@
// Give the user some feedback // Give the user some feedback
statusMessage(ss.i18n._t('UserForms.ADDINGNEWRULE', 'Adding New Rule')); 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 // get the fields li which to duplicate
newCondition.find(".addCondition").hide(); var currentRules = $(this).parent("li").parent("ul");
newCondition.find("a.hidden").removeClass("hidden"); var defaultRule = currentRules.children("li.hidden:first");
var newRule = defaultRule.clone();
newCondition.children(".customRuleField").each(function(i, domElement) { newRule.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());
var currentName = domElement.name.split("]["); var currentName = domElement.name.split("][");
currentName[3] = currentName[2]; currentName[3] = currentName[2];
currentName[2] = grandParent.children().size() + 1; currentName[2] = currentRules.children().size() + 1;
domElement.name = currentName.join("]["); domElement.name = currentName.join("][");
}); });
grandParent.append(newCondition); // remove hidden tag
newRule.removeClass("hidden");
// clear fields // update the fields dropdown
parent.each(function(i, domElement) { newRule.children("select.fieldOption").empty();
$(domElement).find(".customRuleField").val("");
$("#Fields_fields li.EditableFormField").each(function (i, domElement) {
var name = $(this).attr("id").split(' ');
newRule.children("select.fieldOption").append("<option value='"+ name[2] + "'>"+ $(domElement).children(".fieldInfo .text").val() + "</option>");
}); });
// append to the list
currentRules.append(newRule);
return false; return false;
}); });
}); });

View File

@ -26,51 +26,100 @@
<% if showExtraOptions %> <% if showExtraOptions %>
<div class="extraOptions hidden" id="$Name.Attr-extraOptions"> <div class="extraOptions hidden" id="$Name.Attr-extraOptions">
<ul class="editableOptions" id="$Name.Attr-list"> <% if HasAddableOptions %>
<fieldset class="fieldOptionsGroup">
<legend><% _t('OPTIONS', 'Options') %></legend>
<ul class="editableOptions" id="$Name.Attr-list">
<% if isReadonly %> <% if isReadonly %>
<% control Options %> <% control Options %>
$ReadonlyOption $ReadonlyOption
<% end_control %> <% end_control %>
<% else %> <% else %>
<% control Options %> <% control Options %>
$EditSegment $EditSegment
<% end_control %>
<% if HasAddableOptions %>
<li class="{$ClassName}Option">
<a href="#" rel="$ID" class="addableOption" title="<% _t('ADD', 'Add option to field') %>">
Add Option
</a>
</li>
<% end_if %>
<% end_if %>
</ul>
</fieldset>
<% end_if %>
<% if FieldConfiguration %>
<fieldset class="fieldOptionsGroup">
<legend><% _t('FIELDCONFIGURATION', 'Field Configuration') %></legend>
<% control FieldConfiguration %>
$FieldHolder
<% end_control %> <% end_control %>
<% if hasAddableOptions %> </fieldset>
<li class="{$ClassName}Option"> <% end_if %>
<input class="text" type="text" name="$Name.Attr[NewOption]" value="" />
<a href="#" rel="$ID" class="addableOption" title="<% _t('ADD', 'Add option to field') %>"><img src="cms/images/add.gif" alt="<% _t('ADD', 'Add new option') %>" /></a>
</li>
<% end_if %>
<% end_if %>
</ul>
<% control ExtraOptions %> <% if FieldValidationOptions %>
$FieldHolder <fieldset class="fieldOptionsGroup">
<% end_control %> <legend><% _t('VALIDATION', 'Validation') %></legend>
<% control FieldValidationOptions %>
<div class="customRules"> $FieldHolder
<h4>Custom Rules</h4> <% end_control %>
<select name="$Name.Attr[ShowOnLoad]"> </fieldset>
<option value="Show" <% if ShowOnLoad %>selected="selected"<% end_if %>><% _t('SHOW', 'Show') %></option> <% end_if %>
<option value="Hide" <% if ShowOnLoad %><% else %><% if Title %><% else %>selected="selected"<% end_if %><% end_if %>><% _t('HIDE', 'Hide') %></option> <fieldset class="customRules fieldOptionsGroup">
</select> <legend>Custom Rules</legend>
<label class="left">Field On Default</label>
<ul id="$Name.Attr-customRules"> <ul id="$Name.Attr-customRules">
<li>
<a href="#" class="addCondition" title="<% _t('ADD', 'Add') %>">
Add Rule
</a>
</li>
<li class="addCustomRule">
<select name="$Name.Attr[CustomSettings][ShowOnLoad]">
<option value="Show" <% if ShowOnLoad %>selected="selected"<% end_if %>><% _t('SHOW', 'Show') %></option>
<option value="Hide" <% if ShowOnLoad %><% else %>selected="selected"<% end_if %>><% _t('HIDE', 'Hide') %></option>
</select>
<label class="left">Field On Default</label>
</li>
<li class="hidden">
<select class="displayOption customRuleField" name="{$Name}[CustomRules][Display]">
<option value="Show"><% _t('SHOWTHISFIELD', 'Show This Field') %></option>
<option value="Hide"><% _t('HIDETHISFIELD', 'Hide This Field') %></option>
</select>
<label><% _t('WHEN', 'When') %></label>
<select class="fieldOption customRuleField" name="{$Name}[CustomRules][ConditionField]">
</select>
<label><% _t('IS', 'Is') %></label>
<select class="conditionOption customRuleField" name="{$Name}[CustomRules][ConditionOption]">
<option value=""></option>
<option value="IsBlank"><% _t('BLANK', 'Blank') %></option>
<option value="IsNotBlank"><% _t('NOTBLANK', 'Not Blank') %></option>
<option value="HasValue"><% _t('VALUE', 'Value') %></option>
<option value="ValueNot"><% _t('NOTVALUE', 'Not Value') %></option>
</select>
<input type="text" class="ruleValue hidden customRuleField" name="{$Name}[CustomRules][Value]" />
<a href="#" class="deleteCondition" title="<% _t('DELETE', 'Delete') %>"><img src="cms/images/delete.gif" alt="<% _t('DELETE', 'Delete') %>" /></a>
</li>
<% control CustomRules %> <% control CustomRules %>
<li class="customRule"> <li>
<% include CustomRule %> <% include CustomRule %>
</li> </li>
<% end_control %> <% end_control %>
</ul> </ul>
</div> </fieldset>
</div> </div>
<% end_if %> <% end_if %>
<!-- Hidden option Fields --> <!-- Hidden option Fields -->
<input type="hidden" class="canDeleteHidden" name="$Name.Attr[CanDelete]" value="$CanDelete" /> <input type="hidden" class="canDeleteHidden" name="$Name.Attr[CanDelete]" value="$CanDelete" />
<input type="hidden" class="customParameterHidden" name="$Name.Attr[CustomParameter]" value="$CustomParameter" />
<input type="hidden" class="typeHidden" name="$Name.Attr[Type]" value="$ClassName" /> <input type="hidden" class="typeHidden" name="$Name.Attr[Type]" value="$ClassName" />
<input type="hidden" class="sortHidden" name="$Name.Attr[Sort]" value="$Sort" /> <input type="hidden" class="sortHidden" name="$Name.Attr[Sort]" value="$Sort" />
</li> </li>

View File

@ -1,10 +1,10 @@
<select class="displayOption customRuleField" name="{$Name}[CustomRules]<% if First %><% else %><% if Pos %>[$Pos]<% end_if %><% end_if %>[Display]"> <select class="displayOption customRuleField" name="{$Name}[CustomRules][$Pos][Display]">
<option value="Show" <% if Display = Show %>selected="selected"<% end_if %>><% _t('SHOWTHISFIELD', 'Show This Field') %></option> <option value="Show" <% if Display = Show %>selected="selected"<% end_if %>><% _t('SHOWTHISFIELD', 'Show This Field') %></option>
<option value="Hide" <% if Display = Hide %><% if First %><% else %>selected="selected"<% end_if %><% end_if %>><% _t('HIDETHISFIELD', 'Hide This Field') %></option> <option value="Hide" <% if Display = Hide %><% if First %><% else %>selected="selected"<% end_if %><% end_if %>><% _t('HIDETHISFIELD', 'Hide This Field') %></option>
</select> </select>
<label><% _t('WHEN', 'When') %></label> <label><% _t('WHEN', 'When') %></label>
<select class="fieldOption customRuleField" name="{$Name}[CustomRules]<% if First %><% else %><% if Pos %>[$Pos]<% end_if %><% end_if %>[ConditionField]"> <select class="fieldOption customRuleField" name="{$Name}[CustomRules][$Pos][ConditionField]">
<option value="" selected="selected"></option> <option value="" selected="selected"></option>
<% control Fields %> <% control Fields %>
<option value="$BaseName" <% if isSelected %>selected="selected"<% end_if %>>$Title</option> <option value="$BaseName" <% if isSelected %>selected="selected"<% end_if %>>$Title</option>
@ -12,7 +12,7 @@
</select> </select>
<label><% _t('IS', 'Is') %></label> <label><% _t('IS', 'Is') %></label>
<select class="conditionOption customRuleField" name="{$Name}[CustomRules]<% if First %><% else %><% if Pos %>[$Pos]<% end_if %><% end_if %>[ConditionOption]"> <select class="conditionOption customRuleField" name="{$Name}[CustomRules][$Pos][ConditionOption]">
<option value=""></option> <option value=""></option>
<option value="IsBlank" <% if ConditionOption = IsBlank %>selected="selected"<% end_if %>><% _t('BLANK', 'Blank') %></option> <option value="IsBlank" <% if ConditionOption = IsBlank %>selected="selected"<% end_if %>><% _t('BLANK', 'Blank') %></option>
<option value="IsNotBlank" <% if ConditionOption = IsNotBlank %>selected="selected"<% end_if %>><% _t('NOTBLANK', 'Not Blank') %></option> <option value="IsNotBlank" <% if ConditionOption = IsNotBlank %>selected="selected"<% end_if %>><% _t('NOTBLANK', 'Not Blank') %></option>
@ -20,7 +20,6 @@
<option value="ValueNot" <% if ConditionOption = ValueNot %>selected="selected"<% end_if %>><% _t('NOTVALUE', 'Not Value') %></option> <option value="ValueNot" <% if ConditionOption = ValueNot %>selected="selected"<% end_if %>><% _t('NOTVALUE', 'Not Value') %></option>
</select> </select>
<input type="text" class="ruleValue <% if Value %><% else %>hidden<% end_if %> customRuleField" name="{$Name}[CustomRules]<% if First %><% else %><% if Pos %>[$Pos]<% end_if %><% end_if %>[Value]" value="$Value" /> <input type="text" class="ruleValue <% if Value %><% else %>hidden<% end_if %> customRuleField" name="{$Name}[CustomRules][$Pos][Value]" value="$Value" />
<a href="#" class="addCondition <% if First %><% else %>hidden<% end_if %>" title="<% _t('ADD', 'Add') %>"><img src="cms/images/add.gif" alt="<% _t('ADD', 'Add') %>" /></a> <a href="#" class="deleteCondition" title="<% _t('DELETE', 'Delete') %>"><img src="cms/images/delete.gif" alt="<% _t('DELETE', 'Delete') %>" /></a>
<a href="#" class="deleteCondition <% if First %>hidden<% end_if %>" title="<% _t('DELETE', 'Delete') %>"><img src="cms/images/delete.gif" alt="<% _t('DELETE', 'Delete') %>" /></a>