diff --git a/CHANGELOG.md b/CHANGELOG.md index 9052ff7acba790942887be8d986a5e04bb810852..c8de88847ff534553bacbfa9b29c05d82e0ad3e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Version 1.3 * Fix for converting Title into Name. * Fixed issue with updating status with overridden. * Added getoptions to the FormProcessor and FormProcessorDefaults API. +* Added a type with a list of weekdays Version 1.2 =========== diff --git a/Civi/FormProcessor/Type/Factory.php b/Civi/FormProcessor/Type/Factory.php index 8d8eb1f53a425274048257ca30b0dcffdfd8675c..49178d457f84d15994509f29bf61a34408bf1b34 100644 --- a/Civi/FormProcessor/Type/Factory.php +++ b/Civi/FormProcessor/Type/Factory.php @@ -35,6 +35,7 @@ $this->addType(new ParticipantStatusType('ParticipantStatusType', E::ts('Participant Status'))); $this->addType(new CampaignType('CampaignType', E::ts('Campaign'))); $this->addType(new FileType('file', E::ts('File'))); + $this->addType(new WeekDays('WeekDays', E::ts('Week Days'))); } /** diff --git a/Civi/FormProcessor/Type/WeekDays.php b/Civi/FormProcessor/Type/WeekDays.php new file mode 100644 index 0000000000000000000000000000000000000000..775fe3cf7b1ddea3f6c780c80de0acb27fb16f83 --- /dev/null +++ b/Civi/FormProcessor/Type/WeekDays.php @@ -0,0 +1,76 @@ +<?php + +/** + * @author Jaap Jansma (CiviCooP) <jaap.jansma@civicoop.org> + * @license http://www.gnu.org/licenses/agpl-3.0.html + */ + +namespace Civi\FormProcessor\Type; + +use \Civi\FormProcessor\Config\Specification; +use \Civi\FormProcessor\Config\SpecificationBag; + +use \CRM_FormProcessor_ExtensionUtil as E; + +class WeekDays extends AbstractType implements OptionListInterface { + + /** + * Get the configuration specification + * + * @return SpecificationBag + */ + public function getConfigurationSpecification() { + return new SpecificationBag(array( + new Specification('multiple', 'Boolean', E::ts('Multiple'), false, 0, null, array(0=>E::ts('Single value'), 1=>E::ts('Multiple values'))), + )); + } + + public function validateValue($value, $allValues=array()) { + $multiple = $this->configuration->get('multiple') ? true : false; + $options = $this->getOptions(); + if ($multiple && is_array($value)) { + foreach ($value as $valueItem) { + if (\CRM_Utils_Type::validate($valueItem, 'String', FALSE) === NULL) { + return FALSE; + } + if (!isset($options[$valueItem])) { + return FALSE; + } + } + } elseif (!is_array($value) && $value) { + if (\CRM_Utils_Type::validate($value, 'String', FALSE) === NULL) { + return FALSE; + } + + if (!isset($options[$value])) { + return false; + } + } else { + return false; + } + + return true; + } + + /** + * Returns the type number from CRM_Utils_Type + */ + public function getCrmType() { + return \CRM_Utils_Type::T_STRING; + } + + public function getOptions($params) { + $options = array( + 'sunday' => E::ts('Sunday'), + 'monday' => E::ts('Monday'), + 'tuesday' => E::ts('Tuesday'), + 'wednesday' => E::ts('Wednesday'), + 'thursday' => E::ts('Thursday'), + 'friday' => E::ts('Friday'), + 'saturday' => E::ts('Saturday'), + ); + + return $options; + } + +} diff --git a/ang/form_processor/inputs/InputDialogCtrl.js b/ang/form_processor/inputs/InputDialogCtrl.js index b8c6c55f7d77d0a0f96f0d7b2869b88129adc44c..0b6406671e736f3053dc9fe3aba4759218d3839a 100644 --- a/ang/form_processor/inputs/InputDialogCtrl.js +++ b/ang/form_processor/inputs/InputDialogCtrl.js @@ -6,7 +6,6 @@ $scope.locks = {name: true}; $scope.isNameValid = false; $scope.validators = CRM.form_processor.validators; - if (!$scope.input.deletedValidators) { $scope.input.deletedValidators = []; }