Quantcast
Viewing all articles
Browse latest Browse all 8068

How far does "e.source" bubble? Can a containingTab be passed to a TableView event listener?

Hello Community. I have a couple of noob questions for a single issue. I have a working app that I want to get the full functionality that I envision from. I am using a mac with Mavericks, Titanium 3.2.2.GA, and Titanium Studio, build: 3.2.1.201402041146. Building for iPhone and Android phones.

The app is built using CommonJS with modules for everything I can imagine. Modules create windows, tables, etc. I have a window that when created creates an instance of a table from a module. The table rows show data, an image, and has a label with a phone number and a label that says map. Current functionality is that the row is clicked and it calls a module that creates a new window and that window instantiates the needed map. However if I click the phone number I get both the phone prompt in iOS or the phone pad in android and it goes to the map. I would like it to just do the phone if that label is clicked or the map if that label is clicked.

Here are my problems:

  1. If I add the event listener to the tableview that is instantiated in the window (that is what gives my current functionality of going to the map window on row click) I can open the map window in the containing tab. However I cannot get the source of the labels clicked. I have added custom a parameter to each label called labelID for the phone label its value is "call" and for the map label it is "map". If I could get the source from the event listener at this window level, I can use an if statement on the custom parameter and decide whether to call or map. But I can't get at it to see which label was clicked.

  2. If I add the event listener with the logic mentioned above using the custom parameter to the tableview in the table creation module I get the desired result for the phone call. However, I cannot figure out how to pass the containing tab from the previous window to the table creation module to create the new map window from the table module.

Here is the working code for the first window that instantiates the table and the event listener that creates the map window on row click.

//create new instance of the physicians table
    physicians = new Physicians(sID);
 
    PhysicianWin2.add(physicians);
    PhysicianWin2.add(bottomView);
    PhysicianWin2.add(bottomLogo);
    PhysicianWin2.add(bottomLabel);
 
        //hides bottom view, label and logo when scrolling so last rows of table can be selected.
        physicians.addEventListener('scroll', function(e){
 
        bottomView.hide();
        bottomLabel.hide();
        bottomLogo.hide();
 
        //returns items to view after 5 seconds
        setTimeout(function(){
        bottomView.show();
        bottomLabel.show();
        bottomLogo.show();
        }, 5000);
    });
 
    //event listener to create new mapwindow on row click
    physicians.addEventListener("click", function(e){
    var pID = e.rowData.physID;
    PhysicianMapWin = require('/ui/physicianMapWin');
    pMapWin = new PhysicianMapWin.physicianMapWin_Creation(pID); //passes the physician ID to physicianMapWin
    pMapWin.containingTab = PhysicianWin2.containingTab;
    PhysicianWin2.containingTab.open(pMapWin);
    });
 
 
 
    //return the Win Object
    return PhysicianWin2;
}
 
exports.physicianWindow2_Creation = physicianWindow2_Creation;
I also have a scroll event listener to hide some bling on screen when scrolling and bring it back after 5 seconds. Next is the code that has the table event listener that I have tried (commented out) in the table module.
//adds data in array to tableview
tableview.setData(data);
 
//gets the OS to determine iOS or android for phone dialing
operatingSystem = Ti.Platform.osname;
 
 
//adds event listener to tableview to listen for phone number click 
//to dial or create the map window.
 
/*
tableview.addEventListener('click', function(e){
    if (e.source.labelID==='call'){
        //alert('you clicked the call link');
        if (operatingSystem === 'android'){
            var intent = Ti.Android.createIntent({
                action: Ti.Android.ACTION_DIAL,
                data: 'tel:' + e.rowData.phone
            });
            Ti.Android.currentActivity.startActivity(intent);
        }else{
 
        Ti.Platform.openURL('telprompt://' + e.rowData.phone);
        }
    }
 
    else if (e.source.labelID === 'map'){
        alert('do map stuff');
        var pID = e.rowData.physID;
    var PhysicianMapWin = require('/ui/physicianMapWin');
    var PhysicianWin2 = require('/ui/phyisicanWin2');
    var pMapWin = new PhysicianMapWin.physicianMapWin_Creation(pID); //passes the physician ID to   physicianMapWindow2
 
    //have tried so many ways to accomplish getting the containing tab here to open the window
    //this is just the code from the PhysicianWin2 code that creates the map window from its table event listener.
    pMapWin.containingTab = PhysicianWin2.containingTab;
    PhysicianWin2.containingTab.open(pMapWin);
 
    //I can open the window with the map using the line of code below but it has no back nav
    //as it doesn't have the containing tab.
    //pMapWin.open();
 
    }
    alert(operatingSystem +' '+ e.source.labelID);
 
});
*/
 
//returns the tableview to the window
return tableview;
}
 
//exports as a module for commonJS conformity
module.exports = GetPhysicianTable;
Please let me know if more code is needed or if in my noobness have made this clear as mud! In this instance, should the table be created from scratch in the physician2 window, rather than instantiated from a module? It seems I could get the click source there like I can in the table module. I really want to use best practices and get good at this!

Thanks in advance for any help. While I wait I am going to try and wrap my head around the callback functions to get the currentPosition to show up when I want to calculate distance!


Viewing all articles
Browse latest Browse all 8068

Trending Articles



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