All Downloads are FREE. Search and download functionalities are using the official Maven repository.

static.rules.js Maven / Gradle / Ivy

There is a newer version: 5.6.9
Show newest version
var RULES = (function ($)
{
    var group = '';
    var ruleList = $('#ruleList');
    var selectCategories = $('#selectCategories');
    var selectEngine = $('#selectEngine');
    var selectGroup = $('#selectGroup');
    var selectRules = $('#selectRules');
    var categoryForm = $('#categoryForm');
    var engine = '';
    var info = {};

    function getRules()
    {
        var body = {engine: engine, group: group};
        if (!group)
        {
            return;
        }
        callServer('GET', 'ui/rules', body, buildRules);
    }

    function getCategories()
    {
        var div, category, values;
        var body = {_engine: engine};
        var divs = categoryForm.children('div');
        divs.each(function( index ) {
            div = divs[index];
            category = $(this).find('label').text();
            values = $(this).find('select').val();
            if (0 < values.length)
            {
                body[category] = values;
            }
        });
        callServer('POST', 'ui/rulesByCategory', body, buildRules);
    }

    var buildRules = function buildRules(data)
    {
        var i, len, ruleType, rule, ul, ruleTypeAndName, li;
        var ruleTypes = Object.keys(data);
        for (i = 0, len = ruleTypes.length; i < len; i++)
        {
            ruleType = ruleTypes[i];
            rule = data[ruleType];
            ruleTypeAndName = ruleNameTemplate(ruleType, rule['className'])
            ul = buildObject(rule['objects']);
            li = $('
  • '); li.append(ruleTypeAndName); li.append(ul); ruleList.append(li); ruleList.append('
    ') } $('a').click(function () { getNCubeHtml(this.text, this.getAttribute('data-appId')) }); }; function buildObject(rules) // return ul with object and methods { var i, len, name, title, object, methods, li; var ul = $('
      '); var objects = Object.keys(rules); for (i = 0, len = objects.length; i < len; i++) { name = objects[i]; title = ruleTitleTemplate(objects[i]); object = rules[name]; methods = buildMethods(object); li = $('
    • '); li.append(title); li.append(methods); ul.append(li); } return ul; } function buildMethods(object) // return ul with li of method names { var i, len, rule, li; var ul = $('
        '); var rules = object['rules']; for (i = 0, len = rules.length; i < len; i++) { rule = rules[i]; li = $('
      • '); li.append(methodTemplate(rule)); ul.append(li); } return ul; } function ruleNameTemplate(ruleType, className) { return `${ruleType} (${className})`; } function ruleTitleTemplate(name) { return `${name}` } function methodTemplate(rule) { let ruleHtml = '' if (rule['name']) { ruleHtml += `${rule['name']}: ` } if (rule['condition']) { if (rule['condition'] === "true") { ruleHtml += `${rule['condition']}` } else if (rule['condition'] === "false") { ruleHtml += `${rule['condition']}` } else { ruleHtml += `Condition${rule['condition']}` } } if (rule['noContent']) { ruleHtml += `` ruleHtml += '' return ruleHtml } if (rule['documentation']) { ruleHtml += `${rule['documentation']}` } if (rule['code']) { ruleHtml += `Code${rule['code']}` } if (rule['methodName']) { ruleHtml += `Method${rule['methodName']}` } if (rule['ncubes']) { var i, len, ncube, ref; let ncubes = rule['ncubes']; if (ncubes.length > 0) { let appId = rule['appId']; var list = ' ['; for (i = 0, len = ncubes.length; i < len; i++) { ncube = ncubes[i]; ref = `${ncubes[i]}`; list += ref; if (i < len -1) { list += ', ' } } list += ']' ruleHtml += list } } ruleHtml += '' return ruleHtml } function resetRules() { ruleList.empty(); } function getNCubeHtml(ncube, appIdString) { var callback = function(data) { var w = window.open('', ncube + appIdString); w.document.write(data.html); }; var body = {name: ncube, appIdString: appIdString}; callServer('GET', 'ui/ncube', body, callback); } function loadPage() { resetRules(); setListeners(); getInfo(); } function getInfo() { callServer('GET', 'ui/rulesInfo', null, buildPage) } var buildPage = function buildPage(data) { var i, len, listEngine; var engines = Object.keys(data); info = data; engine = engines[0]; for (i = 0, len = engines.length; i < len; i++) { listEngine = engines[i]; selectEngine.append($('