aboutsummaryrefslogtreecommitdiffstats
path: root/www/js/views/details_extra.js
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2014-10-03 15:07:08 +0100
committerDave Arter <davea@mysociety.org>2015-08-28 14:27:15 +0100
commita69d425c0e5c004145ac1ab70e2f7f9fc329b54c (patch)
tree8eb7ff0ff7aaa0fce8bc7214ec6e15b694fddbdc /www/js/views/details_extra.js
parent8fd15b58733c51d7f001f9eac66b7d03830ec0b4 (diff)
update Android to Cordova 3.6
Required due to security issue Remove Android directory as no longer required, move src -> www to match standard layout, update .gitignore to avoid including the standard platform files, update README based on Steve's zurich one
Diffstat (limited to 'www/js/views/details_extra.js')
-rw-r--r--www/js/views/details_extra.js108
1 files changed, 108 insertions, 0 deletions
diff --git a/www/js/views/details_extra.js b/www/js/views/details_extra.js
new file mode 100644
index 0000000..160ff11
--- /dev/null
+++ b/www/js/views/details_extra.js
@@ -0,0 +1,108 @@
+(function (FMS, Backbone, _, $) {
+ _.extend( FMS, {
+ DetailsExtraView: FMS.FMSView.extend({
+ template: 'details_extra',
+ id: 'details-extra-page',
+ prev: 'details',
+ next: 'submit-start',
+
+ events: {
+ 'pagehide': 'destroy',
+ 'pagebeforeshow': 'beforeDisplay',
+ 'pageshow': 'afterDisplay',
+ 'vclick .ui-btn-left': 'onClickButtonPrev',
+ 'vclick .ui-btn-right': 'onClickButtonNext',
+ 'blur textarea': 'updateCurrentReport',
+ 'change select': 'updateCurrentReport',
+ 'blur input': 'updateCurrentReport'
+ },
+
+ afterRender: function() {
+ this.populateFields();
+ },
+
+ onClickButtonPrev: function() {
+ this.model.set('hasExtras', 0);
+ this.updateCurrentReport();
+ this.navigate( this.prev, true );
+ },
+
+ onClickButtonNext: function() {
+ this.clearValidationErrors();
+ var valid = 1;
+ var that = this;
+
+ var isRequired = function(index) {
+ var el = $(this);
+ if ( el.attr('required') && el.val() === '' ) {
+ valid = 0;
+ that.validationError(el.attr('id'), FMS.strings.required);
+ }
+ };
+ // do validation
+ $('input').each(isRequired);
+ $('textarea').each(isRequired);
+ $('select').each(isRequired);
+ this.model.set('hasExtras', 1);
+
+ if ( valid ) {
+ this.clearValidationErrors();
+ this.updateCurrentReport();
+ this.navigate( this.next );
+ }
+ },
+
+ validationError: function(id, error) {
+ var el_id = '#' + id;
+ var el = $(el_id);
+
+ el.addClass('error');
+ if ( el.val() === '' ) {
+ el.attr('orig-placeholder', el.attr('placeholder'));
+ el.attr('placeholder', error);
+ }
+ },
+
+ clearValidationErrors: function() {
+ $('.error').removeClass('error');
+ $('.error').each(function(el) { if ( el.attr('orig-placeholder') ) { el.attr('placeholder', el.attr('orig-placeholder') ); } } );
+ },
+
+ updateSelect: function() {
+ this.updateCurrentReport();
+ },
+
+ updateCurrentReport: function() {
+ var fields = [];
+ var that = this;
+ var update = function(index) {
+ var el = $(this);
+ if ( el.val() !== '' ) {
+ that.model.set(el.attr('name'), el.val());
+ fields.push(el.attr('name'));
+ } else {
+ that.model.set(el.attr('name'), '');
+ }
+
+ };
+
+ $('input').each(update);
+ $('select').each(update);
+ $('textarea').each(update);
+
+ this.model.set('extra_details', fields);
+ FMS.saveCurrentDraft();
+ },
+
+ populateFields: function() {
+ var that = this;
+ var populate = function(index) {
+ that.$(this).val(that.model.get(that.$(this).attr('name')));
+ };
+ this.$('input').each(populate);
+ this.$('select').each(populate);
+ this.$('textarea').each(populate);
+ }
+ })
+ });
+})(FMS, Backbone, _, $);