om/public/routes/home.js

95 lines
2.8 KiB
JavaScript
Raw Normal View History

2018-12-05 16:35:54 +01:00
const HomeRouter = {
2018-12-28 10:18:21 +01:00
template: `
2018-12-19 18:18:42 +01:00
<div id="om-msg-cards">
2018-12-05 16:35:54 +01:00
<MsgCard
v-for="id in messagelist.slice().reverse()"
2018-12-19 18:18:42 +01:00
:key="id"
:msg="messages[id] || {}"
2018-12-05 16:35:54 +01:00
></MsgCard>
</div>`,
2018-12-28 10:18:21 +01:00
data: function () {
return {
messagelist: _messagelist,
messages: _messages,
};
},
methods: {
2019-01-31 19:01:40 +01:00
/*refresh_messages: function () {
2018-12-28 10:18:21 +01:00
_messages.push({ //////// alt
id: 42,
subject: "xxx",
message: "warum habt ihr auch so viel",
user: "nobody",
tags: "foo"
});
2019-01-31 19:01:40 +01:00
},*/
list_messages: function () {
2019-02-08 13:52:48 +01:00
$.ajax({url: "api/ids", method: "GET"})
.done(jd => {
// NICHT SO wg. Vue: _messagelist = jd;
_messagelist.splice(0, _messagelist.length);
_messagelist.push.apply(_messagelist, jd);
2019-02-08 13:40:21 +01:00
console.log("jd: "+jd);
for (var e in jd) {
if (!_messages[jd[e]]) {
get_insert_message(jd[e]);
}
}
/*if(!($".om-searchbar" = "")){
for (var e in jd) {
if (!_messages[jd[e]]) {
get_insert_message(jd[e]);
}
}
}else{
for (var e in jd) {
if (!_messages[jd[e]]) {
get_search_message(jd[e]);
}
}
}*/
}).fail(function (e, f, g) {
console.log("err: " + e + f + g);
});
}
2018-12-28 10:18:21 +01:00
},
2018-12-19 18:18:42 +01:00
mounted: function () {
this.list_messages();
//this.refresh_messages();
2019-01-31 19:01:40 +01:00
}
2018-12-05 16:35:54 +01:00
};
2018-12-28 10:18:21 +01:00
function get_insert_message(id) {
2019-02-08 13:52:48 +01:00
$.ajax({ url: "api/msg/"+id, method: "GET" }).done(function (msg) {
2018-12-28 10:18:21 +01:00
Vue.set(_messages, id, msg);
}).fail(function (e, f, g) {
console.log("cannot load " + id + ".json: " + e + f + g);
})
}
/*function get_search_message(phrase) {
$.ajax({ url: "api/msg/search/"+phrase, method: "GET" }).done(function (msg) {
Vue.set(_messages, id, msg);
}).fail(function (e, f, g) {
console.log("cannot load " + id + ".json: " + e + f + g);
})
}
$(document).ready(function () {
2018-12-28 10:18:21 +01:00
console.log("egal");
$.get('list.json').done(function (jd) {
// _messagelist = jd;
_messagelist.splice(0, _messagelist.length);
_messagelist.push.apply(_messagelist, jd);
console.log("egal2");
//$('#xxx').text(jd[0]);
for (var e in jd) {
if (!_messages[jd[e]]) {
get_insert_message(jd[e]);
}
}
}).fail(function (e, f, g) {
console.log("egal3: " + e + f + g);
});
2019-01-31 19:01:40 +01:00
});*/