Subversion Repositories bacoAlunos

Rev

Rev 1758 | Rev 1760 | 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')
1756 jmachado 98
                        .on('shown.bs.collapse', function(e) {
99
                            if ($(this).is(e.target)) {
100
                                $(this)
101
                                    .parent().eq(0)
1755 jmachado 102
                                    .find(".glyphicon-plus").eq(0)
103
                                    .removeClass("glyphicon-plus")
104
                                    .addClass("glyphicon-minus");
1756 jmachado 105
                            }
1755 jmachado 106
                        })
1756 jmachado 107
                        .on('hidden.bs.collapse', function(e) {
108
                            if ($(this).is(e.target)) {
109
                                $(this)
110
                                        .parent().eq(0)
111
                                        .find(".glyphicon-minus").eq(0)
112
                                        .removeClass("glyphicon-minus")
113
                                        .addClass("glyphicon-plus");
114
                            }
1755 jmachado 115
                        });
116
 
117
 
118
 
1712 jmachado 119
                $("#documentFilterInput").unbind("click");
120
                $('#documentFilterInput').bind("keypress", function(e) {
121
                    if (e.keyCode == 13) {
122
                        e.preventDefault();
123
                        return false;
124
                    }
125
                });
126
                $("#documentFilterInput").keyup(
127
                        function(){
128
                            if($("#documentFilterInput").val()=="")
129
                            {
130
                                $(".repository-document").show();
131
                            }
132
                            else
133
                            {
1755 jmachado 134
                                $('.repository-interface .collapse').collapse('show');
1712 jmachado 135
                                var fields = $("#documentFilterInput").val().split(" ");
136
 
137
                                $(".repository-document").show();
138
                                $(".repository-document").each(
139
                                        function()
140
                                        {
141
                                            for(var i = 0; i < fields.length; i++)
142
                                            {
143
                                                if($(this).find(" *:containsi('"+fields[i]+"')").length == 0)
144
                                                {
145
                                                    $(this).hide();
146
                                                    break;
147
                                                }
148
                                            }
149
                                        }
150
                                );
151
                            }
152
                        }
153
                );
1755 jmachado 154
 
155
 
1712 jmachado 156
            }
157
    );
158
 
1755 jmachado 159
    function toogleId()
160
    {
161
 
162
    }
163
 
1703 jmachado 164
</script>
1675 jmachado 165
<style>
166
    body
167
    {
168
        background-color: white !important;
169
    }
170
</style>
171
 
172
 
1703 jmachado 173
<div class="repository-interface">
1675 jmachado 174
 
1703 jmachado 175
    <div class="repository-intro repository-interface-intro">
176
        <logic:equal value="true" name="loadedConfig" property="showTitle">
1712 jmachado 177
            <div class="repository-title clearfix">
1703 jmachado 178
                    ${loadedConfig.title}
1712 jmachado 179
 
180
 
181
                <span class="pull-right" style="font-size: 0.7em;display: inline-block">
182
                     <input class="form-control" id="documentFilterInput" type="text" style="width: 200px"/>
183
                </span>
184
                <span class="pull-right" style="font-size: 0.7em;margin-right: 5px; margin-top: 5px">
185
                        Pesquisar Nesta Página:
186
                </span>
187
 
188
 
1703 jmachado 189
            </div>
190
        </logic:equal>
191
        <logic:equal value="true" name="loadedConfig" property="showDescription">
192
            <div class="repository-description">
193
                ${loadedConfig.description}
194
            </div>
195
        </logic:equal>
196
    </div>
1675 jmachado 197
 
1692 jmachado 198
    <nested:iterate id="interfaceRow" name="loadedConfig" property="rows" type="pt.estgp.estgweb.services.data.repositorydocuments.interfaces.InterfaceRow">
199
        <div class="row">
1703 jmachado 200
            <div class="repository-intro">
201
                <logic:equal value="true" name="interfaceRow" property="showTitle">
202
                    <div class="repository-title">
203
                            ${interfaceRow.title}
204
                    </div>
205
                </logic:equal>
206
                <logic:equal value="true" name="interfaceRow" property="showDescription">
207
                    <div class="repository-description">
208
                            ${interfaceRow.description}
209
                    </div>
210
                </logic:equal>
211
            </div>
1692 jmachado 212
            <nested:iterate id="interfaceColumn" name="interfaceRow" property="columns" type="pt.estgp.estgweb.services.data.repositorydocuments.interfaces.InterfaceColumn">
1703 jmachado 213
                <div class="col-md-${interfaceColumn.cols} repository-column">
214
                    <div class="repository-intro">
215
                        <logic:equal value="true" name="interfaceColumn" property="showTitle">
216
                            <div class="repository-title">
217
                                <span class="btn-xs glyphicon glyphicon-bookmark"></span>
1692 jmachado 218
                                ${interfaceColumn.title}
1703 jmachado 219
                            </div>
220
                        </logic:equal>
221
                        <logic:equal value="true" name="interfaceColumn" property="showDescription">
222
                            <div class="repository-description">
223
                                    ${interfaceColumn.description}
224
                            </div>
225
                        </logic:equal>
226
                    </div>
1675 jmachado 227
 
1714 jmachado 228
 
1692 jmachado 229
                    <nested:iterate id="interfaceBlock" name="interfaceColumn" property="blocks" type="pt.estgp.estgweb.services.data.repositorydocuments.interfaces.InterfaceBlock">
1714 jmachado 230
                        <%
231
                        List<Long> collections = interfaceBlock.getCollectionIds();
232
                        %>
1755 jmachado 233
 
234
                        <%
235
 
236
                            String idChilds = "block_" + interfaceBlock.hashCode();
237
 
238
 
239
                            //String toogleAttrs = interfaceBlock.isBrowseMinimizeMaximize() ? " data-toggle=\"collapse\" data-target=\"#" + idChilds + "\" " :"";
240
                            //String styleCol = interfaceBlock.isBrowseMinimizeMaximize() ? " style=\"cursor:hand; text-decoration:underline\" " :"";
241
 
242
                            String toogleAttrs = " data-toggle=\"collapse\" data-target=\"#" + idChilds + "\" " ;
243
                            String styleCol = " style=\"cursor:hand; text-decoration:underline\" ";
244
                            String folderIcon = !interfaceBlock.isTree() && interfaceBlock.isBrowseMinimizeMaximize() ? " glyphicon-plus " : " glyphicon-minus ";
245
 
246
 
247
                        %>
1703 jmachado 248
                        <div class="repository-block">
1755 jmachado 249
                            <div class="repository-intro" <%=toogleAttrs%>>
1703 jmachado 250
                                <logic:equal value="true" name="interfaceBlock" property="showTitle">
1755 jmachado 251
 
1703 jmachado 252
                                    <div class="repository-title">
1755 jmachado 253
                                        <span class="btn-xs glyphicon <%=folderIcon%>" style="margin-right: 5px"></span>
1703 jmachado 254
                                        <span class="btn-xs glyphicon glyphicon-bookmark"></span>
1755 jmachado 255
                                        <label <%=styleCol%>>${interfaceBlock.title}</label>
1703 jmachado 256
                                    </div>
257
                                </logic:equal>
1725 jmachado 258
 
1758 jmachado 259
                                <baco:hasRole role="admin,all,repositoryDocs,repositoryDeposit">
1717 jmachado 260
                                    <logic:notEmpty name="interfaceBlock" property="collectionIds">
261
                                        <%
1725 jmachado 262
                                            if(collections != null && collections.size() == 1 && !interfaceBlock.isTree())
1717 jmachado 263
                                            {
264
                                                request.setAttribute("colToAdd",collections.get(0));
265
                                        %>
266
                                        <html:link styleClass="btn btn-xs btn-success pull-right" action="/user/repositoryEditDocument?repositoryCollectionId=${colToAdd}" target="_blank">
267
                                            <span class="glyphicon glyphicon-plus"></span>
268
                                        </html:link>
269
                                        <%
270
                                            }
1758 jmachado 271
                                            else if(collections != null && collections.size() == 1 && interfaceBlock.isTree())
272
                                            {
1717 jmachado 273
                                        %>
1758 jmachado 274
                                        <html:link styleClass="btn btn-success pull-right" action="/user/repositoryEditDocument?repositoryCollectionId=${colToAdd}" target="_blank">
275
                                            <span class="glyphicon glyphicon-plus"> na Raiz da Colecção</span>
276
                                        </html:link>
277
                                        <%
278
                                            }
279
                                        %>
1717 jmachado 280
                                    </logic:notEmpty>
281
                                </baco:hasRole>
1703 jmachado 282
                                <logic:equal value="true" name="interfaceBlock" property="showDescription">
283
                                    <div class="repository-description">
284
                                            ${interfaceBlock.description}
285
                                    </div>
286
                                </logic:equal>
287
                            </div>
1755 jmachado 288
                            <div id="<%=idChilds%>" <%=!interfaceBlock.isTree() && interfaceBlock.isBrowseMinimizeMaximize() ? " class=\"repository-block-childs collapse\"" :" class=\"repository-block-childs collapse in \" "%>>
1703 jmachado 289
                            <%!
290
 
291
                                public Criterion getAllCollectionsClauses(Long collectionId)
292
                                {
293
                                    Criterion c;
294
                                    RepositoryDocumentCollection col = DaoFactory.getRepositoryDocumentCollectionDaoImpl().load(collectionId);
295
                                    c = eq("collection.id",col.getId());
296
                                    if( col.getChilds() != null &&  col.getChilds().size() > 0)
297
                                    {
298
                                        for(RepositoryDocumentCollection child: col.getChilds())
299
                                        {
300
                                            Criterion cChilds = getAllCollectionsClauses(child.getId());
301
                                            if(cChilds != null)
302
                                                c = or(c,cChilds);
303
                                        }
304
                                    }
305
                                    return c;
306
                                }
307
 
1755 jmachado 308
                                %>
309
                                <%
1703 jmachado 310
 
1692 jmachado 311
 
312
 
1675 jmachado 313
 
1703 jmachado 314
 
1714 jmachado 315
 
1755 jmachado 316
                                    if(!interfaceBlock.isTree())
1675 jmachado 317
                                    {
1755 jmachado 318
                                        Criteria c = AbstractDao.getCurrentSession().createCriteria(RepositoryDocument.class);
319
                                        Criterion clauses = null;
320
                                        for(Long collection : collections)
1703 jmachado 321
                                        {
1755 jmachado 322
                                            Criterion clausesCol = getAllCollectionsClauses(collection);
323
                                            if(clauses == null)
324
                                                clauses = clausesCol;
325
                                            else
326
                                            {
327
                                                clauses = or(clauses,clausesCol);
328
                                            }
1703 jmachado 329
                                        }
1755 jmachado 330
                                        c.add(clauses);
331
                                        c.add(eq("visible",true));
332
                                        if(interfaceBlock.getOrderBy() == InterfaceBlock.Order.publishDateAsc)
333
                                            c.addOrder(Order.asc("publishDate"));
334
                                        else if(interfaceBlock.getOrderBy() == InterfaceBlock.Order.publishDateDesc)
335
                                            c.addOrder(Order.desc("publishDate"));
336
                                        else if(interfaceBlock.getOrderBy() == InterfaceBlock.Order.saveDateAsc)
337
                                            c.addOrder(Order.asc("saveDate"));
338
                                        else if(interfaceBlock.getOrderBy() == InterfaceBlock.Order.saveDateDesc)
339
                                            c.addOrder(Order.desc("saveDate"));
340
                                        else if(interfaceBlock.getOrderBy() == InterfaceBlock.Order.updateDateAsc)
341
                                            c.addOrder(Order.desc("updateDate"));
342
                                        else if(interfaceBlock.getOrderBy() == InterfaceBlock.Order.updateDateDesc)
343
                                            c.addOrder(Order.desc("updateDate"));
344
                                        else if(interfaceBlock.getOrderBy() == InterfaceBlock.Order.title)
345
                                            c.addOrder(Order.asc("title"));
1711 jmachado 346
 
1755 jmachado 347
                                        if(interfaceBlock.getMaxPublishDate() != null && interfaceBlock.getMaxPublishDate().getTime() > 0)
348
                                        {
349
                                            c.add(le("publishDate", interfaceBlock.getMaxPublishDate()));
350
                                        }
351
                                        if(interfaceBlock.getMinPublishDate() != null && interfaceBlock.getMinPublishDate().getTime() > 0)
352
                                        {
353
                                            c.add(ge("publishDate", interfaceBlock.getMinPublishDate()));
354
                                        }
355
                                        List<RepositoryDocument> documents = c.list();
356
                                        request.setAttribute("documents",documents);
357
                                        request.setAttribute("interfaceBlock",interfaceBlock);
1692 jmachado 358
 
1755 jmachado 359
                                        %>
360
                                        <jsp:include page="showInterfaceDocsFragment.jsp"/>
361
                                        <%
1703 jmachado 362
 
1755 jmachado 363
                                    }
364
                                    else
1703 jmachado 365
                                    {
1755 jmachado 366
                                        for(Long collection : collections)
1703 jmachado 367
                                        {
1755 jmachado 368
                                            RepositoryDocumentCollection col = DaoFactory.getRepositoryDocumentCollectionDaoImpl().get(collection);
369
                                            for(RepositoryDocumentCollection child: col.getChilds())
370
                                            {
371
                                                request.setAttribute("collection",child);
372
                                                request.setAttribute("interfaceBlock",interfaceBlock);
373
                                                %>
374
                                                <jsp:include page="showInterfaceColFragment.jsp"/>
375
                                                <%
376
                                            }
1703 jmachado 377
                                        }
378
                                    }
1755 jmachado 379
                                %>
380
                            </div>
1675 jmachado 381
                        </div>
1692 jmachado 382
                    </nested:iterate>
1675 jmachado 383
 
1692 jmachado 384
                </div>
385
            </nested:iterate>
386
        </div>
387
    </nested:iterate>
388
 
1675 jmachado 389
</div>
390
 
391
<%
1759 jmachado 392
    AbstractDao.getCurrentSession().getTransaction().rollback();
1675 jmachado 393
%>