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) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • edit via profile pop up
Pages: [1]

Author Topic: edit via profile pop up  (Read 888 times)

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
edit via profile pop up
September 06, 2012, 08:45:40 am
Hey there,

I want to enable editing some records on a report via a pop up profile.  I have got a fair amount of the way down the road - I am able to open the pop up - but am now stuck.  Maybe I am missing a trick and this functionality already exists (do you know anywhere where you can edit contacts (as opposed to create them) via a profile pop up?)).

But I don't get how CiviCRM implements this.  Here is what I am doing.

I have a crude understanding of jquery dialogue http://jqueryui.com/demos/dialog/ including the button options and the close method. So far I have this function that I am binding to a link as so:

Code: [Select]
<a href="#" onclick="updateViaProfile(17332); return false;">e</a>
Code: [Select]
function updateViaProfile( contactID ) {

    var dataURL = {/literal}"{crmURL p="civicrm/profile/create" q="reset=1&snippet=5&context=dialog&blockNo=1&gid=4&createCallback=1&id=" h=0}"{literal};
    dataURL = dataURL + contactID;

    cj.ajax({
        url: dataURL,
        success: function( content ) {
            cj( '#update_via_profile' ).show( ).html( content ).dialog({
                title: "Update contact details",
                modal: true,
                }
               
            });
        }
    });
}

What I am unsure about is how to bind to the 'Save' on the profile snippet so that it actually saves the edits in the profile, closes the pop up and refreshes by report with the new data.

Any help appreciated :)
Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

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 via profile pop up
September 06, 2012, 10:26:05 am
Hi,

If you keep putting javascript inline in the code like that,  the gods of the interwebs cry a little inside the tubes;) NEVER put javascript inline , do

Code: [Select]
<a id='yourid'>...
<script>
cj(function($){
  $('#yourid').click(function(){...}
});

As for your question, You should try (assuming you are on 4.2) using the following:

Code: [Select]
<a class='crm-editable' href='{crmURL p="civicrm/profile/create" q="reset=1gid=4"}"}>edit via profile</a>

If you want to edit, the url is (top of my head, you will need to check) civicrm/profile/edit?gid=xx&id=yy

Or whatever your "normal way url". The trick is to add the class crm-editable
and
{include file="CRM/common/crmeditable.tpl"}
Somewhere (at the bottom of your tpl) to start the edit in place magic

If everything works according to the plan the edit in place
1) add a snippet=1
2) open in a dialog
3) add a snippet=1 in the form so you get the result in without the layout
4) modify the save so it does an ajax save (awesome form plugin)
5) get the result and display it in the dialog if it's an error
6) close the dialog if ok

Check out js/jquery/jquery.crmeditable.js if you want to look at how it's done

Not super happy with 6 still, and I would like to be able to know what has been changed and return that in a json, but should get you closer to where you want to be.

please let me know if works in your case too.

X+
« Last Edit: September 06, 2012, 12:02:19 pm by Michael McAndrew »
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Re: edit via profile pop up
September 06, 2012, 11:41:00 am
hey xavier - thanks for the reply

do you mean civicrm/profile/edit ? and wouldn't i need to pass the contact id somehow? are you not happy with 6) because you want to update the page?

i am on 4.1.6 sadly - can't upgrade for a couple of weeks but will try when i do and (am using the bits i can now)...
Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Re: edit via profile pop up
September 06, 2012, 11:52:22 am
ps. can you tell me (or get the gods of the interwebs to tell me) what the best way to call that function for a specific contact id is? since this will be a report full of contacts, i need a way of specifying which contact to edit.
Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

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 via profile pop up
September 06, 2012, 12:12:02 pm
Quote from: Michael McAndrew on September 06, 2012, 11:41:00 am

do you mean civicrm/profile/edit ? and wouldn't i need to pass the contact id somehow?

yes, cid=yy (or contact_id=yy ?)

Quote from: Michael McAndrew on September 06, 2012, 11:41:00 am
are you not happy with 6) because you want to update the page?


Yes, don't know about your use case, but in general you'd want to update the page that contained that dialog.

Quote from: Michael McAndrew on September 06, 2012, 11:41:00 am

i am on 4.1.6 sadly - can't upgrade for a couple of weeks but will try when i do and (am using the bits i can now)...

If you copy js/jquery/crmeditable.js and includes it in the list of js, should work (not for the other edit in place, but for the dialog mode it should)

Code: [Select]
can you tell me (or get the gods of the interwebs to tell me) what the best way to call that function for a specific contact id is? since this will be a report full of contacts, i need a way of specifying which contact to edit.

Well, if you create the link in the template for each contact (row?), you just have to put the right url with the contact id for each row.

I you need to do it dynamically, What I push as the new standard and what I'm using for the edit in place is to put in a parent element in the dom (eg if it's a list in the tr, otherwise in a div:
<tr class='crm-entity' id='contact_{$row.contact_id}'>

(assuming you have the contact id assigned somewhere in the template, adjust the {$row.contact_id} accordingly)
Then in js, you look for the nearest parent that has the class crm-entity and extract the id
Code: [Select]
            var id= $i.closest('.crm-entity').attr('id');
            if (id) {
              var e=id.match(/(\S*)-(\S*)/);
               if (!e)
                 $().crmNotification ("Couldn't get the entity id. You need to set class='crm-entity' id='{entityName}-{id}'",'notification',this);
              //var entity=e[1];
              var contact_id=e[2];
            }


and you have it.
crmeditable has a method getEntityID, but it's private. Might make it available to outside if needed.

Another way the gods of the interwebs are telling me to use is the html5 data, so
instead of

<tr class='crm-entity' id='contact_{$row.contact_id}'>

you do

<tr class='crm-entity' data-entity='contact' data-id='{$row.contact_id}'>

and the js is

Code: [Select]
            var contact_id= $i.closest('.crm-entity').data('id');

The data-entity='contact' is not necessary, but they are telling me it's good practice.
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • edit via profile pop up

This forum was archived on 2017-11-26.