Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 KB | None | 0 0
  1. var Observable = require("FuseJS/Observable");
  2. var geoLocation = require('FuseJS/GeoLocation');
  3. var ROOT_URL = "http://192.168.1.56:180/yz/wp-json/wp/v2/";
  4. var path = Observable("");
  5. var options = Observable("");
  6. var YZallPosts = Observable("Hallo");
  7. var YZ_NewTitle = Observable("");
  8. var YZ_NewContent = Observable("");
  9. var YZ_NewDate = Observable("");
  10. var yzzoom = Observable(13);
  11. // var yzgeo = Observable();
  12. var yzgeo2 = Observable('Aktueller Standort');
  13. var yzlat = Observable(51.9303675);
  14. var yzlon = Observable(6.950763000000052);
  15. var YZ_ADDRESS = "Test";
  16.  
  17.  
  18. function apiFetch(path, options) {
  19. // console.log("Go2");
  20. var url = encodeURI(ROOT_URL + path);
  21. // console.log(url);
  22. if(options === undefined) {
  23. options = {};
  24. }
  25. console.log(options.value);
  26. // If a body is provided, serialize it as JSON and set the Content-Type header
  27. if(options.body !== undefined) {
  28. // console.log(options);
  29. options = Object.assign({}, options, {
  30. body: JSON.stringify(options.body),
  31. headers: Object.assign({}, options.headers, {
  32. "Content-Type": "application/json"
  33. })
  34. });
  35.  
  36. }
  37.  
  38. // Fetch the resource and parse the response as JSON
  39. return fetch(url, options)
  40. // .then(function(response) { return response.json(); });
  41. // oder
  42. // .then(function(response) { console.log(JSON.stringify(response)) });
  43. .then(function(response) {
  44. // YZallPosts.value = JSON.stringify(response)
  45. });
  46. }
  47.  
  48. /*
  49. function YZpostNEW(title, contents) {
  50. return apiFetch("posts", {
  51. method: "POST",
  52. body: {
  53. title: title,
  54. contents: contents
  55. }
  56. });
  57. }
  58. */
  59.  
  60. function YZpostNEW() {
  61.  
  62. var YZ_TITEL = JSON.stringify(YZ_NewTitle._values).replace("[", "").replace("]", "").replace("\"", "").replace("\"", "");
  63. var YZ_CONTENT = JSON.stringify(YZ_NewContent._values).replace("[", "").replace("]", "").replace("\"", "").replace("\"", "");
  64. var YZ_DATUM = JSON.stringify(YZ_NewDate._values).replace("[", "").replace("]", "").replace("\"", "").replace("\"", "");
  65. var YZ_LONG = JSON.stringify(yzlon.value).replace("\"", "").replace("\"", "");
  66. var YZ_LAT = JSON.stringify(yzlat.value).replace("\"", "").replace("\"", "");
  67.  
  68. console.log('YZ_ADDRESS1:'+YZ_ADDRESS);
  69. fetch('http://maps.googleapis.com/maps/api/geocode/json?latlng='+YZ_LAT+','+YZ_LONG)
  70. .then(function(response) { return response.json(); })
  71. .then(function(responseObject) {
  72. var i=1;
  73. responseObject.results.forEach(function(item){
  74. if (i == 1) {
  75. // console.log('YZ_ADDRESS1337:'+JSON.stringify(item.formatted_address));
  76. YZ_ADDRESS2=JSON.stringify(item.formatted_address);
  77.  
  78. console.log('YZ_ADDRESS3:'+YZ_ADDRESS2);
  79. i++;
  80. }
  81. YZ_ADDRESS=YZ_ADDRESS2;
  82. // data3.add(JSON.stringify(responseObject));
  83. })
  84. });
  85.  
  86. console.log(JSON.stringify(YZ_TITEL) + YZ_LONG + " " + YZ_LAT) + YZ_ADDRESS;
  87. // var YZ_TEST= YZ_TEST1.node.data.YZallPosts._values
  88.  
  89. return apiFetch("posts", {
  90. method: "POST",
  91. headers: {
  92. "Authorization": "Basic QmxhZGU6YXNk",
  93. "Content-Type": "application/json"
  94. },
  95. body:
  96. {
  97. "title": {
  98. "raw": YZ_TITEL,
  99. "rendered": YZ_TITEL
  100. },
  101. "status": "publish",
  102. "content": {
  103. "raw": YZ_CONTENT,
  104. "rendered": YZ_CONTENT
  105. },
  106. "acf_fields": {
  107. "datum": YZ_DATUM,
  108. "icon": "YZjob/images/icons/aufbau.png",
  109. "iconpanel": "images/icons/aufbau.png",
  110. "location": {
  111. "address": YZ_ADDRESS,
  112. "lat": YZ_LAT,
  113. "lng": YZ_LONG
  114. }
  115. }
  116. }
  117. });
  118.  
  119. }
  120.  
  121. function clear() {
  122. YZallPosts.value = ""
  123. }
  124.  
  125. function getAllArticles() {
  126. console.log("OK");
  127. return apiFetch("posts");
  128. }
  129.  
  130.  
  131. module.exports = {
  132. apiFetch: apiFetch,
  133. getAllArticles: getAllArticles,
  134. YZallPosts: YZallPosts,
  135. clear: clear,
  136. YZ_NewTitle: YZ_NewTitle,
  137. YZpostNEW: YZpostNEW,
  138. YZ_NewContent: YZ_NewContent,
  139. YZ_NewDate: YZ_NewDate,
  140. yzgeo2: yzgeo2,
  141. yzlat: yzlat,
  142. yzlon: yzlon,
  143. yzzoom:yzzoom,
  144. yzgeo: function yzgeo() {
  145. var timeout = 4000;
  146. geoLocation.getLocation(timeout).then(function(location) {
  147. yzlat.value = JSON.stringify(location.latitude)
  148. yzlon.value = JSON.stringify(location.longitude);
  149. yzzoom.value = '15';
  150. console.log('lat:'+yzlat+' lon:'+yzlon);
  151. yzgeo2.value=JSON.stringify(location);
  152. });
  153. }
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement