or
<
div
data-role
=
"view"
id
=
"share"
data-layout
=
"default"
class
=
"share-view"
data-init
=
"app.viewModels.editYFKey.init"
data-show
=
"app.viewModels.editYFKey.show"
data-model
=
"app.viewModels.editYFKey"
>
<
header
data-role
=
"header"
>...
</
header
>
<
div
id
=
"enterStatus"
class
=
"user-status-wrp"
style
=
"background-color: white; height:100%;"
>
<
div
class
=
"user-share"
style
=
"width:100%;"
>
<
span
id
=
"YFKeyEdit_NameLabel"
style
=
"width: 98%; text-align: center;"
><
b
>Name:</
b
></
span
><
br
/>
<
input
id
=
"YFKeyEdit_Name"
placeholder
=
"Enter a brief name for the key area here"
style
=
"width:99%;"
required
validationMessage
=
"The name for this key must be given!"
/>
<
div
id
=
"newCommentValidation"
class
=
"validation"
>The name is required!</
div
>
</
div
>
<
div
class
=
"user-share"
style
=
"width:100%;"
>
<
span
id
=
"YFKeyEdit_IntentionsLabel"
style
=
"width: 100%; text-align: center;"
><
b
>Intentions:</
b
></
span
>
<
a
class
=
"nav-button"
data-align
=
"right"
data-role
=
"button"
onclick
=
"AddIntention"
>Add</
a
>
<
span
id
=
"editYFKeyIntentions"
>
<
ul
>
<
li
>test1</
li
>
<
li
>test2</
li
>
<
li
>test3</
li
>
<
li
>test4</
li
>
</
ul
>
</
span
>
</
div
>
<
div
class
=
"user-share"
style
=
"width:100%;"
>
<
span
id
=
"YFKeyEdit_DescriptionLabel"
style
=
"width: 100%; text-align: center;"
><
b
>Description:</
b
></
span
><
br
/>
<
span
class
=
"txtarea-wrp"
>
<
textarea
id
=
"YFKeyEdit_Description"
rows
=
"3"
placeholder
=
"Enter a description for the key area here"
style
=
"width:99%; resize: none;"
required
validationMessage
=
"The name for this key must be given!"
/>
</
span
>
<
div
id
=
"newCommentValidation"
class
=
"validation"
>The name is required!</
div
>
</
div
>
</
div
>
</
div
>
<
div
data-role
=
"view"
id
=
"share"
data-layout
=
"default"
class
=
"share-view"
data-init
=
"app.viewModels.editYFKey.init"
data-show
=
"app.viewModels.editYFKey.show"
data-model
=
"app.viewModels.editYFKey"
>
<
header
data-role
=
"header"
>...
</
header
>
<
div
id
=
"enterStatus"
class
=
"user-status-wrp"
style
=
"background-color: white; height:100%;"
>
<
div
class
=
"user-share"
style
=
"width:100%;"
>
<
span
id
=
"YFKeyEdit_NameLabel"
style
=
"width: 98%; text-align: center;"
><
b
>Name:</
b
></
span
><
br
/>
<
input
id
=
"YFKeyEdit_Name"
placeholder
=
"Enter a brief name for the key area here"
style
=
"width:99%;"
required
validationMessage
=
"The name for this key must be given!"
/>
<
div
id
=
"newCommentValidation"
class
=
"validation"
>The name is required!</
div
>
</
div
>
<
div
class
=
"user-share"
style
=
"width:100%;"
>
<
span
id
=
"YFKeyEdit_DescriptionLabel"
style
=
"width: 100%; text-align: center;"
><
b
>Description:</
b
></
span
><
br
/>
<
span
class
=
"txtarea-wrp"
>
<
textarea
id
=
"YFKeyEdit_Description"
rows
=
"3"
placeholder
=
"Enter a description for the key area here"
style
=
"width:99%; resize: none;"
required
validationMessage
=
"The name for this key must be given!"
/>
</
span
>
<
div
id
=
"newCommentValidation"
class
=
"validation"
>The name is required!</
div
>
</
div
>
<
div
class
=
"user-share"
style
=
"width:100%;"
>
<
span
id
=
"YFKeyEdit_IntentionsLabel"
style
=
"width: 100%; text-align: center;"
><
b
>Intentions:</
b
></
span
>
<
a
class
=
"nav-button"
data-align
=
"right"
data-role
=
"button"
onclick
=
"AddIntention"
>Add</
a
>
<
span
id
=
"editYFKeyIntentions"
>
<
ul
>
<
li
>test1</
li
>
<
li
>test2</
li
>
<
li
>test3</
li
>
<
li
>test4</
li
>
</
ul
>
</
span
>
</
div
>
</
div
>
</
div
>
public ActionResult Section()
{
return
View();
}
public
ActionResult EditingPopup_Read([DataSourceRequest] DataSourceRequest request)
{
return
Json(db.Sections.Where( s=>s.IsPublished ==
true
).ToList().ToDataSourceResult(request));
}
[AcceptVerbs(HttpVerbs.Post)]
public
ActionResult EditingPopup_Create([DataSourceRequest] DataSourceRequest request, Section section)
{
if
(section !=
null
&& ModelState.IsValid)
{
db.Sections.Add(section);
db.SaveChanges();
}
return
Json(
new
[] { section }.ToDataSourceResult(request, ModelState));
}
[AcceptVerbs(HttpVerbs.Post)]
public
ActionResult EditingPopup_Update([DataSourceRequest] DataSourceRequest request, Section section)
{
if
(section !=
null
&& ModelState.IsValid)
{
var target = db.Sections.FirstOrDefault( s => s.SectionID == section.SectionID);
if
(target !=
null
)
{
target.Name = section.Name;
target.Description = section.Description;
db.Entry<Section>(section).State = System.Data.EntityState.Modified;
db.SaveChanges();
}
}
return
Json(ModelState.ToDataSourceResult());
}
[AcceptVerbs(HttpVerbs.Post)]
public
ActionResult EditingPopup_Destroy([DataSourceRequest] DataSourceRequest request, Section section)
{
if
(section !=
null
&& ModelState.IsValid)
{
var target = db.Sections.FirstOrDefault(s => s.SectionID == section.SectionID);
if
(target !=
null
)
{
target.IsPublished =
false
;
db.Entry<Section>(section).State = System.Data.EntityState.Modified;
db.SaveChanges();
}
}
return
Json(ModelState.ToDataSourceResult());
}
@(Html.Kendo().Grid<
MVC4Kendo.Models.Section
>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.Name);
columns.Bound(p => p.Description).Width(100);
columns.Bound(p => p.IsPublished).Width(100);
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(160);
})
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.PopUp))
.Pageable()
.Sortable()
.Scrollable()
.HtmlAttributes(new { style = "height:430px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Events(events => events.Error("error_handler"))
.Model(model => model.Id(p => p.SectionID))
.Create(update => update.Action("EditingPopup_Create", "Grid"))
.Read(read => read.Action("EditingPopup_Read", "Grid"))
.Update(update => update.Action("EditingPopup_Update", "Grid"))
.Destroy(update => update.Action("EditingPopup_Destroy", "Grid"))
)
)
<
script
type
=
"text/javascript"
>
function error_handler(e) {
if (e.errors) {
var message = "Errors:\n";
$.each(e.errors, function (key, value) {
if ('errors' in value) {
$.each(value.errors, function () {
message += this + "\n";
});
}
});
alert(message);
}
}
</
script
>