To install the backend pages and register the widgets in the toolbox, add the following method:
public
override
void
Install(SiteInitializer initializer)
{
#region Install Pages
// get page manager
var pageManager = initializer.PageManager;
// create Module Landing Page if doesn't exist
var landingPage = pageManager.GetPageNodes().SingleOrDefault(p => p.Id ==
this
.LandingPageId);
if
(landingPage ==
null
)
{
// create admin list view control and add to new landing page
var ctrl = pageManager.CreateControl<PageControl>(
"~/Modules/Testimonials/Admin/TestimonialsAdminView.ascx"
,
"Content"
);
CreatePage(pageManager, LandingPageId, SiteInitializer.ModulesNodeId, TestimonialsModule.ModuleName,
true
, TestimonialsModule.ModuleName, ctrl);
}
// create testimonials "Create" Page if doesn't exist
var createPage = pageManager.GetPageNodes().SingleOrDefault(p => p.Id ==
this
.CreatePageId);
if
(createPage ==
null
)
{
// create admin control, set properties
var ctrl = pageManager.CreateControl<PageControl>(
"~/Modules/Testimonials/Admin/TestimonialsAddEditView.ascx"
,
"Content"
);
var prop = ctrl.Properties.FirstOrDefault(p => p.Name ==
"Mode"
);
if
(prop ==
null
)
{
prop =
new
ControlProperty();
prop.Id = Guid.NewGuid();
prop.Name =
"Mode"
;
ctrl.Properties.Add(prop);
}
// set control to "Create" mode
prop.Value = SitefinityWebApp.Modules.Testimonials.Admin.TestimonialsAddEditView.AdminControlMode.Create.ToString();
// create backend page and add control
CreatePage(pageManager, CreatePageId, LandingPageId,
"Create"
,
false
,
"Create Testimonial"
, ctrl);
}
// create testimonials "Edit" Page if doesn't exist
var editPage = pageManager.GetPageNodes().SingleOrDefault(p => p.Id ==
this
.EditPageId);
if
(editPage ==
null
)
{
// create admin control, set properties
var ctrl = pageManager.CreateControl<PageControl>(
"~/Modules/Testimonials/Admin/TestimonialsAddEditView.ascx"
,
"Content"
);
var prop = ctrl.Properties.FirstOrDefault(p => p.Name ==
"Mode"
);
if
(prop ==
null
)
{
prop =
new
ControlProperty();
prop.Id = Guid.NewGuid();
prop.Name =
"Mode"
;
ctrl.Properties.Add(prop);
}
// set control to "Create" mode
prop.Value = SitefinityWebApp.Modules.Testimonials.Admin.TestimonialsAddEditView.AdminControlMode.Edit.ToString();
// create backend page and add control
CreatePage(pageManager, EditPageId, LandingPageId,
"Edit"
,
false
,
"Edit Testimonial"
, ctrl);
}
#endregion
#region Register Toolbox Widget
string
toolboxName =
"PageControls"
;
string
sectionName =
"Samples"
;
var config = initializer.Context.GetConfig<ToolboxesConfig>();
var controls = config.Toolboxes[toolboxName];
var section = controls.Sections.Where<ToolboxSection>(e => e.Name == sectionName).FirstOrDefault();
if
(section ==
null
)
{
section =
new
ToolboxSection(controls.Sections)
{
Name = sectionName,
Title = sectionName,
Description = sectionName,
ResourceClassId =
typeof
(PageResources).Name
};
controls.Sections.Add(section);
}
// Add TestimonialsView Widget if doesn't exist
if
(!section.Tools.Any<ToolboxItem>(e => e.Name == TestimonialsView.ViewName))
{
var tool =
new
ToolboxItem(section.Tools)
{
Name = TestimonialsView.ViewName,
Title =
"TestimonialsView"
,
Description =
"Public control for the Testimonials module"
,
ControlType =
"~/Modules/Testimonials/TestimonialsView.ascx"
,
CssClass =
"sfTestimonialsWidget"
};
section.Tools.Add(tool);
}
// Add SubmitTestimonial Widget if doesn't exist
if
(!section.Tools.Any<ToolboxItem>(e => e.Name == SubmitTestimonial.ViewName))
{
var tool =
new
ToolboxItem(section.Tools)
{
Name = SubmitTestimonial.ViewName,
Title =
"SubmitTestimonial"
,
Description =
"Public control for submitting Testimonial"
,
ControlType =
"~/Modules/Testimonials/SubmitTestimonial.ascx"
,
CssClass =
"sfTestimonialsWidget"
};
section.Tools.Add(tool);
}
#endregion
}