var usr=new function(){this.fblogin=function(){$.ajax({url:"http://www.facebook.com/dialog/oauth?client_id\x3d506636689469976\x26redirect_uri\x3d http%3A%2F%2Fsravan.planeshub.com%2Fsc%2Ffbsignin%2Fsignin \x26scope\x3demail"}).done(function(){log.debug("login with facebook done")})};this.create=function(){comm.post("/sc/usr/register",$("#frmRegister"),null)};this.signup=function(a){console.log("signup");comm.post(a,"/sc/usr/register",$("#frmSignup"),usr.signupSuccess)};this.signupSuccess=function(a){a&&
a.success&&comm.alert("You have successfully Signed-Up. Please check your email. We have emailed you a temporary password. Please use temporary password to Login.","INFO")};this.login=function(a){if("button"==a.target.type||"password"==a.target.id&&13==a.keyCode)$("#frmLogin #password").attr("required","required"),comm.post(a,"/sc/usr/login",$("#frmLogin"),usr.loginSuccess)};this.loginSuccess=function(a){a&&a.success?(session.set("loggedInUser",a.resultData),session.set("fullName",a.resultData.firstName+
" "+a.resultData.lastName),session.remove("navFoot"),session.remove("navTop"),session.remove("navBelow"),session.remove("navBottom"),session.remove("ctx"),window.location.href="/c/u/dash"):logger.showError("ERROR : Authentication Failed. Invalid user credentials. Please try again.")};this.fetchCurrentRoleInOrg=function(a){a?session.set("loggedInUserRoleInOrg",a.resultData):comm.get("/sc/usr/currentroleinorg",null,usr.fetchCurrentRoleInOrg)};this.validatesession=function(){comm.get("/sc/usr/validate",
null,usr.validatesessionResult)};this.validatesessionResult=function(a){log.debug("cmn.usr.validatesessionResult");a.resultData||session.get("loggedInUser")&&usr.logoutSuccess({})};this.logout=function(){comm.get("/sc/usr/logout",null,usr.logoutSuccess)};this.logoutSuccess=function(a){null!=a?(session.remove("loggedInUser"),session.remove("fullName"),session.remove("navFoot"),session.remove("navTop"),session.remove("navBelow"),session.remove("navBottom"),session.remove("ctx"),window.location.href=
"/"):logger.showError("ERROR : Sign-out Failed. Please try again.")};this.list=function(){comm.get("/sc/usr/list",null,usr.listSuccess)};this.listSuccess=function(a){log.debug("usr.listSuccess.0");session.set("users",a.resultData);null!=$("#listOfUsers")&&($("#listOfUsers").html(""),pg.grid($("#listOfUsers"),a.resultData,JSON.parse(a.displayFieldsMetadata),"/sc/usr/list"))};this.changeUserRoles=function(a){log.debug("user.changeUserRoles.0");a=JSON.parse($(a.target.parentElement.parentElement).attr("row_id"));
session.set("editUserRoles",a);document.location="/c/pg-s/sys/user-role.html"};this.listUserRoles=function(){log.debug("user.listUserRoles.0");var a=session.get("editUserRoles"),b=session.get("loggedInUserRoleInOrg");$("#pgHeading").html("Roles of "+a.fullName+' in "'+b.role.org.name+'"');$("#userfirstName").attr("placeholder",a.fullName);$("#userid").val(a.id);usr.populateRoleDeptInForm();comm.post(null,"/sc/crm/org/userorgroles",a,usr.listUserRolesSuccess)};this.populateRoleDeptInForm=function(){comm.get("/sc/crm/org/listorgroles",
null,usr.listRolesOptionSuccess);comm.post(null,"/sc/c/dept/list",null,usr.listDeptSuccess)};this.listRolesOptionSuccess=function(a){var b=$("#role");$(b).html("");$.each(a.resultData,function(a,c){b.append($("\x3coption\x3e\x3c/option\x3e").val(c.id).html(c.name))})};this.listDeptSuccess=function(a){var b=$("#dept");$(b).html("");a.resultData&&$.each(a.resultData,function(a,c){b.append($("\x3coption\x3e\x3c/option\x3e").val(c.id).html(c.name))})};this.listUserRolesSuccess=function(a){log.debug("user.listUserRolesSuccess.0");
$("#listOfUserRoles").html("");pg.grid($("#listOfUserRoles"),a.resultData,JSON.parse('[{"label": "#","name": "userOrgRoleId"},{"label": "Role","name": "role.name"},{"label": "Title","name": "title"},{"label": "Team ?","name": "canHaveTeam"},{"label": "Start Dt","name": "startDt", "type":"date"},{"label": "End Dt","name": "endDt", "type":"date"}]'),"/sc/crm/org/userorgroles",usr.loadUserRoleForUpdate)};this.loadUserRoleForUpdate=function(a){a=JSON.parse($(a.target.parentElement).attr("row_id"));frm.populateFromJson($("#frmUserRoleInOrg"),
a)};this.updateUserRole=function(a){comm.post(a,"/sc/crm/org/updateusrrole",$("#frmUserRoleInOrg"),usr.updateUserRoleSuccess)};this.updateUserRoleSuccess=function(a){comm.alert(a.message,"success");usr.listUserRoles()};this.createCompany=function(a){comm.post(a,"/sc/crm/org/setup",$("#frmNewCompany"),usr.createCompanySuccess)};this.createCompanySuccess=function(a){a&&a.success?usr.listCompany():logger.showError("ERROR : Authentication Failed. Invalid user credentials. Please try again.")};this.currentCompany=
function(a){var b=JSON.parse($(a.target.parentElement.parentElement).attr("rowObj"));session.set("loggedInUserRoleInOrg",b);comm.post(a,"/sc/crm/org/current",b,usr.currentCompanySuccess)};this.currentStore=function(a){console.log("usr.currentStore");var b=JSON.parse($(a.target.parentElement.parentElement).attr("rowObj"));session.set("selectedStore",b);comm.post(a,"/sc/usr/select/store",b,usr.selectStoreSuccess)};this.currentWarehouse=function(a){var b=JSON.parse($(a.target.parentElement.parentElement).attr("rowObj"));
session.set("selectedWarehouse",b);comm.post(a,"/sc/usr/select/warehouse",b,usr.selectStoreSuccess)};this.currentCompanySuccess=function(a){session.remove("navFoot");session.remove("navTop");session.remove("navBelow");session.remove("navBottom");session.remove("ctx");window.location.reload()};this.selectStoreSuccess=function(a){console.log("this.selectStoreSuccess.0");session.remove("navTop");session.remove("navBelow");session.remove("navBottom");window.location.reload()};this.updateCompany=function(a){$("#frmLogin #password").attr("required",
"required");comm.post(a,"/sc/usr/login",$("#frmLogin"),usr.loginSuccess)};this.updateCompanySuccess=function(a){log.debug("usr.updateCompanySuccess.0")};this.listCompany=function(a){comm.get("/sc/crm/org/myorgs",null,usr.listCompanySuccess)};this.listCompanySuccess=function(a){null!=$("#listOfCompanies")&&($("#listOfCompanies").html(""),pg.grid($("#listOfCompanies"),a.resultData,a.metadata,"/sc/crm/org/list"))};this.deleteCompany=function(a){$("#frmLogin #password").attr("required","required");comm.post(a,
"/sc/usr/login",$("#frmLogin"),usr.loginSuccess)};this.deleteCompanySuccess;this.populateMyAccountPage=function(){session&&session.get("loggedInUser")&&(frm.populateFromJson($("#frmPersonalInfo"),session.get("loggedInUser")),frm.populateFromJson($("#frmAddressInfo"),session.get("loggedInUser")))};this.initUserSession=function(){session&&session.get("loggedInUser")&&(usr.listCompany(),nav.update())};this.update=function(a){var b=$(a.target).closest(".form-horizontal").attr("id");"frmSecurityInfo"==
b&&$("#newPassword").val()!=$("#confirmPassword").val()?comm.alert("ERROR : Password and confirmation password are not the same. Please check."):session&&session.get("loggedInUser")?($("\x3cinput /\x3e").attr("type","hidden").attr("name","id").attr("value",session.get("loggedInUser").id).appendTo($(a.target).closest(".form-horizontal")),comm.post(a,"/sc/usr/update?wii\x3d"+b,$(a.target).closest(".form-horizontal"),usr.updateSuccess)):comm.alert("ERROR : It seems your session has expired. Please re-login and try again.")};
this.updateSuccess=function(a){comm.alert("Done. Updated your profile.","success");a&&a.success&&(session.set("loggedInUser",a.resultData),session.set("fullName",a.resultData.firstName+" "+a.resultData.lastName))};this.forgotpwd=function(a){$("#frmLogin #password").removeAttr("required");comm.post(a,"/sc/usr/forgotpwd",$("#frmLogin"))}},tkt=new function(){this.list=function(){cmncontrol.fetch(null,"/sc/crm/tkt/list")};this.create=function(a){comm.post(a,"/sc/crm/tkt/create",$("#frmEdit"),tkt.list)}},
dept=new function(){this.list=function(){log.debug("dept.list");cmncontrol.fetchPost(null,"/sc/c/dept/list",null)};this.create=function(a){comm.post(a,"/sc/c/dept/create",$("#frmEdit"),dept.list)}},prj=new function(){this.list=function(){cmncontrol.fetchPost(null,"/sc/work/prj/list",null)};this.create=function(a){comm.post(a,"/sc/work/prj/create",$("#frmEdit"),prj.list)};this.milestone=function(a){a=JSON.parse($(a.target.parentElement.parentElement).attr("row_id"));session.set("project",a);document.location=
"/c/pgs/work/milestone.html"};this.listms=function(){log.debug("prj.listms");var a=session.get("project");$("#projectId").val(a.id);var b={},d={},c={};c.id=a.id;d.project=c;b.criteria=d;$("#pgheading").html("Milestones of Project "+a.name);cmncontrol.fetchPost(null,"/sc/work/prj/listmilestone",b)};this.createms=function(a){comm.post(a,"/sc/work/prj/createmilestone",$("#frmEdit"),prj.listms)}},facility=new function(){this.list=function(){log.debug("facility.list");cmncontrol.fetchPost(null,"/sc/c/facility/building/list",
null)};this.create=function(a){comm.post(a,"/sc/c/facility/building/create",$("#frmEdit"),facility.list)}},metamodel=new function(){this.list=function(){log.debug("metamodel.list");cmncontrol.fetchPost(null,"/sc/sys/metadata/list",null)};this.create=function(a){log.debug("metamodel.create");comm.post(a,"/sc/sys/metadata/create",$("#frmEdit"),metamodel.list)}};