diff options
Diffstat (limited to 'www')
-rw-r--r-- | www/index.html | 2 | ||||
-rw-r--r-- | www/js/app.js | 2 | ||||
-rw-r--r-- | www/js/router.js | 14 | ||||
-rw-r--r-- | www/js/views/home.js | 7 | ||||
-rw-r--r-- | www/js/views/offline.js | 82 | ||||
-rw-r--r-- | www/js/views/reports.js | 9 | ||||
-rw-r--r-- | www/templates/en/offline.html | 40 | ||||
-rw-r--r-- | www/templates/en/reports.html | 10 |
8 files changed, 162 insertions, 4 deletions
diff --git a/www/index.html b/www/index.html index a6a6717..c24a972 100644 --- a/www/index.html +++ b/www/index.html @@ -38,6 +38,8 @@ <script type="text/javascript" src="js/views/fms.js"></script> <script type="text/javascript" src="js/views/home.js"></script> + <script type="text/javascript" src="js/views/offline.js"></script> + <script type="text/javascript" src="js/views/reports.js"></script> <script type="text/javascript" src="js/views/around.js"></script> <script type="text/javascript" src="js/views/search.js"></script> <script type="text/javascript" src="js/views/existing.js"></script> diff --git a/www/js/app.js b/www/js/app.js index 42916b1..caf7bed 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -38,7 +38,7 @@ var tpl = { (function (FMS, Backbone, _, $) { _.extend(FMS, { templates: [ - 'home', 'around', 'address_search', 'existing', 'photo', 'details', 'submit', 'submit_email', 'submit_name', 'submit_password', 'sent' + 'home', 'around', 'offline', 'reports', 'address_search', 'existing', 'photo', 'details', 'submit', 'submit_email', 'submit_name', 'submit_password', 'sent' ], initialized: 0, diff --git a/www/js/router.js b/www/js/router.js index f220422..fe43d69 100644 --- a/www/js/router.js +++ b/www/js/router.js @@ -6,6 +6,7 @@ routes: { '': 'home', 'home': 'home', + 'offline': 'offline', 'around': 'around', 'search': 'search', 'existing': 'existing', @@ -15,7 +16,8 @@ 'submit-email': 'submitEmail', 'submit-name': 'submitName', 'submit-password': 'submitPassword', - 'sent': 'sent' + 'sent': 'sent', + 'reports': 'reports' }, initialize: function() { @@ -53,6 +55,11 @@ this.changeView(homeView); }, + offline: function() { + var offlineView = new FMS.OfflineView({ model: FMS.currentDraft }); + this.changeView(offlineView); + }, + photo: function(){ var photoView = new FMS.PhotoView({ model: FMS.currentDraft }); this.changeView(photoView); @@ -88,6 +95,11 @@ this.changeView(sentView); }, + reports: function() { + var reportsView = new FMS.ReportsView({ model: FMS.currentDraft }); + this.changeView(reportsView); + }, + changeView: function(view) { console.log( 'change View to ' + view.id ); $(view.el).attr('data-role', 'page'); diff --git a/www/js/views/home.js b/www/js/views/home.js index 9c169a9..383275e 100644 --- a/www/js/views/home.js +++ b/www/js/views/home.js @@ -26,8 +26,11 @@ if ( navigator && navigator.connection && ( navigator.connection.type == Connection.NONE || navigator.connection.type == Connection.UNKNOWN ) ) { localStorage.offline = 1; - this.navigate( 'no_connection' ); - } else if ( FMS.currentDraft && FMS.currentDraft.get('lat') ) { + this.navigate( 'offline' ); + } else if ( FMS.currentDraft && ( + FMS.currentDraft.get('title') || FMS.currentDraft.get('lat') || + FMS.currentDraft.get('details') || FMS.currentDraft.get('file') ) + ) { this.navigate( 'existing' ); } else { this.navigate( 'around' ); diff --git a/www/js/views/offline.js b/www/js/views/offline.js new file mode 100644 index 0000000..d2af4e0 --- /dev/null +++ b/www/js/views/offline.js @@ -0,0 +1,82 @@ +(function (FMS, Backbone, _, $) { + _.extend( FMS, { + OfflineView: FMS.FMSView.extend({ + template: 'offline', + id: 'offline', + prev: 'home', + next: 'reports', + + events: { + 'pagehide': 'destroy', + 'pageshow': 'afterDisplay', + 'click .ui-btn-left': 'onClickButtonPrev', + 'click .ui-btn-right': 'onClickButtonNext', + 'click #id_photo_button': 'takePhoto', + 'click #id_existing': 'addPhoto', + 'click #id_del_photo_button': 'deletePhoto' + }, + + takePhoto: function() { + var that = this; + navigator.camera.getPicture( function(imgURI) { that.addPhotoSuccess(imgURI); }, function(error) { that.addPhotoFail(error); }, { saveToPhotoAlbum: true, quality: 49, destinationType: Camera.DestinationType.FILE_URI, sourceType: navigator.camera.PictureSourceType.CAMERA, correctOrientation: true }); + }, + + addPhoto: function() { + var that = this; + navigator.camera.getPicture( function(imgURI) { that.addPhotoSuccess(imgURI); }, function(error) { that.addPhotoFail(error); }, { saveToPhotoAlbum: false, quality: 49, destinationType: Camera.DestinationType.FILE_URI, sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY, correctOrientation: true }); + }, + + addPhotoSuccess: function(imgURI) { + var move = FMS.files.moveURI( imgURI ); + + var that = this; + move.done( function( file ) { + $('#photo').attr('src', file.toURL()); + that.model.set('file', file.toURL()); + FMS.saveCurrentDraft(); + + $('#photo-next-btn .ui-btn-text').text('Next'); + $('#display_photo').show(); + $('#add_photo').hide(); + }); + + move.fail( function() { that.addPhotoFail(); } ); + }, + + addPhotoFail: function() { + if ( message != 'no image selected' && + message != 'Selection cancelled.' && + message != 'Camera cancelled.' ) { + this.displayError(FMS.strings.photo_failed); + } + }, + + deletePhoto: function() { + var that = this; + var del = FMS.files.deleteURI( this.model.get('file') ); + + del.done( function() { + that.model.set('file', ''); + FMS.saveCurrentDraft(); + $('#photo').attr('src', ''); + + $('#photo-next-btn .ui-btn-text').text('Skip'); + $('#display_photo').hide(); + $('#add_photo').show(); + }); + }, + + onClickButtonNext: function() { + this.updateCurrentReport(); + this.navigate( this.next, 'left' ); + }, + + updateCurrentReport: function() { + this.model.set('title', $('#form_title').val()); + this.model.set('details', $('#form_detail').val()); + FMS.saveCurrentDraft(); + localStorage.currentDraftID = FMS.currentDraft.id; + } + }) + }); +})(FMS, Backbone, _, $); diff --git a/www/js/views/reports.js b/www/js/views/reports.js new file mode 100644 index 0000000..3ad2c01 --- /dev/null +++ b/www/js/views/reports.js @@ -0,0 +1,9 @@ +(function (FMS, Backbone, _, $) { + _.extend( FMS, { + ReportsView: FMS.FMSView.extend({ + template: 'reports', + id: 'reports', + next: 'home' + }) + }); +})(FMS, Backbone, _, $); diff --git a/www/templates/en/offline.html b/www/templates/en/offline.html new file mode 100644 index 0000000..ebf16db --- /dev/null +++ b/www/templates/en/offline.html @@ -0,0 +1,40 @@ +<div data-role="header" data-position="fixed" > + <a id="offline-prev-btn" data-icon="arrow-l" data-iconpos="left" class="ui-btn-left">Try Again</a> + <h1>Offline</h1> + <a id="offline-next-btn" data-icon="arrow-r" data-iconpos="right" class="ui-btn-right">Save</a> +</div> +<div class="container" data-enhance="false"> + <div class="content" role="main"> + <p> + Sorry, there doesn't seem to be any internet connection. You can save this report for sending later though + </p> + + <input type="text" value="" name="title" id="form_title" placeholder="Provide a title" required> + + <textarea rows="7" cols="26" name="detail" id="form_detail" placeholder="Please fill in details of the problem." required></textarea> + + <% if ( file != '' ) { %> + <div id="add_photo" style="display: none"> + <% } else { %> + <div id="add_photo"> + <% } %> + <label>Optionally Add a Photo</label> + <input value="Take Photo" type="button" name="photo_button" id="id_photo_button" class="green-btn"> Or + <input value="Choose" type="button" name="existing" id="id_existing" class="green-btn"> + </div> + + <% if ( file == '' ) { %> + <div id="display_photo" style="display: none"> + <% } else { %> + <div id="display_photo"> + <% } %> + <label>Your Photo</label> + <div class="photo"> + <img class="small" id="photo" src="<%= file %>" /> + </div> + <div class="right"> + <input value="Remove Photo" type="button" name="del_photo_button" id="id_del_photo_button" class="green-btn"> + <div> + </div> + </div> +</div> diff --git a/www/templates/en/reports.html b/www/templates/en/reports.html new file mode 100644 index 0000000..226eec2 --- /dev/null +++ b/www/templates/en/reports.html @@ -0,0 +1,10 @@ +<div data-role="header" data-position="fixed" > + <h1>My Reports</h1> + <a id="reports-next-btn" data-icon="arrow-r" data-iconpos="right" class="ui-btn-right">Home</a> +</div> +<div class="container" data-enhance="false"> + <div class="content" role="main"> + <h1>Holding page :)</h1> + </div> + +</div> |