Search in sources :

Example 16 with ScriptMethod

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

Example 17 with ScriptMethod

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

Example 18 with ScriptMethod

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);
    }
}
Also used : FlattenedSolution(com.servoy.j2db.FlattenedSolution) 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 19 with ScriptMethod

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);
    }
}
Also used : FoundSetManager(com.servoy.j2db.dataprocessing.FoundSetManager) TableNode(com.servoy.j2db.persistence.TableNode) FlattenedSolution(com.servoy.j2db.FlattenedSolution) 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 20 with ScriptMethod

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

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