PDA

View Full Version : How to convert this code into Sencha Touch code?



Sunforever0220
18 Mar 2011, 5:40 AM
How to change this code into SenchaTouch executable code (some of the functions in this code might not be accepted in sencha touch)?



var startDate= new Date(currentDate + " "+startTime);
var endDate= new Date(currentDate + " "+endTime);
var nextStart = new Date(currentDate+1 + " "+nextStartTime);//date of the next day, and user input.
var df=(endDate.getTime()-startDate.getTime());
var dailyrest=0;
var typeofRest = "";
var nextRest = new Date();
var mustRest = new Date();
var Rest = "";
var MRest = "";

if multi-manning //when the checkbox "Multi-Manning of this shift" is Checked
if nextStart>=startDate + 30hours
dailyrest = (30*3600*1000-df);
else dailyrest = nextStart.getTime()-df;
else //the checkbox is not checked
if nextStart>=startDate + 24hours
dailyrest = (24*3600*1000-df);
else dailyrest = nextStart.getTime()-df;

var DRHour = Math.floor (dailyrest/3600/1000);
var DRMin = Math.floor ((dailyrest%3600/1000)/60/1000);

var DailyRestMsg = "Your daily rest is " + DRHour + "hours " + DRMin + "mins." ;

//normal daily rest or reduced daily rest?
if dailyrest>=11*3600*1000
typeofRest = "It was a normal daily rest.";
else if dailyrest>=9*3600*1000&&dailyrest<11*3600*1000milliseconds
typeofRest = "It was a reduced daily rest.";
else
typeofRest = "Illegal daily rest occured!";

//prediction of next rest and must rest
if multi-manningNextShift //Checkbox "Multi-manning of the next shift" is checked
nextRest = nextStart.getTime()+19hours;
mustRest = nextStart.getTime()+21hours;
Rest = "Suggested next rest is " + nextRest.getTime();
MRest = "You must take rest from " + mustRest.getTime();

else //Checkbox "Multi-manning of the next shift" is not checked
nextRest = nextStart.getTime()+13hours;
mustRest = nextStart.getTime()+15hours;
Rest = "Suggested next rest is " + nextRest.getTime();
MRest = "You must take rest from " + mustRest.getTime();

//alert the result
alert(DailyRestMsg + "\t" + typeofRest + "\t" + Rest + "\t" + MRest);


The input values of variables startTime, endTime and nextStartTime are taken from the form
input time.js:



Ext.setup( {
onReady: function() {
// create the root panel
new Ext.Panel({
fullscreen: true,
items: [
// add a panel to the root panel
{
xtype: "form",
items: [
{
xtype: "textfield",
name: "Start Time",
label: "Start",
placeHolder: "hh:mm (0:00-23:59)"
},
{
xtype: "textfield",
name: "End Time",
label: "End",
placeHolder: "hh:mm (0:00-23:59)"
},
{
xtype: "textfield",
name: "Start Next",
label: "Start Time of Next Shift",
placeHolder: "hh:mm (0:00-23:59)"
},
//checkbox for multi-manning (current shift)
//checkbox for multi-manning (next shift)
//Take the input values and calculate, alert the result after calculation(click on the calculation button or something similar)

]
}
]
});
}
})


How to implement these in SenchaTouch in this form?
//checkbox for multi-manning (current shift)
//checkbox for multi-manning (next shift)
//Take the input values and calculate, alert the result after calculation(click on the calculation button or something similar)

mitchellsimoens
18 Mar 2011, 8:06 AM
Have you tried to convert it? I will for $300 an hour :D

Sunforever0220
18 Mar 2011, 8:10 AM
Have you tried to convert it? I will for $300 an hour :D
Yes I tried but seems some fomulas of date time calculation are not available in sencha touch. Any hints?

mitchellsimoens
18 Mar 2011, 8:13 AM
Yes I tried but seems some fomulas of date time calculation are not available in sencha touch. Any hints?

First I would clean up the code, it's a bit messy IMHO.

Now, when you get an error, it should tell you where the error is. Once you get an error, check the API docs to see if it should be correct. If you still can't figure it out, let us know where the error is on which line.

Sunforever0220
18 Mar 2011, 8:17 AM
First I would clean up the code, it's a bit messy IMHO.

Now, when you get an error, it should tell you where the error is. Once you get an error, check the API docs to see if it should be correct. If you still can't figure it out, let us know where the error is on which line.

Actually I'm using xcode for code editing and the executing was on browser. Not able to do emulator test at this moment. Before that I used eclipse only but this cannot get debugged on eclipse....

mitchellsimoens
18 Mar 2011, 8:18 AM
Have you tried to view in Chrome or Safari and look at any errors?

Sunforever0220
18 Mar 2011, 8:19 AM
Have you tried to view in Chrome or Safari and look at any errors?

I tried safari but it returns blank page only....no error messages...

mitchellsimoens
18 Mar 2011, 8:23 AM
I tried safari but it returns blank page only....no error messages...

Really? Just copied and pasted your panel (which is overnested) and I am looking at the 3 fields you have.

Sunforever0220
18 Mar 2011, 8:32 AM
Really? Just copied and pasted your panel (which is overnested) and I am looking at the 3 fields you have.

I think the 3 fields are for the input times.js. The first part of code is for calculation, not user interface...
How to see the error messages then?

mitchellsimoens
18 Mar 2011, 8:42 AM
First, let's clean up your code and add checkboxes and some buttons...


Ext.setup({
onReady: function() {
var form = new Ext.form.FormPanel({
fullscreen : true,
dockedItems : {
xtype : "toolbar",
dock : "top",
items : [
{ text : "Reset", ui : "decline" },
{ xtype : "spacer" },
{ text : "Calculate", ui : "confirm" }
]
},
items : [
{
xtype : "textfield",
name : "start_time",
label : "Start",
placeHolder : "hh:mm (0:00-23:59)"
},
{
xtype : "textfield",
name : "end_time",
label : "End",
placeHolder : "hh:mm (0:00-23:59)"
},
{
xtype : "textfield",
name : "next_start",
label : "Start Time of Next Shift",
placeHolder : "hh:mm (0:00-23:59)"
},
{
xtype : "checkboxfield",
name : "current_shift",
label : "Current Shift"
},
{
xtype : "checkboxfield",
name : "next_shift",
label : "Next Shift"
}
]
});
}
});

Look a little better? Next step is to handle the buttons to do calculation.

Sunforever0220
18 Mar 2011, 12:43 PM
This code is not executable. Is this because of the version difference?(I'm using sencha touch beta v0.97)

First, let's clean up your code and add checkboxes and some buttons...


Ext.setup({
onReady: function() {
var form = new Ext.form.FormPanel({
fullscreen : true,
dockedItems : {
xtype : "toolbar",
dock : "top",
items : [
{ text : "Reset", ui : "decline" },
{ xtype : "spacer" },
{ text : "Calculate", ui : "confirm" }
]
},
items : [
{
xtype : "textfield",
name : "start_time",
label : "Start",
placeHolder : "hh:mm (0:00-23:59)"
},
{
xtype : "textfield",
name : "end_time",
label : "End",
placeHolder : "hh:mm (0:00-23:59)"
},
{
xtype : "textfield",
name : "next_start",
label : "Start Time of Next Shift",
placeHolder : "hh:mm (0:00-23:59)"
},
{
xtype : "checkboxfield",
name : "current_shift",
label : "Current Shift"
},
{
xtype : "checkboxfield",
name : "next_shift",
label : "Next Shift"
}
]
});
}
});

Look a little better? Next step is to handle the buttons to do calculation.

mitchellsimoens
18 Mar 2011, 12:44 PM
Wow, you are still using a beta? Yeah, that could definitely be it

Sunforever0220
23 Mar 2011, 2:42 AM
Ok now another question: How to get the input from the form and calculate? The standard submit only send all the input data together to a server instead of processing data from each fields. Any solution?