<|start_filename|>RelatosdeSeguranca/RelatosdeSeguranca/RelatosdeSeguranca.Web/Modules/Common/Reporting/DynamicDataReport.cs<|end_filename|>
﻿using Serenity.ComponentModel;
using Serenity.Data;
using Serenity.PropertyGrid;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace Serenity.Reporting
{
    public class DynamicDataReport : IDataOnlyReport
    {
        public IEnumerable Data { get; private set; }
        public IEnumerable<string> ColumnList { get; set; }
        public Type ColumnsType { get; private set; }

        public DynamicDataReport(IEnumerable data, IEnumerable<string> columnList, Type columnsType)
        {
            if (data == null)
                throw new ArgumentNullException("data");

            this.Data = data;
            this.ColumnList = columnList ?? new List<string>();
            this.ColumnsType = columnsType;
        }

        public object GetData()
        {
            return Data;
        }

        public List<ReportColumn> GetColumnList()
        {
            var list = new List<ReportColumn>();

            if (!ColumnList.Any())
                return list;

            IDictionary<string, PropertyItem> propertyItems = null;
            IDictionary<string, PropertyInfo> propertyInfos = null;
            Row basedOnRow = null;

            if (ColumnsType != null)
            {
                propertyItems = LocalCache.Get("DynamicDataReport:Columns:" + ColumnsType.FullName, TimeSpan.Zero,
                    () => PropertyItemHelper.GetPropertyItemsFor(ColumnsType).ToDictionary(x => x.Name));

                propertyInfos = ColumnsType.GetProperties().ToDictionary(x => x.Name);

                var basedOnAttr = ColumnsType.GetCustomAttribute<BasedOnRowAttribute>();
                if (basedOnAttr != null && 
                    basedOnAttr.RowType != null && 
                    typeof(Row).IsAssignableFrom(basedOnAttr.RowType))
                {
                    basedOnRow = (Row)Activator.CreateInstance(basedOnAttr.RowType);
                }
            }

            foreach (var columnName in ColumnList)
            {
                PropertyItem item;
                if (!propertyItems.TryGetValue(columnName, out item))
                    continue;

                var basedOnField = basedOnRow == null ? (Field)null :
                    (basedOnRow.FindField(columnName) ?? basedOnRow.FindFieldByPropertyName(columnName));

                PropertyInfo p;
                if (propertyInfos == null || !propertyInfos.TryGetValue(columnName, out p))
                    p = null;

                list.Add(FromPropertyItem(item, basedOnField, p));
            }

            return list;
        }

        private ReportColumn FromPropertyItem(PropertyItem item, Field field, PropertyInfo property)
        {
            var result = new ReportColumn();
            result.Name = item.Name;
            result.Title = item.Title ?? item.Name;
            if (result.Title != null)
                result.Title = LocalText.TryGet(result.Title) ?? result.Title;

            if (item.Width != null)
                result.Width = item.Width;

            if (!string.IsNullOrWhiteSpace(item.DisplayFormat))
                result.Format = item.DisplayFormat;
            else
            {
                var dtf = field as DateTimeField;
                if (!ReferenceEquals(null, dtf) &&
                    dtf.DateTimeKind != DateTimeKind.Unspecified)
                {
                    result.Format = "dd/MM/yyyy HH:mm";
                }
                else if (!ReferenceEquals(null, dtf))
                {
                    result.Format = "dd/MM/yyyy";
                }
            }

            var enumField = field as IEnumTypeField;
            if (enumField != null && enumField.EnumType != null)
            {
                result.Decorator = new EnumDecorator(enumField.EnumType);
            }

            if (property != null)
            {
                var decorator = property.GetCustomAttribute<CellDecoratorAttribute>();
                if (decorator != null && decorator.DecoratorType != null)
                    result.Decorator = (ICellDecorator)Activator.CreateInstance(decorator.DecoratorType);
            }

            if (!ReferenceEquals(null, field))
            {
                if (result.Title == null)
                    result.Title = field.Title;

                if (result.Width == null && field is StringField && field.Size != 0)
                    result.Width = field.Size;
            }

            result.DataType = !ReferenceEquals(null, field) ? field.ValueType : null;

            return result;
        }
    }
}

<|start_filename|>RelatosdeSeguranca/RelatosdeSeguranca/RelatosdeSeguranca.Web/Scripts/jquery.dialogextendQ.js<|end_filename|>
﻿$.widget("ui.dialogExtend", {
    options: {
        "dblclick": true,
        "load": null,
        "beforeRestore": null,
        "restore": null,
        "maximizable": false,
        "beforeMaximize": null,
        "maximize": null
    },
    _create: function () {
        this._state = "normal";
        this._initButtons();
        this._setState("normal");
        return this._trigger("load");
    },
    _setState: function (state) {
        this.element.removeClass("ui-dialog-" + this._state).addClass("ui-dialog-" + state);
        return this._state = state;
    },
    _initButtons: function () {
        var _this = this;

        this._addButton("maximize", this.options.maximizable, Q.text('Dialogs.MaximizeHint'), "fa fa-window-maximize");
        this._addButton("restore", false, Q.text('Dialogs.RestoreHint'), "fa fa-window-restore");

        var titlebar = this.element.closest('.ui-dialog').children('.ui-dialog-titlebar');
        titlebar.dblclick(function (evt) {
            if (_this.options.dblclick) {
                if (_this._state !== "normal") {
                    return _this.restore();
                } else {
                    return _this[_this.options.dblclick]();
                }
            }
        }).select(function () {
            return false;
        });
    },
    _addButton: function (name, show, hint, icon) {
        var _this = this;

        var titlebar = this.element.closest('.ui-dialog').children('.ui-dialog-titlebar');
        var closeButton = titlebar.find('.ui-dialog-titlebar-close').first();
        var button = $('<button class="ui-button ui-corner-all ui-button-icon-only ui-dialog-titlebar-'
            + name + '" href="javascript:;" tabindex="-1"><i class="' + icon + '"></i></a>')
            .attr('title', hint)
            .toggle(show)
            .click(function (e) {
                e.preventDefault();
                return _this[name]();
            });

        if (closeButton)
            button.insertBefore(closeButton);
        else
            button.appendTo(titlebar);

        return button;
    },
    maximize: function () {
        var newHeight, newWidth;

        newHeight = $(window).height() - 1;
        newWidth = $(window).width() - 1;
        this._trigger("beforeMaximize");
        if (this._state !== "normal") {
            this._restore();
        }
        this._saveSnapshot();
        if ($(this.element[0]).dialog("option", "draggable")) {
            $(this.element[0]).dialog("widget").draggable("option", "handle", null).find(".ui-dialog-draggable-handle").css("cursor", "text").end();
        }
        $(this.element[0]).dialog("widget").css("position", "fixed").find(".ui-dialog-content").show().dialog("widget").find(".ui-dialog-buttonpane").show().end().find(".ui-dialog-content").dialog("option", {
            "resizable": false,
            "draggable": false,
            "height": newHeight,
            "width": newWidth,
            "position": {
                of: window,
                my: "left top",
                at: "left top"
            }
        });
        this._setState("maximized");
        this._toggleButtons();

        if (this.original_config_resizable)
            this.element.closest('.ui-dialog').triggerHandler("resize");

        return this._trigger("maximize");
    },
    _restore_maximized: function () {
        var original;

        original = this._loadSnapshot();
        $(this.element[0]).dialog("widget").css("position", original.position.mode).find(".ui-dialog-titlebar").css("white-space", original.titlebar.wrap).end().find(".ui-dialog-content").dialog("option", {
            "resizable": original.config.resizable,
            "draggable": original.config.draggable,
            "height": original.size.height,
            "width": original.size.width,
            "maxHeight": original.size.maxHeight,
            "position": {
                of: window,
                my: "left top",
                at: "left+" + original.position.left + " top+" + original.position.top
            }
        });
        if ($(this.element[0]).dialog("option", "draggable")) {
            return $(this.element[0]).dialog("widget").draggable("option", "handle", $(this.element[0]).dialog("widget").find(".ui-dialog-draggable-handle").length ? $(this.element[0]).dialog("widget").find(".ui-dialog-draggable-handle") : ".ui-dialog-titlebar").find(".ui-dialog-draggable-handle").css("cursor", "move");
        }
    },
    state: function () {
        return this._state;
    },
    restore: function () {
        this._trigger("beforeRestore");
        this._restore();
        this._setState("normal");
        this._toggleButtons();

        if (this.original_config_resizable)
            this.element.closest('.ui-dialog').triggerHandler("resize");

        return this._trigger("restore");
    },
    _restore: function () {
        if (this._state !== "normal") {
            return this["_restore_" + this._state]();
        }
    },
    _saveSnapshot: function () {
        if (this._state === "normal") {
            this.original_config_resizable = $(this.element[0]).dialog("option", "resizable");
            this.original_config_draggable = $(this.element[0]).dialog("option", "draggable");
            this.original_size_height = $(this.element[0]).dialog("widget").outerHeight();
            this.original_size_width = $(this.element[0]).dialog("option", "width");
            this.original_size_maxHeight = $(this.element[0]).dialog("option", "maxHeight");
            this.original_position_mode = $(this.element[0]).dialog("widget").css("position");
            this.original_position_left = $(this.element[0]).dialog("widget").offset().left - $('body').scrollLeft();
            this.original_position_top = $(this.element[0]).dialog("widget").offset().top - $('body').scrollTop();
            return this.original_titlebar_wrap = $(this.element[0]).dialog("widget").find(".ui-dialog-titlebar").css("white-space");
        }
    },
    _loadSnapshot: function () {
        return {
            "config": {
                "resizable": this.original_config_resizable,
                "draggable": this.original_config_draggable
            },
            "size": {
                "height": this.original_size_height,
                "width": this.original_size_width,
                "maxHeight": this.original_size_maxHeight
            },
            "position": {
                "mode": this.original_position_mode,
                "left": this.original_position_left,
                "top": this.original_position_top
            },
            "titlebar": {
                "wrap": this.original_titlebar_wrap
            }
        };
    },
    _toggleButtons: function () {
        var uiDialog = this.element.closest('.ui-dialog');
        uiDialog.find(".ui-dialog-titlebar-restore").toggle(this._state !== "normal");
        uiDialog.find(".ui-dialog-titlebar-maximize").toggle(this._state !== "maximized");
    }
});

<|start_filename|>RelatosdeSeguranca/RelatosdeSeguranca/RelatosdeSeguranca.Web/Scripts/serenity/Serenity.Script.UI.min.js<|end_filename|>
﻿(function() {
	'use strict';
	var $asm = {};
	ss.initAssembly($asm, 'Serenity.Script.UI');
})();


<|start_filename|>RelatosdeSeguranca/RelatosdeSeguranca/RelatosdeSeguranca.Web/Views/Shared/_LayoutSlimHead.cshtml<|end_filename|>
﻿
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<link rel="home" id="ApplicationPath" href="~/" />
<link rel="icon" type="image/x-icon" href="~/favicon.ico" />
@Html.StyleBundle("Base")
@if (System.Globalization.CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft)
{
    @Html.Stylesheet("~/Content/site/site.rtl.css")
}
@*{var cookie = Request.Cookies["ThemePreference"]; var theme = cookie != null && !cookie.Value.IsEmptyOrNull() ? cookie.Value : "default"; *}*@
<script type="application/json" id="ScriptCulture">
    @Html.Raw(Serenity.JSON.Stringify(new ScriptCulture()))
</script>
@Html.ScriptBundle("Base")

<|start_filename|>RelatosdeSeguranca/RelatosdeSeguranca/RelatosdeSeguranca.Web/Views/Errors/AccessDenied.cshtml<|end_filename|>
﻿@model string

@{
    ViewData["Title"] = Texts.Site.AccessDenied.PageTitle;
    ViewData["PageId"] = "AccessDenied";
    Layout = Serenity.Authorization.IsLoggedIn ?
        "~/Views/Shared/_Layout.cshtml" :
        "~/Views/Shared/_LayoutNoNavigation.cshtml";
}

<div class="page-content">
    <div class="message">
        <table>
            <tr>
                <td style="width: 200px;">
                    <i class="fa fa-times-circle text-red" style="font-size: 180px;"></i>
                </td>
                <td>
                    <h1>@Texts.Site.AccessDenied.PageTitle</h1>
                    <h3>@(Serenity.Authorization.IsLoggedIn ? Texts.Site.AccessDenied.LackPermissions : Texts.Site.AccessDenied.NotLoggedIn)</h3>
                    @if (Model != null)
                    {
                        <a class="redirect" href="/Account/Login?returnURL=@Model">@(Serenity.Authorization.IsLoggedIn ? 
                            Texts.Site.AccessDenied.ClickToChangeUser : Texts.Site.AccessDenied.ClickToLogin)</a>
                    }
                    else
                    {
                        <a class="redirect" href="/Account/Login">@Texts.Site.AccessDenied.ClickToLogin</a>
                    }
                    <div class="date-time">
                        @(!Serenity.Authorization.IsLoggedIn ? "" : (Serenity.Authorization.Username + " - "))@DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
                    </div>
                    <div class="clear"></div>
                </td>
            </tr>
        </table>
        
    </div>
</div>