Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

commonjs get view or update database on a open window

$
0
0

Hi there, Stupid question. I have a app.js with a open window. First problem is that i open a window on top add a name to a database and fire a event to update it on the app.js window. But since its a open window, when it drops to null it will return "null is not a opject". So I am trying to open a view from a module and up date it there, but it is not working. no errors or anything. This is for IOS here is some sample code. main window app.js

////////////////////////////////////////////////
 
////////The Main Window
 function createCenterNavWindow(){  
     win = Ti.UI.createWindow({
        statusBarStyle:Titanium.UI.iPhone.StatusBar.Light_CONTENT,
        backgroundColor:'#01ACE4',
        tintColor:"#000000",
        translucent:false,
        //barColor:"white"
        barImage:'/images/bar.png'
    }); 
 
    //adduserblock
    userBlockf = require('/control/userblock');
    function createuserblockview(){
        userBlockH = new userBlockf();
        win.add(userBlockH)
    };
    //end add userblock
 
     leftBtn = Ti.UI.createButton({title:""});
        leftBtn.addEventListener("click", function(){
        window.toggleLeftView();
        window.setCenterhiddenInteractivity("TouchEnabled");    
    });
    //var rightBtn = Ti.UI.createButton({title:"right"});
    //  rightBtn.addEventListener("click", function(){
    //  window.toggleRightView();
    //  window.setCenterhiddenInteractivity("TouchEnabled");
    //});
    win.leftNavButton = leftBtn;
    //win.rightNavButton = rightBtn;
 
    // EXAMPLE API USAGE 
     scrollView = Ti.UI.createScrollView({
        layout:"vertical",left:0,right:0,top:0,
        contentHeight:'auto',contentWidth:"100%",
        showVerticalScrollIndicator: true,showHorizontalScrollIndicator: false
    });
 
 
     panningMode = 1;
 
 
    win.add(scrollView);
 
    //NAV
     navController = Ti.UI.iOS.createNavigationWindow({
        window : win
    });
 
 
 
    return navController;
}
this is were im adding a name to database winone.js
function WinOne(){
    'use strict';
    var ProfileWin, CloseBtn, Logo, ProfileView, ID, db, rows, data, Name, insertButton, NameTextField, NameLabel, sql4 ;
 
 
    ProfileWin = Ti.UI.createWindow({
        backgroundColor:'#01ACE4'   
    });
 
 
 
    Logo = Ti.UI.createImageView({
        image:'images/barblank.png',
        top:0
    });
 
 
    ProfileView = Titanium.UI.createView({
        backgroundColor:'white',
        width:320,
        height:25,
        borderRadius: 10,
        top:90
    });
 
    CloseBtn = Ti.UI.createButton({
        title:'Done',
        width:100,
        heigth:80,
        top:28,
        right: -15,
        color:'#0066FF'
    });
 
    CloseBtn.addEventListener('click', function(e){
        ProfileWin.close();
        CloseBtn = null;
        ProfileWin = null;
        Ti.App.fireEvent('reset');
    });
 
//database
    ID = '1';
 
//install database  DATABASE NUMBERE HERE!!!!!
    db = Ti.Database.install('/ui/common/JnCust.db', 'JnCust1');
    db = Ti.Database.open('JnCust1');
 
//get data for wishlist, amount own to vars
    rows = db.execute('SELECT * FROM CustTable WHERE ID ="' + ID + '"');    
    data = [
            {title:'' + rows.fieldByName('Name') + '', header:'Name'},
            ];
    Name = rows.fieldByName('Name');
    Ti.API.info(Name);
 
//name question
    NameLabel = Titanium.UI.createLabel({
        text:"Hello   " + Name,
        color:"black",
        top:60,
        left:10,
        height:35,
        width:"75%",
        textAlign:"left",
        font:{fontSize:15}
    });
 
 
 
// text box for name
    NameTextField = Titanium.UI.createTextField({
        //hintText: Name,
        hintText: 'Name: First   Last',
        value: Name,
        top: 96,
        left: 10,
        width: 200,
        height: 15,
        color:"black",
        //borderColor: '#bbb',
        editable: true,
        keyboardType : Titanium.UI.KEYBOARD_Default
    });
 
//update info button
    insertButton = Ti.UI.createButton({
        title: 'Update Info!',
        color: "black",
        //top:330,
        top:252,
        left:10,
        height: 28,
        font:{fontSize:15}
    });
 
//update the cust   DATABASE NUMBERE HERE!!!!!
    function updateData(Name){
    db = Titanium.Database.open('JnCust1');
        db.execute('DELETE  FROM CustTable WHERE ID = ?', ID);
        db.execute('INSERT INTO CustTable (ID,  Name) VALUES (?, ?)', ID,  Name);
        sql4 = db.execute('SELECT Name FROM CustTable WHERE ID ="' + ID + '"');
        Name = sql4.fieldByName('Name');
        db.close();
        alert("Info Updated!"); 
        Ti.App.fireEvent('getData');
    }
    db.close();
 
//Add event listener to update
    insertButton.addEventListener("click", function(){
    updateData(NameTextField.value.toString()); 
    });
//database  
    ProfileWin.add(Logo,  CloseBtn, ProfileView, insertButton, NameTextField, NameLabel);
 
    return ProfileWin;
    }
    exports.WinOne = WinOne;
this is the view module, were i thought i can update the name and apply it to the app.js userBlock.js
function userBlockf(){
    'use strict';
 
    var navGroup, winLeft, db, rows, data, Name, nameLabel, ID, sql4, ProfileView, leftTableView, newWin,  leftBtn, scrollView, panningMode, navController, win, NappSlideMenu, createCenterNavWindow, window;
    ////ceter window stuff added here
 
    ProfileView = Titanium.UI.createView({
        backgroundColor:'white',
        width:'fill',
        height:'fill',
        borderRadius: 10,
        top:90
    });
 
 
    ID = '1';
    //install database  DATABASE NUMBERE HERE!!!!!
    db = Ti.Database.install('/ui/common/JnCust.db', 'JnCust1');
    db = Ti.Database.open('JnCust1');
 
//get data for wishlist, amount own to vars
    rows = db.execute('SELECT * FROM CustTable WHERE ID ="' + ID + '"');    
    data = [
            {title:'' + rows.fieldByName('Name') + '', header:'Name'},
            ];
    Name = rows.fieldByName('Name');
    Ti.API.info(Name);
 
    //reset
    Ti.App.addEventListener('getData', function(){
        sql4.fieldByName = 'Resetting'
     //ProfileView.close();
     //ProfileView.open();
});
    //reset
 
//update fireevent
//Update the data on this page from interface fire event for wishlist DATABASE NUMBERE HERE!!!!!
Ti.App.addEventListener('reset', function(e){ 
    sql4 = db.execute('SELECT Name FROM CustTable WHERE ID ="' + ID + '"'); 
    Name = sql4.fieldByName('Name');
    NameLabel.text = "";
    NameLabel.text = Name;
    close();
    });
//end fireevent 
 
//name question
    NameLabel = Titanium.UI.createLabel({
        text: Name,
        color:"black",
        top:160,
        left:50,
        height:35,
        width:"75%",
        textAlign:"left",
        font:{fontSize:15}
    });
    db.close();
    ///end center window stuff added here
    win.add(userBlockH)
    ProfileView.add(NameLabel);
    return ProfileView;
    }
    exports.userBlockf = userBlockf;
any help would be cool.

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>