CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Discussion (deprecated) »
  • Feature Requests and Suggestions »
  • Usability Improvements (Moderator: Dave Greenberg) »
  • Edit Contact form doesn't use tag grouping
Pages: [1]

Author Topic: Edit Contact form doesn't use tag grouping  (Read 5673 times)

JoeMurray

  • Administrator
  • Ask me questions
  • *****
  • Posts: 578
  • Karma: 24
    • JMA Consulting
  • CiviCRM version: 4.4 and 4.5 (as of Nov 2014)
  • CMS version: Drupal, WordPress, Joomla
  • MySQL version: MySQL 5.5, 5.6, MariaDB 10.0 (as of Nov 2014)
Edit Contact form doesn't use tag grouping
August 10, 2009, 06:39:06 pm
Grouping tags on the Tags tab of a contact is a really great improvement. It would be a better UX if there was a similar interface for the Tags portion of the Groups and Tags section of the Contact Edit form.
Co-author of Using CiviCRM https://www.packtpub.com/using-civicrm/book

Yashodha Chaku

  • Forum Godess / God
  • Ask me questions
  • *****
  • Posts: 755
  • Karma: 57
    • CiviCRM
Re: Edit Contact form doesn't use tag grouping
August 11, 2009, 06:19:57 am
Quote
It would be a better UX if there was a similar interface for the Tags portion of the Groups and Tags section of the Contact Edit form.

Agreed. But if we have a n-level hierarchy for both groups and tags, it may not look good since they are placed next to each other on Contact Edit Form. IMO, linear format suits well in such a scenario.
Thoughts?

-Yashodha
Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

JoeMurray

  • Administrator
  • Ask me questions
  • *****
  • Posts: 578
  • Karma: 24
    • JMA Consulting
  • CiviCRM version: 4.4 and 4.5 (as of Nov 2014)
  • CMS version: Drupal, WordPress, Joomla
  • MySQL version: MySQL 5.5, 5.6, MariaDB 10.0 (as of Nov 2014)
Re: Edit Contact form doesn't use tag grouping
August 11, 2009, 07:34:43 am
Well, I'm doing a test migration for a client who has many dozens of tags in their legacy system, so the contrast is very dramatic in favour of the new approach. I don't think it's such an issue for groups. In fact, it might useful to use their hierarchies to create a similar UX for them.
Co-author of Using CiviCRM https://www.packtpub.com/using-civicrm/book

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Edit Contact form doesn't use tag grouping
September 10, 2009, 10:13:11 pm
OOps, just realised that I have a related advanced search hierarchy to fix. Thanks.

And I'll see if I can provide a patch for the edit (too late to put in the 3.0)

Stay tuned...

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

grahamgilchrist

  • I post occasionally
  • **
  • Posts: 70
  • Karma: 3
Re: Edit Contact form doesn't use tag grouping
November 05, 2009, 08:13:21 am
Sorry to resurrect this topic, but this is a feature I am also really interested in.

We have a number of different tag 'groups' divided up by parents. Whilst this is really clear on the contact view pages, most of our groups/tag work goes on in the contact edit pages, as having to save and then go to the groups/tags tab is a lot of UI steps. Our users get quite confused which tags they should be using on the edit page, and a lot of this would be saved by showing their hierarchy.
It would also be really useful to see the tag/group hierarchy on the manage groups/tags screens?

I can't see a feature request issue for this in the JIRA issue tracker. Am I allowed to create one?
I am happy to contribute some coding, I made a bit of a hack already for the tags part of the editing form on our site by modifying the buildQuickForm method in CRM/Contact/Form/Edit/TagsAndGroups.php

Is this the right sort of approach or does it need changing elsewhere?

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Edit Contact form doesn't use tag grouping
November 05, 2009, 09:55:00 am
Hi,

Definitely makes sense indeed to offer the hierarchy on the edit.

For the tag, shouldn't be too difficult as the code is already existing and used for the tag tab for instance, not that sure about the group.

And yes for the hierarchy as well on the admin, have to admit I quickly hacked it and didn't think much more than that. This is problably more complex as it uses the standard list admin screen, that only displays a list.

P.S. On a somehow related topic, it would be great to have the hierarchy as well in the input select in the standard simple search. I vaguely remember you can do that in html in a select, but couldn't find an example. Might have been dreaming ?

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

grahamgilchrist

  • I post occasionally
  • **
  • Posts: 70
  • Karma: 3
Re: Edit Contact form doesn't use tag grouping
November 05, 2009, 10:19:40 am
Yes, in the search options would also be great. We make heavy use of hierarchical tags, so propagating that throughout the UI would be high on my feature request list.
There is the HTML OPTGROUP:
http://www.w3schools.com/tags/tag_optgroup.asp

which allows you to subdivide items in a select box. I think it only supports one level of hierarchy though. We only make use of one level, but I imagine other sites use more. The other option is to simply indent the list items thus:

Code: [Select]
Tag 1
Tag 2
- Subtag 1
- Subtag 2
- Subtag 3
-- Subsubtag 1
-- Subsubtag 2
- Subtag 4
Tag 3
Tag 4

Unless you have more than 5 or so levels, this does not hugely impact the width of the select box either. I can't think of a use case where you would need a large number of tag levels like that, but I'm sure it exists and is probably and edge case?

I'm pretty familiar with PHP and am willing to do some of the work, but am still getting to grips with the CiviCRM architecture, so if someone could point me to the files I need to modify to update the tags in the search boxes and the edit contact pages, I could have a go and submit it as a patch. At the moment my approach for the contact edit pages was to edit the BuildQuickForm method in CRM/Contact/Form/Edit/TagsAndGroups.php, where it loads the tag list. I changed the code so that the tags are re-ordered to come consecutively after their parents and applied a css class to subtags which I added some left padding to.

Here is the code I used replacing lines 130-139 of CRM/Contact/Form/Edit/TagsAndGroups.php in civicrm 3.0.1:
Code: [Select]
        if ( $type & CRM_Contact_Form_Edit_TagsandGroups::TAG ) {
            $fName = 'tag';
            if ($fieldName) {
                $fName = $fieldName;
            }
            $form->_tagGroup[$fName] = 1;
            $elements = array( );
            $tag =& CRM_Core_PseudoConstant::tag  ( );

            //new stuff added here
            //--------------------------------------------------------
            //this should really be replaced with a recursive db search to find the full tags
            //heirarchy. This currently fails for more than 1 level deep.

            //get list of parent tag ids
            CRM_Core_PseudoConstant::populate( $tag_parents, 'CRM_Core_DAO_Tag', true, $retrieve = 'parent_id', $filter = 'is_active', $condition = null, $orderby = 'parent_id', $key = 'id' );
            $form->assign('tag_parents', $tag_parents);
            $sorted_parent_list = array();
            //sort array with parents id before all it's children
            $flag = array();
            foreach ($tag_parents as $id => $this_parent) {
                if ($this_parent && $flag[$this_parent] == false) {
                    unset($sorted_parent_list[$this_parent]);
                    $sorted_parent_list[$this_parent] = '';
                    $sorted_parent_list[$id] = $this_parent;
                    $flag[$this_parent] = true;
                } else {
                    $sorted_parent_list[$id] = $this_parent;
                }
            }

            foreach ($sorted_parent_list as $id => $this_parent) {
                if ($this_parent) {
                    $elements[] =& HTML_QuickForm::createElement('checkbox', $id, null, $tag[$id], 'class="subtag"');
                } else {
                    $elements[] =& HTML_QuickForm::createElement('checkbox', $id, null, $tag[$id]);
                }
            }

It's quite hacky and only works for one level deep. I think it should really be replaced with a recursive call to CRM_Core_PseudoConstant::populate to support deeper levels, and then rendering the items in nested divs which can be indented with css,  but I don't quite understand how to do this in quickform yet. Any pointers would be gratefully received.

Any better ideas?


P.S. - I recall we also had this conversation in the comments of a page on the civicrm site as well, but for the life of me can't find it now :)

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Edit Contact form doesn't use tag grouping
November 05, 2009, 12:21:37 pm

the wiki page is here: http://wiki.civicrm.org/confluence/display/CRM/CiviCRM+v3.1?focusedCommentId=23724227#comment-23724227

but this forum is a better place to discuss :)

to answer your questions below:

1. In general, recursive calls to the DB are not great. preferably get all the active tags in one db call and then build the tree within PHP

2. if you can edit your fix to handle multiple levels (along with search) that would be great and we could get it into 3.2

3. note that there is a patch to add optgroup support and was rolled into 3.1, but had to be rolled back due to some issues

http://issues.civicrm.org/jira/browse/CRM-5246

4. The search code is here:

CRM/Contact/Form/Search/Basic.php
CRM/Contact/Form/Search/Criteria.php

search for _tag

ping us on IRC if u need any help or want a quick response

lobo


A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Edit Contact form doesn't use tag grouping
November 05, 2009, 11:29:38 pm
Hi,

You can reuse the function that is used on the tab for the tags. It does one fetch only on the db and reorder in PHP and build a 3 level array. you can use that array directly.

Limitation: no more than 3 levels.

-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

grahamgilchrist

  • I post occasionally
  • **
  • Posts: 70
  • Karma: 3
Re: Edit Contact form doesn't use tag grouping
November 06, 2009, 04:02:49 am
Ok that sounds good - and means I don't have to re-code the sorting array :)

If it's limited to 3 levels deep, what happens to tags deeper than that?
We don't want them to be ignored completely. Does it just place them at the 3rd level deep? This would seem like a good compromise as it wouldn't require huge width to display many layered tags

grahamgilchrist

  • I post occasionally
  • **
  • Posts: 70
  • Karma: 3
Re: Edit Contact form doesn't use tag grouping
November 06, 2009, 11:37:37 am
Ok, I've made changes in 3 files which supports the 3-level tag hierarchy display:

CRM/Contact/Form/Edit/TagsAndGroups.php
CRM/Contact/Form/Search/Basic.php
CRM/Contact/Form/Search/Criteria.php

This adds the 3-level tag heirarchy to the basic search dropdown, the advanced search tag list, and the contact edit page. It uses Xavier's tree array, and displays the basic search dropdown using text indents and modifies the advanced search and contact edit pages using a class applied to the checkbox indicating the tag level. Some extra CSS is therefore needed for the latter two.
These solutions will work for an array of any depth, so if Xavier's array creating function was ever updated to allow more tag levels, these functions would work for the extra levels. Some extra css would be needed for the advanced search and contact edit screens.
I implemented these in my own installation by copying the core files to my custom php directory and editing them there, so as not to interfere with future upgrades.

To support indented tags on the contact edit screen:
CRM/Contact/Form/Edit/TagsAndGroups.php

change lines 137-140:
Code: [Select]
           $tag =& CRM_Core_PseudoConstant::tag  ( );
            foreach ($tag as $id => $name) {
                $elements[] =& HTML_QuickForm::createElement('checkbox', $id, null, $name);
            }
to:
Code: [Select]
           require_once 'CRM/Core/BAO/Tag.php';
            $tags = new CRM_Core_BAO_Tag ();
            $tag_tree = $tags->getTree();

            $form->assign('tag_tree', $tag_tree);
            $tag_level = '0';
            self::render_tag_tree(&$elements, $tag_tree, $level);

also add the following function to the class:
Code: [Select]
   static function render_tag_tree(&$elements, $tag_tree, $level = '0') {
            $level += 1;
            foreach ($tag_tree as $this_tag_id => $this_tag) {
                $elements[] =& HTML_QuickForm::createElement('checkbox', $this_tag_id, null, $this_tag['name'], 'class="tag level'.$level.'"');
                self::render_tag_tree(&$elements, $this_tag['children'], $level);
            }
    }

To support indented tags on the advanced search criteria screen:
CRM/Contact/Form/Edit/Criteria.php

Change lines 65-67:

Code: [Select]
           foreach ($form->_tag as $tagID => $tagName) {
                $form->_tagElement =& $form->addElement('checkbox', "tag[$tagID]", null, $tagName);
            }

to this:
Code: [Select]
           $tag_level = '0';
            self::render_tag_tree(&$form, $tree, $level);

and add this function to the class:
Code: [Select]
   static function render_tag_tree(&$form, $tag_tree, $level = '0') {
            $level += 1;
            foreach ($tag_tree as $this_tag_id => $this_tag) {
                $form->_tagElement = &$form->addElement('checkbox', "tag[$this_tag_id]", null, $this_tag['name'], 'class="tag level'.$level.'"');
                self::render_tag_tree(&$form, $this_tag['children'], $level);
            }
    }

To support indented tags on the basic search screen:
CRM/Contact/Form/Edit/Basic.php

Change lines 116-117:
Code: [Select]
           $tag = array('' => ts('- any tag -')) + $this->_tag;
            $this->_tagElement =& $this->addElement('select', 'tag', ts('with'), $tag);

to:

Code: [Select]
           require_once 'CRM/Core/BAO/Tag.php';
            $tags = new CRM_Core_BAO_Tag ();
            $tag_tree = $tags->getTree();

            $tag_list = array('' => ts('- any tag -'));
            $tag_level = '0';
            self::_render_tag_tree(&$tag_list, $tag_tree, $level);

            $this->_tagElement =& $this->addElement('select', 'tag', ts('with'), $tag_list);

and add this function to the class:
Code: [Select]
   static function _render_tag_tree(&$tag_list, $tag_tree, $level = '0') {
            $level += 1;
            $indent_string = "";
            for ($i = 2; $i <= $level; $i++) {
                $indent_string .= "--";
            }
            if (strlen($indent_string) > 0) $indent_string .= " ";
            foreach ($tag_tree as $this_tag_id => $this_tag) {
                $tag_list[$this_tag_id] = $indent_string.$this_tag['name'];
                self::_render_tag_tree(&$tag_list, $this_tag['children'], $level);
            }
    }

Add css for the search criteria and edit pages

I also added the following css to the civicrm.css file to actually display the indents.

Code: [Select]
input.tag.level2 {margin-left: 2em; }
input.tag.level3 {margin-left: 4em; }

Now, this lot probably doesn't conform to the project coding standards so I would welcome any help and suggestions to get it included in the main project, as I think it will be genuinely useful for a lot of people, plus I don't want to be maintaining lots of custom code between upgrades :)

I would really like to do the same thing for groups, but am having trouble locating the files that render the pages again. Any suggestions? Groups might be a little more difficult because the way they display is also dependent on ACL.
I am learning the Civi architecture slowly!
« Last Edit: November 06, 2009, 11:45:10 am by grahamgilchrist »

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Edit Contact form doesn't use tag grouping
November 06, 2009, 01:40:44 pm

in most cases tags and groups are in exactly the same place. any specific instance of where you cannot find the groups code?

i dont know if this is the same patch xavier had submitted, but that patch broke advanced search and we had to roll it back

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

grahamgilchrist

  • I post occasionally
  • **
  • Posts: 70
  • Karma: 3
Re: Edit Contact form doesn't use tag grouping
November 06, 2009, 02:33:54 pm
ok, I will have a closer look at groups on monday.

Do you have a link to Xaviers patch? Is it this you're referring to?
http://issues.civicrm.org/jira/browse/CRM-3840

I'm not sure how he did it, but essentially all I am doing here is adding a css class to the checkboxes on the advanced search form, so I'm not sure how it could break anything. Will do some more testing.

I think we have had different approaches and goals. It looks like he is trying to update the tag edit page, whereas I am just trying to update the interface that my contact editors see? Sorry, I am still getting to grips with the project and don't quite understand how everything fits together yet!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Discussion (deprecated) »
  • Feature Requests and Suggestions »
  • Usability Improvements (Moderator: Dave Greenberg) »
  • Edit Contact form doesn't use tag grouping

This forum was archived on 2017-11-26.