diff options
Diffstat (limited to 'templates/home.html')
| -rw-r--r-- | templates/home.html | 61 |
1 files changed, 53 insertions, 8 deletions
diff --git a/templates/home.html b/templates/home.html index eda6e82..e7bbbd0 100644 --- a/templates/home.html +++ b/templates/home.html @@ -10,14 +10,6 @@ <script src="/static/js/underscore-min.js"></script> <script src="/static/js/bootstrap.min.js"></script> <script> - function load_data() { - - }; - - function save_data(data) { - - } - $(document).ready(function() { $.get('/data', function(res) { var data = res.data.split('\n===\n'); @@ -25,6 +17,56 @@ $('#composition-area').val(data[1]); }) + $('#validate-btn').click(function() { + var sequences = $('#sequences-area').val(); + var composition = $('#composition-area').val(); + + var sequences_len = 0; + var sequence_names = []; + + _.each(sequences.split('\n\n'), function(seq) { + _.each(seq.split('\n'), function(s) { + if (s.startsWith('#')) { + if (s.split(' ').length > 2) { + alert('Sequence name ' + s + ' has whitespace in it'); + } + else { + sequence_names.push(s.split(' ')[1]); + } + } + else if (s != '') { + if (sequences_len == 0) { + sequences_len = s.length; + } + else { + if (s.length != sequences_len) { + alert('One or more sequences are not equal in length'); + return; + } + } + } + }) + }); + + var composition_len = 0; + _.each(composition.split('\n'), function(cl) { + if (!(cl.startsWith('#') || cl == '')) { + _.each(cl.split(','), function(seq) { + if (!(sequence_names.indexOf(seq) > -1)) { + alert('Sequence name ' + seq + ' in composition does not exist'); + } + }); + if (sequences_len == 0) { + sequences_len = cl.split(',').length; + } + else if (cl.split(',').length != sequences_len) { + alert('One or more sequences in composition are not equal in length'); + return; + } + } + }); + }) + $('#save-btn').click(function() { $.ajax({ type: 'POST', @@ -45,6 +87,9 @@ <h1>Light Loop Pi</h1> <div class="btn-toolbar" role="toolbar"> <div class="btn-group"> + <button id="validate-btn" type="button" class="btn btn-info">Validate</button> + </div> + <div class="btn-group"> <button id="save-btn" type="button" class="btn btn-primary">Save</button> </div> </div> |
