Subversion Repositories bacoAlunos

Rev

Rev 1725 | Rev 1756 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1714 jmachado 1
<%@ page import="jomm.dao.DaoException" %>
1675 jmachado 2
<%@ page import="jomm.dao.impl.AbstractDao" %>
3
<%@ page import="org.hibernate.Criteria" %>
4
<%@ page import="org.hibernate.criterion.Criterion" %>
1692 jmachado 5
 
1714 jmachado 6
<%@ page import="org.hibernate.criterion.Order" %>
1675 jmachado 7
<%@ page import="static org.hibernate.criterion.Restrictions.eq" %>
8
<%@ page import="static org.hibernate.criterion.Restrictions.or" %>
1714 jmachado 9
<%@ page import="pt.estgp.estgweb.domain.RepositoryDocument" %>
10
<%@ page import="pt.estgp.estgweb.domain.RepositoryDocumentCollection" %>
11
<%@ page import="pt.estgp.estgweb.domain.RepositoryDocumentInterfaceImpl" %>
1692 jmachado 12
<%@ page import="pt.estgp.estgweb.domain.dao.DaoFactory" %>
1714 jmachado 13
<%@ page import="pt.estgp.estgweb.services.data.repositorydocuments.interfaces.InterfaceBlock" %>
1692 jmachado 14
<%@ page import="pt.estgp.estgweb.services.data.repositorydocuments.interfaces.RepositoryInterface" %>
1714 jmachado 15
<%@ page import="java.util.List" %>
1713 jmachado 16
<%@ page import="static org.hibernate.criterion.Restrictions.le" %>
17
<%@ page import="static org.hibernate.criterion.Restrictions.*" %>
1675 jmachado 18
<%@ taglib uri="/WEB-INF/tlds/struts-html.tld"  prefix="html" %>
19
<%@ taglib uri="/WEB-INF/tlds/struts-nested.tld"  prefix="nested" %>
20
<%@ taglib uri="/WEB-INF/tlds/struts-logic.tld"  prefix="logic" %>
21
<%@ taglib uri="/WEB-INF/tlds/struts-bean.tld"  prefix="bean" %>
22
<%@ taglib uri="/WEB-INF/tlds/struts-tiles.tld"  prefix="tiles" %>
23
<%@ taglib tagdir="/WEB-INF/tags"  prefix="bacoTags" %>
1714 jmachado 24
<%@ taglib prefix="baco" uri="http://www.estgp.pt/baco/" %>
1675 jmachado 25
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
26
<%
1692 jmachado 27
    String slugOrId = (String) request.getAttribute("slug");
28
    AbstractDao.getCurrentSession().beginTransaction();
1675 jmachado 29
 
1692 jmachado 30
    RepositoryDocumentInterfaceImpl repositoryDocumentInterface;
31
    try{
32
        repositoryDocumentInterface = DaoFactory.getRepositoryDocumentInterfaceDaoImpl().findBySlug(slugOrId);
33
    }
34
    catch(DaoException e)
35
    {
36
        response.sendError(404);
37
        return;
38
    }
39
    RepositoryInterface loadedConfig = repositoryDocumentInterface.getRepositoryInterface();
40
    request.setAttribute("loadedConfig",loadedConfig);
1675 jmachado 41
 
42
 
43
 
44
%>
1692 jmachado 45
<%--<jsp:useBean id="loadedConfig" type="pt.estgp.estgweb.services.data.repositorydocuments.interfaces.RepositoryInterface" scope="request"/>
46
--%>
1703 jmachado 47
<script>
1714 jmachado 48
    <%
49
        String toReplaceContainer;
50
        String newContainer;
51
 
52
        if(loadedConfig.isContainerFluid())
53
        {
54
            toReplaceContainer = "container";
55
            newContainer = "container-fluid";
56
        }
57
        else
58
        {
59
            toReplaceContainer = "container-fluid";
60
            newContainer = "container";
61
        }
62
    %>
63
 
64
    $(document).ready(function()
65
    {
66
        var toReplaceContainer = "<%=toReplaceContainer%>";
67
        var newContainer = "<%=newContainer%>";
68
        var containerToReplace = $("." + toReplaceContainer);
69
        var containerToUse = $("." + newContainer);
70
        if(containerToReplace)
71
        {
72
            containerToReplace.removeClass(toReplaceContainer);
73
            containerToReplace.addClass(newContainer);
74
        }
75
        else if(!containerToUse)
76
        {
77
            $(".repository-interface").wrap("<div class='" + newContainer + "'></div>")
78
        }
1703 jmachado 79
    });
1712 jmachado 80
 
81
 
1714 jmachado 82
    /**********************************
83
     * FUNCIONALIDADE DE PESQUISA
84
     * *******************************/
85
 
86
     $.extend($.expr[':'], {
1712 jmachado 87
                'containsi': function(elem, i, match, array)
88
                {
89
                    return (elem.textContent || elem.innerText || '').toLowerCase()
90
                            .indexOf((match[3] || "").toLowerCase()) >= 0;
91
                }
92
            });
93
    $(document).ready(
94
            function(){
95
 
1755 jmachado 96
 
97
                $('.repository-interface .collapse')
98
                        .on('shown.bs.collapse', function() {
99
                            $(this)
100
                                    .parent()
101
                                    .find(".glyphicon-plus").eq(0)
102
                                    .removeClass("glyphicon-plus")
103
                                    .addClass("glyphicon-minus");
104
                        })
105
                        .on('hidden.bs.collapse', function() {
106
                            $(this)
107
                                    .parent()
108
                                    .find(".glyphicon-minus").eq(0)
109
                                    .removeClass("glyphicon-minus")
110
                                    .addClass("glyphicon-plus");
111
                        });
112
 
113
 
114
 
1712 jmachado 115
                $("#documentFilterInput").unbind("click");
116
                $('#documentFilterInput').bind("keypress", function(e) {
117
                    if (e.keyCode == 13) {
118
                        e.preventDefault();
119
                        return false;
120
                    }
121
                });
122
                $("#documentFilterInput").keyup(
123
                        function(){
124
                            if($("#documentFilterInput").val()=="")
125
                            {
126
                                $(".repository-document").show();
127
                            }
128
                            else
129
                            {
1755 jmachado 130
                                $('.repository-interface .collapse').collapse('show');
1712 jmachado 131
                                var fields = $("#documentFilterInput").val().split(" ");
132
 
133
                                $(".repository-document").show();
134
                                $(".repository-document").each(
135
                                        function()
136
                                        {
137
                                            for(var i = 0; i < fields.length; i++)
138
                                            {
139
                                                if($(this).find(" *:containsi('"+fields[i]+"')").length == 0)
140
                                                {
141
                                                    $(this).hide();
142
                                                    break;
143
                                                }
144
                                            }
145
                                        }
146
                                );
147
                            }
148
                        }
149
                );
1755 jmachado 150
 
151
 
1712 jmachado 152
            }
153
    );
154
 
1755 jmachado 155
    function toogleId()
156
    {
157
 
158
    }
159
 
1703 jmachado 160
</script>
1675 jmachado 161
<style>
162
    body
163
    {
164
        background-color: white !important;
165
    }
166
</style>
167
 
168
 
1703 jmachado 169
<div class="repository-interface">
1675 jmachado 170
 
1703 jmachado 171
    <div class="repository-intro repository-interface-intro">
172
        <logic:equal value="true" name="loadedConfig" property="showTitle">
1712 jmachado 173
            <div class="repository-title clearfix">
1703 jmachado 174
                    ${loadedConfig.title}
1712 jmachado 175
 
176
 
177
                <span class="pull-right" style="font-size: 0.7em;display: inline-block">
178
                     <input class="form-control" id="documentFilterInput" type="text" style="width: 200px"/>
179
                </span>
180
                <span class="pull-right" style="font-size: 0.7em;margin-right: 5px; margin-top: 5px">
181
                        Pesquisar Nesta Página:
182
                </span>
183
 
184
 
1703 jmachado 185
            </div>
186
        </logic:equal>
187
        <logic:equal value="true" name="loadedConfig" property="showDescription">
188
            <div class="repository-description">
189
                ${loadedConfig.description}
190
            </div>
191
        </logic:equal>
192
    </div>
1675 jmachado 193
 
1692 jmachado 194
    <nested:iterate id="interfaceRow" name="loadedConfig" property="rows" type="pt.estgp.estgweb.services.data.repositorydocuments.interfaces.InterfaceRow">
195
        <div class="row">
1703 jmachado 196
            <div class="repository-intro">
197
                <logic:equal value="true" name="interfaceRow" property="showTitle">
198
                    <div class="repository-title">
199
                            ${interfaceRow.title}
200
                    </div>
201
                </logic:equal>
202
                <logic:equal value="true" name="interfaceRow" property="showDescription">
203
                    <div class="repository-description">
204
                            ${interfaceRow.description}
205
                    </div>
206
                </logic:equal>
207
            </div>
1692 jmachado 208
            <nested:iterate id="interfaceColumn" name="interfaceRow" property="columns" type="pt.estgp.estgweb.services.data.repositorydocuments.interfaces.InterfaceColumn">
1703 jmachado 209
                <div class="col-md-${interfaceColumn.cols} repository-column">
210
                    <div class="repository-intro">
211
                        <logic:equal value="true" name="interfaceColumn" property="showTitle">
212
                            <div class="repository-title">
213
                                <span class="btn-xs glyphicon glyphicon-bookmark"></span>
1692 jmachado 214
                                ${interfaceColumn.title}
1703 jmachado 215
                            </div>
216
                        </logic:equal>
217
                        <logic:equal value="true" name="interfaceColumn" property="showDescription">
218
                            <div class="repository-description">
219
                                    ${interfaceColumn.description}
220
                            </div>
221
                        </logic:equal>
222
                    </div>
1675 jmachado 223
 
1714 jmachado 224
 
1692 jmachado 225
                    <nested:iterate id="interfaceBlock" name="interfaceColumn" property="blocks" type="pt.estgp.estgweb.services.data.repositorydocuments.interfaces.InterfaceBlock">
1714 jmachado 226
                        <%
227
                        List<Long> collections = interfaceBlock.getCollectionIds();
228
                        %>
1755 jmachado 229
 
230
                        <%
231
 
232
                            String idChilds = "block_" + interfaceBlock.hashCode();
233
 
234
 
235
                            //String toogleAttrs = interfaceBlock.isBrowseMinimizeMaximize() ? " data-toggle=\"collapse\" data-target=\"#" + idChilds + "\" " :"";
236
                            //String styleCol = interfaceBlock.isBrowseMinimizeMaximize() ? " style=\"cursor:hand; text-decoration:underline\" " :"";
237
 
238
                            String toogleAttrs = " data-toggle=\"collapse\" data-target=\"#" + idChilds + "\" " ;
239
                            String styleCol = " style=\"cursor:hand; text-decoration:underline\" ";
240
                            String folderIcon = !interfaceBlock.isTree() && interfaceBlock.isBrowseMinimizeMaximize() ? " glyphicon-plus " : " glyphicon-minus ";
241
 
242
 
243
                        %>
1703 jmachado 244
                        <div class="repository-block">
1755 jmachado 245
                            <div class="repository-intro" <%=toogleAttrs%>>
1703 jmachado 246
                                <logic:equal value="true" name="interfaceBlock" property="showTitle">
1755 jmachado 247
 
1703 jmachado 248
                                    <div class="repository-title">
1755 jmachado 249
                                        <span class="btn-xs glyphicon <%=folderIcon%>" style="margin-right: 5px"></span>
1703 jmachado 250
                                        <span class="btn-xs glyphicon glyphicon-bookmark"></span>
1755 jmachado 251
                                        <label <%=styleCol%>>${interfaceBlock.title}</label>
1703 jmachado 252
                                    </div>
253
                                </logic:equal>
1725 jmachado 254
 
1717 jmachado 255
                                <baco:hasRole role="admin,all,repositoryDocs">
256
                                    <logic:notEmpty name="interfaceBlock" property="collectionIds">
257
                                        <%
1725 jmachado 258
                                            if(collections != null && collections.size() == 1 && !interfaceBlock.isTree())
1717 jmachado 259
                                            {
260
                                                request.setAttribute("colToAdd",collections.get(0));
261
                                        %>
262
                                        <html:link styleClass="btn btn-xs btn-success pull-right" action="/user/repositoryEditDocument?repositoryCollectionId=${colToAdd}" target="_blank">
263
                                            <span class="glyphicon glyphicon-plus"></span>
264
                                        </html:link>
265
                                        <%
266
                                            }
267
                                        %>
268
                                    </logic:notEmpty>
269
                                </baco:hasRole>
1703 jmachado 270
                                <logic:equal value="true" name="interfaceBlock" property="showDescription">
271
                                    <div class="repository-description">
272
                                            ${interfaceBlock.description}
273
                                    </div>
274
                                </logic:equal>
275
                            </div>
1755 jmachado 276
                            <div id="<%=idChilds%>" <%=!interfaceBlock.isTree() && interfaceBlock.isBrowseMinimizeMaximize() ? " class=\"repository-block-childs collapse\"" :" class=\"repository-block-childs collapse in \" "%>>
1703 jmachado 277
                            <%!
278
 
279
                                public Criterion getAllCollectionsClauses(Long collectionId)
280
                                {
281
                                    Criterion c;
282
                                    RepositoryDocumentCollection col = DaoFactory.getRepositoryDocumentCollectionDaoImpl().load(collectionId);
283
                                    c = eq("collection.id",col.getId());
284
                                    if( col.getChilds() != null &&  col.getChilds().size() > 0)
285
                                    {
286
                                        for(RepositoryDocumentCollection child: col.getChilds())
287
                                        {
288
                                            Criterion cChilds = getAllCollectionsClauses(child.getId());
289
                                            if(cChilds != null)
290
                                                c = or(c,cChilds);
291
                                        }
292
                                    }
293
                                    return c;
294
                                }
295
 
1755 jmachado 296
                                %>
297
                                <%
1703 jmachado 298
 
1692 jmachado 299
 
300
 
1675 jmachado 301
 
1703 jmachado 302
 
1714 jmachado 303
 
1755 jmachado 304
                                    if(!interfaceBlock.isTree())
1675 jmachado 305
                                    {
1755 jmachado 306
                                        Criteria c = AbstractDao.getCurrentSession().createCriteria(RepositoryDocument.class);
307
                                        Criterion clauses = null;
308
                                        for(Long collection : collections)
1703 jmachado 309
                                        {
1755 jmachado 310
                                            Criterion clausesCol = getAllCollectionsClauses(collection);
311
                                            if(clauses == null)
312
                                                clauses = clausesCol;
313
                                            else
314
                                            {
315
                                                clauses = or(clauses,clausesCol);
316
                                            }
1703 jmachado 317
                                        }
1755 jmachado 318
                                        c.add(clauses);
319
                                        c.add(eq("visible",true));
320
                                        if(interfaceBlock.getOrderBy() == InterfaceBlock.Order.publishDateAsc)
321
                                            c.addOrder(Order.asc("publishDate"));
322
                                        else if(interfaceBlock.getOrderBy() == InterfaceBlock.Order.publishDateDesc)
323
                                            c.addOrder(Order.desc("publishDate"));
324
                                        else if(interfaceBlock.getOrderBy() == InterfaceBlock.Order.saveDateAsc)
325
                                            c.addOrder(Order.asc("saveDate"));
326
                                        else if(interfaceBlock.getOrderBy() == InterfaceBlock.Order.saveDateDesc)
327
                                            c.addOrder(Order.desc("saveDate"));
328
                                        else if(interfaceBlock.getOrderBy() == InterfaceBlock.Order.updateDateAsc)
329
                                            c.addOrder(Order.desc("updateDate"));
330
                                        else if(interfaceBlock.getOrderBy() == InterfaceBlock.Order.updateDateDesc)
331
                                            c.addOrder(Order.desc("updateDate"));
332
                                        else if(interfaceBlock.getOrderBy() == InterfaceBlock.Order.title)
333
                                            c.addOrder(Order.asc("title"));
1711 jmachado 334
 
1755 jmachado 335
                                        if(interfaceBlock.getMaxPublishDate() != null && interfaceBlock.getMaxPublishDate().getTime() > 0)
336
                                        {
337
                                            c.add(le("publishDate", interfaceBlock.getMaxPublishDate()));
338
                                        }
339
                                        if(interfaceBlock.getMinPublishDate() != null && interfaceBlock.getMinPublishDate().getTime() > 0)
340
                                        {
341
                                            c.add(ge("publishDate", interfaceBlock.getMinPublishDate()));
342
                                        }
343
                                        List<RepositoryDocument> documents = c.list();
344
                                        request.setAttribute("documents",documents);
345
                                        request.setAttribute("interfaceBlock",interfaceBlock);
1692 jmachado 346
 
1755 jmachado 347
                                        %>
348
                                        <jsp:include page="showInterfaceDocsFragment.jsp"/>
349
                                        <%
1703 jmachado 350
 
1755 jmachado 351
                                    }
352
                                    else
1703 jmachado 353
                                    {
1755 jmachado 354
                                        for(Long collection : collections)
1703 jmachado 355
                                        {
1755 jmachado 356
                                            RepositoryDocumentCollection col = DaoFactory.getRepositoryDocumentCollectionDaoImpl().get(collection);
357
                                            for(RepositoryDocumentCollection child: col.getChilds())
358
                                            {
359
                                                request.setAttribute("collection",child);
360
                                                request.setAttribute("interfaceBlock",interfaceBlock);
361
                                                %>
362
                                                <jsp:include page="showInterfaceColFragment.jsp"/>
363
                                                <%
364
                                            }
1703 jmachado 365
                                        }
366
                                    }
1755 jmachado 367
                                %>
368
                            </div>
1675 jmachado 369
                        </div>
1692 jmachado 370
                    </nested:iterate>
1675 jmachado 371
 
1692 jmachado 372
                </div>
373
            </nested:iterate>
374
        </div>
375
    </nested:iterate>
376
 
1675 jmachado 377
</div>
378
 
379
<%
380
    AbstractDao.getCurrentSession().getTransaction().commit();
381
%>