Calendar Plugin - Posted (5002 Views)
Forum Administrator
/mvc/ProtectedContent/Avatar/HuwR132430879466080654.jpg
Posts: 4383
starstarstarstarstar
This is the events calendar plugin for Snitz Mvc. The calendar is fully-integrated into the forum: all the events are posted as topics. The plugin should be fully compatible with Red1's Event Calendar mod available from SnitzBitz for the classic asp version.

You can download the PLUGIN here ?filename=SnitzEvents_1_1_2_0.zip

Installing the PLUGIN

  1. Unzip the contents of the downloaded file
  2. Copy the file in the App_Data folder to your Forums App_Data folder on the webserver
  3. Copy the SnitzEvents folder and its contents to your Forums Plugins folder
  4. Open your forum in a browser, Navigate to the Admin/Tools page and use the 'Reset Application' button to recycle the application

Adding a menu link

To add a link to the calendar, open the file /Views/Shared/_Menu.cshtml in a text editor.
Add the following code wherever you want the link to appear.
Code:

@if (ClassicConfig.GetIntValue("INTCALEVENTS") == 1)
{
<li>@Html.ActionLink(ResourceManager.GetLocalisedString("mnuEvents", "Menu"), "Index", "Calendar")</li>
}

Installing Admin code

  1. Install Admin page, open the file /Views/Admin/ModConfiguration.cshtml and add the code below at the end of the file.
    Code:
    @if (Config.TableExists("CAL_EVENTS"))
    {
    <div class="panel panel-primary panel-body clearfix">
    @Html.Action("Admin","Calendar")
    </div>
    }
    You can access the PLUGIN config from the Admin|Plugins|Other Plugins menu

  2. To post events, Forums must have a flag set to determine who can post events, To enable this, open the file /Views/Forum/Details.cshtml, scroll down the page until you find the @section Scripts { line, just above that you will see the code below
    Code:

    <div class="">

    <div class="col-sm-6">
    @Html.Partial("_FormButtons")</div>

    </div>

    Edit the section so it appears as below.
    Code:
    <div class=""> 
    @if (Config.TableExists("CAL_EVENTS") && ClassicConfig.GetIntValue("INTCALEVENTS") == 1)
    {
    @Html.Action("ForumEventSettings","Calendar",new {id=Model.Id})
    }
    <div class="col-sm-6">
    @Html.Partial("_FormButtons")</div>

    </div>
    The following section will appear on the form when editing Forum properties.

Add the Event form to the Post Topic form

  1. Open the file /Views/Shared/PostMessage.cshtml in a text editor.
  2. Look for the following block of code (around line 190)
    Code:

    @Html.HiddenFor(model => model.CatId)
    @Html.HiddenFor(model => model.TopicId)
    @Html.HiddenFor(model => model.ReplyId)
    @Html.HiddenFor(model => model.Referrer)
    @Html.HiddenFor(model => model.IsPoll)

    }
  3. Now add the code below directly after the closing } in the code section from above
    Code:

    @if (Config.TableExists("CAL_EVENTS") && ClassicConfig.GetIntValue("INTCALEVENTS") == 1)
    {
    if (Model.Type == PostType.Topic && (User.IsInRole("Administrator") || Model.IsAuthor || User.IsForumModerator(Model.ForumId)))
    {
    <div class="col-md-3 pull-right hidden-xs hidden-sm" id="cal-container">
    @if (Model.TopicId > 0)
    {
    @Html.Action("TopicEventEdit", "Calendar", new { id = Model.TopicId, page = 1 })
    }
    else
    {
    @Html.Action("TopicEvent", "Calendar", new { id = Model.ForumId })
    }
    </div>
    }
    }
  4. Scroll down the page until you find the line @section Scripts{ insert the following line below that
    Code:
    @Scripts.Render("~/scripts/snitz.cal.js")
  5. Continue down the page until you find the line setConditionalValidators();
    Insert the javascript code below above the line we just located.
    Code:

    /* Event Calendar code */

    $(document).on('click', '#cal-nextevent', function (event) {
    var tId = $('#cal-topicid').val();
    var fId = $('#cal-forumid').val();
    var page = parseInt($('#cal-curpage').val());

    event.preventDefault();
    $.ajax({
    type: "POST",
    url: SnitzVars.baseUrl + 'Calendar/TopicEventEdit/' + tId + '/?forumid=' + fId + '&page=' + (page+1),
    success: function (data) {
    $('#cal-container').html(data);
    if ($('#cal-recur').val() == 'EveryDay') {
    $('#cal-dow').show();
    }
    },
    error: function (result) {
    BootstrapDialog.alert(
    {
    title: "Error ",
    message: result.responseText
    });
    }
    });
    });
    $(document).on('click', '#cal-prevevent', function (event) {
    var tId = $('#cal-topicid').val();
    var fId = $('#cal-forumid').val();
    var page = parseInt($('#cal-curpage').val());

    event.preventDefault();
    $.ajax({
    type: "POST",
    url: SnitzVars.baseUrl + 'Calendar/TopicEventEdit/' + tId + '/?forumid=' + fId + '&page=' + (page - 1),
    success: function (data) {
    $('#cal-container').html(data);
    if ($('#cal-recur').val() == 'EveryDay') {
    $('#cal-dow').show();
    }
    },
    error: function (result) {
    BootstrapDialog.alert(
    {
    title: "Error ",
    message: result.responseText
    });
    }
    });
    });
    $(document).on('click', '#cal-update', function (event) {
    //debugger;
    var serializedForm = $("#cal-editTopicEvent").serialize();
    event.preventDefault();
    $.ajax({
    type: "POST",
    url: SnitzVars.baseUrl + 'Calendar/EditEvent',
    data: serializedForm,
    dataType: "json",
    success: function (data) {
    $('#cal-container').html(data);
    if ($('#cal-recur').val() == 'EveryDay') {
    $('#cal-dow').show();
    }
    },
    error: function (result) {
    BootstrapDialog.alert(
    {
    title: "Error ",
    message: result.responseText
    });
    }
    });
    });

    /* Event Calendar code */
    Just below the setConditionalValidators(); line you will see the following function
    Code:
            // This function is called after a Topic or Reply is posted
    // data contains topic.Id + ":" + ReferrerUrl
    function postPostMessage(event,data) {
    var arr = data.responseText.split(':');

    }
    It may or may not contain other code, just add the following to the end of the function, before the closing }
    Code:
    if ($("#cal-addTopicEvent").length > 0) {
    postEvent(event, arr);
    } else {
    window.location.href = arr[1];
    }
    Now when posting a topic in forums that allow events, the form below will be visible on the post page.

Adding Calendar icon to topic displays

    \Views\Topic\_MessageButtons.cshtml
    Open the above file and look for the line <a id="@Model.Id"></a> Add the code below just after the line.
    Code:
          
    @if (ClassicConfig.GetIntValue("INTCALEVENTS") == 1)
    {
    @Html.Action("EventIcon", "Calendar", new {id = Model.Id})
    }
  1. \Views\Shared\DisplayTemplates\Topic.cshtml
    Open the above file and look for the lines
    <div class="topic-strap">
    <span class="hidden-xs">

    Add the code below just after those lines.
    Code:

    @if (ClassicConfig.GetIntValue("INTCALEVENTS") == 1)
    {
    @Html.Action("EventIcon","Calendar",new{id=Model.Id})
    }
That should be all the changes done, topics posted with an event should now appear on the calendar page.
Signature Test