Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var imageMaxTargetWidth = 1024;
  2. var imageMaxTargetHeight = 1024;
  3.  
  4. document.addEventListener("deviceready", onDeviceReady, false);
  5.  
  6. // Main jQuery function for when document has loaded.
  7. function onDeviceReady() {
  8.  
  9.     // Handle the change of the plot selection type
  10.     $('input[name=plotSelectionType]').change(function(e){
  11.         if(this.value == 'all'){
  12.             // Disable the select
  13.             //$('#plotSelectorHolder').hide();
  14.             $('#select-choice-2').selectmenu('disable');   
  15.         }
  16.         else if(this.value == 'selected'){
  17.             // Show the select
  18.             //$('#plotSelectorHolder').show();
  19.             $('#select-choice-2').selectmenu('enable');
  20.         }
  21.     });
  22.  
  23.  
  24.     // =========================================
  25.     // START The Defect Page JS Specific Actions
  26.     // =========================================
  27.  
  28.     $('#list-ticket-tab').on('click',function(){
  29.         $('#tab-action-button').attr('href', '#new-ticket');
  30.         $('#tab-action-button').text('Ticket');
  31.     });
  32.     $('#list-meter-tab').on('click',function(){
  33.         $('#tab-action-button').attr('href', '#camera-meter-reading');
  34.         $('#tab-action-button').text('Meter Reading');
  35.     });
  36.     $('#list-inspection-tab').on('click',function(){
  37.         $('#tab-action-button').attr('href', '#new-defect');
  38.         $('#tab-action-button').text('Inspection');
  39.     });
  40.  
  41.     $('.fireCamera').click(function(e){
  42.  
  43.         // Stop the initial redirect
  44.         e.preventDefault();
  45.  
  46.         // Get the location we are going to be redirecting to
  47.         var redirectTo = $(this).attr('href');
  48.         console.log(redirectTo);
  49.  
  50.         // The taking of the picture for the incident
  51.         navigator.camera.getPicture(
  52.             // The Success Function of taking a picture
  53.             function(imageURI) {
  54.  
  55.                 // Store the photo in persistant storage first then we can reference it whenever we want
  56.                 window.resolveLocalFileSystemURI(imageURI, copyPhoto, fail);
  57.  
  58.                 // Copies the photo to persistant storage.
  59.                 function copyPhoto(entry){
  60.                   var d = new Date();
  61.                   var n = d.getTime();
  62.  
  63.                   //new file name
  64.                   var newFileName = n + ".jpg";
  65.                   var myFolderApp = "tmpImages";
  66.  
  67.                   window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSys) {
  68.                       fileSys.root.getDirectory( myFolderApp,
  69.                         {create:true},
  70.                         function(directory) {
  71.                             entry.moveTo(directory, newFileName, function(new_entry){
  72.                                 path = new_entry.fullPath;
  73.                                 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.                                
  74.  
  75.                                 // Set the image in the next page
  76.                                 if(redirectTo == '#camera-meter-reading'){
  77.                                     $('#meterReadingImage').attr('src', url);
  78.                                 }
  79.                                 else if(redirectTo == '#new-ticket'){
  80.                                     // TODO Need image element here
  81.                                     $('#ticketImage').attr('src', url);
  82.                                 }
  83.                                 else if(redirectTo == '#new-defect'){
  84.                                     $('#defectImage').attr('src', url);
  85.                                 }
  86.                                 else if(redirectTo == '#defect-quick-add'){
  87.                                     $('#quickDefectImage').attr('src', url);
  88.                                 }
  89.  
  90.  
  91.                                 // The redirect will happen here if successful to the correct place
  92.                                 $.mobile.changePage($(redirectTo), 'pop');
  93.                                 return true;
  94.                             }, fail);
  95.                         },
  96.                         fail);
  97.                   },
  98.                   fail);
  99.                 }
  100.                 // The error function for the failure to copy to the device, eg not enough storage.
  101.                 function fail(err){
  102.                   console.log(err);
  103.                 }
  104.             },
  105.             // The Error Function if a pic cant be taken. This also fires when the cancel button is pressed.
  106.             function(errMsg) {
  107.                 // Display an error message here
  108.  
  109.             },
  110.             // The configuration settings here
  111.             {
  112.              saveToPhotoAlbum: true,
  113.              destinationType: Camera.DestinationType.FILE_URI,
  114.              sourceType : Camera.PictureSourceType.CAMERA,
  115.              correctOrientation: true,
  116.              targetWidth: imageMaxTargetWidth,
  117.              targetHeight: imageMaxTargetHeight,
  118.             }
  119.         );
  120.     }); // End of Tab Action Click Button
  121.  
  122.     // =========================================
  123.     // END The Defect Page JS Specific Actions
  124.     // =========================================
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement