Ejemplo n.º 1
0
        public static IDictionary <ToolbarActionNames, string> GetMoreActionsMenu(this View view, string guid, TableViewer tableViewer, UrlHelper UrlHelper)
        {
            IDictionary <ToolbarActionNames, string> actionsMenu = new Dictionary <ToolbarActionNames, string>();

            bool isViewDisabled      = view.IsDisabled(guid);
            bool hasHistoryAction    = view.SaveHistory && tableViewer.IsEditable(view);
            bool hasExportAction     = view.ExportToCsv && !isViewDisabled;
            bool isImportable        = view.ImportFromExcel && !Durados.Web.Mvc.UI.Helpers.SecurityHelper.IsDenied(view.DenyEditRoles, view.AllowEditRoles) && !Durados.Web.Mvc.UI.Helpers.SecurityHelper.IsDenied(view.DenyCreateRoles, view.AllowCreateRoles);
            bool hasImportAction     = isImportable && !isViewDisabled;
            bool hasPrintAction      = view.Print && !isViewDisabled;
            bool hasMessagesAction   = view.HasMessages();
            bool hasCopyConfigAction = view is Durados.Config.IConfigView && Durados.Web.Mvc.UI.Helpers.SecurityHelper.IsInRole("Developer") && view.Name == "View";
            bool hasDatabaseRoles    = view is Durados.Config.IConfigView && (Durados.Web.Mvc.UI.Helpers.SecurityHelper.IsInRole("Developer") || Durados.Web.Mvc.UI.Helpers.SecurityHelper.IsInRole("Admin")) && (view.Name == "Database" || view.Name == "View");
            bool hasDiagnoseAction   = view is Durados.Config.IConfigView && Durados.Web.Mvc.UI.Helpers.SecurityHelper.IsInRole("Developer") && (view.Name == "Database" || view.Name == "View");
            bool hasSyncAllAction    = view is Durados.Config.IConfigView && (Durados.Web.Mvc.UI.Helpers.SecurityHelper.IsInRole("Developer") || Durados.Web.Mvc.UI.Helpers.SecurityHelper.IsInRole("Admin")) && (view.Name == "View");

            if (hasHistoryAction)
            {
                string historyGuid = "History_" + ShortGuid.Next() + "_";
                string historyUrl  = UrlHelper.Action("HistoryFilter", "History", new { viewName = "durados_v_ChangeHistory" });
                string historyView = view.Name;
                string onclick     = "History('" + historyUrl + "', '" + guid + "', '" + historyGuid + "', '" + historyView + "');return false;";
                if (view.Base.Name != null)
                {
                    historyView = view.Base.Name;
                }

                AddClickMenuItem(view, actionsMenu, ToolbarActionNames.HISTORY, onclick);
            }

            if (hasExportAction)
            {
                string iconClass = "icon export";
                string href      = view.GetExportToCsvUrl() + "?guid=" + guid;
                AddHrefMenuItem(view, actionsMenu, ToolbarActionNames.EXPORT, href, iconClass);
            }

            if (hasImportAction)
            {
                string onclick = "Excel.Import('" + view.Name + "','" + guid + "');return false;";
                AddClickMenuItem(view, actionsMenu, ToolbarActionNames.IMPORT, onclick);
            }

            if (hasPrintAction)
            {
                string onclick = "Print('" + guid + "');return false;";
                AddClickMenuItem(view, actionsMenu, ToolbarActionNames.PRINT, onclick);
            }

            if (hasMessagesAction)
            {
                string onclick = "Messages.Show('" + view.Name + "','" + guid + "');return false;";
                AddClickMenuItem(view, actionsMenu, ToolbarActionNames.MESSAGE_BOARD, onclick);
            }

            if (hasCopyConfigAction)
            {
                string onclick = "showCopyDialog('" + guid + "', this); return false;";
                AddClickMenuItem(view, actionsMenu, ToolbarActionNames.COPY_CONFIG, onclick);

                onclick = "showCloneDialog('" + guid + "'); return false;";
                AddClickMenuItem(view, actionsMenu, ToolbarActionNames.CLONE_CONFIG, onclick);
            }

            if (hasDatabaseRoles)
            {
                string sendConfigUrl = UrlHelper.Action("SendConfig", "Admin");
                string onclick       = "sendConfig('" + sendConfigUrl + "');";
                AddClickMenuItem(view, actionsMenu, ToolbarActionNames.SEND_CONFIG, onclick);

                //BR: TODO
                //<a target="_blank" href="<%= downloadConfigUrl%>" title="<%= title%>">
                //<%=Map.Database.Localizer.Translate("Download")%></a>
                string href = UrlHelper.Action("DownloadConfig", "Admin");
                AddHrefMenuItem(view, actionsMenu, ToolbarActionNames.DOWNLOAD_CONFIG, href);

                onclick = "UploadConfig.Open('Database', '" + guid + "')";
                AddClickMenuItem(view, actionsMenu, ToolbarActionNames.UPLOAD_CONFIG, onclick);
            }
            if (hasDiagnoseAction)
            {
                string onclick = "Diagnostics.Diagnose('" + guid + "');";
                AddClickMenuItem(view, actionsMenu, ToolbarActionNames.DIAGNOSE, onclick);

                string dictionaryUrl = UrlHelper.Action("Index", "Block", new { parameters = "xxx" });
                onclick = "Dictionary('" + dictionaryUrl + "', '" + guid + "');";
                AddClickMenuItem(view, actionsMenu, ToolbarActionNames.DICTIONARY, onclick);
            }

            if (hasSyncAllAction)
            {
                string onclick = "syncAll()";
                AddClickMenuItem(view, actionsMenu, ToolbarActionNames.SYNC_ALL, onclick);
            }

            return(actionsMenu);
        }