Subversion Repositories bacoAlunos

Rev

Rev 1618 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1616 jmachado 1
<%@ tag import="jomm.dao.impl.AbstractDao" %>
1617 jmachado 2
 
1616 jmachado 3
<%@ tag import="pt.estgp.estgweb.domain.dao.DaoFactory" %>
1617 jmachado 4
 
5
<%@ tag import="jomm.utils.BytesUtils" %>
1616 jmachado 6
<%@tag description="Tag to Call Ajax Request" pageEncoding="UTF-8"%>
7
<%@ taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html" %>
8
<%@ taglib uri="/WEB-INF/tlds/struts-nested.tld" prefix="nested" %>
9
<%@ taglib uri="/WEB-INF/tlds/struts-logic.tld" prefix="logic" %>
10
<%@ taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean" %>
11
<%@ taglib uri="/WEB-INF/tlds/struts-tiles.tld" prefix="tiles" %>
12
<%@ taglib uri="/WEB-INF/tlds/baco.tld" prefix="baco" %>
13
<%@ taglib uri="/WEB-INF/tlds/jomm.tld" prefix="jomm" %>
1617 jmachado 14
<%@taglib prefix="bacoTags" tagdir="/WEB-INF/tags" %>
15
 
1616 jmachado 16
<%@attribute name="role" type="java.lang.String" required="true" %>
17
<%@attribute name="title" type="java.lang.String" required="false" %>
18
<%@attribute name="transactional" type="java.lang.Boolean" required="true" %>
1617 jmachado 19
<%@attribute name="printOnlyList" type="java.lang.Boolean" required="false" %>
20
<%@attribute name="ignoreUserId" type="java.lang.Long" required="false" %>
21
<%@attribute name="useWellTitle" type="java.lang.Boolean" required="false" %>
1618 jmachado 22
<%@attribute name="useModals" type="java.lang.Boolean" required="false" %>
1616 jmachado 23
 
24
<%
1617 jmachado 25
    String idTemp = BytesUtils.generateHexKey() + role.replaceAll(" ", "_").replaceAll("\\.","_");
1616 jmachado 26
%>
27
 
1617 jmachado 28
<!-- Usar o Angular para Printar os Roles -->
29
<div class="clearfix">
30
 
1667 jmachado 31
    <div class="col-md-12 printRoleModule" style="padding: 0; margin: 0" id="printRoleModule<%=idTemp%>" ng-app="printRoleModule<%=idTemp%>" ng-controller="printRoleModuleController<%=idTemp%>">
1617 jmachado 32
 
33
        <%
34
            if(printOnlyList == null || printOnlyList == false)
35
            {
36
        %>
37
        <logic:notEmpty name="title">
38
            <h3 <%if(useWellTitle != null && useWellTitle){%>class="well well-sm"<%}%>>${title}</h3>
39
        </logic:notEmpty>
40
        <logic:empty name="title">
41
            <h3 <%if(useWellTitle != null && useWellTitle){%>class="well well-sm"<%}%>><bean:message key="user.role.${role}"/></h3>
42
        </logic:empty>
43
        <%
44
            }
45
        %>
1618 jmachado 46
        <div class="col-md-6" style="padding: 2px; margin: 0">
1617 jmachado 47
            <ul>
48
                <li ng-repeat="u in roleUsers" class="roleUser{{u.id}}">
1618 jmachado 49
                    <baco:hasRole role="admin,all,servicesRolesManagement,servicesCoursesManagement,services">
50
                        <%
51
                            if(useModals != null && !useModals)
52
                            {
53
                        %>
54
                        <button type="button" class="btn btn-danger btn-xs" ng-click="removeUser( u.id )"><span class="glyphicon glyphicon-remove"/></button>
55
                        <%
56
                            }
57
                            else
58
                            {
59
                        %>
1617 jmachado 60
                        <bacoTags:confirm icon="glyphicon glyphicon-remove" btnClass="btn btn-danger btn-xs">
61
                            <jsp:attribute name="targetFunction">removeUser<%=idTemp%>({{u.id}})</jsp:attribute>
62
                            <jsp:attribute name="msg">Tem a certeza que deseja remover o utilizador {{u.name}} do grupo <bean:message key="user.role.${role}"/></jsp:attribute>
63
                        </bacoTags:confirm>
1618 jmachado 64
                        <%
65
                            }
66
                        %>
67
                    </baco:hasRole>
1617 jmachado 68
 
69
                    {{u.username}}
70
                    <label ng-if="u.name">
71
                        - {{u.name}}
72
                    </label>
73
                    <label ng-if="u.sigesCode">
74
                        ({{u.sigesCode}})
75
                    </label>
76
                    <%--</label>--%>
77
 
78
                </li>
79
            </ul>
80
        </div>
1618 jmachado 81
        <baco:hasRole role="admin,all,servicesRolesManagement,servicesCoursesManagement,services">
82
            <div class="col-md-6" style="padding: 2px; margin: 0">
1617 jmachado 83
 
84
            <div class="panel panel-default">
85
                <div class="panel-heading">
86
                    Adicionar elemento ao grupo <bean:message key="user.role.${role}"/>
87
                </div>
88
                <div class="panel-body">
89
                    <div class="web-messages"> </div>
1667 jmachado 90
                    <baco:hasNotRole role="admin,all,servicesRolesManagement">
91
                        <p>Necessita de permissões de administrador ou de Gestão de Papeis</p>
92
                    </baco:hasNotRole>
1617 jmachado 93
                    <div class="input-group">
1618 jmachado 94
                        <input type="text" id="queryPersons<%=idTemp%>"  onkeyup="if(event.keyCode == 13){searchPersons<%=idTemp%>();}" class="form-control" placeholder="Pesquisar...">
1617 jmachado 95
                          <span class="input-group-btn">
96
                            <button class="btn btn-secondary" type="button" onclick="searchPersons<%=idTemp%>();return false;"><span class="glyphicon glyphicon-search"/></button>
97
                          </span>
98
                    </div>
99
                    <div ng-show="findUser.length > 0" class="clearfix" id="personsResults<%=idTemp%>" style="position: absolute; background-color: gray;border: 1px solid gray;z-index: 1000; right: 30px;left:30px;">
100
                        <div class="clearfix" style="padding:0">
101
                            <table class="tablesorter-blue" style="margin:0">
102
                                <thead>
103
                                <tr>
104
                                    <th>Nome</th>
105
                                    <th>Tipo</th>
106
                                    <th>Código</th>
107
                                    <th><button ng-click="removeAllUsers()" type="button" class="btn btn-danger btn-xs pull-right clearfix"><span class="glyphicon glyphicon-remove"/></button></th>
108
                                </tr>
109
                                </thead>
110
                                <tbody>
111
                                <tr ng-repeat="f in findUser">
112
                                    <td>{{f.name}}</td>
113
                                    <td ng-if="f.type == 'student'">
114
                                        Estudante
115
                                    </td>
116
                                    <td ng-if="f.type == 'teacher'">
117
                                        Professor
118
                                    </td>
119
                                    <td ng-if="f.type != 'teacher' && f.type != 'student'">
120
                                        User
121
                                    </td>
122
                                    <td>{{f.sigesCode}}</td>
1618 jmachado 123
                                    <td>
124
                                        <%
125
                                        if(useModals != null && !useModals)
126
                                        {
127
                                        %>
128
                                            <button type="button" class="btn btn-success btn-xs" ng-click="addUser( f.id )"><span class="glyphicon glyphicon-plus"/></button>
129
                                        <%
130
                                        }
131
                                        else
132
                                        {
133
                                        %>
134
                                            <bacoTags:confirm icon="glyphicon glyphicon-plus" btnClass="btn btn-success btn-xs">
135
                                                <jsp:attribute name="targetFunction">addUser<%=idTemp%>({{f.id}});angular.element($('#printRoleModule<%=idTemp%>')).scope().removeAllUsers();angular.element($('#printRoleModule<%=idTemp%>')).scope().$apply();</jsp:attribute>
136
                                                <jsp:attribute name="msg">Tem a certeza que deseja adicionar o utilizador {{f.name}} ao grupo <bean:message key="user.role.${role}"/></jsp:attribute>
137
                                            </bacoTags:confirm>
138
                                        <%
139
                                        }
140
                                        %>
141
                                    </td>
1617 jmachado 142
                                </tr>
143
                                </tbody>
144
                            </table>
145
                        </div>
146
                    </div>
147
 
148
                </div>
149
            </div>
150
 
151
            <script>
1618 jmachado 152
 
153
 
1617 jmachado 154
                //DECLARACAO DA APLICACAO LOCAL EM ANGULAR
1667 jmachado 155
 
1617 jmachado 156
                var printRoleModule<%=idTemp%> = angular.module('printRoleModule<%=idTemp%>', []);
157
                GLOBAL_BacoAngularAppDependencies.push('printRoleModule<%=idTemp%>');
1667 jmachado 158
 
1617 jmachado 159
                printRoleModule<%=idTemp%>.controller('printRoleModuleController<%=idTemp%>', function($scope) {
160
                    //variavel para a pesquisa de users
161
                    $scope.findUser = [];
162
                    $scope.roleUsers = [];
163
                    $scope.removeAllUsers = function()
164
                    {
165
                        $scope.findUser = [];
166
                    }
1618 jmachado 167
                    $scope.removeUser = function(id)
168
                    {
169
                        if(confirm("Tem a certeza que deseja remover o utilizador?"))
170
                            removeUser<%=idTemp%>(id);
171
                    }
172
                    $scope.addUser = function(id)
173
                    {
174
                        if(confirm("Tem a certeza que deseja adicionar o utilizador?"))
175
                        {
176
                            addUser<%=idTemp%>(id);
177
                            $scope.removeAllUsers();
178
                        }
179
 
180
                    }
1617 jmachado 181
                });
1618 jmachado 182
 
1617 jmachado 183
            </script>
184
            <script language="javascript">
185
 
186
                $(document).ready(function()
187
                {
188
                    loadUserRoles<%=idTemp%>();
189
                });
190
 
191
                function removeUser<%=idTemp%>(id)
192
                {
193
                    widgetCallWithActionParameters(
194
                            '<%=request.getContextPath()%>/user/json/model.do',
195
                            'removeRole2User',
196
                            {
197
                                q :
198
                                "{ userId : " + id + ", role : '${role}' }"
199
                            }
200
                            ,
201
                            $("#printRoleModule<%=idTemp%>"),
202
                            function(response)
203
                            {
204
                                angular.element($("#printRoleModule<%=idTemp%>")).scope().roleUsers = response.results;
205
                                angular.element($("#printRoleModule<%=idTemp%>")).scope().$apply();
206
                            },
207
                            function(response)
208
                            {
209
                                alert("Accao Falhou mas as resposta foi esta: "  + JSON.stringify(response));
210
                            });
211
 
212
                }
1618 jmachado 213
 
214
                function addUser<%=idTemp%>(id)
215
                {
216
                    widgetCallWithActionParameters(
217
                            '<%=request.getContextPath()%>/user/json/model.do',
218
                            'addRole2User',
219
                            {
220
                                q :
221
                                        "{ userId : " + id + ", role : '${role}' }"
222
                            }
223
                            ,
224
                            $("#printRoleModule<%=idTemp%>"),
225
                            function(response)
226
                            {
227
                                angular.element($("#printRoleModule<%=idTemp%>")).scope().roleUsers = response.results;
228
                                angular.element($("#printRoleModule<%=idTemp%>")).scope().$apply();
229
                            },
230
                            function(response)
231
                            {
232
                                alert("Accao Falhou mas as resposta foi esta: "  + JSON.stringify(response));
233
                            });
234
 
235
                }
1617 jmachado 236
                function loadUserRoles<%=idTemp%>()
237
                {
238
                    widgetCallWithActionParameters(
239
                            '<%=request.getContextPath()%>/user/json/model.do',
240
                            'findUserRoles',
241
                            {
242
                                q : "${role}"
243
                            }
244
                            ,
245
                            $("#printRoleModule<%=idTemp%>"),
246
                            function(response)
247
                            {
248
                                angular.element($("#printRoleModule<%=idTemp%>")).scope().roleUsers = response.results;
249
                                angular.element($("#printRoleModule<%=idTemp%>")).scope().$apply();
250
                            },
251
                            function(response)
252
                            {
253
                                alert("Accao Falhou mas as resposta foi esta: "  + JSON.stringify(response));
254
                            });
255
                }
256
 
257
                function searchPersons<%=idTemp%>()
258
                {
259
 
260
                    widgetCallWithActionParameters(
261
                            '<%=request.getContextPath()%>/user/json/model.do',
262
                            'findUser',
263
                            {
264
                                q : $('#queryPersons<%=idTemp%>').val()
265
                            }
266
                            ,
267
                            $("#printRoleModule<%=idTemp%>"),
268
                            function(response)
269
                            {
270
                                angular.element($("#printRoleModule<%=idTemp%>")).scope().findUser = response.results;
271
                                angular.element($("#printRoleModule<%=idTemp%>")).scope().$apply();
272
                                setTimeout(function() { evaluateTableSortersInside("#personsResults<%=idTemp%>"); }, 500);
273
 
274
                                //evaluateTableSortersInside("#personsResults");
275
                            },
276
                            function(response)
277
                            {
278
                                alert("Accao Falhou mas as resposta foi esta: "  + JSON.stringify(response));
279
                            });
280
 
281
                }
282
 
283
            </script>
284
        </div>
1618 jmachado 285
        </baco:hasRole>
1617 jmachado 286
    </div>
287
</div>