Subversion Repositories bacoAlunos

Rev

Rev 1617 | Go to most recent revision | 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
 
1618 jmachado 31
    <div class="col-md-12" 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>
90
 
91
                    <div class="input-group">
1618 jmachado 92
                        <input type="text" id="queryPersons<%=idTemp%>"  onkeyup="if(event.keyCode == 13){searchPersons<%=idTemp%>();}" class="form-control" placeholder="Pesquisar...">
1617 jmachado 93
                          <span class="input-group-btn">
94
                            <button class="btn btn-secondary" type="button" onclick="searchPersons<%=idTemp%>();return false;"><span class="glyphicon glyphicon-search"/></button>
95
                          </span>
96
                    </div>
97
                    <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;">
98
                        <div class="clearfix" style="padding:0">
99
                            <table class="tablesorter-blue" style="margin:0">
100
                                <thead>
101
                                <tr>
102
                                    <th>Nome</th>
103
                                    <th>Tipo</th>
104
                                    <th>Código</th>
105
                                    <th><button ng-click="removeAllUsers()" type="button" class="btn btn-danger btn-xs pull-right clearfix"><span class="glyphicon glyphicon-remove"/></button></th>
106
                                </tr>
107
                                </thead>
108
                                <tbody>
109
                                <tr ng-repeat="f in findUser">
110
                                    <td>{{f.name}}</td>
111
                                    <td ng-if="f.type == 'student'">
112
                                        Estudante
113
                                    </td>
114
                                    <td ng-if="f.type == 'teacher'">
115
                                        Professor
116
                                    </td>
117
                                    <td ng-if="f.type != 'teacher' && f.type != 'student'">
118
                                        User
119
                                    </td>
120
                                    <td>{{f.sigesCode}}</td>
1618 jmachado 121
                                    <td>
122
                                        <%
123
                                        if(useModals != null && !useModals)
124
                                        {
125
                                        %>
126
                                            <button type="button" class="btn btn-success btn-xs" ng-click="addUser( f.id )"><span class="glyphicon glyphicon-plus"/></button>
127
                                        <%
128
                                        }
129
                                        else
130
                                        {
131
                                        %>
132
                                            <bacoTags:confirm icon="glyphicon glyphicon-plus" btnClass="btn btn-success btn-xs">
133
                                                <jsp:attribute name="targetFunction">addUser<%=idTemp%>({{f.id}});angular.element($('#printRoleModule<%=idTemp%>')).scope().removeAllUsers();angular.element($('#printRoleModule<%=idTemp%>')).scope().$apply();</jsp:attribute>
134
                                                <jsp:attribute name="msg">Tem a certeza que deseja adicionar o utilizador {{f.name}} ao grupo <bean:message key="user.role.${role}"/></jsp:attribute>
135
                                            </bacoTags:confirm>
136
                                        <%
137
                                        }
138
                                        %>
139
                                    </td>
1617 jmachado 140
                                </tr>
141
                                </tbody>
142
                            </table>
143
                        </div>
144
                    </div>
145
 
146
                </div>
147
            </div>
148
 
149
            <script>
1618 jmachado 150
 
151
 
1617 jmachado 152
                //DECLARACAO DA APLICACAO LOCAL EM ANGULAR
153
                var printRoleModule<%=idTemp%> = angular.module('printRoleModule<%=idTemp%>', []);
154
                GLOBAL_BacoAngularAppDependencies.push('printRoleModule<%=idTemp%>');
155
                printRoleModule<%=idTemp%>.controller('printRoleModuleController<%=idTemp%>', function($scope) {
156
                    //variavel para a pesquisa de users
157
                    $scope.findUser = [];
158
                    $scope.roleUsers = [];
159
                    $scope.removeAllUsers = function()
160
                    {
161
                        $scope.findUser = [];
162
                    }
1618 jmachado 163
                    $scope.removeUser = function(id)
164
                    {
165
                        if(confirm("Tem a certeza que deseja remover o utilizador?"))
166
                            removeUser<%=idTemp%>(id);
167
                    }
168
                    $scope.addUser = function(id)
169
                    {
170
                        if(confirm("Tem a certeza que deseja adicionar o utilizador?"))
171
                        {
172
                            addUser<%=idTemp%>(id);
173
                            $scope.removeAllUsers();
174
                        }
175
 
176
                    }
1617 jmachado 177
                });
1618 jmachado 178
 
1617 jmachado 179
            </script>
180
            <script language="javascript">
181
 
182
                $(document).ready(function()
183
                {
184
                    loadUserRoles<%=idTemp%>();
185
                });
186
 
187
                function removeUser<%=idTemp%>(id)
188
                {
189
                    widgetCallWithActionParameters(
190
                            '<%=request.getContextPath()%>/user/json/model.do',
191
                            'removeRole2User',
192
                            {
193
                                q :
194
                                "{ userId : " + id + ", role : '${role}' }"
195
                            }
196
                            ,
197
                            $("#printRoleModule<%=idTemp%>"),
198
                            function(response)
199
                            {
200
                                angular.element($("#printRoleModule<%=idTemp%>")).scope().roleUsers = response.results;
201
                                angular.element($("#printRoleModule<%=idTemp%>")).scope().$apply();
202
                            },
203
                            function(response)
204
                            {
205
                                alert("Accao Falhou mas as resposta foi esta: "  + JSON.stringify(response));
206
                            });
207
 
208
                }
1618 jmachado 209
 
210
                function addUser<%=idTemp%>(id)
211
                {
212
                    widgetCallWithActionParameters(
213
                            '<%=request.getContextPath()%>/user/json/model.do',
214
                            'addRole2User',
215
                            {
216
                                q :
217
                                        "{ userId : " + id + ", role : '${role}' }"
218
                            }
219
                            ,
220
                            $("#printRoleModule<%=idTemp%>"),
221
                            function(response)
222
                            {
223
                                angular.element($("#printRoleModule<%=idTemp%>")).scope().roleUsers = response.results;
224
                                angular.element($("#printRoleModule<%=idTemp%>")).scope().$apply();
225
                            },
226
                            function(response)
227
                            {
228
                                alert("Accao Falhou mas as resposta foi esta: "  + JSON.stringify(response));
229
                            });
230
 
231
                }
1617 jmachado 232
                function loadUserRoles<%=idTemp%>()
233
                {
234
                    widgetCallWithActionParameters(
235
                            '<%=request.getContextPath()%>/user/json/model.do',
236
                            'findUserRoles',
237
                            {
238
                                q : "${role}"
239
                            }
240
                            ,
241
                            $("#printRoleModule<%=idTemp%>"),
242
                            function(response)
243
                            {
244
                                angular.element($("#printRoleModule<%=idTemp%>")).scope().roleUsers = response.results;
245
                                angular.element($("#printRoleModule<%=idTemp%>")).scope().$apply();
246
                            },
247
                            function(response)
248
                            {
249
                                alert("Accao Falhou mas as resposta foi esta: "  + JSON.stringify(response));
250
                            });
251
                }
252
 
253
                function searchPersons<%=idTemp%>()
254
                {
255
 
256
                    widgetCallWithActionParameters(
257
                            '<%=request.getContextPath()%>/user/json/model.do',
258
                            'findUser',
259
                            {
260
                                q : $('#queryPersons<%=idTemp%>').val()
261
                            }
262
                            ,
263
                            $("#printRoleModule<%=idTemp%>"),
264
                            function(response)
265
                            {
266
                                angular.element($("#printRoleModule<%=idTemp%>")).scope().findUser = response.results;
267
                                angular.element($("#printRoleModule<%=idTemp%>")).scope().$apply();
268
                                setTimeout(function() { evaluateTableSortersInside("#personsResults<%=idTemp%>"); }, 500);
269
 
270
                                //evaluateTableSortersInside("#personsResults");
271
                            },
272
                            function(response)
273
                            {
274
                                alert("Accao Falhou mas as resposta foi esta: "  + JSON.stringify(response));
275
                            });
276
 
277
                }
278
 
279
            </script>
280
        </div>
1618 jmachado 281
        </baco:hasRole>
1617 jmachado 282
    </div>
283
</div>