om/public/search.js

167 lines
5.1 KiB
JavaScript
Raw Normal View History

Vue.component('search',{
template: `
<form class="om-searchbar" @submit.prevent="search()">
<b-field>
<b-autocomplete
v-model="searchtext"
@keydown.native.enter="search"
:data="filteredDataArray"
placeholder="suche..."
icon="magnify"
2019-07-24 12:36:43 +02:00
@reset-searchtext="resetSearchtext($event)"
@select="option => selected = option">
</b-autocomplete>
<button class="clearButton" @click="clear">x</button>
</b-field>
</form>`,
data: function() {
2019-07-24 12:36:43 +02:00
return {
searchtext: "",
selected: [],
taglist: data,
};
},
computed:{
2019-07-24 12:36:43 +02:00
filteredDataArray: function() {
return this.taglist.filter((option) => {
return option
.toString()
.toLowerCase()
.indexOf(this.searchtext.toLowerCase()) >= 0
2019-07-24 12:36:43 +02:00
});
},
},
methods: {
2019-07-24 12:36:43 +02:00
resetSearchtext: function(param) {
this.searchtext = param;
},
getFilteredTags: function(text) {
this.taglist = data.filter((option) => {
return option
.toString()
.toLowerCase()
.indexOf(text.toLowerCase()) >= 0
})
this.search();
},
search: function() {
2019-07-24 12:36:43 +02:00
var btnString = '';
btnString = searching(this.searchtext, btnString);
console.info(btnString);
this.$emit('update-home-abo-button', btnString);
vueForceRender('key');
},
saveTagsToArray: function() {
tagArray = this.selected;
// console.info(tagArray);
},
list_messages: function() {
messages();
},
list_tags: function () {
$.ajax({url: "api/tag/ids", method: "GET"})
.done(jd => {
// NICHT SO wg. Vue: _messagelist = jd;
if(data == ""){
_taglist.splice(0, _taglist.length);
_taglist.push.apply(_taglist, jd);
// console.log("tag: jd: " + jd);
for (var e in jd) {
if (!_tags[jd[e]]) {
get_insert_tag(jd[e]);
}
}
}
}).fail(function (e, f, g) {
console.log("err: " + e + f + g);
});
},
clear: function() {
2019-07-23 17:34:57 +02:00
this.searchtext = "";
this.list_messages();
2019-07-23 17:34:57 +02:00
//router.push('/files')
//router.push('/home')
2019-07-24 12:36:43 +02:00
_isSearchActiv = false;
_isSubscripeButtonActiv = false;
this.$emit('toggle-escape-search-link');
vueForceRender('key');
console.info('done');
// $("#escape-search-link").css("visibility", "hidden");
// $("#subscribe-btn").css("visibility", "hidden");
},
},
mounted: function() {
//this.search();
this.list_tags();
},
});
// Global Functions !!!
function get_insert_tag(id) {
$.ajax({
url: "api/tag/id/" + id,
method: "GET"
}).done(function(tag) {
2019-07-24 12:36:43 +02:00
data.push('#'+tag.name);
}).fail(function(e, f, g) {
console.log("cannot load " + id + ".json: " + e + f + g);
})
}
2019-07-24 12:36:43 +02:00
function searching(searchtext,btnString) {
2019-07-22 18:40:51 +02:00
_isSearchActiv = true;
2019-07-24 12:36:43 +02:00
// $("#escape-search-link").css("visibility", "visible");
2019-07-23 21:41:27 +02:00
//console.log(_tags);
2019-07-24 12:36:43 +02:00
// console.log(data);
2019-07-23 21:41:27 +02:00
if(data.indexOf(searchtext) > -1){
2019-07-24 12:36:43 +02:00
btnString = searchtext + " abonnieren";
// $("#btn-text").text(btnString);
// $("#subscribe-btn").css("visibility", "visible");
_isSubscripeButtonActiv = true;
2019-07-23 17:34:57 +02:00
}else{
2019-07-24 12:36:43 +02:00
// $("#subscribe-btn").css("visibility", "hidden");
_isSubscripeButtonActiv = false;
2019-07-23 17:34:57 +02:00
}
2019-07-24 12:36:43 +02:00
if (searchtext !== '') {
$.ajax({
url: "api/msg/search/" + searchtext.replace(/#/g, ''),
method: "GET"
}).done(jd => {
// NICHT SO wg. Vue: _messagelist = jd;
_messagelist.splice(0, _messagelist.length);
_messagelist.push.apply(_messagelist, jd);
//console.log("jd: "+jd);
for (var e in jd) {
if (!_messages[jd[e]]) {
get_insert_message(jd[e]);
}
}
2019-07-24 12:36:43 +02:00
}).fail(function(e, f, g) {
console.log("searching: err: " + e + f + g);
})
}
return btnString;
}
function messages() {
$.ajax({
url: "api/msg/ids",
method: "GET"
})
.done(jd => {
// NICHT SO wg. Vue: _messagelist = jd;
_messagelist.splice(0, _messagelist.length);
_messagelist.push.apply(_messagelist, jd);
//console.log("jd: "+jd);
for (var e in jd) {
if (!_messages[jd[e]]) {
get_insert_message(jd[e]);
}
}
}).fail(function(e, f, g) {
console.log("list_msg: err: " + e + f + g);
});
}