App-Dochazka-WWW

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

  numbers
- js: tests: implement new test "Masquerading as active, set inactive as supervisor"
- js: empProfile: call reports "Supervisees"
- js: Always load employee profile from server

0.167 2017-11-27 13:21 CET
- js: caches: check more carefully if activityCache populated; refactor masqEmployee
- js: allow inactives to view intervals
- js: hide inaccessible functionality from passerbies
- js: implement vetting of privlevels when adding/modifying status records
- js: viewer: use throw for assert-like conditions
- js: int-lib: use multi-date viewer even when no intervals in range

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


        setProfileCache = function (profileObj) {
            var eid, nick, cacheEID, i, cached = false;
            if ( typeof profileObj !== 'object' ||
                 profileObj === null ||
                 ! 'emp' in profileObj ||
                 ! 'eid' in profileObj.emp
               )
            {
                console.log("CRITICAL ERROR: bad profileObj in setProfileCache()", profileObj);
                throw "bad profile object";
            }
            eid = parseInt(profileObj.emp.eid, 10);
            nick = String(profileObj.emp.nick);
            console.log("setProfileCache() EID, nick", eid, nick);
            console.log(profileCache.length + " objects in profileCache");
            for (i = 0; i < profileCache.length; i += 1) {
                cacheEID = parseInt(profileCache[i].emp.eid, 10);
                if (eid === cacheEID) {
                    cached = true;
                    profileCache[i] = $.extend(profileCache[i], profileObj);

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

        currentEmpHasReports = function () {
            var cu = currentUser('obj'),
                cup = appCaches.getProfileByEID(cu.eid),
                priv = currentUser('priv');
            console.log("Entering currentEmpHasReports(), current employee profile", cup);
            if (priv === 'admin') {
                // not applicable to admins
                return true;
            }
            if (typeof cup !== 'object' || ! 'hasReports' in cup || typeof cup.hasReports !== 'function') {
                throw "Profile of current user has not been loaded into the cache";
            }
            if (typeof cup.hasReports === 'function') {
                return cup.hasReports();
            }
            console.log("CRITICAL ERROR: Bad current user profile object", cup);
            throw "Bad current user profile object";
        },

        empProfileEditSave = function (emp) {
                // protoEmp = Object.create(prototypes.empProfile),
            var empObj,
                parentTarget,
                protoEmp = $.extend(Object.create(prototypes.empObject), emp);
            console.log("Entering empProfileEditSave with object", emp);
            // protoEmp = {
            //     'emp': { 'eid': emp.eid,

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

                             appCaches.setProfileCache(empProfile);
                        }
                        stack.unwindToType('dmenu', {
                            "_start": false
                        });
                        stack.push('myProfileAction', {
                            "resultLine": "Commit OK"
                        });
                    } else {
                        coreLib.displayError("CRITICAL ERROR THIS IS A BUG: " + st.code);
                        throw st.code;
                    }
                };
            console.log("Entered empProfileSetSuperCommit() with obj", obj);
            ajax(rest, sc);
        },

        empProfileSetSuperSearch = function (superEmp) {
            empProfileEmp = superEmp;
            stack.push('searchEmployee', {}, {
                "supervisor": true,

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

                sc = function (st) {
                    if (st.code === 'DISPATCH_SCHEDULED_INTERVALS_IDENTIFIED') {
                        scheduledIntervals = st.payload.success.intervals;
                        for (i = 0; i < scheduledIntervals.length; i += 1) {
                            [date, tr] = dt.tsrangeToDateAndTimeRange(scheduledIntervals[i].intvl);
                            haw[date].scheduled.push(tr);
                        }
                    } else if (st.code === 'DISPATCH_NO_SCHEDULED_INTERVALS_IDENTIFIED') {
                        // do nothing, for the time being
                    } else {
                        throw "unexpected \"interval/scheduled\" status code " + st.code;
                    }
                    $('#dcallback').html(entryPoint(obj));
                };
            ajax(rest, sc);
            return null;
        },

        holidayOrWeekend = function (d) {
            var rv = false;
            // returns true if a given date is a holiday or weekend
            if (haw.hasOwnProperty(d)) {
                if (haw[d].hasOwnProperty('holiday') && haw[d].holiday) {
                    rv = true;
                }
                if (haw[d].hasOwnProperty('weekend') && haw[d].weekend) {
                    rv = true;
                }
            } else {
                throw "haw lookup failed (unexpectedly) for key " + d;
            }
            return rv;
        },

        initializeStore = function (pl) {
            // by "Store" here, I mean "haw" and "sortedDates"
            var date, i;
            haw = $.extend({}, pl);
            sortedDates = Object.keys(haw).sort();
            for (i = 0; i < sortedDates.length; i += 1) {

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

                sc = function (st) {
                    if (st.code === 'DOCHAZKA_HOLIDAYS_AND_WEEKENDS_IN_TSRANGE') {
                        initializeStore(st.payload);
                        for (i = 0; i < obj.intervals.length; i += 1) {
                            aid = obj.intervals[i].aid;
                            [date, tr] = [obj.intervals[i].iNdate, obj.intervals[i].iNtimerange];
                            haw[date].clocked.push({"iNtimerange": tr, "aid": aid});
                        }
                        addScheduledIntervals(obj);
                    } else {
                        throw "unexpected holidays status code " + st.code;
                    }
                };
            ajax(rest, sc);
            return null;
        },

    };
    
});



( run in 0.386 second using v1.01-cache-2.11-cpan-496ff517765 )