mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-29 20:19:22 +03:00
Get a working Sieve scripts manager
This commit is contained in:
parent
a31834458b
commit
e3125ebfff
24 changed files with 439 additions and 304 deletions
|
|
@ -1,22 +1,22 @@
|
|||
import ko from 'ko';
|
||||
|
||||
import { delegateRunOnDestroy } from 'Common/UtilsUser';
|
||||
import { StorageResultType, Notification } from 'Common/Enums';
|
||||
import { getNotification } from 'Common/Translator';
|
||||
|
||||
import FilterStore from 'Stores/User/Filter';
|
||||
import SieveStore from 'Stores/User/Sieve';
|
||||
import Remote from 'Remote/User/Fetch';
|
||||
|
||||
import { FilterModel } from 'Model/Filter';
|
||||
import { SieveScriptModel } from 'Model/SieveScript';
|
||||
|
||||
import { showScreenPopup } from 'Knoin/Knoin';
|
||||
|
||||
class FiltersUserSettings {
|
||||
constructor() {
|
||||
this.filters = FilterStore.filters;
|
||||
this.sieve = SieveStore;
|
||||
|
||||
this.scripts = SieveStore.scripts;
|
||||
this.loading = ko.observable(false).extend({ throttle: 200 });
|
||||
|
||||
ko.addObservablesTo(this, {
|
||||
serverError: false,
|
||||
|
|
@ -33,23 +33,17 @@ class FiltersUserSettings {
|
|||
}
|
||||
|
||||
updateList() {
|
||||
if (!this.filters.loading()) {
|
||||
this.filters.loading(true);
|
||||
if (!this.loading()) {
|
||||
this.loading(true);
|
||||
|
||||
Remote.filtersGet((result, data) => {
|
||||
this.filters.loading(false);
|
||||
this.loading(false);
|
||||
this.serverError(false);
|
||||
this.scripts([]);
|
||||
|
||||
if (StorageResultType.Success === result && data && data.Result && Array.isArray(data.Result.Filters)) {
|
||||
if (StorageResultType.Success === result && data && data.Result) {
|
||||
this.serverError(false);
|
||||
|
||||
this.filters(
|
||||
data.Result.Filters.map(aItem => FilterModel.reviveFromJson(aItem)).filter(v => v)
|
||||
);
|
||||
|
||||
FilterStore.modules(data.Result.Capa);
|
||||
|
||||
SieveStore.capa(data.Result.Capa);
|
||||
/*
|
||||
this.scripts(
|
||||
|
|
@ -60,20 +54,9 @@ class FiltersUserSettings {
|
|||
value = SieveScriptModel.reviveFromJson(value);
|
||||
value && this.scripts.push(value)
|
||||
});
|
||||
|
||||
FilterStore.raw(data.Result.Scripts['rainloop.user.raw'].body);
|
||||
FilterStore.capa(data.Result.Capa.join(' '));
|
||||
// this.filterRaw.active(data.Result.Scripts['rainloop.user.raw'].active);
|
||||
// this.filterRaw.allow(!!data.Result.RawIsAllow);
|
||||
} else {
|
||||
this.filters([]);
|
||||
FilterStore.modules({});
|
||||
|
||||
this.scripts([]);
|
||||
SieveStore.capa([]);
|
||||
|
||||
FilterStore.raw('');
|
||||
FilterStore.capa({});
|
||||
|
||||
this.serverError(true);
|
||||
this.serverErrorDesc(
|
||||
data && data.ErrorCode ? getNotification(data.ErrorCode) : getNotification(Notification.CantGetFilters)
|
||||
|
|
@ -106,13 +89,42 @@ class FiltersUserSettings {
|
|||
]);
|
||||
}
|
||||
|
||||
deleteScript() {
|
||||
// TODO
|
||||
deleteScript(script) {
|
||||
if (!script.active()) {
|
||||
Remote.filtersScriptDelete(
|
||||
(result, data) => {
|
||||
if (StorageResultType.Success === result && data && data.Result) {
|
||||
this.scripts.remove(script);
|
||||
delegateRunOnDestroy(script);
|
||||
} else {
|
||||
this.saveError(true);
|
||||
this.saveErrorText((data && data.ErrorCode)
|
||||
? (data.ErrorMessageAdditional || getNotification(data.ErrorCode))
|
||||
: getNotification(Notification.CantActivateFiltersScript)
|
||||
);
|
||||
}
|
||||
},
|
||||
script.name()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
toggleScript(script) {
|
||||
// TODO: activate/deactivate script
|
||||
script.active(!script.active());
|
||||
let name = script.active() ? '' : script.name();
|
||||
Remote.filtersScriptActivate(
|
||||
(result, data) => {
|
||||
if (StorageResultType.Success === result && data && data.Result) {
|
||||
this.scripts().forEach(script => script.active(script.name() === name));
|
||||
} else {
|
||||
this.saveError(true);
|
||||
this.saveErrorText((data && data.ErrorCode)
|
||||
? (data.ErrorMessageAdditional || getNotification(data.ErrorCode))
|
||||
: getNotification(Notification.CantActivateFiltersScript)
|
||||
);
|
||||
}
|
||||
},
|
||||
name
|
||||
);
|
||||
}
|
||||
|
||||
onBuild(oDom) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue