Skip to content
Permalink
Browse files

Finaly main logic works, but need to modify module

  • Loading branch information...
Enigma228322 committed Aug 7, 2019
1 parent 3ed8a4b commit dec42bb5f58fa6c3ca2abc9286f81ca1c52c71d1
@@ -0,0 +1,11 @@
from lxml import etree
import logging

from odoo import http
from odoo.http import request

class MyController(odoo.http.Controller):

@http.route('/', auth='public')
def handler(self):
return "Hello"
@@ -1,8 +1,20 @@
from odoo import models, fields, api, _
import wdb

class Chat(models.Model):
_name = 'pos.chat'

name = fields.Char(string='Name')
maxUsers = fields.Integer()
current_user = fields.Many2one('res.users', 'Current User', default=lambda self: self.env.user)
messages = []

@api.model
def get_user_name(self):
return self.current_user

@api.model
def send_field_updates(self, message, date):
channel_name = "pos_chat_228"
data = {'message': message, 'date': date}
self.env['pos.config'].send_to_all_poses(channel_name, data)
@@ -46,20 +46,45 @@
font-family: Lato;
}

.pos .modal-dialog .message-field{
height:
}

.pos .modal-dialog .popup .Label{
margin-top: 10px;
}

.pos .modal-dialog .popup .text-input-place{
margin-top: 60%;
margin-top: 350px;
height: 22px;
border-bottom: 2px solid green;
}

.pos .modal-dialog .button.next{
margin-top: 60%;
margin-top: 350px;
}

.pos .modal-dialog .button.back{
margin-top: 60%;
margin-top: 350px;
}

.pos .modal-dialog .messages{
overflow: scroll;
position: absolute;
top: 20px;
bottom: 60px;
left: 20px;
right: 20px;
margin: 0;
padding: 0;
border: 2px solid #ccc;
font-size: 16px;
font-family: Arial, sans-serif;
-webkit-overflow-scrolling: touch;
}

.pos .modal-dialog .text-right.small{
text-align: left;
margin-left: 10px;
}

@@ -4,6 +4,9 @@ odoo.define('pos_chat_button', function (require){
var gui = require('point_of_sale.gui');
var PopupWidget = require('point_of_sale.popups');
var screens = require('point_of_sale.screens');
var rpc = require('web.rpc');

var models = require('point_of_sale.models');
//declare a new variable and inherit ActionButtonWidget

var ChatButton = screens.ActionButtonWidget.extend({
@@ -13,11 +16,34 @@ odoo.define('pos_chat_button', function (require){
'title': 'Chat',
'value': false,
});
var messageList = document.getElementById('message-list');
messageList.innerHTML = '<li class="text-right small"><em>Welcome to chat!</em></li>';
loadComments();
}
});

// Massages are stored here
var massages = [];

// Messages are stored here
var messages = [];
var user = models.PosModel;

var PosModelSuper = models.PosModel;
models.PosModel = models.PosModel.extend({
initialize: function () {
PosModelSuper.prototype.initialize.apply(this, arguments);
var self = this;
self.bus.add_channel_callback("pos_chat_228", self.on_barcode_updates, self);
},
on_barcode_updates: function(data){
var self = this;
console.log("Hello!!!");
var tempMessage = {
text : data.message,
time : data.date
}
AddNewMessage(tempMessage);
},
})

var ChatPopupWidget = PopupWidget.extend({
template: 'ChatPopupWidget',
@@ -30,43 +56,56 @@ odoo.define('pos_chat_button', function (require){
});

this.$('.next').click(function () {
var newMassage = document.getElementById('text-line');
var tempMassage = {
name : newMassage.value,
var newMessage = document.getElementById('text-line');
var tempMessage = {
text : newMessage.value,
time : Math.floor(Date.now()/1000)
}

newMassage.value = '';
massages.push(newMassage);
saveMassages();
showMassages();
console.log(timeConverter(tempMassage.time));
AddNewMessage(tempMessage);
newMessage.value = '';
self._rpc({
model: "pos.chat",
method: "send_field_updates",
args: [tempMessage.text, tempMessage.time]
})
});
},
});

function AddNewMessage(message)
{
messages.push(message);
saveMessages();
showMessages();
}

gui.define_popup({name:'chat', widget: ChatPopupWidget});

screens.define_action_button({
'name': 'chat_button',
'widget': ChatButton,
});

function saveMassages()
function saveMessages()
{
localStorage.setItem('massages', JSON.stringify(massages));
localStorage.setItem('messages', JSON.stringify(messages));
}

function showMassages()
function showMessages()
{
var massageField = document.getElementById('massage-field');
var messageList = document.getElementById('message-list');
var out = '';
massages.forEach(function (item)
messages.forEach(function (item)
{
out += '<p class="text-right small"><em>' + timeConverter(item.time) + '</em></p>';
out += '<p class="text-right small"><em>' + item.name + '</em></p>';
out += '<li class="text-right small"><em>' + timeConverter(item.time) + ' (' + user.id888 +'):</em></li>';
out += '<li class="text-right small"><em>' + item.text + '</em></li>';
});
massageField.innerHTML = out;
messageList.innerHTML = out;
}

function loadComments()
{
localStorage.setItem('messages', JSON.stringify(messages));
}

// Time converter function
@@ -12,8 +12,10 @@
<div class="modal-dialog">
<div class="popup popup-chat">

<Label>Chat</Label>
<div id="message-field"></div>
<div id="message-field">
<ul class="messages" id="message-list">
</ul>
</div>
<div class="chat-popup" id="myForm">
<form class="form-container">

0 comments on commit dec42bb

Please sign in to comment.
You can’t perform that action at this time.