facebook

two different Custom JS

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #344020 Reply

    fbod383
    Member

    Hello, I have a main screen that when you open the app it directs you to another .mobi screen depending on your GPS location. however, after it redirects you the custom JS on the second screen no longer works (it works fine when testing the second screen as a stand alone) thoughts?

    #344022 Reply

    Hi fbod383,

    When you generate code for a .mobi file, Mobione will just pull other screens that are linked to it and additional project files and css/javascript libraries to include them in the project. Your secondary_custom.js file is not included in this process, so you’ll have to include this code in main_custom.js to make it work. Hope this make sense. Let me know if you need further assistance.

    #344023 Reply

    fbod383
    Member

    Yep, I’ve got the code in the main custom JS, I dont know if some code is interfering with each other or what.
    Index.mobi is the first screen, by geolocator it takes me the “iowa.mobi” screen then there is a button to push that takes you to another screen and also gives an alert, this is the

    beginHelp();

    but it does nothing, no error or anything

    attached is the custom JS

    /**
     * Notification that the UI is about to transition to a new screen.
     * Perform custom prescreen-transition logic here.
     * @param {String} currentScreenId 
     * @param {String} targetScreenId 
     * @returns {boolean} true to continue transtion; false to halt transition
     */
    
    
        //  document.addEventListener("deviceready", onDeviceReady, false);
    
        // device APIs are available
        //
        function onDeviceReady() {
        // navigator.geolocation.getCurrentPosition(onSuccess, onError);
        }
    
        // onSuccess Geolocation
        //
        function onSuccess(position) {
           codeLatLng(position.coords.latitude,position.coords.longitude)
        }
    
        // onError Callback receives a PositionError object
        //
        function onError(error) {
            alert('code: '    + error.code    + '\n' +
                  'message: ' + error.message + '\n');
        }
        
        
        /**
     * Perform custom preprocessing or actions before submitting form. 
     * Common presubmission tasks include form validation and 
     * preprocessing of form data.
     * 
     * @param {boolean} true if all OK to proceed with form submission; 
     *                  false implies terminate form submission process
     * @param {Object} data results of form processing; error message if isSuccess == false
     * @return {boolean} true if OK; otherwise false
     */
    phoneui.preSubmitForm_m1_info = function(form) {
      // add custom presubmission code here, e.g., form validation & error handling
      // return false to terminate form submission
      return true;
    }
    
    /**
     * Perform custom actions upon return from form submission.
     * 
     * @param {boolean} isSuccess true if all OK; otherwise false
     * @param {Object} data results of form processing; error message if isSuccess == false
     * @return {boolean} true if OK; otherwise false
     */
    phoneui.postSubmitForm_m1_info = function(isSuccess, data) {
      // add custom postubmission processing code here,
      // e.g., parse and process results & update UI controls with data as needed
      // return false to terminate form processing
      var result = true;
      if (isSuccess) {
        // process data
        result = true;
      } else {
        // submit failed
        // data = error msg
        result = false;
      }
      return result;
    }
    
    function saveInfo()
    {
        localStorage.setItem('myName',$('#m1-newInfo-name').val());
        localStorage.setItem('myPhone',$('#m1-newInfo-number').val());
        localStorage.setItem('myAddress',$('#m1-newInfo-street').val());
        localStorage.setItem('myCityState',$('#m1-newInfo-city').val());
        localStorage.setItem('myContact1',$('#m1-newInfo-contact').val());
        localStorage.setItem('myContact2',$('#m1-newInfo-contactnumber').val());
        localStorage.setItem('myProvider',$('select[name="selectListMenu1"]').val());
    myProvider = $('select[name="selectListMenu1"]').val();
    localStorage.setItem('myAttorney',$('#m1-newInfo-attorney').val());
    localStorage.setItem('myAttorneyNumber',$('#m1-newInfo-attorneynumber').val());
    
    phoneui.gotoPage('#m1-index');
    }
    
    function checkInfo()
    {
        var needsInfo = 0;
      if (localStorage.getItem('myName').length == '0'){needsInfo = 1;}
       if ( localStorage.getItem('myPhone').length == '0') {needsInfo = 1;}
      if ( localStorage.getItem('myAddress').length == '0') {needsInfo = 1;}
      if ( localStorage.getItem('myCityState').length == '0'){needsInfo = 1;}
      if ( localStorage.getItem('myContact1').length == '0') {needsInfo = 1;}
      if ( localStorage.getItem('myContact2').length == '0'){needsInfo = 1;}
      if ( localStorage.getItem('myAttorney').length == '0') {needsInfo = 1;}
      if ( localStorage.getItem('myAttorneyNumber').length == '0') {needsInfo = 1;}
      if ( localStorage.getItem('myProvider').length == '0') {needsInfo = 1;}
      if (needsInfo == 1)
    {  phoneui.gotoPage('#m1-newInfo'); }
    else
    {navigator.geolocation.getCurrentPosition(onSuccess, onError);
    }
    
    /**
     * Notification that the UI has transitioned to a new screen.
     * 
     * @param {String} newScreenId 
     */
    phoneui.postPageTransition = function(newScreenId) {
      myName = localStorage.getItem('myName');
    //if (myName == ''){alert('Please fill out the user information form completely.');return false;break;}
    myPhone = localStorage.getItem('myPhone');
    //if (myPhone == ''){alert('Please fill out the user information form completely.');return false;break;}
    myAddress = localStorage.getItem('myAddress');
    //if (myAddress == ''){alert('Please fill out the user information form completely.');return false;break;}
    myCityState = localStorage.getItem('myCityState');
    //if (myCityState == ''){alert('Please fill out the user information form completely.');return false;break;}
    myContact1 = localStorage.getItem('myContact1');
    //if (myContact1 == ''){alert('Please fill out the user information form completely.');return false;break;}
    myContact2 = localStorage.getItem('myContact2');
    //if (myContact2 == ''){alert('Please fill out the user information form completely.');return false;break;}
    myAttorney = localStorage.getItem('myAttorney');
    //if (myAttorney == ''){alert('Please fill out the user information form completely.');return false;break;}
    myAttorneyNumber = localStorage.getItem('myAttorneyNumber');
    //if (myAttorneyNumber == ''){alert('Please fill out the user information form completely.');return false;break;}
    myProvider = localStorage.getItem('myProvider');
    //if (myProvider== ''){alert('Please fill out the user information form completely.');return false;break;}
      myMessage = 'Hello, I am sending the information from the GRL Mobile App, I am being arrested. Please see my information below \nMy Name: ' + myName + '\nMy Phone Number: ' + myPhone+ '\nMy Address: ' +myAddress+ ' ' + myCityState+ '\nEmergency Contact: ' +myContact1+ '\nEmergency Contact Number: ' +myContact2+ '\nMy Attorney: ' +myAttorney+ '\nMy Attorney Phone Number: ' +myAttorneyNumber;
    $('#m1-kenny-myMessageText').val(myMessage);
    $('#m1-kenny-textMail').val(myContact2+myProvider);
    $('#m1-notify-myMessageText').val(myMessage);
    $('#m1-notify-textMail').val(myContact2+myProvider);
    }
    
    /**
     * Notification that device orientation has changed. 
     * 
     * @param {String} newOrientation 
     */
    phoneui.postOrientationChange = function(newOrientation) {
      
    }
    
    /**
     * Called when document is loaded.
     */
    phoneui.documentReadyHandler = function() {
    //$('#m1-kenny-myMessageText').css('visibility','hidden');
    //$('#m1-kenny-textMail').css('visibility','hidden');
    }
    
    /**
     * Perform custom preprocessing or actions before submitting form. 
     * Common presubmission tasks include form validation and 
     * preprocessing of form data.
     * 
     * @param {boolean} true if all OK to proceed with form submission; 
     *                  false implies terminate form submission process
     * @param {Object} data results of form processing; error message if isSuccess == false
     * @return {boolean} true if OK; otherwise false
     */
    phoneui.preSubmitForm_m1_kenny = function(form) {
      // add custom presubmission code here, e.g., form validation & error handling
      // return false to terminate form submission
      myName = localStorage.getItem('myName');
    //if (myName == ''){alert('Please fill out the user information form completely.');return false;break;}
    myPhone = localStorage.getItem('myPhone');
    //if (myPhone == ''){alert('Please fill out the user information form completely.');return false;break;}
    myAddress = localStorage.getItem('myAddress');
    //if (myAddress == ''){alert('Please fill out the user information form completely.');return false;break;}
    myCityState = localStorage.getItem('myCityState');
    //if (myCityState == ''){alert('Please fill out the user information form completely.');return false;break;}
    myContact1 = localStorage.getItem('myContact1');
    //if (myContact1 == ''){alert('Please fill out the user information form completely.');return false;break;}
    myContact2 = localStorage.getItem('myContact2');
    //if (myContact2 == ''){alert('Please fill out the user information form completely.');return false;break;}
    myAttorney = localStorage.getItem('myAttorney');
    //if (myAttorney == ''){alert('Please fill out the user information form completely.');return false;break;}
    myAttorneyNumber = localStorage.getItem('myAttorneyNumber');
    //if (myAttorneyNumber == ''){alert('Please fill out the user information form completely.');return false;break;}
    myProvider = localStorage.getItem('myProvider');
    //if (myProvider== ''){alert('Please fill out the user information form completely.');return false;break;}
      myMessage = 'Hello, I am sending the information from the GRL Mobile App, Iam being arrested. Please see my information below \nMy Name: ' + myName + '\nMy Phone Number: ' + myPhone+ '\nMy Address: ' +myAddress+ ' ' + myCityState+ '\nEmergency Contact: ' +myContact1+ '\nEmergency Contact Number: ' +myContact2+ '\nMy Attorney: ' +myAttorney+ '\nMy Attorney Phone Number: ' +myAttorneyNumber;
    $('#m1-kenny-myMessageText').val(myMessage);
    $('#m1-kenny-textMail').val(myContact2+myProvider);
    return true;
    
    }
    
    /**
     * Perform custom actions upon return from form submission.
     * 
     * @param {boolean} isSuccess true if all OK; otherwise false
     * @param {Object} data results of form processing; error message if isSuccess == false
     * @return {boolean} true if OK; otherwise false
     */
    phoneui.postSubmitForm_m1_kenny = function(isSuccess, data) {
      // add custom postubmission processing code here,
      // e.g., parse and process results & update UI controls with data as needed
      // return false to terminate form processing
       //    $('#m1-kenny-myMessageText').css('visibility','hidden');
      var result = true;
      if (isSuccess) {
        // process data
    
        result = true;
      } else {
        // submit failed
        // data = error msg
        result = false;
      }
    alert(data);
    $('#m1-kenny-myMessageText').css('visibility','hidden');
    $('#m1-kenny-textMail').css('visibility','hidden');
      return result;
    }
    
    /**
     * Perform custom preprocessing or actions before submitting form. 
     * Common presubmission tasks include form validation and 
     * preprocessing of form data.
     * 
     * @param {boolean} true if all OK to proceed with form submission; 
     *                  false implies terminate form submission process
     * @param {Object} data results of form processing; error message if isSuccess == false
     * @return {boolean} true if OK; otherwise false
     */
    phoneui.preSubmitForm_m1_notify = function(form) {
      // add custom presubmission code here, e.g., form validation & error handling
      // return false to terminate form submission
        myName = localStorage.getItem('myName');
    //if (myName == ''){alert('Please fill out the user information form completely.');return false;break;}
    myPhone = localStorage.getItem('myPhone');
    //if (myPhone == ''){alert('Please fill out the user information form completely.');return false;break;}
    myAddress = localStorage.getItem('myAddress');
    //if (myAddress == ''){alert('Please fill out the user information form completely.');return false;break;}
    myCityState = localStorage.getItem('myCityState');
    //if (myCityState == ''){alert('Please fill out the user information form completely.');return false;break;}
    myContact1 = localStorage.getItem('myContact1');
    //if (myContact1 == ''){alert('Please fill out the user information form completely.');return false;break;}
    myContact2 = localStorage.getItem('myContact2');
    //if (myContact2 == ''){alert('Please fill out the user information form completely.');return false;break;}
    myAttorney = localStorage.getItem('myAttorney');
    //if (myAttorney == ''){alert('Please fill out the user information form completely.');return false;break;}
    myAttorneyNumber = localStorage.getItem('myAttorneyNumber');
    //if (myAttorneyNumber == ''){alert('Please fill out the user information form completely.');return false;break;}
    myProvider = localStorage.getItem('myProvider');
    //if (myProvider== ''){alert('Please fill out the user information form completely.');return false;break;}
      myMessage = 'Hello, I am sending the information from the GRL Mobile App, Iam being arrested. Please see my information below \nMy Name: ' + myName + '\nMy Phone Number: ' + myPhone+ '\nMy Address: ' +myAddress+ ' ' + myCityState+ '\nEmergency Contact: ' +myContact1+ '\nEmergency Contact Number: ' +myContact2+ '\nMy Attorney: ' +myAttorney+ '\nMy Attorney Phone Number: ' +myAttorneyNumber;
    $('#m1-notify-myMessageText').val(myMessage);
    $('#m1-notify-textMail').val(myContact2+myProvider);
    phoneui.gotoPage('m1-quick1', "FADE");
      return true;
    
    }
    
    /**
     * Perform custom actions upon return from form submission.
     * 
     * @param {boolean} isSuccess true if all OK; otherwise false
     * @param {Object} data results of form processing; error message if isSuccess == false
     * @return {boolean} true if OK; otherwise false
     */
    phoneui.postSubmitForm_m1_notify = function(isSuccess, data) {
      // add custom postubmission processing code here,
      // e.g., parse and process results & update UI controls with data as needed
      // return false to terminate form processing
       //    $('#m1-notify-myMessageText').css('visibility','hidden');
      var result = true;
      if (isSuccess) {
        // process data
    
        result = true;
      } else {
        // submit failed
        // data = error msg
        result = false;
      }
    alert(data);
    $('#m1-notify-myMessageText').css('visibility','hidden');
    $('#m1-notify-textMail').css('visibility','hidden');
      return result;
    }
    
    
    //////////////////
      //////////////
      //////////////
      var myAudioFile;
      var myFileRecord = "myrecording.mp3";
      var myMime = "audio/mpeg3";
        // Wait for PhoneGap to load
        //
        //document.addEventListener("deviceready", onDeviceReady, false);
    
        // Record audio
        // 
        function recordAudio() {
         
            src = myFileRecord;
            mediaRec = new Media(src, onSuccess, onError);
        
            // Record audio
            mediaRec.startRecord();
    
            // Stop recording after 611 sec
            var recTime = 0;
            var recInterval = setInterval(function() {
                recTime = recTime + 1;
                setAudioPosition(recTime + " sec");
                if (recTime >= 1000) {
                    clearInterval(recInterval);
                    mediaRec.stopRecord();
                  
                    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
                   
                }
            }, 1000);
        }
    // Upload files to server
    function uploadFile() {
    var options = new FileUploadOptions();
    options.fileKey="file";
    options.fileName=myFileRecord;
    options.mimeType=myMime;
    options.chunkedMode = false;
    file = "file://" + myAudioFile;
                    var ft = new FileTransfer();
                    var recordingPath = myAudioFile;
                    //var name = "myrecording.mp3";
      var name = localStorage.getItem('myName') + ".mp3";
                    
                    ft.upload(file,
                              "http://legaldocs.info/grl/upload.php",
                              function(result) {
                              
                              console.log('Upload success: ' + result.responseCode);
                              console.log(result.bytesSent + ' bytes sent');
                              },
                              function(error) {
                              
                           //   document.getElementById('audio_position').innerHTML = error.code;
                              },
                              { fileName: name });   
                }
        
      
       
    function gotFS(fileSystem) {
            fileSystem.root.getFile(myFileRecord, null, gotFileEntry, fail);
        }
        function gotFileEntry(fileEntry) {
            fileEntry.file(gotFile, fail);
        }
    
        function gotFile(file){
        
        myAudioFile = file.fullPath;
            uploadFile();
        }
        function fail(evt) {
           alert(evt.target.error.code);
        }
        // onSuccess Callback
        //
        function onSuccess() {
            console.log("recordAudio():Audio Success");
        }
    
        // onError Callback 
        //
        function onError(error) {
            alert('code: '    + error.code    + '\n' + 
                  'message: ' + error.message + '\n');
        }
    
        // Set audio position
        // 
        function setAudioPosition(position) {
         //   document.getElementById('audio_position').innerHTML = position;
        }
    
      
       function beginHelp()
      {
    alert("You have activated The Oh Crap App Rights Reminder.  If enabled, your phone voice recorder has also been activated to ensure any interaction between you and law enforcement is recorded to fully protect your rights.  Keep your phone on your person if possible.");
    //document.forms["m1_kenny"].submit();
    phoneui.gotoPage('m1-quick1', "FADE");
    if(device.platform == "iPhone")
    {
        myFileRecord = "myrecording.wav";myMime="audio/x-wav";
        
    document.addEventListener("deviceready", function onDeviceReady() {
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS1, function fail1(){});
    }, false);
    
    var gotFS1 = function (fileSystem) {
        fileSystem.root.getFile("myrecording.wav",
            { create: true, exclusive: false }, //create if it does not exist
            function success(entry) {
                var src = entry.toURI();
                console.log(src); //logs blank.wav's path starting with file://
            },
            function fail1() {}
        );
    };
        
        }
    recordAudio();
    
       }
    }/**
     * Notification that the UI is about to transition to a new screen.
     * Perform custom prescreen-transition logic here.
     * @param {String} currentScreenId 
     * @param {String} targetScreenId 
     * @returns {boolean} true to continue transtion; false to halt transition
     */
    phoneui.prePageTransition = function(currentScreenId, targetScreenId) {
      // add custom pre-transition code here
      // return false to terminate transition
      return true;
    }
    
    /**
     * Notification that the page's HTML/CSS/JS is about to be loaded.
     * Perform custom logic here, f.e. you can cancel request to the server.
     * @param {String} targetScreenId 
     * @returns {boolean} true to continue loading; false to halt loading
     */
    phoneui.prePageLoad = function(targetScreenId) {
      // add custom pre-load code here
      // return false to terminate page loading, this cancels transition to page as well
      return true;
    }
    
    
    #344067 Reply

    support-michael
    Keymaster

    @fbod383

    Let me recommend that if you are not using MobiOne 2.5 that you upgrade and begin using the new Mobile Web Simulator in Chrome. This will give you access to the Chrome Developer Tools which are awesome for finding js syntax and runtime bugs.

    You can learn more here:
    http://www.genuitec.com/mobile/docs/highlights/current/

    http://www.genuitec.com/mobile/docs/mobile_simulator/mobile_simulator.html#using_emulator
    includes references to Google’s tutorials and videos for using the Chrome Dev Tools.

    #344097 Reply

    fbod383
    Member

    Yes I am using it, there seem to be no errors.

Viewing 5 posts - 1 through 5 (of 5 total)
Reply To: two different Custom JS

You must be logged in to post in the forum log in