I have a simple login form that after a correct login slides to the next view. A combination of two examples I found. I want to divide this login over several files using the MVC pattern. In many examples I have seen on the web this is a piece of cake in Sencha Touch 2. No matter what I try, I can’t get it working. I’m used to program in Flex, Java, ActionScript, Php but the Sencha jSon is a whole other ballgame. Anyone could help me with this? I would like to have a Model, Store, View and Controller package in the recommended folder structure:
-app
-controller
-Controller.js
-model
-Model.js
-store
-Store.js
-view
-Main.js
-Login.js
-SecondView.js
-app.js
-app.css
-index.html
This is the current app.js that contains all the logic in one file.
Ext.require([
'Ext.form.Panel',
'Ext.form.FieldSet',
'Ext.field.Text',
'Ext.field.Password',
'Ext.data.Store'
]);
Ext.define('User', {
extend: 'Ext.data.Model',
config: {
fields: [
{name: 'name', type: 'string'},
{name: 'password', type: 'string'}
]
}
});
Ext.setup({
icon: 'icon.png',
tabletStartupScreen: 'tablet_startup.png',
phoneStartupScreen: 'phone_startup.png',
glossOnIcon: false,
onReady: function() {
var form;
var formBase = {
url: 'login.php',
standardSubmit: false,
title:"Login",
items: [
{
xtype: 'fieldset',
title: 'MyCompony',
instructions: 'Log in with username and password.',
defaults: {
required: true,
labelAlign: 'left',
labelWidth: '40%'
},
items: [
{
xtype: 'textfield',
name: 'name',
label: 'Name',
value: 'user',
autoCapitalize: false
},
{
xtype: 'passwordfield',
name: 'password',
label: 'Password',
value: 'test'
}
]
},
{
xtype: 'toolbar',
docked: 'bottom',
items: [
{xtype: 'spacer'},
{
text: 'Reset',
handler: function() {
form.reset();
}
},
{
text: 'Login',
ui: 'confirm',
handler: function() {
if (formBase.user) {
form.updateRecord(formBase.user, true);
}
form.submit({
waitMsg: {message: 'Submitting'}
});
}
}
]
}
],
listeners: {
submit: function(form, result) {
console.log('success', Ext.toArray(arguments));
view.push({
title: 'Second View',
padding: 10,
items: [
{
html: 'Second view'
},
{
xtype: 'button',
text: 'Pop this view!',
width: 200,
handler: function() {
view.pop();
}
}
]
});
},
exception: function(form, result) {
console.log('failure', Ext.toArray(arguments));
}
}
};
if (Ext.os.deviceType == 'Phone') {
Ext.apply(formBase, {
xtype: 'formpanel',
autoRender: true
});
} else {
Ext.apply(formBase, {
xtype: 'formpanel',
autoRender: true,
padding: 100
});
}
form = Ext.create('Ext.form.Panel', formBase);
var view = Ext.create('Ext.navigation.View', {
fullscreen: true,
items: [
form
]
});
}
});
This is a simple php script (login.php) to answer the login request.
<?php
$pw = $_REQUEST['password'];
header('Content-Type: application/json');
if($pw == 'asdf'){
echo '{"success":true, "msg":'.json_encode('This User is authorized').'}';
}else{
echo '{"success":false, "msg":'.
json_encode('This User is NOT authorized').
', "errors" : { "password" :'.json_encode('Password is required').
'}'.
', "pwd" :'.json_encode($pw).'}';
}
Anyone?
Okay after some research (days) here’s the answer:
index.html:
login.php:
app.js:
werkorders.json
app/view/Main.js:
app/view/Login.js:
app/view/workorder/map.js:
app/view/workorder/Edit.js:
app/controller/AppController.js:
app/model/WorkOrder.js:
app/store/WorkOrders.js: