Search in sources :

Example 26 with ScriptMethod

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;
}
Also used : FormManager(com.servoy.j2db.FormManager) FlattenedSolution(com.servoy.j2db.FlattenedSolution) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 27 with ScriptMethod

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;
}
Also used : FlattenedSolution(com.servoy.j2db.FlattenedSolution) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 28 with ScriptMethod

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);
    }
}
Also used : RepositoryException(com.servoy.j2db.persistence.RepositoryException) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) ScriptNameValidator(com.servoy.j2db.persistence.ScriptNameValidator) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 29 with ScriptMethod

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());
    }
}
Also used : JSFunction(org.mozilla.javascript.annotations.JSFunction) Function(org.mozilla.javascript.Function) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod)

Example 30 with ScriptMethod

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());
    }
}
Also used : JSFunction(org.mozilla.javascript.annotations.JSFunction) Function(org.mozilla.javascript.Function) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod)

Aggregations

ScriptMethod (com.servoy.j2db.persistence.ScriptMethod)55 JSFunction (org.mozilla.javascript.annotations.JSFunction)31 Function (org.mozilla.javascript.Function)27 FlattenedSolution (com.servoy.j2db.FlattenedSolution)14 Solution (com.servoy.j2db.persistence.Solution)14 RepositoryException (com.servoy.j2db.persistence.RepositoryException)12 Form (com.servoy.j2db.persistence.Form)11 TableNode (com.servoy.j2db.persistence.TableNode)9 ServoyException (com.servoy.j2db.util.ServoyException)8 ArrayList (java.util.ArrayList)7 GlobalScope (com.servoy.j2db.scripting.GlobalScope)6 Scriptable (org.mozilla.javascript.Scriptable)5 IMobileSMForm (com.servoy.base.solutionmodel.mobile.IMobileSMForm)4 ISMForm (com.servoy.j2db.solutionmodel.ISMForm)4 ServoyClientSupport (com.servoy.base.scripting.annotations.ServoyClientSupport)3 ApplicationException (com.servoy.j2db.ApplicationException)3 FlattenedForm (com.servoy.j2db.persistence.FlattenedForm)3 IPersist (com.servoy.j2db.persistence.IPersist)3 ISupportChilds (com.servoy.j2db.persistence.ISupportChilds)3 FormScope (com.servoy.j2db.scripting.FormScope)3