From b2703f3bfc3fb86715a53ea0d03793e491cf660a Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 9 Sep 2013 15:05:37 -0500 Subject: [PATCH] Fix contact tag tab with tagsets --- templates/CRM/Tag/Form/Tag.tpl | 52 +++++++++++----------------------- templates/CRM/common/Tag.tpl | 24 ++++++---------- 2 files changed, 25 insertions(+), 51 deletions(-) diff --git a/templates/CRM/Tag/Form/Tag.tpl b/templates/CRM/Tag/Form/Tag.tpl index d75cee5b87..ba980ca598 100644 --- a/templates/CRM/Tag/Form/Tag.tpl +++ b/templates/CRM/Tag/Form/Tag.tpl @@ -47,42 +47,10 @@ }); cj("#tagtree input").change(function(){ - tagid = this.id.replace("check_", ""); - //get current tags from Summary and convert to array - var tagLabels = cj.trim( cj("#tags").text( ) ); - if ( tagLabels ) { - var tagsArray = tagLabels.split(','); - } - else{ - var tagsArray = new Array(); - } - - //get current tag label - var currentTagLabel = cj("#tagLabel_" + tagid ).text( ); - if (this.checked) { - CRM.api('entity_tag','create',{entity_table:entityTable,entity_id:entityID,tag_id:tagid}); - // add check to tab label array - tagsArray.push( currentTagLabel ); - } - else { - CRM.api('entity_tag','delete',{entity_table:entityTable,entity_id:entityID,tag_id:tagid}); - // build array of tag labels - tagsArray = cj.map(tagsArray, function (a) { - if ( cj.trim( a ) != currentTagLabel ) { - return cj.trim( a ); - } - }); - } - - //showing count of tags in summary tab - var existingTagsInTagset = cj('.token-input-delete-token-facebook').length; - var tagCount = cj("#tagtree input:checkbox:checked").length + existingTagsInTagset; - cj('#tab_tag a em').html('' + tagCount); - tagCount ? cj('#tab_tag').removeClass('disabled') : cj('#tab_tag').addClass('disabled'); - - //update summary tab - tagLabels = tagsArray.join(', '); - cj("#tags").html( tagLabels ); + var tagid = this.id.replace("check_", ""); + var op = (this.checked) ? 'create' : 'delete'; + CRM.api('entity_tag', op, {entity_table: entityTable, entity_id: entityID, tag_id: tagid}); + CRM.updateContactSummaryTags(); }); //load js tree. @@ -98,6 +66,18 @@ {/literal} {/if} {literal} + } + + CRM.updateContactSummaryTags = function() { + var tags = []; + cj('.tag-section .token-input-token-facebook p, #tagtree input:checkbox:checked+label').each(function() { + tags.push(cj(this).text()); + }) + // showing count of tags in summary tab + cj('#tab_tag a em').html('' + tags.length); + tags.length ? cj('#tab_tag').removeClass('disabled') : cj('#tab_tag').addClass('disabled'); + // update summary tab + cj("#tags").html(tags.join(', ')); }; })(); {/literal} diff --git a/templates/CRM/common/Tag.tpl b/templates/CRM/common/Tag.tpl index 6567ea2d89..f16417a6be 100644 --- a/templates/CRM/common/Tag.tpl +++ b/templates/CRM/common/Tag.tpl @@ -32,23 +32,9 @@ hintText: hintText, onAdd: function ( item ) { processContactTags_{/literal}{$tagset.parentID}{literal}( 'select', item.id ); - - //update count of tags in summary tab - if ( cj( '.ui-tabs-nav #tab_tag a' ).length ) { - var existingTagsInTagset = cj('.token-input-delete-token-facebook').length; - var tagCount = cj("#tagtree input:checkbox:checked").length + existingTagsInTagset; - cj( '.ui-tabs-nav #tab_tag a' ).html( 'Tags ' + tagCount + ''); - } }, onDelete: function ( item ) { processContactTags_{/literal}{$tagset.parentID}{literal}( 'delete', item.id ); - - //update count of tags in summary tab - if ( cj( '.ui-tabs-nav #tab_tag a' ).length ) { - var existingTagsInTagset = cj('.token-input-delete-token-facebook').length; - var tagCount = cj("#tagtree input:checkbox:checked").length + existingTagsInTagset; - cj( '.ui-tabs-nav #tab_tag a' ).html( 'Tags ' + tagCount + ''); - } } } ); @@ -77,8 +63,12 @@ setVal[x] = valArray[x]; } } + CRM.alert('', '{/literal}{ts escape='js'}Removed{/ts}{literal}', 'success'); } - else if ( response.action == 'select' ) { + else { + CRM.alert('', '{/literal}{ts escape='js'}Saved{/ts}{literal}', 'success'); + } + if ( response.action == 'select' ) { setVal = valArray; setVal[ setVal.length ] = response.id; } @@ -86,6 +76,10 @@ var actualValue = setVal.join( ',' ); cj( ".contact-taglist_{/literal}{$tagset.parentID}{literal}" ).val( actualValue ); } + // update contact summary tab + if (CRM.updateContactSummaryTags) { + CRM.updateContactSummaryTags(); + } }, "json" ); } -- 2.25.1