Page 1 of 1

Make Email module active for related and/or selected records

PostPosted: Tue Sep 15, 2009 1:07 am
by zabelle_motte
Hello,

I have been installing the Email module that works fine and I would like to make this module working with related records list and/or with selected records.

It seems the email action (defined in the actions.ini of the Email Module) is associated to the "result-list-actions" div, that is used to present every action tool set.

I found this interresting post on the same king of question :
http://xataface.com/forum/viewtopic.php?t=4484#22151

This let me think that I have to define a specific action of category "selected_result_actions" and a specific javascript as url.
Or perhaps directly adapt the email module to enable a new action on category "selected_result_actions"?

I also found how to call the email action with specified items :
...index.php?-action=email&-table=personnes&id=11 OR =91

The post below seems also interresting to understand how to make an action on related records :
http://xataface.com/forum/viewtopic.php?t=4325#21566

So, may you help me to match all of these ?


Thanks in advance.

Zabelle

I make a try ...

PostPosted: Tue Sep 15, 2009 3:21 am
by zabelle_motte
While compiling the ideas in the above link, I tried to adapt the actions.ini file of the email module with a new action :

Code: Select all
[email_selected]
      label="Send email to selected"
      url="{$this->url('-action=email')}&--related=1"
      description= "Send email to selected persons."
      email_column="email"
      email_table="newsletters"
      category=selected_result_actions
      icon="{$dataface_url}/images/mail_icon.gif"
     permission=email


This do create a new action button with the chosen label, but this do send an email to the all list. Please let me know how to adapt the url to make it possible.

I also need this button to appear in the related record action list.
Any idea on how to do ?


Great thanks for help.

Zabelle

A first solution to this question ...

PostPosted: Wed Sep 16, 2009 2:55 am
by zabelle_motte
Finally, I found a solution to this problem that works locally on my specific datas. I have to present a solution rapidly so that is the solution I implement for the moment. I hope to have time to think about a more robust solution.

Some contextual informations are necessary to understand :
- the informations about persons are stored in a table named "personnes";
- the persons have to register to formations and informations about formations are stored in the "sessions" table and the join between the two is a relation called "inscrits" where the person identifier is "id_personne".

My aim is to present the "sessions" table with relation "inscrits" and possibility to check some participants and send them an email.

Here is my solution :
In the actions.ini of the "sessions" table, I added the following code :
Code: Select all
[email_selected]
    label="Mail manuel"
    url="javascript:emailSelected('relatedList')"
    description= "Envoyer un message personnalise aux personnes selectionnees."
    category=selected_related_result_actions
    icon="{$dataface_url}/images/mail_icon.gif"
    permission=email

That will create the button and call a special javascript function with the right form name.

Here is my "fiddle" script that was added using the <a> procedure to add a custom javascript </a> :

Code: Select all
function emailSelected(tableid){
   var ids = getSelectedIds(tableid);
   if ( ids.length == 0 )
           {
           alert("Please first check boxes beside the records you wish to copy, and then press 'Copy'.");
                  return;
           }
       selected_ids_url="";
       selected_ids=ids.join(",");
       selected_ids+=",";
       while (selected_ids.indexOf("personne_id")!= -1)
       {
       ind_ps=selected_ids.indexOf("personne_id");
       ind_or=selected_ids.indexOf(",");
       sub=selected_ids.substring(ind_ps+11,ind_or);
       alert(sub);
       selected_ids_url=selected_ids_url+ sub +" OR ";
       selected_ids=selected_ids.replace("personne_id","");
       selected_ids=selected_ids.replace(",","");
       }
       ind_lo=selected_ids_url.lastIndexOf(" OR ");
       selected_ids_urlf=selected_ids_url.substring(0,ind_lo);
       alert(selected_ids_urlf);
       new_url="index.php?-action=email&-table=personnes&id"+selected_ids_urlf;
       window.location.replace(new_url);
                                 }

Each entry of the table "ids" looks like "session_id=3&personne_id=91" and the script makes creates the right url to send an email to right persons : "index.php?action=email&-table=personnes&id =91 OR =101".

I am sure it is possible to make it better, and do not hesitate to make suggestions about it. It would be interresting for me to better understand how the email module works.

Zabelle

PostPosted: Thu Sep 17, 2009 9:27 am
by shannah
Looks like a good solution. Currently, as you already know, the email action doesn't operate on related lists, only primary lists. In practice, I usually create a view for my email table. Then I can do a search for whatever I want. This method could be adapted quite easily to simulate related lists by creating a view that contains the foreign key to join with your primary record. Then create a custom action that links to the list of the view filtered on the foreign key.

But your solution looks like it will work fine (as long as you're only sending to a few addresses at a time. the url would get pretty long when you get over, say, a couple hundred records).

-Steve

Thanks for suggestion ...

PostPosted: Fri Sep 18, 2009 12:07 am
by zabelle_motte
Hello Steve,
and thanks for your suggestion.

I understand what you mean but I not yet see how to implement it in my application. How to present the information of a many-to-many relationship in one sigle view ?

If you have time, I would appreciate you to post an example where you use this. I will also sleep on that suggestion and that will help.

Zabelle

PostPosted: Fri Sep 18, 2009 9:33 am
by shannah
You can simulate a many-to-many relationship in a view by creating a view with all possible combinations.

e.g. If you have a Many to Many relationship between books and authors your relationship from the books table might be something like:

Code: Select all
[authors]
__sql__ = "select * from authors a inner join book_authors ab on a.author_id=ab.author_id where ab.book_id='$book_id'"


And your relationship from the authors table would be something like:
Code: Select all
[books]
__sql__ = "select * from books b inner join book_authors ab on b.book_id=ab.book_id where ab.author_id='$author_id'"


Now if our goal was to be able to send email to all authors of a particular book (i.e. send to the authors relationship), we could create a view:
Code: Select all
create view book_authors_maillist as
select * from authors a inner join book_authors ab on a.author_id=ab.author_id


This view can now be used in xataface like a regular table (if you add a fields.ini for it and mark the primary key columns - http://xataface.com/wiki/Key). If you wanted to find all authors for a certain book you would just do:
index.php?-action=list&-table=book_authors_maillist&book_id=10

So you could easily create an action that would like to the mail action on the book_authors_maillist table with the parameters you wanted.

e.g.

Code: Select all
[related_authors_mail]
    category=related_list_actions
    url="{$site_href}?-action=email&-table=book_authors_maillist&book_id={$record->val('book_id')}"
    icon="{$dataface_url}/images/mail_icon.gif"
    url_condition="$record"
    condition="$query['-table']=='books' and $query['-relationship'] == 'authors'"
    permission="email"



This action would send mail to only the authors related to the current books. It would be made available in the icons in the upper right on the related list view of only the authors of a book.

OK, I see ...

PostPosted: Thu Sep 24, 2009 5:48 am
by zabelle_motte
Thanks a lot for your example that makes your suggestion clear.

I will try to implement that when I will have time.

Much thanks and keep up the good work with Xataface ...

Zabelle