mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Refactoring the Grid layout so it's compatible with grid systems using <div>
Required Change: All previous layouts based on Grid will have to set table/tr/td to behave as the previous version. The tags are no more set by default. --HG-- branch : 1.x
This commit is contained in:
@@ -42,16 +42,25 @@ namespace Orchard.Projections.Providers.Layouts {
|
||||
public dynamic RenderLayout(LayoutContext context, IEnumerable<LayoutComponentResult> layoutComponentResults) {
|
||||
int columns = Convert.ToInt32(context.State.Columns);
|
||||
bool horizontal = Convert.ToString(context.State.Alignment) != "vertical";
|
||||
string rowClass = context.State.RowClass;
|
||||
string gridClass = context.State.GridClass;
|
||||
string gridId = context.State.GridId;
|
||||
|
||||
string gridTag = Convert.ToString(context.State.GridTag);
|
||||
string gridClass = Convert.ToString(context.State.GridClass);
|
||||
string gridId = Convert.ToString(context.State.GridId);
|
||||
|
||||
string rowTag = Convert.ToString(context.State.RowTag);
|
||||
string rowClass = Convert.ToString(context.State.RowClass);
|
||||
|
||||
string cellTag = Convert.ToString(context.State.CellTag);
|
||||
string cellClass = Convert.ToString(context.State.CellClass);
|
||||
|
||||
string emptyCell = Convert.ToString(context.State.EmptyCell);
|
||||
|
||||
IEnumerable<dynamic> shapes =
|
||||
context.LayoutRecord.Display == (int)LayoutRecord.Displays.Content
|
||||
? layoutComponentResults.Select(x => _contentManager.BuildDisplay(x.ContentItem, context.LayoutRecord.DisplayType))
|
||||
: layoutComponentResults.Select(x => x.Properties);
|
||||
|
||||
return Shape.Grid(Id: gridId, Horizontal: horizontal, Columns: columns, Items: shapes, Classes: new [] { gridClass }, RowClasses: new [] { rowClass });
|
||||
return Shape.Grid(Id: gridId, Horizontal: horizontal, Columns: columns, Items: shapes, Tag: gridTag, Classes: new[] { gridClass }, RowTag: rowTag, RowClasses: new[] { rowClass }, CellTag: cellTag, CellClasses: new[] { cellClass }, EmptyCell: emptyCell);
|
||||
}
|
||||
}
|
||||
}
|
@@ -43,24 +43,54 @@ namespace Orchard.Projections.Providers.Layouts {
|
||||
)
|
||||
),
|
||||
_HtmlProperties: Shape.Fieldset(
|
||||
Title: T("Html properties"),
|
||||
_ListId: Shape.TextBox(
|
||||
Title: T("Html properties"),
|
||||
_GridTag: Shape.TextBox(
|
||||
Id: "grid-tag", Name: "GridTag",
|
||||
Title: T("Grid tag"),
|
||||
Description: T("The tag of the grid. Leave empty for no tag. (e.g., table)"),
|
||||
Classes: new[] { "textMedium", "tokenized" }
|
||||
),
|
||||
_GridId: Shape.TextBox(
|
||||
Id: "grid-id", Name: "GridId",
|
||||
Title: T("Grid id"),
|
||||
Description: T("The id to provide on the table element."),
|
||||
Description: T("The id to provide on the grid element."),
|
||||
Classes: new[] { "textMedium", "tokenized" }
|
||||
),
|
||||
_ListClass: Shape.TextBox(
|
||||
_GridClass: Shape.TextBox(
|
||||
Id: "grid-class", Name: "GridClass",
|
||||
Title: T("Grid class"),
|
||||
Description: T("The class to provide on the table element."),
|
||||
Description: T("The class to provide on the grid element."),
|
||||
Classes: new[] { "textMedium", "tokenized" }
|
||||
),
|
||||
_ItemClass: Shape.TextBox(
|
||||
_RowTag: Shape.TextBox(
|
||||
Id: "row-tag", Name: "RowTag",
|
||||
Title: T("Row tag"),
|
||||
Description: T("The tag of a row. Leave empty for no tag. (e.g., tr)"),
|
||||
Classes: new[] { "textMedium", "tokenized" }
|
||||
),
|
||||
_RowClass: Shape.TextBox(
|
||||
Id: "row-class", Name: "RowClass",
|
||||
Title: T("Row class"),
|
||||
Description: T("The class to provide on each row."),
|
||||
Classes: new[] { "textMedium", "tokenized" }
|
||||
),
|
||||
_CellTag: Shape.TextBox(
|
||||
Id: "cell-tag", Name: "CellTag",
|
||||
Title: T("Cell tag"),
|
||||
Description: T("The tag of a cell. Leave empty for no tag. (e.g., td)"),
|
||||
Classes: new[] { "textMedium", "tokenized" }
|
||||
),
|
||||
_CellClass: Shape.TextBox(
|
||||
Id: "cell-class", Name: "CellClass",
|
||||
Title: T("Cell class"),
|
||||
Description: T("The class to provide on each cell."),
|
||||
Classes: new[] { "textMedium", "tokenized" }
|
||||
),
|
||||
_EmptyCell: Shape.TextBox(
|
||||
Id: "empty-cell", Name: "EmptyCell",
|
||||
Title: T("Empty Cell"),
|
||||
Description: T("The HTML to render as empty cells to fill a row. (e.g., <td> </td>"),
|
||||
Classes: new[] { "textMedium", "tokenized" }
|
||||
)
|
||||
)
|
||||
);
|
||||
|
@@ -3,12 +3,8 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Mvc.Html;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Mvc.Html;
|
||||
using Orchard.Utility.Extensions;
|
||||
|
||||
namespace Orchard.Projections.Providers.Layouts {
|
||||
public class LayoutShapes : IDependency {
|
||||
@@ -19,7 +15,7 @@ namespace Orchard.Projections.Providers.Layouts {
|
||||
public Localizer T { get; set; }
|
||||
|
||||
[Shape]
|
||||
public void Grid(dynamic Display, TextWriter Output, HtmlHelper Html, string Id, bool Horizontal, IEnumerable<dynamic> Items, int Columns, IEnumerable<string> Classes, IDictionary<string, string> Attributes, IEnumerable<string> RowClasses, IDictionary<string, string> RowAttributes, IEnumerable<string> CellClasses, IDictionary<string, string> CellAttributes) {
|
||||
public void Grid(dynamic Display, TextWriter Output, HtmlHelper Html, string Id, bool Horizontal, IEnumerable<dynamic> Items, int Columns, string Tag, IEnumerable<string> Classes, IDictionary<string, string> Attributes, string RowTag, IEnumerable<string> RowClasses, IDictionary<string, string> RowAttributes, string CellTag, IEnumerable<string> CellClasses, IDictionary<string, string> CellAttributes, string EmptyCell) {
|
||||
if (Items == null)
|
||||
return;
|
||||
|
||||
@@ -28,12 +24,14 @@ namespace Orchard.Projections.Providers.Layouts {
|
||||
|
||||
if (itemsCount < 1)
|
||||
return;
|
||||
|
||||
var gridTag = GetTagBuilder("table", Id, Classes, Attributes);
|
||||
var rowTag = GetTagBuilder("tr", string.Empty, RowClasses, RowAttributes);
|
||||
var cellTag = GetTagBuilder("td", string.Empty, CellClasses, CellAttributes);
|
||||
|
||||
Output.Write(gridTag.ToString(TagRenderMode.StartTag));
|
||||
var gridTag = String.IsNullOrEmpty(Tag) ? null : GetTagBuilder(Tag, Id, Classes, Attributes);
|
||||
var rowTag = String.IsNullOrEmpty(RowTag) ? null : GetTagBuilder(RowTag, string.Empty, RowClasses, RowAttributes);
|
||||
var cellTag = String.IsNullOrEmpty(CellTag) ? null : GetTagBuilder(CellTag, string.Empty, CellClasses, CellAttributes);
|
||||
|
||||
if (gridTag != null) {
|
||||
Output.Write(gridTag.ToString(TagRenderMode.StartTag));
|
||||
}
|
||||
|
||||
// resolves which item to display in a specific cell
|
||||
Func<int, int, int> seekItem = (row, col) => row*Columns + col;
|
||||
@@ -47,24 +45,39 @@ namespace Orchard.Projections.Providers.Layouts {
|
||||
}
|
||||
|
||||
for(int row=0; row < maxRows; row++) {
|
||||
Output.Write(rowTag.ToString(TagRenderMode.StartTag));
|
||||
|
||||
if (rowTag != null) {
|
||||
Output.Write(rowTag.ToString(TagRenderMode.StartTag));
|
||||
}
|
||||
|
||||
for (int col = 0; col < maxCols; col++) {
|
||||
int index = seekItem(row, col);
|
||||
Output.Write(cellTag.ToString(TagRenderMode.StartTag));
|
||||
|
||||
if (cellTag != null) {
|
||||
Output.Write(cellTag.ToString(TagRenderMode.StartTag));
|
||||
}
|
||||
|
||||
if (index < itemsCount) {
|
||||
Output.Write(Display(items[index]));
|
||||
}
|
||||
else {
|
||||
// fill an empty cell
|
||||
Output.Write(" ");
|
||||
Output.Write(EmptyCell);
|
||||
}
|
||||
|
||||
Output.Write(cellTag.ToString(TagRenderMode.EndTag));
|
||||
if (cellTag != null) {
|
||||
Output.Write(cellTag.ToString(TagRenderMode.EndTag));
|
||||
}
|
||||
}
|
||||
|
||||
if (rowTag != null) {
|
||||
Output.Write(rowTag.ToString(TagRenderMode.EndTag));
|
||||
}
|
||||
Output.Write(rowTag.ToString(TagRenderMode.EndTag));
|
||||
}
|
||||
|
||||
Output.Write(gridTag.ToString(TagRenderMode.EndTag));
|
||||
if (gridTag != null) {
|
||||
Output.Write(gridTag.ToString(TagRenderMode.EndTag));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static TagBuilder GetTagBuilder(string tagName, string id, IEnumerable<string> classes, IDictionary<string, string> attributes) {
|
||||
|
Reference in New Issue
Block a user