Skip to content

Instantly share code, notes, and snippets.

@feedhenry-gists
feedhenry-gists / gist:1024729
Created June 14, 2011 11:33
Tutorial Sencha Touch Contact Model Registeration
// Define what a contact is, and its fields
app.m.contact = Ext.regModel('Contact', {
fields: ['first', 'last']
});
@feedhenry-gists
feedhenry-gists / gist:1024728
Created June 14, 2011 11:32
Tutorial Sencha Touch MVC Pattern List Contacts Callback
app.c.contact = function () {
....
list: function (b, e) {
....
}
})();
@feedhenry-gists
feedhenry-gists / gist:1024725
Created June 14, 2011 11:31
Tutorial Sencha Touch MVC Pattern List Contacts
....
items: [{
ui_type: 'Ext.Button',
text: 'List Contacts',
.....
handler: 'contact.list' // Controller endpoint to callback to
}, ....]
....
@feedhenry-gists
feedhenry-gists / gist:1024720
Created June 14, 2011 11:30
Tutorial Sencha Touch Display Image
$fh.webview({
url: "www.feedhenry.com",
title: "FeedHenry"
}, function (result) {
// no need to do anything as webview is displayed
}, function (err) {
// Problem showing webview, show error instead
....
});
@feedhenry-gists
feedhenry-gists / gist:1024718
Created June 14, 2011 11:29
Tutorial Sencha Touch Mapping Lookup
// Get location using Geolocation API
$fh.geo({interval: 0}, function (res) {
// Got geolocation details in response. Pass them into map api, initialising map at that point
$fh.map({
target: '#maps_div',
lat: res.lat,
lon: res.lon,
zoom: 15
}, function (res) {
// Map is being shown, no need to do anything here
@feedhenry-gists
feedhenry-gists / gist:1024715
Created June 14, 2011 11:28
Tutorial Sencha Touch Display Image
// get the format of the image and base64 data from the returned picdata
var resultHtml = "<img src='data:image/" + picdata.format + ";base64," + picdata.b64 + "' width='300px' height='300px' ></img>";
// get the last item below the buttons, which should be a container,
// and update it with the image
var items = inst.v.mainPanel.getActiveItem().items;
items.get(items.length - 1).update({
html: resultHtml
});
@feedhenry-gists
feedhenry-gists / gist:1024711
Created June 14, 2011 11:22
Tutorial Sencha Touch List Creation
// Get contacts from device
$fh.contacts({act: 'list'}, function (data) {
// get the contacts array from data returned
var contacts = data.list;
// create the data store, passing in the contacts list
var store = new Ext.data.JsonStore({
model: app.m.contact, // the contact model that is registered in /client/default/script/models/contact.js
sorters: 'last', // sort by 'last' field
getGroupString: self.getGroupString, // the grouping callback for each item
@feedhenry-gists
feedhenry-gists / gist:1024689
Created June 14, 2011 11:03
Current Date/Time Cache Current Time
function getCurrentTimeRegEx() {
var response = $fh.web({
url: 'http://www.timeanddate.com/worldclock/city.html?n=78',
period: 10000, //Cache response for 10 seconds
method: 'GET'
});
// Construct a regular expression to extract the date and time from the response
var reg = /(<strong id=ct[^>]*>)([^<]*)/;
@feedhenry-gists
feedhenry-gists / gist:1024688
Created June 14, 2011 11:03
Current Date/Time Cache Server Side New
function readTime() {
$fh.act({act:'getCurrentTimeRegEx'}, function(res) {
// Display the time in-app using jQuery
$('#current_time_response').html(res.date);
});
}
@feedhenry-gists
feedhenry-gists / gist:1024687
Created June 14, 2011 11:01
Current Date/Time Cache Return Time Date
function getCurrentTimeRegEx() {
var response = $fh.web({
url: 'http://www.timeanddate.com/worldclock/city.html?n=78',
method: 'GET'
});
// Construct a regular expression to extract the date and time from the response
var reg = /(<strong id=ct[^>]*>)([^<]*)/;