PageSourceSearch

http://monumenta.gov.br/assets/js/ng.module.chat-3324308708-1649785341.js

js monumenta.gov.br collected 2026-10-02 14:18:30 UTC 8,133 bytes, 228 lines download raw bytes

1(function (angular) {
2    "use strict";
3
4    var app = angular.module('ng.module.chat', [
5        "mc.directive.editBox",
6        "mc.module.notifications",
7        "ngSanitize"
8    ]);
9
10    app.config(['$httpProvider', function ($httpProvider) {
11        $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
12        $httpProvider.defaults.transformRequest = function (data) {
13            var result = angular.isObject(data) && String(data) !== '[object File]' ? $.param(data) : data;
14
15            return result;
16        };
17    }]);
18
19    app.factory('ChatService', ['$http', '$rootScope', function ($http, $rootScope) {
20        return {
21            serviceProperty: null,
22            getUrl: function () {
23                return MapasCulturais.baseURL // + controllerId  + '/' + actionName 
24            },
25            doSomething: function (param) {
26                var data = {
27                    prop: name
28                };
29                return $http.post(this.getUrl(), data).
30                success(function (data, status) {
31                    $rootScope.$emit('something', { message: "Something was done", data: data, status: status });
32                }).
33                    error(function (data, status) {
34                        $rootScope.$emit('error', { message: "Cannot do something", data: data, status: status });
35                    });
36                },
37                
38            find: function (data) {
39
40                var qdata = '/api/chatMessage/find?@select=id,createTimestamp,payload,user.profile.{id,name,singleUrl}&thread=EQ(' + data + ')';
41
42                return $http.get(qdata).
43                    success(function (data, status) {
44                        for (var i = 0; i < data.length; i++) {
45                            data[i].date = moment(data[i].createTimestamp.date).format('DD/MM/YYYY');
46                            data[i].time = moment(data[i].createTimestamp.date).format('HH:mm');
47                        }
48                        $rootScope.$emit('something', { message: "Something was done", data: data, status: status });
49                    }).
50                    error(function (data, status) {
51                        $rootScope.$emit('error', { message: "Cannot do something", data: data, status: status });
52                    });
53
54            },
55            
56            create: function (data) {
57              
58                var url = MapasCulturais.createUrl('chatMessage');
59
60                return $http.post(url, {thread: data.thread, payload: data.payload}).
61                    success(function (data, status) {
62                        data.date = moment(data.createTimestamp.date).format('DD/MM/YYYY');
63                        data.time = moment(data.createTimestamp.date).format('HH:mm');
64                        $rootScope.$emit('something', { message: "Something was done", data: data, status: status });
65                    }).
66                    error(function (data, status) {
67                        $rootScope.$emit('error', { message: "Cannot do something", data: data, status: status });
68                    });
69            },
70        };
71    }]);
72
73    app.controller('ChatController', ['$scope', '$rootScope', '$timeout', 'ChatService', 'EditBox', function ($scope, $rootScope, $timeout, ChatService, EditBox) {
74        var adjustingBoxPosition = false;
75        $scope.editbox = EditBox;
76        $scope.data = {
77            threadId: null,
78            messages: [],
79            newMessage: '',
80            previousMessage: {},
81            spinner: false,
82            sending: false,
83            chatFocusTime: 60000,
84            currentUserId: MapasCulturais.userProfile.id,
85            chatFocus: false,
86            
87            apiQuery: {
88
89            }
90        };
91
92        $scope.setFocus = function (fieldId) {   
93            if(!fieldId){
94                fieldId = "event";
95            }  
96
97            document.querySelector('.txt-'+fieldId).focus();
98        }
99
100        $scope.toogleTalk = function (fieldId) { 
101            if(!fieldId){
102                fieldId = "event";
103            } 
104
105            var chat = document.querySelector('.chat-'+fieldId);            
106            chat.classList.toggle('hidden')
107        }
108        
109        $scope.checkToggleTalk = function(fieldId){
110            if(!fieldId){
111                fieldId = "event";
112            } 
113
114            var chat = document.querySelector('.chat-'+fieldId);       
115            
116            if(chat.classList.contains("hidden")){
117                chat.classList.toggle('hidden')
118            }
119        }
120
121        $scope.getClassName = function(fieldId){
122            if(!fieldId){
123                return "event";
124            } 
125
126            return fieldId;
127        }
128
129        $scope.init = function(threadId) {
130            $scope.data.threadId = threadId;
131        }
132
133        $scope.isChatClosed = function() {
134            return $rootScope.closedChats && $rootScope.closedChats[$scope.data.threadId];
135        }
136
137        $scope.$watch('data.chatFocus', function(new_val, old_val) {
138            
139            if(new_val != old_val){
140                clearInterval($scope.data.interval);
141                $scope.data.chatFocusTime = new_val ? 10000 : 60000;
142                $scope.data.interval = setInterval(getLatestMessages, $scope.data.chatFocusTime);           
143            }
144        });
145
146        var adjustBoxPosition = function () {
147            setTimeout(function () {
148                adjustingBoxPosition = true;
149                $('#module-name-owner-button').click();
150                adjustingBoxPosition = false;
151            });
152        };
153
154        var getLatestMessages = function () {
155            ChatService.find($scope.data.threadId).success(function (data, status, headers) {
156                $scope.data.messages.forEach(function (current) {
157                    
158                    var found = false;
159                    data.forEach(function(returnApi){
160                        if(current.id == returnApi.id){
161                            found = true;
162                        }
163                    });
164
165                    if(!found){
166                        data.push(current);
167                    }
168                });
169
170                $scope.data.messages = data;
171            });
172        };
173
174        // Verifica se pressionou CTRl+ENTER
175        $scope.handleCtrlEnterAction = function (e) {
176            var chatMessage = this.data.newMessage;
177            if (e.ctrlKey && e.key === 'Enter' && chatMessage.trim() !== '') {
178                e.preventDefault();
179                $scope.sendMessage(chatMessage);
180            }
181        };
182
183        $scope.sendMessage = function (message) {
184            if($scope.data.sending){
185                return;
186            }
187
188            var newMessage = {
189                thread: $scope.data.threadId,
190                payload: message
191            };
192
193            $scope.data.sending = true;
194
195            ChatService.create(newMessage).success(function (data, status, headers) {
196                $scope.data.messages.push(data);
197                $scope.data.newMessage = '';
198                $scope.data.sending = false;
199            });
200
201
202        }
203
204        $rootScope.$on('repeatDone:findEntity:find-entity-module-name-owner', adjustBoxPosition);
205
206        $scope.$watch('data.spinner', function (ov, nv) {
207            if (ov && !nv)
208                adjustBoxPosition();
209        });
210
211        setTimeout(() => {
212            ChatService.find($scope.data.threadId).success(function (data, status, headers) {
213                $scope.data.messages = data;
214            });
215
216            // @todo: Mover para local adequado
217            $("textarea.new-message").each(function () {
218                this.setAttribute("style", "height:" + (this.scrollHeight) + "px;overflow-y:hidden;min-height:52px");
219            }).on("input", function () {
220                this.style.height = "auto";
221                this.style.height = (this.scrollHeight) + "px";
222            });
223        }, 0);
224
225        $scope.data.interval = setInterval(getLatestMessages, $scope.data.chatFocusTime);
226
227    }]);
228})(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.