FileSaver.js is saving .ics as .txt on iPhones - javascript

I'm trying to save a blob as name.ics, but for some reason on iPhone they all get saved as name.ics.txt
This is the code
// Creating event template for ICS file
const event = {
start: startAt,
end: endAt,
title: !location ? "Appointment " + appointment.appointmentType + " " + appointment.sessionName : "Appointment",
description: "Your Practitionier: " + appointment.practitionerName,
location: !location ? appointment.locationName + ", " + addressString + ", " + postalCode : location,
status: "CONFIRMED",
alarms: [
{
action: "display",
description: "Appointment",
trigger: { hours: reminder.hours, minutes: reminder.minutes, before: true },
},
],
};
// Event handlers
const handleSave = () => {
createEvent(event, (error, value) => {
const blob = new Blob([value], { type: "text/plain;charset=utf-8" });
saveAs(blob, "event-schedule.ics");
});
};

Related

How can i display massages based on the user who sent and received the message

I don't know what's wrong with my code am not getting the intended output. Anybody to lend a helping hand and I'll really appreciate it.
If append the row class inside the for loop am getting all the messages but you can't differentiate who sent and who received and when I append the class outside the for loop am only getting one message.
xhr.onload = function () {
var messages = [
{ id: 36, message: "hay here", username: null, senderId: 1, receiverId: 9 },
{ id: 38, message: "hay there again", username: null, senderId: 1, receiverId: 9 },
{ id: 37, message: "yes hay", username: null, senderId: 9, receiverId: 1 },
];
var rowClass = "";
for (var message = 0; message < messages.length; message++) {
if (messages[message].senderId === messages[message].senderId) {
rowClass =
'<div style="text-align:right">' +
'<p style="background-color:lightblue">' +
mymessages[message].message +
"</p>" +
"<div>";
} else {
rowClass =
'<div style="text-align:left">' + '<p style="background-color:green">';
messages[message].message;
"</p>" + "<div>";
}
}
$(".message").append(rowClass);
};
You need to check whether the current user's id is same as that of the message, for example:
const currentUserId = 9;
var messages = [
{ id: 36, message: "hay here", username: null, senderId: 1, receiverId: 9 },
{ id: 38, message: "hay there again", username: null, senderId: 1, receiverId: 9 },
{ id: 37, message: "yes hay", username: null, senderId: 9, receiverId: 1 },
];
var rowClass = "";
for (var message = 0; message < messages.length; message++) {
if (messages[message].senderId === currentUserId) {
rowClass +=
'<div style="text-align:right">' +
'<p style="background-color:lightblue">' +
messages[message].message +
"</p>" +
"<div>";
} else {
rowClass +=
'<div style="text-align:left">' +
'<p style="background-color:green">' +
messages[message].message +
"</p>" +
"<div>";
}
}
$(".message").append(rowClass);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="message"></div>

Global Count Variable not increasing

For some reason, I cannot get my global variable counter to increase, even when it increases within the function I have the count++ occurring in. My outputted results are different between the text outputted within the function and the text outside of it. Any idea what I am doing wrong here? Shouldn't the count increase on each iteration of the survey.oncomplete function results?
Survey
.StylesManager
.applyTheme("modern");
var kn2 = "LwrHXqFRN_pszCopTKHF_Q"
var kn3 = "exroCUoYl4wVzs7pKU_49w"
var count = 0
var keyname = ("kn" + count)
var mapilink = "https://images.mapillary.com/" + (keyname) + "/thumb-1024.jpg";
var json = {
pages: [
{
name: "page1",
elements: [
{
type: "image",
name: "image",
imageLink: (mapilink),
imageHeight: 580,
imageWidth: 640
},
{
type: "html",
name: (keyname),
visible: false,
html: (keyname)
},
{
type: "rating",
name: "Walkability",
title: "How walkable does this look to you"
},
{
type: "rating",
name: "Saftey",
title: "How safe does this look to you"
},
{
type: "rating",
name: "Comfortability",
title: "How comfortable does this look to you"
}
]
}
]
}
window.survey = new Survey.Model(json);
var username = document.getElementById("user").value;
survey
.onComplete
.add(function (result) {
count ++;
var PID = document.getElementById("user").value;
var results = PID + "_" + (keyname) + ":\n" + JSON.stringify(result.data, null, 3) + (count) ;
document
.querySelector('#surveyResult')
.textContent = results;
survey.clear();
survey.render();
});
$("#surveyElement").Survey({model: survey});
Got an answer from a seperate stackexchange post - basically, I needed to wrap everything in more functions.
function outputting function text rather than expected output

How to send JSON object as string for email

I am trying to send an email with JSON data being pulled in by default, the problem I ma having is in my mail once received I only see the object and not the value. Any ideas?
link to my site : http://wingfield.vmgdemo.co.za/
What I get in my received mail:
Make: {{car.make}}
Variant: {{car.variant}}
Year: {{car.year}}
Price: {{car.selling_price}}
My input:
<input type="text" ng-model="vm.drive.make" class="form-control" name="make" id="make" ng-init="vm.drive.make='{{car.make}}'" value="{{car.make}}">
My controller for mail:
(function() {
'use strict';
var controllerId = 'testDrive';
var app = angular.module('app').controller(controllerId, testDrive);
function testDrive($scope) {
var vm = this;
vm.drive = {
name: '',
number: '',
email: '',
message: '',
make: '',
variant: '',
year: '',
selling_price: ''
};
vm.sendMail = function sendEmail() {
var driveRequest = '';
var data = {
notification: {
ToList: '',
CcList: '',
BccList: '',
Subject: 'Contact from ' + vm.drive.name,
Message: vm.drive.message + '\nContact Number: ' + vm.drive.number + '\n\nInterested In:' + '\nID: ' + vm.drive.carid + '\nMake: ' + vm.drive.make + '\nVariant: ' + vm.drive.variant + '\nYear: ' + vm.drive.year + '\nPrice: ' + vm.drive.selling_price,
MessageSubject: 'Enquiry from ' + vm.drive.name,
ToName: 'Wingfield Motors',
FromName: vm.drive.name,
FromEmail: vm.drive.email
}
};
driveRequest = JSON.stringify(data);
$.ajax({
"url": "--REMOVED--",
"method": "POST",
"headers": {
"content-type": "application/json",
"accept": "application/json"
},
data: driveRequest,
dataType: "json",
success: function(response) {
//
},
error: function(response) {
//
}
});
};
}
})();

x-editable custom fields cannot get text of select menu

Ive followed this example from another SO thread:
X-editable custom field type not respecting overridden defaults
and its helped me to create a similar custom field with x-editable. All is working ok but i cant figure out how render/display the 'text' of the select - the SO example ouputs the 'value'. my js to initialis the x-editable to use my custom inputs is thus:
$('#stffulladdress').editable({
url : '',
pk : 6,
value : {
address : "",
city : "",
region : "",
postcode : "",
country : "eng"
},
sourceCountry: [
{ value: "eng", text: "ENGLAND" },
{ value: "ire", text: "IRELAND" },
{ value: "sco", text: "SCOTLAND" },
{ value: "cym", text: "WALES" }
],
validate : function(value) {
if (value.address == '' || value.postcode == '') return "Address first lines AND Postcode required";
},
display : function(value) {
if (!value) {
$(this).empty();
return;
}
console.log(value.country);
var html = $('<div>').html( value.address + '<br />' + value.city + '<br />' + value.region + '<br />' + value.postcode + '<br />' + value.country );
$(this).html(html);
}
});
My custom x-editable class is the same as the SO example mentioned with the only difference being i have more inputs -they work ok as expected. I would have thought that this snippet from the x-edit class gets the text of the selected item:
value2html: function(value, element) {
if(!value) {
$(element).empty();
return;
}
var countryText = value.country;
$.each(this.sourceCountryData, function (i, v) {
if (v.value == countryText) {
countryText = v.text.toUpperCase();
}
});
var html = $('<div>').html( value.address + ',<br />' + value.city + ',<br />' + value.region + ',<br />' + value.postcode + ',<br />' + countryText );
$(element).html(html);
},
But upn displaying the selected country i still get the country value "eng" and not the text "England".
I've tried :
value.country which gives me the value 'eng'
and value.text gives undefined
Any idea how i can get the selected text??
thanks
Try the sourceCountry as follow:
sourceCountry: [
{ "eng": "ENGLAND" },
{ "ire": "IRELAND" },
{ "sco": "SCOTLAND" },
{ "cym": "WALES" }
],

Node Js Steam Trade Offers Bot Items

This bot accept all trades but it need to accept only trade offers which contains [type: 'Consumer Grade SMG',] item in itemsToReceive. I was trying to do something like: If itemsToReceive contains Consumer Grade SMG then accpet offer else cancel offer but i failed. Im newby and i dont have any idea how to do that.
Sorry for my bad english.
My output console:
New offer #644673626 from [U:1:205839253]
[ { appid: 730,
contextid: { low: 2, high: 0, unsigned: true },
assetid: '3142560367',
classid: '310777708',
instanceid: '302028390',
amount: 1,
missing: true,
id: '3142560367',
icon_url: '-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4oFJZEHL
bXH5ApeO4YmlhxYQknCRvCo04DEVlxkKgpopuP1FBRw7ODYYzxb08-3moS0m_7zO6-fxzNQ65J03L2Vo
9-sigzj_kU6Mmr6LIKVdwNvZVHTqVTqxri8jZS4tYOJlyVoTeLjug',
icon_url_large: '-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4o
FJZEHLbXH5ApeO4YmlhxYQknCRvCo04DEVlxkKgpopuP1FBRw7ODYYzxb08-3moS0m_7zO6_ummpD78A
_27HA9tvw3gDg_UBlMWH0IYDDIwU3aVzQ_1Tvxefs1pPou8uawXBnsz5iuyjoOPjz8g',
icon_drag_url: '',
name: 'P90 | Sand Spray',
market_hash_name: 'P90 | Sand Spray (Minimal Wear)',
market_name: 'P90 | Sand Spray (Minimal Wear)',
name_color: 'D2D2D2',
background_color: '',
type: 'Consumer Grade SMG',
tradable: true,
marketable: true,
commodity: false,
market_tradable_restriction: 7,
fraudwarnings: '',
descriptions:
{ '0': [Object],
'1': [Object],
'2': [Object],
'3': [Object],
'4': [Object],
'5': [Object] },
owner_descriptions: '',
actions: { '0': [Object] },
market_actions: { '0': [Object] },
tags:
{ '0': [Object],
'1': [Object],
'2': [Object],
'3': [Object],
'4': [Object],
'5': [Object] } } ]
Offer accepted
Offer #644673626 changed: Active -Accepted
Received: P90 | Sand Spray
And bot code:
/**
* STOREHOUSE - node-steam
*
* Uses node-steam-user for notifications and accepts all incoming trade offers
*/
var SteamUser = require('steam-user');
var TradeOfferManager = require('../lib/index.js'); // use require('steam-tradeoffer-manager') in production
var fs = require('fs');
var client = new SteamUser();
var manager = new TradeOfferManager({
"steam": client, // Polling every 30 seconds is fine since we get notifications from Steam
"domain": "example.com", // Our domain is example.com
"language": "en" // We want English item descriptions
});
// Steam logon options
var logOnOptions = {
"accountName": "xxxxx",
"password": "xxxxx"
};
if(fs.existsSync('polldata.json')) {
manager.pollData = JSON.parse(fs.readFileSync('polldata.json'));
}
client.logOn(logOnOptions);
client.on('loggedOn', function() {
console.log("Logged into Steam");
});
client.on('webSession', function(sessionID, cookies) {
manager.setCookies(cookies, function(err) {
if(err) {
console.log(err);
process.exit(1); // Fatal error since we couldn't get our API key
return;
}
console.log("Got API key: " + manager.apiKey);
});
});
manager.on('newOffer', function(offer) {
console.log("New offer #" + offer.id + " from " + offer.partner.getSteam3RenderedID());
console.log(offer.itemsToReceive);
offer.accept(function(err) {
if(err) {
console.log("Unable to accept offer: " + err.message);
} else {
console.log("Offer accepted");
}
});
});
manager.on('receivedOfferChanged', function(offer, oldState) {
console.log("Offer #" + offer.id + " changed: " + TradeOfferManager.getStateName(oldState) + " -> " + TradeOfferManager.getStateName(offer.state));
if(offer.state == TradeOfferManager.ETradeOfferState.Accepted) {
offer.getReceivedItems(function(err, items) {
if(err) {
console.log("Couldn't get received items: " + err);
} else {
var names = items.map(function(item) {
return item.name;
});
console.log("Received: " + names.join(', '));
}
});
}
});
manager.on('pollData', function(pollData) {
fs.writeFile('polldata.json', JSON.stringify(pollData));
});
Have try.
manager.on('newOffer', function(offer) {
console.log("New offer #" + offer.id + " from " + offer.partner.getSteam3RenderedID());
console.log(offer.itemsToReceive);
for(var i = 0; i > offer.itemsToReceive.length)
{
if(offer.itemsToReceive[i]['type'] != "Consumer Grade SMG")
{
return;
if(i == offer.itemsToReceive.length)
{
offer.accept(function(err){
if(err){
console.log("Unable to accept offer: " + err.message);
}
else{
console.log("Offer accepted");
}
});
}
}
}
});

Categories

Resources