Added Custom Donation UI

This commit is contained in:
Jim MacKenzie 2016-10-08 19:24:45 -05:00
commit e3bbc7202b
5 changed files with 97 additions and 9 deletions

View file

@ -58,8 +58,9 @@ namespace PlexRequests.Core.SettingModels
public bool Wizard { get; set; }
public bool DisableTvRequestsByEpisode { get; set; }
public bool DisableTvRequestsBySeason { get; set; }
public string PayPalMeName { get; set; }
public bool EnablePayPalMe { get; set; }
public string CustomDonationUrl { get; set; }
public bool EnableCustomDonationUrl { get; set; }
public string CustomDonationMessage { get; set; }
/// <summary>
/// The CSS name of the theme we want
/// </summary>

View file

@ -0,0 +1,60 @@
using System;
using System.Threading.Tasks;
using Nancy;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NLog;
using PlexRequests.Core;
using PlexRequests.Core.SettingModels;
using PlexRequests.Helpers;
using PlexRequests.UI.Models;
namespace PlexRequests.UI.Modules
{
public class DonationLinkModule : BaseAuthModule
{
public DonationLinkModule(ICacheProvider provider, ISettingsService<PlexRequestSettings> pr) : base("customDonation", pr)
{
Cache = provider;
Get["/", true] = async (x, ct) => await GetCustomDonationUrl(pr);
}
private ICacheProvider Cache { get; }
private static Logger Log = LogManager.GetCurrentClassLogger();
private async Task<Response> GetCustomDonationUrl(ISettingsService<PlexRequestSettings> pr)
{
PlexRequestSettings settings = pr.GetSettings();
try
{
if (settings.EnableCustomDonationUrl)
{
JObject o = new JObject();
o["url"] = "\""+ settings.CustomDonationUrl + "\"";
o["message"] = "\"" + settings.CustomDonationMessage + "\"";
return Response.AsJson(o);
}
else
{
JObject o = new JObject();
o["url"] = "https://www.paypal.me/PlexRequestsNet";
return Response.AsJson(o);
}
}
catch (Exception e)
{
Log.Warn("Exception Thrown when attempting to check the custom donation url");
Log.Warn(e);
JObject o = new JObject();
o["url"] = "https://www.paypal.me/PlexRequestsNet";
o["message"] = "\"" + "Donate to Library Maintainer" + "\"";
return Response.AsJson(o);
}
}
}
}

View file

@ -248,6 +248,7 @@
<Compile Include="Modules\BaseModule.cs" />
<Compile Include="Modules\BetaModule.cs" />
<Compile Include="Modules\CultureModule.cs" />
<Compile Include="Modules\DonationLinkModule.cs" />
<Compile Include="Modules\IssuesModule.cs" />
<Compile Include="Modules\LandingPageModule.cs" />
<Compile Include="Modules\RequestsBetaModule.cs" />

View file

@ -256,21 +256,27 @@
<div class="form-group">
<div class="checkbox">
@if (Model.EnablePayPalMe)
@if (Model.EnableCustomDonationUrl)
{
<input type="checkbox" id="EnablePayPalMe" name="EnablePayPalMe" checked="checked">
<label for="EnablePayPalMe">Enable custom paypal.me link</label>
<input type="checkbox" id="EnableCustomDonationUrl" name="EnableCustomDonationUrl" checked="checked">
<label for="EnableCustomDonationUrl">Enable custom donation link</label>
}
else
{
<input type="checkbox" id="EnablePayPalMe" name="EnablePayPalMe"><label for="EnablePayPalMe">Enable custom paypal.me donate link</label>
<input type="checkbox" id="EnableCustomDonationUrl" name="EnableCustomDonationUrl"><label for="EnableCustomDonationUrl">Enable custom donation link</label>
}
</div>
</div>
<div class="form-group">
<label for="PayPalMeName" class="control-label">Paypal.me name</label>
<label for="CustomDonationUrl" class="control-label">Custom Donation URL</label>
<div>
<input type="text" class="form-control-custom form-control " id="PayPalMeName" name="PayPalMeName" placeholder="paypay.me name" value="@Model.PayPalMeName">
<input type="text" class="form-control-custom form-control " id="CustomDonationUrl" name="CustomDonationUrl" placeholder="Custom URL" value="@Model.CustomDonationUrl">
</div>
</div>
<div class="form-group">
<label for="CustomDonationMessage" class="control-label">Custom Donation Message</label>
<div>
<input type="text" class="form-control-custom form-control " id="CustomDonationMessage" name="CustomDonationMessage" placeholder="Custom Donation Message" value="@Model.CustomDonationMessage">
</div>
</div>
@ -278,6 +284,7 @@
<p class="form-group">A comma separated list of users whose requests do not require approval (These users also do not have a request limit).</p>
<div class="form-group">
<label for="NoApprovalUsers" class="control-label">Approval White listed Users</label>
<div>

View file

@ -1,6 +1,7 @@
@using Nancy.Security
@using Nancy.Session
@using Nancy;
@using PlexRequests.Core.SettingModels
@using PlexRequests.UI.Helpers
@using PlexRequests.UI.Models
@using PlexRequests.UI.Resources
@ -38,10 +39,11 @@
{
<li><a id="donate" href="https://www.paypal.me/PlexRequestsNet" target="_blank"><i class="fa fa-heart" style="color: red"></i> @UI.Layout_Donate</a></li>
}
<li id="customDonate" style="display: none"><a id="customDonateHref" href="https://www.paypal.me/PlexRequestsNet" target="_blank"><i class="fa fa-heart" style="color: yellow;"></i> <span id="donationText">Donate to Library Maintainer</span></a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
@if (!Context.CurrentUser.IsAuthenticated() && Context.Request.Session[SessionKeys.UsernameKey] == null) // TODO replace with IsAdmin
{
@ -91,5 +93,22 @@
</ul>
</div>
</div>
<script>
$.ajax({
url: "/customDonation",
success: function (result) {
$("#customDonate").show();
var donateLink = $("#customDonateHref");
var donationText = $("#donationText");
donateLink.attr("href", result.url);
if(result.message) {
donationText.text(result.message);
}
},
error: function(xhr, status, error) {
console.log("error " + error);
}
});
</script>
<div id="updateAvailable" hidden="hidden"></div>
</nav>