openwebrx-clone/htdocs/lib/MetaPanel.js

205 lines
5.6 KiB
JavaScript
Raw Normal View History

function MetaPanel(el) {
this.el = el;
this.modes = [];
}
MetaPanel.prototype.update = function(data) {
};
MetaPanel.prototype.isSupported = function(data) {
return this.modes.includes(data.protocol);
};
MetaPanel.prototype.clear = function() {
this.el.find(".openwebrx-meta-slot").removeClass("active").removeClass("sync");
};
function DmrMetaSlot(el) {
this.el = $(el);
2021-01-16 21:07:55 +00:00
this.clear();
}
DmrMetaSlot.prototype.update = function(data) {
this.el[data['sync'] ? "addClass" : "removeClass"]("sync");
if (data['sync'] && data['sync'] === "voice") {
2021-01-16 21:07:55 +00:00
this.setId(data['additional'] && data['additional']['callsign'] || data['source']);
this.setName(data['additional'] && data['additional']['fname']);
if (data['type'] === "group") {
2021-01-16 21:07:55 +00:00
this.setTalkgroup(data['target']);
}
if (data['type'] === "direct") {
this.setDirect(data['target']);
}
this.el.addClass("active");
} else {
2021-01-16 21:07:55 +00:00
this.clear();
}
2021-01-16 21:07:55 +00:00
};
DmrMetaSlot.prototype.setId = function(id) {
if (this.id === id) return;
this.id = id;
this.el.find('.openwebrx-dmr-id').text(id || '');
}
2021-01-16 21:07:55 +00:00
DmrMetaSlot.prototype.setName = function(name) {
if (this.name === name) return;
this.name = name;
this.el.find('.openwebrx-dmr-name').text(name || '');
};
DmrMetaSlot.prototype.setTalkgroup = function(talkgroup) {
if (this.talkgroup === talkgroup && this.targetMode === 'talkgroup') return;
this.talkgroup = talkgroup;
this.targetMode = 'talkgroup';
var text = '';
if (talkgroup && talkgroup != '') {
text = 'Talkgroup: ' + talkgroup;
}
this.el.find('.openwebrx-dmr-target').text(text);
this.el.find(".openwebrx-meta-user-image").addClass("group");
};
DmrMetaSlot.prototype.setDirect = function(call) {
if (this.call === call && this.targetMode === 'direct') return;
this.call = call;
this.targetMode = 'direct';
var text = '';
if (call && call != '') {
text = 'Direct: ' + call;
}
this.el.find('.openwebrx-dmr-target').text(text);
this.el.find(".openwebrx-meta-user-image").removeClass("group");
};
DmrMetaSlot.prototype.clear = function() {
this.setId();
this.setName();
this.setTalkgroup();
this.setDirect();
this.el.removeClass("active");
};
function DmrMetaPanel(el) {
MetaPanel.call(this, el);
this.modes = ['DMR'];
this.slots = this.el.find('.openwebrx-meta-slot').toArray().map(function(el){
return new DmrMetaSlot(el);
});
}
DmrMetaPanel.prototype = new MetaPanel();
DmrMetaPanel.prototype.update = function(data) {
if (!this.isSupported(data)) return;
if (data['slot']) {
var slot = this.slots[data['slot']];
slot.update(data);
} else {
this.clear();
}
}
DmrMetaPanel.prototype.clear = function() {
MetaPanel.prototype.clear.call(this);
this.el.find(".openwebrx-dmr-timeslot-panel").removeClass("muted");
2021-01-16 21:07:55 +00:00
this.slots.forEach(function(slot) {
slot.clear();
});
};
function YsfMetaPanel(el) {
MetaPanel.call(this, el);
this.modes = ['YSF'];
this.clear();
}
YsfMetaPanel.prototype = new MetaPanel();
YsfMetaPanel.prototype.update = function(data) {
if (!this.isSupported(data)) return;
this.setMode(data['mode']);
if (data['mode'] && data['mode'] !== "") {
this.setSource(data['source']);
this.setLocation(data['lat'], data['lon'], data['source']);
this.setUp(data['up']);
this.setDown(data['down']);
this.el.find(".openwebrx-meta-slot").addClass("active");
} else {
2021-01-16 20:16:49 +00:00
this.clear();
}
};
YsfMetaPanel.prototype.clear = function() {
MetaPanel.prototype.clear.call(this);
2021-01-16 20:16:49 +00:00
this.setMode();
this.setSource();
this.setLocation();
this.setUp();
this.setDown();
};
YsfMetaPanel.prototype.setMode = function(mode) {
if (this.mode === mode) return;
this.mode = mode;
var text = '';
if (mode && mode != '') {
text = 'Mode: ' + mode;
}
this.el.find('.openwebrx-ysf-mode').text(text);
};
YsfMetaPanel.prototype.setSource = function(source) {
if (this.source === source) return;
this.source = source;
this.el.find('.openwebrx-ysf-source .callsign').text(source || '');
};
YsfMetaPanel.prototype.setLocation = function(lat, lon, callsign) {
2021-01-16 20:16:49 +00:00
var hasLocation = lat && lon && callsign && callsign != '';
if (hasLocation === this.hasLocation && this.callsign === callsign) return;
this.hasLocation = hasLocation; this.callsign = callsign;
var html = '';
2021-01-16 20:16:49 +00:00
if (hasLocation) {
html = '<a class="openwebrx-maps-pin" href="map?callsign=' + encodeURIComponent(callsign) + '" target="_blank"></a>';
}
this.el.find('.openwebrx-ysf-source .location').html(html);
};
YsfMetaPanel.prototype.setUp = function(up) {
if (this.up === up) return;
this.up = up;
var text = '';
if (up && up != '') {
text = 'Up: ' + up;
}
this.el.find('.openwebrx-ysf-up').text(text);
};
YsfMetaPanel.prototype.setDown = function(down) {
if (this.down === down) return;
this.down = down;
var text = '';
if (down && down != '') {
text = 'Down: ' + down;
}
this.el.find('.openwebrx-ysf-down').text(text);
}
MetaPanel.types = {
dmr: DmrMetaPanel,
ysf: YsfMetaPanel
};
$.fn.metaPanel = function() {
return this.map(function() {
var $self = $(this);
if (!$self.data('metapanel')) {
var matches = /^openwebrx-panel-metadata-([a-z]+)$/.exec($self.prop('id'));
var constructor = matches && MetaPanel.types[matches[1]] || MetaPanel;
$self.data('metapanel', new constructor($self));
}
return $self.data('metapanel');
});
};