Getting method names for standard form events

Is there a way to get or read the currently assigned method names for the standard form events? For example I want to get the onShow method name, or the onLoad method name for a form and then set it to a new method name while using the new solutionModel functionality.

Thanks!

Gary

Great observation – definitely needed. Cross posted for more visibility:

viewtopic.php?f=1&t=11620

We will look at this for the next release of servoy (4.2) we wont have these methods in 4.1
What exactly do you want to do with it? Do you want to get it from an existing form and set it on a new form? (so the existing form is more of a template? )

jcompagner:
We will look at this for the next release of servoy (4.2) we wont have these methods in 4.1
What exactly do you want to do with it? Do you want to get it from an existing form and set it on a new form? (so the existing form is more of a template? )

Yes.

A specific example is element level security. Because it is so fast to recreate a form, it would be easier to control element level security by just duplicating a base form and adding/removing specific elements a user can interact with based on their login credentials than to go through the Servoy element security.

ahh now i hear again that “duplicating a form”

But then you dont want to get the names of a form what you really want to be really quick is:

var duplicate = solutionModel.duplicateForm(“newname”,existingForm);

and you have a complete copy of that form under a new name

thats way faster i think…
(not that you really dont need to be able to get to the names thats a bit different, but this is at least the second time that i hear that they want this because of they want to duplicate)

There’s a lot of things I’d like to do in unit testing with “get” calls in the solutionModel.

If there’s a set, there should be a get, to my mind.

For example, I use a standard set of global methods for all events on all forms. I’d like to write a unit test that inspects my forms and confirms that they have the right events attached to them.

g.

We also need a get for ANY set + Clone or duplicate existing form with the ability to change to a dataset from a foundset and the ability to rename the dataproviders to match the dataset.
Without these we are stuck with over 50 forms with complex queries where the only other solution is to create them as newForms in the Solution Model using metadata which is a step backwards from using a GUI interface in our opinion.

Gary

jcompagner:
ahh now i hear again that “duplicating a form”

But then you dont want to get the names of a form what you really want to be really quick is:

var duplicate = solutionModel.duplicateForm(“newname”,existingForm);

If a duplicate/clone is implemented (which would be great), I would prefer a get/set approach so that we have the “get” result in an object that we can modify before we “set” a new form. So basically it would replace our deconstruct/reconstruct code we’ve put together (we use this approach exclusively over the default “form.extendsForm” approach the demo app uses):

viewtopic.php?f=21&t=11272

I also agree with Greg’s matching get and set request for everything else as well.

Here is some code to make my idea more clear:

function sm_idea()
{
	var f = solutionModel.getForm("products")
		
	// change something
	f.getButton("submit").text = "Click here!" 
	f.name = "new_form"
		
	// would prefer to change a child object property this way:
	f.button.submit.text = "Click here!"
		
	// would like to create an entire form with all objects with one call:
	solutionModel.newForm(f)
	
	// instead of current way of creating a new form, then attaching all objects to the form:
	var f2 = solutionModel.newForm("new_form", "server_name", "table_name", "style_name", true, 400,  200)
	f2.newButton("Click here!", 10, 200, 60, 20, submit)
	// ...continue adding all form objects with all the various properties until you're blue in the face....
}

Managing the SM right now requires a LOT of lines of code.

David
if you just have 1 call to create a form ‘f’

how do you get f? How is that build up?

How do you create a new button without calling really newbutton() method

so before you say:

solutionModel.newForm(f)

How do you want to construct f and how do you want to construct a button on f??

those newXXX methods are constructor calls. And you have or can set there properties that are mandatory.

for example if you wanted things like solutionModel.newForm(f)

then i guess you want something like this??

var f = new JSForm(“new_form”, “server_name”, “table_name”, “style_name”, true, 400, 200);
var b = new JSButton(“btname”,x,y,z);
b.text = “text”;
f.add(b); // or maybe f.btname = b;
and then solutionModel.newForm(f) ???

but how is that smaller then:

var f = solutionModel.newForm(“new_form”, “server_name”, “table_name”, “style_name”, true, 400, 200);
var b = f.newButton(“btname”,x,y,z);
b.text = “text”;

and then i am done… (so it is even shorter the current way)

The property based method could be handy. Problem is that currently they are not scriptables (js objects)
It could be even

f.buttonname.text = “text”

That would work for fields/labels/portals because they should be name unique but a problem could be variables or methods those can have the same name as elements.
so i guess creating another indirection scope like

form.button(.name.property) is also possible and will have less conflicts

but it is not that much more typing by the way with getButton() the extra stuff you type is 2 times a "

another problem if i create for methods/command a property like: onAction or onShowOmittedRecordsCmdMethod
that it is a property and not a set method anymore so i would break the current scripts

And then i guess the type should also really change and be a String or a JSMethod

how does this look?

function alterForm()
{
	// get the form.
	var form = solutionModel.getForm("bug_web");
	// set delete all to none (disable it)
	form.onDeleteAllRecordsCmd = SM_DEFAULTS.COMMAND_NONE;
	// get a defined method
	var method = form.getFormMethod("mymethod");
	application.output(method.code);
	// replace the code.
	method.code = "function mymethod2()\n{\napplication.output('onload!');\n}\n";
	// name should be changed now.
	application.output(method.getName());
	// attach it to the onload
	form.onLoad = method;
	
	var onshowMethod = form.newFormMethod("function mymethod(){application.output('onshow')}");
	form.onShow = onshowMethod;
	
	var globalVariable = solutionModel.getGlobalVariable("bug_status");
	form.newTextField(globalVariable,10,10,80,20);
	
	var globalVariable2 = solutionModel.newGlobalVariable("mynewglobal",SM_VARIABLETYPE.INTEGER);
	globalVariable2.defaultValue = 10;
	form.newTextField(globalVariable2,10,60,80,20);
	
	var globalMethod = solutionModel.newGlobalMethod("function myglobalmethod(){application.output('myglobalmethod')}");
	form.newButton("globalmethod",100,10,80,20,globalMethod);
	
	
	
}
var onshowMethod = form.newFormMethod("function mymethod(){application.output('onshow')}");

Is there a reason this takes a string and not a function literal?

I know I’m being typically obtuse here, but I’m pretty sure that would break that ability to use closures in dynamically created methods because the creating scope would be lost.

Otherwise looks pretty good to me.

greg.

its not really doable for us to create this syntax:

form.onload = function() {xxxxx}

at least that will never work in the solution model interface, it is not really possible because we need in the solution model all solution elements/objects
live function object are not allowed there thats runtime syntax not design time (what solution model is)

So you have to create a JSMethod (what is a solution object) to be able to create methods in the solution model.

Way later on when the solution form object is instantiated to a UI Form object then for the jsmethod a js function object is created.

maybe we find a nicer way to do stuff like that but i guess it must be more tied to the runtime model then to the design time/solution model

I see that, but I was imagining this should be possible…

var onshowMethod = form.newFormMethod( function mymethod() {
    application.output('onshow')
});

No? You can still get your hook in that way. It would by nice if it took either string or function, as the string option would be better for loading a method from the database.

greg.

no thats not possible

because you pass in a Function object which is not a string and we need really the string as code to be able to create our own functions

Just see it this way if you do this:

var onshowMethod = form.newFormMethod( function mymethod() {
application.output(‘onshow’)
});

and then you would store the solution to disk. How would you save that onshowmethod? How would be be persisted?

Well, you could call “toString()” on the function passed, if you wanted to support it just for the syntax benefit – that would, of course, break and closure context of the original function and defeat my original reason for wanting to do that though. :(

greg.

toString is not possible as far as i know, because in a compiled form there is no debug/source anymore on it. So that could maybe only work in the serclipse where we have debug info.

However, we also need a the ones like this:

· var tempActionMethodName = forms.myForm.elements.myButton.getOnActionMethodName(); // return a string with the name of the method attached to the onAction event for the button

· var tempOnShowMethodName = forms.myForm.getOnShowMethodName() // get the name of the method attached to the onShow event for the form

Gary

thats runtime notation that api is not in the planning.

instead it is:

var form = solutionModel.getForm("myForm");
var buttonActionMethod = form.getButton("myButton").onAction;
// to get the name
if (buttonActionMethod != null)
{
   var name = buttonActionMethod.getName()
}

We only need it for the solution model so what you presented would work fine!

Thanks!

Gary