Re: [web2py] Javascript return value

2019-02-27 Thread Val K

here is scaffold

view script:

$(function(){
var url  = '{{=URL()}}';
function onvalidate (d) {
if d.company_list {
// do popup here using d.company_list


//finally post user choice (that is stored in the 
`company` variable)
  $.post(url, {'company': company}
 ); 
}
else{
   // login failed - do error-popup 
};

};
function onsubmit(){
   // grab 'user' and 'password' values and 
send it to `url` via ajax, response will be processed by `onvalidate` 
function
   ajax(url, ['user', 'password'], null , 
{success: onvalidate});
return false; // this prevents the page reloading
};
// intercept form submission
$('form').submit(onsubmit);
});


controller.py:

def login():
if request.ajax:
if session.user and request.vars.company:
#validate request.vars.company
if company_is_valid:
session.company = request.vars.company
# do login using session.user
redirect(URL(...), client_side = True)
else:
#user is playing with browser console:)
return None
elif request.vars.user:
user = request.vars.user
password = request.vars.password
# do validatoin
if is_valid:
session.user = user
return response.json(dict(company_list = ...))
else:
#validation fail
return None # or somthing like response.json(dict(error = 
'invalid login'))
else:
return SQLFORM.factory(...).process()










On Wednesday, February 27, 2019 at 8:29:51 PM UTC+3, Ben Duncan wrote:
>
> Ok  a little more detail in  pseudo code:
>
> Display Login page:
> get user name and password.
> If form validates:
>validate username and password
>if username and password validates
>   popup company selection
>   get company 
>   redirect to next page
>else
>   show "username password" error message
>   go back Display Login page: 
> else  # Forms did not pass validation ...
>   go back Display Login page: 
>
> That's the flow I'm used to using in CS software ...
>
> Thanks ...
>
> *Ben Duncan*
> DBA / Chief Software Architect 
> Mississippi State Supreme Court
> Electronic Filing Division
>
>
> On Wed, Feb 27, 2019 at 6:53 AM Ben Duncan  > wrote:
>
>> What I was hoping to do was a javascript popup to to choose a company, 
>> then a redirect.
>> I load the company number and values in a session variables upon 
>> connection.
>>
>> The user id file can have a default company (court) assignment , in which 
>> case there would be no reason to do the popup, but
>> if the user had '0' in the company or was a super admin, it would do the 
>> popup for company (Court)
>>
>> Make sense ?
>>
>> *Ben Duncan*
>> DBA / Chief Software Architect 
>> Mississippi State Supreme Court
>> Electronic Filing Division
>>
>>
>> On Wed, Feb 27, 2019 at 2:51 AM Val K > 
>> wrote:
>>
>>> Hard to understand the workflow, do you want the user to be redirected 
>>> to choose the company after he has logged in? or he should make a choice 
>>> along the login form filling?
>>>
>>> -- 
>>> Resources:
>>> - http://web2py.com
>>> - http://web2py.com/book (Documentation)
>>> - http://github.com/web2py/web2py (Source code)
>>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>>> --- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "web2py-users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to web2py+un...@googlegroups.com .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Javascript return value

2019-02-27 Thread Ben Duncan
Ok  a little more detail in  pseudo code:

Display Login page:
get user name and password.
If form validates:
   validate username and password
   if username and password validates
  popup company selection
  get company
  redirect to next page
   else
  show "username password" error message
  go back Display Login page:
else  # Forms did not pass validation ...
  go back Display Login page:

That's the flow I'm used to using in CS software ...

Thanks ...

*Ben Duncan*
DBA / Chief Software Architect
Mississippi State Supreme Court
Electronic Filing Division


On Wed, Feb 27, 2019 at 6:53 AM Ben Duncan  wrote:

> What I was hoping to do was a javascript popup to to choose a company,
> then a redirect.
> I load the company number and values in a session variables upon
> connection.
>
> The user id file can have a default company (court) assignment , in which
> case there would be no reason to do the popup, but
> if the user had '0' in the company or was a super admin, it would do the
> popup for company (Court)
>
> Make sense ?
>
> *Ben Duncan*
> DBA / Chief Software Architect
> Mississippi State Supreme Court
> Electronic Filing Division
>
>
> On Wed, Feb 27, 2019 at 2:51 AM Val K  wrote:
>
>> Hard to understand the workflow, do you want the user to be redirected to
>> choose the company after he has logged in? or he should make a choice along
>> the login form filling?
>>
>> --
>> Resources:
>> - http://web2py.com
>> - http://web2py.com/book (Documentation)
>> - http://github.com/web2py/web2py (Source code)
>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "web2py-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to web2py+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Javascript return value

2019-02-27 Thread Ben Duncan
What I was hoping to do was a javascript popup to to choose a company, then
a redirect.
I load the company number and values in a session variables upon connection.

The user id file can have a default company (court) assignment , in which
case there would be no reason to do the popup, but
if the user had '0' in the company or was a super admin, it would do the
popup for company (Court)

Make sense ?

*Ben Duncan*
DBA / Chief Software Architect
Mississippi State Supreme Court
Electronic Filing Division


On Wed, Feb 27, 2019 at 2:51 AM Val K  wrote:

> Hard to understand the workflow, do you want the user to be redirected to
> choose the company after he has logged in? or he should make a choice along
> the login form filling?
>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Javascript return value

2019-02-27 Thread Val K
Hard to understand the workflow, do you want the user to be redirected to 
choose the company after he has logged in? or he should make a choice along the 
login form filling?

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Javascript return value

2019-02-26 Thread Ben Duncan
Given I have the following sweet alert js:

--
(async function getCompany () {
  const inputOptions = new Promise((resolve) => {
setTimeout(() => {
  resolve(myargs)
}, 2000)
  })

  const {value: company} = await Swal.fire({
title: 'Select Company',
input: 'radio',
inputOptions: inputOptions,
inputValidator: (value) => {
  return !value && 'You need to choose something!'
}
  })

  if (company) {
Swal.fire({html: 'You selected: ' + company})
  }
  return company
})
()
--

And i have the following code in the view:

{{if CHOOSE_COMPANY == 'Y' : }}
  {{ print "LOGIN view : choose: \n", CHOOSE_COMPANY }}
  {{print "LOGIN view : swalcompany fired \n"}}
  {{print "JSARGS is :\n", js_args}}
  {{=ASSIGNJS(myargs=js_args)}}
  {{=ASSIGNJS(myargs=js_args)}}
  var html_post = "center"
  

{{pass}}

AND in the controller:

if in_form.process(session=None, formname='login').accepted:
print "LOGIN: Accepts...\n"
response.flash = 'form accepted'
FRM_ERR = 'N'
CHOOSE_COMPANY = 'Y'
print "LOGIN: Accepts Trying the return \n"
return dict(form=in_form, FRM_ERR=FRM_ERR, js_args=js_args,
CHOOSE_COMPANY=CHOOSE_COMPANY)
redirect(URL('buttonbar'))
elif in_form.errors :
print "LOGIN: error...\n"
response.flash = 'form has errors'
FRM_ERR = 'Y'
return dict(form=in_form, FRM_ERR=FRM_ERR, js_args=js_args,
CHOOSE_COMPANY=CHOOSE_COMPANY)

I'm trying to accomplish 2 things:

A: get some value backup from the javascript file and
instead of the "return" under the accepted section of controller code, want
to set
a session value and then continue on to the redirect.

How do I go about doing both of theses's ??

As always, Thanks ...
\
*Ben Duncan*
DBA / Chief Software Architect
Mississippi State Supreme Court
Electronic Filing Division

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.