Changeset View
Changeset View
Standalone View
Standalone View
assets/js/widgets/chatdetails.js
- This file was added.
class ChatDetailsWidget | |||||
{ | |||||
/** | |||||
* Configuration: | |||||
* - submit: Callback for chat details update (only name for now) | |||||
*/ | |||||
constructor(id, config) | |||||
{ | |||||
this.config = config || {} | |||||
this.id = id | |||||
this.render() | |||||
} | |||||
/** | |||||
* Set chat room details and re-render the widget | |||||
*/ | |||||
setRoom(room) | |||||
{ | |||||
this.render(room) | |||||
} | |||||
/** | |||||
* Renders text chat input widget | |||||
*/ | |||||
render(room) | |||||
{ | |||||
if (!room || !room.id) { | |||||
return $('#' + this.id).html('') | |||||
} | |||||
// TODO: Localization | |||||
let room_name = room.name || ''; | |||||
let html = ` | |||||
<div>Room id: ${room.id}</div> | |||||
<div>Room name: <input name="chat_name" value="${room_name}" class="form-control" /></div> | |||||
` | |||||
$('#' + this.id) | |||||
.html(html) | |||||
.on('keypress', 'input', e => { | |||||
let txt | |||||
if (e.keyCode == 13 && this.config.submit && (txt = $(e.target).val())) { | |||||
this.config.submit(e, txt) | |||||
} | |||||
}) | |||||
} | |||||
} | |||||
export default ChatDetailsWidget |