Advertisement
Minatys

Fixing crach in Umbraco 6.1.6 and uBlogsy 3.0.1

Oct 26th, 2013
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.02 KB | None | 0 0
  1. @*
  2.     Lists all posts in a collapsable list.    
  3.     Note: you probably don't want to use this if you have 1000's of nodes as the markup will get quite heavy.
  4. *@
  5.  
  6. @{ /* Displays post items in list form:
  7.     *   - year
  8.     *       - month
  9.     *           - post item
  10.     *           - post item
  11.     */}
  12. @using System.Linq;
  13. @using uBlogsy.Common.Extensions
  14. @using uBlogsy.Common.Helpers
  15. @using uBlogsy.BusinessLogic;
  16. @using uHelpsy.Extensions
  17.  
  18. @inherits UmbracoTemplatePage
  19. @{
  20.     int firstYear = -1;
  21.     var nodes = PostService.Instance
  22.         .GetPosts(Model.Content)
  23.         .Where(x => x.Url() != "#")
  24.         .ToIPublishedContent(true)
  25.         .ToList();
  26.  
  27.     var archiveClass = "uBlogsy_archive uBlogsy_bottom_border";
  28.     if ((bool)ViewData["AltLayout"])
  29.     {
  30.         archiveClass += " uBlogsy_post_archive_alt";
  31.     }
  32.  
  33.     @RenderScript()
  34.  
  35.     <section class="@archiveClass">
  36.         <h2 class="uBlogsy_head_style20">@Umbraco.GetDictionaryValue("uBlogsyDicArchive")</h2>
  37.         <div id="uBlogsy_post_archive">
  38.             <ul class="uBlogsy_years">
  39.                 @foreach (var node in nodes)
  40.                 {
  41.                     var date = node.GetPropertyValue<DateTime>("uBlogsyPostDate");
  42.                     var currentYear = date.Year;
  43.  
  44.                     if (firstYear == -1) { firstYear = currentYear; }
  45.  
  46.                     var yearClass = "uBlogsy_year";
  47.                    
  48.                     if (currentYear == firstYear) { yearClass += " uBlogsy_year_first"; }
  49.  
  50.                     // render years-months-items
  51.                     <li class="@yearClass"><a class="uBlogsy_year_name" href="#"><span>@currentYear</span></a>
  52.                         @*render year name*@
  53.                         <ul class="uBlogsy_months">
  54.                             @foreach (var monthNode in nodes)
  55.                             {
  56.                                 date = monthNode.GetPropertyValue<DateTime>("uBlogsyPostDate");
  57.  
  58.                                 if (date.Year != currentYear) { break; }
  59.                                
  60.                                 var currentMonth = date.Month;
  61.  
  62.                                 // render month
  63.                                 <li class="uBlogsy_month"><a class="uBlogsy_month_name" href="#"><span>@DateHelper.GetMonthName(currentMonth, false)</span>
  64.                                 </a> @* render month name *@
  65.                                     <ul class="uBlogsy_post_items">
  66.                                         @RenderPosts(nodes, currentYear, currentMonth)
  67.                                     </ul>
  68.                                 </li>
  69.                             }
  70.                         </ul>
  71.                     </li>
  72.                 }
  73.             </ul>
  74.         </div>
  75.     </section>
  76. }
  77.  
  78.  
  79. @helper RenderPosts(List<IPublishedContent> nodes, int currentYear, int currentMonth)
  80. {
  81.     foreach (var node in nodes)
  82.     {
  83.         var date = node.GetPropertyValue<DateTime>("uBlogsyPostDate");
  84.         var formattedDate = date.ToString().FormatDateTime("d MMMM yyyy");
  85.         var title = node.GetPropertyValue<string>("uBlogsyNavigationTitle");
  86.  
  87.         if (date.Month != currentMonth) { index--; break; }
  88.         if (date.Year != currentYear) { index--; break; }
  89.         var cssClass = "uBlogsy_post_item" + (Model.Content.Id == node.Id ? " uBlogsy_current" : string.Empty);                                          
  90.        
  91.         <li class="@cssClass"><a href="@node.Url()"><span class="uBlogsy_post_title">@title</span>
  92.             <span class="uBlogsy_post_date uBlogsy_font_style50">- @formattedDate</span>
  93.         </a></li>
  94.     }
  95. }
  96.  
  97.  
  98.  
  99. @helper RenderScript()
  100.     {
  101.     <script type="text/javascript">
  102.         $(document).ready(function () {
  103.             $('#uBlogsy_post_archive .uBlogsy_year_name').click(function () {
  104.  
  105.                 // toggle months
  106.                 $(this).siblings(".uBlogsy_months").toggle();
  107.                 $(this).siblings(".uBlogsy_months").find('.uBlogsy_post_items').trigger('click');
  108.  
  109.                 return false;
  110.             });
  111.  
  112.             $('#uBlogsy_post_archive .uBlogsy_month_name').click(function () {
  113.                 // toggle months
  114.                 $(this).siblings(".uBlogsy_post_items").toggle();
  115.                 return false;
  116.             });
  117.  
  118.             // expand current post item's month
  119.             var postItem = $('#uBlogsy_post_archive').find('a[href$="' + window.location.pathname + '"]');
  120.             if (postItem.length == 1) {
  121.                 $(postItem).parents('#uBlogsy_post_archive .uBlogsy_post_items').show();
  122.                 $(postItem).parents('#uBlogsy_post_archive .uBlogsy_months').show();
  123.             }
  124.             else {
  125.                 // expand latest month
  126.                 $(postItem).parents('#uBlogsy_post_archive .uBlogsy_months:eq(0)').show();
  127.  
  128.                 // trigger click to show first month
  129.                 $('.uBlogsy_month_name:eq(0)').trigger('click');
  130.             }
  131.         });
  132.     </script>
  133. }
  134.  
  135.  
  136.  
  137.  
  138. @functions
  139. {
  140.     private int index = 0;
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement