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>
|
||||||
|
|
||||||
<script type="text/x-red" data-help-name="pushbullet">
|
<script type="text/x-red" data-help-name="pushbullet">
|
||||||
@ -49,6 +50,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
@ -70,6 +72,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
@ -82,15 +85,18 @@
|
|||||||
RED.nodes.registerType('bullet-device', {
|
RED.nodes.registerType('bullet-device', {
|
||||||
category: 'config',
|
category: 'config',
|
||||||
defaults: {
|
defaults: {
|
||||||
name: {value: "", required: true},
|
name: {value: "", required: true}
|
||||||
//apikey: -> credentials
|
//apikey: -> credentials
|
||||||
deviceid: {value: "", required: true}
|
//deviceid -> credentials
|
||||||
},
|
},
|
||||||
label: function () {
|
label: function () {
|
||||||
return this.name;
|
return this.name;
|
||||||
},
|
},
|
||||||
oneditprepare: function () {
|
oneditprepare: function () {
|
||||||
$.getJSON('pushbullet-api/' + this.id, function (data) {
|
$.getJSON('pushbullet-api/' + this.id, function (data) {
|
||||||
|
if (data.deviceid) {
|
||||||
|
$('#node-config-input-deviceid').val(data.deviceid);
|
||||||
|
}
|
||||||
if (data.hasApiKey) {
|
if (data.hasApiKey) {
|
||||||
$('#node-config-input-apikey').val('__PWRD__');
|
$('#node-config-input-apikey').val('__PWRD__');
|
||||||
} else {
|
} else {
|
||||||
@ -101,9 +107,11 @@
|
|||||||
},
|
},
|
||||||
oneditsave: function () {
|
oneditsave: function () {
|
||||||
var newApiKey = $('#node-config-input-apikey').val();
|
var newApiKey = $('#node-config-input-apikey').val();
|
||||||
if (newApiKey != '__PWRD__') {
|
|
||||||
var credentials = {};
|
var credentials = {};
|
||||||
|
if (newApiKey != '__PWRD__') {
|
||||||
credentials.apikey = newApiKey;
|
credentials.apikey = newApiKey;
|
||||||
|
}
|
||||||
|
credentials.deviceid = $('#node-config-input-deviceid').val();
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'pushbullet-api/' + this.id,
|
url: 'pushbullet-api/' + this.id,
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
@ -111,7 +119,7 @@
|
|||||||
success: function (result) {
|
success: function (result) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
},
|
},
|
||||||
ondelete: function () {
|
ondelete: function () {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
@ -33,7 +33,7 @@ RED.httpAdmin.get('/pushbullet-api/global', function (req, res) {
|
|||||||
RED.httpAdmin.get('/pushbullet-api/:id', function (req, res) {
|
RED.httpAdmin.get('/pushbullet-api/:id', function (req, res) {
|
||||||
var credentials = RED.nodes.getCredentials(req.params.id);
|
var credentials = RED.nodes.getCredentials(req.params.id);
|
||||||
if (credentials) {
|
if (credentials) {
|
||||||
res.send(JSON.stringify({hasApiKey: (credentials.apikey && credentials.apikey != "")}));
|
res.send(JSON.stringify({hasApiKey: (credentials.apikey && credentials.apikey != ""), deviceid: credentials.deviceid}));
|
||||||
} else {
|
} else {
|
||||||
res.send(JSON.stringify({}));
|
res.send(JSON.stringify({}));
|
||||||
}
|
}
|
||||||
@ -55,7 +55,12 @@ RED.httpAdmin.post('/pushbullet-api/:id', function (req, res) {
|
|||||||
if (newCreds.apikey == "") {
|
if (newCreds.apikey == "") {
|
||||||
delete credentials.apikey;
|
delete credentials.apikey;
|
||||||
} else {
|
} 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);
|
RED.nodes.addCredentials(req.params.id, credentials);
|
||||||
res.send(200);
|
res.send(200);
|
||||||
@ -65,10 +70,10 @@ RED.httpAdmin.post('/pushbullet-api/:id', function (req, res) {
|
|||||||
function PushBulletDevice(n) {
|
function PushBulletDevice(n) {
|
||||||
RED.nodes.createNode(this, n);
|
RED.nodes.createNode(this, n);
|
||||||
this.name = n.name;
|
this.name = n.name;
|
||||||
this.deviceid = n.deviceid;
|
|
||||||
var credentials = RED.nodes.getCredentials(n.id);
|
var credentials = RED.nodes.getCredentials(n.id);
|
||||||
if (credentials) {
|
if (credentials) {
|
||||||
this.apikey = credentials.apikey;
|
this.apikey = credentials.apikey;
|
||||||
|
this.deviceid = credentials.deviceid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("bullet-device", PushBulletDevice);
|
RED.nodes.registerType("bullet-device", PushBulletDevice);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user