snappymail/dev/sieve.js

84 lines
1.7 KiB
JavaScript
Raw 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',
(iError, data) => {
if (iError) {
setError(data?.ErrorMessageAdditional || getNotification(iError));
} else {
scripts.remove(script);
}
},
{name:script.name()}
);
},
toggleScript(script) {
let name = script.active() ? '' : script.name();
serverError(false);
Remote.request('FiltersScriptActivate',
(iError, data) => {
if (iError) {
setError(data?.ErrorMessageAdditional || iError)
} else {
scripts.forEach(script => script.active(script.name() === name));
}
},
{name:name}
);
}
};