Jump to content
Sign in to follow this  
Graham Quince

Parents view of Teacher email addresses

Recommended Posts

Here's something you might like to experiment with...

This code below searches for the children of a logged-in parent, displays them, lists their classes and then displays the teachers of those classes with a link to their email address:

<style>
    .childlist {
        border: 1px solid #CCCCCC;
        border-radius: 10px;
        padding: 10px;
        font-size: 14pt;
        line-height: 14pt;
        width: 40%;  
        float: left;
        margin: 10px;
    }
    .childlist a {
        color: #FF0000;
        font-weight: bold;
    }
</style>

<div class="emailList"></div>

<script>
var emailList = this.element.find('.emailList');


    
var getGroupsforChild = function(child) {
    
    Frog.Model.api('groups.getFor', {
        identity: child.uuid,
        group_type: "Class"
    }).done(function(groupResponse) {       
        var groupString="";              
        $.each(groupResponse.data, function(index1,group) {
                var classid = child.user_uuid+index1
                    /* Now run the function to list all the members of the group */
                    getTeachersforGroup(group,classid);
                    groupString+='<li class="Class'+classid+'">'+group.name+'</li>'
        });
        emailList.append(
            '<div class="childlist">'+
            '<h3>'+child.displayname+"'s classes:</h3>"+
            '<ul>'+groupString+'</ul>'+
            '</div>'
        );
    });

};
    
    
var getTeachersforGroup = function(group,classid) {
    
    Frog.Model.api('groups.getMembers', {
        uuid: group.uuid
    }).done(function(membersResponse) {
        var members = membersResponse.data,
            TeacherString=" - ";
        //console.log(groups);                
        $.each(members, function(index2,member) {
                /* This IF statement looks for Staff profiles */
                if (member.profile.name==="Staff" || member.profile.name==="Admin") {
                    TeacherString+='<a href="mailto:'+member.email+'">'+member.displayname+'</a>&nbsp;&nbsp;'
                }
                
        });
        if (TeacherString!==" - ") {
            emailList.find(".Class"+classid).append(TeacherString);
        }
    });
    
};    

/* First, get each child of the parent */
Frog.Model.api('users.getChildren').done(function(listResponse) {
        var children = listResponse.data;
        $.each(children, function(index,child) {
            /* now run the function to list all the groups */
            getGroupsforChild(child);
       });
});
</script>

@adamw helped me refine this script and showed me some more APIs I wasn't aware of.   

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...