forked from codeBarb/js-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d3eedb
commit 674613f
Showing
2 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Core — RingCentral™ Platform</title> | ||
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"> | ||
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css"> | ||
<link rel="stylesheet" href="common.css"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
</head> | ||
<body> | ||
|
||
|
||
<div class="container"> | ||
|
||
<h1> | ||
<a href="index.html" id="logo"></a> | ||
</h1> | ||
|
||
<hr> | ||
|
||
<form class="panel panel-default" id="mms-form" action="" enctype="multipart/form-data" method="post"> | ||
<div class="panel-heading"><h3 class="panel-title">MMS</h3></div> | ||
<div class="panel-body form-horizontal"> | ||
|
||
<div class="form-group"> | ||
<label for="mms-from" class="col-xs-2 control-label">From</label> | ||
|
||
<div class="col-xs-10 dropdown"> | ||
<select class="form-control" id="mms-from"></select> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<label for="mms-to" class="col-xs-2 control-label">To</label> | ||
|
||
<div class="col-xs-10"> | ||
<input type="text" class="form-control" id="mms-to" name="to"> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<label for="mms-attachment" class="col-xs-2 control-label">Attachment</label> | ||
|
||
<div class="col-xs-10"> | ||
<input type="file" class="form-control" id="mms-attachment" name="attachment" multiple="multiple"> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<label class="col-xs-2 control-label">Attached files</label> | ||
|
||
<div class="col-xs-10"> | ||
<pre id="mms-files"></pre> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
<div class="panel-footer text-center"> | ||
<button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-send"></span> Send MMS</button> | ||
</div> | ||
</form> | ||
|
||
<hr> | ||
|
||
<p class="text-center text-muted"> | ||
© 1999 – <span id="date"></span> RingCentral™, Inc. All rights reserved. | ||
<script> document.getElementById('date').innerHTML = (new Date()).getFullYear().toString(); </script> | ||
</p> | ||
|
||
</div> | ||
|
||
<script type="text/javascript"> | ||
window.fetch = null; // force to use polyfill | ||
</script> | ||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/fetch/2.0.2/fetch.js"></script> | ||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/es6-promise/4.0.5/es6-promise.auto.js"></script> | ||
<script type="text/javascript" src="https://cdn.pubnub.com/sdk/javascript/pubnub.4.4.3.js"></script> | ||
<script src="../build/ringcentral.js" type="text/javascript"></script> | ||
<script src="scripts.js" type="text/javascript"></script> | ||
<script type="text/javascript"> | ||
|
||
(function() { | ||
|
||
var sdk = getSDK(); | ||
var platform = sdk.platform(); | ||
|
||
|
||
function populateFromNumbers() { | ||
|
||
var fromPhoneNumbers = []; | ||
platform | ||
.get('/account/~/extension/~/phone-number', {'perPage': 'max'}) | ||
.then(function(res) { | ||
var phoneNumbers = res.json().records; | ||
for (var i = 0; i < phoneNumbers.length; i++ ) { | ||
if (phoneNumbers[i].features.indexOf("MmsSender") != -1 ) { | ||
fromPhoneNumbers.push(phoneNumbers[i].phoneNumber); | ||
} | ||
} | ||
return showMMS(fromPhoneNumbers); | ||
}) | ||
.catch(function(e) { | ||
alert('MMS From Phone Number Population Error:\n\n' + e.message); | ||
}); | ||
|
||
} | ||
|
||
function showMMS(fromPhoneNumbers) { | ||
|
||
var $from = document.getElementById('mms-from'); | ||
var $to = document.getElementById('mms-to'); | ||
var $attachment = document.getElementById('mms-attachment'); | ||
var $files = document.getElementById('mms-files'); | ||
var $form = document.getElementById('mms-form'); | ||
|
||
$to.value = localStorage.getItem('ringcentral-demo-mms-to'); | ||
$form.action = platform.createUrl('/account/~/extension/~/sms', {addToken: true, addServer: true}); | ||
|
||
// Populate the dropdown menu | ||
for( var i = 0; i < fromPhoneNumbers.length; i++) { | ||
var li = document.createElement("option"); | ||
var text = document.createTextNode(fromPhoneNumbers[i]); | ||
li.appendChild(text); | ||
$from.appendChild(li); | ||
} | ||
|
||
$attachment.addEventListener('change', function(e) { | ||
|
||
var text = []; | ||
|
||
for (var i = 0, file; file = $attachment.files[i]; ++i) { | ||
text.push(JSON.stringify({ | ||
name: file.name, | ||
lastModifiedDate: file.lastModifiedDate, | ||
size: file.size, | ||
type: file.type | ||
})); | ||
} | ||
|
||
$files.innerText = text.join('\n'); | ||
|
||
}); | ||
|
||
$form.addEventListener('submit', function(e) { | ||
|
||
e.preventDefault(); | ||
|
||
if (!$attachment.files.length) return alert('You must attach a file.'); | ||
|
||
var body = { | ||
from: {phoneNumber: $from.value}, | ||
to: [{phoneNumber: $to.value}] // see all available options on Developer Portal | ||
}, | ||
formData = new FormData(); | ||
|
||
// This is the mandatory part, the name and type should always be as follows | ||
formData.append('json', new File([JSON.stringify(body)], 'request.json', {type: 'application/json'})); | ||
|
||
if ($attachment.files.length) { | ||
for (var i = 0, file; file = $attachment.files[i]; ++i) { | ||
formData.append('attachment', file); // you can also use file.name instead of 'attachment' | ||
} | ||
} | ||
|
||
platform | ||
.post('/account/~/extension/~/sms', formData) | ||
.then(function(res) { | ||
localStorage.setItem('ringcentral-demo-mms-to', $to.value); | ||
alert('MMS has been sent', $to.value); | ||
}) | ||
.catch(function(e) { | ||
alert('MMS Send Error:\n\n' + e.message); | ||
}); | ||
|
||
}); | ||
|
||
} | ||
|
||
|
||
platform.ensureLoggedIn().then(populateFromNumbers).catch(function() { | ||
location.assign('login.html'); | ||
}); | ||
|
||
})(); | ||
|
||
</script> | ||
|
||
</body> | ||
</html> |