App-Dochazka-WWW

 view release on metacpan or  search on metacpan

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

            ajax(rest, sc, fc);
        },

        populateSupervisorNick = function (populateArray) {
            var cu = currentUser('obj'),
                eid = cu.supervisor,
                nick,
                rest, sc, fc, populateContinue;
            console.log("Entering populateSupervisorNick(), supervisor EID is", eid);
            populateContinue = populate.shift(populateArray);
            // we assume the supervisor EID is in the current user object
            // which was populated when we logged in or started masquerade
            rest = {
                "method": 'GET',
                "path": 'employee/eid/' + eid + "/minimal"
            };
            sc = function (st) {
                nick = st.payload.nick,
                $('#ePsuperNick').html(nick);
                populateContinue(populateArray);
            },
            fc = function (st) {
                coreLib.displayError(st.payload.message);
                $('#ePsuperNick').html('(ERR)');
                populateContinue(populateArray);
            };
            if (eid) {
                ajax(rest, sc, fc);
            } else {
                populateContinue(populateArray);
            }
        },

        populateYear = function (populateArray) {
            var populateContinue;
            console.log("Entering populateYear()");
            $('input[id="iNyear"]').val(dt.currentYear());
            populate.shift(populateArray);
        },

        selectActivityAction = function (obj) {
            if (activityCache.length > 0) {
                stack.push('selectActivity', {
                    'pos': 0,
                    'set': activityCache,
                });
            } else {
                coreLib.displayError("CRITICAL ERROR: activity cache is empty");
            }
        },

        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);
                    console.log("Employee " + nick + ": profile cache updated");
                    profileObj = profileCache[i];
                }
            }
            if (! cached) {
                profileCache.push($.extend({}, profileObj));
                coreLib.displayResult("Employee " + nick + ": profile cache created");
            }
            profileByEID[eid] = $.extend({}, profileObj);
            profileByNick[nick] = $.extend({}, profileObj);
        }
        ;

    return {
        activityCache: activityCache,
        endTheMasquerade: endTheMasquerade,
        getActivityByAID: getActivityByAID,
        getActivityByCode: getActivityByCode,
        getProfileByEID: getProfileByEID,
        getProfileByNick: getProfileByNick,
        getScheduleByScode: getScheduleByScode,
        getScheduleBySID: getScheduleBySID,
        masqEmployee: masqEmployee,
        populateActivityCache: populateActivityCache,
        populateAIDfromCode: populateAIDfromCode,
        populateExistingIntervals: populateExistingIntervals,
        populateFullEmployeeProfileCache: populateFullEmployeeProfileCache,
        populateLastExisting: populateLastExisting,
        populateLastPlusOffset: populateLastPlusOffset,
        populateNextScheduled: populateNextScheduled,
        populateSchedIntvlsForDate: populateSchedIntvlsForDate,
        populateScheduleBySID: populateScheduleBySID,
        populateSIDByDate: populateSIDByDate,
        populateSupervisorNick: populateSupervisorNick,
        populateYear: populateYear,
        profileCacheLength: function () {
            return profileCache.length
        },
        scheduleCacheLength: function () {
            return scheduleCache.length
        },
        selectActivityAction: selectActivityAction,
        setProfileCache: setProfileCache,
    };

});



( run in 1.549 second using v1.01-cache-2.11-cpan-5b529ec07f3 )