forked from IBM-Cloud/openwhisk-contact
-
Notifications
You must be signed in to change notification settings - Fork 0
/
requestController.js
120 lines (100 loc) · 4.39 KB
/
requestController.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
angular.module('ngWhisk')
.controller('requestController', function($scope, $http, $log, $rootScope, ngDialog) {
$log.log('inside');
var API_URL = 'https://b4651037-d05a-4b7d-ab46-1e9a1abc096f-gws.api-gw.mybluemix.net/OpenWhiskContact/api/v1'; // OpenWhisk exposed API
$scope.emailSent = false; // setting message logic to false not display any message by default
$scope.sendMail = function () { //The send button will call this method to make an API to a OpenWhisk Action exposed as a API
//scope binding the form data
var data = {
myName: $scope.myName,
myEmail: $scope.myEmail,
myUrl: $scope.myUrl,
myDescription: $scope.myDescription
};
// adding content type for post header, this is needed for when calling OpenWhisk API
var config = {
headers : {
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
}
};
// Simple POST request example (passing data) :
$http.post(API_URL, data, config)
.then(function(response) {
// this callback will be called asynchronously
// when the response is available
$log.log('Email Sent with response status of: ' + JSON.stringify(response.status));
$scope.emailSent = true;
// Injecting success into the array of alerts
$scope.alerts = [ {type: 'success', msg: ''} ];
$scope.alerts[0].msg = 'Thanks, ' + $scope.myName + ' we have got your request, and we will be in touch. ';
// After user sent the email, then clear the values to be empty
$scope.myName = "";
$scope.myEmail = "";
$scope.myUrl = "";
$scope.myDescription = "";
}, function(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
$log.log("Error occurred with status: " + '' + JSON.stringify(response.status));
$scope.emailSent = true;
// if there was an error, then display this message
$scope.alerts = [
{type: 'danger', msg: ''}
];
$scope.alerts[0].msg = 'Oops there was a problem sending your request, please contact Twana Daniel at [email protected]';
});
};
// Remove alert message area
$scope.closeAlert = function (index) {
$scope.alerts.splice(index, 1);
};
///////Handling the popup
$rootScope.jsonData = '{"foo": "bar"}';
$rootScope.theme = 'ngdialog-theme-default';
$scope.open = function () {
ngDialog.open({ template: 'firstDialogId', controller: 'InsideCtrl' });
};
$scope.openDefault = function () {
ngDialog.open({
template: 'firstDialogId',
controller: 'InsideCtrl',
className: 'ngdialog-theme-default'
});
};
$scope.openPlain = function () {
$rootScope.theme = 'ngdialog-theme-plain';
ngDialog.open({
template: 'firstDialogId',
controller: 'InsideCtrl',
className: 'ngdialog-theme-plain'
});
};
$scope.openTemplate = function () {
$scope.value = true;
ngDialog.open({
template: 'externalTemplate.html',
className: 'ngdialog-theme-plain',
scope: $scope
});
};
});
//popup ctrl
angular
.module('ngWhisk')
.controller('InsideCtrl', function ($scope, ngDialog) {
$scope.openSecond = function () {
ngDialog.open({
template: '<h3><a href="" ng-click="closeSecond()">Close all by click here!</a></h3>',
plain: true,
closeByEscape: false,
controller: 'SecondModalCtrl'
});
};
});
angular
.module('ngWhisk')
.controller('SecondModalCtrl', function ($scope, ngDialog) {
$scope.closeSecond = function () {
ngDialog.close();
};
});