CRM-13992 : custom data single record view handling, DELETE action handling, QA check...
authorPratik Joshi <pratik.joshi@webaccess.co.in>
Mon, 24 Feb 2014 15:30:17 +0000 (21:00 +0530)
committerPratik Joshi <pratik.joshi@webaccess.co.in>
Thu, 27 Feb 2014 06:15:04 +0000 (11:45 +0530)
CRM/Profile/Page/MultipleRecordFieldsListing.php
templates/CRM/Contact/Form/CustomData.tpl
templates/CRM/Contact/Page/View/CustomData.tpl
templates/CRM/Custom/Page/CustomDataView.tpl
templates/CRM/Profile/Page/MultipleRecordFieldsListing.tpl

index 03b8b927c94ffe66200b3b2d329b4febe628b2f9..355a46efbbc7b4e5d8f74a7b4384755863b3138c 100644 (file)
@@ -115,6 +115,7 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic {
         $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%%";
       }
+      // NOTE : links for DELETE action for customDataView is handled in browse
 
       self::$_links[$this->_pageViewType] = $links;
     }
@@ -258,7 +259,7 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic {
       // and $cgcount is used to build new record url
       $cgcount = 1;
       if ($result && !empty($result)) {
-        $links = self::links($this->_pageViewType);
+        $links = self::links();
         if ($this->_pageViewType == 'profileDataView') {
           $pageCheckSum = $this->get('pageCheckSum');
           if ($pageCheckSum) {
@@ -290,10 +291,16 @@ class CRM_Profile_Page_MultipleRecordFieldsListing extends CRM_Core_Page_Basic {
                 $actionParams['recId'] = $recId;
                 $actionParams['type'] = $this->_contactType;
                 $actionParams['cgcount'] = $cgcount;
+
+                // DELETE action links
+                $links[CRM_Core_Action::DELETE]['url'] = '#';
+                $links[CRM_Core_Action::DELETE]['extra'] = " onclick='showDeleteInDialog({$recId}, {$this->_customGroupId}, {$this->_contactId})' ";
+                $links[CRM_Core_Action::DELETE]['class'] = 'ignore-jshref';
               }
               if (!empty($pageCheckSum)) {
                 $actionParams['cs'] = $pageCheckSum;
               }
+
               $value['action'] = CRM_Core_Action::formLink(
                 $links,
                 $linkAction,
index b011b2bc0f3dc58a4940e6c02520ed30fa2d2654..a0cbf755dc52bb333e1769537078c57ead805d6c 100644 (file)
 *}
 {* this template is used for building tabbed custom data *}
 {if $cdType }
-    {include file="CRM/Custom/Form/CustomData.tpl"}
-{if $multiRecordDisplay eq 'single'}
-    <div class="html-adjust">{$form.buttons.html}</div>
-{/if}
+   {include file="CRM/Custom/Form/CustomData.tpl"}
+   {if $multiRecordDisplay eq 'single'}
+     <div class="html-adjust">{$form.buttons.html}</div>
+     {* for form rule handling *}
+     {include file="CRM/Form/validate.tpl"}
+     {literal}
+     <script type='text/javascript'>
+       cj(function($) {
+         $('#custom-record-dialog .crm-container-snippet #CustomData').validate(CRM.validate.params);
+       });
+     </script>
+     {/literal}
+   {/if}
 {else}
-{debug}
     <div id="customData"></div>
     <div class="html-adjust">{$form.buttons.html}</div>
 
     {*include custom data js file*}
     {include file="CRM/common/customData.tpl"}
 
-
-  {if $customValueCount }
+  {if $customValueCount}
     {literal}
     <script type="text/javascript">
       var customValueCount = {/literal}"{$customValueCount}"{literal};
@@ -54,4 +61,4 @@
   {/if}
 {/if}
 
-{include file="CRM/Form/attachmentjs.tpl"}
+{include file="CRM/Form/attachmentjs.tpl"}
\ No newline at end of file
index b5f53d721111996eb1c0f96fecc3d655e46e3b2b..78413561cbdc473b12a880de545a4eb6d9db2784 100644 (file)
   {include file="CRM/Contact/Form/CustomData.tpl" mainEdit=$mainEditForm}
 {/if}
 {if $displayStyle eq 'tableOriented'}
-   {include file='CRM/Profile/Page/MultipleRecordFieldsListing.tpl' showListing=1 dontShowTitle=1 pageViewType='customDataView'}
+  {include file='CRM/Profile/Page/MultipleRecordFieldsListing.tpl' showListing=1 dontShowTitle=1 pageViewType='customDataView'}
+  {literal}
+  <script type="text/javascript">
+    function showDeleteInDialog(valueID, groupID, contactID) {
+      var confirmText = '{/literal}{ts escape='js'}Are you sure you want to delete this record?{/ts}{literal}';
+      cj('#browseValues').after("<div id='delete-record'></div>");
+        cj('#delete-record').html(confirmText).dialog({
+          title: "{/literal}{ts escape='js'}Delete Record{/ts}{literal}",
+          modal: true,
+          width: 680,
+          overlay: {
+            opacity: 0.5,
+            background: "black"
+          },
+
+          buttons: {
+          {/literal}"{ts escape='js'}Cancel{/ts}"{literal}: function() {
+            cj(this).dialog("close");
+            cj('#delete-record').html('');
+          },
+          {/literal}"{ts escape='js'}OK{/ts}{literal}": function() {
+            deleteCustomValueRec(valueID, groupID, contactID);
+            window.setTimeout(function(){window.location.reload( )}, 1000);
+          }
+        }
+        });
+    }
+
+    function deleteCustomValueRec(valueID, groupID, contactID) {
+      var postUrl = {/literal}"{crmURL p='civicrm/ajax/customvalue' h=0 }"{literal};
+      cj.ajax({
+        type: "POST",
+        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');
+        }
+      });
+    }
+  </script>
+  {/literal}
 {else}
 {strip}
   {if $action eq 16 or $action eq 4} {* Browse or View actions *}
index 0037143ae17cbda99e6a8ef652c582ec4edce6a7..4604ba35797a3a0dc99bcd67b94a49355e55f8e9 100644 (file)
 {assign var="showEdit" value=1}
 {foreach from=$viewCustomData item=customValues key=customGroupId}
   {foreach from=$customValues item=cd_edit key=cvID}
+{if $multiRecordDisplay neq 'single'}
     <table class="no-border">
       {assign var='index' value=$groupId|cat:"_$cvID"}
-      {if $multiRecordDisplay neq 'single' and (($editOwnCustomData and $showEdit) or ($showEdit and $editCustomData and $groupId))}
+      {if ($editOwnCustomData and $showEdit) or ($showEdit and $editCustomData and $groupId)}
         <tr>
           <td>
             <a
         </tr>
       {/if}
       {assign var="showEdit" value=0}
-      {if $multiRecordDisplay neq 'single'}
         <tr id="statusmessg_{$index}" class="hiddenElement">
           <td><span class="success-status"></span></td>
         </tr>
-      {/if}
       <tr>
         <td id="{$cd_edit.name}_{$index}" class="section-shown form-item">
-          <div {if $multiRecordDisplay neq 'single'} class="crm-accordion-wrapper {if $cd_edit.collapse_display eq 0 or $skipTitle} {else}collapsed{/if}"{/if}>
+          <div class="crm-accordion-wrapper {if $cd_edit.collapse_display eq 0 or $skipTitle} {else}collapsed{/if}">
             {if !$skipTitle}
               <div class="crm-accordion-header">
                 {$cd_edit.title}
               </div>
             {/if}
-            <div {if $multiRecordDisplay neq 'single'} class="crm-accordion-body" {/if}>
-              {if $groupId and $cvID and $editCustomData and $multiRecordDisplay neq 'single'}
+            <div class="crm-accordion-body">
+              {if $groupId and $cvID and $editCustomData}
                 <div class="crm-submit-buttons">
                   <a href="#"
                      onclick="showDelete( {$cvID}, '{$cd_edit.name}_{$index}', {$customGroupId}, {$contactId} ); return false;"
                 </div>
               {/if}
               {foreach from=$cd_edit.fields item=element key=field_id}
-                <table class="crm-info-panel crm-section">
+                <table class="crm-info-panel">
                   <tr>
                     {if $element.options_per_line != 0}
                       <td class="label">{$element.field_title}</td>
-                      <td class="html-adjust content">
+                      <td class="html-adjust">
                         {* sort by fails for option per line. Added a variable to iterate through the element array*}
                         {foreach from=$element.field_value item=val}
                           {$val}
                       <td class="label">{$element.field_title}</td>
                       {if $element.field_type == 'File'}
                         {if $element.field_value.displayURL}
-                          <td class="html-adjust content">
+                          <td class="html-adjust">
                             <a href="{$element.field_value.displayURL}" class='crm-image-popup'>
                               <img src="{$element.field_value.displayURL}" height="100" width="100">
                             </a>
                           </td>
                         {else}
-                          <td class="html-adjust content">
+                          <td class="html-adjust">
                             <a href="{$element.field_value.fileURL}">{$element.field_value.fileName}</a>
                           </td>
                         {/if}
                       {else}
                         {if $element.field_data_type == 'Money'}
                           {if $element.field_type == 'Text'}
-                            <td class="html-adjust content">{$element.field_value|crmMoney}</td>
+                            <td class="html-adjust">{$element.field_value|crmMoney}</td>
                           {else}
-                            <td class="html-adjust content">{$element.field_value}</td>
+                            <td class="html-adjust">{$element.field_value}</td>
                           {/if}
                         {else}
-                          <td class="html-adjust content">
+                          <td class="html-adjust">
                             {if $element.contact_ref_id}
                             <a href='{crmURL p="civicrm/contact/view" q="reset=1&cid=`$element.contact_ref_id`"}'>
                               {/if}
         </td>
       </tr>
     </table>
+{else}
+   {foreach from=$cd_edit.fields item=element key=field_id}
+     <div class="crm-section">
+      {if $element.options_per_line != 0}
+          <div class="label">{$element.field_title}</div>
+          <div class="content">
+          {* sort by fails for option per line. Added a variable to iterate through the element array*}
+          {foreach from=$element.field_value item=val}
+             {$val}
+             <br/>
+          {/foreach}
+          </div>
+       {else}
+          <div class="label">{$element.field_title}</div>
+          {if $element.field_type == 'File'}
+          {if $element.field_value.displayURL}
+            <div class="content">
+              <a href="{$element.field_value.displayURL}" class='crm-image-popup'>
+               <img src="{$element.field_value.displayURL}" height="100" width="100">
+              </a>
+            </div>
+          {else}
+            <div class="content">
+              <a href="{$element.field_value.fileURL}">{$element.field_value.fileName}</a>
+            </div>
+          {/if}
+          {else}
+            {if $element.field_data_type == 'Money'}
+              {if $element.field_type == 'Text'}
+                 <div class="content">{$element.field_value|crmMoney}</div>
+              {else}
+                 <div class="content">{$element.field_value}</div>
+              {/if}
+            {else}
+              <div class="content">
+                {if $element.contact_ref_id}
+                  <a href='{crmURL p="civicrm/contact/view" q="reset=1&cid=`$element.contact_ref_id`"}'>
+                {/if}
+                {if $element.field_data_type == 'Memo'}
+                  {$element.field_value|nl2br}
+                {else}
+                  {$element.field_value}
+                {/if}
+                {if $element.contact_ref_id}
+                  </a>
+                {/if}
+              </div>
+            {/if}
+          {/if}
+       {/if}
+   {/foreach}
+{/if}
   {/foreach}
 {/foreach}
 {literal}
index e79714ad0aa586f39fe909263a9e05b032a4eb3d..89d15343e7e084d258ac15217ddee18874867f87 100644 (file)
@@ -68,7 +68,7 @@
 
   {if !$reachedMax}
     {if $pageViewType eq 'customDataView'}
-      <a accesskey="N" href="{crmURL p='civicrm/contact/view/cd/edit' q="reset=1&snippet=1&type=$ctype&groupID=$customGroupId&entityID=$contactId&cgcount=$cgcount&multiRecordDisplay=single"}" 
+      <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`"}"
 
       var profileName = {/literal}"{$ufGroupName}"{literal};
       cj('.action-item').each(function () {
-        if (!cj(this).attr('jshref')) {
+        if (!cj(this).attr('jshref') && !cj(this).hasClass('ignore-jshref')) {
           cj(this).attr('jshref', cj(this).attr('href'));
           cj(this).attr('href', '#browseValues');
         }
       cj(actionItemHeirarchy).click(function () {
         dataURL = cj(this).attr('jshref');
         dialogTitle = cj(this).attr('title');
-        formDialog(profileName, dataURL, dialogTitle);
+        if (!cj(this).hasClass('ignore-jshref')) {
+          formDialog(profileName, dataURL, dialogTitle);
+        }
       });
     });
     </script>