NetTalk Central

Author Topic: refreshing control after a file upload  (Read 6416 times)

robirenz

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
    • Email
refreshing control after a file upload
« on: September 06, 2013, 09:14:46 AM »
Bruce,

Is there anyway to refresh another variable on a form after I upload a file. 
It seems to not want to refresh.. as if the upload script has taken control and then I can't refresh my controls.
If I add a button and click on it, it will refresh my controls normally, but I want to have it do it after I upload my file succesfully...

Best Regards...

Roberto Renz

bshields

  • Sr. Member
  • ****
  • Posts: 392
    • View Profile
    • Inhabit
    • Email
Re: refreshing control after a file upload
« Reply #1 on: September 06, 2013, 05:52:32 PM »
Hi Roberto,

I needed to do some refreshing after file uploads. Mine was a bit complicated, I needed to update not just the current form but also a higher level part form and browse.

I edited Bruces jquery.nt-upload.js to add the ability for a "callback" after each successful upload.

Might be nice for Bruce to add something like this as standard.

Regards
Bill

robirenz

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
    • Email
Re: refreshing control after a file upload
« Reply #2 on: September 07, 2013, 05:21:03 AM »
Bill,

sounds like that's exactly what I need,  care to share what you did to the script?

Best Regards...

Roberto Renz

bshields

  • Sr. Member
  • ****
  • Posts: 392
    • View Profile
    • Inhabit
    • Email
Re: refreshing control after a file upload
« Reply #3 on: September 07, 2013, 08:12:04 PM »
Sure.

Firstly we are modifying one of Bruces internal scripts which mean when you next upgrade it will revert. Its also generally a bad idea, as it will add extra steps and be a pain in the ass going forward. But, on the up side its a great way to get under the hood and understand how NT works internally (and it is very special - its truly very cool code, extremely well abstracted).

So, in conclusion you shouldn't do this...

But I see you are still reading, so lets just call it a training exercise :)

edit: jquery.nt-upload.js

firstly, the key part, finding the correct place for the callback, im on NT7.18 (so your file may vary slightly)

Find the doneone function (line 248). This is called each time a file has completed uploading to the server. So its where we need to get involved.

I added some code like this at line # 260


if(this.options.refreshName)
  setTimeout(sv('',this.options.refreshName,'','',this.options.refreshPar,this.options.refreshSil),1000); /* added by BS to support refresh */
}


All this code does is wait 1 second after the upload to call sv, and reload the requested page/ajax.

refreshName, refreshPar, and refreshSil are extensions I made to Bruces wrapper, I added them

To define those paramaters add:

      refreshName: '',            /* added by BS to support refresh */
      refreshPar: '',
      refreshSil: ''

at about line 44 (they should be last in the list of options)

See how elegantly Bruce has wrapped the normal jquery upload system, its pretty.

Don't forget if you are combining files etc, you'll need to regenerate them otherwise, you're newly modified scripts won't make their way to the browser.

Anyway that will work, but you shouldn't do it :)

Best of luck

robirenz

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
    • Email
Re: refreshing control after a file upload
« Reply #4 on: September 08, 2013, 07:18:09 AM »
Thanks Bill, I will try this out monday.. and comment back..

Best Regards...

Roberto Renz

robirenz

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
    • Email
Re: refreshing control after a file upload
« Reply #5 on: September 09, 2013, 07:25:36 AM »
Hi Bill.

Ok I've gotten as far as changint he script file.

added this to the approprate function

if(this.options.refreshName)
  setTimeout(sv('',this.options.refreshName,'','',this.options.refreshPar,this.options.refreshSil),1000); /* added by BS to support refresh */
}

and added the following parameters to the option widget.

      refreshName: '',            /* added by BS to support refresh */
      refreshPar: '',
      refreshSil: ''

but now what do I do?
do I call the savefile procedure with parĂ¡meters?
add stuff to the loc:options variable?
how do I tell it what controls to refresh on screen?

normaly my controls have these names at least for one of the upload files control and I have like 20 on-screen, so each would be different.

  do Refresh::videoeva1
  do Refresh::videoeva1boton
  do Refresh::evaluacion1
  do Refresh::descargarevaluacion1
  do Refresh::evaluacionsubir
  do Refresh::subirarchivo

Best Regards...

Roberto Renz

bshields

  • Sr. Member
  • ****
  • Posts: 392
    • View Profile
    • Inhabit
    • Email
Re: refreshing control after a file upload
« Reply #6 on: September 09, 2013, 04:09:57 PM »
oops... i left a bit out, you now need to set those options

There will be an embed point called:

Set jQuery File Upload Options

Add this code here:

loc:options = p_web.SetOption(loc:options,'refreshName','contacttable_contacttablefilter')
loc:options = p_web.SetOption(loc:options,'refreshPar','_refresh_=current')
loc:options = p_web.SetOption(loc:options,'refreshSil','_parentProc_=contacttablefilter')


In this example I am refreshing a whole browse screen (including its memory form for filtering) from this memory form which is on the right hand side (which is pretty cool - and show how the ajax stuff is just magic).


Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: refreshing control after a file upload
« Reply #7 on: September 09, 2013, 10:31:53 PM »
short answer: I have added code into the 7.24 build so that the File Upload behaves like other fields (ie you can do the normal server-side "reset fields" or manual embed calls to other procedures and so on.)

longer answer;
I liked your solution Bill, but it was slightly complicated by the fact that the call needed to know the URL. Since the POST already went to that URL it's a little bit simpler just to "process" the response coming back. Since the response is constructed on the server in consistent ways, this means this would just allow it to cope with a "standard response".

Cunningly there is a function for handling responses, called xmlProcess. that said I had to tweak that procedure a little so that it could handle the response already formatted into a string. (in the past xmlProcess would pass-through responses which were just a string.)

When all is said and done, the line added to doneone was
xmlProcess(data.jqXHR.responseText,true);
although I confess it took a bit of experimentation to figure out what the first parameter needed to be.

xmlProcess in netweb.js changed in the first 2 lines to;
function xmlProcess(data,processString){
   if ((typeof(data) == 'string') && (processString != true)) {



This is all in 7.24 - which _may_ (or may not) mean you need to change things on your side. As I said above, the short answer is that the code in Validate::Fieldname routine now behaves like the code in the Validate::Fieldname routine for other fields.

cheers
Bruce

« Last Edit: September 09, 2013, 10:34:15 PM by Bruce »

bshields

  • Sr. Member
  • ****
  • Posts: 392
    • View Profile
    • Inhabit
    • Email
Re: refreshing control after a file upload
« Reply #8 on: September 10, 2013, 01:19:27 AM »
Cool.

Always happy to remove my "impatient" solutions.

I thought I needed to know the URL. But, now with this clue I looked at the page structure to see, something that surprised me. For all my pages and memory forms and hierarchy its all embedded in an all encompassing <form> at the highest level. Wow...

Taking a moment to reflect upon this revelation.....

I see what you are doing now, getting the response from the upload POST and feeding that into the "ajax" system. Hmmm... that is nicer :)

Regards
Bill

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: refreshing control after a file upload
« Reply #9 on: September 10, 2013, 02:30:48 AM »
I'm not sure there's an uber <form> as such, but yes,
procedures (like browses) can be embedded in a form. (but not forms inside forms as HTML doesn't allow a <form> in a <form>.
Also "popup" procedures are all there "on the page" - not in some uber form, but they are there ready to be unhidden.

If you are looking at the logic, and have any questions, then just ask.

cheers
Bruce

bshields

  • Sr. Member
  • ****
  • Posts: 392
    • View Profile
    • Inhabit
    • Email
Re: refreshing control after a file upload
« Reply #10 on: September 10, 2013, 03:42:49 AM »
I think its because with NT i've never had to worry about the action for a form, its all done for me. Obviously when coding web and im not using NT, the action is a big deal. I often embed stuff inside memory forms, and that is where the "uber" form is coming in.

I just didn't think about it, much. Even though when I hand code JS I'm using it, i guess i just didn't understand it.

I really wanted to get to Orlando this year, 2011 was excellent, but this time its fallen on School Holidays and I can't go, which is a terrible shame.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: refreshing control after a file upload
« Reply #11 on: September 10, 2013, 03:48:50 AM »
bummer!

robirenz

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
    • Email
Re: refreshing control after a file upload
« Reply #12 on: September 10, 2013, 05:29:04 AM »
Thanks for fixing this Bruce..
another happy camper...
as for this years Nettalk training in Orlando... I'll be happy to go for you Bill.. <BG>