﻿/// <reference path="~/Scripts/IntelliSense/Intellisense.js" />
(function()
{
	BSC.UI.Ws.Feedback = function()
	{
		/// <summary>
		/// Bind events to ui elements
		/// </summary>
		var bind = function(p1)
		{
			var guid = p1;
			$("#" + guid + "_report").bind("click", guid, function(e)
			{
				var guid = e.data;

				var reasons = $("#" + guid + " input[type='radio']").fieldArray();
				var additionalComments = "" + $("#" + guid + "_feedback").getValue();

				var data =
				{
					reportType: "Feedback",
					reasons: reasons,
					additionalComments: additionalComments
				};

				BSC.UI.Ws.Feedback.Send(guid, data);
			});
			$("#" + guid + "_reportCancel").bind("click", guid, function(e)
			{
				var guid = e.data;
				BSC.UI.W.Close(guid);
			});
		};

		/// <summary>
		/// Unbind events to ui elements
		/// </summary>
		var unbind = function(p1)
		{
			var guid = p1;
			$("#" + guid + "_report").unbind();
			$("#" + guid + "_reportCancel").unbind();
		};
		/// <summary>
		/// Unbind events to ui elements
		/// </summary>
		var send = function(p1, p2, p3)
		{
			var guid = p1;
			var data = p2;
			var profileid = p3;
			BSC.D.AjaxPost("/Feedback/ReceiveReport/" + profileid, data, function(res)
			{
				// Html
				if (res.success)
				{
					BSC.UI.W.Close(guid);
					BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.UserReport.OK"), null, BSC.T.Get("JS.BSC.UI.Ws.UserReport.Report.Success.Title"), BSC.T.Get("JS.BSC.UI.Ws.UserReport.Report.Success.Desc"), null, guid, "info");
				}
				else
				{
					BSC.UI.HideStatus(guid, 200);
					BSC.UI.Alert(BSC.T.Get("JS.BSC.UI.Ws.UserReport.OK"), null, BSC.T.Get("JS.BSC.UI.Ws.UserReport.Error.Title"), BSC.T.Get("JS.BSC.UI.Ws.UserReport.Error.Desc"), null, guid, "info");
				}
				if (data.reportType == "Applicant")
				{ GO("/Rating"); return; }
			}, "json", guid);
		};
		return {
			/// <summary></summary>
			/// <param name="data"></param>
			/// <return></return>
			Bind: bind,

			/// <summary></summary>
			/// <param name="data"></param>
			/// <return></return>
			Unbind: unbind,

			/// <summary></summary>
			/// <param name="data"></param>
			/// <return></return>
			Send: send
		};
	} ();
})();
BSC.E.Subscribe("bind", BSC.UI.Ws.Feedback.Bind, null, "feedback");
BSC.E.Subscribe("unbind", BSC.UI.Ws.Feedback.Unbind, null, "feedback");



(function()
{
	BSC.Require("BSC.UI.Ws.Feedback");
	BSC.UI.Ws.Feedback.ReportProfile = function()
	{
		/// <summary>
		/// Bind events to ui elements
		/// </summary>
		var bind = function(p1)
		{
			var guid = p1;
			$("#" + guid + "_report").bind("click", guid, function(e)
			{
				var guid = e.data;
				var w = BSC.UI.Ws.Get(guid);
				if (!w.data.id) return;

				//var reasons = $("#" + guid + " input[type='radio']").fieldArray();
				var reasons = $("#" + guid + " input.checkbox.report").fieldArray();
				var additionalComments = "" + $("#" + guid + "_additionalcomments").getValue();

				var data =
				{
					reportType: "Profile",
					reasons: reasons,
					additionalComments: additionalComments
				};

				BSC.UI.Ws.Feedback.Send(guid, data, w.data.id);
			});
			$("#" + guid + "_reportCancel").bind("click", guid, function(e)
			{
				var guid = e.data;
				BSC.UI.W.Close(guid);
			});
		};

		/// <summary>
		/// Unbind events to ui elements
		/// </summary>
		var unbind = function(p1)
		{
			var guid = p1;
			$("#" + guid + "_report").unbind();
			$("#" + guid + "_reportCancel").unbind();
		};
		return {
			/// <summary></summary>
			/// <param name="data"></param>
			/// <return></return>
			Bind: bind,

			/// <summary></summary>
			/// <param name="data"></param>
			/// <return></return>
			Unbind: unbind
		};
	} ();
})();
BSC.E.Subscribe("bind", BSC.UI.Ws.Feedback.ReportProfile.Bind, null, "feedback.reportprofile");
BSC.E.Subscribe("unbind", BSC.UI.Ws.Feedback.ReportProfile.Unbind, null, "feedback.reportprofile");





(function()
{
	BSC.Require("BSC.UI.Ws.Feedback");
	BSC.UI.Ws.Feedback.ReportApplicant = function()
	{
		/// <summary>
		/// Bind events to ui elements
		/// </summary>
		var bind = function(p1)
		{
			var guid = p1;
			$("#" + guid + "_report").bind("click", guid, function(e)
			{
				var guid = e.data;
				var w = BSC.UI.Ws.Get(guid);
				if (!w.data.id) return;

				var reasons = $("#" + guid + " input.checkbox.report").fieldArray();
				var additionalComments = "" + $("#" + guid + "_additionalcomments").getValue();

				var data =
				{
					reportType: "Applicant",
					reasons: reasons,
					additionalComments: additionalComments
				};

				BSC.UI.Ws.Feedback.Send(guid, data, w.data.id);
			});
			$("#" + guid + "_reportCancel").bind("click", guid, function(e)
			{
				var guid = e.data;
				BSC.UI.W.Close(guid);
			});
		};

		/// <summary>
		/// Unbind events to ui elements
		/// </summary>
		var unbind = function(p1)
		{
			var guid = p1;
			$("#" + guid + "_report").unbind();
			$("#" + guid + "_reportCancel").unbind();
		};
		return {
			/// <summary></summary>
			/// <param name="data"></param>
			/// <return></return>
			Bind: bind,

			/// <summary></summary>
			/// <param name="data"></param>
			/// <return></return>
			Unbind: unbind
		};
	} ();
})();
BSC.E.Subscribe("bind", BSC.UI.Ws.Feedback.ReportApplicant.Bind, null, "feedback.reportapplicant");
BSC.E.Subscribe("unbind", BSC.UI.Ws.Feedback.ReportApplicant.Unbind, null, "feedback.reportapplicant");


