diff options
author | Struan Donald <struan@exo.org.uk> | 2013-06-12 13:34:19 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2013-06-12 18:47:53 +0100 |
commit | b513e82c1e6fa9624d17fdfdc2809a5f6d53a1eb (patch) | |
tree | e9f25a7d9046770656bb334749a934636f202e3e /www/js | |
parent | 4abf38cb9a70b5de01f36293f471ee41ab25313e (diff) |
if the server rejects the report as invalid then display some errors
Diffstat (limited to 'www/js')
-rw-r--r-- | www/js/models/report.js | 4 | ||||
-rw-r--r-- | www/js/views/submit.js | 14 |
2 files changed, 16 insertions, 2 deletions
diff --git a/www/js/models/report.js b/www/js/models/report.js index 2508b3f..88e9dfd 100644 --- a/www/js/models/report.js +++ b/www/js/models/report.js @@ -93,7 +93,7 @@ if ( data.success ) { that.trigger('sync', that, data, options); } else { - that.trigger('error', that, data, options); + that.trigger('invalid', that, data, options); } } else { that.trigger('error', that, FMS.strings.report_send_error, options); @@ -128,7 +128,7 @@ if ( data.success ) { that.trigger('sync', that, data, options); } else { - that.trigger('error', that, data, options); + that.trigger('invalid', that, data, options); } }, error: function (data, status, errorThrown ) { diff --git a/www/js/views/submit.js b/www/js/views/submit.js index 3e1ef8e..654fb01 100644 --- a/www/js/views/submit.js +++ b/www/js/views/submit.js @@ -43,6 +43,7 @@ } else { this.report = new FMS.Report( this.model.toJSON() ); this.listenTo( this.report, 'sync', this.onReportSync ); + this.listenTo( this.report, 'invalid', this.onReportInvalid ); this.listenTo( this.report, 'error', this.onReportError ); this.report.save(); } @@ -73,6 +74,19 @@ this.navigate( 'sent' ); }, + onReportInvalid: function(model, err, options) { + var errors = err.errors; + var errorList = '<ul><li class="plain">Invalid report</li>'; + for ( var k in errors ) { + // FIXME! to stop jslint complaining for now + if ( k !== '' ) { + errorList += '<li>' + errors[k] + '</li>'; + } + } + errorList += '</ul>'; + $('#errors').html(errorList).show(); + }, + onReportError: function(model, err, options) { alert( FMS.strings.sync_error + ': ' + err.errors); }, |