Open jlu344 opened 8 years ago
var app = angular.module("pricingApp", ["ngRoute", "ui.bootstrap", "ngMessages", "ngAnimate"]);
//app.provider( // "$exceptionHandler","$rootScope",function () // { // $get: function (errorLogService) { // return (errorLogService); // } // } // );
app.config([ "$routeProvider", "$locationProvider", "rootDirectory", function ($routeProvider, $locationProvider, rootDirectory) {
// Specify the three simple routes ('/', '/About', and '/Contact')
$routeProvider.when("/FAHomePage", {
templateUrl: rootDirectory + "/HomePage/FAHomePage"
});
$routeProvider.when("/CAHomePage", {
templateUrl: rootDirectory + "/HomePage/CAHomePage"
});
$routeProvider.when("/ApproverHomePage", {
templateUrl: rootDirectory + "/HomePage/ApproverHomePage"
});
$routeProvider.when("/HelpDeskHomePage", {
templateUrl: rootDirectory + "/HomePage/HelpDeskHomePage"
});
$routeProvider.when("/AdminReports", {
templateUrl: rootDirectory + "/Reports/AdminReports"
});
$routeProvider.when("/TierConfig", {
templateUrl: rootDirectory + "/Admin/TierConfig"
});
$routeProvider.when("/ManageCompetitor", {
templateUrl: rootDirectory + "/Admin/ManageCompetitorList"
});
$routeProvider.when("/ManageUsers", {
templateUrl: rootDirectory + "/Admin/ManageUsers"
});
$routeProvider.when("/ManageExceptions", {
templateUrl: rootDirectory + "/Admin/ManageAccountExceptions"
});
$routeProvider.when("/PricingAndAccounts", {
templateUrl: rootDirectory + "/Admin/PricingAndAccounts"
});
$routeProvider.when("/Request", {
templateUrl: rootDirectory + "/Request/RequestFlow"
});
$routeProvider.when("/MarginRequest", {
templateUrl: rootDirectory + "/MarginRequest/RequestFlow"
});
$routeProvider.when("/Approver", {
templateUrl: rootDirectory + "/Approver/ApproverFlow"
});
// Specify HTML5 mode (using the History APIs) or HashBang syntax.
$locationProvider.html5Mode(false).hashPrefix("!");
}
]);
app.config([ '$provide', function ($provide) { $provide.decorator('$locale', [ '$delegate', function ($delegate) { if ($delegate.id == 'en-us') { $delegate.NUMBER_FORMATS.PATTERNS[1].negPre = '(\u00A4'; $delegate.NUMBER_FORMATS.PATTERNS[1].negSuf = ')'; } return $delegate; } ]); } ]);
app.filter("handleblanktext", [ "$filter", function ($filter) { return function (input, filter) { if (input == '' || input == null || input == 'null, null' || input == ', ') { return '--' } return input; }
}
]);
app.filter("to_trusted", [ "$sce", function ($sce) { return function (text) { return $sce.trustAsHtml(text); }; } ]);
app.filter("startFrom", function () { return function (input, start) { if (input) { start = +start; return input.slice(start); } return []; }; });
// Setup for disabling Ajax caching for Internet Explorer app.config([ "$routeProvider", "$httpProvider", function ($routeProvider, $httpProvider) { $httpProvider.defaults.cache = false; if (!$httpProvider.defaults.headers.get) { $httpProvider.defaults.headers.get = {}; } $httpProvider.interceptors.push("LoadingInterceptor");
$httpProvider.defaults.headers.common["X-Requested-With"] = "XMLHttpRequest";
// disable IE ajax request caching
$httpProvider.defaults.headers.get["Cache-Control"] = "no-cache";
$httpProvider.defaults.headers.get["Pragma"] = "no-cache";
//.....here proceed with your routes
}
]);
app.filter("trustedhtml", [ "$sce", function ($sce) { return function (text) { return $sce.trustAsHtml(text); }; } ]);
app.filter("picker", [ "$interpolate", function ($interpolate) { return function (item, name) { if (angular.isUndefined(arguments[1])) return arguments[0]; var result = $interpolate("{{value | " + arguments[1] + "}}"); return result({ value: arguments[0] }); }; } ]);
app.filter("datetime", [ "$filter", function ($filter) {
return function (jsonDate, type) {
var format = "medium";
if (!angular.isUndefined(type)) format = type;
if (angular.isUndefined(jsonDate) || jsonDate == null || jsonDate == "") return "";
if (isNaN(Date.parse(jsonDate)))
return $filter("date")(new Date(parseInt(jsonDate.substr(6))), format);
return $filter("date")(Date.parse(jsonDate), format);
};
}
]);
app.filter("percentage", [ "$filter", function ($filter) { return function (input, decimals) { if (angular.isUndefined(input)) return $filter("number")(0, decimals) + "%"; return $filter("number")(input, decimals) + "%"; }; } ]);
app.filter("nullablecurrency", [ "$filter", function ($filter) { return function (input, decimals) { if (angular.isUndefined(input) || input === 0) return "$-"; if (angular.isUndefined(input)) return $filter("currency")(0, decimals); return $filter("currency")(input, decimals); }; } ]);
app.service("LoadingInterceptor", [ "$q", "$rootScope", "$log", function ($q, $rootScope, $log) { "use strict";
var xhrCreations = 0;
var xhrResolutions = 0;
function isLoading() {
return xhrResolutions < xhrCreations;
}
function updateStatus() {
$rootScope.loading = isLoading();
}
return {
request: function (config) {
xhrCreations++;
updateStatus();
return config;
},
requestError: function (rejection) {
xhrResolutions++;
updateStatus();
$log.error("Request error:", rejection);
return $q.reject(rejection);
},
response: function (response) {
xhrResolutions++;
updateStatus();
return response;
},
responseError: function (rejection) {
xhrResolutions++;
updateStatus();
$log.error("Response error:", rejection);
return $q.reject(rejection);
}
};
}
]);
//app.factory('stacktraceService', // function () { // // "printStackTrace" is a global object. // return ({ // print: printStackTrace // }); // });
//app.factory( // "errorLogService", // function ($log, $window, stacktraceService, rootDirectory) { // // I log the given error to the remote server. // function log(exception, cause) { // // Pass off the error to the default error handler // // on the AngualrJS logger. This will output the // // error to the console (and let the application // // keep running normally for the user). // $log.error.apply($log, arguments); // // Now, we need to try and log the error the server. // // -- // // NOTE: In production, I have some debouncing // // logic here to prevent the same client from // // logging the same error over and over again! All // // that would do is add noise to the log. // try { // var errorMessage = exception.toString(); // var stackTrace = stacktraceService.print({ e: exception }); // // Log the JavaScript error to the server. // // -- // // NOTE: In this demo, the POST URL doesn't // // exists and will simply return a 404. // $.ajax({ // type: "POST", // url: rootDirectory + "/SITMaintenance/LogError", // contentType: "application/json", // data: angular.toJson({ // errorUrl: $window.location.href, // errorMessage: errorMessage, // stackTrace: stackTrace, // cause: (cause || "") // }) // }); // } catch (loggingError) { // // For Developers - log the log-failure. // $log.warn("Error logging failed"); // $log.log(loggingError); // } // } // // Return the logging function. // return (log); // } // );
app.directive("customTable1", [ "rootDirectory", function (rootDirectory) {
return {
restrict: "E",
scope: {
grid: "=data",
pagination: "=pagination",
pageLimit: "=?pageLimit",
pageSizeArray: "=?pageSizeArray",
showPageSizeArray: "=?showPageSize",
select: "&",
click: "&",
actions: "=actions",
selected: "=selected"
},
templateUrl: rootDirectory + "/Scripts/app/template/custom-table.html",
link: function ($scope, $elem, $attr) {
if (angular.isUndefined($scope.showPageSizeArray))
$scope.showPageSizeArray = false;
if (angular.isUndefined($scope.pageSizeArray))
$scope.pageSizeArray = [5, 10, 20, 30];
$scope.$watch("grid", function (value) {
if (typeof value != "undefined") {
// pagination controls
if (angular.isUndefined($scope.pageLimit)) {
if ($scope.pagination)
$scope.pageLimit = 10; //Default items per page
else {
$scope.pageLimit = 100; //Default items per page
}
}
$scope.grid.currentPage = 1;
$scope.grid.entryLimit = $scope.pageLimit; //Items per page
$scope.totalItems = angular.isUndefined(value.data) ? 0 : value.data.length;
$scope.noOfPages = Math.ceil($scope.totalItems / $scope.grid.entryLimit);
if (angular.isUndefined(value.sort))
$scope.grid.sort = { column: "", descending: false };
else if (angular.isUndefined(value.sort.column))
$scope.grid.column = "";
else if (angular.isUndefined(value.sort.descending))
$scope.grid.descending = false;
if (angular.isUndefined($scope.grid.directive))
$scope.grid.directive = [];
}
});
},
controller: [
"$scope", "$filter", function ($scope, $filter) {
$scope.sort = function (index, issort) {
if (issort === false) return;
$scope.grid.sort.descending = !$scope.grid.sort.descending;
$scope.grid.sort.column = $scope.grid.databind[index];
};
$scope.isDirective = function (id) {
return (!angular.isUndefined($scope.grid.directive[id]));
};
$scope.isCustomBinding = function (id) {
if (angular.isUndefined($scope.grid.customBinding)) {
return false;
} else if (!angular.isUndefined($scope.grid.customBinding[id])) {
return true;
}
};
$scope.replaceValue = function (html, value, index) {
html = html.replace(/_VALUE_/g, value);
html = html.replace(/_INDEX_/g, index);
return html;
}
$scope.dropdown = { selected: false };
$scope.actionselected = function (fn, index) {
index = index + ($scope.grid.entryLimit * ($scope.grid.currentPage - 1));
$scope.dropdown.selected = false;
var sortedGrid = $filter('orderBy')($scope.grid.data, $scope.grid.sort.column, $scope.grid.sort.descending);
if (angular.isFunction($scope.selected)) $scope.selected(angular.copy(sortedGrid[index]));
if (angular.isFunction(fn)) fn();
}
if (!angular.isUndefined($scope.actions)) {
$scope.noAssignGrid = $scope.actions.filter(function (value) {
return (value.l.toLowerCase().indexOf("assign") < 0);
});
}
}
]
};
}
]);
app.directive("customTable", [ "rootDirectory", function (rootDirectory) {
return {
restrict: "E",
scope: {
grid: "=data",
pagination: "=pagination",
pageLimit: "=?pageLimit",
pageSizeArray: "=?pageSizeArray",
showPageSizeArray: "=?showPageSize",
select: "&",
click: "&",
actions: "=actions",
selected: "=selected"
},
templateUrl: rootDirectory + "/Scripts/app/template/custom-table.html",
link: function ($scope, $elem, $attr) {
if (angular.isUndefined($scope.showPageSizeArray))
$scope.showPageSizeArray = false;
if (angular.isUndefined($scope.pageSizeArray))
$scope.pageSizeArray = [5, 10, 20, 30];
$scope.$watch("grid", function (value) {
if (typeof value != "undefined") {
// pagination controls
if (angular.isUndefined($scope.pageLimit)) {
if ($scope.pagination)
$scope.pageLimit = 10; //Default items per page
else {
$scope.pageLimit = 100; //Default items per page
}
}
$scope.grid.currentPage = 1;
$scope.grid.entryLimit = $scope.pageLimit; //Items per page
$scope.totalItems = angular.isUndefined(value.data) ? 0 : value.data.length;
$scope.noOfPages = Math.ceil($scope.totalItems / $scope.grid.entryLimit);
if (angular.isUndefined(value.sort))
$scope.grid.sort = { column: "", descending: false };
else if (angular.isUndefined(value.sort.column))
$scope.grid.column = "";
else if (angular.isUndefined(value.sort.descending))
$scope.grid.descending = false;
if (angular.isUndefined($scope.grid.directive))
$scope.grid.directive = [];
}
});
},
controller: [
"$scope", "$filter", function ($scope, $filter) {
$scope.sort = function (index, issort) {
if (issort === false) return;
$scope.grid.sort.descending = !$scope.grid.sort.descending;
$scope.grid.sort.column = $scope.grid.databind[index];
};
$scope.isDirective = function (id) {
return (!angular.isUndefined($scope.grid.directive[id]));
};
$scope.isCustomBinding = function (id) {
if (angular.isUndefined($scope.grid.customBinding)) {
return false;
} else if (!angular.isUndefined($scope.grid.customBinding[id])) {
return true;
}
};
$scope.replaceValue = function (html, value, index) {
html = html.replace(/_VALUE_/g, value);
html = html.replace(/_INDEX_/g, index);
return html;
}
$scope.dropdown = { selected: false };
$scope.actionselected = function (fn, index) {
index = index + ($scope.grid.entryLimit * ($scope.grid.currentPage - 1));
$scope.dropdown.selected = false;
var sortedGrid = $filter('orderBy')($scope.grid.data, $scope.grid.sort.column, $scope.grid.sort.descending);
if (angular.isFunction($scope.selected)) $scope.selected(angular.copy(sortedGrid[index]));
if (angular.isFunction(fn)) fn();
}
if (!angular.isUndefined($scope.actions)) {
$scope.noAssignGrid = $scope.actions.filter(function (value) {
return (value.l.toLowerCase().indexOf("assign") < 0);
});
}
}
]
};
}
]); app.directive("bindHtmlCompile", [ "$compile", function ($compile) { return { restrict: "A", link: function (scope, element, attrs) { scope.$watch(function () { return scope.$eval(attrs.bindHtmlCompile); }, function (value) { element.html(value); $compile(element.contents())(scope); }); } }; } ]);
app.directive('back', ['$window', function ($window) { return { restrict: 'A', link: function (scope, elem, attrs) { elem.bind('click', function () { $window.history.back(); }); } }; }]);
app.directive("alphanumeric", function () { return { require: "ngModel", link: function (scope, element, attr, ngModelCtrl) { function fromUser(text) { var transformedInput = text.replace(/[^0-9a-zA-Z\s]/g, ""); if (transformedInput !== text) { ngModelCtrl.$setViewValue(transformedInput); ngModelCtrl.$render(); } return transformedInput; // or return Number(transformedInput) }
ngModelCtrl.$parsers.push(fromUser);
}
};
});
app.directive("numeric", function () { return { require: "ngModel", link: function (scope, element, attr, ngModelCtrl) { function fromUser(text) { var transformedInput = text.replace(/[^0-9]/g, ""); if (transformedInput !== text) { ngModelCtrl.$setViewValue(transformedInput); ngModelCtrl.$render(); } return transformedInput; // or return Number(transformedInput) }
ngModelCtrl.$parsers.push(fromUser);
}
};
});
app.directive("capitalize", function () { return { require: "ngModel", link: function (scope, element, attrs, modelCtrl) { var capitalize = function (inputValue) { if (inputValue == undefined) inputValue = ""; var capitalized = inputValue.toUpperCase(); if (capitalized !== inputValue) { modelCtrl.$setViewValue(capitalized); modelCtrl.$render(); } return capitalized; } modelCtrl.$parsers.push(capitalize); capitalize(scope[attrs.ngModel]); // capitalize initial value } }; });
app.directive("approverIcon", [ "rootDirectory", function (rootDirectory) {
return {
restrict: "E",
scope: {
data: "=data"
},
templateUrl: rootDirectory + "/Scripts/app/template/approver-icon.html",
controller: [
"$scope", function ($scope) {
$scope.approverIcon = {
active: "approver-active",
alert: "approver-alert",
inactive: "approver-inactive",
check: "approver-check",
reject: "approver-reject"
}
$scope.icons = [];
$scope.approvers = [];
$scope.market = [];
$scope.assignIcon = function (status, name, market) {
switch (status) {
case "1": //Active Approver
{
$scope.icons.push("alert");
break;
}
case "2": //Rejected Approver
{
$scope.icons.push("reject");
break;
}
case "4": //Approved
{
$scope.icons.push("check");
break;
}
case "5": //Inactive Approver
{
$scope.icons.push("inactive");
break;
}
default: //Invalid
{
$scope.icons.push("inactive");
break;
}
}
$scope.approvers.push(name);
$scope.market.push(market);
}
}
],
link: function ($scope, $elem, $attr) {
$scope.$watch("data", function (value) {
if (angular.isUndefined(value)) return;
if (angular.isObject(value)) {
if (value.Step1ApproverName && value.Step1ApproverName.length > 0)
$scope.assignIcon(value.Step1StatusID, value.Step1ApproverName, value.Step1ApproverDistrictName);
if (value.Step2ApproverName && value.Step2ApproverName.length > 0)
$scope.assignIcon(value.Step2StatusID, value.Step2ApproverName, value.Step2ApproverDistrictName);
if (value.Step3ApproverName && value.Step3ApproverName.length > 0)
$scope.assignIcon(value.Step3StatusID, value.Step3ApproverName, value.Step3ApproverDistrictName);
}
});
}
};
}
]);
app.directive("approverWaitingFor", [ "rootDirectory", function (rootDirectory) {
return {
restrict: "E",
scope: {
data: "=data"
},
controller: [
"$scope", function ($scope) {
$scope.waitingForName = "";
$scope.waitingFor = function (status, name) {
if (name.length > 0) {
switch (status) {
case "1": //Active Approver
{
$scope.waitingForName = name;
break;
}
}
}
}
}
],
link: function ($scope, $elem, $attr) {
$scope.$watch("data", function (value) {
if (typeof value != "undefined") {
$scope.waitingFor(value.Step1StatusID, value.Step1ApproverName);
$scope.waitingFor(value.Step2StatusID, value.Step2ApproverName);
$scope.waitingFor(value.Step3StatusID, value.Step3ApproverName);
$elem.html($scope.waitingForName);
}
});
}
};
}
]);
app.directive("currencyText", [ "$filter", "$locale", function ($filter, $locale) { return { require: "ngModel", scope: { min: "=?min", max: "=?max", currencySymbol: "@", ngRequired: "=?ngRequired", fraction: "=?decimal" }, link: function (scope, element, attrs, ngModel) {
if (attrs.ngCurrency === "false") return;
scope.fraction = (typeof scope.fraction !== "undefined") ? scope.fraction : 2;
function decimalRex(dChar) {
return RegExp("\\d|\\-|\\" + dChar, "g");
}
function clearRex(dChar) {
return RegExp("\\-{0,1}((\\" + dChar + ")|([0-9]{1,}\\" + dChar + "?))&?[0-9]{0," + scope.fraction + "}", "g");
}
function clearValue(value) {
value = String(value);
var dSeparator = $locale.NUMBER_FORMATS.DECIMAL_SEP;
var cleared = null;
if (value.indexOf($locale.NUMBER_FORMATS.DECIMAL_SEP) == -1 &&
value.indexOf(".") != -1 &&
scope.fraction) {
dSeparator = ".";
}
// Replace negative pattern to minus sign (-)
var neg_dummy = $filter("currency")("-1", getCurrencySymbol(), scope.fraction);
var neg_regexp = RegExp("[0-9." + $locale.NUMBER_FORMATS.DECIMAL_SEP + $locale.NUMBER_FORMATS.GROUP_SEP + "]+");
var neg_dummy_txt = neg_dummy.replace(neg_regexp.exec(neg_dummy), "");
var value_dummy_txt = value.replace(neg_regexp.exec(value), "");
// If is negative
if (neg_dummy_txt == value_dummy_txt) {
value = "-" + neg_regexp.exec(value);
}
if (RegExp("^-[\\s]*$", "g").test(value)) {
value = "-0";
}
if (decimalRex(dSeparator).test(value)) {
cleared = value.match(decimalRex(dSeparator))
.join("").match(clearRex(dSeparator));
cleared = cleared ? cleared[0].replace(dSeparator, ".") : null;
}
return cleared;
}
function getCurrencySymbol() {
if (angular.isDefined(scope.currencySymbol)) {
return scope.currencySymbol;
} else {
return $locale.NUMBER_FORMATS.CURRENCY_SYM;
}
}
function reformatViewValue() {
var formatters = ngModel.$formatters,
idx = formatters.length;
var viewValue = ngModel.$$rawModelValue;
while (idx--) {
viewValue = formatters[idx](viewValue);
}
ngModel.$setViewValue(viewValue);
ngModel.$render();
}
ngModel.$parsers.push(function (viewValue) {
var cVal = clearValue(viewValue);
//return parseFloat(cVal);
// Check for fast digitation (-. or .)
if (cVal == "." || cVal == "-.") {
cVal = ".0";
}
return parseFloat(cVal);
});
element.on("blur", function () {
ngModel.$commitViewValue();
reformatViewValue();
});
ngModel.$formatters.unshift(function (value) {
return $filter("currency")(value, getCurrencySymbol(), scope.fraction);
});
ngModel.$validators.min = function (cVal) {
if (!scope.ngRequired && (isNaN(cVal) || cVal === "")) {
return true;
}
if (typeof scope.min !== "undefined") {
return cVal >= parseFloat(scope.min);
}
return true;
};
scope.$watch("min", function (val) {
ngModel.$validate();
});
ngModel.$validators.max = function (cVal) {
if (!scope.ngRequired && (isNaN(cVal) || cVal === "")) {
return true;
}
if (typeof scope.max !== "undefined") {
return cVal <= parseFloat(scope.max);
}
return true;
};
scope.$watch("max", function (val) {
ngModel.$validate();
});
ngModel.$validators.fraction = function (cVal) {
if (!!cVal && isNaN(cVal)) {
return false;
}
return true;
};
scope.$on("currencyRedraw", function () {
ngModel.$commitViewValue();
reformatViewValue();
});
element.on("focus", function () {
var viewValue = ngModel.$$rawModelValue;
if (isNaN(viewValue) || viewValue === "" || viewValue == null) {
viewValue = "";
} else {
viewValue = parseFloat(viewValue).toFixed(scope.fraction);
}
ngModel.$setViewValue(viewValue);
ngModel.$render();
});
}
}
}
]);
app.directive("percentageText", [ "$filter", "$locale", function ($filter, $locale) { return { require: "ngModel", scope: { min: "=?min", max: "=?max", ngRequired: "=?ngRequired", fraction: "=?decimal" }, link: function (scope, element, attrs, ngModel) {
if (attrs.ngCurrency === "false") return;
scope.fraction = (typeof scope.fraction !== "undefined") ? scope.fraction : 2;
function decimalRex(dChar) {
return RegExp("\\d|\\-|\\" + dChar, "g");
}
function clearRex(dChar) {
return RegExp("\\-{0,1}((\\" + dChar + ")|([0-9]{1,}\\" + dChar + "?))&?[0-9]{0," + scope.fraction + "}", "g");
}
function clearValue(value) {
value = String(value);
var dSeparator = $locale.NUMBER_FORMATS.DECIMAL_SEP;
var cleared = null;
if (value.indexOf($locale.NUMBER_FORMATS.DECIMAL_SEP) == -1 &&
value.indexOf(".") != -1 &&
scope.fraction) {
dSeparator = ".";
}
// Replace negative pattern to minus sign (-)
var neg_dummy = $filter("percentage")("-1", scope.fraction);
var neg_regexp = RegExp("[0-9." + $locale.NUMBER_FORMATS.DECIMAL_SEP + "]+");
var neg_dummy_txt = neg_dummy.replace(neg_regexp.exec(neg_dummy), "");
var value_dummy_txt = value.replace(neg_regexp.exec(value), "");
// If is negative
if (neg_dummy_txt == value_dummy_txt) {
value = "-" + neg_regexp.exec(value);
}
if (RegExp("^-[\\s]*$", "g").test(value)) {
value = "-0";
}
if (decimalRex(dSeparator).test(value)) {
cleared = value.match(decimalRex(dSeparator))
.join("").match(clearRex(dSeparator));
cleared = cleared ? cleared[0].replace(dSeparator, ".") : null;
}
return cleared;
}
function reformatViewValue() {
var formatters = ngModel.$formatters,
idx = formatters.length;
var viewValue = ngModel.$$rawModelValue;
while (idx--) {
viewValue = formatters[idx](viewValue);
}
ngModel.$setViewValue(viewValue);
ngModel.$render();
}
ngModel.$parsers.push(function (viewValue) {
var cVal = clearValue(viewValue);
//return parseFloat(cVal);
// Check for fast digitation (-. or .)
if (cVal == "." || cVal == "-.") {
cVal = ".0";
}
return parseFloat(cVal);
});
element.on("blur", function () {
ngModel.$commitViewValue();
reformatViewValue();
});
ngModel.$formatters.unshift(function (value) {
return $filter("percentage")(value, scope.fraction);
});
ngModel.$validators.min = function (cVal) {
if (!scope.ngRequired && (isNaN(cVal) || cVal === "")) {
return true;
}
if (typeof scope.min !== "undefined") {
return cVal >= parseFloat(scope.min);
}
return true;
};
scope.$watch("min", function (val) {
ngModel.$validate();
});
ngModel.$validators.max = function (cVal) {
if (!scope.ngRequired && (isNaN(cVal) || cVal === "")) {
return true;
}
if (typeof scope.max !== "undefined") {
return cVal <= parseFloat(scope.max);
}
return true;
};
scope.$watch("max", function (val) {
ngModel.$validate();
});
ngModel.$validators.fraction = function (cVal) {
if (!!cVal && isNaN(cVal)) {
return false;
}
return true;
};
scope.$on("currencyRedraw", function () {
ngModel.$commitViewValue();
reformatViewValue();
});
element.on("focus", function () {
var viewValue = ngModel.$$rawModelValue;
if (isNaN(viewValue) || viewValue === "" || viewValue == null) {
viewValue = "";
} else {
viewValue = parseFloat(viewValue).toFixed(scope.fraction);
}
ngModel.$setViewValue(viewValue);
ngModel.$render();
});
}
}
}
]);
app.controller("UserContextController", [ "$rootScope", "$scope", "dataFactoryUser", "$location", "UserType", function ($rootScope, $scope, dataFactoryUser, $location, UserType) {
$rootScope.location = $location;
$rootScope.systemId = 1;
$scope.UserType = UserType;
$rootScope.indirectDisplayUserPopup = false;
$scope.InitialValues = {};
var noMVCController = function () {
var splitValue = window.location.pathname.split("/");
var sUrlLength = splitValue.length;
if (sUrlLength >= 3) {
var controllerName = splitValue[2];
if (controllerName.length === 0)
return true;
}
return (sUrlLength < 3);
};
$scope.UserSelectedInDropDown = function () {
if ($scope.selectedUser.length > 0 && $scope.selectedUser.indexOf("|") > -1) {
var arSelectedUser = $scope.selectedUser.split("|");
var mlId = arSelectedUser[0];
var isPool = arSelectedUser[1].toLowerCase() === "true";
if (isPool) {
dataFactoryUser.GetUsersToEmulate($scope.UserContext.MlId, mlId, 7).then(function (response) {
$scope.PointOfContactFAEmulateUsers = response.data;
$scope.selectedPointOfContactFA = "0";
$scope.showPointOfContactFA = true;
}, function () {
$scope.PointOfContactFAEmulateUsers = "";
});
} else {
$scope.showPointOfContactFA = false;
$scope.PointOfContactFAEmulateUsers = "";
}
} else {
$scope.showPointOfContactFA = false;
$scope.PointOfContactFAEmulateUsers = "";
}
};
$scope.emulateUser = function (userMlid, callback) {
if (!angular.isUndefined($rootScope.PleaseSave) && $rootScope.PleaseSave) {
var u = angular.isUndefined(userMlid) ? $scope.selectedUser : userMlid;
var cbFn = function () {
$scope.emulateUser(u, callback);
}
$rootScope.tempEmulate = {
callback: cbFn,
EmulateInBetween: true
};
$rootScope.$broadcast("RequestFlowBackToHomePopup");
} else {
$rootScope.tempEmulate = undefined;
var userToEmulate = "";
var poolId = "";
if (!angular.isUndefined(userMlid) && userMlid !== "") {
$scope.selectedUser = userMlid;
}
if ($scope.selectedUser.length === 0) return;
if ($scope.selectedUser.indexOf("|") > -1) {
var arSelectedUser = $scope.selectedUser.split("|");
var mlId = arSelectedUser[0];
var isPool = arSelectedUser[1].toLowerCase() === "true";
if (isPool && arSelectedUser.length == 3) { // For external calls PoolID|isPool|MLID
$scope.selectedPointOfContactFA = arSelectedUser[2];
}
if (isPool) {
userToEmulate = $scope.selectedPointOfContactFA;
poolId = mlId;
} else {
userToEmulate = mlId;
poolId = "";
}
} else
userToEmulate = $scope.selectedUser;
$scope.changeUser = false;
if (userToEmulate.length > 0)
dataFactoryUser.EmulateUser(userToEmulate, poolId).then(function (response) {
$scope.UserContext = response.data;
$scope.LoginUserContext = $scope.UserContext.EmulatedUserContext ? $scope.UserContext.EmulatedUserContext : $scope.UserContext;
$rootScope.request = {}; // Root data
$scope.displayUserPopup = false;
if (!angular.isUndefined(callback) && angular.isFunction(callback)) {
callback();
} else {
$scope.$broadcast("UserContextLoaded");
}
});
}
};
$scope.EmulateUsers = [];
$scope.selectedUser = "0";
$scope.selectedPointOfContactFA = "0";
$scope.GetUsersToEmulate = function (search) {
var searchCode = 5;
if ($scope.UserContext.Identity === UserType.HelpDesk)
searchCode = $scope.UserContext.SblTitleCode;
$scope.showPointOfContactFA = false;
if (!angular.isUndefined(search))
$scope.searchText = search;
dataFactoryUser.GetUsersToEmulate($scope.UserContext.MlId, $scope.searchText, searchCode).then(function (response) {
$scope.EmulateUsers = response.data;
$scope.selectedUser = "0";
if ($scope.UserContext.Identity === UserType.CA && (angular.isUndefined(search) && (angular.isUndefined($scope.searchText) || $scope.searchText === "")))
$scope.$broadcast("LoadCAHomePage");
}, function () {
$scope.EmulateUsers = "";
});
}
$scope.getUserContext = function (reset) {
if (!angular.isUndefined($rootScope.PleaseSave) && $rootScope.PleaseSave && reset) {
var cbFn = function () {
$scope.getUserContext(reset);
}
$rootScope.tempEmulate = {
callback: cbFn,
EmulateInBetween: true
};
$rootScope.$broadcast("RequestFlowBackToHomePopup");
} else {
$rootScope.tempEmulate = undefined;
if (reset) $scope.searchText = "";
var urlParams = $location.absUrl();
var noRedirect = (urlParams.toLowerCase().indexOf("noredirect") > -1);
dataFactoryUser.GetLoginUserContext(reset, noRedirect)
.success(function (response) {
if (!angular.isUndefined(response.url)) {
window.location = response.url;
} else {
$scope.UserContext = response;
$scope.LoginUserContext = $scope.UserContext.EmulatedUserContext ? $scope.UserContext.EmulatedUserContext : $scope.UserContext;
$rootScope.request = {}; // Root data
$scope.displayUserPopup = false;
dataFactoryUser.GetInitialValues().success(function (response) {
if (response != '') {
var tmp = $scope.InitialValues.LMTPost = response;
$scope.emulateUser($scope.InitialValues.LMTPost.FAMLID, null);
}
$scope.$broadcast("UserContextLoaded");
}).error(function (error) {
alert("AN ERROR OCCURRED WHILE LOADING InitialValues: " + error);
});
}
})
.error(function (error) {
alert("AN ERROR OCCURRED WHILE LOADING LoginUserContext: " + error);
});
}
};
$scope.toggleUserPopup = function () {
$scope.displayUserPopup = !$scope.displayUserPopup;
};
$scope.toggleChangeUser = function () {
$scope.changeUser = !$scope.changeUser;
};
$scope.cancelUser = function () {
$scope.changeUser = !$scope.changeUser;
$scope.displayUserPopup = false;
if (UserContext.Identity !== UserType.CA) {
$scope.EmulateUsers = "";
$scope.searchText = "";
}
};
var moveToPage = function (titlecode, usertype) {
switch (usertype) {
case UserType.CA:
$scope.GetUsersToEmulate();
$location.path("CAHomePage");
break;
case UserType.Approver:
case UserType.Admin:
$location.path("ApproverHomePage");
break;
case UserType.FA:
$location.path("FAHomePage");
break;
case UserType.HelpDesk:
$location.path("HelpDeskHomePage");
break;
default:
$location.path("ErrorPage");
break;
}
};
var redirectUserBasedOnRole = function () {
var uc = $scope.UserContext;
if (uc.EmulatedUserContext) {
moveToPage(uc.EmulatedUserContext.SblTitleCode, uc.EmulatedUserContext.Identity);
} else {
moveToPage(uc.SblTitleCode, uc.Identity);
}
};
var redirectHome = function () {
angular.forEach($rootScope.$$listeners, function (value, key) {
if (key.indexOf("$") == -1) {
$rootScope.$$listeners[key] = [];
}
});
$rootScope.approverCalcs = {};
redirectUserBasedOnRole();
};
$scope.$on("UserContextLoaded", redirectHome);
$scope.goToHomePage = redirectHome;
}
]);
app.service('dataFactoryUser', ['$http', 'rootDirectory', function ($http, rootDirectory) {
var urlBase = rootDirectory + '/UserContext/';
var dataFactoryUser = {};
dataFactoryUser.GetUserContext = function (MLID) {
return $http({
url: urlBase + "GetUserContext",
method: "GET",
params: { mlid: MLID }
});
};
dataFactoryUser.GetLoginUserContext = function (reset, noRedirect) {
return $http({
url: urlBase + "GetLoginUserContext",
method: "GET",
params: {
reset: reset,
noRedirect: noRedirect
}
});
}
dataFactoryUser.EmulateUser = function (emulateMlId, poolId) {
return $http({
url: urlBase + "EmulateUser",
method: "GET",
params: { emulateMlId: emulateMlId, poolId: poolId }
});
};
dataFactoryUser.GetUsersToEmulate = function (MlId, searchText, SblTitleCode) {
return $http({
url: urlBase + "GetUsersToEmulate",
method: "POST",
data: {
MlId: MlId,
searchText: searchText,
sblTitleCode: SblTitleCode
}
});
}
dataFactoryUser.GetInitialValues = function () {
return $http({
url: urlBase + "GetInitialValues",
method: "GET"
});
}
return dataFactoryUser;
}]);
echo "# angular" >> README.md git init git add README.md git commit -m "first commit" git remote add origin git@github.com:jlu344/angular.git git push -u origin master