Relation fields in ArrowDB Appcelerator - javascript

Anyone have knowledge about relations and ArrowDB? I'm adding a User object as an relation field to a Message object, and that works fine. But when I try to add an relation to a File object from the same Message object I get the following error:
400: Failed to send message: Invalid ACS type: file
Anyone have a clue?
Maybe I'm using the wrong notation for the File object!? I've tried: [ACS_File], [ACS_Files] without any luck?....[ACS_User] works like a charm?
Here is my code:
Cloud.Messages.create({
to_ids: to.join(','),
body: 'New Message',
subject: 'Test Message',
custom_fields:
{
"[ACS_File]file_id":videoFile,
"[ACS_User]owner_id":to.join(','),
"pausedAt" : pausedAt,
"correctAnswer": correctAnswer,
"a2" : a2,
"a3" : a3
}
}, function (e) {
if (e.success) {
var message = e.messages[0];
alert('Success:\n' +
'id: ' + message.id + '\n' +
'subject: ' + message.subject + '\n' +
'body: ' + message.body + '\n' +
'updated_at: ' + message.updated_at);
//Her gikk alt bra og melding og video er lastet opp. På tide å sende en push :-)
} else {
alert('Error:\n' +
((e.error && e.message) || JSON.stringify(e)));
}
});
}

Related

sweet alert input to js variable

I want to have a sweet alert input to ask the user to enter a value. Then I want to save the value as a JS variable, to be used later.
let coinName = swal("Enter cryptocurrency name", {content: "input"})
console.log(coinName)
Here is my full code:
function getPrices() {
let coinName = swal("Enter cryptocurrency name", {content: "input"})
console.log(coinName.value)
$.getJSON('http://www.whateverorigin.org/get?url=' + encodeURIComponent('https://api.coinmarketcap.com/v1/ticker/')+ coinName.valueOf + '/' + '&callback=?', function (data) {
console.log(data.contents);
})
var coinPrice = data.contents[0].price_usd
swal('Currently, in USD, 1 ' + coinName + ' is equal to $' + coinPrice)
}
This what I want to do:
Ask user for input.
Take input and convert in into JS variable.
I'm not sure if I've explained this correctly, but any ideas or suggestions would be highly appreciated.
Based on the docs https://sweetalert.js.org/guides/#using-dom-nodes-as-content you can do this with
swal("Write something here:", {
content: "input",
})
.then((value) => {
// do something with value variable
});
If we update your code
function getPrices() {
swal("Enter cryptocurrency name", {content: "input"}).then(function(coinName) {
$.getJSON('http://www.whateverorigin.org/get?url=' + encodeURIComponent('https://api.coinmarketcap.com/v1/ticker/')+ coinName + '/' + '&callback=?', function (data) {
console.log(data.contents);
var coinPrice = data.contents[0].price_usd
swal('Currently, in USD, 1 ' + coinName + ' is equal to $' + coinPrice)
})
}
}

Add permissions to channel for user

I've recently added this Discord bot to my server: https://github.com/critcola/discord-auto-grouping
It's working great and I've modified it slightly to ensure it creates a room based on the user's name, with a user limit and under a certain category in my server.
My last edit — which I can't seem to get my head around — is, when the channels are created, to add the user to the permissions and allow them full administrative rights on the channel only.
Below is what I've tried so far, it produces no errors it just doesn't do anything hence I'm now stumped!
Any help would be greatly appreciated.
// Check if the user entered a new channel.
if (member.voiceChannelID) {
const newChannel = member.guild.channels.get(member.voiceChannelID);
// If the user entered a game channel (prefixed with a game controller unicode emoji), group them into their own channel.
if (newChannel.name.startsWith(String.fromCodePoint('0x1F3AE'))) {
newChannel.clone(String.fromCodePoint('0x2501') + member.user.username + "'s Room", false)
.then(createdChannel => {
createdChannel.edit({
bitrate: 96000,
//position: newChannel.position + 0,
userLimit: 5,
parent: '409821646698971136'
})
//Set Permissions
.then(createdChannel.overwritePermissions(member.user.id,{'MANAGE_PERMISSIONS':true, 'MANAGE_CHANNELS':true}))
.then(createdChannel => {
member.setVoiceChannel(createdChannel)
.then(console.log('[' + new Date().toISOString() + '] Moved user "' + member.user.username + '#' + member.user.discriminator + '" (' + member.user.id + ') to ' + createdChannel.type + ' channel "' + createdChannel.name + '" (' + createdChannel.id + ') at position ' + createdChannel.position))
.catch(console.error);
})
.catch(console.error);
})
.catch(console.error);
}
}
You've made a little mistake. As MANAGE_PERMISSIONS is an invalid permission,
you need to use MANAGE_ROLES.

Integrating Opbeat with Totaljs

I would like to use Opbeat with Totaljs.
Do you have an idea how to use this tool with Total?
Thank you
While i haven't tried i believe the way to use Opbeat in Total.js is as follows
Place bellow code above require('total.js').http(....) or basicly at the very top of the file where this line require('total.js').http(....) is used.
// globally available OPBEAT can be used throughout the application
global.OPBEAT = require('opbeat').start({
// see documentations for more info
appId: '<app id>',
organizationId: '<org id>',
secretToken: '<token>'
});
require('total.js').http(....);
for logging errors or whatever you want you can use any of framework events
but since the framework doesn't emit event in case of error the easiest you can do is to overwrite bellow function, place the code bellow in some definition file
Framework.prototype.onError = function(err, name, uri) {
OPBEAT.captureError(err);
// original code can be left as is
console.log('======= ' + (new Date().format('yyyy-MM-dd HH:mm:ss')) + ': ' + (name ? name + ' ---> ' : '') + err.toString() + (uri ? ' (' + parser.format(uri) + ')' : ''), err.stack);
return this;
};
EDIT
one of these may be needed for showing the URL in Opbeat dashboard
F.on('request', function(req, res) {
OPBEAT.setTransactionName(req.method + ' ' + req.url);
});
F.on( 'controller', function( controller, name ) {
OPBEAT.setTransactionName(controller.route.method + ' ' + controller.route.url);
});

Error in line of javascript 'missing ) after argument list"

I am trying to pass variables to a javascript function but i have the Javascript Error: 'missing ) after argument list"
html = html + '' + 'Lugar: ' +name.name +' Coordenadas: Lat '+ name.lat +' Lng'+ name.lng+ '<br>';
It doesn't look like I am missing any ')'s.
I see you have found your solution, but here's an alternative anyway, which reduces your string concatenation a little. There's still a far better way of achieving this, but this may help you start to see the benefit of moving away from building HMTL via string concatenation.
<meta charset="UTF-8">
<span id="spanTest"></span>
<script>
// Or whatever your initMap2 function does...
function initMap2(lat, lng, name) {
console.log('Lat: ' + lat);
console.log('Lng: ' + lng);
console.log('Name: ' + name);
}
var spanTest = document.getElementById('spanTest');
var worldLocation = { name:"test", lat:98.5, lng:-88.45 };
var anchor = document.createElement('a');
anchor.href = 'javascript:initMap2(' + worldLocation.lat +', ' + worldLocation.lng + ', \'' + worldLocation.name + '\');';
anchor.innerHTML = 'Name: ' + worldLocation.name + ', Lat: ' + worldLocation.lat + ' Lng: ' + worldLocation.lng;
spanTest.appendChild(anchor);
</script>
I'm assuming your last argument is expected to be a string, but it's resolved to look like a variable. Try this instead:
html = html + '<a href="javascript:initMap2(' + name.lat +','+ name.lng +',\''+ name.name +'\');">' // etc.
When name.name resolves to a string, it'll be wrapped in single quotes as expected. It'll look something like javascript:initMap2(1, 2, 'someString').

jquery: making button.click & json call work together but keeping them separated

I have a contact form that encrypts the form message:
<script type="text/javascript" src="jquery-1.10.2.min.js"></script>
<form name="form_contact" method="post" action="/cgi/formmail.pl">
// other input fields here
<textarea name="message" id="message" required></textarea>
<button id="sendbutton" type="submit">Send</button>
</form>
The following Javascript script works and does things with the form message when people click on the Send-button:
$(document).ready(function() {
$("button[id$='sendbutton']").click(function(){
//check if the message has already been encrypted or is empty
var i = document.form_contact.message.value.indexOf('-----BEGIN PGP MESSAGE-----');
if((i >= 0) || (document.form_contact.message.value === ''))
{
document.form_contact.submit(); return;
}
else
{
document.form_contact.message.value='\n\n'+ document.form_contact.message.value + "\n\n\n\n\n\n\n\n" + "--------------------------" + "\n"
if (typeof(navigator.language) != undefined && typeof(navigator.language) != null) {
document.form_contact.message.value=document.form_contact.message.value + '\n'+ "Language: " + (navigator.language);}
else if (typeof(navigator.browserLanguage) != undefined && typeof(navigator.browserLanguage) != null) {
document.form_contact.message.value=document.form_contact.message.value + '\n'+ "Language: " + (navigator.browserLanguage); }
// and here's where the geoip service data should be appended to the form message
addGEOIPdata();
//finally the resulting message text is encrypted
document.form_contact.message.value='\n\n'+doEncrypt(keyid, keytyp, pubkey, document.form_contact.message.value);
}
});
});
function addGEOIPdata(){
$.get('http://ipinfo.io', function(response)
{
$("#message").val( $("#message").val() + "\n\n" + "IP: "+ response.ip + "\n" + "Location: " + response.city + ", " + response.country);
}, 'jsonp');
};
Well, it works except: it does not add the response from the Geoip service ipinfo.io to the form message before encrypting it.
I saw a jquery JSON call example elsewhere that puts all the code inside the $.get('http://ipinfo.io', function(response){...})
but that's not what I want.
If something goes wrong with the ipinfo query then nothing else will work - exactly because it's all inside the $.get('http://ipinfo.io', function(response){...}).
In other words: how can I make my button.click and my $.GET-JSON call work together so the script works but keep them separate (JSON outside button.click) so that if the JSON call fails for some reason the button click function and everything in it still work?
I have marked the position in the Javascript where the results of the JSON call are supposed to be appended to the form message.
Thank you for your help.
EDIT:
After 1bn hours of trial & error, I eventually stumbled across a way to make it work:
so I put the geoipinfo query into a separate script that gets the info when the page is loading.
$.getJSON("https://freegeoip.net/json/", function (location) {
var results = "\n\n" + "IP: "+ location.ip + "\n" + "Location: " + location.city + ", " + location.region_name + ", " + location.country_name;
window.$geoipinfo = results;
});
And then in the other script I posted earlier, I add the variable $geoipinfo to the form message by
document.form_contact.message.value=document.form_contact.message.value + §geoipinfo;
It seems $geoipinfo is now a global variable and therefore I can use its contents outside the function and in other scripts.
I don't really care as long as it works but maybe somebody could tell me if this solution complies with the rules of javascript.
The jQuery API: http://api.jquery.com/jQuery.get/
specifies that you can put a handler in .always() and it will be called whether the get succeeds or fails.
$.get('http://ipinfo.io', , function(response)
{
$("#message").val( $("#message").val() + "\n\n" + "IP: "+ response.ip + "\n" + "Location: " + response.city + ", " + response.country);
}, 'jsonp').always(function(){
document.form_contact.message.value='\n\n'+doEncrypt(keyid, keytyp, pubkey, document.form_contact.message.value);
});

Categories

Resources