// VideoLibrary DEMO - DaST Technology Demonstrator
// Copyright (C) 2011 Roman Gubarenko
// http://www.rgubarenko.net
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// Licence terms for AspNetDaST.dll (in Bin folder) are below.
//
// ASP.NET DaST Rendering Engine (BETA version)
// Copyright (C) 2011 Roman Gubarenko
// http://www.rgubarenko.net
//
// Redistribution and use of BETA version of DaST Rendering Engine
// is permitted in binary form without modification. Only original and
// unmodified .NET dll (AspNetDaST.dll) can be used in your own projects and
// redistributed. You may not copy, decompile, reverse engineer, disassemble,
// modify, or create derivative works of the software or any part thereof.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE.
//
// DaST technology dev site: http://www.rgubarenko.net
// My contact email for questions: rgubarenko@gmail.com
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AspNetDaST.Web;
public class VideoLibraryController : ScopeController
{
public override void SetTemplate(SetTemplateArgs template)
{
template.Markup = Utils.LoadTemplate("VideoLibraryTemplate.htm");
}
public override void SetupModel(ControllerModelBuilder model)
{
model.SetDataBind(new DataBindHandler(ROOT_DataBind));
model.Select("PageSizeRepeater").SetDataBind(new DataBindHandler(PageSizeRepeater_DataBind));
model.Select("SiteThemeRepeater").SetDataBind(new DataBindHandler(SiteThemeRepeater_DataBind));
model.Select("PlaylistHeader").SetDataBind(new DataBindHandler(PlaylistHeader_DataBind));
model.Select("PlaylistRepeater").SetDataBind(new DataBindHandler(PlaylistRepeater_DataBind));
model.Select("PlaylistRepeater", "VideoItem").SetController(new VideoItemController());
model.Select("PlaylistPager").SetController(new PagerController());
model.Select("VideoItemGridInfo").SetDataBind(new DataBindHandler(VideoItemGridInfo_DataBind));
model.Select("VideoItemPager").SetController(new PagerController());
model.Select("VideoItemRepeater").SetDataBind(new DataBindHandler(VideoItemRepeater_DataBind));
model.Select("VideoItemRepeater", "VideoItem").SetController(new VideoItemController());
model.Select("DetailsPopup").SetController(new DetailsPopupController());
model.HandleAction("PageSizeChanged", new ActionHandler(Action_PageSizeChanged));
model.Select("PlaylistPager").HandleAction("NextPage", new ActionHandler(PlaylistPager_PageChanged));
model.Select("PlaylistPager").HandleAction("PrevPage", new ActionHandler(PlaylistPager_PageChanged));
model.Select("PlaylistRepeater", "VideoItem").HandleAction("PlaylistUpdated", new ActionHandler(VideoItem_PlaylistUpdated));
model.Select("VideoItemPager").HandleAction("NextPage", new ActionHandler(VideoItemPager_PageChanged));
model.Select("VideoItemPager").HandleAction("PrevPage", new ActionHandler(VideoItemPager_PageChanged));
model.Select("VideoItemRepeater", "VideoItem").HandleAction("PlaylistUpdated", new ActionHandler(VideoItem_PlaylistUpdated));
model.Select("DetailsPopup").HandleAction("PlaylistUpdated", new ActionHandler(VideoItem_PlaylistUpdated));
}
private void Action_PageSizeChanged(ActionArgs args)
{
int newPageSize = int.Parse((string)args.ActionData);
// pass new page size to pager
ControlPath.Fwd("VideoItemPager").Scope.Method("UpdatePagerValues", new { PageSize = newPageSize });
// refresh scopes
ControlPath.Fwd("PageSizeRepeater").Scope.Refresh();
ControlPath.Fwd("VideoItemGridInfo").Scope.Refresh();
ControlPath.Fwd("VideoItemRepeater").Scope.Refresh();
ControlPath.Fwd("VideoItemPager").Scope.Refresh();
}
private void PlaylistPager_PageChanged(ActionArgs args)
{
ControlPath.Fwd("PlaylistHeader").Scope.Refresh();
ControlPath.Fwd("PlaylistPager").Scope.Refresh();
ControlPath.Fwd("PlaylistRepeater").Scope.Refresh();
}
private void VideoItemPager_PageChanged(ActionArgs args)
{
ControlPath.Fwd("VideoItemGridInfo").Scope.Refresh();
ControlPath.Fwd("VideoItemRepeater").Scope.Refresh();
ControlPath.Fwd("VideoItemPager").Scope.Refresh();
}
private void VideoItem_PlaylistUpdated(ActionArgs args)
{
// pass total items count to parent scope
int itemTotalCount = DataLayer.GetPlayItemCount();
ControlPath.Fwd("PlaylistPager").Scope.Method(
"UpdatePagerValues", new { ItemTotalCount = itemTotalCount });
ControlPath.Fwd("PlaylistHeader").Scope.Refresh();
ControlPath.Fwd("PlaylistPager").Scope.Refresh();
ControlPath.Fwd("PlaylistRepeater").Scope.Refresh();
ControlPath.Fwd("VideoItemRepeater").Scope.Refresh();
}
private void ROOT_DataBind()
{
CurrentPath.Scope.Replace("{PageTitleDate}", DateTime.Now.ToShortDateString());
// initialize playlist items pager
int playCount = DataLayer.GetPlayItemCount();
CurrentPath.Fwd("PlaylistPager").Scope.SetParam("StartItemIdx", 0);
CurrentPath.Fwd("PlaylistPager").Scope.SetParam("PageSize", 5);
CurrentPath.Fwd("PlaylistPager").Scope.SetParam("ItemTotalCount", playCount);
// initialize video item grid pager
int pageSize = DataLayer.GetAvailablePageSizes()[2];
int videoCount = DataLayer.GetVideoItemCount(null);
CurrentPath.Fwd("VideoItemPager").Scope.SetParam("StartItemIdx", 0);
CurrentPath.Fwd("VideoItemPager").Scope.SetParam("PageSize", pageSize);
CurrentPath.Fwd("VideoItemPager").Scope.SetParam("ItemTotalCount", videoCount);
}
private void PageSizeRepeater_DataBind()
{
int currPageSize = CurrentPath.Rew(1).Fwd("VideoItemPager").Scope.Param<int>("PageSize");
int[] pageSizes = DataLayer.GetAvailablePageSizes();
CurrentPath.Scope.RestartRepeater();
foreach (int pageSize in pageSizes)
{
CurrentPath.Scope.Repeat();
CurrentPath.Scope.Replace("{OptionValue}", pageSize);
CurrentPath.Scope.Replace("attr_selected", pageSize == currPageSize ? "selected='selected'" : "");
}
}
private void SiteThemeRepeater_DataBind()
{
string[] themes = DataLayer.GetAvailableThemes();
CurrentPath.Scope.RestartRepeater();
foreach (string theme in themes)
{
CurrentPath.Scope.Repeat();
CurrentPath.Scope.Replace("{OptionValue}", theme);
CurrentPath.Scope.Replace("attr_selected", theme == themes[0] ? "selected='selected'" : "");
}
}
private void PlaylistHeader_DataBind()
{
// retrieve pager values
int startItemIdx = ControlPath.Fwd("PlaylistPager").Scope.Param<int>("StartItemIdx");
int pageSize = ControlPath.Fwd("PlaylistPager").Scope.Param<int>("PageSize");
int itemTotalCount = ControlPath.Fwd("PlaylistPager").Scope.Param<int>("ItemTotalCount");
if (itemTotalCount > 0)
{
CurrentPath.Scope.ShowConditionArea("playlist-empty:yes", false);
CurrentPath.Scope.ShowConditionArea("playlist-empty:no", true);
CurrentPath.Scope.ReplaceRange(new
{
FromItemNum = startItemIdx + 1,
ToItemNum = Math.Min(startItemIdx + pageSize, itemTotalCount),
TotalItemCount = itemTotalCount
}, null, "{{name}}");
// hide pager if there is only a single page
if (itemTotalCount <= pageSize)
{
ControlPath.Fwd("PlaylistPager").Scope.RenderType = ScopeRenderType.Empty;
}
}
else
{
CurrentPath.Scope.ShowConditionArea("playlist-empty:yes", true);
CurrentPath.Scope.ShowConditionArea("playlist-empty:no", false);
ControlPath.Fwd("PlaylistPager").Scope.RenderType = ScopeRenderType.Empty;
ControlPath.Fwd("PlaylistRepeater").Scope.RenderType = ScopeRenderType.Empty;
}
}
private void PlaylistRepeater_DataBind()
{
int startItemIdx = CurrentPath.Rew(1).Fwd("PlaylistPager").Scope.Param<int>("StartItemIdx");
int pageSize = CurrentPath.Rew(1).Fwd("PlaylistPager").Scope.Param<int>("PageSize");
int itemTotalCount = CurrentPath.Rew(1).Fwd("PlaylistPager").Scope.Param<int>("ItemTotalCount");
object[] videoItems = DataLayer.GetPlayItems(startItemIdx, pageSize);
CurrentPath.Scope.RestartRepeater();
for (int i = 0; i < videoItems.Length; i++)
{
CurrentPath.Scope.Repeat();
CurrentPath.Fwd(i, "VideoItem").Scope.SetParam("ItemIndex", startItemIdx + i);
CurrentPath.Fwd(i, "VideoItem").Scope.SetParam("VideoItemObject", videoItems[i]);
}
}
private void VideoItemGridInfo_DataBind()
{
int startItemIdx = CurrentPath.Rew(1).Fwd("VideoItemPager").Scope.Param<int>("StartItemIdx");
int pageSize = CurrentPath.Rew(1).Fwd("VideoItemPager").Scope.Param<int>("PageSize");
int itemTotalCount = CurrentPath.Rew(1).Fwd("VideoItemPager").Scope.Param<int>("ItemTotalCount");
CurrentPath.Scope.Replace("{FromItemNum}", startItemIdx + 1);
CurrentPath.Scope.Replace("{ToItemNum}", Math.Min(startItemIdx + pageSize, itemTotalCount));
CurrentPath.Scope.Replace("{TotalItemCount}", itemTotalCount);
}
private void VideoItemRepeater_DataBind()
{
int startItemIdx = CurrentPath.Rew(1).Fwd("VideoItemPager").Scope.Param<int>("StartItemIdx");
int pageSize = CurrentPath.Rew(1).Fwd("VideoItemPager").Scope.Param<int>("PageSize");
int itemTotalCount = CurrentPath.Rew(1).Fwd("VideoItemPager").Scope.Param<int>("ItemTotalCount");
object[] videoItems = DataLayer.GetVideoItems(startItemIdx, pageSize, null);
CurrentPath.Scope.RestartRepeater();
for (int i = 0; i < videoItems.Length; i++)
{
CurrentPath.Scope.Repeat();
CurrentPath.Fwd(i, "VideoItem").Scope.SetParam("ItemIndex", startItemIdx + i);
CurrentPath.Fwd(i, "VideoItem").Scope.SetParam("VideoItemObject", videoItems[i]);
}
}
}