Skip to content
Snippets Groups Projects
Commit f5be7414 authored by Erik Hommel's avatar Erik Hommel
Browse files

fix #97, #94 changed validation of selected trigger and added description and helptext

parent bc4181a9
No related branches found
No related tags found
No related merge requests found
......@@ -56,6 +56,14 @@ class CRM_Civirules_DAO_Rule extends CRM_Core_DAO {
'name' => 'is_active',
'type' => CRM_Utils_Type::T_INT,
),
'description' => array(
'name' => 'description',
'type' => CRM_Utils_Type::T_STRING,
),
'help_text' => array(
'name' => 'help_text',
'type' => CRM_Utils_Type::T_TEXT,
),
'created_date' => array(
'name' => 'created_date',
'type' => CRM_Utils_Type::T_DATE
......@@ -92,6 +100,8 @@ class CRM_Civirules_DAO_Rule extends CRM_Core_DAO {
'trigger_id' => 'trigger_id',
'trigger_params' => 'trigger_params',
'is_active' => 'is_active',
'description' => 'description',
'help_text' => 'help_text',
'created_date' => 'created_date',
'created_user_id' => 'created_user_id',
'modified_date' => 'modified_date',
......
......@@ -239,12 +239,15 @@ class CRM_Civirules_Form_Rule extends CRM_Core_Form {
$this->add('hidden', 'id', ts('RuleId'), array('id' => 'ruleId'));
if ($this->_action != CRM_Core_Action::DELETE) {
$this->add('text', 'rule_label', ts('Name'), array('size' => CRM_Utils_Type::HUGE), TRUE);
$this->add('text', 'rule_description', ts('Description'), array('size' => 100, 'maxlength' => 256));
$this->add('textarea', 'rule_help_text', ts('Help text with purpose of rule'),
array('rows' => 6, 'cols' => 100), false);
$this->add('checkbox', 'rule_is_active', ts('Enabled'));
$this->add('text', 'rule_created_date', ts('Created Date'));
$this->add('text', 'rule_created_contact', ts('Created By'));
$triggerList = array(' - select - ') + CRM_Civirules_Utils::buildTriggerList();
asort($triggerList);
$this->add('select', 'rule_trigger_select', ts('Select Trigger'), $triggerList, true, array('class' => 'crm-select2'));
$this->add('select', 'rule_trigger_select', ts('Select Trigger'), $triggerList, false, array('class' => 'crm-select2'));
if ($this->_action == CRM_Core_Action::UPDATE) {
$this->createUpdateFormElements();
}
......@@ -306,6 +309,12 @@ class CRM_Civirules_Form_Rule extends CRM_Core_Form {
$ruleData = CRM_Civirules_BAO_Rule::getValues(array('id' => $this->ruleId));
if (!empty($ruleData) && !empty($this->ruleId)) {
$defaults['rule_label'] = $ruleData[$this->ruleId]['label'];
if (isset($ruleData[$this->ruleId]['description'])) {
$defaults['rule_description'] = $ruleData[$this->ruleId]['description'];
}
if (isset($ruleData[$this->ruleId]['help_text'])) {
$defaults['rule_help_text'] = $ruleData[$this->ruleId]['help_text'];
}
$defaults['rule_is_active'] = $ruleData[$this->ruleId]['is_active'];
$defaults['rule_created_date'] = date('d-m-Y',
strtotime($ruleData[$this->ruleId]['created_date']));
......@@ -433,6 +442,9 @@ class CRM_Civirules_Form_Rule extends CRM_Core_Form {
'id' => $formValues['id']);
}
$ruleParams['label'] = $formValues['rule_label'];
$ruleParams['description'] = $formValues['rule_description'];
$ruleParams['help_text'] = $formValues['rule_help_text'];
$ruleParams['label'] = $formValues['rule_label'];
$ruleParams['name'] = CRM_Civirules_Utils::buildNameFromLabel($formValues['rule_label']);
$ruleParams['is_active'] = $formValues['rule_is_active'] ? 1 : 0;
$savedRule = CRM_Civirules_BAO_Rule::add($ruleParams);
......
......@@ -104,4 +104,21 @@ class CRM_Civirules_Upgrader extends CRM_Civirules_Upgrader_Base {
CRM_Core_DAO::executeQuery("update `civirule_trigger` SET `class_name` = 'CRM_CivirulesPostTrigger_Relationship' where `object_name` = 'Relationship'");
return true;
}
/**
* Update for issue 97 - add description and help_text to civirule_rule
* See https://github.com/CiviCooP/org.civicoop.civirules/issues/97
* @return bool
*/
public function upgrade_1007() {
if (CRM_Core_DAO::checkTableExists('civirule_rule')) {
if (!CRM_Core_DAO::checkFieldExists('civirule_rule', 'description')) {
CRM_Core_DAO::executeQuery("ALTER TABLE `civirule_rule` ADD COLUMN `description` VARCHAR(256) NULL AFTER `is_active`");
}
if (!CRM_Core_DAO::checkFieldExists('civirule_rule', 'help_text')) {
CRM_Core_DAO::executeQuery("ALTER TABLE `civirule_rule` ADD COLUMN `help_text` TEXT NULL AFTER `description`");
}
}
return true;
}
}
\ No newline at end of file
......@@ -5,6 +5,8 @@ CREATE TABLE IF NOT EXISTS civirule_rule (
trigger_id INT UNSIGNED NULL,
trigger_params TEXT NULL,
is_active TINYINT NULL DEFAULT 1,
description VARCHAR(256) NULL,
help_text TEXT NULL,
created_date DATE NULL,
created_user_id INT NULL,
modified_date DATE NULL,
......
......@@ -6,6 +6,16 @@
<div class="content">{$form.rule_label.html}</div>
<div class="clear"></div>
</div>
<div class="crm-section">
<div class="label">{$form.rule_description.label}</div>
<div class="content">{$form.rule_description.html}</div>
<div class="clear"></div>
</div>
<div class="crm-section">
<div class="label">{$form.rule_help_text.label}</div>
<div class="content">{$form.rule_help_text.html}</div>
<div class="clear"></div>
</div>
<div class="crm-section">
<div class="label">{$form.rule_is_active.label}</div>
<div class="content">{$form.rule_is_active.html}</div>
......
......@@ -14,6 +14,7 @@
<th class="sorting-disabled" rowspan="1" colspan="1">{ts}Name{/ts}</th>
<th class="sorting-disabled" rowspan="1" colspan="1">{ts}Trigger{/ts}</th>
<th class="sorting-disabled" rowspan="1" colspan="1">{ts}Active{/ts}</th>
<th class="sorting-disabled" rowspan="1" colspan="1">{ts}Description{/ts}</th>
<th class="sorting-disabled" rowspan="1" colspan="1">{ts}Date Created{/ts}</th>
<th class="sorting-disabled" rowspan="1" colspan="1">{ts}Created By{/ts}</th>
<th class="sorting_disabled" rowspan="1" colspan="1"></th>
......@@ -21,11 +22,13 @@
</thead>
<tbody>
{assign var="row_class" value="odd-row"}
{foreach from=$rules key=rule_id item=rule}
<tr id="row1" class={$row_class}>
{foreach from=$rules key=rule_id item=rule}
<tr id="row_{$rule.id}" class={$row_class}>
<td hidden="1">{$rule.id}</td>
<td>{$rule.label}</td>
<td>{$rule.trigger_label}</td>
<td>{$rule.is_active}</td>
<td>{$rule.description} <a href = "#" class="helpicon" onclick="showRuleHelp({$rule.id},'{$rule.help_text}')"></a></td>
<td>{$rule.created_date|crmDate}</td>
<td>{$rule.created_contact_name}</td>
<td>
......@@ -51,3 +54,17 @@
</a>
</div>
</div>
{literal}
<script type="text/javascript">
function showRuleHelp(ruleId, helpText) {
if (helpText) {
CRM.alert(helpText, 'CiviRule Help', 'info');
} else {
CRM.alert('There is no help text defined for this rule. You can set the help text when you edit the rule', 'No Help for CiviRule', 'info');
}
}
</script>
{/literal}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment