Commit 24d31deb by Urvil Shah

Add The Get Url Feature

parent 6314ad9e
Pipeline #8057 passed with stages
in 23 minutes 51 seconds
......@@ -16,7 +16,9 @@ using System.IO;
using System.Collections;
using Newtonsoft.Json;
using System.Net.Mail;
using System.Text.RegularExpressions;
using System.Text;
namespace Mobile.Search.Web.Controllers
{
......@@ -77,6 +79,8 @@ namespace Mobile.Search.Web.Controllers
{
return View("Edit", new KeyValuePair<string, string>(Chronos.GenerateRandom.String(6), "<html></html>"));
}
public ActionResult CreateFroala()
{
return View("FroalaIndex", new KeyValuePair<string, string>(Chronos.GenerateRandom.String(6), "<html></html>"));
......@@ -142,13 +146,15 @@ namespace Mobile.Search.Web.Controllers
// POST: Template/Edit/5
[HttpPost, ValidateInput(false)]
public ActionResult FroalaIndex(string key, string value, string EmailId, bool isSendEmail = false,bool WrapUrl=false, bool AdvertiserHasUnSub=false)
[ValidateInput(false)]
[HttpPost]
public ActionResult FroalaIndex(string key, string value, string EmailId, bool isSendEmail = false, bool WrapUrl = false, bool AdvertiserHasUnSub = false, bool isGetUrl = false)
{
try
{
string url = "http://config.minbox.email/Offer/Create?template_attributes=";
string url = "http://config.minbox.email/Offer/Create?template_attributes=";
string OriginalValue = value;
Match m;
string HRefPattern = "href\\s*=\\s*(?:[\"'](?<1>[^\"']*)[\"']|(?<1>\\S+))";
// _dynamoClient.WriteSingle("prd_2click_templates", d);
......@@ -160,26 +166,37 @@ namespace Mobile.Search.Web.Controllers
if (!isSendEmail)
WrapUrl = true;
HashSet<string> Url = new HashSet<string>();
HashSet<string> UrlWrap = new HashSet<string>();
StringBuilder sb = new StringBuilder();
while (m.Success && WrapUrl)
{
count=count-1;
count = count - 1;
if (!m.Value.Contains("Wrap"))
{
string to_replace = String.Format("{{{{WrapUrl('{0}')}}}}", m.Groups[1]);
if(count==0 && AdvertiserHasUnSub)
if (count == 0 && AdvertiserHasUnSub)
{
to_replace= String.Format("{{{{WrapAdvertiserUnsubscribeUrl('{0}')}}}}", m.Groups[1]);
to_replace = String.Format("{{{{WrapAdvertiserUnsubscribeUrl('{0}')}}}}", m.Groups[1]);
}
if(m.Groups[1].Value.Count()>0 && !m.Groups[1].Value.Contains("anchor") && !UrlWrap.Contains(m.Groups[1].Value))
if (m.Groups[1].Value.Count() > 0 && !m.Groups[1].Value.Contains("anchor") && !Url.Contains(m.Groups[1].Value) && !m.Groups[1].Value.Contains(".css") && !m.Groups[1].Value.Contains(".js"))
{
string changeset = Request.Form[count.ToString()];
if (changeset != null)
{
to_replace = changeset;
}
value = value.Replace(m.Groups[1].Value, to_replace);
UrlWrap.Add(m.Groups[1].Value);
Url.Add(m.Groups[1].Value);
UrlWrap.Add(to_replace);
string s = String.Format("<textarea id='{0}' name='{0}' runat='server' style =width:90% rows=1 cols=100>{1}</textarea>", count, to_replace);
sb.Append(s);
sb.Append("<br/> <br/>");
}
}
m = m.NextMatch();
}
var d = new Dictionary<string, object>
{
......@@ -187,8 +204,13 @@ namespace Mobile.Search.Web.Controllers
{"html", value}
};
if (isGetUrl)
{
return Json(new { Allstring = sb.ToString() });
if (isSendEmail)
}
else if (isSendEmail)
{
if (sendEmail(value, EmailId))
{
......@@ -201,6 +223,7 @@ namespace Mobile.Search.Web.Controllers
}
}
else
{
_dynamoClient.WriteSingle("prd_2click_templates", d);
......
@model KeyValuePair<string, string>
@{
ViewBag.Title = "FroalaIndex";
Layout = null;
var Urls = (HashSet<string>)TempData["message"];
}
<html>
......@@ -93,7 +95,8 @@
</style>
</head>
<body>
@using (Html.BeginForm("FroalaIndex", "Template", FormMethod.Post, new { @class = "pure-form pure-form-stacked" }))
@using (Html.BeginForm("FroalaIndex", "Template", FormMethod.Post | FormMethod.Get, new { @class = "pure-form pure-form-stacked" }))
{
<div class="left col">
......@@ -158,11 +161,19 @@
</td>
</tr>
</table>
</div>
</div>
<div>
<div class="pure-controls">
<button type="submit" id="GetUrls" class="pure-button pure-button-primary">Get All Urls</button>
</div>
<div id="output" style="width:80%; margin-right:10px;margin-left:10px">
</div>
</div>
</div>
</div>
......@@ -191,23 +202,7 @@
<!-- Include Editor JS files. -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/froala-editor/2.7.6/js/froala_editor.pkgd.min.js"></script>
<script>
//$(function () {
// $('textarea').froalaEditor({
// heightMin: 900,
// })
//});
//$(function () {
// $('textarea')
// .on('froalaEditor.contentChanged froalaEditor.initialized', function (e, editor) {
// $('pre#eg-previewer').text(editor.codeBeautifier.run(editor.html.get()))
// $('pre#eg-previewer').removeClass('prettyprinted');
// prettyPrint()
// })
// .froalaEditor()
//});
$(document).ready(function () {
var original_helpers = $.FE.MODULES.helpers;
$.FE.MODULES.helpers = function (editor) {
......@@ -217,7 +212,6 @@
// This is the original sanitizer.
helpers.sanitizeURL = function (url) {
console.log('hello :)')
return url;
};
......@@ -245,6 +239,7 @@
$('#SendEmail').click(function (e) {
e.preventDefault();
var Content = $('#FroalaHtmlEditor').froalaEditor('html.get');
if (Content.length < 1) {
Content = $('#FroalaHtmlEditor').froalaEditor('codeView.get');
}
......@@ -280,7 +275,55 @@
});
});
$('#GetUrls').click(function (e) {
e.preventDefault();
var Content = $('#FroalaHtmlEditor').froalaEditor('html.get');
if (Content.length < 1) {
Content = $('#FroalaHtmlEditor').froalaEditor('codeView.get');
}
var EmailId = document.getElementById("EmailId").value;
var key = document.getElementById("KeyValue").value;
var WrapUrl = document.getElementById("WrapUrl").checked;
var WrapAdvertiserUrl = document.getElementById("WrapAdvertiserUrl").checked;
//$('#GetUrls').hide();
//$('#sent_to_email_failed').hide();
//$('WrapUrl').hide();
//$('WrapAdvertiserUrl').hide();
$.ajax({
url: "/Template/FroalaIndex",
type: "POST",
data: JSON.stringify({ 'key': key, 'value': Content, 'EmailId': EmailId, 'isSendEmail': false, 'WrapUrl': WrapUrl, 'AdvertiserHasUnSub': WrapAdvertiserUrl, 'isGetUrl': true }),
dataType: "json",
traditional: true,
async: false,
cache: false,
contentType: "application/json; charset=utf-8",
success: function (data) {
$('#output').html(data.Allstring);
if (data.status == "Success") {
$('#sent_to_email_failed').hide();
$('#email_id').empty().append(EmailId);
$('#sent_to_email').show();
document.getElementById("EmailId").value = ""
} else {
$('#sent_to_email').hide();
$('#email_id_failed').empty().append(EmailId);
$('#sent_to_email_failed').hide();
document.getElementById("EmailId").value = ""
}
}
});
});
});
</script>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment