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) {
//
}
});
};
}
})();
Related
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");
});
};
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>
I was trying to reuse an object property in a loop. Is this the right way? I'm always getting an undefined error. The properties I want to use are 'field_id' and 'field_text'. I'm not sure if it should be defined as a variable or a string.
Below is my full code:
var client_id = '', company_name = '', vacancy_category_id = '', category_name = '', user_id = '', full_name = '';
let select2El = {
params: [{
'id': '#client_id',
'url': '/consultant/vacancy/get-clients',
'field_id': client_id,
'field_text': company_name,
'success_response': $scope.clients
}, {
'id': '#clone_client_id',
'url': '/consultant/vacancy/get-clients',
'field_id': client_id,
'field_text': company_name,
'success_response': $scope.clients
}, {
'id': '#category_id',
'url': '/consultant/vacancy/get-categories',
'field_id': vacancy_category_id,
'field_text': category_name,
'success_response': $scope.categories
}, {
'id': '#owner_id',
'url': '/consultant/vacancy/get-users-by-type',
'field_id': user_id,
'field_text': full_name,
'success_response': $scope.users
}]
}
for (var key in select2El.params) {
var sel = select2El.params[key];
angular.element(sel['id']).select2({
width: '100%',
placeholder: '--Select--',
ajax: {
url: sel['url'],
dataType: 'json',
data: function (params) {
return {
search: params.term,
page: params.page || 1
}
},
processResults: function (response, params) {
params.page = params.page || 1;
return {
results: response.data.map(function (res) {
console.log(res);
return { id: res.sel['field_id'], 'text': res.sel['field_text'] }
}),
pagination: {
more: (params.page * 10) < response.total
}
};
},
success: function (response) {
sel['success_response'] = response.data;
}
}
});
}
The line where the object property has been looped over is this:
return { id: res.sel['field_id'], 'text': res.sel['field_text']
When I console.log(res), I get this data.
This is happening because your res.sel field is undefined. From what I understand you want the value field_id and field_text from the object stored in select2El.params.
Try the following code -
var client_id = '', company_name = '', vacancy_category_id = '', category_name = '', user_id = '', full_name = '';
let select2El = {
params: [{
'id': '#client_id',
'url': '/consultant/vacancy/get-clients',
'field_id': client_id,
'field_text': company_name,
'success_response': $scope.clients
}, {
'id': '#clone_client_id',
'url': '/consultant/vacancy/get-clients',
'field_id': client_id,
'field_text': company_name,
'success_response': $scope.clients
}, {
'id': '#category_id',
'url': '/consultant/vacancy/get-categories',
'field_id': vacancy_category_id,
'field_text': category_name,
'success_response': $scope.categories
}, {
'id': '#owner_id',
'url': '/consultant/vacancy/get-users-by-type',
'field_id': user_id,
'field_text': full_name,
'success_response': $scope.users
}]
}
for (let key in select2El.params) {
let sel = select2El.params[key];
angular.element(sel['id']).select2({
width: '100%',
placeholder: '--Select--',
ajax: {
url: sel['url'],
dataType: 'json',
data: function (params) {
return {
search: params.term,
page: params.page || 1
}
},
processResults: function (response, params) {
params.page = params.page || 1;
return {
results: response.data.map(function (res, index) {
console.log(res);
return { id: sel['field_id'], 'text': sel['field_text'] }
}),
pagination: {
more: (params.page * 10) < response.total
}
};
},
success: function (response) {
sel['success_response'] = response.data;
}
}
});
}
I used index inside .map to fetch the values of field_text and field_id from the original object
In order to load some data from the server after the page has loaded I have the following script:
<script>
export default {
data() {
return {
imageDirectory: "../../images/",
fileName: "img",
extension: ".png",
products:
[
{
name: 'loading data',
imageUrl: require("../../assets/t1.png")
}
]
}
},
name: "ProductList",
created: function () {
this.fetchData();
},
methods: {
fetchData: function () {
$.ajax({
type: "GET",
timeout: 1200000,
url: 'api/test',
contentType: "application/json",
dataType: "text",
success: function (data) {
window.alert(data);
this.products = [{
name: 'success' + 'test',
imageUrl: require("../../assets/t1.png")
}] },
error: function (data) {
this.products = [{
name: 'failed' + 'test',
imageUrl: require("../../assets/t1.png")
}]
}
});
}
}
}
</script>
Now when I run this I do get the alert window showing me that it did indeed fetch the data, however, it does not actually manage to update the object in question (product name remains loading data and not success test). If I move the code
this.products = [{
name: 'success' + 'test',
imageUrl: require("../../assets/t1.png")
}]
into the created: function() like so:
created: function () {
this.products = [{
name: 'success' + 'test',
imageUrl: require("../../assets/t1.png")
}]
this.fetchData();
}
it does actually update the data. So this means that both the code to fetch the data is accurate and the placeholder to update the data is functional, so why is the data not getting updated?
(note that the code to update the data is a placeholder).
in your fetchData function you have used 'this' keyword inside $.ajax() which can confuse compiler to which object you are referring so why not try this:
fetchData: function () {
let app = this;
$.ajax({
type: "GET",
timeout: 1200000,
url: 'api/test',
contentType: "application/json",
dataType: "text",
success: function (data) {
window.alert(data);
app.products = [{
name: 'success' + 'test',
imageUrl: require("../../assets/t1.png")
}] },
error: function (data) {
app.products = [{
name: 'failed' + 'test',
imageUrl: require("../../assets/t1.png")
}]
}
});
}
I want to loop through an array of objects named tier1.
what I get is this:
TypeError: Cannot read property 'length' of undefined
My code looks something like this:
module.exports.getTier1= function(curUser, callback){
for (var i = 0; i < curUser.tier1.length; i++) {
var val = curUser.tier1[i];
console.log("index: " + i + " val: " + val);
}
};
var UserSchema = mongoose.Schema({
username: {
type: String,
index:true
},
password: {
type: String
},
email: {
type: String
},
name: {
type: String
},
tier1: [Tier1]
});