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