Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var imageMaxTargetWidth = 1024;
- var imageMaxTargetHeight = 1024;
- document.addEventListener("deviceready", onDeviceReady, false);
- // Main jQuery function for when document has loaded.
- function onDeviceReady() {
- // Handle the change of the plot selection type
- $('input[name=plotSelectionType]').change(function(e){
- if(this.value == 'all'){
- // Disable the select
- //$('#plotSelectorHolder').hide();
- $('#select-choice-2').selectmenu('disable');
- }
- else if(this.value == 'selected'){
- // Show the select
- //$('#plotSelectorHolder').show();
- $('#select-choice-2').selectmenu('enable');
- }
- });
- // =========================================
- // START The Defect Page JS Specific Actions
- // =========================================
- $('#list-ticket-tab').on('click',function(){
- $('#tab-action-button').attr('href', '#new-ticket');
- $('#tab-action-button').text('Ticket');
- });
- $('#list-meter-tab').on('click',function(){
- $('#tab-action-button').attr('href', '#camera-meter-reading');
- $('#tab-action-button').text('Meter Reading');
- });
- $('#list-inspection-tab').on('click',function(){
- $('#tab-action-button').attr('href', '#new-defect');
- $('#tab-action-button').text('Inspection');
- });
- $('.fireCamera').click(function(e){
- // Stop the initial redirect
- e.preventDefault();
- // Get the location we are going to be redirecting to
- var redirectTo = $(this).attr('href');
- console.log(redirectTo);
- // The taking of the picture for the incident
- navigator.camera.getPicture(
- // The Success Function of taking a picture
- function(imageURI) {
- // Store the photo in persistant storage first then we can reference it whenever we want
- window.resolveLocalFileSystemURI(imageURI, copyPhoto, fail);
- // Copies the photo to persistant storage.
- function copyPhoto(entry){
- var d = new Date();
- var n = d.getTime();
- //new file name
- var newFileName = n + ".jpg";
- var myFolderApp = "tmpImages";
- window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSys) {
- fileSys.root.getDirectory( myFolderApp,
- {create:true},
- function(directory) {
- entry.moveTo(directory, newFileName, function(new_entry){
- path = new_entry.fullPath;
- url = new_entry.toURL(); // This is the URL that will need to be stored an used when an upload is made to the server etc.
- // Set the image in the next page
- if(redirectTo == '#camera-meter-reading'){
- $('#meterReadingImage').attr('src', url);
- }
- else if(redirectTo == '#new-ticket'){
- // TODO Need image element here
- $('#ticketImage').attr('src', url);
- }
- else if(redirectTo == '#new-defect'){
- $('#defectImage').attr('src', url);
- }
- else if(redirectTo == '#defect-quick-add'){
- $('#quickDefectImage').attr('src', url);
- }
- // The redirect will happen here if successful to the correct place
- $.mobile.changePage($(redirectTo), 'pop');
- return true;
- }, fail);
- },
- fail);
- },
- fail);
- }
- // The error function for the failure to copy to the device, eg not enough storage.
- function fail(err){
- console.log(err);
- }
- },
- // The Error Function if a pic cant be taken. This also fires when the cancel button is pressed.
- function(errMsg) {
- // Display an error message here
- },
- // The configuration settings here
- {
- saveToPhotoAlbum: true,
- destinationType: Camera.DestinationType.FILE_URI,
- sourceType : Camera.PictureSourceType.CAMERA,
- correctOrientation: true,
- targetWidth: imageMaxTargetWidth,
- targetHeight: imageMaxTargetHeight,
- }
- );
- }); // End of Tab Action Click Button
- // =========================================
- // END The Defect Page JS Specific Actions
- // =========================================
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement