Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- angular.module('myApp')
- .controller('AddUserController',
- function($scope,
- $rootScope,
- $http,
- REST_URL,
- $uibModal,
- $uibModalInstance,
- GoogleAnalytics,
- company,
- user,
- CompanyService,
- $routeParams) {
- 'use strict';
- $scope.company = company;
- $scope.getLocations = getLocations;
- $scope.save = save;
- $scope.close = close;
- $scope.user = user || {};
- $scope.editUser = !!user;
- $scope.selected = {
- location: $scope.editUser ? { id: user.defaultLocationId, name: user.locationName } : null,
- };
- function getLocations() {
- var params = {
- sortName: 'name',
- sortDirection: 'ASC',
- start: 0,
- limit: 100,
- archiving: 'non-archived'
- };
- CompanyService.getLocations(REST_URL, $routeParams.id, params).then(function(result) {
- $scope.locations = result.data;
- });
- }
- function save() {
- var userDetail = {
- user: {
- name: $scope.user.name,
- username: $scope.user.email,
- password: $scope.user.password,
- defaultLocationId: $scope.selected.location.id,
- createdBy: $rootScope.globals.userid,
- modifiedBy: $rootScope.globals.userid,
- },
- company: company,
- sellerCompany: $rootScope.globals.sellerCompany,
- defaultLocation: $scope.selected.location,
- roleList: [{
- role: 'buyer',
- }],
- sendNotification: true,
- };
- if ($scope.editUser) {
- delete userDetail.user.password;
- delete userDetail.user.createdBy;
- delete userDetail.roleList;
- delete userDetail.sendNotification;
- }
- if ($scope.editUser) {
- $http.put(REST_URL + '/users/' + $scope.user.id, userDetail).then(success);
- } else {
- $http.post(REST_URL + '/users', userDetail).then(success);
- }
- }
- function success(result) {
- noty({
- layout: 'topRight',
- type: 'success',
- text: 'User: ' + $scope.user.name + ' was successfully ' + ($scope.editUser ? 'updated' : 'created'),
- animation: {
- open: { height: 'toggle' },
- close: { height: 'toggle' },
- easing: 'swing',
- speed: 500
- },
- timeout: 3000,
- closeWith: ['click'],
- });
- $uibModalInstance.close(true);
- }
- function close() {
- $uibModalInstance.close(false);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement