2022-03-11 17:26:25 +08:00
|
|
|
import {
|
|
|
|
capa,
|
2022-03-11 20:01:46 +08:00
|
|
|
forEachObjectValue,
|
|
|
|
getNotification,
|
2022-03-11 17:26:25 +08:00
|
|
|
loading,
|
2022-03-11 20:01:46 +08:00
|
|
|
Remote,
|
|
|
|
scripts,
|
2022-03-11 17:26:25 +08:00
|
|
|
serverError,
|
|
|
|
serverErrorDesc,
|
2022-03-11 20:01:46 +08:00
|
|
|
setError
|
2022-03-11 17:26:25 +08:00
|
|
|
} from 'Sieve/Utils';
|
|
|
|
|
2022-03-11 20:01:46 +08:00
|
|
|
import { SieveScriptModel } from 'Sieve/Model/Script';
|
2022-03-11 17:26:25 +08:00
|
|
|
import { SieveScriptPopupView } from 'Sieve/View/Script';
|
2022-03-10 17:27:04 +08:00
|
|
|
|
|
|
|
// SieveUserStore
|
2022-03-11 17:26:25 +08:00
|
|
|
window.Sieve = {
|
|
|
|
capa: capa,
|
|
|
|
scripts: scripts,
|
|
|
|
setError: setError,
|
|
|
|
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);
|
2022-05-17 22:19:17 +08:00
|
|
|
value && (value.allowFilters() ? scripts.unshift(value) : scripts.push(value))
|
2022-03-11 20:01:46 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-03-11 17:26:25 +08:00
|
|
|
deleteScript: script => {
|
|
|
|
serverError(false);
|
|
|
|
Remote.request('FiltersScriptDelete',
|
|
|
|
(iError, data) => {
|
|
|
|
if (iError) {
|
2022-05-22 05:58:46 +08:00
|
|
|
setError(data?.ErrorMessageAdditional || getNotification(iError));
|
2022-03-11 17:26:25 +08:00
|
|
|
} else {
|
|
|
|
scripts.remove(script);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{name:script.name()}
|
|
|
|
);
|
2022-03-10 17:27:04 +08:00
|
|
|
},
|
|
|
|
|
2022-03-11 17:26:25 +08:00
|
|
|
toggleScript(script) {
|
|
|
|
let name = script.active() ? '' : script.name();
|
|
|
|
serverError(false);
|
|
|
|
Remote.request('FiltersScriptActivate',
|
|
|
|
(iError, data) => {
|
|
|
|
if (iError) {
|
2022-05-22 05:58:46 +08:00
|
|
|
setError(data?.ErrorMessageAdditional || iError)
|
2022-03-11 17:26:25 +08:00
|
|
|
} else {
|
|
|
|
scripts.forEach(script => script.active(script.name() === name));
|
2022-03-10 17:27:04 +08:00
|
|
|
}
|
|
|
|
},
|
2022-03-11 17:26:25 +08:00
|
|
|
{name:name}
|
|
|
|
);
|
2022-03-10 17:27:04 +08:00
|
|
|
}
|
2022-03-11 17:26:25 +08:00
|
|
|
};
|