From 1dde099b8bb35d5772bd59191a81127e95db8dd6 Mon Sep 17 00:00:00 2001 From: Pratik Joshi Date: Tue, 25 Feb 2014 18:41:03 +0530 Subject: [PATCH] CRM-13992 : COPY action implementation --- CRM/Contact/Form/CustomData.php | 29 +++++++++- CRM/Core/BAO/CustomGroup.php | 1 - CRM/Core/BAO/CustomValue.php | 3 +- .../Page/MultipleRecordFieldsListing.php | 54 +++++++++++-------- .../CRM/Contact/Page/View/CustomData.tpl | 3 +- .../Page/MultipleRecordFieldsListing.tpl | 9 ++-- 6 files changed, 68 insertions(+), 31 deletions(-) diff --git a/CRM/Contact/Form/CustomData.php b/CRM/Contact/Form/CustomData.php index d8e9b071ec..a3e9feffd1 100644 --- a/CRM/Contact/Form/CustomData.php +++ b/CRM/Contact/Form/CustomData.php @@ -102,6 +102,8 @@ class CRM_Contact_Form_CustomData extends CRM_Core_Form { public $_groupID; public $_multiRecordDisplay; + + public $_copyValueId; /** * pre processing work done here. * @@ -129,6 +131,7 @@ class CRM_Contact_Form_CustomData extends CRM_Core_Form { if ($this->_multiRecordDisplay) { $this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this); $this->_tableID = $this->_entityId; + $this->_copyValueId = CRM_Utils_Request::retrieve('copyValueId', 'Positive', $this); } return; } @@ -168,10 +171,11 @@ class CRM_Contact_Form_CustomData extends CRM_Core_Form { ); if ($isMultiple) { $this->assign('multiRecordDisplay', $this->_multiRecordDisplay); + $saveButtonName = $this->_copyValueId ? 'Save a Copy': 'Save'; $this->addButtons(array( array( 'type' => 'upload', - 'name' => ts('Save'), + 'name' => ts('%1', array(1 => $saveButtonName)), 'isDefault' => TRUE, ), array( @@ -214,7 +218,28 @@ class CRM_Contact_Form_CustomData extends CRM_Core_Form { */ function setDefaultValues() { if ($this->_cdType || $this->_multiRecordDisplay == 'single') { - $customDefaultValue = CRM_Custom_Form_CustomData::setDefaultValues($this); + if ($this->_copyValueId) { + // cached tree is fetched + $groupTree = &CRM_Core_BAO_CustomGroup::getTree($this->_type, + $this, + $this->_entityId, + $this->_groupID + ); + $valueIdDefaults = array(); + $groupTreeValueId = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, $this->_copyValueId, $this); + CRM_Core_BAO_CustomGroup::setDefaults($groupTreeValueId, $valueIdDefaults, FALSE, FALSE, $this->get('action')); + $tableId = $groupTreeValueId[$this->_groupID]['table_id']; + foreach ($valueIdDefaults as $valueIdElementName => $value) { + // build defaults for COPY action for new record saving + $valueIdElementNamePieces = explode('_', $valueIdElementName); + $valueIdElementNamePieces[2] = "-{$this->_groupCount}"; + $elementName = implode('_', $valueIdElementNamePieces); + $customDefaultValue[$elementName] = $value; + } + } + else { + $customDefaultValue = CRM_Custom_Form_CustomData::setDefaultValues($this); + } return $customDefaultValue; } diff --git a/CRM/Core/BAO/CustomGroup.php b/CRM/Core/BAO/CustomGroup.php index ccb7324c7d..1c06d2d3fe 100644 --- a/CRM/Core/BAO/CustomGroup.php +++ b/CRM/Core/BAO/CustomGroup.php @@ -2231,6 +2231,5 @@ SELECT civicrm_custom_group.id as groupID, civicrm_custom_group.title as groupT } return $multipleGroup; } - } diff --git a/CRM/Core/BAO/CustomValue.php b/CRM/Core/BAO/CustomValue.php index 8cced8e7c8..615b6c828a 100644 --- a/CRM/Core/BAO/CustomValue.php +++ b/CRM/Core/BAO/CustomValue.php @@ -215,5 +215,4 @@ class CRM_Core_BAO_CustomValue extends CRM_Core_DAO { $customValueID ); } -} - +} \ No newline at end of file diff --git a/CRM/Profile/Page/MultipleRecordFieldsListing.php b/CRM/Profile/Page/MultipleRecordFieldsListing.php index 355a46efbb..99e6442224 100644 --- a/CRM/Profile/Page/MultipleRecordFieldsListing.php +++ b/CRM/Profile/Page/MultipleRecordFieldsListing.php @@ -76,46 +76,52 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic { $update = array_search(CRM_Core_Action::UPDATE, CRM_Core_Action::$_names); $delete = array_search(CRM_Core_Action::DELETE, CRM_Core_Action::$_names); + // names and titles $links[CRM_Core_Action::VIEW] = array( 'name' => ts('View'), 'title' => ts('View %1', array( 1 => $this->_customGroupTitle . ' record')), ); - if ($this->_pageViewType == 'profileDataView') { - $links[CRM_Core_Action::VIEW]['url'] = 'civicrm/profile/view'; - $links[CRM_Core_Action::VIEW]['qs'] = "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$view}&snippet=1&context=multiProfileDialog&onPopupClose=%%onPopupClose%%"; - } - elseif ($this->_pageViewType == 'customDataView') { - // custom data specific view links - $links[CRM_Core_Action::VIEW]['url'] = 'civicrm/contact/view/cd'; - $links[CRM_Core_Action::VIEW]['qs'] = 'reset=1&snippet=1&gid=%%gid%%&cid=%%cid%%&recId=%%recId%%&multiRecordDisplay=single'; - } - $links[CRM_Core_Action::UPDATE] = array( 'name' => ts('Edit'), 'title' => ts('Edit %1', array( 1 => $this->_customGroupTitle . ' record')), ); - if ($this->_pageViewType == 'profileDataView') { - $links[CRM_Core_Action::UPDATE]['url'] = 'civicrm/profile/edit'; - $links[CRM_Core_Action::UPDATE]['qs'] = "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$update}&snippet=1&context=multiProfileDialog&onPopupClose=%%onPopupClose%%"; - } - elseif ($this->_pageViewType == 'customDataView') { - // custom data specific update links - $links[CRM_Core_Action::UPDATE]['url'] = 'civicrm/contact/view/cd/edit'; - $links[CRM_Core_Action::UPDATE]['qs'] = 'reset=1&snippet=1&type=%%type%%&groupID=%%groupID%%&entityID=%%entityID%%&cgcount=%%cgcount%%&multiRecordDisplay=single'; - } - $links[CRM_Core_Action::DELETE] = array( 'name' => ts('Delete'), 'title' => ts('Delete %1', array( 1 => $this->_customGroupTitle . ' record')), ); + // urls and queryStrings if ($this->_pageViewType == 'profileDataView') { + $links[CRM_Core_Action::VIEW]['url'] = 'civicrm/profile/view'; + $links[CRM_Core_Action::VIEW]['qs'] = "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$view}&snippet=1&context=multiProfileDialog&onPopupClose=%%onPopupClose%%"; + + $links[CRM_Core_Action::UPDATE]['url'] = 'civicrm/profile/edit'; + $links[CRM_Core_Action::UPDATE]['qs'] = "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$update}&snippet=1&context=multiProfileDialog&onPopupClose=%%onPopupClose%%"; + $links[CRM_Core_Action::DELETE]['url'] = 'civicrm/profile/edit'; $links[CRM_Core_Action::DELETE]['qs'] = "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$delete}&snippet=1&context=multiProfileDialog&onPopupClose=%%onPopupClose%%"; + + } + elseif ($this->_pageViewType == 'customDataView') { + // custom data specific view links + $links[CRM_Core_Action::VIEW]['url'] = 'civicrm/contact/view/cd'; + $links[CRM_Core_Action::VIEW]['qs'] = 'reset=1&snippet=1&gid=%%gid%%&cid=%%cid%%&recId=%%recId%%&multiRecordDisplay=single'; + + // custom data specific update links + $links[CRM_Core_Action::UPDATE]['url'] = 'civicrm/contact/view/cd/edit'; + $links[CRM_Core_Action::UPDATE]['qs'] = 'reset=1&snippet=1&type=%%type%%&groupID=%%groupID%%&entityID=%%entityID%%&cgcount=%%cgcount%%&multiRecordDisplay=single'; + // NOTE : links for DELETE action for customDataView is handled in browse + + // copy action + $links[CRM_Core_Action::COPY] = array( + 'name' => ts('Copy'), + 'title' => ts('Copy %1', array( 1 => $this->_customGroupTitle . ' record')), + 'url' => 'civicrm/contact/view/cd/edit', + 'qs' => 'reset=1&snippet=1&type=%%type%%&groupID=%%groupID%%&entityID=%%entityID%%&cgcount=%%newCgCount%%&multiRecordDisplay=single©ValueId=%%cgcount%%' + ); } - // NOTE : links for DELETE action for customDataView is handled in browse self::$_links[$this->_pageViewType] = $links; } @@ -269,6 +275,11 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic { } } $linkAction = array_sum(array_keys($this->links())); + + if ($reached) { + unset($links[CRM_Core_Action::COPY]); + } + $newCgCount = (!$reached) ? count($result) + 1 : NULL; foreach ($result as $recId => &$value) { foreach ($value as $fieldId => &$val) { if (is_numeric($fieldId)) { @@ -291,6 +302,7 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic { $actionParams['recId'] = $recId; $actionParams['type'] = $this->_contactType; $actionParams['cgcount'] = $cgcount; + $actionParams['newCgCount'] = $newCgCount; // DELETE action links $links[CRM_Core_Action::DELETE]['url'] = '#'; diff --git a/templates/CRM/Contact/Page/View/CustomData.tpl b/templates/CRM/Contact/Page/View/CustomData.tpl index 78413561cb..06d751e99b 100644 --- a/templates/CRM/Contact/Page/View/CustomData.tpl +++ b/templates/CRM/Contact/Page/View/CustomData.tpl @@ -50,7 +50,6 @@ }, {/literal}"{ts escape='js'}OK{/ts}{literal}": function() { deleteCustomValueRec(valueID, groupID, contactID); - window.setTimeout(function(){window.location.reload( )}, 1000); } } }); @@ -63,7 +62,7 @@ data: "valueID=" + valueID + "&groupID=" + groupID + "&contactId=" + contactID + "&key={/literal}{crmKey name='civicrm/ajax/customvalue'}{literal}", url: postUrl, success: function (html) { - CRM.alert('', '{/literal}{ts escape="js"}Record Deleted{/ts}{literal}', 'success'); + window.location.reload( ); } }); } diff --git a/templates/CRM/Profile/Page/MultipleRecordFieldsListing.tpl b/templates/CRM/Profile/Page/MultipleRecordFieldsListing.tpl index 89d15343e7..114712168f 100644 --- a/templates/CRM/Profile/Page/MultipleRecordFieldsListing.tpl +++ b/templates/CRM/Profile/Page/MultipleRecordFieldsListing.tpl @@ -68,7 +68,7 @@ {if !$reachedMax} {if $pageViewType eq 'customDataView'} -
{ts 1=$customGroupTitle}Add %1 Record{/ts}
{else}