CRM-13992 : COPY action implementation
authorPratik Joshi <pratik.joshi@webaccess.co.in>
Tue, 25 Feb 2014 13:11:03 +0000 (18:41 +0530)
committerPratik Joshi <pratik.joshi@webaccess.co.in>
Thu, 27 Feb 2014 06:15:04 +0000 (11:45 +0530)
CRM/Contact/Form/CustomData.php
CRM/Core/BAO/CustomGroup.php
CRM/Core/BAO/CustomValue.php
CRM/Profile/Page/MultipleRecordFieldsListing.php
templates/CRM/Contact/Page/View/CustomData.tpl
templates/CRM/Profile/Page/MultipleRecordFieldsListing.tpl

index d8e9b071ec6e76b3968dbbcbf6fa2cbec91d2b56..a3e9feffd1f01dbd746d6f8d13e07410b3926df7 100644 (file)
@@ -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;
     }
 
index ccb7324c7dd9841bb79544c69061f2d03874c281..1c06d2d3fe2651d4ab7a21f0150700e38b1f66e7 100644 (file)
@@ -2231,6 +2231,5 @@ SELECT  civicrm_custom_group.id as groupID, civicrm_custom_group.title as groupT
     }
     return $multipleGroup;
   }
-
  }
 
index 8cced8e7c8e74a5a6218c821ef3067e0bd2ecf20..615b6c828aa3f9171a6163d16fa893e4e1f83bac 100644 (file)
@@ -215,5 +215,4 @@ class CRM_Core_BAO_CustomValue extends CRM_Core_DAO {
       $customValueID
     );
   }
-}
-
+}
\ No newline at end of file
index 355a46efbbc7b4e5d8f74a7b4384755863b3138c..99e6442224ecfce7de4b7cf479e70e89cdf9b594 100644 (file)
@@ -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&copyValueId=%%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'] = '#';
index 78413561cbdc473b12a880de545a4eb6d9db2784..06d751e99bef4e344d5ecc19fb314b80581a7ed5 100644 (file)
@@ -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( );
         }
       });
     }
index 89d15343e7e084d258ac15217ddee18874867f87..114712168ff223776c279cc6b1786855fc8c2c0d 100644 (file)
@@ -68,7 +68,7 @@
 
   {if !$reachedMax}
     {if $pageViewType eq 'customDataView'}
-      <a accesskey="N" title="{ts 1=$customGroupTitle}Add %1 Record{/ts}" href="{crmURL p='civicrm/contact/view/cd/edit' q="reset=1&snippet=1&type=$ctype&groupID=$customGroupId&entityID=$contactId&cgcount=$cgcount&multiRecordDisplay=single"}" 
+      <br/><a accesskey="N" title="{ts 1=$customGroupTitle}Add %1 Record{/ts}" href="{crmURL p='civicrm/contact/view/cd/edit' q="reset=1&snippet=1&type=$ctype&groupID=$customGroupId&entityID=$contactId&cgcount=$cgcount&multiRecordDisplay=single"}" 
        class="button action-item"><span><div class="icon add-icon"></div>{ts 1=$customGroupTitle}Add %1 Record{/ts}</span></a>
     {else}
       <a accesskey="N" href="{crmURL p='civicrm/profile/edit' q="reset=1&id=`$contactId`&multiRecord=add&gid=`$gid`&snippet=1&context=multiProfileDialog&onPopupClose=`$onPopupClose`"}"
               }
             });
             cj('.action-link').hide();
-            if (pageViewType != 'customDataView') {
-              cj('#profile-dialog #crm-profile-block .edit-value label').css('display', 'inline');
+            if (pageViewType == 'customDataView') {
+              var labelElement = cj('#custom-record-dialog .html-adjust label').css('display', 'inline');
+            }
+            else {
+              var labelElement = cj('#profile-dialog #crm-profile-block .edit-value label').css('display', 'inline');
             }
           }
         });