2016-08-17 06:01:20 +08:00
|
|
|
import ko from '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';
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2021-03-11 05:41:35 +08:00
|
|
|
import { MessageUserStore } from 'Stores/User/Message';
|
2014-08-25 15:10:51 +08:00
|
|
|
|
2021-02-19 19:09:20 +08:00
|
|
|
import { decorateKoCommands } from 'Knoin/Knoin';
|
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
|
|
|
|
|
|
|
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: '',
|
|
|
|
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-11-03 09:28:01 +08:00
|
|
|
this.showMultisearch = ko.computed(() => FolderUserStore.hasCapability('MULTISEARCH'));
|
|
|
|
|
2021-01-26 18:46:30 +08:00
|
|
|
let prefix = 'SEARCH/LABEL_ADV_DATE_';
|
2016-08-17 06:01:20 +08:00
|
|
|
this.selectedDates = ko.computed(() => {
|
|
|
|
translatorTrigger();
|
|
|
|
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-11-03 09:28:01 +08:00
|
|
|
prefix = 'SEARCH/LABEL_ADV_SUBFOLDERS_';
|
|
|
|
this.selectedTree = ko.computed(() => {
|
|
|
|
translatorTrigger();
|
|
|
|
return [
|
|
|
|
{ id: '', name: i18n(prefix + 'NONE') },
|
|
|
|
{ id: 'subtree-one', name: i18n(prefix + 'SUBTREE_ONE') },
|
|
|
|
{ id: 'subtree', name: i18n(prefix + 'SUBTREE') }
|
|
|
|
];
|
|
|
|
});
|
|
|
|
|
2021-02-19 19:09:20 +08:00
|
|
|
decorateKoCommands(this, {
|
|
|
|
searchCommand: 1
|
|
|
|
});
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
searchCommand() {
|
|
|
|
const search = this.buildSearchString();
|
2020-07-28 23:20:14 +08:00
|
|
|
if (search) {
|
2021-03-11 05:41:35 +08:00
|
|
|
MessageUserStore.mainMessageListSearch(search);
|
2016-09-10 06:38:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
this.cancelCommand();
|
|
|
|
}
|
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
parseSearchStringValue(search) {
|
|
|
|
const parts = (search || '').split(/[\s]+/g);
|
2020-07-22 20:49:18 +08:00
|
|
|
parts.forEach(part => {
|
2019-07-05 03:19:24 +08:00
|
|
|
switch (part) {
|
2016-08-17 06:01:20 +08:00
|
|
|
case 'has:attachment':
|
|
|
|
this.hasAttachment(true);
|
|
|
|
break;
|
|
|
|
case 'is:unseen,flagged':
|
|
|
|
this.starred(true);
|
2019-07-05 03:19:24 +08:00
|
|
|
/* falls through */
|
2016-08-17 06:01:20 +08:00
|
|
|
case 'is:unseen':
|
|
|
|
this.unseen(true);
|
|
|
|
break;
|
|
|
|
// no default
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-12-17 00:08:05 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
buildSearchString() {
|
2021-11-03 09:28:01 +08:00
|
|
|
const
|
|
|
|
result = new FormData();
|
|
|
|
|
|
|
|
let value = this.from().trim();
|
|
|
|
if (value) {
|
|
|
|
result.set('from', value);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2021-11-03 09:28:01 +08:00
|
|
|
value = this.to().trim();
|
|
|
|
if (value) {
|
|
|
|
result.set('to', value);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2021-11-03 09:28:01 +08:00
|
|
|
value = this.subject().trim();
|
|
|
|
if (value) {
|
|
|
|
result.set('subject', value);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (this.hasAttachment()) {
|
2021-11-03 09:28:01 +08:00
|
|
|
result.set('has', 'attachment');
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (this.unseen()) {
|
2021-11-03 09:28:01 +08:00
|
|
|
result.set('is[]', 'unseen');
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (this.starred()) {
|
2021-11-03 09:28:01 +08:00
|
|
|
result.set('is[]', 'flagged');
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
if (-1 < this.selectedDateValue()) {
|
2020-08-07 20:44:33 +08:00
|
|
|
let d = new Date();
|
2020-07-31 22:45:43 +08:00
|
|
|
d.setDate(d.getDate() - this.selectedDateValue());
|
2021-11-03 09:28:01 +08:00
|
|
|
result.set('date', d.format('Y.m.d') + '/');
|
|
|
|
}
|
|
|
|
|
|
|
|
value = this.selectedTreeValue();
|
|
|
|
if (value) {
|
|
|
|
result.set('in', value);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2021-11-03 09:28:01 +08:00
|
|
|
value = this.text().trim();
|
|
|
|
if (value) {
|
|
|
|
result.set('text', value);
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2021-11-03 09:28:01 +08:00
|
|
|
return new URLSearchParams(result).toString();
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
clearPopup() {
|
|
|
|
this.from('');
|
|
|
|
this.to('');
|
|
|
|
this.subject('');
|
|
|
|
this.text('');
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.selectedDateValue(-1);
|
|
|
|
this.hasAttachment(false);
|
|
|
|
this.starred(false);
|
|
|
|
this.unseen(false);
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
onShow(search) {
|
|
|
|
this.clearPopup();
|
|
|
|
this.parseSearchStringValue(search);
|
2016-06-30 08:02:45 +08:00
|
|
|
}
|
2016-08-17 06:01:20 +08:00
|
|
|
}
|
2013-11-16 06:21:12 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
export { AdvancedSearchPopupView, AdvancedSearchPopupView as default };
|