snappymail/dev/sieve.js

79 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

import {
capa,
2022-03-11 20:01:46 +08:00
forEachObjectValue,
getNotification,
loading,
2022-03-11 20:01:46 +08:00
Remote,
scripts,
serverError,
serverErrorDesc,
2022-03-11 20:01:46 +08:00
setError
} from 'Sieve/Utils';
2022-03-11 20:01:46 +08:00
import { SieveScriptModel } from 'Sieve/Model/Script';
import { SieveScriptPopupView } from 'Sieve/View/Script';
// SieveUserStore
window.Sieve = {
capa: capa,
scripts: scripts,
loading: loading,
serverError: serverError,
serverErrorDesc: serverErrorDesc,
ScriptView: SieveScriptPopupView,
folderList: null,
2022-03-11 20:01:46 +08:00
updateList: () => {
if (!loading()) {
loading(true);
serverError(false);
Remote.request('Filters', (iError, data) => {
loading(false);
scripts([]);
if (iError) {
capa([]);
setError(getNotification(iError));
} else {
capa(data.Result.Capa);
/*
scripts(
data.Result.Scripts.map(aItem => SieveScriptModel.reviveFromJson(aItem)).filter(v => v)
);
*/
forEachObjectValue(data.Result.Scripts, value => {
value = SieveScriptModel.reviveFromJson(value);
value && (value.allowFilters() ? scripts.unshift(value) : scripts.push(value))
2022-03-11 20:01:46 +08:00
});
}
});
}
},
deleteScript: script => {
serverError(false);
Remote.request('FiltersScriptDelete',
2023-01-09 19:28:07 +08:00
(iError, data) =>
iError
? setError(data?.messageAdditional || getNotification(iError))
2023-01-09 19:28:07 +08:00
: scripts.remove(script)
,
{name:script.name()}
);
},
2022-10-31 05:08:30 +08:00
setActiveScript(name) {
serverError(false);
Remote.request('FiltersScriptActivate',
2023-01-09 19:28:07 +08:00
(iError, data) =>
iError
? setError(data?.messageAdditional || iError)
2023-01-09 19:28:07 +08:00
: scripts.forEach(script => script.active(script.name() === name))
,
{name:name}
);
}
};