diff options
author | Struan Donald <struan@exo.org.uk> | 2013-07-12 09:47:56 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2013-07-12 11:00:11 +0100 |
commit | 25e3a0c94551b0faac3f16e0598e6f4bdffcf7d8 (patch) | |
tree | f78f68ba8ed39e5b5004e41435aac3e9bbe9c044 /src/js/views/details_extra.js | |
parent | 4c2206c97250b7f72eb04d13ae886a7fb4f4086a (diff) |
instead of using js to inject the correct cordova js file in to
index.html restructure things so that the common files are a level down
and the platofrm specific ones are directly placed in the relevant
project. This both makes for less fuss and also avoids the error with
Android < v3 instantiating cordova twice.
Note that the iOS common assets are included by a build script rather
than a symlink as symlinking doesn't seem to agree with Xcode
Diffstat (limited to 'src/js/views/details_extra.js')
-rw-r--r-- | src/js/views/details_extra.js | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/src/js/views/details_extra.js b/src/js/views/details_extra.js new file mode 100644 index 0000000..7a96e8c --- /dev/null +++ b/src/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() { + console.log(this.model); + this.populateFields(); + }, + + onClickButtonPrev: function() { + 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); + + 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) { + console.log(that.$(this).attr('name')); + that.$(this).val(that.model.get(that.$(this).attr('name'))); + }; + this.$('input').each(populate); + this.$('select').each(populate); + this.$('textarea').each(populate); + } + }) + }); +})(FMS, Backbone, _, $); |