use of com.servoy.j2db.persistence.ScriptMethod in project servoy-client by Servoy.
the class JSForm method js_setOnNextRecordCmdMethod.
/**
* @deprecated As of release 4.1, replaced by setOnNextRecordCmd(JSMethod).
*/
@Deprecated
public void js_setOnNextRecordCmdMethod(Object functionOrInteger) {
checkModification();
if (functionOrInteger instanceof Function) {
Function function = (Function) functionOrInteger;
ScriptMethod scriptMethod = getScriptMethod(function, application.getFlattenedSolution());
if (scriptMethod != null) {
getForm().setOnNextRecordCmdMethodID(scriptMethod.getID());
} else {
getForm().setOnNextRecordCmdMethodID(0);
}
} else if (functionOrInteger instanceof Number) {
getForm().setOnNextRecordCmdMethodID(((Number) functionOrInteger).intValue());
}
}
use of com.servoy.j2db.persistence.ScriptMethod in project servoy-client by Servoy.
the class JSForm method js_setOnRecordEditStartMethod.
/**
* @deprecated As of release 4.1, replaced by setOnRecordEditStart(JSMethod).
*/
@Deprecated
@ServoyClientSupport(ng = false, wc = true, sc = true)
public void js_setOnRecordEditStartMethod(Object functionOrInteger) {
checkModification();
if (functionOrInteger instanceof Function) {
Function function = (Function) functionOrInteger;
ScriptMethod scriptMethod = getScriptMethod(function, application.getFlattenedSolution());
if (scriptMethod != null) {
getForm().setOnRecordEditStartMethodID(scriptMethod.getID());
} else {
getForm().setOnRecordEditStartMethodID(0);
}
} else if (functionOrInteger instanceof Number) {
getForm().setOnRecordEditStartMethodID(((Number) functionOrInteger).intValue());
}
}
use of com.servoy.j2db.persistence.ScriptMethod in project servoy-client by Servoy.
the class JSSolutionModel method newGlobalMethod.
/**
* Creates a new global method with the specified code in a scope.
*
* @sample
* var method = solutionModel.newGlobalMethod('globals', 'function myglobalmethod(){foundset.newRecord()}')
*
* @param scopeName the scope in which the method is created
* @param code the specified code for the global method
*
* @return a JSMethod object
*/
@JSFunction
public JSMethod newGlobalMethod(String scopeName, String code) {
FlattenedSolution fs = application.getFlattenedSolution();
String name = JSMethod.parseName(code);
try {
String scope = scopeName == null ? ScriptVariable.GLOBAL_SCOPE : scopeName;
ScriptMethod method = fs.getSolutionCopy().createNewGlobalScriptMethod(new ScriptNameValidator(application.getFlattenedSolution()), scope, name);
method.setDeclaration(code);
application.getScriptEngine().getScopesScope().getGlobalScope(scope).put(method, method);
JSMethod jsMethod = new JSMethod(method, application, true);
return jsMethod;
} catch (RepositoryException e) {
throw new RuntimeException(e);
}
}
use of com.servoy.j2db.persistence.ScriptMethod in project servoy-client by Servoy.
the class JSDataSourceNode method newMethod.
/**
* Creates a new foundset method with the specified code.
*
* @sample
* var method = solutionModel.getDataSourceNode("db:/example_data/orders").newMethod("function doubleSize() { return 2*getSize(); }");
*
* application.output('Doubled orders for this customer: '+customers_to_orders.doubleSize())
*
* @param code the specified code for the foundset method
*
* @return a JSMethod object
*/
@JSFunction
public JSMethod newMethod(String code) {
try {
FlattenedSolution fs = application.getFlattenedSolution();
TableNode tablenode = fs.getSolutionCopyTableNode(dataSource);
if (tablenode == null)
throw new RuntimeException("Couldnt create method for datasource: " + dataSource);
String name = JSMethod.parseName(code);
ScriptMethod method = tablenode.createNewFoundsetMethod(new ScriptNameValidator(fs), name, null);
method.setDeclaration(code);
((FoundSetManager) application.getFoundSetManager()).reloadFoundsetMethod(dataSource, method);
return new JSMethod(this, method, application, true);
} catch (RepositoryException e) {
throw new RuntimeException(e);
}
}
use of com.servoy.j2db.persistence.ScriptMethod in project servoy-client by Servoy.
the class JSDataSourceNode method removeMethod.
/**
* Removes the foundset method specified by name.
*
* @sample
* var method1 = solutionModel.getDataSourceNode("db:/example_data/customers").newMethod("function myFoundsetMethod1() { return 123; }");
* var method2 = solutionModel.getDataSourceNode("db:/example_data/customers").newCalculation("function myFoundsetMethod2() { return '20'; }");
*
* var m = solutionModel.getDataSourceNode("db:/example_data/customers").getMethod("myFoundsetMethod1");
* application.output("Name: " + m.getName());
*
* solutionModel.getDataSourceNode("db:/example_data/customers").removeMethod("myFoundsetMethod1");
* m = solutionModel.getDataSourceNode("db:/example_data/customers").getCalculation("myFoundsetMethod1");
* if (m != null) { application.output("myFoundsetMethod1 could not be removed."); }
*
* var allMethods = solutionModel.getDataSourceNode("db:/example_data/customers").getMethod();
* for (var i = 0; i < allMethods; i++)
* {
* application.output(allMethods[i]);
* }
*
* @param name the name of the method to be removed
*
* @return true if the removal was successful, false otherwise
*/
@JSFunction
public boolean removeMethod(String name) {
try {
FlattenedSolution fs = application.getFlattenedSolution();
TableNode tablenode = fs.getSolutionCopyTableNode(dataSource);
ScriptMethod sc = tablenode.getFoundsetMethod(name);
if (sc != null) {
tablenode.removeChild(sc);
return true;
}
// it is a design time method, therefore we "hide" it
sc = fs.getFoundsetMethod(name, dataSource);
if (sc != null) {
fs.addToRemovedPersists(sc);
if (application.getFormManager() instanceof FormManager)
((FormManager) application.getFormManager()).fillScriptMenu();
return true;
}
// not found
return false;
} catch (RepositoryException e) {
throw new RuntimeException(e);
}
}
Aggregations