Where to define function in rhomobile..?

Showing 1-16 of 16 messages
Where to define function in rhomobile..? abhay 8/22/12 11:28 AM
Hi,
 
I am trying to create Login Screen, which contains two edit text fields(Username and Password) and two buttons(Login and Register). When the user clicks on Login Button, I am trying to call login.erb and when the user tries to click on the button Register i tried to call register.erb file.
 
For that i tried something  like this when the user clicks on button:
 

      <a  href="<%= url_for :controller => :Settings, :action => :login%>"><button value ="Login"/></a>

      <a href="<%= url_for :controller => :Settings, :action => :register%>"><button value ="Register"/></a>

 

It's working fine but, before calling login.erb file where do I have to do validations for username and password..? . Actually I had tried validations in javascript it's working fine but from javascript we cannot call ruby syntax(the above shown two statements)....?

 

Do I need to do valdations using ruby or what..?but I am very new to rho mobile, I am not aware of ruby..

Can we call ruby fron java script..? Help me out,please....

 

 
Re: Where to define function in rhomobile..? Rob 8/22/12 3:39 PM
Yes, you can call a controller method from javascript using asynchttp.  I do it all through my app...
Re: Where to define function in rhomobile..? abhay 8/22/12 11:35 PM
Hi ,
 
Thanks for the reply, Could you please send me some code snippet, bcoz I am new rhomobile and started learning ruby now..
 
I tried something like this,
Onclick of Login button I am calling the function validateLogin() which is defined in script,
 
<script type = "text/javascript">
  function validateLogin(){
       if(condition true){
  //calling here to go to welcome.erb,iflogin success .
     <a href="<%= url_for :controller => :Settings, :action => :welcome%>"></a>
 
}
}
</script>
 
which is not working, How can I call welcome.erb, if login is success...?   
Re: [rhomobile] Re: Where to define function in rhomobile..? inchara 8/23/12 2:49 AM
Hi abhay

try like this
def validation
if @params["celnumber"]== '' && @params["password"]== ''
      Alert.show_popup 'Cellphone number or PIN incorrect.'
      redirect :action => :login
    elsif @valueCellN == false
      Alert.show_popup 'Cellphone number or PIN incorrect.'
      redirect :action => :login
else
redirect :action => :home
end

--
You received this message because you are subscribed to the Google Groups "rhomobile" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rhomobile/-/oitP75VmYScJ.

To post to this group, send email to rhom...@googlegroups.com.
To unsubscribe from this group, send email to rhomobile+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rhomobile?hl=en.

Re: [rhomobile] Re: Where to define function in rhomobile..? abhay 8/25/12 7:35 AM
Hi,

I tried but it's not working.. Inside javascript function I defined ruby function as you mentioned but it's not working.. any help please....
Re: [rhomobile] Re: Where to define function in rhomobile..? abhay 8/25/12 8:49 PM
Hi,

I defined the ruby function as you told in the javascript but it's not working.... can anyone suggest me where I am doing wrong...


On Thursday, August 23, 2012 3:19:13 PM UTC+5:30, inchara wrote:
Re: [rhomobile] Re: Where to define function in rhomobile..? Jon Tara 8/26/12 8:26 AM
You can't define a Ruby function in Javascript.

We can't show you what you are doing wrong unless you give us an example.

You can do validation in Javascript, in your Controller, or both. Normally, doing validation in Javascript is considered insecure. However, since Javascript in Rhodes is embedded in an app, doing validation in Javascript is sufficient.

If you do validation in your controller, then you would either use some Ajax to let the user know about invalid input, or you would re-render the page with error messages.
Re: [rhomobile] Re: Where to define function in rhomobile..? abhay 8/26/12 10:15 PM
Hi,
 
Thanks for the reply.
Below I mentioned my index.erb file, what I am trying over there is, I am having Login screen(index.erb) in which if the username and password equals to 10603542
then I want to take the user to welcome.erb file, I am not knowing how to take the user to welcome.erb file from the javascript function check(form). Please help me out.
 
 
<div data-role="page" data-url="<%=Rho::RhoConfig.start_path%>/">
 
  <div data-role="header" data-position="inline">
    <h1>Splice Test</h1>
    <%if SyncEngine::logged_in > 0 %>
    <a href="<%=url_for:controller=>:Settings,:action=>:do_sync%>"class="ui-btn-left" data-icon="refresh">
      Sync
    </a>
    <a href="<%=url_for:controller=>:Settings,:action=>:logout%>"class="ui-btn-right" data-icon="star">
          Logout
        </a>
    <%else %>
        <a href="<%=url_for:controller=>:Settings,:action=>:login%>"class="ui-btn-right" data-icon="star">Login</a>
    <%end%>
 </div>
 
  <div data-role="content">
      <html>
      <head>
      <title>Login page</title></head>
      <body>
      <h1 style="font-family:ComicSansMs;text-align="center";font-size:20pt;color:#00FF00;>SimpleLoginPage</h1>
     <formname="login">
     Username<inputtype="text"name="userid"/>
     Password<inputtype="password"name="pswrd"/>
     <inputtype="button"onclick="check(this.form)" value="Login"/>
      <input type="reset" value="Cancel"/>
      </form>
 
      <script language="javascript">
    
      function check(form)
     /*functiontocheckuserid&password*/
      {
        /*thefollowingcodecheckeswhethertheentereduseridandpasswordarematching*/
        if(form.userid.value == "10603542" && form.pswrd.value =="10603542")
          {
            alert("LoginSuccessfull");
        // From here I want to call welcome.erb file , I tried by using the below statement but it's not working..
            <a  href="<%=url_for:controller=>:Settings,:action=>:welcome%>"></a>
          }else {
            alert("ErrorPasswordorUsername");
          }
        }
        </script>
        </body>
        </html>
  </div>
 
</div>
Re: [rhomobile] Re: Where to define function in rhomobile..? Jon Tara 8/27/12 10:17 AM
I don't understand why you want to do password authentication in Javascript. Why don't you do it in the controller, where this is normally done?

When I said that it is OK to do validation in Javascript, I mean like checking a field to see if it is a phone number, has invalid characters, etc.

This is just form submission. Surely there are examples in sample app. I'm sure there is a login example there as well.

I think if you are trying to do password authentication in Javascript, you are missing some fundamental concept of Rhodes or MVC in general. It's quite simple, and you are making it complicated.

You send a form to the server. The server does something with the data. The server sends back a page. In the case of Rhodes, the server in in the device.


Re: [rhomobile] Re: Where to define function in rhomobile..? abhay 8/27/12 11:11 AM
Hi Jon Tara,
 
Thanks for the reply. To do validations in controller we need to know Ruby right but I am not aware of Ruby, I have to learn.
 
Actually, I am not understanding, how to communicate from .erb file to controller.?
 
 For example as you told, I'm having an index.erb file  which contains an edit field  in which user have to enter phone numner, After entering the phone number if the user clicks on submit button then
I want to validate that number, for that  how to pass the Phonenumber to controller for validation. Means if the user enters the proper phone number then I want to take him to success.erb file else fialure.erb file. How can I achieve this. Help me out please.
Re: [rhomobile] Re: Where to define function in rhomobile..? Jon Tara 8/27/12 11:47 AM
Well, since Rhodes uses Ruby for mostly (with javascript for UI only) I'd suggest you learn Ruby.

You need to learn the MVC pattern, which is used by Rhodes.

When the user hits the submit button on a form, it's just like submitting a form to a website. You need to write a controller method (in Ruby) to handle the form data.

I think you need to begin at the beginning, and read the documentation.

I'd at least read about App Structure:

http://docs.rhomobile.com/rhodes/application

and User Interface:

http://docs.rhomobile.com/rhodes/ui

If you want to do your project in Javascript, you shouldn't be using Rhodes. Use PhoneGap, or something similar.
Re: [rhomobile] Re: Where to define function in rhomobile..? Egghead 8/27/12 7:03 PM
I think trying to avoid Ruby while using Rhodes would be a bit ambitious. Many of us are new to Ruby, but it's not very hard to learn, in fact, you might like it :)
Re: [rhomobile] Re: Where to define function in rhomobile..? inchara 8/31/12 2:30 AM
Please define that code controller.rb file

On Tue, Aug 28, 2012 at 7:33 AM, Egghead <mark.no...@gmail.com> wrote:
I think trying to avoid Ruby while using Rhodes would be a bit ambitious. Many of us are new to Ruby, but it's not very hard to learn, in fact, you might like it :)

--
You received this message because you are subscribed to the Google Groups "rhomobile" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rhomobile/-/b-D954Rko_wJ.

To post to this group, send email to rhom...@googlegroups.com.
To unsubscribe from this group, send email to rhomobile+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rhomobile?hl=en.


Re: [rhomobile] Re: Where to define function in rhomobile..? Prabu Duraiswamy 9/7/12 10:47 PM
Hi Abhy,

Hope this sample help you to get some idea.

In View page.
login.erb
<script src="/public/jquery/jquery.min.js" type="text/javascript"></script>
<form method="POST" action="<%= url_for :action => :create %>" id="login-form">
  <div id="error" style="display:block">
       <%= @params['notice'] %>
  </div>
  <input id="phonenum" name="authentication[phonenumber]" type="text" placeholder="Phonenumber">
  <input id="password" name="authentication[password]" placeholder = "Password" type="password">
  <button type="submit">Sign In</button>
</form>
<script type="text/javascript">
$(document).ready(function() {
    $("#login-form").submit(function(event) {
        phone= $('#phonenum').val();
        pwd = $('#password').val();
        if (phone == '') {
            $("#error").css("display", "block");
            $('#error').html("Please enter your phone number");
            return false;
        } else if (pwd == '') {
            $("#error").css("display", "block");
            $('#error').html("Please enter your password");
            return false;
        }
    });
});
</script>

In Controller
def create
    if @params['authentication']["phonenumber"] == ''10603542"
        notice = " Login successful"
        WebView.navigate(url_for(:action => :welcome, :controller => :Home, :notice=> notice))
    else
        notice = "Invalid access try again."
        redirect :action => :login, :query=>{:notice => notice }
    end
end

--
Regards,
Prabu D


--
You received this message because you are subscribed to the Google Groups "rhomobile" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rhomobile/-/5LaFqG6MgxYJ.

To post to this group, send email to rhom...@googlegroups.com.
To unsubscribe from this group, send email to rhomobile+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rhomobile?hl=en.


Re: [rhomobile] Re: Where to define function in rhomobile..? Egghead 10/10/12 11:36 PM
Just tested this in Win Mobile. On not entering any Phone Number and submitting the form, I only get the controller (server-side) validation message : "Invalid access try again". So it looks like JavaScript/AJAX is not supported at all on Windows Mobile without webkit. Please correct me if I'm wrong.

In another app using JQM, I included data-filter="true" in a listview. When built and run on Windows Mobile (without webkit), it graciously ignored that directive, and my app's functionality was not affected, albeit not having the filtering facility offered in other platforms.

So, on to some questions :

1. If we are to target WM without webkit, do we need to do all our validations in Ruby code (server-side)?

2. What JQM features (besides the data-filter attribute mentioned above) can be "safely used" to have a better UI  experience in other platforms, whilst at the same time not affecting the functionality of the WM-built app?
Re: [rhomobile] Re: Where to define function in rhomobile..? Jon Tara 10/11/12 8:17 AM

You should check the jQuery Mobile website and support forum.