Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Observable = require("FuseJS/Observable");
- var geoLocation = require('FuseJS/GeoLocation');
- var ROOT_URL = "http://192.168.1.56:180/yz/wp-json/wp/v2/";
- var path = Observable("");
- var options = Observable("");
- var YZallPosts = Observable("Hallo");
- var YZ_NewTitle = Observable("");
- var YZ_NewContent = Observable("");
- var YZ_NewDate = Observable("");
- var yzzoom = Observable(13);
- // var yzgeo = Observable();
- var yzgeo2 = Observable('Aktueller Standort');
- var yzlat = Observable(51.9303675);
- var yzlon = Observable(6.950763000000052);
- var YZ_ADDRESS = "Test";
- function apiFetch(path, options) {
- // console.log("Go2");
- var url = encodeURI(ROOT_URL + path);
- // console.log(url);
- if(options === undefined) {
- options = {};
- }
- console.log(options.value);
- // If a body is provided, serialize it as JSON and set the Content-Type header
- if(options.body !== undefined) {
- // console.log(options);
- options = Object.assign({}, options, {
- body: JSON.stringify(options.body),
- headers: Object.assign({}, options.headers, {
- "Content-Type": "application/json"
- })
- });
- }
- // Fetch the resource and parse the response as JSON
- return fetch(url, options)
- // .then(function(response) { return response.json(); });
- // oder
- // .then(function(response) { console.log(JSON.stringify(response)) });
- .then(function(response) {
- // YZallPosts.value = JSON.stringify(response)
- });
- }
- /*
- function YZpostNEW(title, contents) {
- return apiFetch("posts", {
- method: "POST",
- body: {
- title: title,
- contents: contents
- }
- });
- }
- */
- function YZpostNEW() {
- var YZ_TITEL = JSON.stringify(YZ_NewTitle._values).replace("[", "").replace("]", "").replace("\"", "").replace("\"", "");
- var YZ_CONTENT = JSON.stringify(YZ_NewContent._values).replace("[", "").replace("]", "").replace("\"", "").replace("\"", "");
- var YZ_DATUM = JSON.stringify(YZ_NewDate._values).replace("[", "").replace("]", "").replace("\"", "").replace("\"", "");
- var YZ_LONG = JSON.stringify(yzlon.value).replace("\"", "").replace("\"", "");
- var YZ_LAT = JSON.stringify(yzlat.value).replace("\"", "").replace("\"", "");
- console.log('YZ_ADDRESS1:'+YZ_ADDRESS);
- fetch('http://maps.googleapis.com/maps/api/geocode/json?latlng='+YZ_LAT+','+YZ_LONG)
- .then(function(response) { return response.json(); })
- .then(function(responseObject) {
- var i=1;
- responseObject.results.forEach(function(item){
- if (i == 1) {
- // console.log('YZ_ADDRESS1337:'+JSON.stringify(item.formatted_address));
- YZ_ADDRESS2=JSON.stringify(item.formatted_address);
- console.log('YZ_ADDRESS3:'+YZ_ADDRESS2);
- i++;
- }
- YZ_ADDRESS=YZ_ADDRESS2;
- // data3.add(JSON.stringify(responseObject));
- })
- });
- console.log(JSON.stringify(YZ_TITEL) + YZ_LONG + " " + YZ_LAT) + YZ_ADDRESS;
- // var YZ_TEST= YZ_TEST1.node.data.YZallPosts._values
- return apiFetch("posts", {
- method: "POST",
- headers: {
- "Authorization": "Basic QmxhZGU6YXNk",
- "Content-Type": "application/json"
- },
- body:
- {
- "title": {
- "raw": YZ_TITEL,
- "rendered": YZ_TITEL
- },
- "status": "publish",
- "content": {
- "raw": YZ_CONTENT,
- "rendered": YZ_CONTENT
- },
- "acf_fields": {
- "datum": YZ_DATUM,
- "icon": "YZjob/images/icons/aufbau.png",
- "iconpanel": "images/icons/aufbau.png",
- "location": {
- "address": YZ_ADDRESS,
- "lat": YZ_LAT,
- "lng": YZ_LONG
- }
- }
- }
- });
- }
- function clear() {
- YZallPosts.value = ""
- }
- function getAllArticles() {
- console.log("OK");
- return apiFetch("posts");
- }
- module.exports = {
- apiFetch: apiFetch,
- getAllArticles: getAllArticles,
- YZallPosts: YZallPosts,
- clear: clear,
- YZ_NewTitle: YZ_NewTitle,
- YZpostNEW: YZpostNEW,
- YZ_NewContent: YZ_NewContent,
- YZ_NewDate: YZ_NewDate,
- yzgeo2: yzgeo2,
- yzlat: yzlat,
- yzlon: yzlon,
- yzzoom:yzzoom,
- yzgeo: function yzgeo() {
- var timeout = 4000;
- geoLocation.getLocation(timeout).then(function(location) {
- yzlat.value = JSON.stringify(location.latitude)
- yzlon.value = JSON.stringify(location.longitude);
- yzzoom.value = '15';
- console.log('lat:'+yzlat+' lon:'+yzlon);
- yzgeo2.value=JSON.stringify(location);
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement