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) »
  • Support »
  • Using CiviCRM »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • Missing 'CiviCRM Search' block in 3.1 installation
Pages: [1]

Author Topic: Missing 'CiviCRM Search' block in 3.1 installation  (Read 2184 times)

websynapse

  • I post frequently
  • ***
  • Posts: 216
  • Karma: 3
    • Ryan Kennedy
  • CiviCRM version: 4.3.7
  • CMS version: Drupal 6
Missing 'CiviCRM Search' block in 3.1 installation
March 22, 2010, 06:06:16 pm
Hi all

Am I blind, or has the CiviCRM Search block been removed for 3.1?

That's the block where you type Lastname, Firstname and it autocompletes.

I have CiviCRM Quick Add, CiviCRM Create New Record, CiviCRM Language Switcher, CiviCRM Full-text Search and CiviCRM Upcoming Events available, but no CiviCRM Search.

cheers

Kiran Jagtap

  • Ask me questions
  • ****
  • Posts: 533
  • Karma: 51
Re: Missing 'CiviCRM Search' block in 3.1 installation
March 24, 2010, 01:05:38 am
Now it is present as a part of navigation menu on the top of page at left corner.

kiran
You Are Designed To Choose... Defined By Choice.

websynapse

  • I post frequently
  • ***
  • Posts: 216
  • Karma: 3
    • Ryan Kennedy
  • CiviCRM version: 4.3.7
  • CMS version: Drupal 6
Re: Missing 'CiviCRM Search' block in 3.1 installation
March 24, 2010, 12:49:04 pm
So it is, thank you.

mhonman

  • I’m new here
  • *
  • Posts: 20
  • Karma: 2
Re: Missing 'CiviCRM Search' block in 3.1 installation
May 24, 2010, 04:02:21 am
We have a "staff" website where are are going to expose some data from CiviCRM so that workers can get each other's contact details (workers are scattered around the world so this is a real need!).

So it's not a CiviCRM-centric site and the new CiviCRM menu is a bit like overkill. It would be *very* useful to have the traditional type of Quick Search block for use in Drupal. Any chance of this being retrofitted to Civi 3.x? If it is technically feasible I would be happy to have a go at it.

I'd imagine there are two possibilities,
  • adapt the Civi 2.x block to the CiviCRM 3.0 back-end infrastructure
  • Create a new block that uses the same AJAX interface as the search box in the new menu

Slightly off-topic, but thinking of future projects, if there is a way to embed a search box in the Drupal UI (via theme, I guess) - hooking into the new menu's Ajax that could be interesting. Sorry to be vague, I've still got a lot to learn.

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: Missing 'CiviCRM Search' block in 3.1 installation
May 24, 2010, 06:20:44 am

yes, either of your two options are possibilities and should be easy to accomplish via a drupal block

you might want to check the html/js generated for both cases and adapt them to a drupal block. please share your code once u've developed and tested it

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

mhonman

  • I’m new here
  • *
  • Posts: 20
  • Karma: 2
Re: Missing 'CiviCRM Search' block in 3.1 installation
May 25, 2010, 05:24:48 am
[edit... still digging here... ignorance is bliss, but not today!]

Mark
« Last Edit: May 25, 2010, 02:39:44 pm by mhonman »

mhonman

  • I’m new here
  • *
  • Posts: 20
  • Karma: 2
Re: Missing 'CiviCRM Search' block in 3.1 installation
May 26, 2010, 09:22:10 am
Right... here we go...

**UPDATE 1 Nov 2011 - a wee bugfix to solve a problem that raised its head with Civi 3.4**

First the disclaimer... this is the first time I've dealth with Ajax, and just about my first go at PHP, so there are likely to be lots of stupid errors, particularly violations of "house style".

Working from our test installation of CiviCRM 3.1.4, the following changes have been made

  • CRM/Core/Block.php - added a new CONTACT_SEARCH block type, linked to the new template...
  • templates/CRM/Block/ContactSearch.tpl - based on bits of the FullTextSearch and Navigation templates. References Basic search help from the existing file templates/CRM/Contact/Form/Search/basic.hlp

Changes to Block.php

58,59c58
<         FULLTEXT_SEARCH = 7,
<         CONTACT_SEARCH  = 8;
---
>         FULLTEXT_SEARCH = 7;
161,171c160
<                                                                         'region'     => 'left' ),
<                                        self::CONTACT_SEARCH => array(  'template'   => 'ContactSearch.tpl',
<                                                                         'info'       => ts('CiviCRM Contact Search'),
<                                                                         'subject'    => ts('Contact Search'),
<                                                                         'active'     => true,
<                                                                         'cache'      => BLOCK_CACHE_GLOBAL,
<                                                                         'visibility' => 1,
<                                                                         'weight'     => -93,
<                                                                         'status'     => 0,
<                                                                         'pages'      => 'civicrm*',
<                                                                         'region'     => 'left' ),
---
>                                                                         'region'     => 'left' )
311,313d299
<         case self::CONTACT_SEARCH:
<             break;
<


The new ContactSearch block template

Somehow I feel that it is possible to do this without the javascript cut-and-paste... that feels like a maintenance problem in the making.

The other thing that feels wrong is the naming of the input fields - when they were sort_name and contact_id (as in the menu search box) the javascript was picking up the ones in the civicrm menu & that was why autocomplete didn't work. However when the search form is submitted the field needs to be called sort_name. Hence the use of an field ID that differs from the field name - but there must be some way of limiting the scope of the javascript to just a part of the DOM?


<div class="block-crm">
    <form id="id_contact_search_block" onsubmit="getContactSearchURLValue( );" method="post" name="contact_search_block" action="{crmURL p='civicrm/contact/search/basic' h=0 }"/>
        <div style="margin-bottom: 8px;">
        <input type="text" class="form-text" id="contact_search_block_sort_name" name="sort_name" style="width: 10em;"/>
        <input type="hidden" id="contact_search_block_contact_id" value=""/>
        <input type="submit" class="form-submit default" name="_qf_Basic_refresh" value="{ts}Go{/ts}"/>
    </div>
    <a title="{ts}Go to Advanced Search{/ts}" href="{crmURL p="civicrm/contact/search/advanced" h=0 q="reset=1"}">&raquo; {ts}Advanced Search{/ts}</a>
        {help id="id-basic-criteria" file="CRM/Contact/Form/Search/Basic.hlp"}
    </form>
</div>
{literal}
<script type="text/javascript">
function getContactSearchURLValue( )
{
    var contactId =  cj( '#contact_search_block_contact_id' ).val();
    if ( ! contactId || isNaN( contactId ) ) {
        var sortValue = cj( '#contact_search_block_sort_name' ).val();
        contactId = '';
        if ( sortValue ) {
            //using xmlhttprequest check if there is only one contact and redirect to view page
            var dataUrl = {/literal}"{crmURL p='civicrm/ajax/contact' h=0 q='name='}"{literal} + sortValue;

            var response = cj.ajax({
                url: dataUrl,
                async: false
                }).responseText;

            if ( response != '\n' ) {
                contactId = response;
            }
        }
    }

    if ( contactId ) {
        var url = {/literal}"{crmURL p='civicrm/contact/view' h=0 q='reset=1&cid='}"{literal} + contactId;
        document.getElementById('id_contact_search_block').action = url;
    }
}
cj( function() {
    var contactUrl = {/literal}"{crmURL p='civicrm/ajax/contactlist' h=0 }"{literal};

    cj( '#contact_search_block_sort_name' ).autocomplete( contactUrl, {
        width: 200,
        selectFirst: false,
        minChars:2,
        matchContains: true
    }).result(function(event, data, formatted) {
       document.location={/literal}"{crmURL p='civicrm/contact/view' h=0 q='reset=1&cid='}"{literal}+data[1];
       return false;
    });
});
</script>
{/literal}

« Last Edit: November 02, 2011, 02:16:39 am by mhonman »

mhonman

  • I’m new here
  • *
  • Posts: 20
  • Karma: 2
Re: Missing 'CiviCRM Search' block in 3.1 installation
November 02, 2011, 10:28:27 am
New ContactSearch.tpl

Based on templates/CRM/Common/menu.tpl in CiviCRM 3.4.7, here is the latest product of the cut-paste-and-mangle shop. Probably still pretty hideous, but solves a long-standing (ignorance-based!) problem with rendering of the drop-down autocomplete list.

<div class="block-crm">
    <form id="id_contact_search_block" onsubmit="getContactSearchURLValue( );" method="post" name="contact_search_block" action="{crmURL p='civicrm/contact/search/basic' h=0 }"/>
        <div style="margin-bottom: 8px;">
        <input type="text" class="form-text" id="contact_search_block_sort_name" name="sort_name" style="width: 10em;"/>
        <input type="hidden" id="contact_search_block_contact_id" value=""/>
        <input type="submit" class="form-submit default" name="_qf_Basic_refresh" value="{ts}Go{/ts}"/>
    </div>
    <a title="{ts}Go to Advanced Search{/ts}" href="{crmURL p="civicrm/contact/search/advanced" h=0 q="reset=1"}">&raquo; {ts}Advanced Search{/ts}</a>
        {help id="id-basic-criteria" file="CRM/Contact/Form/Search/Basic.hlp"}
    </form>
</div>
<script type="text/javascript">
var contactViewUrl="{crmURL p='civicrm/contact/view' h=0 q='reset=1'}";
{literal}
function getContactSearchURLValue( )
{
    var contactId =  cj( '#contact_search_block_contact_id' ).val();
    if ( ! contactId || isNaN( contactId ) ) {
        var sortValue = cj( '#contact_search_block_sort_name' ).val();
        if ( sortValue ) {
            //using xmlhttprequest check if there is only one contact and redirect to view page
            var dataUrl = {/literal}"{crmURL p='civicrm/ajax/contact' h=0 q='name='}"{literal} + sortValue;

            var response = cj.ajax({
                url: dataUrl,
                async: false
                }).responseText;

            if ( response != '\n' ) {
                contactId = response;
            }
        }
    }

    if ( contactId ) {
        var url = {/literal}"{crmURL p='civicrm/contact/view' h=0 q='reset=1&cid='}"{literal} + contactId;
        document.getElementById('id_contact_search_block').action = url;
    }
}
cj( function() {
     var contactUrl = {/literal}"{crmURL p='civicrm/ajax/rest' h=0 q='fnName=civicrm/contact/search&json=1&return[display_name]=1&return[contact_type]&return[email]&rowCount=15'}"{literal};

     cj("#contact_search_block_sort_name").autocomplete( contactUrl, {
       dataType:"json",
       extraParams:{sort_name:function () { //extra % to force looking to the data typed anywhere in the name
              return "%"+$("#contact_search_block_sort_name").val();}
       },
       formatMatch: function (data,i,max) {
         data.display_name+ " " + data.email;
       },
       parse: function(data){
         //either an array of objects or {is_error":0} ???
         if ("is_error" in data) { return [{data:{contact_type:"Individual"},value:"create an individual"},
                                           {data:{contact_type:"Organization"},value:"create an Organization"},
                                           {data:{contact_type:"Household"},value:"create an Household"}
                                          ];};;
         var parsed = new Array();
         for(cid in data){
           parsed.push({ data:data[cid], value:data[cid].sort_name, result:data[cid].sort_name });
         }
         return parsed;
       },
       formatItem: function(data,i,max,value,term){
          if ("email" in data)
            email = " ("+ data["email"]+")";
          else
            email = "";
          return "<span class='"+data["contact_type"]+ "'>"+ value + email + "</span>";
       },
       width: 500,
       delay:200,
       max:15,
       minChars:1,
       selectFirst: true,
       matchContains: true
     }).result(function(event, data, formatted) {
         document.location= contactViewUrl+'&cid='+data["contact_id"];
     });
});
</script>
{/literal}

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • Missing 'CiviCRM Search' block in 3.1 installation

This forum was archived on 2017-11-26.