use of com.servoy.j2db.persistence.ScriptMethod in project servoy-client by Servoy.
the class JSSolutionModel method removeGlobalMethod.
/**
* Removes the specified global method.
*
* @sample
* var m1 = solutionModel.newGlobalMethod('globals', 'function myglobalmethod1(){application.output("Global Method 1");}');
* var m2 = solutionModel.newGlobalMethod('globals', 'function myglobalmethod2(){application.output("Global Method 2");}');
*
* var success = solutionModel.removeGlobalMethod('globals', 'myglobalmethod1');
* if (success == false) application.output('!!! myglobalmethod1 could not be removed !!!');
*
* var list = solutionModel.getGlobalMethods('globals');
* for (var i = 0; i < list.length; i++) {
* application.output(list[i].code);
* }
*
* @param scopeName the scope in which the method is declared
* @param name the name of the global method to be removed
* @return true if the removal was successful, false otherwise
*/
@JSFunction
public boolean removeGlobalMethod(String scopeName, String name) {
FlattenedSolution fs = application.getFlattenedSolution();
ScriptMethod sm = fs.getScriptMethod(scopeName, name);
if (sm != null) {
fs.deletePersistCopy(sm, false);
if (application.getFormManager() instanceof FormManager)
((FormManager) application.getFormManager()).fillScriptMenu();
return true;
}
return false;
}
use of com.servoy.j2db.persistence.ScriptMethod in project servoy-client by Servoy.
the class JSSolutionModel method getGlobalMethod.
/**
* Gets an existing global method by the specified name.
*
* @sample
* var method = solutionModel.getGlobalMethod('globals', 'nameOfGlobalMethod');
* if (method != null) application.output(method.code);
*
* @param scopeName the scope in which the method is searched
* @param name the name of the specified global method
*
* @return a JSMethod
*/
@JSFunction
public JSMethod getGlobalMethod(String scopeName, String name) {
FlattenedSolution fs = application.getFlattenedSolution();
ScriptMethod sm = fs.getScriptMethod(scopeName, name);
if (sm != null) {
return new JSMethod(sm, application, false);
}
return null;
}
use of com.servoy.j2db.persistence.ScriptMethod in project servoy-client by Servoy.
the class JSForm method newMethod.
/**
* Creates a new form JSMethod - based on the specified code.
*
* @sample
* var form = solutionModel.newForm('newForm1', myDatasource, null, true, 800, 600);
* var method = form.newMethod('function aMethod(event){application.output("Hello world!");}');
* var button = myListViewForm.newButton('Show message!',50,50,100,30,method);
* forms['newForm1'].controller.show();
*
* @param code the specified code for the new method
*
* @return a new JSMethod object for this form
*/
@JSFunction
public JSMethod newMethod(String code) {
checkModification();
String name = JSMethod.parseName(code);
try {
ScriptMethod method = getForm().createNewScriptMethod(new ScriptNameValidator(application.getFlattenedSolution()), name);
method.setDeclaration(code);
// addMethodToScopes(method);
refreshFromScopes();
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 JSForm method js_setOnDeleteRecordCmdMethod.
/**
* @deprecated As of release 4.1, replaced by setOnDeleteRecordCmd(JSMethod).
*/
@Deprecated
public void js_setOnDeleteRecordCmdMethod(Object functionOrInteger) {
checkModification();
if (functionOrInteger instanceof Function) {
Function function = (Function) functionOrInteger;
ScriptMethod scriptMethod = getScriptMethod(function, application.getFlattenedSolution());
if (scriptMethod != null) {
getForm().setOnDeleteRecordCmdMethodID(scriptMethod.getID());
} else {
getForm().setOnDeleteRecordCmdMethodID(0);
}
} else if (functionOrInteger instanceof Number) {
getForm().setOnDeleteRecordCmdMethodID(((Number) functionOrInteger).intValue());
}
}
use of com.servoy.j2db.persistence.ScriptMethod in project servoy-client by Servoy.
the class JSForm method js_setOnInvertRecordsCmdMethod.
/**
* @deprecated As of release 4.1, replaced by setOnInvertRecordsCmd(JSMethod).
*/
@Deprecated
public void js_setOnInvertRecordsCmdMethod(Object functionOrInteger) {
checkModification();
if (functionOrInteger instanceof Function) {
Function function = (Function) functionOrInteger;
ScriptMethod scriptMethod = getScriptMethod(function, application.getFlattenedSolution());
if (scriptMethod != null) {
getForm().setOnInvertRecordsCmdMethodID(scriptMethod.getID());
} else {
getForm().setOnInvertRecordsCmdMethodID(0);
}
} else if (functionOrInteger instanceof Number) {
getForm().setOnInvertRecordsCmdMethodID(((Number) functionOrInteger).intValue());
}
}
Aggregations