summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Adam <yuv.adm@gmail.com>2014-06-08 09:52:58 +0300
committerYuval Adam <yuv.adm@gmail.com>2014-06-08 09:54:00 +0300
commit23536127ff0f4a902968b724a6686d28550f811b (patch)
treea62eb8a0b532c7456e5813ad80a4391303d4aaf1
parentcf88518e6d25ef036723d4ff41a118051cc1e9b7 (diff)
Add validations
-rw-r--r--templates/home.html61
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>