implementing crm with laravel mailbox module

Implementing CRM System With Laravel Part 11: Mailbox Complete

We will complete the mailbox module in this part and we will finish the remaining actions that we need for the mailbox like, forwarding, replying and trashing emails.

 

 

Series Topics:

 

 

Email Toggle Important

Let’s update method toggleImportant() like this:

This method accepts an array of mailbox_flag_ids then we use a simple for each loop to update each id.

Now we will update functions.js file so open public/theme/views/mailbox/functions.js inside toggleImportant() function add this code:

Also update public/theme/views/mailbox/index.js add this code inside $(function() {  }).

Add this function at the end of public/theme/views/mailbox/index.js

This above javascript code manipulates when the user click the star button whether it’s one row or when checked mulitple rows. I have created another function “handleImportant()” which receives a response of updated ids and using the map() javascript function i iterated over them to toggle each star.

 

Email Trash

Update the trash() method in the Mailbox controller as follows:

This method also accepts an array of folder ids. Trashing a message is a matter of adding it to the Trash folder, and this is the above code do, I loop over the array of ids then i update each folder to the Trash folder id.

 

update functions.js file, inside trash() function add this code:

In the same way update public/theme/views/mailbox/index.js add this code inside $(function() {  }).

Add this function at the end of public/theme/views/mailbox/index.js

Now the code for trashing and set important is complete. Let’s continue the mailbox actions and add the reply, forward and send draft.

 

Email Reply

To reply to an email the process is identical to sending the email except that the receiver in this case is the sender of the parent message.

Update those two methods in the Mailbox controller as follows:

Here the process is quite similar to the store() method that we discussed in the previous part. But in the reply the subject is added automatically from parent message and appended with “RE”. Also is save the parent id which is the id of the message to reply to.

resources/views/pages/mailbox/reply.blade.php

Email Forward

Forwarding the message is the same as sending the message so update those two methods in the Mailbox controller.

resources/views/pages/mailbox/forward.blade.php

 

Sending the draft  Emails

You remember the compose form it has two buttons, the first which sends the message immediately and the other which save the message as a Draft which means that the message is saved but not sent to the recipients.

update the send() method in Mailbox controller

As you can see above i am doing the same steps as we have done in the store() methods. First we fetched the tmp receivers. Then for the sender we update the folder to be “Sent”, for the receivers i have looped over them inserting records in the receiver table, and receiver folders and receiver flags tables. Note that this method called for draft emails only.

Displaying single Email

Let’s update the show() method as shown:

I make a check for the “is_unread” property and if it’s equal to “1” i update it to be “0” and save.

 

resources/views/pages/mailbox/show.blade.php

resources/views/pages/mailbox/includes/attachments.blade.php

 

Adjusting Permissions

Now after we finished the core functions of the mailbox let’s update the permissions so that authorized users only can access the mailbox so update the below files.

Update the Mailbox controller constructor to be like this:

Open resources/views/pages/mailbox/index.blade.php replace this line

with this line

update resources/views/pages/includes/mailbox_controls.blade.php

Sidebar

Update resources/views/layout/sidebar.blade.php

 

Email Header Notifications

To finish up this part we will show the email header notifications which display in the top icon located in the header. This icon shows a count for the unread messages according to the current logged in user and if you click on it it will show these messages.

Update resources/views/layout/header.blade.php

 

Continue to Part 12: Calendar Module

 

Share this: