sync
This commit is contained in:
File diff suppressed because one or more lines are too long
@ -1,43 +1,12 @@
|
||||
import { Dropdown, Grid, Popup, createCheckbox, createElement, createIcon } from "../ui";
|
||||
import { r as lang } from "../utility";
|
||||
import { Dropdown, Grid, OptionBase, createCheckbox, createElement, createIcon } from "../ui";
|
||||
|
||||
let r = lang;
|
||||
|
||||
export default class AssetSelector {
|
||||
export default class AssetSelector extends OptionBase {
|
||||
_var = {
|
||||
option: {
|
||||
assetFullcontrol: false,
|
||||
/**
|
||||
* @private
|
||||
* @type {(hidden: boolean, search?: string, groups?: string[], jobsites?: number[], codes?: string[]) => Promise<any[]>}
|
||||
*/
|
||||
requestAssets: null,
|
||||
/**
|
||||
* @private
|
||||
* @type {() => Promise<any>}
|
||||
*/
|
||||
requestAddAsset: null,
|
||||
/**
|
||||
* @private
|
||||
* @type {() => Promise<{AssetGroups: any[], Codes: any[], Jobsites: any[]}>}
|
||||
*/
|
||||
requestAssetParams: null,
|
||||
dataSource: {
|
||||
AssetGroups: [],
|
||||
Codes: [],
|
||||
Jobsites: []
|
||||
}
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @type {HTMLElement}
|
||||
*/
|
||||
container: null,
|
||||
/**
|
||||
* @private
|
||||
* @type {Popup}
|
||||
*/
|
||||
popup: null,
|
||||
el: {
|
||||
/**
|
||||
* @private
|
||||
@ -74,24 +43,60 @@ export default class AssetSelector {
|
||||
|
||||
onSelected;
|
||||
|
||||
constructor(opt) {
|
||||
opt ??= {};
|
||||
this._var.option = opt;
|
||||
const getText = opt.getText;
|
||||
if (typeof getText === 'function') {
|
||||
r = getText;
|
||||
} else if (typeof GetTextByKey === 'function') {
|
||||
r = GetTextByKey;
|
||||
constructor(opt = {
|
||||
assetFullcontrol: false,
|
||||
ignoreHidden: false,
|
||||
/**
|
||||
* @private
|
||||
* @type {(flag: boolean) => void}
|
||||
*/
|
||||
loading: null,
|
||||
/**
|
||||
* @private
|
||||
* @type {() => void}
|
||||
*/
|
||||
close: null,
|
||||
/**
|
||||
* @private
|
||||
* @type {(hidden: boolean, search?: string, groups?: string[], jobsites?: number[], codes?: string[]) => Promise<any[]>}
|
||||
*/
|
||||
requestAssets: null,
|
||||
/**
|
||||
* @private
|
||||
* @type {() => Promise<any>}
|
||||
*/
|
||||
requestAddAsset: null,
|
||||
/**
|
||||
* @private
|
||||
* @type {() => Promise<{AssetGroups: any[], Codes: any[], Jobsites: any[]}>}
|
||||
*/
|
||||
requestAssetParams: null,
|
||||
dataSource: {
|
||||
AssetGroups: [],
|
||||
Codes: [],
|
||||
Jobsites: []
|
||||
}
|
||||
}) {
|
||||
super(opt);
|
||||
}
|
||||
|
||||
get title() { return this.r('P_MA_SELECTASSET', 'Select Asset') }
|
||||
|
||||
get currentAsset() { return this._var.el.grid.currentItem }
|
||||
|
||||
loading(flag) {
|
||||
if (typeof this._option.loading === 'function') {
|
||||
this._option.loading(flag);
|
||||
}
|
||||
}
|
||||
|
||||
refresh() {
|
||||
const requestAssets = this._var.option.requestAssets;
|
||||
const requestAssets = this._option.requestAssets;
|
||||
if (typeof requestAssets !== 'function') {
|
||||
return;
|
||||
}
|
||||
const el = this._var.el;
|
||||
this._var.popup.loading = true;
|
||||
this.loading(true);
|
||||
requestAssets(
|
||||
el.checkHidden.querySelector('input[type="checkbox"]')?.checked,
|
||||
el.inputSearch.value,
|
||||
@ -100,23 +105,28 @@ export default class AssetSelector {
|
||||
el.dropJobsiteCode.selected?.value
|
||||
).then(data => {
|
||||
el.grid.source = data;
|
||||
}).finally(() => this._var.popup.loading = false);
|
||||
}).finally(() => this.loading(false));
|
||||
}
|
||||
|
||||
select(item) {
|
||||
if (typeof this.onSelected !== 'function') {
|
||||
return false;
|
||||
}
|
||||
if (item == null) {
|
||||
item = this._var.el.grid.currentItem;
|
||||
}
|
||||
if (item == null) {
|
||||
return false;
|
||||
}
|
||||
this.onSelected(item);
|
||||
}
|
||||
|
||||
async create() {
|
||||
const option = this._var.option;
|
||||
const title = r('P_MA_SELECTASSET', 'Select Asset');
|
||||
create() {
|
||||
const option = this._option;
|
||||
const tabIndex = Math.max.apply(null, [...document.querySelectorAll('[tabindex]')].map(e => e.tabIndex ?? 0)) + 3;
|
||||
const inputSearch = createElement('input', input => {
|
||||
input.type = 'text';
|
||||
input.placeholder = r('P_SELECTASSETS_SEARCH', 'Search');
|
||||
input.placeholder = this.r('P_SELECTASSETS_SEARCH', 'Search');
|
||||
input.tabIndex = tabIndex + 2;
|
||||
input.className = 'ui-input';
|
||||
input.addEventListener('keypress', e => {
|
||||
@ -127,9 +137,12 @@ export default class AssetSelector {
|
||||
});
|
||||
const checkHidden = createCheckbox({
|
||||
tabIndex: tabIndex + 3,
|
||||
label: r('P_SELECTASSETS_SHOWHIDDEN', 'Show Hidden'),
|
||||
label: this.r('P_SELECTASSETS_SHOWHIDDEN', 'Show Hidden'),
|
||||
onchange: () => this.refresh()
|
||||
});
|
||||
if (option.ignoreHidden) {
|
||||
checkHidden.style.display = 'none';
|
||||
}
|
||||
const dropAssetGroup = new Dropdown({
|
||||
tabIndex: tabIndex + 4,
|
||||
search: true,
|
||||
@ -153,21 +166,23 @@ export default class AssetSelector {
|
||||
div.className = 'popup-selector-content';
|
||||
div.style.height = '400px';
|
||||
});
|
||||
const grid = new Grid(gridContent, r);
|
||||
const grid = new Grid(gridContent, this.r);
|
||||
grid.columns = [
|
||||
{ key: 'VIN', caption: r('P_SELECTASSETS_VIN', 'VIN'), width: 170 },
|
||||
{ key: 'DisplayName', caption: r('P_SELECTASSETS_NAME', 'Name'), width: 190 },
|
||||
{ key: 'MakeName', caption: r('P_SELECTASSETS_MAKE', 'Make'), width: 110, allowFilter: true },
|
||||
{ key: 'ModelName', caption: r('P_SELECTASSETS_MODEL', 'Model'), width: 110, allowFilter: true },
|
||||
{ key: 'TypeName', caption: r('P_SELECTASSETS_TYPE', 'Type'), width: 110, allowFilter: true },
|
||||
{ key: 'AcquisitionType', caption: r('P_MA_ACQUISITIONTYPE', 'Acquisition Type'), width: 130, allowFilter: true },
|
||||
{ key: 'AssetGroups', caption: r('P_MA_ASSETGROUP', 'Asset Group'), width: 150 },
|
||||
{ key: 'Jobsites', caption: r('P_SELECTASSETS_JOBSITE', 'Jobsite'), width: 180, filter: it => it.Jobsites?.map(s => s.Key) }
|
||||
{ key: 'VIN', caption: this.r('P_SELECTASSETS_VIN', 'VIN'), width: 170 },
|
||||
{ key: 'DisplayName', caption: this.r('P_SELECTASSETS_NAME', 'Name'), width: 190 },
|
||||
{ key: 'MakeName', caption: this.r('P_SELECTASSETS_MAKE', 'Make'), width: 110, allowFilter: true },
|
||||
{ key: 'ModelName', caption: this.r('P_SELECTASSETS_MODEL', 'Model'), width: 110, allowFilter: true },
|
||||
{ key: 'TypeName', caption: this.r('P_SELECTASSETS_TYPE', 'Type'), width: 110, allowFilter: true },
|
||||
{ key: 'AcquisitionType', caption: this.r('P_MA_ACQUISITIONTYPE', 'Acquisition Type'), width: 130, allowFilter: true },
|
||||
{ key: 'AssetGroups', caption: this.r('P_MA_ASSETGROUP', 'Asset Group'), width: 150 },
|
||||
{ key: 'Jobsites', caption: this.r('P_SELECTASSETS_JOBSITE', 'Jobsite'), width: 180, filter: it => it.Jobsites?.map(s => s.Key) }
|
||||
];
|
||||
grid.onRowDblClicked = index => {
|
||||
const item = grid.source[index];
|
||||
this.select(item);
|
||||
this._var.popup.close();
|
||||
if (typeof this._option.close === 'function') {
|
||||
this._option.close();
|
||||
}
|
||||
};
|
||||
grid.init();
|
||||
grid.element.tabIndex = tabIndex + 7;
|
||||
@ -183,19 +198,21 @@ export default class AssetSelector {
|
||||
const container = createElement('div', 'popup-selector',
|
||||
createElement('div', 'popup-selector-header',
|
||||
createElement('img', img => img.src = '../img/modules/devices.png'),
|
||||
createElement('h3', h3 => h3.innerText = title),
|
||||
createElement('h3', h3 => h3.innerText = this.title),
|
||||
option.assetFullcontrol ? createElement('button', button => {
|
||||
button.className = 'ui-popup-button';
|
||||
button.tabIndex = tabIndex + 1;
|
||||
button.innerText = r('P_MA_ADDASSET', 'Add Asset');
|
||||
button.innerText = this.r('P_MA_ADDASSET', 'Add Asset');
|
||||
button.addEventListener('click', async () => {
|
||||
if (typeof option.requestAddAsset === 'function') {
|
||||
this._var.popup.loading = true;
|
||||
this.loading(true);
|
||||
const asset = await option.requestAddAsset();
|
||||
this._var.popup.loading = false;
|
||||
this.loading(false);
|
||||
if (asset != null) {
|
||||
this.select(asset);
|
||||
this._var.popup.close();
|
||||
if (typeof this._option.close === 'function') {
|
||||
this._option.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -211,59 +228,33 @@ export default class AssetSelector {
|
||||
)
|
||||
),
|
||||
checkHidden,
|
||||
createElement('span', span => span.innerText = r('P_WO_ASSETGROUP', 'Asset Group')),
|
||||
createElement('span', span => span.innerText = this.r('P_WO_ASSETGROUP', 'Asset Group')),
|
||||
dropAssetGroup.create(),
|
||||
createElement('span', span => span.innerText = r('P_WO_JOBSITE', 'Jobsite')),
|
||||
createElement('span', span => span.innerText = this.r('P_WO_JOBSITE', 'Jobsite')),
|
||||
dropJobsite.create(),
|
||||
createElement('span', span => span.innerText = r('P_SELECTASSETS_JOBSITECODE', 'Jobsite Code')),
|
||||
createElement('span', span => span.innerText = this.r('P_SELECTASSETS_JOBSITECODE', 'Jobsite Code')),
|
||||
dropJobsiteCode.create()
|
||||
),
|
||||
gridContent
|
||||
);
|
||||
this._var.container = container;
|
||||
const popup = new Popup({
|
||||
title,
|
||||
content: container,
|
||||
persistent: true,
|
||||
buttons: [
|
||||
{
|
||||
key: 'ok',
|
||||
text: r('P_GRID_OK', 'OK'),
|
||||
trigger: () => {
|
||||
const item = grid.source[grid.selectedIndex];
|
||||
if (item == null) {
|
||||
return false;
|
||||
}
|
||||
this.select(item);
|
||||
}
|
||||
},
|
||||
{ text: r('P_WO_CANCEL', 'Cancel') }
|
||||
]
|
||||
});
|
||||
this._var.popup = popup;
|
||||
popup.create();
|
||||
popup.rect = { width: 1220 };
|
||||
const mask = await popup.show();
|
||||
return container;
|
||||
}
|
||||
|
||||
async init() {
|
||||
const option = this._option;
|
||||
if (option.dataSource == null) {
|
||||
if (typeof option.requestAssetParams === 'function') {
|
||||
popup.loading = true;
|
||||
this.loading(true);
|
||||
const data = await option.requestAssetParams();
|
||||
option.dataSource = data;
|
||||
} else {
|
||||
option.dataSource = { AssetGroups: [], Jobsites: [], Codes: [] };
|
||||
}
|
||||
}
|
||||
dropAssetGroup.source = [{ Key: '-1', Value: '' }, ...option.dataSource.AssetGroups];
|
||||
dropJobsite.source = [{ ID: '-1', Name: '' }, ...option.dataSource.Jobsites];
|
||||
dropJobsiteCode.source = [{ value: '-1', text: '' }, ...option.dataSource.Codes.map(c => ({ value: c, text: c }))];
|
||||
this._var.el.dropAssetGroup.source = [{ Key: '-1', Value: '' }, ...option.dataSource.AssetGroups];
|
||||
this._var.el.dropJobsite.source = [{ ID: '-1', Name: '' }, ...option.dataSource.Jobsites];
|
||||
this._var.el.dropJobsiteCode.source = [{ value: '-1', text: '' }, ...option.dataSource.Codes.map(c => ({ value: c, text: c }))];
|
||||
this.refresh();
|
||||
return mask;
|
||||
}
|
||||
|
||||
show() {
|
||||
if (this._var.popup == null) {
|
||||
return this.create();
|
||||
}
|
||||
return this._var.popup.show();
|
||||
}
|
||||
}
|
169
lib/element/inspectionWizard.js
Normal file
169
lib/element/inspectionWizard.js
Normal file
@ -0,0 +1,169 @@
|
||||
import { OptionBase, Popup, createElement, showAlert } from "../ui";
|
||||
import AssetSelector from "./assetselector";
|
||||
import TemplateSelector from "./templateselector";
|
||||
|
||||
export default class InspectionWizard extends OptionBase {
|
||||
_var = {
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
index: 0,
|
||||
/**
|
||||
* @private
|
||||
* @type {HTMLElement[]}
|
||||
*/
|
||||
containers: [],
|
||||
/**
|
||||
* @private
|
||||
* @type {AssetSelector}
|
||||
*/
|
||||
assetSelector: null,
|
||||
asset: null,
|
||||
template: null,
|
||||
/**
|
||||
* @private
|
||||
* @type {Popup}
|
||||
*/
|
||||
popup: null
|
||||
};
|
||||
|
||||
/**
|
||||
* @event
|
||||
* @type {(this: InspectionWizard, asset: any, template: any) => void}
|
||||
*/
|
||||
onSelected;
|
||||
|
||||
constructor(opt = {
|
||||
/**
|
||||
* @private
|
||||
* @type {(assetId: number, search: string) => Promise<any[]>}
|
||||
*/
|
||||
requestTemplates: null,
|
||||
/**
|
||||
* @private
|
||||
* @type {(hidden: boolean, search?: string, groups?: string[], jobsites?: number[], codes?: string[]) => Promise<any[]>}
|
||||
*/
|
||||
requestAssets: null,
|
||||
/**
|
||||
* @private
|
||||
* @type {() => Promise<{AssetGroups: any[], Codes: any[], Jobsites: any[]}>}
|
||||
*/
|
||||
requestAssetParams: null
|
||||
}) {
|
||||
super(opt);
|
||||
}
|
||||
|
||||
async create() {
|
||||
const option = this._option;
|
||||
const loading = flag => this._var.popup.loading = flag;
|
||||
const assetSelector = new AssetSelector({
|
||||
ignoreHidden: true,
|
||||
loading,
|
||||
requestAssets: option.requestAssets,
|
||||
requestAssetParams: option.requestAssetParams
|
||||
});
|
||||
this._var.assetSelector = assetSelector;
|
||||
const templateSelector = new TemplateSelector({
|
||||
loading,
|
||||
requestTemplates: option.requestTemplates
|
||||
});
|
||||
assetSelector.onSelected = asset => {
|
||||
this._var.asset = asset;
|
||||
this._var.template = null;
|
||||
this._changePage(1);
|
||||
templateSelector.assetId = asset.Id;
|
||||
};
|
||||
templateSelector.onSelected = template => {
|
||||
this._var.template = template;
|
||||
this._select();
|
||||
this._var.popup.close();
|
||||
}
|
||||
this._var.containers = [
|
||||
assetSelector.create(),
|
||||
templateSelector.create()
|
||||
];
|
||||
const popup = new Popup({
|
||||
title: this.r('ADDINSPECTION', 'Add Inspection'),
|
||||
content: createElement('div', null, ...this._var.containers),
|
||||
persistent: true,
|
||||
buttons: [
|
||||
{
|
||||
text: this.r('BACK', 'Back'),
|
||||
trigger: () => {
|
||||
this._changePage(0);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
{
|
||||
text: this.r('NEXT', 'Next'),
|
||||
trigger: () => {
|
||||
const asset = assetSelector.currentAsset;
|
||||
if (asset == null) {
|
||||
showAlert(assetSelector.title, this.r('P_SELECTASSETS_SELECTASSET', 'Please select an Asset.'));
|
||||
return false;
|
||||
}
|
||||
this._var.asset = asset;
|
||||
this._var.template = null;
|
||||
this._changePage(1);
|
||||
templateSelector.assetId = asset.Id;
|
||||
return false;
|
||||
}
|
||||
},
|
||||
{
|
||||
text: this.r('P_GRID_OK', 'OK'),
|
||||
trigger: () => {
|
||||
const template = templateSelector.currentTemplate;
|
||||
if (template == null) {
|
||||
showAlert(templateSelector.title, this.r('P_WO_PLEASESELECTATEMPLATE', 'Please select a template.'));
|
||||
return false;
|
||||
}
|
||||
this._var.template = template;
|
||||
this._select();
|
||||
}
|
||||
},
|
||||
{ text: this.r('P_WO_CANCEL', 'Cancel') }
|
||||
]
|
||||
});
|
||||
this._var.popup = popup;
|
||||
popup.create();
|
||||
this._changePage(0);
|
||||
popup.rect = { width: 1220 };
|
||||
const mask = await popup.show();
|
||||
assetSelector.init();
|
||||
return mask;
|
||||
}
|
||||
|
||||
show() {
|
||||
if (this._var.popup == null) {
|
||||
return this.create();
|
||||
}
|
||||
this._changePage(0);
|
||||
const selector = this._var.assetSelector;
|
||||
selector._var.el.inputSearch.value = '';
|
||||
selector._var.el.dropAssetGroup.select('-1');
|
||||
selector._var.el.dropJobsite.select('-1');
|
||||
selector._var.el.dropJobsiteCode.select('-1');
|
||||
selector.refresh();
|
||||
return this._var.popup.show();
|
||||
}
|
||||
|
||||
_select() {
|
||||
if (typeof this.onSelected === 'function') {
|
||||
this.onSelected(this._var.asset, this._var.template);
|
||||
}
|
||||
}
|
||||
|
||||
_changePage(index) {
|
||||
if (isNaN(index) || index < 0 || index >= 2) {
|
||||
return;
|
||||
}
|
||||
this._var.index = index;
|
||||
this._var.containers[0].style.display = index === 0 ? '' : 'none';
|
||||
this._var.containers[1].style.display = index === 1 ? '' : 'none';
|
||||
const footerButtons = this._var.popup.container.querySelectorAll('.ui-popup-footer>.ui-popup-button');
|
||||
footerButtons[0].style.display = index === 0 ? 'none' : '';
|
||||
footerButtons[1].style.display = index === 1 ? 'none' : '';
|
||||
footerButtons[2].style.display = index === 0 ? 'none' : '';
|
||||
}
|
||||
}
|
@ -1,19 +1,10 @@
|
||||
import { createElement, createCheckbox, createRadiobox, Dropdown, validation, toDateValue } from "../ui";
|
||||
import { r as lang } from "../utility";
|
||||
import { createElement, createCheckbox, createRadiobox, Dropdown, validation, toDateValue, OptionBase } from "../ui";
|
||||
|
||||
let r = lang;
|
||||
|
||||
export default class ScheduleItem {
|
||||
export default class ScheduleItem extends OptionBase {
|
||||
_var = {};
|
||||
|
||||
constructor(opt) {
|
||||
this._var.option = opt ?? {};
|
||||
const getText = opt?.getText;
|
||||
if (typeof getText === 'function') {
|
||||
r = getText;
|
||||
} else if (typeof GetTextByKey === 'function') {
|
||||
r = GetTextByKey;
|
||||
}
|
||||
constructor(opt = {}) {
|
||||
super(opt);
|
||||
}
|
||||
|
||||
get checkOccurOnce() { return this._var.container.querySelector('.schedule-id-box-occur-once>input'); }
|
||||
@ -99,7 +90,7 @@ export default class ScheduleItem {
|
||||
}
|
||||
|
||||
create() {
|
||||
const option = this._var.option;
|
||||
const option = this._option;
|
||||
const drop = new Dropdown({ selected: '0' });
|
||||
this.dropFrequency = drop;
|
||||
drop.source = [
|
||||
|
151
lib/element/signature.js
Normal file
151
lib/element/signature.js
Normal file
@ -0,0 +1,151 @@
|
||||
import { OptionBase, Popup, createElement } from "../ui";
|
||||
|
||||
export default class Signature extends OptionBase {
|
||||
_var = {
|
||||
/**
|
||||
* @private
|
||||
* @type {HTMLCanvasElement}
|
||||
*/
|
||||
canvas: null,
|
||||
/**
|
||||
* @private
|
||||
* @type {Popup}
|
||||
*/
|
||||
popup: null,
|
||||
isDrawing: false,
|
||||
/**
|
||||
* @private
|
||||
* @type {{x: number, y: number}[]}
|
||||
*/
|
||||
points: [],
|
||||
/**
|
||||
* @private
|
||||
* @type {{x: number, y: number}[][]}
|
||||
*/
|
||||
allPoints: []
|
||||
};
|
||||
|
||||
/**
|
||||
* @event
|
||||
* @type {(this: Signature, singature: string) => void}
|
||||
*/
|
||||
onSignatured;
|
||||
|
||||
constructor(opt = {}) {
|
||||
super(opt);
|
||||
}
|
||||
|
||||
async show() {
|
||||
const popup = new Popup({
|
||||
title: this.r('P_IPT_SIGNATURE', 'Signature'),
|
||||
content: this._var.canvas = createElement('canvas', canvas => {
|
||||
canvas.style.width = '100%';
|
||||
canvas.style.height = '100%';
|
||||
}),
|
||||
resolve: result => {
|
||||
if (result.result === 'ok' && this._var.allPoints.length > 0) {
|
||||
if (typeof this.onSignatured === 'function') {
|
||||
const data = this._var.canvas.toDataURL('image/png');
|
||||
this.onSignatured(data);
|
||||
}
|
||||
} else {
|
||||
if (typeof this.onSignatured === 'function') {
|
||||
this.onSignatured();
|
||||
}
|
||||
}
|
||||
},
|
||||
buttons: [
|
||||
{
|
||||
text: this.r('P_GRID_OK', 'OK'),
|
||||
trigger: () => {
|
||||
if (this._var.allPoints.length === 0) {
|
||||
return false;
|
||||
}
|
||||
return 'ok';
|
||||
}
|
||||
},
|
||||
{
|
||||
text: this.r('P_GRID_RESET', 'Reset'),
|
||||
trigger: () => {
|
||||
const ctx = this._var.canvas.getContext('2d');
|
||||
ctx.clearRect(0, 0, this._var.canvas.width, this._var.canvas.height);
|
||||
return false
|
||||
}
|
||||
},
|
||||
{ text: this.r('P_WO_CANCEL', 'Cancel') }
|
||||
]
|
||||
});
|
||||
this._var.popup = popup;
|
||||
popup.create();
|
||||
popup.container.classList.add('ui-popup-signature');
|
||||
const mask = await popup.show();
|
||||
this.init();
|
||||
return mask;
|
||||
}
|
||||
|
||||
init() {
|
||||
const canvas = this._var.canvas;
|
||||
canvas.width = canvas.clientWidth;
|
||||
canvas.height = canvas.clientHeight;
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.lineWidth = 3;
|
||||
ctx.strokeStyle = '#000';
|
||||
|
||||
canvas.addEventListener('mousedown', e => this._down(ctx, e.offsetX, e.offsetY), false);
|
||||
canvas.addEventListener('mousemove', e => this._move(ctx, e.offsetX, e.offsetY), false);
|
||||
canvas.addEventListener('mouseup', () => this._up(ctx), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {CanvasRenderingContext2D} ctx
|
||||
* @param {number} x1
|
||||
* @param {number} y1
|
||||
* @param {number} x2
|
||||
* @param {number} y2
|
||||
*/
|
||||
_draw(ctx, x1, y1, x2, y2) {
|
||||
ctx.moveTo(x1, y1);
|
||||
ctx.lineTo(x2, y2);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {CanvasRenderingContext2D} ctx
|
||||
* @param {number} x
|
||||
* @param {number} y
|
||||
*/
|
||||
_down(ctx, x, y) {
|
||||
this._var.isDrawing = true;
|
||||
this._var.points.push({ x, y });
|
||||
ctx.beginPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {CanvasRenderingContext2D} ctx
|
||||
* @param {number} x
|
||||
* @param {number} y
|
||||
*/
|
||||
_move(ctx, x, y) {
|
||||
if (this._var.isDrawing) {
|
||||
const lastPoint = this._var.points.at(-1);
|
||||
this._draw(ctx, lastPoint.x, lastPoint.y, x, y);
|
||||
this._var.points.push({ x, y });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {CanvasRenderingContext2D} ctx
|
||||
*/
|
||||
_up(ctx) {
|
||||
if (this._var.isDrawing) {
|
||||
this._var.isDrawing = false;
|
||||
ctx.closePath();
|
||||
this._var.allPoints.push(this._var.points);
|
||||
this._var.points = [];
|
||||
}
|
||||
}
|
||||
}
|
@ -115,6 +115,10 @@
|
||||
opacity: .4;
|
||||
}
|
||||
}
|
||||
|
||||
.col-icon.disabled>.ui-icon {
|
||||
cursor: inherit;
|
||||
}
|
||||
}
|
||||
|
||||
.open-wo-container {
|
||||
@ -137,7 +141,7 @@
|
||||
flex: 1 1 auto;
|
||||
margin: 10px;
|
||||
display: grid;
|
||||
grid-template-columns: minmax(130px,auto) 1fr;
|
||||
grid-template-columns: minmax(130px, auto) 1fr;
|
||||
grid-auto-rows: minmax(32px, auto);
|
||||
align-items: center;
|
||||
justify-items: start;
|
||||
@ -271,6 +275,7 @@
|
||||
|
||||
>.search-box {
|
||||
position: relative;
|
||||
margin-right: 8px;
|
||||
|
||||
>span {
|
||||
position: absolute;
|
||||
|
@ -1,27 +1,18 @@
|
||||
import { Grid, Popup, createElement, createIcon } from "../ui";
|
||||
import { r as lang, nullOrEmpty } from "../utility";
|
||||
import { Grid, OptionBase, createElement, createIcon } from "../ui";
|
||||
import { nullOrEmpty } from "../utility";
|
||||
|
||||
let r = lang;
|
||||
|
||||
export default class TemplateSelector {
|
||||
export default class TemplateSelector extends OptionBase {
|
||||
_var = {
|
||||
option: {
|
||||
/**
|
||||
* @private
|
||||
* @type {(search: string) => Promise<any[]>}
|
||||
*/
|
||||
requestTemplates: null
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
assetId: -1,
|
||||
/**
|
||||
* @private
|
||||
* @type {HTMLElement}
|
||||
*/
|
||||
container: null,
|
||||
/**
|
||||
* @private
|
||||
* @type {Popup}
|
||||
*/
|
||||
popup: null,
|
||||
el: {
|
||||
/**
|
||||
* @private
|
||||
@ -38,30 +29,47 @@ export default class TemplateSelector {
|
||||
|
||||
/**
|
||||
* @event
|
||||
* @type {(this: TemplateSelector, template: string) => void}
|
||||
* @type {(this: TemplateSelector, template: any) => void}
|
||||
*/
|
||||
onSelected;
|
||||
|
||||
constructor(opt = {}) {
|
||||
this._var.option = opt;
|
||||
const getText = opt.getText;
|
||||
if (typeof getText === 'function') {
|
||||
r = getText;
|
||||
} else if (typeof GetTextByKey === 'function') {
|
||||
r = GetTextByKey;
|
||||
constructor(opt = {
|
||||
/** @type {(flag: boolean) => void} */
|
||||
loading: null,
|
||||
/** @type {() => void} */
|
||||
close: null,
|
||||
/** @type {(assetId: number, search: string) => Promise<any[]>} */
|
||||
requestTemplates: null
|
||||
}) {
|
||||
super(opt);
|
||||
}
|
||||
|
||||
get assetId() { return this._var.assetId }
|
||||
set assetId(id) {
|
||||
this._var.assetId = id;
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
get title() { return this.r('P_MODULE_INSPECTIONTEMPLATES', 'Inspection Templates') }
|
||||
|
||||
get currentTemplate() { return this._var.el.grid.currentItem }
|
||||
|
||||
loading(flag) {
|
||||
if (typeof this._option.loading === 'function') {
|
||||
this._option.loading(flag);
|
||||
}
|
||||
}
|
||||
|
||||
refresh() {
|
||||
const requestTemplates = this._var.option.requestTemplates;
|
||||
const requestTemplates = this._option.requestTemplates;
|
||||
if (typeof requestTemplates !== 'function') {
|
||||
return;
|
||||
}
|
||||
const el = this._var.el;
|
||||
this._var.popup.loading = true;
|
||||
requestTemplates(el.inputSearch.value)
|
||||
this.loading(true);
|
||||
requestTemplates(this._var.assetId, el.inputSearch.value)
|
||||
.then(data => el.grid.source = data)
|
||||
.finally(() => this._var.popup.loading = false);
|
||||
.finally(() => this.loading(false));
|
||||
}
|
||||
|
||||
select(item) {
|
||||
@ -71,13 +79,11 @@ export default class TemplateSelector {
|
||||
this.onSelected(item);
|
||||
}
|
||||
|
||||
async create() {
|
||||
const option = this._var.option;
|
||||
const title = r('P_MODULE_INSPECTIONTEMPLATES', 'Inspection Templates');
|
||||
create() {
|
||||
const tabIndex = Math.max.apply(null, [...document.querySelectorAll('[tabindex]')].map(e => e.tabIndex ?? 0)) + 3;
|
||||
const inputSearch = createElement('input', input => {
|
||||
input.type = 'text';
|
||||
input.placeholder = r('P_SELECTASSETS_SEARCH', 'Search');
|
||||
input.placeholder = this.r('P_SELECTASSETS_SEARCH', 'Search');
|
||||
input.tabIndex = tabIndex + 1;
|
||||
input.className = 'ui-input';
|
||||
input.addEventListener('keypress', e => e.key === 'Enter' && this.refresh());
|
||||
@ -86,22 +92,25 @@ export default class TemplateSelector {
|
||||
div.className = 'popup-selector-content';
|
||||
div.style.height = '400px';
|
||||
});
|
||||
const grid = new Grid(gridContent, r);
|
||||
const grid = new Grid(gridContent, this.r);
|
||||
grid.columns = [
|
||||
{
|
||||
key: 'IssueId',
|
||||
type: Grid.ColumnTypes.Icon,
|
||||
width: 30,
|
||||
enabled: false,
|
||||
resizable: false,
|
||||
filter: it => nullOrEmpty(it.IssueId) ? '' : 'cubes'
|
||||
},
|
||||
{ key: 'Name', caption: r('P_IPT_NAME', 'Name'), width: 390 },
|
||||
{ key: 'Notes', caption: r('P_IPT_NOTES', 'Notes'), width: 630 }
|
||||
{ key: 'Name', caption: this.r('P_IPT_NAME', 'Name'), width: 390 },
|
||||
{ key: 'Notes', caption: this.r('P_IPT_NOTES', 'Notes'), width: 630 }
|
||||
];
|
||||
grid.onRowDblClicked = index => {
|
||||
const item = grid.source[index];
|
||||
this.select(item);
|
||||
this._var.popup.close();
|
||||
if (typeof this._option.close === 'function') {
|
||||
this._option.close();
|
||||
}
|
||||
};
|
||||
grid.init();
|
||||
grid.element.tabIndex = tabIndex + 2;
|
||||
@ -113,7 +122,7 @@ export default class TemplateSelector {
|
||||
// content
|
||||
const container = createElement('div', 'popup-selector',
|
||||
createElement('div', 'popup-selector-header',
|
||||
createElement('h3', h3 => h3.innerText = r('P_WO_PLEASESELECTATEMPLATE', 'Please select a template.'))
|
||||
createElement('h3', h3 => h3.innerText = this.r('P_WO_PLEASESELECTATEMPLATE', 'Please select a template.'))
|
||||
),
|
||||
createElement('div', 'popup-selector-function',
|
||||
createElement('div', 'search-box',
|
||||
@ -128,36 +137,6 @@ export default class TemplateSelector {
|
||||
gridContent
|
||||
);
|
||||
this._var.container = container;
|
||||
const popup = new Popup({
|
||||
title,
|
||||
content: container,
|
||||
persistent: true,
|
||||
buttons: [
|
||||
{
|
||||
text: r('P_GRID_OK', 'OK'),
|
||||
trigger: () => {
|
||||
const item = grid.source[grid.selectedIndex];
|
||||
if (item == null) {
|
||||
return false;
|
||||
}
|
||||
this.select(item);
|
||||
}
|
||||
},
|
||||
{ text: r('P_WO_CANCEL', 'Cancel') }
|
||||
]
|
||||
});
|
||||
this._var.popup = popup;
|
||||
popup.create();
|
||||
popup.rect = { width: 1200 };
|
||||
const mask = await popup.show();
|
||||
this.refresh();
|
||||
return mask;
|
||||
}
|
||||
|
||||
show() {
|
||||
if (this._var.popup == null) {
|
||||
return this.create();
|
||||
}
|
||||
return this._var.popup.show();
|
||||
return container;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user