Create module "api" for various repeated api method calls inside UI
This commit is contained in:
parent
ccf5954091
commit
8e1f2af662
|
@ -0,0 +1,19 @@
|
||||||
|
var api = {
|
||||||
|
account: {
|
||||||
|
block: function(url, cback) {
|
||||||
|
cback = cback || function() {};
|
||||||
|
http.post(`/api/v1/accounts/block?url=${url}`, {}, function(json) {
|
||||||
|
if (json === undefined) return;
|
||||||
|
if (json.warn !== undefined)
|
||||||
|
app.toast.warn(app.strings.app.warn[json.warn]);
|
||||||
|
else if (json.error !== undefined)
|
||||||
|
app.toast.error(app.strings.app.error[json.error]);
|
||||||
|
else if (json.result !== undefined && json.result === 1) {
|
||||||
|
const n = randomNum(0, 3);
|
||||||
|
app.toast.warn(app.strings.app.ok['discarded_success_'+n]);
|
||||||
|
cback(json);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
|
@ -558,6 +558,7 @@ window.onload = function(e) {
|
||||||
handle('pages.quiz', /^quiz\/[^\/]+?$/);
|
handle('pages.quiz', /^quiz\/[^\/]+?$/);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.script('api');
|
||||||
app.template.loadMany([
|
app.template.loadMany([
|
||||||
'toast.confirm', 'toast.info',
|
'toast.confirm', 'toast.info',
|
||||||
'toast.warn', 'toast.error',
|
'toast.warn', 'toast.error',
|
||||||
|
|
|
@ -181,26 +181,17 @@ app.pages.meet = {
|
||||||
const current = app.pages.meet.dataCurrent();
|
const current = app.pages.meet.dataCurrent();
|
||||||
if (current === undefined || current === null)
|
if (current === undefined || current === null)
|
||||||
return app.toast.error(s('app.error.unknown_error'));
|
return app.toast.error(s('app.error.unknown_error'));
|
||||||
http.post(`/api/v1/accounts/block?url=${current.account.url}`, {}, function(json) {
|
api.account.block(current.account.url, function(json) {
|
||||||
if (json === undefined) return;
|
setTimeout(function() {
|
||||||
if (json.warn !== undefined)
|
for (var i = app.pages.meet.data.length-1; i >= 0; i--)
|
||||||
app.toast.warn(app.strings.app.warn[json.warn]);
|
if (app.pages.meet.data[i].account.url === current.account.url)
|
||||||
else if (json.error !== undefined)
|
app.pages.meet.data.splice(i, 1);
|
||||||
app.toast.error(app.strings.app.error[json.error]);
|
app.pages.meet.carousel.set(0);
|
||||||
else if (json.result !== undefined && json.result === 1) {
|
app.pages.meet.paint();
|
||||||
const n = randomNum(0, 3);
|
const elem = app.pages.meet.carousel._elements()[
|
||||||
app.toast.warn(app.strings.app.ok['discarded_success_'+n]);
|
app.pages.meet.carousel._current];
|
||||||
setTimeout(function() {
|
animateTimeout(elem, 'slide-from-right', 100);
|
||||||
for (var i = app.pages.meet.data.length-1; i >= 0; i--)
|
}, app.toast.DEFAULT_MILLIS);
|
||||||
if (app.pages.meet.data[i].account.url === current.account.url)
|
|
||||||
app.pages.meet.data.splice(i, 1);
|
|
||||||
app.pages.meet.carousel.set(0);
|
|
||||||
app.pages.meet.paint();
|
|
||||||
const elem = app.pages.meet.carousel._elements()[
|
|
||||||
app.pages.meet.carousel._current];
|
|
||||||
animateTimeout(elem, 'slide-from-right', 100);
|
|
||||||
}, app.toast.DEFAULT_MILLIS);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
quiz: function() {
|
quiz: function() {
|
||||||
|
|
Loading…
Reference in New Issue