mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
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:
parent
cf35c706e4
commit
626f09be39
@ -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');
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
||||
?>
|
@ -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();
|
||||
|
@ -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'] ) )
|
||||
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 );
|
||||
parent::populateFromPostData($data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -8,7 +8,7 @@
|
||||
*/
|
||||
class EditableDropdown extends EditableMultipleOptionField {
|
||||
|
||||
static $singular_name = 'Dropdown';
|
||||
static $singular_name = 'Dropdown Field';
|
||||
|
||||
static $plural_name = 'Dropdowns';
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
@ -275,35 +271,27 @@ class EditableFormField extends DataObject {
|
||||
$this->write();
|
||||
}
|
||||
|
||||
function 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();
|
||||
}
|
||||
|
||||
$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;
|
||||
/**
|
||||
* 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;
|
||||
@ -356,10 +344,6 @@ class EditableFormField extends DataObject {
|
||||
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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
?>
|
@ -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() {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ class EditableMultipleOptionField extends EditableFormField {
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasAddableOptions() {
|
||||
public function getHasAddableOptions() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -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,7 +181,6 @@ 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) {
|
||||
@ -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();
|
||||
}
|
||||
|
@ -28,6 +28,7 @@
|
||||
margin: 7px 0 0 4px;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
/* Options / Settings Area
|
||||
---------------------------------------- */
|
||||
.FormOptions {
|
||||
@ -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;
|
||||
}
|
||||
|
@ -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("<option='"+ name[2] +"'>New "+ name[2] + "</option>");
|
||||
//});
|
||||
$("#Fields_fields select.fieldOption").each(function(i, domElement) {
|
||||
$(domElement).append("<option='"+ name[2] +"'>New "+ name[2] + "</option>");
|
||||
});
|
||||
},
|
||||
|
||||
// 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("<option value='"+ name[2] + "'>"+ $(domElement).children(".fieldInfo .text").val() + "</option>");
|
||||
});
|
||||
|
||||
// append to the list
|
||||
currentRules.append(newRule);
|
||||
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
@ -26,51 +26,100 @@
|
||||
|
||||
<% if showExtraOptions %>
|
||||
<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 %>
|
||||
<% control Options %>
|
||||
$ReadonlyOption
|
||||
<% if isReadonly %>
|
||||
<% control Options %>
|
||||
$ReadonlyOption
|
||||
<% end_control %>
|
||||
<% else %>
|
||||
<% control Options %>
|
||||
$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 %>
|
||||
<% else %>
|
||||
<% control Options %>
|
||||
$EditSegment
|
||||
</fieldset>
|
||||
<% end_if %>
|
||||
|
||||
<% if FieldValidationOptions %>
|
||||
<fieldset class="fieldOptionsGroup">
|
||||
<legend><% _t('VALIDATION', 'Validation') %></legend>
|
||||
<% control FieldValidationOptions %>
|
||||
$FieldHolder
|
||||
<% end_control %>
|
||||
<% if hasAddableOptions %>
|
||||
<li class="{$ClassName}Option">
|
||||
<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 %>
|
||||
$FieldHolder
|
||||
<% end_control %>
|
||||
|
||||
<div class="customRules">
|
||||
<h4>Custom Rules</h4>
|
||||
<select name="$Name.Attr[ShowOnLoad]">
|
||||
<option value="Show" <% if ShowOnLoad %>selected="selected"<% end_if %>><% _t('SHOW', 'Show') %></option>
|
||||
<option value="Hide" <% if ShowOnLoad %><% else %><% if Title %><% else %>selected="selected"<% end_if %><% end_if %>><% _t('HIDE', 'Hide') %></option>
|
||||
</select>
|
||||
<label class="left">Field On Default</label>
|
||||
|
||||
</fieldset>
|
||||
<% end_if %>
|
||||
<fieldset class="customRules fieldOptionsGroup">
|
||||
<legend>Custom Rules</legend>
|
||||
<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 %>
|
||||
<li class="customRule">
|
||||
<li>
|
||||
<% include CustomRule %>
|
||||
</li>
|
||||
<% end_control %>
|
||||
</ul>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
<% end_if %>
|
||||
|
||||
<!-- Hidden option Fields -->
|
||||
<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="sortHidden" name="$Name.Attr[Sort]" value="$Sort" />
|
||||
</li>
|
@ -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="Hide" <% if Display = Hide %><% if First %><% else %>selected="selected"<% end_if %><% end_if %>><% _t('HIDETHISFIELD', 'Hide This Field') %></option>
|
||||
</select>
|
||||
|
||||
<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>
|
||||
<% control Fields %>
|
||||
<option value="$BaseName" <% if isSelected %>selected="selected"<% end_if %>>$Title</option>
|
||||
@ -12,7 +12,7 @@
|
||||
</select>
|
||||
|
||||
<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="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>
|
||||
@ -20,7 +20,6 @@
|
||||
<option value="ValueNot" <% if ConditionOption = ValueNot %>selected="selected"<% end_if %>><% _t('NOTVALUE', 'Not Value') %></option>
|
||||
</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 <% if First %>hidden<% end_if %>" title="<% _t('DELETE', 'Delete') %>"><img src="cms/images/delete.gif" alt="<% _t('DELETE', 'Delete') %>" /></a>
|
||||
<a href="#" class="deleteCondition" title="<% _t('DELETE', 'Delete') %>"><img src="cms/images/delete.gif" alt="<% _t('DELETE', 'Delete') %>" /></a>
|
||||
|
Loading…
Reference in New Issue
Block a user