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/fms.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/fms.js')
-rw-r--r-- | src/js/views/fms.js | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/src/js/views/fms.js b/src/js/views/fms.js new file mode 100644 index 0000000..53cdc66 --- /dev/null +++ b/src/js/views/fms.js @@ -0,0 +1,103 @@ +(function (FMS, Backbone, _, $) { + _.extend( FMS, { + FMSView: Backbone.View.extend({ + tag: 'div', + bottomMargin: 20, + contentSelector: '[data-role="content"]', + + events: { + 'pagehide': 'destroy', + 'pagebeforeshow': 'beforeDisplay', + 'pageshow': 'afterDisplay', + 'vclick .ui-btn-left': 'onClickButtonPrev', + 'vclick .ui-btn-right': 'onClickButtonNext' + }, + + render: function(){ + if ( !this.template ) { + console.log('no template to render'); + return; + } + template = _.template( tpl.get( this.template ) ); + var args = null; + if ( this.options.msg ) { + args = { msg: this.options.msg }; + } + if ( this.model ) { + if ( args ) { + args.model = this.model.toJSON(); + } else { + args = this.model.toJSON(); + } + } + this.$el.html(template(args)); + this.afterRender(); + return this; + }, + + fixPageHeight: function() { + var header = this.$("div[data-role='header']:visible"), + content = this.$(this.contentSelector), + top = content.position().top, + viewHeight = $(window).height(), + contentHeight = viewHeight - header.outerHeight() - this.bottomMargin; + + this.setHeight( content, contentHeight - top ); + }, + + setHeight: function(content, height) { + content.height(height); + }, + + afterRender: function() {}, + + beforeDisplay: function() { + this.fixPageHeight(); + }, + + afterDisplay: function() {}, + + navigate: function( route, reverse ) { + if ( reverse ) { + FMS.router.reverseTransition(); + } + + FMS.router.navigate( route, { trigger: true } ); + }, + + onClickButtonPrev: function(e) { + e.preventDefault(); + this.navigate( this.prev, true ); + }, + + onClickButtonNext: function(e) { + e.preventDefault(); + this.navigate( this.next ); + }, + + displayError: function(msg) { + alert(msg); + }, + + validationError: function( id, error ) { + var el_id = '#' + id; + var el = $(el_id); + var err = '<div for="' + id + '" class="form-error">' + error + '</div>'; + if ( $('div[for='+id+']').length === 0 ) { + el.before(err); + el.addClass('form-error'); + } + }, + + clearValidationErrors: function() { + $('div.form-error').remove(); + $('.form-error').removeClass('form-error'); + }, + + destroy: function() { console.log('destory for ' + this.id); this._destroy(); this.remove(); }, + + _destroy: function() {} + }) + }); + _.extend( FMS.FMSView, Backbone.Events ); +})(FMS, Backbone, _, $); |