Monday, December 19, 2011

Titanium Table creation with click event


http://developer.appcelerator.com/question/122206/double-click-textfield-in-tableview-to-fire-click-event
win = Titanium.UI.createWindow({
    backgroundColor:'white',
    fullscreen:false
});
 
tableView = Titanium.UI.createTableView();
 
var dataArray = [];
for(var i=0; i<10; i++){
    var row = Titanium.UI.createTableViewRow();
 
    var label = Titanium.UI.createLabel({
        text:'THIS IS LABEL  ' + i,
        width:100,
        height:'auto'
    });
    var textBox = Titanium.UI.createTextField({
        right:5,
        width:30
    })
 
    row.add(label);
    row.add(textBox);
 
    dataArray.push(row);
}
 
var lastRow;
tableView.addEventListener('click', function(e){
    lastRow = e.row;
    if(lastRow){
        lastRow.backgroundColor='white';
    }
    e.row.backgroundColor='red';
})
 
 
tableView.setData(dataArray);
 
win.add(tableView);
win.open();

titanium Tableview Supported Links

http://developer.appcelerator.com/question/118419/how-to-get-rowdata-from-custom-tableviewrow

alert(e.row.children[0].text);


var thisRow = Ti.UI.createTableViewRow({
        className:"itemOptions",
        layout:"vertical",
        height:50,
        myProperty1:'somevalue',
        myProperty2:1234
        });

table.addEventListener('click', function(e) {
  alert(e.rowData.myProperty1);
});

http://developer.appcelerator.com/question/96441/passing-row-data-to-new-widow


Saturday, December 17, 2011

Titanium Appcelerator Web services method like AJAX

https://wiki.appcelerator.org/display/guides/HTTPClient+and+the+Request+Lifecycle


GET

var url = "https://www.appcelerator.com" ;
var xhr = Ti.Network.createHTTPClient({
    onload: function(e) {
        // this function is called when data is returned from the server and available for use
        // this.responseText holds the raw text return of the message (used for text/JSON)
        // this.responseXML holds any returned XML (including SOAP)
        // this.responseData holds any returned binary data
        Ti.API.debug(this.responseText);
        alert('success');
    },
    onerror: function(e) {
        // this function is called when an error occurs, including a timeout
        Ti.API.debug(e.error);
        alert('error');
    },
    timeout:5000  /* in milliseconds */
});
xhr.open("GET", url);
xhr.send();  // request is actually sent with this statement




POST


var xhr = Ti.Network.createHTTPClient();

xhr.onload = function(e) {
    //handle response, which at minimum will be an HTTP status code
};

xhr.open('POST','http://www.myblog.com/post.php' );
xhr.send({
    title:'My awesome blog',
    body:'Today I met Susy at the laundromat.  Best day EVAR\!'
});




Ready State Monitoring


var xhr = Ti.Network.createHTTPClient({
    onload: function(e) {
        // function called in readyState DONE (4)
        Ti.API.info('onload called, readyState = '+this.readyState);
    },
    onerror: function(e) {
        // function called in readyState DONE (4)
        Ti.API.info('onerror called, readyState = '+this.readyState);
    },
    ondatastream: function(e) {
        // function called as data is downloaded
        Ti.API.info('ondatastream called, readyState = '+this.readyState);
    },
    onsendstream: function(e) {
        // function called as data is uploaded
        Ti.API.info('onsendstream called, readyState = '+this.readyState);
    },
    onreadystatechange: function(e) {
        switch(this.readyState) {
            case 0:
                // after HTTPClient declared, prior to open()
                // though Ti won't actually report on this readyState
                Ti.API.info('case 0, readyState = '+this.readyState);
            break;
            case 1:
                // open() has been called, now is the time to set headers
                Ti.API.info('case 1, readyState = '+this.readyState);
            break;
            case 2:
                // headers received, xhr.status should be available now
                Ti.API.info('case 2, readyState = '+this.readyState);
            break;
            case 3:
                // data is being received, onsendstream/ondatastream being called now
                Ti.API.info('case 3, readyState = '+this.readyState);
            break;
            case 4:
                // done, onload or onerror should be called now
                Ti.API.info('case 4, readyState = '+this.readyState);
            break;
        }
    },
    timeout:5000  /* in milliseconds */
});
xhr.open("GET", 'http://training.appcelerator.com.s3.amazonaws.com/atp_doc.pdf');
xhr.send();  // request is actually sent with this statement



Titanium Appcelerator Remember me

http://developer.appcelerator.com/question/117952/remember-me--session-implementation


Ti.App.Properties.setString('login_name','kamal');
my_property_value = Ti.App.Properties.getString('login_name');

If it's never been set before it will naturally return undefined.
You can also set booleans, integers, lists and doubles. See : http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.App.Properties-module
hope this helps! ;)
As commented, hopefully your app is posting the login to the server securely. If you don't have https, there are some cunning ways to use MD5 to create a 'challenge and response' pair of hashes on login (etc.) which is pretty secure.




Friday, December 9, 2011

Drupal set different theme for admin only

Go to Administer > Site configuration > Administration theme.