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 »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Writing your own dashlet?
Pages: [1]

Author Topic: Writing your own dashlet?  (Read 888 times)

chriscant

  • I post occasionally
  • **
  • Posts: 66
  • Karma: 4
    • PHDCC
  • CiviCRM version: 4.2.19
Writing your own dashlet?
August 24, 2011, 09:02:36 am
It was great to meet people at CiviCom London.  I asked about simplifying the user interface for admin staff and got various ideas, such as turning off parts of CiviCRM, customising permissions, through to writing a Drupal module - all fine. 

My immediate thoughts are to configure the dashboard and add buttons to the View Contact screen.  Using the techniques Xavier showed I've proven that I can use jquery to add items to the templates of these pages.

I am wondering if there's a standard way to write your dashlets.  I know dashlets are reports; at this stage, I'm thinking along the lines of custom code to do exactly what I want, eg display some buttons. (I also know that there's a hook: hook_civicrm_dashboard)

Eventually, I might come up with some ideas on what general purpose functionality could be provided to add items in these places, eg to make a Control Panel of simple buttons that take you to the right place.

PS  Here's how I added code to the Dashboard and View Contact screens, using Xavier's techniques.  I haven't used the "extra" templates but the code will work in these.

For the Dashboard I added this to the end of /CRM/Contact/Page/DashBoardDashlet.tpl, copied into a custom template directory.  If you are on 3.4.3 / 4.0.3 or later, just put this code in DashBoardDashlet.extra.tpl.  The code puts a very simple DIV before the DIV that contains all the user's dashlets.

Code: [Select]
{literal}
<script type="text/javascript">
 $(document).ready(function () {
cj("#civicrm-dashboard").before('<div>Well done</div>');
});
</script>
{/literal}

For the View Contact screen, I added this to the end of /CRM/Contact/Page/View/Summary.tpl.  It adds another button after Edit on the page.

Code: [Select]
{literal}
<script type="text/javascript">
 $(document).ready(function () {
var NewButton = '<li><a title="Dashboard" class="button" href="/civicrm/dashboard&reset=1">Dashboard</a></li>';
cj("#actions").append(NewButton);
});
</script>
{/literal}

To make these examples more useful, you'd need to add some code, eg to get the current contact id.  This looks like it will be much easier if you're using the APIv3 available in 3.4/4 - though the new API can be back-ported into earlier versions.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Writing your own dashlet?

This forum was archived on 2017-11-26.