Skip to content

Commit

Permalink
Updated to 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mick-schroeder committed Nov 7, 2011
1 parent 6ee2045 commit 7b2355b
Show file tree
Hide file tree
Showing 17 changed files with 519 additions and 345 deletions.
6 changes: 5 additions & 1 deletion Resources/ipad/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ var data = [
{ title : 'Current Shortages', hasChild:true, path : './ipad/js/getFeed.js', header:'ASHP Reported Drug Shortages'},
{ title : 'Resolved Shortages', hasChild:true, path : './ipad/js/getFeed.js'},
{ title : 'Unavailable Drugs', hasChild:true, path : './ipad/js/getFeed.js'},
{ title : 'Reported Shortages', hasChild:true, path : './ipad/js/getFDA.js', header:'FDA Reported Drug Shortages'},

{ title : 'Current Drug Shortages', head: 'FDA: Current', hasChild:true, path : './ipad/js/getFDA.js', header:'FDA Reported Drug Shortages'},
{ title : 'Resolved Drug Shortages', head: 'FDA: Resolved', hasChild:true, path : './ipad/js/getFDA.js'},
{ title : 'Drugs to be Discontinued', head: 'FDA: Discontinued', hasChild:true, path : './ipad/js/getFDA.js'},

{ title : 'Shortages Feed', hasChild:true, path : './ipad/js/feed.js', header:'Other'},
{ title : 'Trends', hasChild:true, path : './ipad/js/trends.js'},
{ title : 'Report Shortages', hasChild:true, path : './ipad/main_windows/report.js', header:'Other Views'},
Expand Down
250 changes: 190 additions & 60 deletions Resources/ipad/js/getFDA.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,77 +7,207 @@
* http://www.gnu.org/licenses/gpl.html
*/

// Displays a list of the recent articles
var win = Ti.UI.currentWindow,
query,
siteUrl;
//
// Show Feed
//

if(Ti.Network.online){
// Set properties
var win = Ti.UI.currentWindow;
win.backgroundColor = '#fff';

// YQL query to get feed.
siteUrl = "www.fda.gov/downloads/Drugs/DrugSafety/DrugShortages/UCM163172.xml";
query = "Select title, description, link from rss where url='" + siteUrl + "'";
// Set variables
var data, newRow, query, siteUrl, yqlMatches;

Ti.Yahoo.yql(query, function(e) {
var search = Titanium.UI.createSearchBar({
showCancel:true
});
var data = e.data,
newRow;

var tableView = Ti.UI.createTableView({
search: search,
filterAttribute: 'theTitle'
});

// Create search bar
var search = Titanium.UI.createSearchBar({
showCancel:true,
height:43,
top:0,
});

// Create Tableview
var tableView = Ti.UI.createTableView({
search: search,
filterAttribute: 'theTitle'
});

// Populate a tableview with the titles
Ti.UI.currentWindow.add(tableView);
var tableData = [];

// For each item from the total number of postings returned from the query...
for (var i = 0, j = data.item.length; i < j; i++) {

// Refresh buttons
if (Ti.Platform.name === 'iPhone OS') {
var refresh = Titanium.UI.createButton({
systemButton: Titanium.UI.iPhone.SystemButton.REFRESH
});
win.rightNavButton = refresh;

refresh.addEventListener('click', function () {
Ti.App.fireEvent("show_indicator");
tableView.setData(null);
setTableData();
});
}
else if (Titanium.Platform.name === 'android')
{
var activity = Ti.Android.currentActivity;
activity.onCreateOptionsMenu = function(e) {
var menu = e.menu;
var menuItem = menu.add({ title: "Refresh" });
menuItem.addEventListener("click", function(e) {
Ti.App.fireEvent("show_indicator");
tableView.setData(null);
setTableData();
});
};
}


function setTableData() {

// YQL query to get feed.
YQLMatches = Ti.App.Properties.getString('websiteName');

siteUrl = "www.fda.gov/downloads/Drugs/DrugSafety/DrugShortages/UCM163172.xml";

newRow = Ti.UI.createTableViewRow({
path : 'articleFDA.js',
url : data.item[i].link,
desc : data.item[i].description,
hasChild : true,
theTitle : data.item[i].title,
//className : 'fda_row'
});

// Need label in order to change the font size.
var articleTitleLabel = Ti.UI.createLabel({
text : data.item[i].title,
left : 10,
right : 30,
color: '#000',
font : {fontSize : 15, fontWeight: 'bold'}
});
query = "Select title, description, link from rss where url='" + siteUrl + "' and title MATCHES '.*"+ YQLMatches +".*' | unique(field='link') | sort(field='title')";

Ti.Yahoo.yql(query, function (e) {
data = e.data;

newRow.add(articleTitleLabel);
tableData.push(newRow);
//Ti.API.info(data);
//Ti.API.info(data.item.length);

// if (data === null)
// {
// Ti.App.fireEvent("hide_indicator");
// Titanium.UI.createAlertDialog({
// title: 'ERROR',
// message: 'No data could be retrieved. Please Check your internet connection.' }).show();
// return;
// }
if (data === null) {
Ti.API.info('data.item.length == null');

newRow = Ti.UI.createTableViewRow({
hasChild: false,
});

// Label
var articleTitleLabel = Ti.UI.createLabel({
text: 'Nothing to report',
left: 10,
right: 30,
color: '#000',
font: {
fontSize: '15dp',
fontWeight: 'bold'
}
});
newRow.add(articleTitleLabel);
tableView.appendRow(newRow);
Ti.App.fireEvent("hide_indicator");

}

} // end YQL

tableView.setData(tableData);

// Populate a tableview with the titles
else if (data.item.length == null) {
//Remove titles
data.item.title = data.item.title.replace("Current Drug Shortages: ", "");
data.item.title = data.item.title.replace("Resolved Drug Shortages: ", "");
data.item.title = data.item.title.replace("Drugs to be Discontinued: ", "");
data.item.title = data.item.title.replace("(updated)", "");


// When a title is clicked, open a fire event and pass the details of the selected posting.
newRow = Ti.UI.createTableViewRow({
theTitle: data.item.title,
pubDate: data.item.pubDate,
desc : data.item.description,
url: data.item.link,
hasChild: true,
className: 'FDA_row'
});
// Label
var articleTitleLabel = Ti.UI.createLabel({
text: data.item.title,
left: 10,
right: 30,
color: '#000',
font: {
fontSize: '15dp',
fontWeight: 'bold'
}
});
newRow.add(articleTitleLabel);
tableView.appendRow(newRow);
Ti.App.fireEvent("hide_indicator");
}

else {
var tableData = [];
// For each item from the total number of postings returned from the query...
for (var i = 0, j = data.item.length; i < j; i++) {

//Remove titles
data.item[i].title = data.item[i].title.replace("Current Drug Shortages: ", "");
data.item[i].title = data.item[i].title.replace("Resolved Drug Shortages: ", "");
data.item[i].title = data.item[i].title.replace("Drugs to be Discontinued: ", "");
data.item[i].title = data.item[i].title.replace("(updated)", "");

newRow = Ti.UI.createTableViewRow({
theTitle: data.item[i].title,
pubDate: data.item[i].pubDate,
desc : data.item[i].description,
url: data.item[i].link,
hasChild: true,
className: 'FDA_row'
});
// Label
var articleTitleLabel = Ti.UI.createLabel({
text: data.item[i].title,
left: 10,
right: 30,
color: '#000',
font: {
fontSize: '15dp',
fontWeight: 'bold'
}
});
newRow.add(articleTitleLabel);
tableData.push(newRow);
} // end YQL
tableView.setData(tableData);


// Data has been loaded/added, so remove the loading icon.
Ti.App.fireEvent("hide_indicator");
}
});
}
// When a title is clicked, open a new window and pass the details of the selected posting.
tableView.addEventListener('click', function (e) {

Ti.App.fireEvent('detailLoadFDA', {theUrl:e.rowData.url,desc:e.rowData.desc,theTitle:e.rowData.theTitle});

});

});

}
else {
var alertDialog = Titanium.UI.createAlertDialog({
title: 'CONNECTION REQUIRED!',
message: 'Your device is not online.',
buttonNames: ['OK']
});
alertDialog.show();
}

// Make sure device is connection to the internet

if (Ti.Network.online) {

// Show loading indicator
Ti.App.fireEvent("show_indicator");

// Load table
setTableData();

}

// If not connected, alert the user
else {
var alertDialog = Titanium.UI.createAlertDialog({
title: 'Internet Connection Required',
message: 'Your device is not online',
buttonNames: ['OK']
});
alertDialog.show();
}
2 changes: 1 addition & 1 deletion Resources/ipad/js/getFeed.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ if (Ti.App.Properties.getString('websiteName') == 'Current Shortages') {
function setTableData() {

// YQL query to get feed.
query = "Select link, pubDate, title from rss where url='" + siteUrl + "'";
query = "Select link, pubDate, title from rss where url='" + siteUrl + "' | sort(field='title')";

Ti.Yahoo.yql(query, function (e) {
data = e.data;
Expand Down
2 changes: 1 addition & 1 deletion Resources/ipad/js/trends.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function setTableData() {
right: 30,
color: '#000',
font: {
fontSize: 15,
fontSize: '15dp',
fontWeight: 'bold'
}

Expand Down
13 changes: 8 additions & 5 deletions Resources/ipad/main_windows/main_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ if (Titanium.Platform.name === 'android') { Ti.App.fireEvent("show_ads"); }


var data = [
{ title : 'Current Shortages', hasChild:true, path : '../ipad/js/getFeed.js', header:'ASHP Reported Drug Shortages'},
{ title : 'Resolved Shortages', hasChild:true, path : '../ipad/js/getFeed.js'},
{ title : 'Unavailable Drugs', hasChild:true, path : '../ipad/js/getFeed.js'},
{ title : 'Reported Shortages', hasChild:true, path : '../ipad/js/getFDA.js', header:'FDA Reported Drug Shortages'}
{ title : 'Current Shortages', head: 'ASHP - Current', hasChild:true, path : '../js/getFeed.js', header:'ASHP Reported Drug Shortages'},
{ title : 'Resolved Shortages', head: 'ASHP - Resolved', hasChild:true, path : '../js/getFeed.js'},
{ title : 'Unavailable Drugs', head: 'ASHP - Unavailable', hasChild:true, path : '../js/getFeed.js'},
{ title : 'Current Drug Shortages', head: 'FDA - Current', hasChild:true, path : '../js/getFDA.js', header:'FDA Reported Drug Shortages'},
{ title : 'Resolved Drug Shortages', head: 'FDA - Resolved', hasChild:true, path : '../js/getFDA.js'},
{ title : 'Drugs to be Discontinued', head: 'FDA - Discontinued', hasChild:true, path : '../js/getFDA.js'},
];

// Create table and fill it with list
Expand All @@ -38,7 +40,8 @@ tableView.addEventListener('click', function(e) {
var newWindow = Titanium.UI.createWindow({
url : e.rowData.path,
title : e.rowData.title,
barColor:'#336699'
barColor:'#336699',
backButtonTitle : 'Back',
});

Ti.App.Properties.setString('websiteName', e.rowData.title);
Expand Down
6 changes: 5 additions & 1 deletion Resources/js/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
*/

var win = Ti.UI.currentWindow;



win.backgroundColor = '#ffffff';


var webview = Ti.UI.createWebView({
scalePageToFit : true,
url : 'http://mickschroeder.com/pharmacy/parse/parse.php?Link=' + win.theUrl + '&pubDate=' + win.pubDate
});

Ti.API.info('http://mickschroeder.com/pharmacy/parse/parse.php?Link=' + win.theUrl + '&pubDate=' + win.pubDate);

// Add the webview (the original webpage article), and animate the page into view.
win.add(webview);

Expand Down
4 changes: 2 additions & 2 deletions Resources/js/articleFDA.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

var win = Ti.UI.currentWindow;

// Can't find a way to gain access to variables from within an .html webview. Doing it this way for now - but is sloppy. I'm sure there's a smarter/cleaner way.

var webview = Ti.UI.createWebView({
scalePageToFit : true,
html : '<html><head><style type="text/css">* { max-width: 270px; } body { margin-bottom: 50px; padding: 10px; font-family: helvetica neue, helvetica, arial; width: 270px; overflow: hidden; color : #3f3f3f; } h1,h2,h3,h4,h5 { color: black; } img { max-width: 270px; } pre { white-space: pre-wrap; }</style><body><h3>' + win.theTitle + '</h3>' + win.desc + '</body></html>'
Expand Down Expand Up @@ -56,6 +56,6 @@ activity.onCreateOptionsMenu = function(e) {
}


// Add the webview (the original webpage article), and animate the page into view.
// Add the webview
win.add(webview);

Loading

0 comments on commit 7b2355b

Please sign in to comment.