Пример #1
0
    private void gridElem_OnBeforeDataReload()
    {
        UniGridActions ug = gridElem.GridActions;

        if (ug != null)
        {
            // Find delete
            foreach (var abstractAction in ug.Actions)
            {
                if (abstractAction is Action)
                {
                    var action = (Action)abstractAction;
                    if (String.IsNullOrEmpty(action.ExternalSourceName))
                    {
                        switch (action.Name.ToLowerCSafe())
                        {
                        case "delete":
                        case "#delete":
                            action.ExternalSourceName = "delete";
                            return;
                        }
                    }
                }
            }
        }
    }
Пример #2
0
    /// <summary>
    /// Loads the XML configuration of the grid.
    /// </summary>
    public bool LoadXmlConfiguration()
    {
        // If no configuration is given, do not process
        if (string.IsNullOrEmpty(GridName))
        {
            return true;
        }
        string xmlFilePath = Server.MapPath(GridName);

        // Check the configuration file
        if (!File.Exists(xmlFilePath))
        {
            lblError.Text = String.Format(GetString("unigrid.noxmlfile"), xmlFilePath);
            lblError.Visible = true;
            return false;
        }

        // Load the XML configuration
        XmlDocument document = new XmlDocument();
        document.Load(xmlFilePath);
        XmlNode node = document.DocumentElement;

        if (node != null)
        {
            // Load options definition
            XmlNode optionNode = node.SelectSingleNode("options");
            if (optionNode != null)
            {
                GridOptions = new UniGridOptions(optionNode);
            }

            // Load actions definition
            XmlNode actionsNode = node.SelectSingleNode("actions");
            if (actionsNode != null)
            {
                GridActions = new UniGridActions(actionsNode);
            }

            // Load pager definition
            XmlNode pagerNode = node.SelectSingleNode("pager");
            if (pagerNode != null)
            {
                PagerConfig = new UniGridPagerConfig(pagerNode);
            }

            // Select list of "column" nodes
            XmlNode columnsNode = node.SelectSingleNode("columns");
            if (columnsNode != null)
            {
                GridColumns = new UniGridColumns(columnsNode);
            }

            // Try to get ObjectType from definition
            XmlNode objectTypeNode = node.SelectSingleNode("objecttype");
            if (objectTypeNode != null)
            {
                // Get object type information
                LoadObjectTypeDefinition(objectTypeNode);
            }
            else
            {
                // Get query information
                XmlNode queryNode = node.SelectSingleNode("query");
                LoadQueryDefinition(queryNode);
            }

            return true;
        }

        return false;
    }
Пример #3
0
 /// <summary>
 /// Loads the grid definition.
 /// </summary>
 public override bool LoadGridDefinition()
 {
     if (GridView.Columns.Count == 0)
     {
         using (Table filterTable = new Table())
         {
             filter.Controls.Clear();
             // Clear all columns from the grid view
             UniGridView.Columns.Clear();
             UniGridView.GridLines = GridLines.Horizontal;
             if (!LoadXmlConfiguration())
             {
                 return false;
             }
             // Load options
             if (GridOptions != null)
             {
                 LoadOptionsDefinition(GridOptions, filterTable);
             }
             if (GridActions == null && ShowActionsMenu)
             {
                 EmptyAction emptyAction = new EmptyAction();
                 GridActions = new UniGridActions();
                 GridActions.Actions.Add(emptyAction);
             }
             // Actions
             if (GridActions != null)
             {
                 LoadActionsDefinition(GridActions);
             }
             // Load pager configuration
             if (PagerConfig != null)
             {
                 LoadPagerDefinition(PagerConfig);
             }
             // Set direct page control id from viewstate
             if (ViewState["DirectPageControlID"] != null)
             {
                 Pager.DirectPageControlID = ViewState["DirectPageControlID"].ToString();
             }
             // Raise load columns event
             RaiseLoadColumns();
             // Load columns
             if (GridColumns != null)
             {
                 foreach (Column col in GridColumns.Columns)
                 {
                     // Load column definition
                     LoadColumnDefinition(col, filterTable);
                 }
             }
             if (displayFilter)
             {
                 // Finish filter form with "Show" button
                 CreateFilterButton(filterTable);
             }
         }
     }
     return true;
 }
Пример #4
0
    /// <summary>
    /// Loads actions definition.
    /// </summary>
    /// <param name="actions">Configuration of the actions</param>
    private void LoadActionsDefinition(UniGridActions actions)
    {
        // Custom template field of the grid view
        TemplateField actionsColumn = new TemplateField();

        // Ensure width of the column
        if (!String.IsNullOrEmpty(actions.Width))
        {
            actionsColumn.ItemStyle.Width = new Unit(actions.Width);
        }

        // Add object menu if possible
        if ((actions.Actions.Count > 0 && !(actions.Actions.FirstOrDefault() is EmptyAction)) && ShowObjectMenu && UniGridFunctions.ShowUniGridObjectContextMenu(CMSObjectHelper.GetReadOnlyObject(ObjectType)))
        {
            actions.Actions.RemoveAll(a => a is EmptyAction);
            // Check if object menu already contained
            var menus = from action in actions.Actions.OfType<Action>()
                        where (action.Name.ToLower() == "#objectmenu") || (!String.IsNullOrEmpty(action.ContextMenu))
                        select action;

            // Add object menu of necessary
            if ((menus.Count() == 0) && !IsLiveSite)
            {
                Action action = new Action("#objectmenu");
                action.ExternalSourceName = "#objectmenu";
                actions.Actions.Add(action);
            }
        }

        // Show header?
        if (actions.ShowHeader)
        {
            if (ShowActionsMenu && string.IsNullOrEmpty(actions.ContextMenu))
            {
                actions.ContextMenu = DEFAULT_ACTIONS_MENU;
                actions.Caption = "General.OtherActions";
            }
            // Fill in the custom template field
            GridViewTemplate headerTemplate = new GridViewTemplate(ListItemType.Header, this, actions, GetString("unigrid.actions"), ImageDirectoryPath, DefaultImageDirectoryPath, Page);
            headerTemplate.ContextMenuParent = plcContextMenu;
            headerTemplate.CheckRelative = CheckRelative;
            actionsColumn.HeaderTemplate = headerTemplate;
            if (ShowActionsMenu)
            {
                if (actions.Actions.FirstOrDefault() is EmptyAction)
                {
                    actionsColumn.HeaderStyle.CssClass = "EmptyAC";
                }
                else
                {
                    actionsColumn.HeaderStyle.CssClass = "AC";
                }
            }
        }
        GridViewTemplate actionsTemplate = new GridViewTemplate(ListItemType.Item, this, actions, null, ImageDirectoryPath, DefaultImageDirectoryPath, Page);
        actionsTemplate.OnExternalDataBound += RaiseExternalDataBound;
        actionsTemplate.ContextMenuParent = plcContextMenu;
        actionsTemplate.CheckRelative = CheckRelative;
        actionsColumn.ItemTemplate = actionsTemplate;

        if (!IsLiveSite)
        {
            actionsColumn.ItemStyle.CssClass = "NW UniGridActions";
        }
        else
        {
            actionsColumn.ItemStyle.CssClass = "UniGridActions";
            actionsColumn.ItemStyle.Wrap = false;
        }

        // CSS class name
        string cssClass = actions.CssClass;
        if (cssClass != null)
        {
            actionsColumn.HeaderStyle.CssClass += " " + cssClass;
            actionsColumn.ItemStyle.CssClass += " " + cssClass;
            actionsColumn.FooterStyle.CssClass += " " + cssClass;
        }

        // Add custom column to grid view
        UniGridView.Columns.Add(actionsColumn);
    }
    /// <summary>
    /// Loads the grid definition.
    /// </summary>
    public override bool LoadGridDefinition()
    {
        if (GridView.Columns.Count == 0)
        {
            using (Panel filterPanel = new Panel())
            {
                filterPanel.CssClass = "form-horizontal form-filter";
                plcFilter.Controls.Clear();

                // Clear all columns from the grid view
                GridView.Columns.Clear();
                if (!LoadXmlConfiguration())
                {
                    return false;
                }
                // Load options
                if (GridOptions != null)
                {
                    LoadOptionsDefinition(GridOptions, filterPanel);
                }
                if ((GridActions == null) && ShowActionsMenu)
                {
                    EmptyAction emptyAction = new EmptyAction();
                    GridActions = new UniGridActions();
                    GridActions.Actions.Add(emptyAction);
                }
                // Actions
                if (GridActions != null)
                {
                    LoadActionsDefinition(GridActions);
                }
                // Load pager configuration
                if (PagerConfig != null)
                {
                    LoadPagerDefinition(PagerConfig);
                }

                // Raise load columns event
                RaiseLoadColumns();
                // Load columns
                if (GridColumns != null)
                {
                    foreach (Column col in GridColumns.Columns)
                    {
                        col.DataBind();

                        // Load column definition
                        LoadColumnDefinition(col, filterPanel);
                    }
                }
                if (displayFilter)
                {
                    // Finish filter form with "Show" button
                    CreateFilterButton(filterPanel);
                }
            }
        }
        return true;
    }