以下は私のコントローラーです。チタンで1ページのファイルを表示します
----index.js----
function login(e) {
var uname = $.username.value.split(' ').join('');
var pwd = $.password.value.split(' ').join('');
if(uname == ""){
alert("Enter username.");
return false;
}
if(pwd == ""){
alert("Enter password.");
return false;
}
//if(results.length == 0){
if (Titanium.Network.networkType === Titanium.Network.NETWORK_NONE) {
alert('There is no internet connection.');
return false;
}
var loginReq = Titanium.Network.createHTTPClient();
var params = {
func : "'"+Ti.Utils.base64encode('check_login')+"'",
username : uname,
password : pwd
};
loginReq.onload = function()
{
var json = this.responseText;
var response = JSON.parse(json);
if(response == 'account_inactive'){
alert('Your account has been inactive. Please contact to your company');
//$.index.close();
var index = Alloy.createController('index').getView();
index.open();
return false;
}
if(response == 'invalid'){
alert('Invalid username or password');
//$.index.close();
var index = Alloy.createController('index').getView();
index.open();
return false;
}
else
{
results = {
iuser_id: response.iuser_id,
signup_ids: response.signup_ids,
staff_id : response.staff_id,
vusername: response.vusername,
vfirst_name: response.vfirst_name,
vlast_name: response.vlast_name,
vemail : response.vemail,
vpwd : response.vpwd
};
Ti.App.Properties.setObject("user_session",results);
results = null;
var flag = '';
if (!Ti.App.Properties.hasProperty('installed'))
{
Ti.App.Properties.setBool('app:isLoggedIn', true);
Ti.App.Properties.hasProperty('installed');
Ti.App.Properties.setBool('installed', true);
var th_sign = Alloy.createController('login').getView();
th_sign.open();
}
else
{
var th_sign = Alloy.createController('account').getView();
th_sign.open();
}
}
json = null;
response = null;
};
if(os_name == 'android'){
loginReq.open("GET", WEB_ROOT+"get_init.php");
}
else{
loginReq.open("POST", WEB_ROOT+"get_init.php");
}
loginReq.send(params);
}
$.index.open();
----index.xml---------
<Alloy>
<Window class="login_container" height="auto" horizontalWrap="true">
<ScrollView id="scrollView_index" showVerticalScrollIndicator="true" height="100%" width="100%" scrollType="vertical">
<View id="index_view">
<ImageView class="logo" image="/images/login/logo.png" top='25' />
<TextField id="username" class="usernameTxt" value="" border="0" top="230" />
<TextField id="password" class="passwordTxt" value="" border="0" top="275" />
<Button id="loginButton" class="login_bg" onClick="login">Login</Button>
</View>
</ScrollView>
</Window>
</Alloy>