In my application, I had the idea to implement a straightforward panic button. The functionality of this button is as follows:
When a user clicks on the panic button, an alert will appear providing them with predefined groups that they can send a panic message to.
1) If the user selects the committee group, the panic message will only be sent to users with the role of committee.
2) If the user selects "All," the panic message will be sent to all members of the application.
I was unsure how to pass the specific value to the button click event. The groupList variable contains all the group names. Here is the code snippet:
sendTextMessage() {
let Groups: any = [];
firebase.database().ref('panic_group').orderByKey().once('value', (items: any) => {
items.forEach((item) => {
Groups.push(item.val().Group_name);
this.groupList = Groups;
});
let alertConfirm = this.alertCtrl.create();
alertConfirm.setTitle('Choose Group');
// Add new groups here!
this.groupList.forEach(group => {
alertConfirm.addInput({
type: 'radio',
label: group,
value: group.toLowerCase(),
checked: group === group.toLowerCase()
});
});
// ...
alertConfirm.addButton({
text: 'Cancel',
role: 'cancel',
handler: () => {
console.log("Cancel clicked");
}
});
alertConfirm.addButton({
text: 'Send',
handler: () => {
console.log("Send clicked");
alert('cnt' + this.contacts);
var request = new XMLHttpRequest();
request.open("POST", "https://control.msg91.com", true);
request.setRequestHeader("Access-Control-Allow-Origin", "*");
var settings = {
"async": true,
"crossDomain": true,
"url": "http://api.msg91.com/api/v2/sendsms",
"method": "POST",
"headers": {
"authkey": "198608A17R3Rqgwdh5a87f2ae",
"content-type": "application/json"
},
"processData": false,
"data": "{ \"sender\": \"SOCKET\", \"route\": \"4\", \"country\": \"91\", \"sms\": [ { \"message\": \"Panic Alert from Flat No " + this.flatNo + "\", \"to\": [ " + this.contacts + " ] }, { \"message\": \"Test Panic Alert from Flat No " + this.flatNo + "\", \"to\": [ " + this.contacts + " ] } ] }"
}
alert(settings.data);
console.log(settings.data);
jQuery.ajax(settings).done(function (response) {
console.log(response);
alert('res' + response);
alert("Sms Sent!");
});
}
});
alertConfirm.present();
});
}