),
'status_id' => array(
'type' => 'select',
- 'label' => ts('Status'),
- 'attributes' =>
- CRM_Core_PseudoConstant::activityStatus(),
- 'required' => TRUE
+ 'required' => TRUE,
),
'priority_id' => array(
'type' => 'select',
- 'label' => ts('Priority'),
- 'attributes' =>
- CRM_Core_PseudoConstant::get('CRM_Activity_DAO_Activity', 'priority_id'),
- 'required' => TRUE
+ 'required' => TRUE,
),
'source_contact_id' => array(
'type' => 'text',
foreach ($this->_fields as $field => $values) {
if (!empty($this->_fields[$field])) {
- $attribute = NULL;
- if (!empty($values['attributes'])) {
- $attribute = $values['attributes'];
- }
+ $attribute = CRM_Utils_Array::value('attributes', $values);
+ $required = !empty($values['required']);
- $required = FALSE;
- if (!empty($values['required'])) {
- $required = TRUE;
- }
if ($values['type'] == 'wysiwyg') {
$this->addWysiwyg($field, $values['label'], $attribute, $required);
}
+ elseif ($values['type'] == 'select' && empty($attribute)) {
+ $this->addSelect('CRM_Activity_BAO_Activity', $field, array(), $required);
+ }
elseif ($field != 'source_contact_id') {
$this->add($values['type'], $field, $values['label'], $attribute, $required);
}
$this->assign('urlPath', 'civicrm/case/activity');
$encounterMediums = CRM_Case_PseudoConstant::encounterMedium();
+ // Fixme: what's the justification for this? It seems like it is just re-adding an option in case it is the default and disabled.
+ // Is that really a big problem?
if ($this->_activityTypeFile == 'OpenCase') {
$this->_encounterMedium = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $this->_activityId,
'medium_id'
/**
* Adds a select based on field metadata
* TODO: This could be even more generic and widget type (select in this case) could also be read from metadata
+ * Perhaps a method like $form->bind($name) which would look up all metadata for named field
* @param CRM_Core_DAO $baoName - string representing bao object
* @param $name
* @param array $props
if (!empty($props['placeholder']) && empty($props['multiple'])) {
$options = array('' => '') + $options;
}
+ $bao = new $baoName;
// Handle custom field
if (strpos($name, 'custom_') === 0 && is_numeric($name[7])) {
list(, $id) = explode('_', $name);
$label = isset($props['label']) ? $props['label'] : CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', 'label', $id);
- $props['data-option-group'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', 'option_group_id', $id);
+ $gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', 'option_group_id', $id);
+ $props['data-option-group-url'] = 'civicrm/admin/options/' . CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $gid);
}
// Core field
else {
- $bao = new $baoName;
$meta = $bao->getFieldSpec($name);
- $bao->free();
- // Todo: localize
- $label = CRM_Utils_Array::value('label', $props, $meta['title']);
+ $label = isset($props['label']) ? $props['label'] : ts($meta['title']);
if (!empty($meta['pseudoconstant']['optionGroupName'])) {
- $props['data-option-group'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $meta['pseudoconstant']['optionGroupName'], 'id', 'name');
+ $props['data-option-group-url'] = 'civicrm/admin/options/' . $meta['pseudoconstant']['optionGroupName'];
}
}
+ require_once 'api/api.php';
+ $props['data-api-entity'] = _civicrm_api_get_entity_name_from_dao($bao);
+ $bao->free();
$props['class'] = isset($props['class']) ? $props['class'] . ' ' : '';
$props['class'] .= "crm-select2";
+ CRM_Utils_Array::remove($props, 'label');
return $this->add('select', $name, $label, $options, $required, $props);
}
}
}
- if ($element->getType() == 'select' && $element->getAttribute('data-option-group')) {
+ if ($element->getType() == 'select' && $element->getAttribute('data-option-group-url')) {
$this->addOptionsEditLink($el, $element);
}
*/
function addOptionsEditLink(&$el, $field) {
if (CRM_Core_Permission::check('administer CiviCRM')) {
- $el['html'] .= ' <a href="#" class="crm-edit-optionvalue-link" title="' . ts('Edit Options') . '" data-option-group="' . $field->getAttribute('data-option-group') . '"><span class="batch-edit"></span></a>';
+ $el['html'] .= ' <a href="#" class="crm-edit-optionvalue-link" title="' . ts('Edit Options') . '" data-option-group-url="' . $field->getAttribute('data-option-group-url') . '"><span class="batch-edit"></span></a>';
}
}
}
return false;
}
+CRM.utils = CRM.utils || {};
CRM.strings = CRM.strings || {};
CRM.validate = CRM.validate || {
params: {},
return !!$(e.target).closest('.ui-dialog, .ui-datepicker, .select2-drop').length;
};
+ /**
+ * Populate a select list, overwriting the existing options except for the placeholder.
+ * @param $el jquery collection - 1 or more select elements
+ * @param options array in format returned by api.getoptions
+ */
+ CRM.utils.setOptions = function($el, options) {
+ $el.each(function() {
+ var
+ $elect = $(this),
+ val = $elect.val() || [];
+ if (typeof(val) !== 'array') {
+ val = [val];
+ }
+ $elect.find('option[value!=""]').remove();
+ $.each(options, function(key, option) {
+ var selected = ($.inArray(''+option.key, val) > -1) ? 'selected="selected"' : '';
+ $elect.append('<option value="' + option.key + '"' + selected + '>' + option.value + '</option>');
+ });
+ $elect.trigger('change');
+ });
+ };
+
// Initialize widgets
$(document).on('crmLoad', function(e) {
$('table.row-highlight', e.target)
}
// bind the event for image popup
- $('body').on('click', 'a.crm-image-popup', function() {
- var o = $('<div class="crm-container crm-custom-image-popup"><img src=' + $(this).attr('href') + '></div>');
+ $('body')
+ .on('click', 'a.crm-image-popup', function() {
+ var o = $('<div class="crm-container crm-custom-image-popup"><img src=' + $(this).attr('href') + '></div>');
- CRM.confirm('',
- {
- title: ts('Preview'),
- message: o
- },
- ts('Done')
- );
- return false;
- });
+ CRM.confirm('',
+ {
+ title: ts('Preview'),
+ message: o
+ },
+ ts('Done')
+ );
+ return false;
+ })
+ .on('click', function (event) {
+ $('.btn-slide-active').removeClass('btn-slide-active').find('.panel').hide();
+ if ($(event.target).is('.btn-slide')) {
+ $(event.target).addClass('btn-slide-active').find('.panel').show();
+ }
+ })
+
+ .on('click', 'a.crm-edit-optionvalue-link', function() {
+ var url = $(this).data('option-group-url');
+ CRM.loadForm(CRM.url(url, {reset: 1}))
+ .on('dialogclose', function() {
+ var $elects = $('select[data-option-group-url="' + url + '"]');
+ CRM.api3($elects.data('api-entity'), 'getoptions', {sequential: 1, field: $elects.attr('name')})
+ .done(function(data) {
+ CRM.utils.setOptions($elects, data.values);
+ });
+ });
+ return false;
+ });
$().crmtooltip();
- $('body').on('click', function (event) {
- $('.btn-slide-active').removeClass('btn-slide-active').find('.panel').hide();
- if ($(event.target).is('.btn-slide')) {
- $(event.target).addClass('btn-slide-active').find('.panel').show();
- }
- });
});
$.fn.crmAccordions = function (speed) {
</index>
<field>
<name>activity_type_id</name>
- <title>Activity Type ID</title>
+ <title>Activity Type</title>
<import>true</import>
<type>int unsigned</type>
<required>true</required>
<field>
<name>status_id</name>
<uniqueName>activity_status_id</uniqueName>
- <title>Activity Status Id</title>
+ <title>Activity Status</title>
<import>true</import>
<export>false</export>
<headerPattern>/(activity.)?status(.label$)?/i</headerPattern>