| 
						
						
							
								
							
						
						
					 | 
					@ -3,6 +3,7 @@ odoo.define('whatsapp_mail_messaging.whatsapp_modal.js', function (require) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    var publicWidget = require('web.public.widget'); | 
					 | 
					 | 
					    var publicWidget = require('web.public.widget'); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    var ajax = require('web.ajax'); | 
					 | 
					 | 
					    var ajax = require('web.ajax'); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					    var rpc = require('web.rpc'); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    publicWidget.registry.deliveryDateToggl = publicWidget.Widget.extend({ | 
					 | 
					 | 
					    publicWidget.registry.deliveryDateToggl = publicWidget.Widget.extend({ | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        selector: '#ModalWhatsapp', | 
					 | 
					 | 
					        selector: '#ModalWhatsapp', | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -21,36 +22,29 @@ odoo.define('whatsapp_mail_messaging.whatsapp_modal.js', function (require) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        }, | 
					 | 
					 | 
					        }, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        onclickDefaultRadio: function () { | 
					 | 
					 | 
					        onclickDefaultRadio: function () { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            document.getElementById("myFormControl").style.display = "block"; | 
					 | 
					 | 
					            document.getElementById("myFormControl").style.display = "block"; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					        var self = this; | 
					 | 
					 | 
					            let data = ajax.jsonRpc('/whatsapp_message', {data:'data'}) | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					            this._rpc({ | 
					 | 
					 | 
					            this.updateUI(data); | 
				
			
			
				
				
			
		
	
		
		
			
				
					 | 
					 | 
					                model: 'selection.messages',  // Your Odoo model
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                method: 'search_read',  // Use search_read to retrieve data
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                fields: ['name', 'message'],  // Specify the fields you want to retrieve
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            }).then(function (data) { | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                // Process the data received from the server
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                self.updateUI(data); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            }); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					        }, | 
					 | 
					 | 
					        }, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        updateUI: function (data) { | 
					 | 
					 | 
					        updateUI: function (data) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            // Clear existing options
 | 
					 | 
					 | 
					            // Clear existing options
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            var selectElement = document.getElementById("myFormControl"); | 
					 | 
					 | 
					            var selectElement = document.getElementById("myFormControl"); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            selectElement.innerHTML = ''; | 
					 | 
					 | 
					            selectElement.innerHTML = ''; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            // Add default option
 | 
					 | 
					 | 
					            // Add default option
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            var defaultOption = document.createElement('option'); | 
					 | 
					 | 
					            var defaultOption = document.createElement('option'); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            defaultOption.textContent = 'Select the Template'; | 
					 | 
					 | 
					            defaultOption.textContent = 'Select the Template'; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            selectElement.appendChild(defaultOption); | 
					 | 
					 | 
					            selectElement.appendChild(defaultOption); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            // Add options from the data
 | 
					 | 
					 | 
					            // Add options from the data
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					    data.forEach(function (record) { | 
					 | 
					 | 
					            data.then((result) => { | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                const messages = result.messages; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                messages.forEach((message) => { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    var option = document.createElement('option'); | 
					 | 
					 | 
					                    var option = document.createElement('option'); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					        option.value = record.id; | 
					 | 
					 | 
					                    option.value = message.id; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					        option.textContent = record.name; | 
					 | 
					 | 
					                    option.textContent = message.name; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					        option.setAttribute('data-message', record.message);  // Save the message as a data attribute
 | 
					 | 
					 | 
					                    option.setAttribute('data-message', message.message); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					                    selectElement.appendChild(option); | 
					 | 
					 | 
					                    selectElement.appendChild(option); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                }); | 
					 | 
					 | 
					                }); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            }) | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        }, | 
					 | 
					 | 
					        }, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        onSelectChange: function () { | 
					 | 
					 | 
					        onSelectChange: function () { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            var selectElement = document.getElementById("myFormControl"); | 
					 | 
					 | 
					            var selectElement = document.getElementById("myFormControl"); | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -64,30 +58,24 @@ odoo.define('whatsapp_mail_messaging.whatsapp_modal.js', function (require) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            //Closing the Modal
 | 
					 | 
					 | 
					            //Closing the Modal
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            document.getElementById("ModalWhatsapp").style.display = "none"; | 
					 | 
					 | 
					            document.getElementById("ModalWhatsapp").style.display = "none"; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        }, | 
					 | 
					 | 
					        }, | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					onSendMessageClick: function () { | 
					 | 
					 | 
					        onSendMessageClick: function () { | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					            // Send Message to Whatsapp
 | 
					 | 
					 | 
					            // Send Message to Whatsapp
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            var textareaElement = document.getElementById("exampleFormControlTextarea1"); | 
					 | 
					 | 
					            var textareaElement = document.getElementById("exampleFormControlTextarea1"); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            var messageString = textareaElement.value; | 
					 | 
					 | 
					            var messageString = textareaElement.value; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					    this._rpc({ | 
					 | 
					 | 
					            let data = ajax.jsonRpc('/mobile_number', {data:'data'}) | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					        model: 'website', | 
					 | 
					 | 
					            data.then((result) => { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					        method: 'search_read', | 
					 | 
					 | 
					                const mobile_num = result.mobile; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					        fields: ['mobile_number'], | 
					 | 
					 | 
					                mobile_num.forEach((mobile) => { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					    }).then(function (data) { | 
					 | 
					 | 
					                    if (mobile_num && mobile_num.length > 0 && 'mobile_number' in mobile_num[0] && mobile_num[0].mobile_number) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					        // Process the data received from the server
 | 
					 | 
					 | 
					                        var mobileNumber = mobile_num[0].mobile_number; | 
				
			
			
				
				
			
		
	
		
		
			
				
					 | 
					 | 
					if (data && data.length > 0 && 'mobile_number' in data[0] && data[0].mobile_number) { | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    // Check if 'mobile_number' is present in the first item of the 'data' array and is not falsy
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    var mobileNumber = data[0].mobile_number; | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					                        // Construct the WhatsApp URL using the mobile number and messageString
 | 
					 | 
					 | 
					                        // Construct the WhatsApp URL using the mobile number and messageString
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                        var whatsappUrl = 'https://api.whatsapp.com/send?phone=' + mobileNumber + '&text=' + encodeURIComponent(messageString); | 
					 | 
					 | 
					                        var whatsappUrl = 'https://api.whatsapp.com/send?phone=' + mobileNumber + '&text=' + encodeURIComponent(messageString); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    // Open the WhatsApp URL in a new tab or window
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                        window.open(whatsappUrl, '_blank'); | 
					 | 
					 | 
					                        window.open(whatsappUrl, '_blank'); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					} else { | 
					 | 
					 | 
					                    } else { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					    // If mobile number is not available or falsy, hide the element with id "phoneMessage"
 | 
					 | 
					 | 
					                        document.querySelector("#phoneMessage").style.display = "block"; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					    document.getElementById("phoneMessage").style.display = "block"; | 
					 | 
					 | 
					                    } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					    // You might want to display a user-friendly error message on the UI
 | 
					 | 
					 | 
					                }); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					} | 
					 | 
					 | 
					            }) | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					}) | 
					 | 
					 | 
					        }, | 
				
			
			
				
				
			
		
	
		
		
			
				
					 | 
					 | 
					}, | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					    }); | 
					 | 
					 | 
					    }); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					}); | 
					 | 
					 | 
					}); |