App-Dochazka-WWW

 view release on metacpan or  search on metacpan

share/js/dochazka-www/int-lib.js  view on Meta::CPAN


        genIntvl = function (date, timerange) {
            var ctr = dt.canonicalizeTimeRange(timerange),
                m;
            if (ctr === null) {
                m = 'Time range ->' + timerange + '<- is invalid';
                console.log(m);
                stack.restart(undefined, {
                    "resultLine": m
                });
            } else {
                return '[ "' +
                       date +
                       ' ' +
                       ctr[0] +
                       '", "' +
                       date +
                       ' ' +
                       ctr[1] +
                       '" )';
            }
        },

        updateSingleIntSave = function (obj) {
            var caller = stack.getTarget().name,
                cu = currentUser('obj'),
                rest,
                sc = function (st) {
                    // FIXME: update the interval inside the drowselect state
                    // var pos = coreLib.drowselectState.pos,
                    //     set = coreLib.drowselectState.set.slice();
                    // set[pos] = st.payload;
                    stack.unwindToTarget('viewIntervalsAction');
                };
            console.log("Entering updateSingleIntSave() from caller " + caller + " with obj", obj);
            if (caller === 'updateSingleInt') {
                // obj is scraped by start.js from the form inputs and will look
                // like this:
                // {
                //     iNdate: "foo bar in a box",
                //     iNtimerange: "25:00-27:00",
                //     code: "LOITERING",
                //     iid: 148
                //     long_desc: "none",
                // }
                // any of the above properties may be present or missing
                // also, there may or may not be an acTaid property with the AID of
                // the chosen activity
            } else {
                console.log("CRITICAL ERROR: unexpected caller", caller);
                return null;
            }
            if (! createIntervalCheckMandatoryProps(obj)) {
                return null;
            }
            obj["intvl"] = genIntvl(obj.iNdate, obj.iNtimerange);
            if (! obj.intvl) {
                return null;
            }
            rest = {
                "method": 'PUT',
                "path": 'interval/iid/' + obj.iid,
                "body": {
                    "eid": cu.eid,
                    "aid": obj.acTaid,
                    "intvl": obj.intvl,
                    "long_desc": obj.long_desc,
                },
            }
            ajax(rest, sc);
        },

        vetDayList = function (dl, testing) {
            var buf, daylist,
                month = $('input[id="iNmonth"]').val(),
                year = $('input[id="iNyear"]').val(),
                tokens = String(dl).trim().replace(/\s/g, '').split(',');
            console.log("Entering vetDayList() with tokens", tokens, month);
            if (! coreLib.isInteger(year)) {
                year = dt.currentYear();
                $('input[id="iNyear"]').val(year);
            }
            if (! month) {
                month = dt.currentMonth();
                $('input[id="iNmonth"]').val(month);
            }
            if (! coreLib.isArray(tokens) || (tokens.length === 1 && tokens[0] === "")) {
                tokens = ["1-" + dt.daysInMonth(year, month)];
            }
            daylist = dt.vetDayList(tokens);
            if (daylist.length > 0) {
                // populate hidden entries with begin and end of date range
                $('#iNdaterangeBegin').html(year + "-" + dt.monthToInt(month) + "-" + daylist[0]);
                $('#iNdaterangeEnd').html(year + "-" + dt.monthToInt(month) + "-" + daylist[daylist.length - 1]);
                buf = daylist.join(',');
                $('input[id=iNdaylist]').val(buf);
                return buf;
            } else {
                return null;
            }
        },

        vetDayRange = function (dl, testing) {
            var buf, dayrange,
                month = $('input[id="iNmonth"]').val(),
                year = $('input[id="iNyear"]').val(),
                rangeBegin, rangeEnd,
                tokens = String(dl).trim().replace(/\s/g, '').split(','),
                t;
            console.log("Entering vetDayRange() with tokens", tokens, month);
            if (! coreLib.isInteger(year)) {
                year = dt.currentYear();
                $('input[id="iNyear"]').val(year);
            }
            if (! month) {
                month = dt.currentMonth();
                $('input[id="iNmonth"]').val(month);
            }
            if (! coreLib.isArray(tokens) || (tokens.length === 1 && tokens[0] === "")) {
                tokens = ["1-" + dt.daysInMonth(year, month)];
            }



( run in 0.734 second using v1.01-cache-2.11-cpan-5735350b133 )