App-MFILE-WWW

 view release on metacpan or  search on metacpan

share/js/core/lib.js  view on Meta::CPAN

            name: 'emptyLine',
            aclProfileRead: 'passerby',
            aclProfileWrite: null,
            text: "&nbsp",
            prop: null,
            maxlen: 20
        },

        clearResult: clearResult,

        // dbrowser states
        // FIXME: move this into stack.js
        dbrowserState: dbrowserState,

        // display error message
        displayError: function (buf, id) {
            console.log("ERROR: " + buf);
            $('#result').css('text-align', 'center');
            $("#result").html(buf);
            $('input[name="sel"]').val('');
            if (id) {
                $('input[name="' + id + '"]').focus();
            } else {
                $('input[name="entry0"]').focus();
            }
        },

        displayResult: function (buf) {
            console.log("RESULT", buf);
            if (! buf) {
                clearResult();
                return;
            }
            $('#result').css('text-align', 'center');
            $('#result').html(buf);
        },

        // drowselect state
        // FIXME: move this into stack.js
        drowselectState: drowselectState,

        focusedItem: function () {
            return {
                "id": $(document.activeElement).attr('id'),
                "name": $(document.activeElement).attr('name'),
            };
        },

        // convert null to empty array
        forceArray: function (arr) {
            return (arr === null) ? [] : arr;
        },

        // generate string "n objects" based on array length
        genObjStr: function (len) {
            return (len === 1) ?
                '1 object' :
                len + " objects";
        },

        // give object a "haircut" by throwing out all properties
        // that do not appear in proplist
        hairCut: function (obj, proplist) {
            for (var prop in obj) {
                if (obj.hasOwnProperty(prop)) {
                    if (proplist.indexOf(prop) !== -1) {
                        continue;
                    }
                    delete obj[prop];
                }
            }
            return obj;
        },

        // Crockford, Douglas; "JavaScript: The Good Parts"; page 61
        isArray: function (value) {
            return value &&
                typeof value === 'object' &&
                typeof value.length === 'number' &&
                typeof value.splice === 'function' &&
                !(value.propertyIsEnumerable('length'));
        },

        isInteger: function (value) {
            var pival = parseInt(value, 10),
                cond1 = pival == value,
                cond2 = typeof pival === 'number',
                cond3 = isFinite(pival),
                res = cond1 && cond2 && cond3;
            //console.log("isInteger() called with", value);
            //console.log("parseInt says", pival);
            //console.log("typeof says", typeof pival === 'number');
            //console.log("isFinite says", isFinite(pival));
            //console.log("isInteger says", res);
            return res;
        },

        isObjEmpty: function (obj) {
            if (Object.getOwnPropertyNames(obj).length > 0) return false;
            return true;
        },

        isStringNotEmpty: isStringNotEmpty,

        // log events to browser JavaScript console
        logKeyDown: function (evt) {
            // console.log("WHICH: " + evt.which + ", KEYCODE: " + evt.keyCode);
        },

        // return null if val contains parenthesis
        // used when scraping forms for values, to make sure we don't process
        // values like "(none)" which are created by us
        nullify: function (val) {
            console.log("Entering nullify() with value", val);
            if (isStringNotEmpty(val)) {
                if (val.indexOf('(') !== -1) {
                    return null;
                }
                return val;
            }
            return null;



( run in 1.254 second using v1.01-cache-2.11-cpan-39bf76dae61 )