2020-03-30 13:44:18 +02:00
|
|
|
//TODO: Use the max limit!
|
2020-03-29 12:54:15 +02:00
|
|
|
|
2020-03-30 13:44:18 +02:00
|
|
|
import {sliderfy} from "tc-shared/ui/elements/Slider";
|
|
|
|
import {createModal, Modal} from "tc-shared/ui/elements/Modal";
|
|
|
|
import {ClientEntry} from "tc-shared/ui/client";
|
|
|
|
import * as htmltags from "tc-shared/ui/htmltags";
|
2020-05-20 20:47:48 +02:00
|
|
|
import {spawnReactModal} from "tc-shared/ui/react-elements/Modal";
|
2019-10-13 21:33:07 +02:00
|
|
|
|
2020-03-30 13:44:18 +02:00
|
|
|
let modal: Modal;
|
|
|
|
export function spawnChangeVolume(client: ClientEntry, local: boolean, current: number, max: number | undefined, callback: (number) => void) {
|
|
|
|
if(modal) modal.close();
|
2019-10-13 21:33:07 +02:00
|
|
|
|
2020-03-30 13:44:18 +02:00
|
|
|
let new_value: number;
|
|
|
|
modal = createModal({
|
|
|
|
header: local ? tr("Change local volume") : tr("Change remote volume"),
|
|
|
|
body: function () {
|
|
|
|
let tag = $("#tmpl_change_volume").renderTag({
|
|
|
|
client: htmltags.generate_client_object({
|
|
|
|
add_braces: false,
|
|
|
|
client_name: client.clientNickName(),
|
|
|
|
client_unique_id: client.properties.client_unique_identifier,
|
|
|
|
client_id: client.clientId()
|
|
|
|
}),
|
|
|
|
local: local
|
|
|
|
});
|
2018-04-11 17:56:09 +02:00
|
|
|
|
2020-03-30 13:44:18 +02:00
|
|
|
const container_value = tag.find(".info .value");
|
|
|
|
const set_value = value => {
|
|
|
|
const number = value > 100 ? value - 100 : 100 - value;
|
|
|
|
container_value.html((value == 100 ? "±" : value > 100 ? "+" : "-") + number + "%");
|
2018-04-11 17:56:09 +02:00
|
|
|
|
2020-03-30 13:44:18 +02:00
|
|
|
new_value = value / 100;
|
|
|
|
if(local) callback(new_value);
|
|
|
|
};
|
|
|
|
set_value(current * 100);
|
2018-04-11 17:56:09 +02:00
|
|
|
|
2020-03-30 13:44:18 +02:00
|
|
|
const slider_tag = tag.find(".container-slider");
|
|
|
|
const slider = sliderfy(slider_tag, {
|
|
|
|
initial_value: current * 100,
|
|
|
|
step: 1,
|
|
|
|
max_value: 200,
|
|
|
|
min_value: 0,
|
2018-04-11 17:56:09 +02:00
|
|
|
|
2020-03-30 13:44:18 +02:00
|
|
|
unit: '%'
|
|
|
|
});
|
|
|
|
slider_tag.on('change', event => set_value(parseInt(slider_tag.attr("value"))));
|
2018-04-11 17:56:09 +02:00
|
|
|
|
2020-03-30 13:44:18 +02:00
|
|
|
tag.find(".button-save").on('click', event => {
|
|
|
|
if(typeof(new_value) !== "undefined") callback(new_value);
|
|
|
|
modal.close();
|
|
|
|
});
|
2019-01-20 18:43:14 +01:00
|
|
|
|
2020-03-30 13:44:18 +02:00
|
|
|
tag.find(".button-cancel").on('click', event => {
|
|
|
|
callback(current);
|
|
|
|
modal.close();
|
|
|
|
});
|
2019-01-20 18:43:14 +01:00
|
|
|
|
2020-03-30 13:44:18 +02:00
|
|
|
tag.find(".button-reset").on('click', event => {
|
|
|
|
slider.value(100);
|
|
|
|
});
|
2019-01-20 18:43:14 +01:00
|
|
|
|
2020-03-30 13:44:18 +02:00
|
|
|
tag.find(".button-apply").on('click', event => {
|
|
|
|
callback(new_value);
|
|
|
|
new_value = undefined;
|
|
|
|
});
|
2019-01-20 18:43:14 +01:00
|
|
|
|
2020-03-30 13:44:18 +02:00
|
|
|
return tag.children();
|
|
|
|
},
|
|
|
|
footer: null,
|
2019-01-20 18:43:14 +01:00
|
|
|
|
2020-03-30 13:44:18 +02:00
|
|
|
width: 600
|
|
|
|
});
|
2019-01-20 18:43:14 +01:00
|
|
|
|
2020-03-30 13:44:18 +02:00
|
|
|
modal.close_listener.push(() => modal = undefined);
|
|
|
|
modal.open();
|
|
|
|
modal.htmlTag.find(".modal-body").addClass("modal-volume");
|
2018-04-11 17:56:09 +02:00
|
|
|
}
|