Browse Source

Tarkista ylläpitäjyys asiakasohjelmassa.

master
Linus Vanas 1 month ago
parent
commit
6ed437ca20
1 changed files with 47 additions and 29 deletions
  1. +47
    -29
      src/veturi-js/Panels/OrdersPanel.js

+ 47
- 29
src/veturi-js/Panels/OrdersPanel.js View File

@@ -12,6 +12,7 @@ class OrdersPanel extends Panel
this.form = this.element;

VETURI.orders.subscribeToUpdates(this);
VETURI.login.subscribeToUpdates(this);

const submit = document.createElement("input");
submit.type = "submit";
@@ -33,16 +34,15 @@ class OrdersPanel extends Panel
this.module.span.innerText = _("You're not logged in!");
}

const selectOrder = document.createElement("select");
selectOrder.module = this;
selectOrder.onchange = function()
this.orderSelect = document.createElement("select");
this.orderSelect.onchange = function()
{
if (!this.value)
{
return;
}
const oClass = Function("return "+this.value+";")();
const order = new oClass(this.module.veturi);
const order = new oClass();
const object = order.province || order.country || order.connection;
object.deserialize();
object.activate();
@@ -50,34 +50,12 @@ class OrdersPanel extends Panel
VETURI.orders.addOrder(order);
this.value = "";
}
const defaultOption = document.createElement("option");
defaultOption.value = "";
defaultOption.innerText = _("Give an order");
selectOrder.appendChild(defaultOption);

//if (VETURI.login.isAdmin())
{
const createCountryOption = document.createElement("option");
createCountryOption.value = "CreateCountryOrder";
createCountryOption.innerText = _("Create a country");
selectOrder.appendChild(createCountryOption);

const createProvinceOption = document.createElement("option");
createProvinceOption.value = "CreateProvinceOrder";
createProvinceOption.innerText = _("Create a province");
selectOrder.appendChild(createProvinceOption);

const createConnectionOption = document.createElement("option");
createConnectionOption.value = "CreateConnectionOrder";
createConnectionOption.innerText = _("Create a connection");
selectOrder.appendChild(createConnectionOption);
}

this.span = document.createElement("span");
this.span = document.createElement("div");

this.form.appendChild(submit);
this.form.appendChild(document.createTextNode(" "));
this.form.appendChild(selectOrder);
this.form.appendChild(this.orderSelect);
this.form.appendChild(this.span);
}

@@ -87,7 +65,7 @@ class OrdersPanel extends Panel
*/
receiveUpdate(object, update)
{
if (update.cause === "login")
if (object === VETURI.orders && update.cause === "login")
{
if (!this.waitingForOrdersSaved)
{
@@ -100,6 +78,46 @@ class OrdersPanel extends Panel
return;
}
this.span.innerText = _("Failed to send orders.");
return;
}
if (object === VETURI.login)
{
while (this.orderSelect.firstChild)
{
this.orderSelect.removeChild(this.orderSelect.firstChild);
}
const defaultOption = document.createElement("option");
defaultOption.value = "";
defaultOption.innerText = _("Give an order");
this.orderSelect.appendChild(defaultOption);

if (VETURI.login.isAdmin())
{
const createCountryOption = document.createElement("option");
createCountryOption.value = "CreateCountryOrder";
createCountryOption.innerText = _("Create a country");
this.orderSelect.appendChild(createCountryOption);

const createProvinceOption = document.createElement("option");
createProvinceOption.value = "CreateProvinceOrder";
createProvinceOption.innerText = _("Create a province");
this.orderSelect.appendChild(createProvinceOption);

const createConnectionOption = document.createElement("option");
createConnectionOption.value = "CreateConnectionOrder";
createConnectionOption.innerText = _("Create a connection");
this.orderSelect.appendChild(createConnectionOption);

return;
}
if (VETURI.login.isLoggedIn())
{
const buildUnitOption = document.createElement("option");
buildUnitOption.value = "BuildUnitOrder";
buildUnitOption.innerText = _("Build a unit");
this.orderSelect.appendChild(buildUnitOption);
return;
}
}
}



Loading…
Cancel
Save