Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions app/scripts/controllers/Extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,68 @@ angular
function DialogController($scope, $mdDialog, extension, $shared) {
$scope.$shared = $shared;
$scope.extension = extension;
$scope.isSendingEmail = false;
$scope.close = function () {
$mdDialog.hide();
};
$scope.sendCredentialsEmail = function (ev) {
var prompt = $mdDialog
.prompt()
.title('Send SIP Credentials')
.textContent('Enter the email address to receive these SIP credentials.')
.placeholder('name@example.com')
.ariaLabel('Destination email')
.targetEvent(ev)
.ok('Send')
.cancel('Cancel');

$mdDialog.show(prompt).then(function (email) {
var normalizedEmail = (email || '').trim();
var emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
var extensionId = extension.id;

if (!emailRegex.test(normalizedEmail)) {
$mdToast.show(
$mdToast
.simple()
.textContent('Please enter a valid email address.')
.position('top right')
.hideDelay(3000)
);
return;
}

if (!extensionId) {
$mdToast.show(
$mdToast
.simple()
.textContent('Could not determine extension id.')
.position('top right')
.hideDelay(3000)
);
return;
}

$scope.isSendingEmail = true;
Backend.post('/emailSIPCredentials', {
to_email: normalizedEmail,
extension_id: extensionId,
}).then(
function () {
$mdToast.show(
$mdToast
.simple()
.textContent('SIP credentials sent successfully.')
.position('top right')
.hideDelay(3000)
);
},
function () {}
)['finally'](function () {
$scope.isSendingEmail = false;
});
});
};
}
$scope.settings = {
page: 0,
Expand Down
6 changes: 6 additions & 0 deletions app/views/dialogs/extension-connect-info.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ <h4>How To Connect</h4>

<md-dialog-actions layout="row">
<span flex></span>
<md-button class="md-raised md-primary" ng-click="sendCredentialsEmail($event)" ng-disabled="isSendingEmail">
<span>
<i class="mdi mdi-email"></i>&nbsp;
Email Credentials
</span>
</md-button>
<md-button ng-click="close()">
Close
</md-button>
Expand Down
Loading