PageSourceSearch

http://monumenta.gov.br/assets/js/ng.user-management-2030143798-1649785341.js

js monumenta.gov.br collected 2026-10-02 14:18:28 UTC 13,116 bytes, 312 lines download raw bytes

1(function (angular) {
2    "use strict";
3    
4    var module = angular.module('usermanager.app', ['search.service.find', 'infinite-scroll', 'mc.module.notifications']);
5
6    module.filter('capitalize', function() {
7        return function(input) {
8          return (!!input) ? input.charAt(0).toUpperCase() + input.substr(1).toLowerCase() : '';
9        }
10    });
11
12    module.factory('userManagermentService', ['$http', '$rootScope', '$q', function($http, $rootScope, $q) {
13        
14        var baseUrl = MapasCulturais.baseURL.substr(-1) === '/' ?  MapasCulturais.baseURL : MapasCulturais.baseURL + '/';
15
16        return {
17            
18            getUrl: function(entity, action){
19                return baseUrl + entity + '/' + action;
20            },
21
22            getAgents: function(userId) {
23                return $http.get(this.getUrl('api/agent', 'find') + '?@select=id,name,subsite.name,singleUrl,deleteUrl,archiveUrl,publishUrl,unarchiveUrl,undeleteUrl,destroyUrl,status,__agentRelations.hasControl,__agentRelations.agent.userId&user=EQ(' + userId + ')');
24            },
25
26            getRelatedsAgentControl: function(userId) {
27                return $http.get(this.getUrl('user', 'relatedsAgentsControl') + '?userId=' + userId);
28            },
29
30            getSpaces: function(userId) {
31                return $http.get(this.getUrl('api/space', 'find') + '?@select=id,name,subsite.name,singleUrl,deleteUrl,archiveUrl,publishUrl,unarchiveUrl,undeleteUrl,destroyUrl,status,__agentRelations.hasControl,__agentRelations.agent.userId&user=EQ(' + userId + ')');
32            },
33            
34            getRelatedsSpacesControl: function(userId) {
35                return $http.get(this.getUrl('user', 'relatedsSpacesControl') + '?userId=' + userId);
36            },
37
38            getEvents: function(userId) {
39                return $http.get(this.getUrl('user', 'events') + '?userId=' + userId);
40            },
41
42            getRelatedsEventsControl: function(userId) {
43                return $http.get(this.getUrl('user', 'relatedsEventsControl') + '?userId=' + userId);
44            },
45
46            getHistory: function(userId) {
47                return $http.get(this.getUrl('user', 'history') + '?userId=' + userId);
48            },
49        };
50    }]);
51
52    module.controller('UserManagermentController', ['$scope', '$rootScope', '$window', '$timeout', 'searchService', 'userManagermentService', function ($scope, $rootScope, $window, $timeout, searchService, userManagermentService) {
53        var timeoutTime = 300;
54
55        var rls = [];
56        if (MapasCulturais.infoAdmin && MapasCulturais.infoAdmin.roles)
57            rls = MapasCulturais.infoAdmin.roles;
58
59        $rootScope.resetPagination = function() {
60            $rootScope.pagination = {
61                agent: 1,
62                space: 1,
63                event: 1,
64                project: 1,
65                opportunity: 1,
66            };
67        }
68
69        $scope.data = {
70            global : {
71                filterEntity: null,
72                viewMode: 'list',
73                locationFilters: {
74                    enabled: null
75                }
76            },
77            infoAdmin : {
78                roles: rls
79            }
80        }
81        
82        $scope.hasSubsites = function () {
83            if(MapasCulturais.infoAdmin && MapasCulturais.infoAdmin.roles && MapasCulturais.infoAdmin.roles.users){
84                return Object.keys(MapasCulturais.infoAdmin.roles.users).length > 1;
85            } else {
86                return false;
87            }
88        };
89
90        $scope.spinnerShow = true;
91
92        $rootScope.$on('searchResultsReady', function(ev, results){
93            if($scope.data.global.viewMode !== 'list')
94                return;
95            $rootScope.isPaginating = false;
96
97            if(results.paginating) {
98                $scope.agents = $scope.agents.concat(results.agent ? results.agent : []);
99                $scope.events = $scope.events.concat(results.event ? results.event : []);
100                $scope.spaces = $scope.spaces.concat(results.space ? results.space : []);
101                $scope.projects = $scope.projects.concat(results.project ? results.project : []);
102                $scope.opportunities = $scope.opportunities.concat(results.opportunity ? results.opportunity : []);
103            } else {
104                $scope.agents = results.agent ? results.agent : [];
105                $scope.events = results.event ? results.event : [];
106                $scope.spaces = results.space ? results.space : [];
107                $scope.projects = results.project ? results.project : [];
108                $scope.opportunities = results.opportunity ? results.opportunity : [];
109            }
110            $scope.spinnerShow = false;
111        });
112
113        $scope.addMore = function(entity) {
114            $scope.spinnerShow = true;
115            var entityName = "";
116            if($scope.data.global.viewMode !== 'list')
117                return;
118
119            if(entity !== $scope.data.global.filterEntity)
120                return;
121
122            if($rootScope.isPaginating)
123                return;
124
125            if(entity == 'opportunity') {
126                entityName = 'opportunities';
127            } else {
128                entityName = entity + 's'
129            }
130
131            if($scope[entityName].length === 0 || $scope[entityName].length < 10)
132                return;
133
134            $rootScope.pagination[entity]++;
135            // para não chamar 2 vezes o search quando está carregando a primeira página (o filtro mudou)
136            if($rootScope.pagination[entity] > 1)
137                $rootScope.$emit('resultPagination', $scope.data);
138        };
139
140        $scope.load = function ($userId) {
141            $scope.user = { 'id':$userId, 
142                            'agents': {'spinnerShow':true},
143                            'spaces': {'spinnerShow':true},
144                            'events': {'spinnerShow':true},
145                       'permissions': {'spinnerShow':true},
146                           'history': {'spinnerShow':true}
147                         }            
148            $scope.loadHistory($userId);
149        }
150
151        $scope.loadHistory = function($userId) {
152            $scope.user.history.spinnerShow = true;
153            userManagermentService.getHistory($userId)
154                .success(function (data) {
155                    data.forEach(function(el){
156                        el.objectType = el.objectType.substring(24);
157                        el.createTimestamp.date = new Date(el.createTimestamp.date);
158                    });
159                    $scope.user.history.list = data;
160                })
161                .then(function (data) {
162                    $scope.user.history.spinnerShow = false;
163                });
164        }
165        
166        $scope.hasAdmin = function($subsite) {
167            if(!$subsite)
168                return false;
169                
170            for (var i = 0; i < MapasCulturais.subsitesAdmin.length; i++) {
171                var element = MapasCulturais.subsitesAdmin[i];
172                if (element.id == $subsite.id) {
173                    return true;
174                }
175            }
176            return false;
177        }
178
179        $scope.hasControl = function($list, $entity) {
180            var $useId = MapasCulturais.userId;
181            if (!$list) {
182                return false;
183            }
184
185            for (var i = 0; i < $list.length; i++) {
186                var element = $list[i];
187                if(element.hasControl == true && element[$entity].userId == $useId) {
188                    return true;
189                }
190            }
191            return false;
192        }
193
194        $scope.selectGroupAdmin = 'saasSuperAdmin';
195        $scope.selectSubsite = 'MapasCulturais';
196
197        function isValidCPF(cpf){
198            return cpf.match(/^\d{3}\.\d{3}\.\d{3}\-\d{2}$/) || cpf.match(/^\d{11}$/);
199        }
200
201        if($('#user-managerment-search-form').length) {
202            $('#campo-de-busca').focus();
203            $('#search-filter .submenu-dropdown li').click(function() {
204                $scope.spinnerShow = true;
205
206                var params = {
207                    entity: $(this).data('entity'),
208                    keyword: $('#campo-de-busca').val()
209                };
210
211                $scope.data.global.filterEntity = params.entity;
212                $scope.data[params.entity] = {
213                    keyword: !isValidCPF(params.keyword) ? params.keyword : '',
214                    showAdvancedFilters:false,
215                    filters: isValidCPF(params.keyword) ? {documento: `eq(${params.keyword})`} : {}
216                };
217                
218
219                $window.$timout = $timeout;
220                $timeout.cancel($scope.timer);
221                $scope.timer = $timeout(function() {
222                    $rootScope.$emit('searchDataChange', $scope.data);
223                }, timeoutTime);
224                var $dropdown = $(this).parents('.dropdown'),
225                $submenu = $dropdown.find('.submenu-dropdown');
226                $submenu.hide();
227            });
228            
229            $('#campo-de-busca').on('keydown', function(event){
230                if(event.keyCode === 13) {
231                    event.preventDefault();
232                    $('#search-filter .submenu-dropdown li#agents-filter').click();
233                } else if(event.keyCode === 27) {
234                    $(this).attr('css', '');
235                    $(this).blur();
236                    $('#campo-de-busca').focus();
237                    $('#campo-de-busca').val('')
238                    return false;
239                }
240            });
241        }
242
243        $('.user-managerment-infos table.entity-table caption').click(function() {
244            $(this).closest('table').find('tbody').fadeToggle("fast", "linear");
245            $(this).closest('table').find('thead').fadeToggle("fast", "linear");
246        });
247
248        $('#user-managerment-adminChangePassword').click(function() {
249            let password = $('#admin-set-user-password').val();
250            let email = $('#email-to-admin-set-password').val();
251            $.post(MapasCulturais.baseURL + 'auth/adminchangeuserpassword', {password: password, email: email}, function(r){
252                MapasCulturais.Modal.close('#admin-change-user-password');
253                MapasCulturais.Messages.success('Senha alterada com sucesso');
254                $('#admin-set-user-password').val("");
255            });
256        })
257
258        $('#user-managerment-adminChangeEmail').click(function() {
259            let new_email = $('#new-email').val();
260            let email = $('#email-to-admin-set-email').val();
261            $.post(MapasCulturais.baseURL + 'auth/adminchangeuseremail', {new_email: new_email, email: email}, function(r){
262                if(r.error) {
263                    alert(r.error);
264                    return;
265                }
266                MapasCulturais.Modal.close('#admin-change-user-email');
267                MapasCulturais.Messages.success('Email alterado com sucesso');
268                location.reload();
269            });
270        })
271
272        $('#user-managerment-addRole').click(function() {
273            var subsite_id = $('#subsiteList').val();
274            var roleToAdd = $('#permissionList').val();
275            $.post(MapasCulturais.baseURL + 'agent/addRole/' + MapasCulturais.userProfileId, {role: roleToAdd, subsiteId: subsite_id}, function(r){
276                if(r && !r.error)
277                    MapasCulturais.Modal.close('#add-roles');
278                    location.reload();
279            });
280        });
281
282        if($('#funcao-do-agente-user-managerment').length) {
283            $('#funcao-do-agente-user-managerment .js-options li').click(function() {
284                var element_selected = $(this).parent().parent().parent().find('.js-selected span');
285                var roleToRemove = element_selected.data('role');
286                var roleToAdd = $(this).data('role');
287                var label = $(this).find('span').html();
288                var subsite_id = element_selected.data('subsite');
289                var change = function() {
290                    element_selected.html(label);
291                    element_selected.data('role', roleToAdd);
292                };
293                if(roleToRemove)
294                    $.post(MapasCulturais.baseURL + 'agent/removeRole/' + MapasCulturais.userProfileId, {role: roleToRemove, subsiteId: subsite_id}, function(r){ if(r && !r.error) change(); });
295
296                if(roleToAdd)
297                    $.post(MapasCulturais.baseURL + 'agent/addRole/' + MapasCulturais.userProfileId, {role: roleToAdd, subsiteId: subsite_id}, function(r){ if(r && !r.error) change(); });
298
299                MapasCulturais.Messages.success("Permissão atribuida");
300            });
301        }
302
303        $(".tablinks").click(function() {
304            var tab = $(this).data('tab');
305            var entity = $(this).data('entity');
306            $('#' + entity + ' .tab-content-table').hide();
307            $('#' + entity + ' .tab-table button').removeClass("active");
308            $('#' + entity + ' #' + tab).show();
309            $(this).addClass("active");
310        });
311    }]);
312})(angular);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.