You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
3.6 KiB
103 lines
3.6 KiB
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
var TemplateFactory_1 = require("../template/TemplateFactory");
|
|
var ChatView = /** @class */ (function () {
|
|
// private userBoxes: any[] = [];
|
|
function ChatView(model, element) {
|
|
this._model = model;
|
|
this._element = element;
|
|
}
|
|
Object.defineProperty(ChatView.prototype, "model", {
|
|
/**
|
|
* Getter model
|
|
* @return {Model}
|
|
*/
|
|
get: function () {
|
|
return this._model;
|
|
},
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
Object.defineProperty(ChatView.prototype, "element", {
|
|
/**
|
|
* Getter element
|
|
* @return {any}
|
|
*/
|
|
get: function () {
|
|
return this._element;
|
|
},
|
|
enumerable: true,
|
|
configurable: true
|
|
});
|
|
// /**
|
|
// * Setter model
|
|
// * @param {Model} value
|
|
// */
|
|
// public set model(value: Model) {
|
|
// this._model = value;
|
|
// }
|
|
// /**
|
|
// * Setter element
|
|
// * @param {any} value
|
|
// */
|
|
// public set element(value: any) {
|
|
// this._element = value;
|
|
// }
|
|
ChatView.prototype.update = function (data) {
|
|
var template = TemplateFactory_1.TemplateFactory.getTemplate();
|
|
var html = "";
|
|
data.forEach(function (element) {
|
|
html += template(element);
|
|
});
|
|
this.element.innerHTML = html;
|
|
this.addUserCallBacks();
|
|
console.log(this.element.innerHTML);
|
|
};
|
|
ChatView.prototype.helper = function () {
|
|
};
|
|
ChatView.prototype.addUserCallBacks = function () {
|
|
var userBoxes = document.getElementsByClassName('user-box');
|
|
for (var i = 0; i < userBoxes.length; i++) {
|
|
var userBox = userBoxes[i];
|
|
userBoxes[i].addEventListener('click', this.userCallBack.bind(this, userBox));
|
|
}
|
|
};
|
|
ChatView.prototype.userCallBack = function (el) {
|
|
var current = document.getElementsByClassName('user-box active');
|
|
var passphrase = "";
|
|
if (current.length > 0) {
|
|
if (passphrase == '') {
|
|
// alert('Please input passphrase')
|
|
// alertify.error('Please enter a passphrase');
|
|
// return;
|
|
}
|
|
current[0].className = current[0].className.replace(" active", "");
|
|
}
|
|
// Add the active class to the current/clicked button
|
|
else if (current.length == 0) {
|
|
var elem_1 = document.getElementById('passphrase-initial');
|
|
passphrase = "";
|
|
if (passphrase == '') {
|
|
// // alert('Please input passphrase')
|
|
// // alertify.error('Please enter a passphrase');
|
|
// return;
|
|
}
|
|
// @ts-ignore: Object is possibly 'null'.
|
|
document.getElementById('no-user-selected').hidden = true;
|
|
// @ts-ignore: Object is possibly 'null'.
|
|
document.getElementById('chat-card').hidden = false;
|
|
// @ts-ignore: Object is possibly 'null'.
|
|
elem_1.hidden = true;
|
|
}
|
|
// console.log(this.getElementsByClassName('to-user-span'));
|
|
var elem = el.getElementsByClassName('to-user-span')[0];
|
|
var userName = elem.innerText;
|
|
// @ts-ignore: Object is possibly 'null'.
|
|
document.getElementById('user-name-span').innerText = userName;
|
|
// populateMessages(userName, passphrase);
|
|
sessionStorage.setItem('selectedUser', userName);
|
|
el.className += " active";
|
|
};
|
|
return ChatView;
|
|
}());
|
|
exports.ChatView = ChatView;
|