mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-03-01 10:37:43 +00:00
Save the Device ID (ident) in credentials
This commit is contained in:
parent
022ec67ea7
commit
3e854d63d7
@ -38,6 +38,7 @@
|
||||
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="pushbullet">
|
||||
@ -49,6 +50,7 @@
|
||||
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
@ -70,6 +72,7 @@
|
||||
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
@ -82,15 +85,18 @@
|
||||
RED.nodes.registerType('bullet-device', {
|
||||
category: 'config',
|
||||
defaults: {
|
||||
name: {value: "", required: true},
|
||||
name: {value: "", required: true}
|
||||
//apikey: -> credentials
|
||||
deviceid: {value: "", required: true}
|
||||
//deviceid -> credentials
|
||||
},
|
||||
label: function () {
|
||||
return this.name;
|
||||
},
|
||||
oneditprepare: function () {
|
||||
$.getJSON('pushbullet-api/' + this.id, function (data) {
|
||||
if (data.deviceid) {
|
||||
$('#node-config-input-deviceid').val(data.deviceid);
|
||||
}
|
||||
if (data.hasApiKey) {
|
||||
$('#node-config-input-apikey').val('__PWRD__');
|
||||
} else {
|
||||
@ -101,17 +107,19 @@
|
||||
},
|
||||
oneditsave: function () {
|
||||
var newApiKey = $('#node-config-input-apikey').val();
|
||||
var credentials = {};
|
||||
if (newApiKey != '__PWRD__') {
|
||||
var credentials = {};
|
||||
credentials.apikey = newApiKey;
|
||||
$.ajax({
|
||||
url: 'pushbullet-api/' + this.id,
|
||||
type: 'POST',
|
||||
data: credentials,
|
||||
success: function (result) {
|
||||
}
|
||||
});
|
||||
}
|
||||
credentials.deviceid = $('#node-config-input-deviceid').val();
|
||||
$.ajax({
|
||||
url: 'pushbullet-api/' + this.id,
|
||||
type: 'POST',
|
||||
data: credentials,
|
||||
success: function (result) {
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
ondelete: function () {
|
||||
$.ajax({
|
||||
|
@ -33,7 +33,7 @@ RED.httpAdmin.get('/pushbullet-api/global', function (req, res) {
|
||||
RED.httpAdmin.get('/pushbullet-api/:id', function (req, res) {
|
||||
var credentials = RED.nodes.getCredentials(req.params.id);
|
||||
if (credentials) {
|
||||
res.send(JSON.stringify({hasApiKey: (credentials.apikey && credentials.apikey != "")}));
|
||||
res.send(JSON.stringify({hasApiKey: (credentials.apikey && credentials.apikey != ""), deviceid: credentials.deviceid}));
|
||||
} else {
|
||||
res.send(JSON.stringify({}));
|
||||
}
|
||||
@ -55,7 +55,12 @@ RED.httpAdmin.post('/pushbullet-api/:id', function (req, res) {
|
||||
if (newCreds.apikey == "") {
|
||||
delete credentials.apikey;
|
||||
} else {
|
||||
credentials.apikey = newCreds.apikey;
|
||||
credentials.apikey = newCreds.apikey || credentials.apikey;
|
||||
}
|
||||
if (newCreds.deviceid == "" || newCreds.deviceid == null) {
|
||||
delete credentials.deviceid;
|
||||
} else {
|
||||
credentials.deviceid = newCreds.deviceid;
|
||||
}
|
||||
RED.nodes.addCredentials(req.params.id, credentials);
|
||||
res.send(200);
|
||||
@ -65,10 +70,10 @@ RED.httpAdmin.post('/pushbullet-api/:id', function (req, res) {
|
||||
function PushBulletDevice(n) {
|
||||
RED.nodes.createNode(this, n);
|
||||
this.name = n.name;
|
||||
this.deviceid = n.deviceid;
|
||||
var credentials = RED.nodes.getCredentials(n.id);
|
||||
if (credentials) {
|
||||
this.apikey = credentials.apikey;
|
||||
this.deviceid = credentials.deviceid;
|
||||
}
|
||||
}
|
||||
RED.nodes.registerType("bullet-device", PushBulletDevice);
|
||||
|
Loading…
x
Reference in New Issue
Block a user