Skip to content

Instantly share code, notes, and snippets.

@Amimul100
Created July 7, 2014 03:58
Show Gist options
  • Save Amimul100/4e4c8cea73b661e0f21f to your computer and use it in GitHub Desktop.
Save Amimul100/4e4c8cea73b661e0f21f to your computer and use it in GitHub Desktop.
Titanium Classic DashboardView
/*
Hi, I have tested this issue in Ti SDK 3.3.0.RC. It’s working good.
Testing Environment:
Titanium SDK: 3.3.0.RC, 3.2.3.GA
Titanium CLI: 3.2.3
iOS simulator and device
Appcelerator Studio, build: 3.3.0.201406271159
Step to Reproduce
Create a sample Ti Classic project from AppC Studio
Update app.js file with test code
Run on iOS device or simulator
*/
var win = Ti.UI.createWindow({
backgroundColor: '#13386c'
});
var button = Ti.UI.createButton({
title: 'Edit',
style: Ti.UI.iPhone.SystemButtonStyle.DONE,
});
var toolbar = Ti.UI.iOS.createToolbar({
items:[button],
top: 0
});
win.add(toolbar);
var label = Ti.UI.createLabel({
color: 'white',
font: { fontSize: 14 },
text: 'Click an item to reset badge\nPress and hold an item to enable edit mode',
textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
top: 55,
height: 40,
width: 300
});
win.add(label);
var dashboardData = [];
var itemData = [
{ name: 'account', badge: 10 },
{ name: 'cases', badge: 2 },
{ name: 'calls', badge: 2 },
{ name: 'contacts', badge: 5},
{ name: 'emps' },
{ name: 'leads' },
{ name: 'meetings', badge: 3 },
{ name: 'opps', badge: 126 }, // badge will be displayed as "99+"
{ name: 'tasks' }
];
for (var i=0, ilen=itemData.length; i<ilen; i++){
var item = Ti.UI.createDashboardItem({
badge: itemData[i].badge,
image: '/images/dashboard/' + itemData[i].name + '_off.png',
selectedImage: '/images/dashboard/' + itemData[i].name + '_on.png',
label: itemData[i].name
});
dashboardData.push(item);
}
var dashboard = Ti.UI.createDashboardView({
data: dashboardData,
wobble: true,
top: 100
});
win.add(dashboard);
var isEditable = false;
button.addEventListener('click', function(e){
if(isEditable){
dashboard.stopEditing();
} else {
dashboard.startEditing();
}
});
dashboard.addEventListener('edit',function(e){
button.title = 'Done';
button.style = Ti.UI.iPhone.SystemButtonStyle.DONE;
isEditable = true;
});
dashboard.addEventListener('commit',function(e){
button.title = 'Edit';
button.style = Ti.UI.iPhone.SystemButtonStyle.PLAIN;
isEditable = false;
});
dashboard.addEventListener('click', function(e){
e.item.badge = 0;
});
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment