aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/Dawn/static/dawn.js21
-rw-r--r--python/Dawn/static/utils.js22
-rw-r--r--python/Dawn/templates/cds_trade_entry.html1
3 files changed, 27 insertions, 17 deletions
diff --git a/python/Dawn/static/dawn.js b/python/Dawn/static/dawn.js
index a282d6c1..27d4ca3c 100644
--- a/python/Dawn/static/dawn.js
+++ b/python/Dawn/static/dawn.js
@@ -1,6 +1,3 @@
-function $(s){
- return document.getElementById(s)
-}
var index_list = [];
var bbg_map = {'CDX': ["IG", "HY"], 'ITRX': ["EUR", "XOVER"]}
var index_series = ["21", "23", "24", "25"];
@@ -16,21 +13,11 @@ for(var begin_index in bbg_map){
}
};
-function callback(t) {
- console.log(t);
+function callback(data) {
+ data = JSON.parse(data);
+ console.log(data);
};
-function query_id(secur_id) {
- var xhr = new XMLHttpRequest();
- xhr.open('GET', "/_ajax?bbg_id="+encodeURIComponent(secur_id));
- xhr.onreadystatechange = function() {
- if( xhr.readyState === 4 ){
- callback(xhr.responseText );
- }
- }
- xhr.send();
-}
-
var datalist = $('index_list');
index_list.forEach(function(item){
var option = document.createElement('option');
@@ -51,7 +38,7 @@ document.addEventListener("DOMContentLoaded", function(){
});
$('security_desc').setAttribute('list', 'index_list');
$('security_desc').addEventListener('change', function(){
- query_id(this.value);
+ query('../_ajax', {bbg_id: this.value}, callback);
});
var event = new Event('change');
$('swap_type').dispatchEvent(event);
diff --git a/python/Dawn/static/utils.js b/python/Dawn/static/utils.js
new file mode 100644
index 00000000..0b886e8f
--- /dev/null
+++ b/python/Dawn/static/utils.js
@@ -0,0 +1,22 @@
+function $(s) {
+ return( document.getElementById(s) )
+}
+
+function encode_dict(d){
+ var r = []
+ for(var k in d){
+ r.push(encodeURIComponent(k) + '=' + encodeURIComponent(d[k]));
+ }
+ return r.join('&');
+}
+
+function query(url, params, callback){
+ var xhr = new XMLHttpRequest();
+ xhr.open('GET', url + '?' + encode_dict(params));
+ xhr.onreadystatechange = function() {
+ if( xhr.readyState === 4){
+ callback(xhr.responseText);
+ }
+ }
+ xhr.send();
+}
diff --git a/python/Dawn/templates/cds_trade_entry.html b/python/Dawn/templates/cds_trade_entry.html
index beefc856..26c21903 100644
--- a/python/Dawn/templates/cds_trade_entry.html
+++ b/python/Dawn/templates/cds_trade_entry.html
@@ -35,6 +35,7 @@
</div>
</div>
</form>
+ <script type="text/javascript" src="{{ url_for('static', filename='utils.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='dawn.js') }}"></script>
</body>
</html>