<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
+ | CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
*
* @return string Classname of BAO.
*/
- function getBAOName() {
+ public function getBAOName() {
return '';
}
*
* @return array (reference) of action links
*/
- function &links() {
+ public function &links() {
if (!(self::$_links[$this->_pageViewType])) {
// helper variable for nicer formatting
$links = array();
// names and titles
$links[CRM_Core_Action::VIEW] = array(
'name' => ts('View'),
- 'title' => ts('View %1', array( 1 => $this->_customGroupTitle . ' record')),
+ 'title' => ts('View %1', array(1 => $this->_customGroupTitle . ' record')),
);
$links[CRM_Core_Action::UPDATE] = array(
'name' => ts('Edit'),
- 'title' => ts('Edit %1', array( 1 => $this->_customGroupTitle . ' record')),
+ 'title' => ts('Edit %1', array(1 => $this->_customGroupTitle . ' record')),
);
$links[CRM_Core_Action::DELETE] = array(
'name' => ts('Delete'),
- 'title' => ts('Delete %1', array( 1 => $this->_customGroupTitle . ' record')),
+ 'title' => ts('Delete %1', array(1 => $this->_customGroupTitle . ' record')),
);
// urls and queryStrings
// copy action
$links[CRM_Core_Action::COPY] = array(
'name' => ts('Copy'),
- 'title' => ts('Copy %1', array( 1 => $this->_customGroupTitle . ' record')),
+ 'title' => ts('Copy %1', array(1 => $this->_customGroupTitle . ' record')),
'url' => 'civicrm/contact/view/cd/edit',
'qs' => 'reset=1&type=%%type%%&groupID=%%groupID%%&entityID=%%entityID%%&cgcount=%%newCgCount%%&multiRecordDisplay=single©ValueId=%%cgcount%%&mode=copy'
);
* method.
*
* @return void
- * @access public
*
*/
- function run() {
+ public function run() {
// get the requested action, default to 'browse'
$action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, FALSE);
* Browse the listing
*
* @return void
- * @access public
*/
- function browse() {
+ public function browse() {
$dateFields = NULL;
$cgcount = 0;
$dateFieldsVals = NULL;
NULL,
CRM_Core_Permission::EDIT
);
- $multiRecordFields = array( );
+ $multiRecordFields = array();
$fieldIDs = NULL;
$result = NULL;
$multiRecordFieldsWithSummaryListing = CRM_Core_BAO_UFGroup::shiftMultiRecordFields($fields, $multiRecordFields, TRUE);
$this->_customGroupTitle = $groupDetail[$customGroupId]['title'];
}
if ($fieldIDs && !empty($fieldIDs) && $this->_contactId) {
- $options = array( );
- $returnProperities = array('html_type', 'data_type', 'date_format', 'time_format');
+ $options = array();
+ $returnProperities = array('html_type', 'data_type', 'date_format', 'time_format', 'default_value', 'is_required');
foreach ($fieldIDs as $key => $fieldID) {
$fieldIDs[$key] = !is_numeric($fieldID) ? CRM_Core_BAO_CustomField::getKeyID($fieldID) : $fieldID;
$param = array('id' => $fieldIDs[$key]);
- $returnValues = array( );
+ $returnValues = array();
CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $param, $returnValues, $returnProperities);
if ($returnValues['data_type'] == 'Date') {
$dateFields[$fieldIDs[$key]] = 1;
$options[$fieldIDs[$key]]['attributes']['html_type'] = $returnValues['html_type'];
$options[$fieldIDs[$key]]['attributes']['data_type'] = $returnValues['data_type'];
+ $options[$fieldIDs[$key]]['attributes']['is_required'] = !empty($returnValues['is_required']);
+ $options[$fieldIDs[$key]]['attributes']['default_value'] = CRM_Utils_Array::value('default_value', $returnValues);
$options[$fieldIDs[$key]]['attributes']['format'] =
$options[$fieldIDs[$key]]['attributes']['date_format'] = CRM_Utils_Array::value('date_format', $returnValues);
// assign to $result
$customValue = CRM_Core_BAO_CustomField::getDisplayValue($customValue, $fieldId, $options);
}
- if (!$customValue) {
+ // FIXME: getDisplayValue should always return a string so why is this necessary?
+ if (!$customValue && $customValue !== '0') {
$customValue = "";
}
+ // Set field attributes to support crmEditable
+ // Note that $fieldAttributes[data-type] actually refers to the html type not the sql data type
+ // TODO: Not all widget types and validation rules are supported by crmEditable so some fields will not be in-place editable
+ $fieldAttributes = array('class' => "crmf-custom_{$fieldId}_$recId");
+ $editable = FALSE;
+ if ($linkAction & CRM_Core_Action::UPDATE) {
+ $spec = $options[$fieldId]['attributes'];
+ switch ($spec['html_type']) {
+ case 'Text':
+ // Other data types like money would require some extra validation
+ // FIXME: crmEditable currently does not support any validation rules :(
+ $supportedDataTypes = array('Float', 'String', 'Int');
+ $editable = in_array($spec['data_type'], $supportedDataTypes);
+ break;
+
+ case 'TextArea':
+ $editable = TRUE;
+ $fieldAttributes['data-type'] = 'textarea';
+ break;
+
+ case 'Radio':
+ case 'Select':
+ case 'Select Country':
+ case 'Select State/Province':
+ $editable = TRUE;
+ $fieldAttributes['data-type'] = $spec['data_type'] == 'Boolean' ? 'boolean' : 'select';
+ if (!$spec['is_required']) {
+ $fieldAttributes['data-empty-option'] = ts('- none -');
+ }
+ break;
+ }
+ }
+ if ($editable) {
+ $fieldAttributes['class'] .= ' crm-editable';
+ }
+ $attributes[$fieldId][$recId] = $fieldAttributes;
+
$op = NULL;
if ($this->_pageViewType == 'profileDataView') {
- $actionParams = array('recordId' => $recId, 'gid' => $this->_profileId,
+ $actionParams = array(
+ 'recordId' => $recId,
+ 'gid' => $this->_profileId,
'id' => $this->_contactId);
$op = 'profile.multiValue.row';
}
}
}
- $headers = array( );
+ $headers = array();
if (!empty($fieldIDs)) {
foreach ($fieldIDs as $fieldID) {
$headers[$fieldID] = ($this->_pageViewType == 'profileDataView') ? $customGroupInfo[$fieldID]['fieldLabel'] : $fieldLabels[$fieldID]['label'];
}
}
$this->assign('dateFields', $dateFields);
- $this->assign('dateFieldsVals',$dateFieldsVals);
+ $this->assign('dateFieldsVals', $dateFieldsVals);
$this->assign('cgcount', $cgcount);
$this->assign('customGroupTitle', $this->_customGroupTitle);
$this->assign('headers', $headers);
$this->assign('records', $result);
+ $this->assign('attributes', $attributes);
}
/**
*
* @return string classname of edit form
*/
- function editForm() {
+ public function editForm() {
return '';
}
*
* @return string name of this page
*/
- function editName() {
+ public function editName() {
return '';
}
*
* @return string user context
*/
- function userContext($mode = NULL) {
+ public function userContext($mode = NULL) {
return '';
}
}
-