2021-12-31 20:30:05 +08:00
|
|
|
import { koComputable } from 'External/ko';
|
2013-12-09 23:16:58 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
import { i18n, trigger as translatorTrigger } from 'Common/Translator';
|
2022-08-04 04:23:32 +08:00
|
|
|
import { pString } from 'Common/Utils';
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2022-02-24 02:26:52 +08:00
|
|
|
import { MessagelistUserStore } from 'Stores/User/Messagelist';
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2021-01-24 17:25:23 +08:00
|
|
|
import { AbstractViewPopup } from 'Knoin/AbstractViews';
|
2021-11-03 09:28:01 +08:00
|
|
|
import { FolderUserStore } from 'Stores/User/Folder';
|
2021-01-24 17:25:23 +08:00
|
|
|
|
2022-02-24 21:01:41 +08:00
|
|
|
export class AdvancedSearchPopupView extends AbstractViewPopup {
|
2016-08-17 06:01:20 +08:00
|
|
|
constructor() {
|
2021-01-24 17:25:23 +08:00
|
|
|
super('AdvancedSearch');
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2020-10-26 19:54:03 +08:00
|
|
|
this.addObservables({
|
|
|
|
from: '',
|
|
|
|
to: '',
|
|
|
|
subject: '',
|
|
|
|
text: '',
|
2022-08-03 18:03:34 +08:00
|
|
|
repliedValue: -1,
|
2020-10-26 19:54:03 +08:00
|
|
|
selectedDateValue: -1,
|
2021-11-03 09:28:01 +08:00
|
|
|
selectedTreeValue: '',
|
2020-10-26 19:54:03 +08:00
|
|
|
|
|
|
|
hasAttachment: false,
|
|
|
|
starred: false,
|
|
|
|
unseen: false
|
|
|
|
});
|
2016-08-17 06:01:20 +08:00
|
|
|
|
2021-12-31 20:30:05 +08:00
|
|
|
this.showMultisearch = koComputable(() => FolderUserStore.hasCapability('MULTISEARCH'));
|
2021-11-03 09:28:01 +08:00
|
|
|
|
2022-08-03 18:03:34 +08:00
|
|
|
this.repliedOptions = koComputable(() => {
|
|
|
|
translatorTrigger();
|
|
|
|
return [
|
|
|
|
{ id: -1, name: '' },
|
|
|
|
{ id: 1, name: i18n('GLOBAL/YES') },
|
|
|
|
{ id: 0, name: i18n('GLOBAL/NO') }
|
|
|
|
];
|
|
|
|
});
|
|
|
|
|
2021-12-31 20:30:05 +08:00
|
|
|
this.selectedDates = koComputable(() => {
|
2016-08-17 06:01:20 +08:00
|
|
|
translatorTrigger();
|
2022-08-03 18:03:34 +08:00
|
|
|
let prefix = 'SEARCH/LABEL_DATE_';
|
2016-08-17 06:01:20 +08:00
|
|
|
return [
|
2021-01-26 18:46:30 +08:00
|
|
|
{ id: -1, name: i18n(prefix + 'ALL') },
|
|
|
|
{ id: 3, name: i18n(prefix + '3_DAYS') },
|
|
|
|
{ id: 7, name: i18n(prefix + '7_DAYS') },
|
|
|
|
{ id: 30, name: i18n(prefix + 'MONTH') },
|
|
|
|
{ id: 90, name: i18n(prefix + '3_MONTHS') },
|
|
|
|
{ id: 180, name: i18n(prefix + '6_MONTHS') },
|
|
|
|
{ id: 365, name: i18n(prefix + 'YEAR') }
|
2016-08-17 06:01:20 +08:00
|
|
|
];
|
|
|
|
});
|
2021-02-19 19:09:20 +08:00
|
|
|
|
2021-12-31 20:30:05 +08:00
|
|
|
this.selectedTree = koComputable(() => {
|
2021-11-03 09:28:01 +08:00
|
|
|
translatorTrigger();
|
2022-08-03 18:03:34 +08:00
|
|
|
let prefix = 'SEARCH/LABEL_SUBFOLDERS_';
|
2021-11-03 09:28:01 +08:00
|
|
|
return [
|
|
|
|
{ id: '', name: i18n(prefix + 'NONE') },
|
|
|
|
{ id: 'subtree-one', name: i18n(prefix + 'SUBTREE_ONE') },
|
|
|
|
{ id: 'subtree', name: i18n(prefix + 'SUBTREE') }
|
|
|
|
];
|
|
|
|
});
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2022-02-21 22:36:34 +08:00
|
|
|
submitForm() {
|
2016-09-10 06:38:16 +08:00
|
|
|
const search = this.buildSearchString();
|
2020-07-28 23:20:14 +08:00
|
|
|
if (search) {
|
2022-02-24 02:26:52 +08:00
|
|
|
MessagelistUserStore.mainSearch(search);
|
2016-09-10 06:38:16 +08:00
|
|
|
}
|
|
|
|
|
2022-03-04 16:21:24 +08:00
|
|
|
this.close();
|
2016-09-10 06:38:16 +08:00
|
|
|
}
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
buildSearchString() {
|
2021-11-03 09:28:01 +08:00
|
|
|
const
|
2022-08-04 04:23:32 +08:00
|
|
|
self = this,
|
2021-11-03 21:47:03 +08:00
|
|
|
data = new FormData(),
|
|
|
|
append = (key, value) => value.length && data.append(key, value);
|
|
|
|
|
2022-08-04 04:23:32 +08:00
|
|
|
append('from', self.from().trim());
|
|
|
|
append('to', self.to().trim());
|
|
|
|
append('subject', self.subject().trim());
|
|
|
|
append('text', self.text().trim());
|
|
|
|
append('in', self.selectedTreeValue());
|
|
|
|
if (-1 < self.selectedDateValue()) {
|
2021-11-03 21:47:03 +08:00
|
|
|
let d = new Date();
|
2022-08-04 04:23:32 +08:00
|
|
|
d.setDate(d.getDate() - self.selectedDateValue());
|
2022-03-21 18:34:40 +08:00
|
|
|
append('since', d.toISOString().split('T')[0]);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2021-11-03 21:47:03 +08:00
|
|
|
let result = new URLSearchParams(data).toString();
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2022-08-04 04:23:32 +08:00
|
|
|
if (self.hasAttachment()) {
|
2021-11-03 21:47:03 +08:00
|
|
|
result += '&attachment';
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
2022-08-04 04:23:32 +08:00
|
|
|
if (self.unseen()) {
|
2021-11-03 21:47:03 +08:00
|
|
|
result += '&unseen';
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2022-08-04 04:23:32 +08:00
|
|
|
if (self.starred()) {
|
2021-11-03 21:47:03 +08:00
|
|
|
result += '&flagged';
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2022-08-04 04:23:32 +08:00
|
|
|
if (1 == self.repliedValue()) {
|
2022-08-03 18:03:34 +08:00
|
|
|
result += '&answered';
|
|
|
|
}
|
2022-08-04 04:23:32 +08:00
|
|
|
if (0 == self.repliedValue()) {
|
2022-08-03 18:03:34 +08:00
|
|
|
result += '&unanswered';
|
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2021-11-03 21:47:03 +08:00
|
|
|
return result.replace(/^&+/, '');
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2021-11-03 21:58:34 +08:00
|
|
|
onShow(search) {
|
2022-08-04 04:23:32 +08:00
|
|
|
const self = this,
|
|
|
|
params = new URLSearchParams('?'+search);
|
|
|
|
self.from(pString(params.get('from')));
|
|
|
|
self.to(pString(params.get('to')));
|
|
|
|
self.subject(pString(params.get('subject')));
|
|
|
|
self.text(pString(params.get('text')));
|
|
|
|
self.selectedTreeValue(pString(params.get('in')));
|
|
|
|
// self.selectedDateValue(params.get('since'));
|
|
|
|
self.selectedDateValue(-1);
|
|
|
|
self.hasAttachment(params.has('attachment'));
|
|
|
|
self.starred(params.has('flagged'));
|
|
|
|
self.unseen(params.has('unseen'));
|
|
|
|
if (params.has('answered')) {
|
|
|
|
self.repliedValue(1);
|
|
|
|
} else if (params.has('unanswered')) {
|
|
|
|
self.repliedValue(0);
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|