Refactor PoleDisplay class and update Auth user_log method

- Converted PoleDisplay from a function-based structure to a class-based structure for improved readability and maintainability.
- Simplified the Open and Close methods to handle port state more clearly.
- Enhanced the Send method to support both string and array inputs for sending data.
- Updated the cd_Text method to use modern JavaScript features for padding calculations.
- Modified the user_log method in Auth class to streamline database fetch and update logic.
This commit is contained in:
2026-11-01 15:55:28 +07:00
parent cf100a86e2
commit 929f3af79a
4 changed files with 992 additions and 1195 deletions
+261 -375
View File
@@ -1,40 +1,8 @@
var __extends = (undefined && undefined.__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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var BaseResolver = (function () {
function BaseResolver(options) {
var AjaxResolver = class {
constructor(options) {
this._settings = $.extend(true, {}, this.getDefaults(), options);
}
BaseResolver.prototype.getDefaults = function () {
return {};
};
BaseResolver.prototype.getResults = function (limit, start, end) {
return this.results;
};
BaseResolver.prototype.search = function (q, cbk) {
cbk(this.getResults());
};
return BaseResolver;
}());
var AjaxResolver = (function (_super) {
__extends(AjaxResolver, _super);
function AjaxResolver(options) {
return _super.call(this, options) || this;
}
AjaxResolver.prototype.getDefaults = function () {
getDefaults() {
return {
url: '',
method: 'post',
@@ -43,42 +11,42 @@ var AjaxResolver = (function (_super) {
timeout: 0,
requestThrottling: 500
};
};
AjaxResolver.prototype.search = function (q, cbk) {
var _this = this;
if (this.jqXHR != null) {
this.jqXHR.abort();
}
}
search(q, cbk) {
if (this.jqXHR != null) this.jqXHR.abort();
var data = {};
data[this._settings.queryKey] = q;
if (this._settings.param.length > 0) $.extend(data, FoniaJS.RequestParam(this._settings.param));
if (this.requestTID) {
window.clearTimeout(this.requestTID);
if (this._settings.param.length > 0) {
$.extend(data, FoniaJS.RequestParam(this._settings.param));
}
this.requestTID = window.setTimeout(function () {
_this.jqXHR = $.ajax(_this._settings.url, {
method: _this._settings.method,
if (this.requestTID) window.clearTimeout(this.requestTID);
this.requestTID = window.setTimeout(() => {
this.jqXHR = $.ajax(this._settings.url, {
method: this._settings.method,
data: data,
timeout: _this._settings.timeout
timeout: this._settings.timeout
});
_this.jqXHR.done(function (result) {
//gnips: result in object
cbk((undefined !== result.autodata) ? result.autodata : result);
this.jqXHR.done(result => {
cbk(result.autodata !== undefined ? result.autodata : result);
});
_this.jqXHR.fail(function (err) {
var _a;
(_a = _this._settings) === null || _a === void 0 ? void 0 : _a.fail(err);
this.jqXHR.fail(err => {
this._settings.fail?.(err);
});
_this.jqXHR.always(function () {
_this.jqXHR = null;
this.jqXHR.always(() => {
this.jqXHR = null;
});
}, this._settings.requestThrottling);
};
return AjaxResolver;
}(BaseResolver));
}
};
var DropdownV5 = (function () {
function DropdownV5(e, formatItemCbk, autoSelect, noResultsText) {
var DropdownV5 = class {
constructor(e, formatItemCbk, autoSelect, noResultsText) {
this.initialized = false;
this.shown = false;
this.items = [];
@@ -88,195 +56,160 @@ var DropdownV5 = (function () {
this.autoSelect = autoSelect;
this.noResultsText = noResultsText;
}
DropdownV5.prototype.getElPos = function () {
var pos = $.extend({}, this._$el.position(), {
height: this._$el[0].offsetHeight
});
return pos;
};
DropdownV5.prototype.init = function () {
var _this = this;
getElPos() {
return $.extend({}, this._$el.position(), { height: this._$el[0].offsetHeight });
}
init() {
var pos = this.getElPos();
var fontsize = _this._$el.css('font-size');
this._dd = $('<div />');
this._dd.addClass('bootstrap-autocomplete dropdown-menu');
this._dd.insertAfter(this._$el);
this._dd.css({ top: pos.top + this._$el.outerHeight(), left: pos.left, width: this._$el.outerWidth(), 'font-size': fontsize });
this._dd.on('click', '.dropdown-item', function (evt) {
var fontsize = this._$el.css('font-size');
this._dd = $('<div />')
.addClass('bootstrap-autocomplete dropdown-menu')
.insertAfter(this._$el)
.css({
top: pos.top + this._$el.outerHeight(),
left: pos.left,
width: this._$el.outerWidth(),
'font-size': fontsize
});
this._dd.on('click', '.dropdown-item', evt => {
var item = $(evt.currentTarget).data('item');
_this.itemSelectedLaunchEvent(item);
this.itemSelectedLaunchEvent(item);
evt.preventDefault();
});
this._dd.on('keyup', function (evt) {
if (_this.shown) {
switch (evt.which) {
case 27:
_this.hide();
_this._$el.focus();
break;
}
this._dd.on('keyup', evt => {
if (this.shown && evt.which === 27) {
this.hide();
this._$el.focus();
return false;
}
});
this._dd.on('mouseenter', function (evt) {
_this.ddMouseover = true;
});
this._dd.on('mouseleave', function (evt) {
_this.ddMouseover = false;
});
this._dd.on('mouseenter', '.dropdown-item', function (evt) {
if (_this.haveResults) {
this._dd.on('mouseenter', () => { this.ddMouseover = true; });
this._dd.on('mouseleave', () => { this.ddMouseover = false; });
this._dd.on('mouseenter', '.dropdown-item', evt => {
if (this.haveResults) {
$(evt.currentTarget).closest('div').find('.dropdown-item.active').removeClass('active');
$(evt.currentTarget).addClass('active');
_this.mouseover = true;
this.mouseover = true;
}
});
this._dd.on('mouseleave', '.dropdown-item', function (evt) {
_this.mouseover = false;
});
this._dd.on('mouseleave', '.dropdown-item', () => { this.mouseover = false; });
this.initialized = true;
};
DropdownV5.prototype.checkInitialized = function () {
if (!this.initialized) {
this.init();
}
checkInitialized() {
if (!this.initialized) this.init();
}
get isMouseOver() { return this.mouseover; }
get isDdMouseOver() { return this.ddMouseover; }
get haveResults() { return this.items.length > 0; }
focusNextItem(reversed) {
if (!this.haveResults) return;
var currElem = this._dd.find('.dropdown-item.active');
var nextElem = reversed ? currElem.prev() : currElem.next();
if (nextElem.length === 0) {
nextElem = reversed ? this._dd.find('.dropdown-item').last() : this._dd.find('.dropdown-item').first();
}
};
Object.defineProperty(DropdownV5.prototype, "isMouseOver", {
get: function () {
return this.mouseover;
},
enumerable: false,
configurable: true
});
Object.defineProperty(DropdownV5.prototype, "isDdMouseOver", {
get: function () {
return this.ddMouseover;
},
enumerable: false,
configurable: true
});
Object.defineProperty(DropdownV5.prototype, "haveResults", {
get: function () {
return (this.items.length > 0);
},
enumerable: false,
configurable: true
});
DropdownV5.prototype.focusNextItem = function (reversed) {
if (this.haveResults) {
var currElem = this._dd.find('.dropdown-item.active');
var nextElem = reversed ? currElem.prev() : currElem.next();
if (nextElem.length === 0) {
nextElem = reversed ? this._dd.find('.dropdown-item').last() : this._dd.find('.dropdown-item').first();
}
currElem.removeClass('active');
nextElem.addClass('active');
this.scrollTo(nextElem);
}
};
DropdownV5.prototype.focusPreviousItem = function () {
this.focusNextItem(true);
};
DropdownV5.prototype.selectFocusItem = function () {
this._dd.find('.dropdown-item.active').trigger('click');
};
Object.defineProperty(DropdownV5.prototype, "isItemFocused", {
get: function () {
if (this._dd && this.isShown() && (this._dd.find('.dropdown-item.active').length > 0)) {
return true;
}
return false;
},
enumerable: false,
configurable: true
});
DropdownV5.prototype.show = function () {
currElem.removeClass('active');
nextElem.addClass('active');
this.scrollTo(nextElem);
}
focusPreviousItem() { this.focusNextItem(true); }
selectFocusItem() { this._dd.find('.dropdown-item.active').trigger('click'); }
get isItemFocused() {
return !!(this._dd && this.isShown() && this._dd.find('.dropdown-item.active').length > 0);
}
show() {
if (!this.shown) {
this._dd.addClass('show');
this.shown = true;
this._$el.trigger('autocomplete.dd.shown');
}
};
DropdownV5.prototype.isShown = function () {
return this.shown;
};
DropdownV5.prototype.hide = function () {
}
isShown() { return this.shown; }
hide() {
if (this.shown) {
this._dd.removeClass('show');
this.shown = false;
this._$el.trigger('autocomplete.dd.hidden');
}
};
DropdownV5.prototype.updateItems = function (items, searchText) {
}
updateItems(items, searchText) {
this.items = items;
this.searchText = searchText;
this.refreshItemList();
};
DropdownV5.prototype.showMatchedText = function (text, qry) {
}
showMatchedText(text, qry) {
var startIndex = text.toLowerCase().indexOf(qry.toLowerCase());
if (startIndex > -1) {
var endIndex = startIndex + qry.length;
return text.slice(0, startIndex) + '<b>'
+ text.slice(startIndex, endIndex) + '</b>'
+ text.slice(endIndex);
return text.slice(0, startIndex) + '<b>' + text.slice(startIndex, endIndex) + '</b>' + text.slice(endIndex);
}
return text;
};
DropdownV5.prototype.refreshItemList = function () {
var _this = this;
}
refreshItemList() {
this.checkInitialized();
this._dd.empty();
var liList = [];
if (this.items.length > 0) {
this.items.forEach(function (item) {
var itemFormatted = _this.formatItem(item);
if (typeof itemFormatted === 'string') {
itemFormatted = { text: itemFormatted };
}
var itemText;
var itemHtml;
itemText = _this.showMatchedText(itemFormatted.text, _this.searchText);
if (itemFormatted.html !== undefined) {
itemHtml = itemFormatted.html;
} else {
itemHtml = itemText;
}
var disabledItem = itemFormatted.disabled;
var li = $('<a >');
li.addClass('dropdown-item')
//css bisa dimasukkan ke style default + cursor select
//.css({ 'overflow': 'hidden', 'text-overflow': 'ellipsis' })
this.items.forEach(item => {
var itemFormatted = this.formatItem(item);
if (typeof itemFormatted === 'string') itemFormatted = { text: itemFormatted };
var itemText = this.showMatchedText(itemFormatted.text, this.searchText);
var itemHtml = itemFormatted.html !== undefined ? itemFormatted.html : itemText;
var li = $('<a />')
.addClass('dropdown-item')
.html(itemHtml)
.data('item', item);
if (disabledItem) {
li.addClass('disabled');
}
if (itemFormatted.disabled) li.addClass('disabled');
liList.push(li);
});
this._dd.append(liList);
this.show();
} else if (this.noResultsText !== '') {
var li = $('<a />').addClass('dropdown-item disabled').html(this.noResultsText);
liList.push(li);
this._dd.append(liList);
this.show();
} else {
this.hide();
}
else {
if (this.noResultsText === '') {
this.hide();
}
else {
var li = $('<a >');
li.addClass('dropdown-item disabled')
.html(this.noResultsText);
liList.push(li);
this._dd.append(liList);
this.show();
}
}
};
DropdownV5.prototype.itemSelectedLaunchEvent = function (item) {
}
itemSelectedLaunchEvent(item) {
this._$el.trigger('autocomplete.select', item);
};
DropdownV5.prototype.scrollTo = function (el) {
var _he = this._dd.height(), _to = this._dd.scrollTop(), _ito = el.position().top, _ihe = el.outerHeight(),
}
scrollTo(el) {
var _he = this._dd.height(),
_to = this._dd.scrollTop(),
_ito = el.position().top,
_ihe = el.outerHeight(),
_nto = _to, _wra = false;
if (_ito < 0){
if (_ito < 0) {
_wra = el.is(':first-child');
_nto = _wra ? 0 : _to - _he / 2;
} else if (_ito > _he - _ihe) {
@@ -284,12 +217,11 @@ var DropdownV5 = (function () {
_nto = _wra ? (_ito + _ihe - _he) : _to + _he / 2;
}
this._dd.scrollTop(_nto);
};
return DropdownV5;
}());
}
};
var AutoComplete = (function () {
function AutoComplete(element, options) {
var AutoComplete = class {
constructor(element, options) {
this._selectedItem = null;
this._defaultValue = null;
this._defaultText = null;
@@ -302,235 +234,189 @@ var AutoComplete = (function () {
autoSelect: true,
noResultsText: 'Pencarian Tidak Ketemu',
preventEnter: false,
events: {
typed: null,
searchPre: null,
search: null,
searchPost: null,
select: null,
focus: null,
},
//gnips: adding callback, keyfunc and breakvalue
selectFunc: function(){},
keyFunc: function(){},
events: { typed: null, searchPre: null, search: null, searchPost: null, select: null, focus: null },
selectFunc: () => {},
keyFunc: () => {},
breakFocus: false,
breakValue: []
};
this._el = element;
this._$el = $(this._el);
this.manageInlineDataAttributes();
if (typeof options === 'object') {
this._settings = $.extend(true, {}, this.getSettings(), options);
}
this.init();
}
AutoComplete.prototype.manageInlineDataAttributes = function () {
manageInlineDataAttributes() {
var s = this.getSettings();
if (this._$el.data('url')) {
s.resolverSettings.url = this._$el.data('url');
}
if (this._$el.data('default-value')) {
this._defaultValue = this._$el.data('default-value');
}
if (this._$el.data('default-text')) {
this._defaultText = this._$el.data('default-text');
}
if (this._$el.data('noresults-text') !== undefined) {
s.noResultsText = this._$el.data('noresults-text');
}
};
AutoComplete.prototype.getSettings = function () {
return this._settings;
};
AutoComplete.prototype.init = function () {
if (this._$el.data('url')) s.resolverSettings.url = this._$el.data('url');
if (this._$el.data('default-value')) this._defaultValue = this._$el.data('default-value');
if (this._$el.data('default-text')) this._defaultText = this._$el.data('default-text');
if (this._$el.data('noresults-text') !== undefined) s.noResultsText = this._$el.data('noresults-text');
}
getSettings() { return this._settings; }
init() {
this.bindDefaultEventListeners();
if (this._settings.resolver === 'ajax') {
this.resolver = new AjaxResolver(this._settings.resolverSettings);
}
this._dd = new DropdownV5(this._$el, this._settings.formatResult, this._settings.autoSelect, this._settings.noResultsText);
};
AutoComplete.prototype.bindDefaultEventListeners = function () {
var _this = this;
this._$el.on('keydown', function (evt) {
//gnips: check breakValue and call keydown function
(('' == _this._$el.val() || ((_this._settings.breakValue.length > 0) && (_this._settings.breakValue.indexOf(_this._$el.val()) != -1))) && _this._settings.keyFunc(evt.which, _this._$el.val()));
}
bindDefaultEventListeners() {
this._$el.on('keydown', evt => {
var val = this._$el.val();
if ((val === '' || (this._settings.breakValue.length > 0 && this._settings.breakValue.indexOf(val) !== -1))) {
this._settings.keyFunc(evt.which, val);
}
switch (evt.which) {
case 9:
if (_this._dd.isItemFocused) {
_this._dd.selectFocusItem();
if (!this._settings.breakFocus) {
if (this._dd.isItemFocused) this._dd.selectFocusItem();
this._dd.hide();
}
_this._dd.hide();
break;
case 13:
if (_this._dd.isItemFocused) {
_this._dd.selectFocusItem();
}
_this._dd.hide();
if (_this._settings.preventEnter) {
evt.preventDefault();
}
if (this._dd.isItemFocused) this._dd.selectFocusItem();
this._dd.hide();
if (this._settings.preventEnter) evt.preventDefault();
break;
case 40:
_this._dd.focusNextItem();
this._dd.focusNextItem();
break;
case 38:
_this._dd.focusPreviousItem();
this._dd.focusPreviousItem();
break;
}
});
this._$el.on('keyup', function (evt) {
this._$el.on('keyup', evt => {
switch (evt.which) {
case 16:
case 17:
case 18:
case 39:
case 37:
case 36:
case 35:
case 16: case 17: case 18: case 39: case 37: case 36: case 35: case 40: case 38:
break;
case 13:
_this._dd.hide();
break;
case 27:
_this._dd.hide();
break;
case 40:
break;
case 38:
case 13: case 27:
this._dd.hide();
break;
default:
_this._selectedItem = null;
var newValue = _this._$el.val();
_this.handlerTyped(newValue);
this._selectedItem = null;
this.handlerTyped(this._$el.val());
}
});
this._$el.on('blur', function (evt) {
if (!_this._dd.isMouseOver && _this._dd.isDdMouseOver && _this._dd.isShown()) {
setTimeout(function () { _this._$el.focus(); });
_this._$el.focus();
}
else if (!_this._dd.isMouseOver) {
_this._dd.hide();
this._$el.on('blur', () => {
if (this._settings.breakFocus) return;
if (!this._dd.isMouseOver && this._dd.isDdMouseOver && this._dd.isShown()) {
setTimeout(() => { this._$el.focus(); });
this._$el.focus();
} else if (!this._dd.isMouseOver) {
this._dd.hide();
}
});
this._$el.on('autocomplete.select', function (evt, item) {
_this._selectedItem = item;
_this.itemSelectedDefaultHandler(item);
this._$el.on('autocomplete.select', (evt, item) => {
this._selectedItem = item;
this.itemSelectedDefaultHandler(item);
});
this._$el.on('paste', function (evt) {
setTimeout(function () {
_this._$el.trigger('keyup', evt);
}, 0);
this._$el.on('paste', evt => {
setTimeout(() => { this._$el.trigger('keyup', evt); }, 0);
});
};
AutoComplete.prototype.handlerTyped = function (newValue) {
}
handlerTyped(newValue) {
if (this._settings.events.typed !== null) {
newValue = this._settings.events.typed(newValue, this._$el);
if (!newValue) {
return;
}
if (!newValue) return;
}
if (newValue.length >= this._settings.minLength) {
this._searchText = newValue;
this.handlerPreSearch();
}
else {
} else {
this._dd.hide();
}
};
AutoComplete.prototype.handlerPreSearch = function () {
}
handlerPreSearch() {
if (this._settings.events.searchPre !== null) {
var newValue = this._settings.events.searchPre(this._searchText, this._$el);
if (!newValue)
return;
if (!newValue) return;
this._searchText = newValue;
}
this.handlerDoSearch();
};
AutoComplete.prototype.handlerDoSearch = function () {
var _this = this;
}
handlerDoSearch() {
if (this._settings.events.search !== null) {
this._settings.events.search(this._searchText, function (results) {
_this.postSearchCallback(results);
this._settings.events.search(this._searchText, results => {
this.postSearchCallback(results);
}, this._$el);
} else if (this.resolver) {
this.resolver.search(this._searchText, results => {
this.postSearchCallback(results);
});
}
else {
if (this.resolver) {
this.resolver.search(this._searchText, function (results) {
_this.postSearchCallback(results);
});
}
}
};
AutoComplete.prototype.postSearchCallback = function (results) {
}
postSearchCallback(results) {
if (this._settings.events.searchPost) {
results = this._settings.events.searchPost(results, this._$el);
if ((typeof results === 'boolean') && !results)
return;
if (typeof results === 'boolean' && !results) return;
}
this.handlerStartShow(results);
};
AutoComplete.prototype.handlerStartShow = function (results) {
//gnips: adding auto select when barcode result of 1 item only
if (1 == results.length && 1 == (void 0 !== results[0].bc ? results[0].bc : 0)) {
this._$el.trigger('autocomplete.select', results[0]),
}
handlerStartShow(results) {
var bcVal = results[0]?.bc ?? 0;
if (results.length === 1 && bcVal === 1) {
this._$el.trigger('autocomplete.select', results[0]);
this._dd.hide();
} else this._dd.updateItems(results, this._searchText);
};
AutoComplete.prototype.itemSelectedDefaultHandler = function (item) {
} else {
this._dd.updateItems(results, this._searchText);
}
}
itemSelectedDefaultHandler(item) {
if (item != null) {
var itemFormatted = this._settings.formatResult(item);
if (typeof itemFormatted === 'string') {
itemFormatted = { text: itemFormatted };
}
if (typeof itemFormatted === 'string') itemFormatted = { text: itemFormatted };
this._$el.val(itemFormatted.text);
}
else {
} else {
this._$el.val('');
}
this._selectedItem = item;
//gnips: callback with selected item
this._settings.selectFunc(item);
this._dd.hide();
};
AutoComplete.prototype.defaultFormatResult = function (item) {
if (typeof item === 'string') {
return { text: item };
}
else if (item.text) {
return item;
}
else {
return { text: item.toString() };
}
};
AutoComplete.prototype.manageAPI = function (APICmd, params) {
if (APICmd === 'set') {
this.itemSelectedDefaultHandler(params);
}
else if (APICmd === 'clear') {
this.itemSelectedDefaultHandler(null);
}
else if (APICmd === 'show') {
this._$el.trigger('keyup');
}
else if (APICmd === 'updateResolver') {
this.resolver = new AjaxResolver(params);
}
};
AutoComplete.NAME = 'autoComplete';
return AutoComplete;
}());
}
(function ($, window, document) {
$.fn[AutoComplete.NAME] = function (optionsOrAPI, optionalParams) {
return this.each(function () {
var pluginClass;
pluginClass = $(this).data(AutoComplete.NAME);
if (!pluginClass) {
pluginClass = new AutoComplete(this, optionsOrAPI);
$(this).data(AutoComplete.NAME, pluginClass);
}
pluginClass.manageAPI(optionsOrAPI, optionalParams);
});
};
})(jQuery, window, document);
defaultFormatResult(item) {
if (typeof item === 'string') return { text: item };
if (item.text) return item;
return { text: item.toString() };
}
manageAPI(APICmd, params) {
if (APICmd === 'set') this.itemSelectedDefaultHandler(params);
else if (APICmd === 'clear') this.itemSelectedDefaultHandler(null);
else if (APICmd === 'show') this._$el.trigger('keyup');
else if (APICmd === 'updateResolver') this.resolver = new AjaxResolver(params);
}
};
AutoComplete.NAME = 'autoComplete';
// jQuery plugin wrapper
$.fn[AutoComplete.NAME] = function (optionsOrAPI, optionalParams) {
return this.each(function () {
var pluginClass = $(this).data(AutoComplete.NAME);
if (!pluginClass) {
pluginClass = new AutoComplete(this, optionsOrAPI);
$(this).data(AutoComplete.NAME, pluginClass);
}
pluginClass.manageAPI(optionsOrAPI, optionalParams);
});
};
+665 -750
View File
File diff suppressed because it is too large Load Diff
+63 -67
View File
@@ -4,90 +4,86 @@
Desc. : JS Class Tampil Data di Pole Display POS
Created By : Siau Pheng ([email protected]).
Created Date : October 12th, 2025.
Last Modified : November 1st, 2026.
(c) 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
var PoleDisplay = function(port, options){
var _cd_port = '';
var _cd_pole = '';
var _options = {
rx: { start: '\x02', end: '\x0D', width: null },
baudRate: 9600,
dataBits: 8,
stopBits: 1,
parity: 'NONE',
flowControl: 'NONE'
};
class PoleDisplay {
constructor(port, options = {}) {
this.port = port;
this.pole = '';
this.options = Object.assign({
rx: { start: '\x02', end: '\x0D', width: null },
baudRate: 9600,
dataBits: 8,
stopBits: 1,
parity: 'NONE',
flowControl: 'NONE'
}, options);
}
this.construct = function (port, options){
$.extend(_options, options);
_cd_port = port;
};
Open() {
if (this.pole) return;
this.Open = function (){
if (_cd_pole === '') {
qz.serial.openPort(_cd_port, _options).then(() => {
_cd_pole = _cd_port;
this.cd_Error(_cd_port+' opened');
}).then(() => {
qz.serial.sendData(_cd_pole, {type:'HEX',data:'x1Bx40'}, _options).catch(this.cd_Error);
}).catch(this.cd_Error);
}
};
qz.serial.openPort(this.port, this.options)
.then(() => {
this.pole = this.port;
this.cd_Error(`${this.port} opened`);
return qz.serial.sendData(this.pole, { type: 'HEX', data: 'x1Bx40' }, this.options);
})
.catch(this.cd_Error);
}
this.Close = function (){
qz.serial.closePort(_cd_port).then(() => {
_cd_pole = '';
this.cd_Error(_cd_port+' closed');
}).catch(this.cd_Error);
};
Close() {
if (!this.pole) return;
this.Send = function (txt){
if (_cd_pole === '') return false;
var ascii_to_hexa = function(str) {
var arr1 = [];
for (var n = 0, l = str.length; n < l; n++) {
var hex = Number(str.charCodeAt(n)).toString(16);
if (hex.length==1) hex = '0' + hex;
arr1.push(hex.toUpperCase());
}
return 'x' + arr1.join('x');
};
var _txt = txt;
qz.serial.closePort(this.port)
.then(() => {
this.pole = '';
this.cd_Error(`${this.port} closed`);
})
.catch(this.cd_Error);
}
Send(txt) {
if (!this.pole) return false;
// Convert string to ASCII hex format
const asciiToHex = str =>
Array.from(str, char => char.charCodeAt(0).toString(16).padStart(2, '0').toUpperCase())
.join('x');
let textToSend = txt;
if (Array.isArray(txt)) {
_txt = '';
txt.forEach((ele) => {
_txt += this.cd_Text(ele['t'], ele['a']);
});
textToSend = txt.map(ele => this.cd_Text(ele.t, ele.a)).join('');
}
qz.serial.sendData(_cd_pole, {type:'HEX',data:'x10C'+ascii_to_hexa(_txt)}, _options).catch(this.cd_Error);
};
this.cd_Text = function (text, align){
const hexData = `x10C${asciiToHex(textToSend)}`;
qz.serial.sendData(this.pole, { type: 'HEX', data: hexData }, this.options)
.catch(this.cd_Error);
}
cd_Text(text, align = 'L') {
const totWidth = 20;
const txtLength = text.length;
if (txtLength >= totWidth) {
return text.substring(0, totWidth);
}
const padding = totWidth - txtLength;
var lPadding = 0;
var rPadding = padding;
if (align === null) align = 'L';
if (align == 'C'){
if (text.length >= totWidth) return text.substring(0, totWidth);
const padding = totWidth - text.length;
let lPadding = 0, rPadding = padding;
if (align === 'C') {
lPadding = Math.floor(padding / 2);
rPadding = Math.ceil(padding / 2);
} else if (align == 'R'){
} else if (align === 'R') {
lPadding = padding;
rPadding = 0;
}
return " ".repeat(lPadding) + text + " ".repeat(rPadding);
};
this.cd_Error = function (err){
return ' '.repeat(lPadding) + text + ' '.repeat(rPadding);
}
cd_Error(err) {
console.error(err);
};
this.construct(port, options);
};
}
}
+3 -3
View File
@@ -5,7 +5,7 @@
Module : /App/Auth.php
Created By : Siau Pheng ([email protected]).
Created Date : March 16th, 2008.
Last Modified : October 21st, 2026.
Last Modified : October 31st, 2026.
(c) 3FONIA Software; WWW.3FONIA.COM.
@@ -86,8 +86,8 @@ final class Auth {
public function user_log(): void {
$_user_id = $this->session->get('WEB_USER')['UserID'] ?? 0;
if ($_user_id === 0) return;
$a_hasil = $this->db->fetchRow('SELECT * FROM app_logs WHERE UserID=? ORDER BY Last_Date DESC LIMIT 1', [$_user_id])->getData();
if (count($a_hasil) > 0) {
$a_hasil = $this->db->fetchRow('SELECT * FROM app_logs WHERE UserID=? ORDER BY Last_Date DESC LIMIT 1', [$_user_id]);
if ($a_hasil) {
$this->db->update('app_operator', [ 'Last_IP' => $a_hasil['Last_IP'], 'Last_Date' => $a_hasil['Last_Date'] ], 'UserID=?', [$_user_id]);
}
$this->db->runQuery('INSERT IGNORE INTO app_logs SELECT UserID,Token,IP,DateStamp FROM app_token WHERE Token=?', [$this->session->get('APP_TOKEN')]);