nuBeforeClone in nuBuilderPro v3.0?

nuBeforeClone in nuBuilderPro v3.0?

Unread postby jkdev » Mon Sep 01, 2014 6:04 am

I need to modify some fields in a form when Clone button is pressed before a fresh forn is displayed.

Tried the nuBeforeClone() functuon in Javascript Tab for Custom Code.

Nothing happened.

I wonder wherther similar command is available in V3.0
jkdev
 
Posts: 20
Joined: Fri Aug 01, 2014 9:56 pm

Re: nuBeforeClone in nuBuilderPro v3.0?

Unread postby admin » Tue Sep 02, 2014 8:42 am

jkdev,

You can make changes to a cloned record as the newly cloned record loads - before it is saved.

Just by checking if it a record that is cloned. And then doing what you want.

Code: Select all
function nuLoadEdit(){

   console.log('#nu_cloned_record#');

}



You will need the latest update of nuBuilderPro (created today).

Steven
admin
Site Admin
 
Posts: 3406
Joined: Mon Jun 15, 2009 9:53 am
nuBuilder Version: 4.5

Re: nuBeforeClone in nuBuilderPro v3.0?

Unread postby jkdev » Tue Sep 02, 2014 12:00 pm

Thanks a lot Steven.

I am trying to update via the Update button but it does not detect the updated files.

When I press the button first, it returns internal server error. Second time onwards it just lists
Code: Select all
RESULT: SUCCESS

0 File(s) updated
No Column(s) Added
No Column(s) Changed
No SQL errors
No Warnings


The directory has persmissions for www-data which is the user for apache2.

I see the subdirectories being created in ./tmp directory

Code: Select all
-rw-r--r-- 1 www-data root         0 2014-08-09 10:35 file-uploads-go-here
drwxr-xr-x 3 www-data www-data  4096 2014-08-23 15:05 GIT_2014_08_23_15
drwxr-xr-x 3 www-data www-data  4096 2014-09-02 07:53 GIT_2014_09_02_07 <=======
drwxr-xr-x 3 www-data www-data  4096 2014-09-02 08:00 GIT_2014_09_02_08  <=======
jkdev
 
Posts: 20
Joined: Fri Aug 01, 2014 9:56 pm

Re: nuBeforeClone in nuBuilderPro v3.0?

Unread postby jkdev » Wed Sep 03, 2014 4:43 am

Thanks to Steven's suggestion and modification, I managed to get the form variables to change when cloned.

eg:
Code: Select all
function nuLoadEdit(){

  var cloned = '#nu_cloned_record#';

  if (cloned > 0){
    $('#field1').val('NEW');
    $('#field1').change;
    $('#field2').val('TEMP');
  }
}


However I have buttons displayed on the cloned form based on hash values.

When I click on "Clone" I was shown the correct value via Javascript Console.

However the hash varoables (#var_name) them seleves give back original value.

It appears that hash variable replacement happens before coming to nuLoadEdit()
jkdev
 
Posts: 20
Joined: Fri Aug 01, 2014 9:56 pm

Re: nuBeforeClone in nuBuilderPro v3.0?

Unread postby admin » Wed Sep 03, 2014 7:40 am

jkdev,

Are you trying to show the buttons or hide them? (Because you can obviously use javascript to make them hidden).

The other alternative is to set those hash variables before you run the clone button, with nuSetHash();

And create an Extra Actionn Button that replaces the Clone button with code like this..

Code: Select all
nuSetHash('hashvariable', value);
nuCloneForm(this, formid, nuGetHash('record_id')


Steven
admin
Site Admin
 
Posts: 3406
Joined: Mon Jun 15, 2009 9:53 am
nuBuilder Version: 4.5

Re: nuBeforeClone in nuBuilderPro v3.0?

Unread postby jkdev » Wed Sep 03, 2014 9:12 pm

Steven,
I could not still make it work.

Here is what I want to do:

1. When pr_status=POSTED I need to hide the Save button. I set display condition to hide Save button only when pr_status=POSTED via (#pr_status#)
2. pr_status=POSTED should be changed to pr_status=NEW when cloned
3. When pr_status=NEW Save button should be visible.

The problem happens when #pr_status# does not get changed in to NEW when in step 3 and therefore the Save button does not get visible.

I created a new button and added following:
Code: Select all
nuSetHash('pr_status','NEW');
nuCloneForm(this, '#FORM_ID#', nuGetHash('record_id'));


The nuSetHash apears to be changing the pr_status field to NEW (as observed when the record/field is displayed after cloning). So that part seems to be working.

Hower the hash replacement which occurs on cloned record loading still seem to have the value substituted as pr_status=POSTED. Therefore the Save button does not get displayed.

Am I missing something?

jk
jkdev
 
Posts: 20
Joined: Fri Aug 01, 2014 9:56 pm

Re: nuBeforeClone in nuBuilderPro v3.0?

Unread postby massiws » Thu Sep 04, 2014 1:01 pm

My two cent alternative.
To add the "old" nuBuilder v2 nuBeforeClone() function in nuBuilderPro is pretty simple (obviously hacking nuBuilder core):
in nucommon.js edit the nuCloneForm() function (lines 1095-1107) like this:
Code: Select all
function nuCloneForm(pThis, formID, recordID) {
    // Check if nuBeforeClone() is defined by user
    if (typeof nuBeforeClone == 'function' && nuBeforeClone() == false) {
        return;
    }
    var w          = new nuWindow();
    w.form_id      = formID;
    w.title        = $('title').html();
    w.call_type    = 'cloneform';
    w.cloned       = '1';
    w.record_id    = recordID;
    w.tip          = 'Edit';

    window.nuSession.breadCrumb.pop();                                   //-- remove breadcrumb before another is added
    nuBuildForm(w);

}


Now you can implement your custom nuBeforeClone() function in Custom Code -> Javascript tab, like in nuBuilder v2:
Code: Select all
/*
* This function must return TRUE to allow or FALSE to stop cloning.
*/
function nuBeforeClone() {
    // Make your job
    return confirm('Do you want to clone this record?');
}


Hope this helps,
Max.
massiws
 
Posts: 503
Joined: Thu May 24, 2012 9:38 am
Location: Milan, Italy

Re: nuBeforeClone in nuBuilderPro v3.0?

Unread postby admin » Fri Sep 05, 2014 12:50 pm

Guys,

I have added "nuOnClone()" to the latest nuBuilderPro Build.

Steven
admin
Site Admin
 
Posts: 3406
Joined: Mon Jun 15, 2009 9:53 am
nuBuilder Version: 4.5

Re: nuBeforeClone in nuBuilderPro v3.0?

Unread postby jkdev » Sat Sep 06, 2014 9:51 pm

Thanks both for your quick solutions.

I still have issue in getting this to work though.

I even tried two functions nuBeforeClone() and nuAfterClone():

Code: Select all
function nuCloneForm(pThis, formID, recordID){
    // Check if nuBeforeClone() is defined by user and it returns TRUE
    if (typeof nuBeforeClone == 'function' && nuBeforeClone() == false) {
        return;
    }

   var w          = new nuWindow();
   w.form_id      = formID;
   w.title        = $('title').html();
   w.call_type    = 'cloneform';
   w.cloned       = '1';
   w.record_id    = recordID;
   w.tip          = 'Edit';

   window.nuSession.breadCrumb.pop();                                   //-- remove breadcrumb before another is added
   nuBuildForm(w);

    // Check if nuAfterClone() is defined by user and it returns TRUE
    if (typeof nuAfterClone == 'function' && nuAfterClone() == false) {
        return;
    }
   
}


These are the things that I tried:

1. In nuBeforeClone();
Code: Select all
nuSetHash('pr_status','NEW');

Result: No change to either value on the form nor the hash variable #pr_status#

2. In nuBeforeClone();
Code: Select all
$('#pr_status').val('NEW');

Result: form value changed before cloning. But when form was refreshed after cloning the value was reset to what was on the original form

3. In nuAfterClone();
Code: Select all
nuSetHash('pr_status','NEW');

Same result as 1 above

4. nuAfterClone();
Code: Select all
$('#pr_status').val('NEW');

Result: form value got changed to NEW. However has variable #pr_status# remains at the former value.

So my original problem is not solved ie. I cannot get the hash variable #pr_status# to get changed so that I can control the display of Save button on the value of #pr_status# once the record is cloned.

I believe the issue here may be that we do all the changes before and after the object gets created.
Code: Select all
nuBuildForm(w);


If you try to change values in nuBeforeClone(); the object 'w' has not been created by then and no value get set in the new object.
If you try to change values in nuAfterClone(); then the object 'w' has been created and value can be changed but probably the hash_variables have been already changed when the form data was read in and no further change can be done to them.

Can you help me to understand how the nuSetHash works.
Code: Select all
function nuSetHash(name, value){
   nuFORM[name] = value;
}
jkdev
 
Posts: 20
Joined: Fri Aug 01, 2014 9:56 pm

Re: nuBeforeClone in nuBuilderPro v3.0?

Unread postby admin » Tue Sep 09, 2014 7:35 am

jkdev,

Are you saying nuOnClone() wont work?

Steven
admin
Site Admin
 
Posts: 3406
Joined: Mon Jun 15, 2009 9:53 am
nuBuilder Version: 4.5

Next

Return to Custom Code

Who is online

Users browsing this forum: No registered users and 4 guests