import { JetView } from “webix-jet”
export default class rt extends JetView {
config() {
//all data widgets
webix.proxy.socket = {
$proxy:true,
load:function(view) {
this.socket = new WebSocket(“ws:”+this.source);
this.socket.onerror = (error) => {
console.log(“WebSocket Error”, error);
};
this.socket.onmessage = (e) => {
var update = webix.DataDriver.json.toObject(e.data);
if(update.key != this.key) return;
if(update.clientId == this.clientId){
if(update.operation == "insert")
view.data.changeId(update.id, update.data.id);
}
else{
webix.dp(view).ignore(() => {
if (update.operation == "delete")
view.remove(update.data.id);
else if (update.operation == "insert")
view.add(update.data);
else if (update.operation == "update"){
view.updateItem(update.data.id, update.data);
}
});
}
};
view.attachEvent("onDestruct", () => {
this.socket.close();
});
},
save:function(view, update) {
update.clientId = this.clientId;
update.key = this.key;
this.socket.send(webix.stringify(update));
}
};
//define a common proxy for loading and saving with unique clientId and key
var data_proxy = webix.proxy("socket", "//localhost:1234", {
key:"data", clientId:webix.uid()
});
//Comments widget
webix.proxy.comments = {
init:function(){
webix.extend(this, webix.proxy.socket);
},
load:function(view){
webix.proxy.socket.load.call(this, view.queryView("list"));
}
};
const grid = {
view:"datatable", id:"grid",
columns:[
{ id:"title", editor:"text", header:"Film title", width:200},
{ id:"year", editor:"text", header:"Released" , width:100},
{ header:"", template:"{common.trashIcon()}", width:50}
],
select:"row", editable:true, editaction:"dblclick",
data:[
{title:'Title_1', year:"Year_1", data:"ok"},
{title:'Title_2', year:"Year_2", data:"ok"},
{title:'Title_3', year:"Year_3", data:"ok"},
],
url:data_proxy,
save:data_proxy
}
var imagePath = “https://docs.webix.com/samples/30_comments/common/imgs/”;
const user = {
view:“comments”,
id:“comments”,
width: 450,
currentUser:4,
data: [
{id: 1,user_id:1, text:‘hello’, date:new Date()}
],
users: [
{ id:1, value:“Corvo Attano”, image: imagePath + “corvo.jpg”, status:“none” },
{ id:2, value:“Daisy Fitzroy”, image: imagePath + “daisy.jpg”, status:“busy” },
{ id:3, value:“Glenn Crake”, image: imagePath + “glenn.jpg”, status:“busy” },
{ id:4, value:“Me”, image: imagePath + “tomek.jpg”, status:“active” },
{ id:5, value:“Leia Organa”, image: imagePath + “leia.jpg”, status:“away” }
]
}
return {rows:[
grid,user
]}
}
urlChange() {
}
init() {
// $$(“data”).data.attachEvent(“onStoreUpdated”, (id, update, operation) => {
// socket.send(webix.stringify(update));
// });
}
}