Make Email module active for related and/or selected records

A place for users and developers of the Xataface to discuss and receive support.

Make Email module active for related and/or selected records

Postby zabelle_motte » Tue Sep 15, 2009 1:07 am

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
zabelle_motte
 
Posts: 19
Joined: Tue Sep 01, 2009 6:18 am

I make a try ...

Postby zabelle_motte » Tue Sep 15, 2009 3:21 am

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
zabelle_motte
 
Posts: 19
Joined: Tue Sep 01, 2009 6:18 am

A first solution to this question ...

Postby zabelle_motte » Wed Sep 16, 2009 2:55 am

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
zabelle_motte
 
Posts: 19
Joined: Tue Sep 01, 2009 6:18 am

Postby shannah » Thu Sep 17, 2009 9:27 am

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
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Thanks for suggestion ...

Postby zabelle_motte » Fri Sep 18, 2009 12:07 am

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
zabelle_motte
 
Posts: 19
Joined: Tue Sep 01, 2009 6:18 am

Postby shannah » Fri Sep 18, 2009 9:33 am

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.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

OK, I see ...

Postby zabelle_motte » Thu Sep 24, 2009 5:48 am

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
zabelle_motte
 
Posts: 19
Joined: Tue Sep 01, 2009 6:18 am


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 21 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved