-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathCardController.cs
More file actions
167 lines (147 loc) · 4.65 KB
/
CardController.cs
File metadata and controls
167 lines (147 loc) · 4.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Telerik.Sitefinity.Frontend.Card.Mvc.Models.Card;
using Telerik.Sitefinity.Frontend.Card.Mvc.StringResources;
using Telerik.Sitefinity.Frontend.Mvc.Infrastructure.Controllers;
using Telerik.Sitefinity.Frontend.Mvc.Infrastructure.Controllers.Attributes;
using Telerik.Sitefinity.Localization;
using Telerik.Sitefinity.Modules.Pages.Configuration;
using Telerik.Sitefinity.Mvc;
using Telerik.Sitefinity.Personalization;
using Telerik.Sitefinity.Services;
using Telerik.Sitefinity.Web.UI;
namespace Telerik.Sitefinity.Frontend.Card.Mvc.Controllers
{
/// <summary>
/// This class represents the controller of the Card widget.
/// </summary>
[Localization(typeof(CardResources))]
[ControllerToolboxItem(
Name = CardController.WidgetName,
Title = nameof(CardResources.CardWidgetTitle),
Description = nameof(CardResources.CardWidgetDescription),
ResourceClassId = nameof(CardResources),
SectionName = ToolboxesConfig.ContentToolboxSectionName,
CssClass = CardController.WidgetIconCssClass)]
public class CardController : Controller, ICustomWidgetVisualizationExtended, IPersonalizable
{
#region Properties
/// <summary>
/// Gets the Card widget model.
/// </summary>
/// <value>
/// The model.
/// </value>
[TypeConverter(typeof(ExpandableObjectConverter))]
public virtual ICardModel Model
{
get
{
if (this.model == null)
this.model = ControllerModelFactory.GetModel<ICardModel>(this.GetType());
return this.model;
}
}
/// <summary>
/// Gets or sets the name of the template that widget will be displayed.
/// </summary>
/// <value></value>
public string TemplateName
{
get
{
return this.templateName;
}
set
{
this.templateName = value;
}
}
/// <summary>
/// Gets a value indicating whether widget is empty.
/// </summary>
/// <value>
/// <c>true</c> if widget has no image selected; otherwise, <c>false</c>.
/// </value>
[Browsable(false)]
public bool IsEmpty
{
get
{
return this.Model.IsEmpty();
}
}
/// <inheritdoc />
public string WidgetCssClass
{
get
{
return WidgetIconCssClass;
}
}
/// <inheritdoc />
public string EmptyLinkText
{
get
{
return Res.Get<CardResources>().CreateContent;
}
}
/// <summary>
/// Gets the is design mode.
/// </summary>
/// <value>The is design mode.</value>
protected virtual bool IsDesignMode
{
get
{
return SystemManager.IsDesignMode;
}
}
/// <summary>
/// Gets the image was not selected or has been deleted message.
/// </summary>
/// <value>The image was not selected or has been deleted message.</value>
protected virtual string ImageWasNotSelectedOrHasBeenDeletedMessage
{
get
{
return Res.Get<CardResources>().ImageWasNotSelectedOrHasBeenDeleted;
}
}
#endregion
#region Actions
/// <summary>
/// Renders appropriate list view depending on the <see cref="ListTemplateName" />
/// </summary>
/// <param name="page">The page.</param>
/// <returns>
/// The <see cref="ActionResult" />.
/// </returns>
public ActionResult Index()
{
if (this.IsEmpty)
{
return new EmptyResult();
}
var viewModel = this.Model.GetViewModel();
return this.View(this.TemplateName, viewModel);
}
/// <inheritDoc/>
protected override void HandleUnknownAction(string actionName)
{
this.ActionInvoker.InvokeAction(this.ControllerContext, "Index");
}
#endregion
#region Private fields and constants
internal const string WidgetIconCssClass = "sfCardIcn sfMvcIcn";
private ICardModel model;
private string templateName = "Card";
private const string WidgetName = "Card_MVC";
#endregion
}
}