forked from MapComplete/MapComplete
Intermediate refactoring
This commit is contained in:
parent
93db813cfc
commit
069cddf034
103 changed files with 7950 additions and 0 deletions
69
UI/Input/DropDown.js
Normal file
69
UI/Input/DropDown.js
Normal file
|
@ -0,0 +1,69 @@
|
|||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DropDown = void 0;
|
||||
var UIEventSource_1 = require("../UIEventSource");
|
||||
var UIElement_1 = require("../UIElement");
|
||||
var DropDown = /** @class */ (function (_super) {
|
||||
__extends(DropDown, _super);
|
||||
function DropDown(label, values, selectedElement) {
|
||||
if (selectedElement === void 0) { selectedElement = undefined; }
|
||||
var _this = _super.call(this, undefined) || this;
|
||||
_this._label = label;
|
||||
_this._values = values;
|
||||
_this.selectedElement = selectedElement !== null && selectedElement !== void 0 ? selectedElement : new UIEventSource_1.UIEventSource(values[0].value);
|
||||
if (selectedElement.data === undefined) {
|
||||
_this.selectedElement.setData(values[0].value);
|
||||
}
|
||||
var self = _this;
|
||||
_this.selectedElement.addCallback(function () {
|
||||
self.InnerUpdate();
|
||||
});
|
||||
return _this;
|
||||
}
|
||||
DropDown.prototype.InnerRender = function () {
|
||||
var options = "";
|
||||
for (var _i = 0, _a = this._values; _i < _a.length; _i++) {
|
||||
var value = _a[_i];
|
||||
options += "<option value='" + value.value + "'>" + value.shown + "</option>";
|
||||
}
|
||||
return "<form>" +
|
||||
"<label for='dropdown-" + this.id + "'>" + this._label + "</label>" +
|
||||
"<select name='dropdown-" + this.id + "' id='dropdown-" + this.id + "'>" +
|
||||
options +
|
||||
"</select>" +
|
||||
"</form>";
|
||||
};
|
||||
DropDown.prototype.InnerUpdate = function () {
|
||||
var self = this;
|
||||
var e = document.getElementById("dropdown-" + this.id);
|
||||
if (e === null) {
|
||||
return;
|
||||
}
|
||||
// @ts-ignore
|
||||
if (this.selectedElement.data !== e.value) {
|
||||
// @ts-ignore
|
||||
e.value = this.selectedElement.data;
|
||||
}
|
||||
e.onchange = function () {
|
||||
// @ts-ignore
|
||||
var selectedValue = e.options[e.selectedIndex].value;
|
||||
console.log("Putting data", selectedValue);
|
||||
self.selectedElement.setData(selectedValue);
|
||||
};
|
||||
};
|
||||
return DropDown;
|
||||
}(UIElement_1.UIElement));
|
||||
exports.DropDown = DropDown;
|
39
UI/Input/FixedInputElement.js
Normal file
39
UI/Input/FixedInputElement.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.FixedInputElement = void 0;
|
||||
var InputElement_1 = require("./InputElement");
|
||||
var UIEventSource_1 = require("../UIEventSource");
|
||||
var FixedUiElement_1 = require("../Base/FixedUiElement");
|
||||
var FixedInputElement = /** @class */ (function (_super) {
|
||||
__extends(FixedInputElement, _super);
|
||||
function FixedInputElement(rendering, value) {
|
||||
var _this = _super.call(this, undefined) || this;
|
||||
_this.value = new UIEventSource_1.UIEventSource(value);
|
||||
_this.rendering = typeof (rendering) === 'string' ? new FixedUiElement_1.FixedUiElement(rendering) : rendering;
|
||||
return _this;
|
||||
}
|
||||
FixedInputElement.prototype.GetValue = function () {
|
||||
return this.value;
|
||||
};
|
||||
FixedInputElement.prototype.InnerRender = function () {
|
||||
return this.rendering.Render();
|
||||
};
|
||||
FixedInputElement.prototype.IsValid = function (t) {
|
||||
return t === this.value.data;
|
||||
};
|
||||
return FixedInputElement;
|
||||
}(InputElement_1.InputElement));
|
||||
exports.FixedInputElement = FixedInputElement;
|
25
UI/Input/InputElement.js
Normal file
25
UI/Input/InputElement.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.InputElement = void 0;
|
||||
var UIElement_1 = require("../UIElement");
|
||||
var InputElement = /** @class */ (function (_super) {
|
||||
__extends(InputElement, _super);
|
||||
function InputElement() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
return InputElement;
|
||||
}(UIElement_1.UIElement));
|
||||
exports.InputElement = InputElement;
|
39
UI/Input/InputElementWrapper.js
Normal file
39
UI/Input/InputElementWrapper.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.InputElementWrapper = void 0;
|
||||
var InputElement_1 = require("./InputElement");
|
||||
var UIElement_1 = require("../UIElement");
|
||||
var InputElementWrapper = /** @class */ (function (_super) {
|
||||
__extends(InputElementWrapper, _super);
|
||||
function InputElementWrapper(pre, input, post) {
|
||||
var _this = _super.call(this, undefined) || this;
|
||||
_this.post = UIElement_1.UIElement.Fix(post);
|
||||
_this.input = input;
|
||||
_this.pre = UIElement_1.UIElement.Fix(pre);
|
||||
return _this;
|
||||
}
|
||||
InputElementWrapper.prototype.GetValue = function () {
|
||||
return this.input.GetValue();
|
||||
};
|
||||
InputElementWrapper.prototype.InnerRender = function () {
|
||||
return this.pre.Render() + this.input.Render() + this.post.Render();
|
||||
};
|
||||
InputElementWrapper.prototype.IsValid = function (t) {
|
||||
return this.input.IsValid(t);
|
||||
};
|
||||
return InputElementWrapper;
|
||||
}(InputElement_1.InputElement));
|
||||
exports.InputElementWrapper = InputElementWrapper;
|
122
UI/Input/RadioButton.js
Normal file
122
UI/Input/RadioButton.js
Normal file
|
@ -0,0 +1,122 @@
|
|||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.RadioButton = void 0;
|
||||
var UIEventSource_1 = require("../UIEventSource");
|
||||
var InputElement_1 = require("./InputElement");
|
||||
var RadioButton = /** @class */ (function (_super) {
|
||||
__extends(RadioButton, _super);
|
||||
function RadioButton(elements, selectFirstAsDefault) {
|
||||
if (selectFirstAsDefault === void 0) { selectFirstAsDefault = true; }
|
||||
var _this = _super.call(this, undefined) || this;
|
||||
_this._selectedElementIndex = new UIEventSource_1.UIEventSource(null);
|
||||
_this._elements = elements;
|
||||
_this._selectFirstAsDefault = selectFirstAsDefault;
|
||||
var self = _this;
|
||||
_this.value =
|
||||
UIEventSource_1.UIEventSource.flatten(_this._selectedElementIndex.map(function (selectedIndex) {
|
||||
if (selectedIndex !== undefined && selectedIndex !== null) {
|
||||
return elements[selectedIndex].GetValue();
|
||||
}
|
||||
}), elements.map(function (e) { return e.GetValue(); }));
|
||||
_this.value.addCallback(function (t) {
|
||||
self.SetCorrectValue(t);
|
||||
});
|
||||
var _loop_1 = function (i) {
|
||||
// If an element is clicked, the radio button corresponding with it should be selected as well
|
||||
elements[i].onClick(function () {
|
||||
self._selectedElementIndex.setData(i);
|
||||
});
|
||||
};
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
_loop_1(i);
|
||||
}
|
||||
return _this;
|
||||
}
|
||||
RadioButton.prototype.IsValid = function (t) {
|
||||
for (var _i = 0, _a = this._elements; _i < _a.length; _i++) {
|
||||
var inputElement = _a[_i];
|
||||
if (inputElement.IsValid(t)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
RadioButton.prototype.GetValue = function () {
|
||||
return this.value;
|
||||
};
|
||||
RadioButton.prototype.IdFor = function (i) {
|
||||
return 'radio-' + this.id + '-' + i;
|
||||
};
|
||||
RadioButton.prototype.InnerRender = function () {
|
||||
var body = "";
|
||||
var i = 0;
|
||||
for (var _i = 0, _a = this._elements; _i < _a.length; _i++) {
|
||||
var el = _a[_i];
|
||||
var htmlElement = '<input type="radio" id="' + this.IdFor(i) + '" name="radiogroup-' + this.id + '">' +
|
||||
'<label for="' + this.IdFor(i) + '">' + el.Render() + '</label>' +
|
||||
'<br>';
|
||||
body += htmlElement;
|
||||
i++;
|
||||
}
|
||||
return "<form id='" + this.id + "-form'>" + body + "</form>";
|
||||
};
|
||||
RadioButton.prototype.SetCorrectValue = function (t) {
|
||||
if (t === undefined) {
|
||||
return;
|
||||
}
|
||||
// We check that what is selected matches the previous rendering
|
||||
for (var i = 0; i < this._elements.length; i++) {
|
||||
var e = this._elements[i];
|
||||
if (e.IsValid(t)) {
|
||||
this._selectedElementIndex.setData(i);
|
||||
e.GetValue().setData(t);
|
||||
// @ts-ignore
|
||||
document.getElementById(this.IdFor(i)).checked = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
RadioButton.prototype.InnerUpdate = function (htmlElement) {
|
||||
var self = this;
|
||||
function checkButtons() {
|
||||
for (var i = 0; i < self._elements.length; i++) {
|
||||
var el_1 = document.getElementById(self.IdFor(i));
|
||||
// @ts-ignore
|
||||
if (el_1.checked) {
|
||||
self._selectedElementIndex.setData(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
var el = document.getElementById(this.id);
|
||||
el.addEventListener("change", function () {
|
||||
checkButtons();
|
||||
});
|
||||
if (this._selectFirstAsDefault) {
|
||||
this.SetCorrectValue(this.value.data);
|
||||
if (this._selectedElementIndex.data === null || this._selectedElementIndex.data === undefined) {
|
||||
var el_2 = document.getElementById(this.IdFor(0));
|
||||
if (el_2) {
|
||||
// @ts-ignore
|
||||
el_2.checked = true;
|
||||
checkButtons();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
;
|
||||
return RadioButton;
|
||||
}(InputElement_1.InputElement));
|
||||
exports.RadioButton = RadioButton;
|
94
UI/Input/TextField.js
Normal file
94
UI/Input/TextField.js
Normal file
|
@ -0,0 +1,94 @@
|
|||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TextField = void 0;
|
||||
var UIEventSource_1 = require("../UIEventSource");
|
||||
var InputElement_1 = require("./InputElement");
|
||||
var FixedUiElement_1 = require("../Base/FixedUiElement");
|
||||
var TextField = /** @class */ (function (_super) {
|
||||
__extends(TextField, _super);
|
||||
function TextField(options) {
|
||||
var _a, _b, _c, _d;
|
||||
var _this = _super.call(this, undefined) || this;
|
||||
/**
|
||||
* Pings and has the value data
|
||||
*/
|
||||
_this.enterPressed = new UIEventSource_1.UIEventSource(undefined);
|
||||
_this.value = new UIEventSource_1.UIEventSource("");
|
||||
_this.mappedValue = (_a = options === null || options === void 0 ? void 0 : options.value) !== null && _a !== void 0 ? _a : new UIEventSource_1.UIEventSource(undefined);
|
||||
// @ts-ignore
|
||||
_this._fromString = (_b = options.fromString) !== null && _b !== void 0 ? _b : (function (str) { return (str); });
|
||||
_this.value.addCallback(function (str) { return _this.mappedValue.setData(options.fromString(str)); });
|
||||
_this.mappedValue.addCallback(function (t) { return _this.value.setData(options.toString(t)); });
|
||||
_this._placeholder =
|
||||
typeof (options.placeholder) === "string" ? new FixedUiElement_1.FixedUiElement(options.placeholder) :
|
||||
((_c = options.placeholder) !== null && _c !== void 0 ? _c : new FixedUiElement_1.FixedUiElement(""));
|
||||
_this._toString = (_d = options.toString) !== null && _d !== void 0 ? _d : (function (t) { return ("" + t); });
|
||||
var self = _this;
|
||||
_this.mappedValue.addCallback(function (t) {
|
||||
if (t === undefined && t === null) {
|
||||
return;
|
||||
}
|
||||
var field = document.getElementById('text-' + _this.id);
|
||||
if (field === undefined || field === null) {
|
||||
return;
|
||||
}
|
||||
// @ts-ignore
|
||||
field.value = options.toString(t);
|
||||
});
|
||||
return _this;
|
||||
}
|
||||
TextField.prototype.GetValue = function () {
|
||||
return this.mappedValue;
|
||||
};
|
||||
TextField.prototype.InnerRender = function () {
|
||||
return "<form onSubmit='return false' class='form-text-field'>" +
|
||||
"<input type='text' placeholder='" + this._placeholder.InnerRender() + "' id='text-" + this.id + "'>" +
|
||||
"</form>";
|
||||
};
|
||||
TextField.prototype.InnerUpdate = function (htmlElement) {
|
||||
var field = document.getElementById('text-' + this.id);
|
||||
if (field === null) {
|
||||
return;
|
||||
}
|
||||
var self = this;
|
||||
field.oninput = function () {
|
||||
// @ts-ignore
|
||||
self.value.setData(field.value);
|
||||
};
|
||||
field.addEventListener("keyup", function (event) {
|
||||
if (event.key === "Enter") {
|
||||
// @ts-ignore
|
||||
self.enterPressed.setData(field.value);
|
||||
}
|
||||
});
|
||||
};
|
||||
TextField.prototype.IsValid = function (t) {
|
||||
if (t === undefined || t === null) {
|
||||
return false;
|
||||
}
|
||||
var result = this._toString(t);
|
||||
return result !== undefined && result !== null;
|
||||
};
|
||||
TextField.prototype.Clear = function () {
|
||||
var field = document.getElementById('text-' + this.id);
|
||||
if (field !== undefined) {
|
||||
// @ts-ignore
|
||||
field.value = "";
|
||||
}
|
||||
};
|
||||
return TextField;
|
||||
}(InputElement_1.InputElement));
|
||||
exports.TextField = TextField;
|
Loading…
Add table
Add a link
Reference in a new issue