remove dependency of jQuery plugins.

Grid.expandAll
add total field of exported data.
This commit is contained in:
2024-04-24 14:10:28 +08:00
parent 4e8be83625
commit f676ec76db
6 changed files with 400 additions and 183 deletions

View File

@ -25,6 +25,18 @@ export default class CustomerRecordComment {
}
}
get messageHidden() { return this._var.option.showCommentHidden }
set messageHidden(flag) {
const el = this._var.container.querySelector('.msgadminsetting');
if (el == null) {
return;
}
this._var.option.showCommentHidden = flag;
// TODO: 是否与参数 flag 无关
el.classList.remove('iconview');
el.classList.add('iconnotview');
}
/**
* @param {boolean} flag
*/
@ -50,13 +62,35 @@ export default class CustomerRecordComment {
}
create() {
const option = this._var.option;
const readonly = this._var.option.readonly;
const spanv = createElement('span');
if (option.userIsAdmin) {
spanv.className = 'msgadminsetting sbutton iconnotview';
spanv.style.padding = '0px 0px 0px 5px';
spanv.addEventListener('click', function () {
if (!option.showCommentHidden) {
this.classList.remove('iconnotview');
this.classList.add('iconview');
option.showCommentHidden = true;
container.querySelectorAll('.msgsetting').forEach(x => x.style.display = '');
} else {
this.classList.remove('iconview');
this.classList.add('iconnotview');
option.showCommentHidden = false;
container.querySelectorAll('.msgsetting').forEach(x => x.style.display = 'none');
}
});
}
const container = createBox(
createElement('div', null,
createElement('div', div => {
div.className = 'title-module';
div.innerText = r('P_CR_COMMENTS', 'Comments');
})
},
spanv
)
),
[
createElement('button', button => {
@ -120,7 +154,7 @@ export default class CustomerRecordComment {
return this._var.container = container;
}
load(data) {
load(data, func) {
const children = [];
if (data?.length > 0) {
for (let comment of data) {
@ -145,8 +179,28 @@ export default class CustomerRecordComment {
content,
createElement('div', div => {
div.className = 'item-time';
div.innerText = comment.SubmitLocalDateStr;
})
},
createElement('span', span => {
span.className = 'msgsetting sbutton ' + (comment.Hidden ? 'iconnotview' : 'iconview');
span.style.padding = '0px 0px 0px 5px';
span.style.fontSize = '12px';
span.style.display = this._var.option.showCommentHidden ? '' : 'none';
span.addEventListener('click', function () {
if (this.classList.contains('iconview')) {
func(comment.Id, true);
this.classList.remove('iconview');
this.classList.add('iconnotview');
} else {
func(comment.Id, false);
this.classList.remove('iconnotview');
this.classList.add('iconview');
}
});
}),
createElement('span', span => {
span.innerText = comment.SubmitLocalDateStr;
})
)
);
children.push(div);
}

View File

@ -69,6 +69,18 @@ export default class CustomerCommunication {
element.dispatchEvent(new Event('change'));
}
get messageHidden() { return this._var.option.showMessageHidden }
set messageHidden(flag) {
const el = this._var.container.querySelector('.msgadminsetting');
if (el == null) {
return;
}
this._var.option.showMessageHidden = flag;
// TODO: 是否与参数 flag 无关
el.classList.remove('iconview');
el.classList.add('iconnotview');
}
get _statusLink() { return this._var.container.querySelector('.check-status-link>input') }
get statusLinkEnabled() { return this._statusLink?.disabled !== true }
set statusLinkEnabled(flag) {
@ -413,12 +425,33 @@ export default class CustomerCommunication {
if (option.statusLinkVisible === false) {
checkLink.style.display = 'none';
}
const spanv = createElement('span');
if (option.userIsAdmin) {
spanv.className = 'msgadminsetting sbutton iconnotview';
spanv.style.padding = '0px 0px 0px 5px';
spanv.addEventListener('click', function () {
if (!option.showMessageHidden) {
this.classList.remove('iconnotview');
this.classList.add('iconview');
option.showMessageHidden = true;
container.querySelectorAll('.msgsetting').forEach(x => x.style.display = '');
} else {
this.classList.remove('iconview');
this.classList.add('iconnotview');
option.showMessageHidden = false;
container.querySelectorAll('.msgsetting').forEach(x => x.style.display = 'none');
}
});
}
const container = createBox(
createElement('div', null,
createElement('div', div => {
div.className = 'title-module';
div.innerText = option.title ?? r('P_WO_CUSTOMERCOMMUNICATION', 'Customer Communication');
}),
},
spanv
),
createElement('div', div => {
div.className = 'title-company';
if (nullOrEmpty(option.companyName)) {
@ -1146,7 +1179,7 @@ export default class CustomerCommunication {
return followers;
}
load(data, contacts, followers) {
load(data, contacts, followers, func) {
const children = [];
if (data?.length > 0) {
contacts ??= this._var.data.contacts;
@ -1216,8 +1249,28 @@ export default class CustomerCommunication {
content,
createElement('div', div => {
div.className = 'item-time';
div.innerText = comm.TimeStr;
})
},
createElement('span', span => {
span.className = 'msgsetting sbutton ' + (comm.Hidden ? 'iconnotview' : 'iconview');
span.style.padding = '0px 0px 0px 5px';
span.style.fontSize = '12px';
span.style.display = this._var.option.showMessageHidden ? '' : 'none';
span.addEventListener('click', function () {
if (this.classList.contains('iconview')) {
func(comm.Id, true);
this.classList.remove('iconview');
this.classList.add('iconnotview');
} else {
func(comm.Id, false);
this.classList.remove('iconnotview');
this.classList.add('iconview');
}
});
}),
createElement('span', span => {
span.innerText = comm.TimeStr;
})
)
);
children.push(div);
}

View File

@ -32,6 +32,18 @@ export default class InternalComment {
}
}
get messageHidden() { return this._var.option.showCommentHidden }
set messageHidden(flag) {
const el = this._var.container.querySelector('.msgadminsetting');
if (el == null) {
return;
}
this._var.option.showMessageHidden = flag;
// TODO: 是否与参数 flag 无关
el.classList.remove('iconview');
el.classList.add('iconnotview');
}
/**
* @param {any} contacts
*/
@ -110,7 +122,28 @@ export default class InternalComment {
createElement('div', div => {
div.className = 'title-module';
div.innerText = r('P_WO_INTERNALCOMMENTS', 'Internal Comments');
})
},
createElement('span', span => {
if (option.userIsAdmin) {
span.className = 'msgadminsetting sbutton iconnotview';
span.style.padding = '0px 0px 0px 5px';
span.addEventListener('click', function () {
if (!option.showMessageHidden) {
this.classList.remove('iconnotview');
this.classList.add('iconview');
option.showMessageHidden = true;
container.querySelectorAll('.msgsetting').forEach(x => x.style.display = '');
}
else {
this.classList.remove('iconview');
this.classList.add('iconnotview');
option.showMessageHidden = false;
container.querySelectorAll('.msgsetting').forEach(x => x.style.display = 'none');
}
});
}
})
)
), []
);
const readonly = option.readonly;
@ -245,7 +278,7 @@ export default class InternalComment {
return this._var.container = container;
}
load(data) {
load(data, func) {
const children = [];
if (data?.length > 0) {
this._var.comments = data;
@ -302,8 +335,28 @@ export default class InternalComment {
content,
createElement('div', div => {
div.className = 'item-time';
div.innerText = comment.TimeStr;
})
},
createElement('span', span => {
span.className = 'msgsetting sbutton ' + (comment.Hidden ? 'iconnotview' : 'iconview');
span.style.padding = '0px 0px 0px 5px';
span.style.fontSize = '12px';
span.style.display = this._var.option.showMessageHidden ? '' : 'none';
span.addEventListener('click', function () {
if (this.classList.contains('iconview')) {
func(comment.Id, true);
this.classList.remove('iconview');
this.classList.add('iconnotview');
} else {
func(comment.Id, false);
this.classList.remove('iconnotview');
this.classList.add('iconview');
}
});
}),
createElement('span', span => {
span.innerText = comment.TimeStr;
})
)
);
children.push(div);
}

View File

@ -367,6 +367,7 @@ let r = lang;
* @param {(boolean | string | number)} value - 修改后的值
* @param {(boolean | string | number)} oldValue - 修改前的值
* @param {any} [e] - 列修改事件传递过来的任意对象
* @param {GridExpandableObject} [expandableObject] - 列展开元素对象
* @this Grid
* @memberof GridColumnDefinition
*/
@ -610,6 +611,12 @@ export class Grid {
* @private
*/
currentSource: null,
/**
* 当前是否已全部展开
* @type {boolean}
* @private
*/
expanded: false,
/**
* 列可用性的关联字典
* @type {KeyMap<string | boolean>}
@ -2137,7 +2144,7 @@ export class Grid {
align: c.align,
visible: c.visible
})),
source: this.source.map(s => {
source: this.source?.map(s => {
const item = Object.create(null);
for (let c of this.columns) {
if (c.key == null) {
@ -2167,15 +2174,42 @@ export class Grid {
}
let val;
val = s[prop];
if (val != null) {
if (Object.prototype.hasOwnProperty.call(val, 'DisplayValue')) {
val = val.DisplayValue;
}
if (val != null && Object.prototype.hasOwnProperty.call(val, 'DisplayValue')) {
val = val.DisplayValue;
}
item[prop] = val;
}
return item;
}),
}) ?? [],
total: ((total) => {
if (total == null) {
return null;
}
const item = Object.create(null);
for (let c of this.columns) {
if (c.key == null) {
continue;
}
let val = total[c.key];
if (val != null && Object.prototype.hasOwnProperty.call(val, 'DisplayValue') && val.Value === val.DisplayValue) {
val = val.DisplayValue;
}
val ??= '';
item[c.key] = val;
}
for (let prop of Object.keys(total)) {
if (Object.prototype.hasOwnProperty.call(item, prop)) {
continue;
}
let val;
val = total[prop];
if (val != null && Object.prototype.hasOwnProperty.call(val, 'DisplayValue')) {
val = val.DisplayValue;
}
item[prop] = val;
}
return item;
})(this.total),
rowHeight: this.rowHeight,
sortDirection: this.sortDirection,
sortKey: this.sortKey,
@ -2236,10 +2270,32 @@ export class Grid {
}
})
working = true;
worker.postMessage({ type: 'init', path: ScriptPath.replace(/ui\.min\.js$/, 'wasm_flate_bg.wasm') });
worker.postMessage({ type: 'init', path: ScriptPath });
});
}
/**
* 展开/收折所有行
* @param {boolean} [expanded] - 是否展开,传 null 则切换展开状态
* @returns {boolean} 展开状态
*/
expandAll(expanded) {
if (this._var.currentSource == null) {
return;
}
if (expanded == null) {
expanded = !this._var.expanded;
} else {
expanded = expanded !== false;
}
this._var.expanded = expanded;
for (let vals of this._var.currentSource) {
vals.__expanded = expanded;
}
this.refresh();
return expanded;
}
/**
* @private
* @callback PrivateGridComparerCallback
@ -3892,10 +3948,11 @@ export class Grid {
}
const enabled = isFunction ? col.enabled(item) : isString ? item[col.enabled] : col.enabled;
if (enabled !== false) {
const old = item[key];
item[key] = flag;
row.__changed = true;
if (typeof col.onChanged === 'function') {
col.onChanged.call(this, item, flag);
col.onChanged.call(this, item, flag, old, void 0, row.__expandable_object);
}
}
}
@ -4209,7 +4266,7 @@ export class Grid {
});
vals.__changed = true;
if (typeof col.onChanged === 'function') {
col.onChanged.call(this, item, v, oldValue, e);
col.onChanged.call(this, item, v, oldValue, e, vals.__expandable_object);
}
}
}