2
0
mirror of https://github.com/esiur/iui.git synced 2025-05-06 06:42:58 +00:00

DateTimePicker

This commit is contained in:
Ahmed Zamil 2024-07-06 14:13:27 +03:00
parent 2d73f0c63c
commit b75bb9869f
6 changed files with 64 additions and 144 deletions

View File

@ -165,6 +165,7 @@
--grid-window-drag-border: #46b7e6 dotted 3px; --grid-window-drag-border: #46b7e6 dotted 3px;
--datetimepicker-calendar-border-right: 3px solid pink; --datetimepicker-calendar-border-right: 3px solid pink;
--datetimepicker-clock-background: gainsboro; --datetimepicker-clock-background: gainsboro;
--datetimepicker-calendar-content-background: var(--default-background-color);
--datetimepicker-different-month-color: #bebebe; --datetimepicker-different-month-color: #bebebe;
--datetimepicker-day-background-hover: #a7e3fc; --datetimepicker-day-background-hover: #a7e3fc;
--datetimepicker-day-selected-background: #46b7e6; --datetimepicker-day-selected-background: #46b7e6;
@ -2366,6 +2367,7 @@ html[dir='rtl'] .multiselect-list-remove {
.datetimepicker-calendar-content { .datetimepicker-calendar-content {
display: flex; display: flex;
flex: 1; flex: 1;
background: var(--datetimepicker-calendar-content-background);
} }
.datetimepicker-clock { .datetimepicker-clock {

View File

@ -1,6 +1,6 @@
{ {
"name": "@esiur/iui", "name": "@esiur/iui",
"version": "1.2.1", "version": "1.2.2",
"description": "Interactive User Interface", "description": "Interactive User Interface",
"main": "iui.js", "main": "iui.js",
"type": "module", "type": "module",

View File

@ -13,6 +13,7 @@ export default IUI.module(
this._register("show"); this._register("show");
this._register("hide"); this._register("hide");
this._register("load");
} }
async setData(value) { async setData(value) {
@ -150,6 +151,7 @@ export default IUI.module(
created() { created() {
this.refs._build(); this.refs._build();
this._emit("load", { route: this });
} }
set(value) { set(value) {

View File

@ -114,6 +114,10 @@ export default IUI.module(class DateTimePicker extends IUIElement {
self._value.setFullYear(self._year); self._value.setFullYear(self._year);
self._value.setMonth(self._month); self._value.setMonth(self._month);
self.render(); self.render();
if (self.isAuto)
self.revert();
self._emit("select", { value: self._value }); self._emit("select", { value: self._value });
self._emit(":value", { value }); self._emit(":value", { value });
}); });
@ -165,6 +169,10 @@ export default IUI.module(class DateTimePicker extends IUIElement {
var m = Math.floor(t % 60); var m = Math.floor(t % 60);
self._value.setHours(h); self._value.setHours(h);
self._value.setMinutes(m); self._value.setMinutes(m);
if (self.isAuto)
self.revert();
self._emit("select", self._value); self._emit("select", self._value);
self.render(); self.render();
}); });
@ -180,7 +188,20 @@ export default IUI.module(class DateTimePicker extends IUIElement {
this.value = new Date(); this.value = new Date();
} }
create() { async create() {
await super.create();
this.isAuto = this.hasAttribute("auto");
this.field = this.getAttribute("field");
if (this.field != null) {
this.setAttribute(":data", `d != null ? d['${this.field}'] : null`);
this.setAttribute(
"async:revert",
`d != null ? d['${this.field}'] = this.data : null`
);
}
var self = this; var self = this;
@ -286,13 +307,25 @@ export default IUI.module(class DateTimePicker extends IUIElement {
} }
get data() { get data() {
return super.data; return this.value;
} }
async setData(value) {
await super.setData(value);
this.value = value;
if (this.isAuto)
this.revert();
}
/*
modified(name, value) { modified(name, value) {
if (name == this.field) if (name == this.field)
this.value = value; this.value = value;
} }
*/
set value(value) { set value(value) {
if (value && !isNaN(value.getTime())) { if (value && !isNaN(value.getTime())) {
@ -305,6 +338,9 @@ export default IUI.module(class DateTimePicker extends IUIElement {
this._emit("modified", { value, property: "value" }); this._emit("modified", { value, property: "value" });
//this.modified("value", ); //this.modified("value", );
//this.modified("modified", { value }); //this.modified("modified", { value });
if (this.isAuto)
this.revert();
} }
} }

View File

@ -4,14 +4,12 @@ import Layout from "../Data/Layout.js";
import Menu from "./Menu.js"; import Menu from "./Menu.js";
export default IUI.module(class DropDown extends IUIElement { export default IUI.module(class DropDown extends IUIElement {
visible = false; //visible = false;
constructor() { constructor() {
super({"direction": "down" }); super({"direction": "down" });
this._register("visible"); this._register("visible");
} }
@ -55,17 +53,6 @@ export default IUI.module(class DropDown extends IUIElement {
document.body.appendChild(this.menu); document.body.appendChild(this.menu);
} }
this.addEventListener("click", function (e) {
var t = e.target
do {
if (t == self.menu)
return;
} while (t = t.parentElement)
self.setVisible(!self.visible);
});
app.appendChild(this.menu); app.appendChild(this.menu);
if (app.loaded) if (app.loaded)
@ -80,6 +67,14 @@ export default IUI.module(class DropDown extends IUIElement {
} }
} }
async setData(value){
//debugger;
await super.setData(value);
await this.menu.setData(value);
}
set fixed(value) { set fixed(value) {
if (value) if (value)
document.body.appendChild(this.menu); document.body.appendChild(this.menu);
@ -110,35 +105,17 @@ export default IUI.module(class DropDown extends IUIElement {
app.appendChild(this.menu); app.appendChild(this.menu);
} }
getOffset() {
var el = this;
var _x = 0;
var _y = 0;
while (!isNaN(el.offsetLeft) && !isNaN(el.offsetTop)) {
_x += el.offsetLeft - el.scrollLeft;
_y += el.offsetTop - el.scrollTop;
el = el.offsetParent;
}
_x += window.pageXOffset;
_y += window.pageYOffset;
return { top: _y, left: _x, width: this.clientWidth, height: this.clientHeight };
}
setVisible(visible) { setVisible(visible) {
if (visible == this.visible) if (visible == this.menu.visible)
return; return;
if (visible) { if (visible) {
// show menu // show menu
var rect = this.getBoundingClientRect(); var rect = this.getBoundingClientRect();
this.menu.style.width = (this.clientWidth - this._computeMenuOuterWidth()) + "px"; //this.menu.style.width = (this.clientWidth - this._computeMenuOuterWidth()) + "px";
this.menu.style.paddingTop = rect.height + "px"; this.menu.style.marginTop = rect.height + "px";
this.menu.setVisible(true, rect.left, rect.top);//, this.menu); this.menu.setVisible(true, rect.left, rect.top);//, this.menu);
this.visible = true;
this.classList.add(this.cssClass + "-visible"); this.classList.add(this.cssClass + "-visible");
@ -149,113 +126,15 @@ export default IUI.module(class DropDown extends IUIElement {
} }
else { else {
this.visible = false;
this.classList.remove(this.cssClass + "-visible");
this.classList.remove(this.cssClass + "-visible");
this.menu.hide(); this.menu.hide();
} }
//this.textbox.focus();
} }
_computeMenuOuterWidth() { _computeMenuOuterWidth() {
return this.menu.offsetWidth - this.menu.clientWidth; return this.menu.offsetWidth - this.menu.clientWidth;
} }
setVisibleOld(visible) {
this.visible = visible;
if (!this.fixed) {
if (visible) {
this.menu.classList.add(this.cssClass + "-menu-visible");
this.classList.add(this.cssClass + "-visible");
}
else {
this.menu.classList.remove(this.cssClass + "-menu-visible");
this.classList.remove(this.cssClass + "-visible");
}
}
else {
if (visible) {
var rect = this.getBoundingClientRect();
var menuWidth = this.menu.clientWidth;
var menuHeight = this.menu.clientHeight;
if (menuWidth > document.body.clientWidth) {
menuWidth = (document.body.clientWidth - 10);
this.menu.style.width = menuWidth + "px";
}
var startX = rect.left + (rect.width / 2 - menuWidth / 2);
if (this.direction == "up") {
// var menuTop = rect.top - this.arrow.clientHeight - this.menu.clientHeight;
var menuTop = rect.top - this.menu.clientHeight;
if (menuTop < 0) {
menuTop = 5;
// this.menu.style.height = (rect.top - this.arrow.clientHeight ) + "px";
this.menu.style.height = (rect.top) + "px";
this.menu.classList.add(this.cssClass + "-menu-oversized");
}
else
this.menu.classList.remove(this.cssClass + "-menu-oversized");
//this.arrow.classList.remove(this.customClass + "-arrow-down");
//this.arrow.classList.add(this.customClass + "-arrow-up");
//this.arrow.style.top = ( rect.top - this.arrow.clientHeight ) + "px";
this.menu.style.top = (menuTop) + "px";
}
else {
//var menuTop = rect.top + rect.height + this.arrow.clientHeight;
var menuTop = rect.top + rect.height;
//this.arrow.classList.remove(this.customClass + "-arrow-up");
//this.arrow.classList.add(this.customClass + "-arrow-down");
//this.arrow.style.top = ( rect.top + rect.height ) + "px";
this.menu.style.top = menuTop + "px";
if (menuTop + menuHeight > document.body.clientHeight) {
this.menu.style.height = (document.body.clientHeight - menuTop) + "px";
this.menu.classList.add(this.cssClass + "-menu-oversized");
}
else {
this.menu.classList.remove(this.cssClass + "-menu-oversized");
}
}
if (startX < 0)
startX = 5;
else if (startX + menuWidth > document.body.clientWidth)
startX = document.body.clientWidth - menuWidth - 5;
//this.arrow.style.left = (rect.left + (rect.width/2 - this.arrow.clientWidth/2)) + "px";
this.menu.style.left = startX + "px";
//this.arrow.classList.add(this.customClass + "-arrow-visible");
this.menu.classList.add(this.cssClass + "-menu-visible");
this.classList.add(this.cssClass + "-visible");
}
else {
//this.arrow.classList.remove(this.customClass + "-arrow-visible");
this.menu.classList.remove(this.cssClass + "-menu-visible");
this.classList.remove(this.cssClass + "-visible");
}
}
this._emit("visible", { visible});
return this;
}
}); });

View File

@ -157,7 +157,8 @@ export default IUI.module(
// can't set value on file input // can't set value on file input
} else this._input.value = value; } else this._input.value = value;
if (this._checkValidity() && this.isAuto) this.revert(); if (this._checkValidity() && this.isAuto)
this.revert();
/* /*
await super.setData(value); await super.setData(value);