-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItemsView.qml
77 lines (58 loc) · 3.03 KB
/
ItemsView.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import "js/constants.js" as constants;
import "ItemDelegate.qml";
GridView {
id: itemsView;
delegate: ItemDelegate {}
model: ListModel { id: itemsModelMain; }
function loadData(url) {
itemsView.loading = true;
var request = new XMLHttpRequest();
empty.visible = false;
request.onreadystatechange = function() {
if (request.readyState !== XMLHttpRequest.DONE)
return;
if (request.status && request.status === 200) {
log("response was received");
itemsModelMain.reset();
log(request.responseText);
if(request.responseText != "0 results[]"){
var catalog = JSON.parse(request.responseText);
catalog["data"].forEach(function (catalogItem) {
log(catalogItem["list_id"] + " " + catalogItem["list_title"]);
itemsModelMain.append( { id: catalogItem["list_id"],
type: "recomend",
title: catalogItem["list_title"],
description: catalogItem["list_about"],
kkal: catalogItem["list_kkal"] + "к.",
porsiya: catalogItem["list_porsiya"],
time: catalogItem["list_time"]+"м.",
poster: "https://icookserver.online/imgs/items/"+catalogItem["list_id"]+"_circle.png" } );
});
itemsView.loading = false;
itemsView.setFocus();
}else{
if (itemsList.p == "search") {
toast.show("Поиск не дал результатов", 2500);
itemsList.visible = false;
topItemsView.setFocus();
}else{
empty.visible = true;
itemsView.loading = false;
mainMenu.setFocus();
}
}
log("catalog was updated");
} else
log("unhandled status", request.status);
}
request.open("GET", url, true);
request.send();
log("request was sended:"+url);
}
property bool loading: false;
cellWidth: constants.itemTop["width"] + 10;
cellHeight: constants.itemTop["height"];
visible: !loading;
focus: true;
clip: true;
}