App-Dochazka-WWW

 view release on metacpan or  search on metacpan

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

                sc = function (st) {
                    console.log("POST employee/nick returned status", st);
                    // what we do now depends on what targets are on the stack
                    // the target on the top of the stack will be "empProfileEdit"
                    // but the one below that can be either "empProfile" or
                    // "simpleEmployeeBrowser"
                    parentTarget = stack.getTarget(-1);
                    console.log("parentTarget", parentTarget);
                    empObj = Object.create(prototypes.empObject);
                    $.extend(empObj, st.payload);
                    if (parentTarget.name === 'empProfile') {
                        console.log("Employee object is", empObj);
                        currentUser('obj', empObj);
                        appCaches.setProfileCache({"emp": empObj});
                        stack.unwindToTarget(
                            'myProfileAction', undefined,
                            {"resultLine": "Employee profile updated"}
                        );
                    } else if (parentTarget.name === 'simpleEmployeeBrowser') {
                        console.log("Parent target is " + parentTarget.name);
                        console.log("current object in dbrowerState set",
                                    coreLib.dbrowserState.set[coreLib.dbrowserState.pos]);
                        $.extend(
                            coreLib.dbrowserState.set[coreLib.dbrowserState.pos],
                            empObj,
                        );
                        stack.pop(undefined, {"resultLine": "Employee profile updated"});
                    } else {
                        console.log("FATAL ERROR: unexpected parent target", parentTarget);
                    }
                },
                fc = function (st) {
                    console.log("AJAX: " + rest["path"] + " failed with", st);
                    coreLib.displayError(st.payload.message);
                };
            ajax(rest, sc, fc);
        },

        empProfileSetSuperDelete = function () {
            stack.push('empProfileSetSuperChoose', { "eid": null, "nick": null });
        },

        empProfileSetSuperChoose = function (superEmp) {
            var cu = currentUser('obj'),
                obj = {
                    "ePsetsuperofEID": cu.eid,
                    "ePsetsupertoEID": superEmp.eid,
                    "ePsetsuperof": cu.nick,
                    "ePsetsuperto": superEmp.nick,
                };
            console.log("Entering empSetSupervisor() with superEmp", superEmp);
            console.log("Will set superEmp as the supervisor of " + cu.nick);
            console.log("Pushing empProfileSetSuperConfirm onto stack with obj", obj);
            stack.push('empProfileSetSuperConfirm', obj);
        },

        empProfileSetSuperCommit = function (obj) {
            var cu = currentUser('obj'),
                empProfile,
                rest = {
                    "method": 'PUT',
                    "path": 'employee/eid/' + obj.ePsetsuperofEID,
                    "body": {
                        "supervisor": obj.ePsetsupertoEID,
                    }
                },
                sc = function (st) {
                    if (st.code === 'DOCHAZKA_CUD_OK' || st.code === 'DISPATCH_UPDATE_NO_CHANGE_OK' ) {
                        cu.supervisor = obj.ePsetsupertoEID;
                        empProfile = appCaches.getProfileByEID(obj.ePsetsuperofEID);
                        if (empProfile) {
                             empProfile.supervisor = obj.ePsetsupertoEID;
                             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,
            });
        },

        myProfileActionNewOpts,
        myProfileActionPopulate = function (populateArray) {
            var cu = currentUser('obj'),
                obj = {},
                populateContinue = populate.shift(populateArray),
                profileObj = appCaches.getProfileByEID(cu.eid);
            if (profileObj.privhistory) {
                obj['priv'] = profileObj.privhistory.priv;
                obj['privEffective'] = datetime.readableDate(
                    profileObj.privhistory.effective
                );
            } else {
                obj['priv'] = '(none)';
                obj['privEffective'] = '(none)';
            }
            if (profileObj.schedhistory) {
                obj['sid'] = profileObj.schedhistory.sid;
                if (profileObj.schedhistory.scode !== null) {
                    obj['scode'] = profileObj.schedhistory.scode;
                } else {
                    obj['scode'] = '(none)';
                }
                obj['schedEffective'] = datetime.readableDate(
                    profileObj.schedhistory.effective
                );



( run in 2.482 seconds using v1.01-cache-2.11-cpan-5735350b133 )