Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- flowApp.controller('userController',['$scope', 'blockUI', 'adminService', '$window','gettextCatalog', function($scope, blockUI, adminService, $window, gettextCatalog) {
- $scope.selUsrObj = null;
- $scope.mgrSrchTxt=$scope.deptSrchTxt=$scope.locSrchTxt=null;
- $scope.uniqueUsrType = null;
- $scope.disablePermission = false;
- $scope.disableActivate = false;
- $scope.allLoaded = false;
- $scope.depSearchList = [];
- $scope.locSearchList = [];
- $scope.depObjSearchList = [];
- $scope.locObjSearchList = [];
- $scope.search = {data:'', selected_user_type:'2'};
- $scope.userList = [];
- $scope.usrIds = [];
- $scope.listUsers = function(type, page, srchTxt, userType){
- if ($scope.pageType != type || userType!=null) {
- $scope.usrIds = [];
- $scope.userList = [];
- $scope.search.selected_user_type = userType;
- }else{
- $scope.search.selected_user_type='2';
- }
- var data = {};
- if ($scope.menuName=='User Requests' || $scope.menuName=='Creator Requests'){
- data['Requester'] = $scope.menuName.split(' ')[0];
- }else{
- if(userType){
- var data = {Inactive:userType}
- }else {
- var data = type == "Active" ? {Active: 1} : {Inactive: 1}
- }
- }
- $scope.pageType = type;
- $scope.pageNumber = page;
- if(srchTxt) {
- data["Search"] = srchTxt;
- $('#search-admin-data').css('opacity', 1);
- }
- adminService.getModelData('User', page, $scope.PAGE_SIZE, data)
- .success(function (data) {
- $scope.userList = $scope.userList.concat(data["data"]);
- $scope.totalCount = data["total_count"];
- $('.admin-list-container').css('opacity', 1);
- })
- .error(function (xmlr, status, err) {
- Materialize.toast(gettextCatalog.getString('Unable to get users list'), 4000, 'red');
- });
- }
- $scope.listUsers($scope.menuName.split(' ')[0], 1);
- $scope.toggleUsrSelection = function (usrId) {
- var idx = $scope.usrIds.indexOf(usrId);
- // is currently selected
- if (idx > -1) {
- $scope.usrIds.splice(idx, 1);
- }
- // is newly selected
- else {
- $scope.usrIds.push(usrId);
- }
- if($scope.usrIds.length>1){
- $scope.mgrSrchTxt=$scope.getUnique('Manager');
- $scope.deptSrchTxt=$scope.getUnique('Department');
- $scope.locSrchTxt=$scope.getUnique('Location');
- $scope.uniqueUsrType=$scope.getUnique('UserType');
- }
- $scope.disablePermission=$scope.isCrtrLicnseExcds();
- $scope.disableActivate = $scope.isUsrLicnseExcds();
- };
- $scope.fetchUser = function(usrId){
- return _.find($scope.userList, function(usr){return usr.Id === usrId;});
- }
- $scope.updateUser = function(key, val){
- var userList = [];
- for (var ids in $scope.usrIds){
- var param = {};
- param[key] = val;
- param['Id'] = $scope.usrIds[ids];
- userList.push(param);
- }
- var data = {'user_list':JSON.stringify(userList)}
- $scope.batchUserUpdate(data, key+" updated");
- }
- $scope.removeUsers = function(data){
- var usrIds = _.pluck(JSON.parse(data["user_list"]), "Id")
- $scope.userList = _.reject($scope.userList, function(d){ return $.inArray(d.Id, usrIds)!=-1; });
- }
- $scope.batchUserUpdate = function(data, key, updateCount){
- var updateList = data;
- adminService.updateUserList(data)
- .success(function (result){
- if(key == 'User deactivated' || key=='User activated'){
- $scope.removeUsers(data)
- }else{
- $scope.userList = [];
- $scope.listUsers($scope.pageType, $scope.pageNumber, $scope.search.data);
- }
- if (updateCount) {
- $scope.loadUsersCount();
- $scope.updateToWizard(updateList,key);
- }
- $scope.selUsrObj = $scope.fetchUser($scope.usrIds[0]);
- Materialize.toast(gettextCatalog.getString(key+" successfully"), 4000, 'green');
- })
- .error(function(error){
- Materialize.toast(gettextCatalog.getString('Unable to update the users'), 7000, 'red');
- });
- }
- $scope.getDepList = function(searchText){
- var searchLimit = 1000;
- var data = {SearchBy:searchText}
- adminService.getModelData("Department", 1, searchLimit, data)
- .then(function(result){
- $scope.depObjSearchList = result.data["data"];
- $scope.depSearchList = _.map(result.data["data"], function(obj) {
- return obj.Name
- });
- });
- }
- $scope.getLocList = function(searchText){
- var searchLimit = 1000;
- var data = {SearchBy:searchText}
- adminService.getModelData("Location", 1, searchLimit, data)
- .then(function(result){
- $scope.locObjSearchList = result.data["data"];
- $scope.locSearchList = _.map(result.data["data"], function(obj) {
- return obj.Name
- });
- });
- }
- $scope.updateMgr = function (val) {
- $scope.updateUser('Manager', val);
- }
- $scope.updateDep = function (val) {
- var dep = _.find($scope.depObjSearchList, function(dept){return dept.Name === val;});
- $scope.updateUser('Department', dep.Id);
- }
- $scope.updateLoc = function (val) {
- var loc = _.find($scope.locObjSearchList, function(l){return l.Name === val;});
- $scope.updateUser('Location', loc.Id);
- }
- $scope.getUnique = function (key){
- var selectedUsers = [];
- for(var ids in $scope.usrIds){
- var selectedUser=$scope.fetchUser($scope.usrIds[ids]);
- selectedUsers.push(selectedUser);
- }
- var value=_.unique(_.pluck(selectedUsers, key));
- return value.length==1?value[0]:null;
- }
- $scope.actDeactUser = function(menuName){
- var userList = [];
- if (menuName == 'Inactive Users'){
- if ($scope.isUsrLicnseExcds()==true){
- Materialize.toast(gettextCatalog.getString('License exceeded'), 4000, 'red');
- return;
- }
- }
- /*license check validated so proceeds activation
- * No need to check license when deactivate users
- * */
- for (var ids in $scope.usrIds){
- var param = {};
- param['Id'] = $scope.usrIds[ids];
- param['RequestUser'] = menuName=='Active Users'?'Reject':'Approved';
- param['RequestCreator'] = 'Reject';
- param['mail_args']={
- 'Request':key=menuName=='Active Users'?'User deactivated':'User activated'
- }
- userList.push(param);
- }
- var data = {'user_list':JSON.stringify(userList)}
- $scope.batchUserUpdate(data, key=menuName=='Active Users'?'User deactivated':'User activated', true);
- $scope.usrIds = [];
- }
- $scope.accessRequest = function(usrId, action, mailArgs){
- /* jQuery(dao).osInvoke('admin.items', "invoke", {actionName: "flow.services.mailService.invoke", caption: 'sendMailNotification',
- data:{'mailType':args['Request'], 'mailid':args['mailid'], 'fullName':args['fullName']}})*/
- if (mailArgs["Request"] == 'UserAccessApproved'){
- if ($scope.company.UserLicenses+$scope.company.CreatorLicenses <= $scope.countDict.User+$scope.countDict.Creator==true){
- Materialize.toast(gettextCatalog.getString('User License exceeded'), 4000, 'red');
- return;
- }
- }
- if (mailArgs["Request"] == 'CreatorAccessApproved'){
- if ($scope.company.CreatorLicenses <= $scope.countDict.Creator==true){
- Materialize.toast(gettextCatalog.getString('Creator License exceeded'), 4000, 'red');
- return;
- }
- }
- var param = action;
- param['Id'] = usrId;
- param['mail_args']=mailArgs
- var data = {'user_list':JSON.stringify([param])}
- $scope.batchUserUpdate(data, key=mailArgs["Request"], true);
- }
- $scope.isUsrLicnseExcds = function(){
- /*
- * returns true if license exceeded with user selection
- * return false if license is not exceeded then can proceed activation
- */
- return $scope.company.UserLicenses+$scope.company.CreatorLicenses < $scope.countDict.User+$scope.usrIds.length+$scope.countDict.Creator;
- }
- $scope.isCrtrLicnseExcds = function(){
- /*
- * returns true if license exceeded with creator selection
- * return false if license is not exceeded then can proceed creator activation
- */
- return $scope.company.CreatorLicenses < $scope.countDict.Creator+$scope.usrIds.length;
- }
- $scope.updatePermission = function(perm){
- var userList = [];
- for (var ids in $scope.usrIds){
- var param = {};
- param['Id'] = $scope.usrIds[ids];
- param['RequestCreator'] = perm!='User'?'Approved':'Reject';
- param['IsAdmin'] = perm=='Admin'?'1':'0';
- userList.push(param);
- }
- var data = {'user_list':JSON.stringify(userList)}
- $scope.batchUserUpdate(data, key="User permission updated", true);
- }
- $scope.importUsers = function(){
- blockUI.start();
- blockUI.message('Importing Users');
- var uploadOptions = {
- "managerValidation": false,
- 'groupImport': false,
- "deptValidation": false,
- "locValidation": false,
- "removeNonExist": false
- };
- var options = {
- url: "/" + _APPLICATION_ID + "/1/admin/import/users",
- "dataType": "json",
- "fileElementId": 'userCSV',
- "data": uploadOptions,
- "success": function (result, status) {
- if (result["success"]) {
- Materialize.toast(gettextCatalog.getString('Users Imported Successfully'), 4000, 'green');
- $scope.loadUsersCount();
- if(result["data"]["Manager"]==true||result["data"]["Department"]||result["data"]["Location"]){
- $scope.triggerValidation(result["data"]);
- }else{
- /*Materialize.toast(result['success'], 4000, 'green');*/
- $scope.showMenu('Inactive Users');
- }
- blockUI.stop();
- }else if (result["error"]) {
- Materialize.toast(result["error"], 4000, "red");
- $scope.$apply(function(){blockUI.stop();});
- }else if(result["Error"]){
- Materialize.toast(result["ErrorMessage"], 4000, "red");
- $scope.$apply(function(){blockUI.stop();});
- }
- },
- "error": function (xmlr, status, e) {
- if(xmlr.responseText.search('success')>-1){
- Materialize.toast(gettextCatalog.getString('Import Completed'), 4000, 'green');
- blockUI.stop();
- }else{
- Materialize.toast(gettextCatalog.getString("The import is failed, please contact support"), 4000, 'red');
- Materialize.toast(xmlr.responseText, 4000, 'red');
- blockUI.stop();
- }
- }
- };
- $.ajaxFileUpload(options);
- }
- $scope.triggerValidation = function(chkValue){
- $('.collapsible').collapsible();
- $('#ImportValidation').show();
- if(chkValue["Department"] == true){
- $('#validate-Department').css('display', 'inline');
- $scope.validateNonExist({"managerValidation": false, "groupImport":false,
- "deptValidation": true, "locValidation": false, "removeNonExist":false }, 'Department');
- }else{
- $('#collapse-Department .progress').hide();
- $('#validate-Department').html('No Errors found in Department');
- }
- if(chkValue["Manager"] == true){
- $('#validate-Manager').css('display', 'inline');
- $scope.validateNonExist({"managerValidation": true, "groupImport":false,
- "deptValidation": false, "locValidation": false, "removeNonExist":false} , 'Manager');
- }else{
- $('#collapse-Manager .progress').hide();
- $('#validate-Manager').html('No Errors found in Manager');
- }
- if(chkValue["Location"] == true){
- $('#validate-Location').css('display', 'inline');
- $scope.validateNonExist({"managerValidation": false, "groupImport":false,
- "deptValidation": false, "locValidation": true, "removeNonExist":false }, 'Location');
- }else{
- $('#collapse-Location .progress').hide();
- $('#validate-Location').html('No Errors found in Location');
- }
- }
- $scope.validateNonExist = function(dataValue, alias){
- adminService.importUsers(dataValue)
- .success(function(result){
- if(result["success"]) {
- $('#validate-'+alias).html(alias+" Errors");
- $('#collapse-'+alias+' .progress').hide();
- $('#validate-'+alias).css("display","block");
- $.each(result['data'], function (index, value) {
- $('#collapse-'+alias).append("<li style='margin-left: 20px;padding:5px'>The "+alias+" '"+ value[alias.toLowerCase()] + "' for '" +
- value['userid'] + "' not exist in system</li>");
- });
- if ($('#collapse-'+alias).children().length == 0){
- $('#validate-'+alias).html(getI18NMsg('No Errors found in', 'Admin')+' '+getI18NMsg(alias, 'Admin'));
- }
- }else if(result["error"]){
- Materialize.toast(gettextCatalog.getString("Validating imported data failed, please contact support"), 4000, 'red');
- }
- })
- .error(function(data){
- Materialize.toast(gettextCatalog.getString('Unable to validate Imported data in KiSSFLOW. Please contact support.'), 4000, 'red');
- });
- }
- $scope.removeNonExist = function(){
- var dataValue = {"managerValidation": false, "groupImport":false, "deptValidation": false, "locValidation": false, "removeNonExist":true}
- adminService.importUsers(dataValue)
- .success(function(result){
- if(result["success"]) {
- Materialize.toast(gettextCatalog.getString('Erorr Data Removed, Redirected to Inactive user\'s list'), 4000, 'green');
- $scope.showMenu('Inactive Users');
- }
- })
- .error(function(data){
- Materialize.toast(gettextCatalog.getString('Unable to validate Imported data in KiSSFLOW. Please contact support.'), 4000, 'red');
- });
- }
- $scope.getNextUsers = function(menuName){
- /*console.info(menuName);*/
- if($('.admin-list-container').scrollTop() + $('.admin-list-container').innerHeight() >= $('.admin-list-container')[0].scrollHeight) {
- var to = $scope.totalCount<$scope.PAGE_SIZE*$scope.pageNumber?$scope.totalCount:$scope.PAGE_SIZE*$scope.pageNumber;
- if (to<$scope.totalCount){
- $scope.pageNumber+=1;
- $scope.listUsers($scope.menuName.split(' ')[0], $scope.pageNumber, $scope.search.data);
- }
- }
- }
- $scope.searchUsers = function(searchTxt){
- $scope.userList = [];
- $scope.usrIds = [];
- if($scope.pageType=='Inactive')
- $scope.search.selected_user_type='1';
- $scope.listUsers($scope.pageType, 1, searchTxt, $scope.search.selected_user_type);
- }
- $scope.showSearchInput =function() {
- $('.searchWrapper .searchInput').toggleClass('selectedtext');
- if($('.searchWrapper i').hasClass('icons8-Delete')){
- $('#search-admin-data').val('');
- $scope.searchUsers();
- }
- $('.searchWrapper i').toggleClass('icons8-Delete');
- $('.searchWrapper i').toggleClass('icons8-Search');
- $('.searchWrapper input').focus();
- }
- $scope.updateToWizard = function(updateList,key) {
- var user_list =JSON.parse(updateList["user_list"]);
- /*Checking to send activation mail or not
- * If needs to send getting activation mail content*/
- var preference = JSON.parse(_COMPANY.Preference || "{}");
- var sendActivationMail = false;
- var activationMailContent = '';
- if('ActivateAccount' in preference){
- adminService.sendMailOnActivation(data)
- .success(function(data) {
- sendActivationMail = true;
- activationMailContent = data;
- })
- .error(function(xmlr, status, err){
- blockUI.stop();
- Materialize.toast(gettextCatalog.getString("Update user is failed, please contact support"), 4000, 'red');
- });
- }
- for(var usr in user_list){
- /*console.info(user_list[usr]);*/
- var usr = user_list[usr];
- var user_type = usr["IsAdmin"] >= 1?4:usr["RequestCreator"] == "Approved"?3:usr["RequestUser"] == "Approved"?2:1
- blockUI.start();
- var data = {'email_id': usr.Id, 'app_id': _APPLICATION_ID,
- 'invited_by': _USER_ID, 'UserType': user_type, 'wiz_host': _WIZ_HOST}
- if(sendActivationMail == true){
- data['ActivationMail'] = true;
- data['activationMailContent'] = activationMailContent;
- }
- adminService.addUserAccount(data)
- .success(function(dataObj){
- if(key=="User activated")
- if(dataObj["textStatus"]==500 && dataObj["errorThrown"]){
- Materialize.toast(gettextCatalog.getString("Something went wrong, please refresh the page and try again, " +
- "if the problem still persist,please conatct support"), 4000, 'red');
- }
- if (dataObj["errorMessage"]){
- var msg = $(dataObj["errorMessage"].replace(/\</g, '<').replace(/\>/g, '>')).text();
- Materialize.toast(msg,6000,'red');
- }else{
- blockUI.stop();
- }
- })
- .error(function(xmlr, status, err){
- blockUI.stop();
- Materialize.toast(gettextCatalog.getString("Update user is failed, please contact support"), 4000, 'red');
- });
- }
- }
- $scope.transferPrivilege = function(val){
- if(val==_USER_ID){
- Materialize.toast(gettextCatalog.getString('You cannot transfer to the same user'), 4000, 'red');
- return;
- }
- $('#transferAdminModal').openModal();
- }
- $scope.doTransfer = function(){
- var val = $('#transfer_privilege').val();
- $('#transferAdminModal').closeModal();
- $scope.saveNewAdminToWizard(val, val);
- }
- $scope.saveNewAdminToWizard = function(user_id, full_name){
- /******************** Updating the UserType in Wizard****************/
- /******************** Sharing the process in Wizard****************/
- blockUI.start();
- var data = {'invited_by':_USER_ID, 'email_id':_USER_ID,'new_admin':user_id,'app_id':_APPLICATION_ID, 'new_admin_name':full_name}
- adminService.transferAccount(data)
- .success(function(dataObj){
- if(dataObj["textStatus"]==500 && dataObj["errorThrown"])
- {
- Materialize.toast(gettextCatalog.getString("Something went wrong, please refresh the page and try again, " +
- "if the problem still persist,please conatct support"), 4000, "red");
- return;
- }
- if (dataObj["errorMessage"])
- {
- Materialize.toast(dataObj["errorMessage"], 4000, "red");
- return;
- }else{
- blockUI.stop();
- $scope.removeUpdateAdmin(user_id);
- Materialize.toast(gettextCatalog.getString('Selected user updated as Admin'), 4000, 'green');
- }
- })
- .error(function(xmlr, status, err){
- blockUI.stop();
- Materialize.toast(gettextCatalog.getString('Unable to change admin privileges in KiSSFLOW. Please contact support.'), 4000, 'red');
- });
- }
- $scope.removeUpdateAdmin = function(newAdmin){
- var userList = [{"Id":newAdmin, "IsAdmin":1, "RequestCreator":"Approved"}];
- var dict = {};
- dict['IsAdmin']=0;
- dict['RequestUser']='Approved';
- dict['RequestCreator']='Reject';
- dict["Id"] = _USER_ID;
- userList.push(dict)
- var data = {'user_list':JSON.stringify(userList)}
- $scope.batchUserUpdate(data, key="New admin added and Current admin privileges removed", true);
- $window.location.reload();
- }
- $scope.resetPassword = function(){
- for (var ids in $scope.usrIds) {
- var data = {"emailId": $scope.usrIds[ids]};
- adminService.resetPassword(data)
- .success(function (data) {
- Materialize.toast(gettextCatalog.getString('Reset password mail sent'), 4000, 'green');
- })
- .error(function (xmlr, status, err) {
- Materialize.toast(gettextCatalog.getString('Unable to send reset password mail'), 4000, 'red');
- });
- }
- }
- }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement