17 changed files with 281 additions and 14 deletions
@ -0,0 +1,9 @@ |
|||
from odoo import fields, models |
|||
|
|||
|
|||
class SelectionMessages(models.Model): |
|||
_name = 'selection.messages' |
|||
|
|||
name = fields.Char(string='Name of the Message Template') |
|||
message = fields.Text(string="Message", required=True) |
|||
|
|
@ -0,0 +1,20 @@ |
|||
odoo.define('whatsapp_mail_messaging.whatsapp_icon_website.js', function (require) { |
|||
"use strict"; |
|||
|
|||
var publicWidget = require('web.public.widget'); |
|||
var ajax = require('web.ajax'); |
|||
|
|||
|
|||
publicWidget.registry.WhatsappIcon = publicWidget.Widget.extend({ |
|||
selector: '.cy_whatsapp_web', |
|||
events: { |
|||
'click': '_onClickWhatsappIcon', |
|||
}, |
|||
start: function() { |
|||
this._super.apply(this, arguments); |
|||
}, |
|||
_onClickWhatsappIcon: function (ev) { |
|||
$('#ModalWhatsapp').css('display', 'block'); |
|||
}, |
|||
}); |
|||
}); |
@ -0,0 +1,93 @@ |
|||
odoo.define('whatsapp_mail_messaging.whatsapp_modal.js', function (require) { |
|||
"use strict"; |
|||
|
|||
var publicWidget = require('web.public.widget'); |
|||
var ajax = require('web.ajax'); |
|||
|
|||
publicWidget.registry.deliveryDateToggl = publicWidget.Widget.extend({ |
|||
selector: '#ModalWhatsapp', |
|||
events: { |
|||
'change .custom-default': 'onclickCustomRadio', |
|||
'change .default-default': 'onclickDefaultRadio', |
|||
'change #myFormControl': 'onSelectChange', |
|||
'click .btn-danger': 'onCloseButtonClick', |
|||
'click .btn-success': 'onSendMessageClick', |
|||
}, |
|||
start: function() { |
|||
this._super.apply(this, arguments); |
|||
}, |
|||
onclickCustomRadio: function () { |
|||
document.getElementById("myFormControl").style.display = "none"; |
|||
}, |
|||
onclickDefaultRadio: function () { |
|||
document.getElementById("myFormControl").style.display = "block"; |
|||
var self = this; |
|||
this._rpc({ |
|||
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) { |
|||
|
|||
// Clear existing options
|
|||
var selectElement = document.getElementById("myFormControl"); |
|||
selectElement.innerHTML = ''; |
|||
|
|||
// Add default option
|
|||
var defaultOption = document.createElement('option'); |
|||
defaultOption.textContent = 'Select the Template'; |
|||
selectElement.appendChild(defaultOption); |
|||
|
|||
// Add options from the data
|
|||
data.forEach(function (record) { |
|||
var option = document.createElement('option'); |
|||
option.value = record.id; |
|||
option.textContent = record.name; |
|||
option.setAttribute('data-message', record.message); // Save the message as a data attribute
|
|||
selectElement.appendChild(option); |
|||
}); |
|||
}, |
|||
onSelectChange: function () { |
|||
var selectElement = document.getElementById("myFormControl"); |
|||
var textareaElement = document.getElementById("exampleFormControlTextarea1"); |
|||
var selectedOption = selectElement.options[selectElement.selectedIndex]; |
|||
var selectedMessage = selectedOption.getAttribute('data-message'); |
|||
// Update the textarea with the message from the selected option
|
|||
textareaElement.value = selectedMessage; |
|||
}, |
|||
onCloseButtonClick: function () { |
|||
//Closing the Modal
|
|||
document.getElementById("ModalWhatsapp").style.display = "none"; |
|||
}, |
|||
onSendMessageClick: function () { |
|||
// Send Message to Whatsapp
|
|||
var textareaElement = document.getElementById("exampleFormControlTextarea1"); |
|||
var messageString = textareaElement.value; |
|||
this._rpc({ |
|||
model: 'website', |
|||
method: 'search_read', |
|||
fields: ['mobile_number'], |
|||
}).then(function (data) { |
|||
// Process the data received from the server
|
|||
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
|
|||
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'); |
|||
} else { |
|||
// If mobile number is not available or falsy, hide the element with id "phoneMessage"
|
|||
document.getElementById("phoneMessage").style.display = "block"; |
|||
// You might want to display a user-friendly error message on the UI
|
|||
} |
|||
}) |
|||
}, |
|||
|
|||
}); |
|||
}); |
@ -1,10 +1,78 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<odoo> |
|||
<template id="ChatToCompany" name="Chat With Company" inherit_id="website.footer_custom"> |
|||
<template id="ChatToCompany" name="Chat With Company" |
|||
inherit_id="website.footer_custom"> |
|||
<xpath expr="//div[hasclass('s_social_media')]" position="inside"> |
|||
<a t-attf-href="https://api.whatsapp.com/send?phone=#{website.mobile_number}" class="cy_whatsapp_web" target="_blank"> |
|||
<div class="cy_whatsapp_web"> |
|||
<i class="fa fa-whatsapp cy-icon"/> |
|||
</a> |
|||
</div> |
|||
<!-- Modal --> |
|||
<div class="modal" id="ModalWhatsapp" tabindex="-1" role="dialog" |
|||
aria-labelledby="exampleModalLabel" style="display: none;" |
|||
aria-hidden="true"> |
|||
<div class="modal-dialog" role="document"> |
|||
<div class="modal-content"> |
|||
<div class="modal-header"> |
|||
<h5 class="modal-title text-black" |
|||
id="exampleModalLabel">Compose Whatsapp Message |
|||
</h5> |
|||
</div> |
|||
<div class="modal-body"> |
|||
<div class="form-check"> |
|||
<input class="form-check-input custom-default" |
|||
type="radio" |
|||
name="flexRadioDefault" |
|||
id="CustomSelect"/> |
|||
<label class="form-check-label text-black" |
|||
for="CustomSelect"> |
|||
Custom |
|||
</label> |
|||
</div> |
|||
<div class="form-check"> |
|||
<input class="form-check-input default-default" |
|||
type="radio" |
|||
name="flexRadioDefault" |
|||
id="DefaultSelect"/> |
|||
<label class="form-check-label text-black" |
|||
for="DefaultSelect"> |
|||
Default |
|||
</label> |
|||
</div> |
|||
<div> |
|||
<p id="phoneMessage" |
|||
style="color: red; display: none;">No |
|||
Mobile number available, Please add |
|||
Mobile |
|||
Number in Website Configuration... |
|||
</p> |
|||
</div> |
|||
<br/> |
|||
<select class="form-control" id="myFormControl" |
|||
style="display: none;"> |
|||
<option>Select an Option</option> |
|||
</select> |
|||
<br/> |
|||
<div class="form-group"> |
|||
<label for="exampleFormControlTextarea1" |
|||
style="color: black;">Message |
|||
</label> |
|||
<textarea class="form-control" |
|||
id="exampleFormControlTextarea1" |
|||
rows="3"></textarea> |
|||
</div> |
|||
</div> |
|||
<div class="modal-footer"> |
|||
<button type="button" class="btn btn-danger" |
|||
data-dismiss="modal">Close |
|||
</button> |
|||
<button type="button" |
|||
class="btn btn-success">Send Message |
|||
</button> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</xpath> |
|||
|
|||
</template> |
|||
</odoo> |
@ -0,0 +1,55 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<odoo> |
|||
<!--Selection messages Tree View --> |
|||
<record id="selection_messages_view_tree" model="ir.ui.view"> |
|||
<field name="name">selection.messages.view.tree</field> |
|||
<field name="model">selection.messages</field> |
|||
<field name="arch" type="xml"> |
|||
<tree> |
|||
<field name="name"/> |
|||
<field name="message"/> |
|||
</tree> |
|||
</field> |
|||
</record> |
|||
<!-- Selection messages Form View--> |
|||
<record id="selection_messages_view_form" model="ir.ui.view"> |
|||
<field name="name">selection.messages.view.form</field> |
|||
<field name="model">selection.messages</field> |
|||
<field name="arch" type="xml"> |
|||
<form> |
|||
<sheet> |
|||
<group> |
|||
<group> |
|||
<field name="name"/> |
|||
</group> |
|||
</group> |
|||
<notebook> |
|||
<page string="Message"> |
|||
<group> |
|||
<field colspan="2" name="message" widget="text_emojis" |
|||
nolabel="1" |
|||
placeholder="Write Message here...." |
|||
/> |
|||
</group> |
|||
</page> |
|||
</notebook> |
|||
</sheet> |
|||
</form> |
|||
</field> |
|||
</record> |
|||
<!--Selection messages Action --> |
|||
<record id="selection_messages_action" model="ir.actions.act_window"> |
|||
<field name="name">Selection Messages</field> |
|||
<field name="res_model">selection.messages</field> |
|||
<field name="type">ir.actions.act_window</field> |
|||
<field name="view_mode">tree,form</field> |
|||
<field name="view_id" ref="selection_messages_view_tree"/> |
|||
</record> |
|||
|
|||
<menuitem name="Whatsapp Messages" |
|||
id="menu_website_selection_messages" |
|||
action="selection_messages_action" |
|||
parent="website.menu_website_global_configuration" |
|||
sequence="50" |
|||
/> |
|||
</odoo> |
Loading…
Reference in new issue