Request Cash Advance is ready up to point where writing to db
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Web;
|
||||
using System.Web.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Summary description for FieldValidation
|
||||
/// </summary>
|
||||
[WebService(Namespace = "http://tempuri.org/")]
|
||||
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
|
||||
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
|
||||
[System.Web.Script.Services.ScriptService]
|
||||
public class FieldValidation : System.Web.Services.WebService {
|
||||
|
||||
public FieldValidation () {
|
||||
|
||||
//Uncomment the following line if using designed components
|
||||
//InitializeComponent();
|
||||
}
|
||||
|
||||
[WebMethod]
|
||||
public bool IsAmountValid (string amount)
|
||||
{
|
||||
// Determine correct culture for parsing
|
||||
|
||||
CultureInfo culture = null;
|
||||
|
||||
// Set default culture (English, United States, but that doesn't work so fake it to GB)
|
||||
|
||||
string preferredCulture = "en-GB";
|
||||
|
||||
// ----------- SET CULTURE ------------
|
||||
|
||||
// Does the user have a culture preference?
|
||||
|
||||
if (HttpContext.Current.Request.Cookies["PreferredCulture"] != null)
|
||||
{
|
||||
// Yes, set it
|
||||
preferredCulture = HttpContext.Current.Request.Cookies["PreferredCulture"].Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
// No, determine from browser
|
||||
string browserPreference = "en-GB";
|
||||
if (HttpContext.Current.Request.UserLanguages != null && HttpContext.Current.Request.UserLanguages.Length > 0)
|
||||
{
|
||||
browserPreference = HttpContext.Current.Request.UserLanguages[0];
|
||||
preferredCulture = browserPreference;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
culture = CultureInfo.CreateSpecificCulture(preferredCulture);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
culture = CultureInfo.InvariantCulture;
|
||||
}
|
||||
|
||||
// Try to parse the string we got as a double
|
||||
|
||||
try
|
||||
{
|
||||
Double.Parse(HttpUtility.UrlDecode(amount), NumberStyles.Number, culture);
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<%@ WebService Language="C#" CodeBehind="~/App_Code/FieldValidation.cs" Class="FieldValidation" %>
|
||||
@@ -10,7 +10,6 @@
|
||||
<script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.js" ></script>
|
||||
<script language="javascript" type="text/javascript" src="/Scripts/jquery.leanModal.min.js" ></script>
|
||||
<script language="javascript" type="text/javascript" src="/Scripts/jquery.qtip.js" ></script>
|
||||
<script language="javascript" type="text/javascript" src="/Scripts/alertify.js" ></script>
|
||||
|
||||
<!-- fonts -->
|
||||
<link href='https://fonts.googleapis.com/css?family=Permanent+Marker' rel='stylesheet' type='text/css' />
|
||||
@@ -317,7 +316,11 @@
|
||||
<div style="display:none"><asp:TextBox runat="server" ID="TextSwitchToOrganizationId" /><asp:Button runat="server" ID="ButtonActuatorSwitchOrganizations" OnClick="ButtonSwitchOrganizations_Click"/></div>
|
||||
|
||||
</form>
|
||||
|
||||
<!-- some javascript in footer -->
|
||||
|
||||
<script language="javascript" type="text/javascript" src="/Scripts/alertify.min.js" ></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
@@ -11,21 +11,51 @@
|
||||
$('input.combo-text').click(function () {
|
||||
$('span.combo-arrow').click();
|
||||
});
|
||||
|
||||
alertify.success('test');
|
||||
});
|
||||
|
||||
|
||||
function validateFields() {
|
||||
var isValid = true;
|
||||
|
||||
isValid = validateTextField('#<%=this.TextAccount.ClientID %>', "Please state your bank account number.") && isValid;
|
||||
isValid = validateTextField('#<%=this.TextClearing.ClientID %>', "Please enter your bank's clearing number.") && isValid;
|
||||
isValid = validateTextField('#<%=this.TextBank.ClientID %>', "Please enter your bank's name.") && isValid;
|
||||
|
||||
if ($('#DropBudgets').combotree('tree').tree('getSelected') == null) {
|
||||
isValid = false;
|
||||
alertify.error('test');
|
||||
alertify.error("Please select a budget.");
|
||||
}
|
||||
|
||||
isValid = validateTextField('#<%=this.TextPurpose.ClientID %>', "Please state the purpose of the cash advance.") && isValid;
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/Automation/FieldValidation.asmx/IsAmountValid",
|
||||
data: "{'amount': '" + escape($('#<%=this.TextAmount.ClientID %>').val()) + "'}",
|
||||
contentType: "application/json; charset=utf-8",
|
||||
dataType: "json",
|
||||
async: false, // blocks until function returns - race conditions otherwise
|
||||
success: function (msg) {
|
||||
if (msg.d != true) {
|
||||
isValid = false;
|
||||
alertify.error("Please enter the amount of money (in SEK) that you'd like to advance.");
|
||||
$('#<%=this.TextAmount.ClientID %>').focus();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return isValid;
|
||||
}
|
||||
|
||||
function validateTextField (fieldId, message) {
|
||||
if ($(fieldId).val().length == 0) {
|
||||
alertify.error(message);
|
||||
$(fieldId).focus();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
</script>␍</asp:Content>
|
||||
|
||||
|
||||
+387
-347
@@ -1,347 +1,387 @@
|
||||
/**
|
||||
* Alertify
|
||||
* An unobtrusive customizable JavaScript notification system
|
||||
*
|
||||
* @author Fabien Doiron <fabien.doiron@gmail.com>
|
||||
* @copyright Fabien Doiron 2012
|
||||
* @license MIT <http://opensource.org/licenses/mit-license.php>
|
||||
* @link http://www.github.com/fabien-d
|
||||
* @module Alertify
|
||||
* @version 0.1.1
|
||||
*/
|
||||
|
||||
/*global define*/
|
||||
(function (global, undefined) {
|
||||
"use strict";
|
||||
|
||||
var document = global.document,
|
||||
Alertify;
|
||||
|
||||
Alertify = function () {
|
||||
|
||||
var $, addListeners, bind, build, close, hide, init, notify, setup, unbind,
|
||||
dialog, extend, log,
|
||||
cover, dialogs, delay, element, isopen, keys, labels, logElement, queue;
|
||||
|
||||
dialogs = {
|
||||
buttons : {
|
||||
holder : "<nav class=\"alertify-buttons\">{{buttons}}</nav>",
|
||||
ok : "<a href=\"#\" class=\"alertify-button alertify-button-ok\" id=\"aOK\">{{ok}}</a>",
|
||||
cancel : "<a href=\"#\" class=\"alertify-button alertify-button-cancel\" id=\"aCancel\">{{cancel}}</a>"
|
||||
},
|
||||
input : "<input type=\"text\" class=\"alertify-text\" id=\"aText\">",
|
||||
message : "<p class=\"alertify-message\">{{message}}</p>",
|
||||
log : "<article class=\"alertify-log{{class}}\">{{message}}</article>"
|
||||
};
|
||||
|
||||
delay = 5000;
|
||||
keys = { ENTER: 13, ESC: 27 };
|
||||
labels = { ok: "OK", cancel: "Cancel" };
|
||||
queue = [];
|
||||
isopen = false;
|
||||
|
||||
/**
|
||||
* Shorthand for document.getElementById()
|
||||
*
|
||||
* @param {String} id A specific element ID
|
||||
|
||||
* @return {Object} HTML element
|
||||
*/
|
||||
$ = function (id) {
|
||||
return document.getElementById(id);
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the proper button click events
|
||||
*
|
||||
* @param {Function} fn [Optional] Callback function
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
addListeners = function (fn) {
|
||||
var btnOK = $("aOK") || undefined,
|
||||
btnCancel = $("aCancel") || undefined,
|
||||
input = $("aText") || undefined,
|
||||
hasOK = (typeof btnOK !== "undefined"),
|
||||
hasCancel = (typeof btnCancel !== "undefined"),
|
||||
val = "",
|
||||
ok, cancel, common, key;
|
||||
|
||||
// ok event handler
|
||||
ok = function (event) {
|
||||
common(event);
|
||||
if (typeof input !== "undefined") val = input.value;
|
||||
if (typeof fn === "function") fn(true, val);
|
||||
if (typeof event.preventDefault !== "undefined") event.preventDefault();
|
||||
};
|
||||
|
||||
// cancel event handler
|
||||
cancel = function (event) {
|
||||
common(event);
|
||||
if (typeof fn === "function") fn(false);
|
||||
if (typeof event.preventDefault !== "undefined") event.preventDefault();
|
||||
};
|
||||
|
||||
// common event handler (keyup, ok and cancel)
|
||||
common = function (event) {
|
||||
hide();
|
||||
unbind(document.body, "keyup", key);
|
||||
};
|
||||
|
||||
// keyup handler
|
||||
key = function (event) {
|
||||
var keyCode = event.keyCode;
|
||||
if (keyCode === keys.ENTER && hasOK) ok(event);
|
||||
else if (keyCode === keys.ESC && hasCancel) cancel(event);
|
||||
};
|
||||
|
||||
// handle OK click
|
||||
if (hasOK) bind(btnOK, "click", ok);
|
||||
// handle Cancel click
|
||||
if (hasCancel) bind(btnCancel, "click", cancel);
|
||||
|
||||
// clear focus off activeElement element to ensure
|
||||
// the ENTER key triggers the correct behaviour
|
||||
// Firefox has an issue if this isn't done and the current
|
||||
// focus is an anchor
|
||||
document.activeElement.blur();
|
||||
// listen for keys, OK => ENTER, Cancel => ESC
|
||||
bind(document.body, "keyup", key);
|
||||
};
|
||||
|
||||
/**
|
||||
* Bind events to elements
|
||||
*
|
||||
* @param {Object} el HTML Object
|
||||
* @param {Event} event Event to attach to element
|
||||
* @param {Function} fn Callback function
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
bind = function (el, event, fn) {
|
||||
if (typeof el.addEventListener === "function") {
|
||||
el.addEventListener(event, fn, false);
|
||||
} else if (el.attachEvent) {
|
||||
el.attachEvent("on" + event, fn);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Build the proper message box
|
||||
*
|
||||
* @param {Object} item Current object in the queue
|
||||
* @return {String} An HTML string of the message box
|
||||
*/
|
||||
build = function (item) {
|
||||
var html = "",
|
||||
type = item.type,
|
||||
message = item.message;
|
||||
|
||||
html += "<div class=\"alertify-dialog\">";
|
||||
html += "<article class=\"alertify-inner\">";
|
||||
html += dialogs.message.replace("{{message}}", message);
|
||||
|
||||
if (type === "prompt") { html += dialogs.input; }
|
||||
|
||||
html += dialogs.buttons.holder;
|
||||
html += "</article>";
|
||||
html += "</div>";
|
||||
|
||||
switch (type) {
|
||||
case "confirm":
|
||||
case "prompt":
|
||||
html = html.replace("{{buttons}}", dialogs.buttons.cancel + dialogs.buttons.ok);
|
||||
html = html.replace("{{ok}}", labels.ok).replace("{{cancel}}", labels.cancel);
|
||||
break;
|
||||
case "alert":
|
||||
html = html.replace("{{buttons}}", dialogs.buttons.ok);
|
||||
html = html.replace("{{ok}}", labels.ok);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
element.className = "alertify alertify-show alertify-" + type;
|
||||
cover.className = "alertify-cover";
|
||||
return html;
|
||||
};
|
||||
|
||||
/**
|
||||
* Close the log messages
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
close = function () {
|
||||
setTimeout(function () {
|
||||
var child = logElement.childNodes[logElement.childNodes.length - 1];
|
||||
if (typeof child !== "undefined") logElement.removeChild(child);
|
||||
}, delay);
|
||||
};
|
||||
|
||||
/**
|
||||
* Hide the dialog and rest to defaults
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
hide = function () {
|
||||
// remove reference from queue
|
||||
queue.splice(0,1);
|
||||
// if items remaining in the queue
|
||||
if (queue.length > 0) setup();
|
||||
else {
|
||||
isopen = false;
|
||||
element.className = "alertify alertify-hide alertify-hidden";
|
||||
cover.className = "alertify-cover alertify-hidden";
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize Alertify
|
||||
* Create the 2 main elements
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
init = function () {
|
||||
// ensure legacy browsers support html5 tags
|
||||
document.createElement("nav");
|
||||
document.createElement("article");
|
||||
document.createElement("section");
|
||||
// cover
|
||||
cover = document.createElement("div");
|
||||
cover.setAttribute("id", "alertifycover");
|
||||
cover.className = "alertify-cover alertify-hidden";
|
||||
document.body.appendChild(cover);
|
||||
// main element
|
||||
element = document.createElement("section");
|
||||
element.setAttribute("id", "alertify");
|
||||
element.className = "alertify alertify-hidden";
|
||||
document.body.appendChild(element);
|
||||
// main element
|
||||
logElement = document.createElement("section");
|
||||
logElement.setAttribute("id", "alertifylogs");
|
||||
logElement.className = "alertify-logs";
|
||||
document.body.appendChild(logElement);
|
||||
};
|
||||
|
||||
/**
|
||||
* Add new log message
|
||||
* If a type is passed, a class name "alertify-log-{type}" will get added.
|
||||
* This allows for custom look and feel for various types of notifications.
|
||||
*
|
||||
* @param {String} message The message passed from the callee
|
||||
* @param {String} type [Optional] Type of log message
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
notify = function (message, type) {
|
||||
var log = document.createElement("article");
|
||||
log.className = "alertify-log" + ((typeof type === "string" && type !== "") ? " alertify-log-" + type : "");
|
||||
log.innerHTML = message;
|
||||
// prepend child
|
||||
logElement.insertBefore(log, logElement.firstChild);
|
||||
// triggers the CSS animation
|
||||
setTimeout(function() { log.className = log.className + " alertify-log-show"; }, 50);
|
||||
close();
|
||||
};
|
||||
|
||||
/**
|
||||
* Initiate all the required pieces for the dialog box
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
setup = function () {
|
||||
var item = queue[0];
|
||||
|
||||
isopen = true;
|
||||
element.innerHTML = build(item);
|
||||
addListeners(item.callback);
|
||||
// adding focus to prompt input box
|
||||
// doesn't work without a setTimeout...
|
||||
if (item.type === "prompt") global.setTimeout(function () { document.getElementById("aText").focus(); }, 0);
|
||||
};
|
||||
|
||||
/**
|
||||
* Unbind events to elements
|
||||
*
|
||||
* @param {Object} el HTML Object
|
||||
* @param {Event} event Event to detach to element
|
||||
* @param {Function} fn Callback function
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
unbind = function (el, event, fn) {
|
||||
if (typeof el.removeEventListener === "function") {
|
||||
el.removeEventListener(event, fn, false);
|
||||
} else if (el.detachEvent) {
|
||||
el.detachEvent("on" + event, fn);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a dialog box
|
||||
*
|
||||
* @param {String} message The message passed from the callee
|
||||
* @param {String} type Type of dialog to create
|
||||
* @param {Function} fn [Optional] Callback function
|
||||
*
|
||||
* @return {Object}
|
||||
*/
|
||||
dialog = function (message, type, fn) {
|
||||
// error catching
|
||||
if (typeof message !== "string") throw new Error("message must be a string");
|
||||
if (typeof type !== "string") throw new Error("type must be a string");
|
||||
if (typeof fn !== "undefined" && typeof fn !== "function") throw new Error("fn must be a function");
|
||||
|
||||
queue.push({ type: type, message: message, callback: fn });
|
||||
if (!isopen) setup();
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Extend the log method to create custom methods
|
||||
*
|
||||
* @param {String} type Custom method name
|
||||
* @return {Function}
|
||||
*/
|
||||
extend = function (type) {
|
||||
return function (message) { log(message, type); };
|
||||
};
|
||||
|
||||
/**
|
||||
* Show a new log message box
|
||||
*
|
||||
* @param {String} message The message passed from the callee
|
||||
* @param {String} type [Optional] Optional type of log message
|
||||
*
|
||||
* @return {Object}
|
||||
*/
|
||||
log = function (message, type) {
|
||||
notify(message, type);
|
||||
return this;
|
||||
};
|
||||
|
||||
// Bootstrap
|
||||
init();
|
||||
|
||||
return {
|
||||
alert : function (message, fn) { dialog(message, "alert", fn); return this; },
|
||||
confirm : function (message, fn) { dialog(message, "confirm", fn); return this; },
|
||||
extend : extend,
|
||||
log : log,
|
||||
prompt : function (message, fn) { dialog(message, "prompt", fn); return this; },
|
||||
success : function (message) { log(message, "success"); return this; },
|
||||
error : function (message) { log(message, "error"); return this; },
|
||||
delay : delay,
|
||||
labels : labels
|
||||
};
|
||||
};
|
||||
|
||||
// AMD and window support
|
||||
if (typeof define === "function") {
|
||||
define([], function () { return new Alertify(); });
|
||||
} else {
|
||||
if (typeof global.alertify === "undefined") { global.alertify = new Alertify(); }
|
||||
}
|
||||
|
||||
}(this));
|
||||
/*global define*/
|
||||
(function (global, undefined) {
|
||||
"use strict";
|
||||
|
||||
var document = global.document,
|
||||
Alertify;
|
||||
|
||||
Alertify = function () {
|
||||
|
||||
var $, addListeners, bind, build, close, hide, init, notify, setup, unbind,
|
||||
dialog, extend, log,
|
||||
cover, dialogs, delay, element, isopen, keys, labels, logElement, queue;
|
||||
|
||||
dialogs = {
|
||||
buttons: {
|
||||
holder: "<nav class=\"alertify-buttons\">{{buttons}}</nav>",
|
||||
submit: "<button type=\"submit\" class=\"alertify-button alertify-button-ok\" id=\"aOK\" />{{ok}}</button>",
|
||||
ok: "<a href=\"#\" class=\"alertify-button alertify-button-ok\" id=\"aOK\">{{ok}}</a>",
|
||||
cancel: "<a href=\"#\" class=\"alertify-button alertify-button-cancel\" id=\"aCancel\">{{cancel}}</a>"
|
||||
},
|
||||
input: "<input type=\"text\" class=\"alertify-text\" id=\"aText\">",
|
||||
message: "<p class=\"alertify-message\">{{message}}</p>",
|
||||
log: "<article class=\"alertify-log{{class}}\">{{message}}</article>"
|
||||
};
|
||||
|
||||
delay = 5000;
|
||||
keys = { ENTER: 13, ESC: 27, SPACE: 32 };
|
||||
labels = { ok: "OK", cancel: "Cancel" };
|
||||
queue = [];
|
||||
isopen = false;
|
||||
|
||||
/**
|
||||
* Shorthand for document.getElementById()
|
||||
*
|
||||
* @param {String} id A specific element ID
|
||||
|
||||
* @return {Object} HTML element
|
||||
*/
|
||||
$ = function (id) {
|
||||
return document.getElementById(id);
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the proper button click events
|
||||
*
|
||||
* @param {Function} fn [Optional] Callback function
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
addListeners = function (fn) {
|
||||
var btnReset = $("aResetFocus"),
|
||||
btnOK = $("aOK") || undefined,
|
||||
btnCancel = $("aCancel") || undefined,
|
||||
input = $("aText") || undefined,
|
||||
form = $("aForm") || undefined,
|
||||
hasOK = (typeof btnOK !== "undefined"),
|
||||
hasCancel = (typeof btnCancel !== "undefined"),
|
||||
hasInput = (typeof input !== "undefined"),
|
||||
val = "",
|
||||
ok, cancel, common, key, reset;
|
||||
|
||||
// ok event handler
|
||||
ok = function (event) {
|
||||
common(event);
|
||||
if (typeof input !== "undefined") val = input.value;
|
||||
if (typeof fn === "function") fn(true, val);
|
||||
if (typeof event.preventDefault !== "undefined") event.preventDefault();
|
||||
};
|
||||
|
||||
// cancel event handler
|
||||
cancel = function (event) {
|
||||
common(event);
|
||||
if (typeof fn === "function") fn(false);
|
||||
if (typeof event.preventDefault !== "undefined") event.preventDefault();
|
||||
};
|
||||
|
||||
// common event handler (keyup, ok and cancel)
|
||||
common = function (event) {
|
||||
hide();
|
||||
unbind(document.body, "keyup", key);
|
||||
unbind(btnReset, "focus", reset);
|
||||
if (hasInput) unbind(form, "submit", ok);
|
||||
if (hasOK) unbind(btnOK, "click", ok);
|
||||
if (hasCancel) unbind(btnCancel, "click", cancel);
|
||||
};
|
||||
|
||||
// keyup handler
|
||||
key = function (event) {
|
||||
var keyCode = event.keyCode;
|
||||
if (keyCode === keys.SPACE && !hasInput) ok(event);
|
||||
if (keyCode === keys.ESC && hasCancel) cancel(event);
|
||||
};
|
||||
|
||||
// reset focus to first item in the dialog
|
||||
reset = function (event) {
|
||||
if (hasInput) input.focus();
|
||||
else if (hasCancel) btnCancel.focus();
|
||||
else btnOK.focus();
|
||||
};
|
||||
|
||||
// handle reset focus link
|
||||
// this ensures that the keyboard focus does not
|
||||
// ever leave the dialog box until an action has
|
||||
// been taken
|
||||
bind(btnReset, "focus", reset);
|
||||
// handle OK click
|
||||
if (hasOK) bind(btnOK, "click", ok);
|
||||
// handle Cancel click
|
||||
if (hasCancel) bind(btnCancel, "click", cancel);
|
||||
// listen for keys, Cancel => ESC
|
||||
bind(document.body, "keyup", key);
|
||||
// bind form submit
|
||||
if (hasInput) bind(form, "submit", ok);
|
||||
// set focus on OK button or the input text
|
||||
global.setTimeout(function () {
|
||||
if (input) input.focus();
|
||||
else btnOK.focus();
|
||||
}, 50);
|
||||
};
|
||||
|
||||
/**
|
||||
* Bind events to elements
|
||||
*
|
||||
* @param {Object} el HTML Object
|
||||
* @param {Event} event Event to attach to element
|
||||
* @param {Function} fn Callback function
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
bind = function (el, event, fn) {
|
||||
if (typeof el.addEventListener === "function") {
|
||||
el.addEventListener(event, fn, false);
|
||||
} else if (el.attachEvent) {
|
||||
el.attachEvent("on" + event, fn);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Build the proper message box
|
||||
*
|
||||
* @param {Object} item Current object in the queue
|
||||
* @return {String} An HTML string of the message box
|
||||
*/
|
||||
build = function (item) {
|
||||
var html = "",
|
||||
type = item.type,
|
||||
message = item.message;
|
||||
|
||||
html += "<div class=\"alertify-dialog\">";
|
||||
|
||||
if (type === "prompt") html += "<form id=\"aForm\">";
|
||||
|
||||
html += "<article class=\"alertify-inner\">";
|
||||
html += dialogs.message.replace("{{message}}", message);
|
||||
|
||||
if (type === "prompt") html += dialogs.input;
|
||||
|
||||
html += dialogs.buttons.holder;
|
||||
html += "</article>";
|
||||
|
||||
if (type === "prompt") html += "</form>";
|
||||
|
||||
html += "<a id=\"aResetFocus\" class=\"alertify-resetFocus\" href=\"#\">Reset Focus</a>";
|
||||
html += "</div>";
|
||||
|
||||
switch (type) {
|
||||
case "confirm":
|
||||
html = html.replace("{{buttons}}", dialogs.buttons.cancel + dialogs.buttons.ok);
|
||||
html = html.replace("{{ok}}", labels.ok).replace("{{cancel}}", labels.cancel);
|
||||
break;
|
||||
case "prompt":
|
||||
html = html.replace("{{buttons}}", dialogs.buttons.cancel + dialogs.buttons.submit);
|
||||
html = html.replace("{{ok}}", labels.ok).replace("{{cancel}}", labels.cancel);
|
||||
break;
|
||||
case "alert":
|
||||
html = html.replace("{{buttons}}", dialogs.buttons.ok);
|
||||
html = html.replace("{{ok}}", labels.ok);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
element.className = "alertify alertify-show alertify-" + type;
|
||||
cover.className = "alertify-cover";
|
||||
return html;
|
||||
};
|
||||
|
||||
/**
|
||||
* Close the log messages
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
close = function (elem) {
|
||||
bind(elem, "click", function () {
|
||||
logElement.removeChild(elem);
|
||||
});
|
||||
setTimeout(function () {
|
||||
if (typeof elem !== "undefined" && elem.parentNode === logElement) logElement.removeChild(elem);
|
||||
}, delay);
|
||||
};
|
||||
|
||||
/**
|
||||
* Hide the dialog and rest to defaults
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
hide = function () {
|
||||
// remove reference from queue
|
||||
queue.splice(0, 1);
|
||||
// if items remaining in the queue
|
||||
if (queue.length > 0) setup();
|
||||
else {
|
||||
isopen = false;
|
||||
element.className = "alertify alertify-hide alertify-hidden";
|
||||
cover.className = "alertify-cover alertify-hidden";
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize Alertify
|
||||
* Create the 2 main elements
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
init = function () {
|
||||
// ensure legacy browsers support html5 tags
|
||||
document.createElement("nav");
|
||||
document.createElement("article");
|
||||
document.createElement("section");
|
||||
// cover
|
||||
cover = document.createElement("div");
|
||||
cover.setAttribute("id", "alertifycover");
|
||||
cover.className = "alertify-cover alertify-hidden";
|
||||
document.body.appendChild(cover);
|
||||
// main element
|
||||
element = document.createElement("section");
|
||||
element.setAttribute("id", "alertify");
|
||||
element.className = "alertify alertify-hidden";
|
||||
document.body.appendChild(element);
|
||||
// main element
|
||||
logElement = document.createElement("section");
|
||||
logElement.setAttribute("id", "alertifylogs");
|
||||
logElement.className = "alertify-logs";
|
||||
document.body.appendChild(logElement);
|
||||
// clean up init method
|
||||
delete this.init;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add new log message
|
||||
* If a type is passed, a class name "alertify-log-{type}" will get added.
|
||||
* This allows for custom look and feel for various types of notifications.
|
||||
*
|
||||
* @param {String} message The message passed from the callee
|
||||
* @param {String} type [Optional] Type of log message
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
notify = function (message, type) {
|
||||
var log = document.createElement("article");
|
||||
log.className = "alertify-log" + ((typeof type === "string" && type !== "") ? " alertify-log-" + type : "");
|
||||
log.innerHTML = message;
|
||||
// prepend child
|
||||
logElement.insertBefore(log, logElement.firstChild);
|
||||
// triggers the CSS animation
|
||||
setTimeout(function () { log.className = log.className + " alertify-log-show"; }, 50);
|
||||
close(log);
|
||||
};
|
||||
|
||||
/**
|
||||
* Initiate all the required pieces for the dialog box
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
setup = function () {
|
||||
var item = queue[0];
|
||||
|
||||
isopen = true;
|
||||
element.innerHTML = build(item);
|
||||
addListeners(item.callback);
|
||||
};
|
||||
|
||||
/**
|
||||
* Unbind events to elements
|
||||
*
|
||||
* @param {Object} el HTML Object
|
||||
* @param {Event} event Event to detach to element
|
||||
* @param {Function} fn Callback function
|
||||
*
|
||||
* @return {undefined}
|
||||
*/
|
||||
unbind = function (el, event, fn) {
|
||||
if (typeof el.removeEventListener === "function") {
|
||||
el.removeEventListener(event, fn, false);
|
||||
} else if (el.detachEvent) {
|
||||
el.detachEvent("on" + event, fn);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a dialog box
|
||||
*
|
||||
* @param {String} message The message passed from the callee
|
||||
* @param {String} type Type of dialog to create
|
||||
* @param {Function} fn [Optional] Callback function
|
||||
*
|
||||
* @return {Object}
|
||||
*/
|
||||
dialog = function (message, type, fn) {
|
||||
// check to ensure the alertify dialog element
|
||||
// has been successfully created
|
||||
var check = function () {
|
||||
if (element && element.scrollTop !== null) return;
|
||||
else check();
|
||||
};
|
||||
// error catching
|
||||
if (typeof message !== "string") throw new Error("message must be a string");
|
||||
if (typeof type !== "string") throw new Error("type must be a string");
|
||||
if (typeof fn !== "undefined" && typeof fn !== "function") throw new Error("fn must be a function");
|
||||
// initialize alertify if it hasn't already been done
|
||||
if (typeof this.init === "function") {
|
||||
this.init();
|
||||
check();
|
||||
}
|
||||
|
||||
queue.push({ type: type, message: message, callback: fn });
|
||||
if (!isopen) setup();
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Extend the log method to create custom methods
|
||||
*
|
||||
* @param {String} type Custom method name
|
||||
* @return {Function}
|
||||
*/
|
||||
extend = function (type) {
|
||||
return function (message) { log(message, type); };
|
||||
};
|
||||
|
||||
/**
|
||||
* Show a new log message box
|
||||
*
|
||||
* @param {String} message The message passed from the callee
|
||||
* @param {String} type [Optional] Optional type of log message
|
||||
*
|
||||
* @return {Object}
|
||||
*/
|
||||
log = function (message, type) {
|
||||
// check to ensure the alertify dialog element
|
||||
// has been successfully created
|
||||
var check = function () {
|
||||
if (logElement && logElement.scrollTop !== null) return;
|
||||
else check();
|
||||
};
|
||||
// initialize alertify if it hasn't already been done
|
||||
if (typeof this.init === "function") {
|
||||
this.init();
|
||||
check();
|
||||
}
|
||||
notify(message, type);
|
||||
return this;
|
||||
};
|
||||
|
||||
return {
|
||||
alert: function (message, fn) { dialog.call(this, message, "alert", fn); return this; },
|
||||
confirm: function (message, fn) { dialog.call(this, message, "confirm", fn); return this; },
|
||||
extend: extend,
|
||||
init: init,
|
||||
log: function (message, type) { log.call(this, message, type); return this; },
|
||||
prompt: function (message, fn) { dialog.call(this, message, "prompt", fn); return this; },
|
||||
success: function (message) { log.call(this, message, "success"); return this; },
|
||||
error: function (message) { log.call(this, message, "error"); return this; },
|
||||
delay: delay,
|
||||
labels: labels
|
||||
};
|
||||
};
|
||||
|
||||
// AMD and window support
|
||||
if (typeof define === "function") {
|
||||
define([], function () { return new Alertify(); });
|
||||
} else {
|
||||
if (typeof global.alertify === "undefined") { global.alertify = new Alertify(); }
|
||||
}
|
||||
|
||||
} (this));
|
||||
Vendored
+12
-12
File diff suppressed because one or more lines are too long
@@ -57,7 +57,7 @@
|
||||
-webkit-box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
font-size: 100%;
|
||||
font-size: 18px;
|
||||
}
|
||||
.alertify-buttons {
|
||||
}
|
||||
@@ -82,11 +82,12 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* Default Look and Feel
|
||||
* Default Look and Feel - modified for Activizr
|
||||
*/
|
||||
.alertify,
|
||||
.alertify-log {
|
||||
font-family: sans-serif;
|
||||
font-family: Ubuntu, sans-serif;
|
||||
font-size: 15px;
|
||||
}
|
||||
.alertify {
|
||||
background: #FFF;
|
||||
@@ -143,13 +144,27 @@
|
||||
padding: 15px;
|
||||
border-radius: 4px;
|
||||
color: #FFF;
|
||||
text-shadow: -1px -1px 0 rgba(0,0,0,.5);
|
||||
text-shadow: 0px 0px rgba(0,0,0,.5);
|
||||
}
|
||||
.alertify-log-error {
|
||||
background: #FE1A00;
|
||||
background: rgba(254,26,0,.9);
|
||||
background-color: #FF8080;
|
||||
background: hsla(0,89%,78%,.9);
|
||||
border: 2px solid #FE1A00;
|
||||
box-shadow: 0px 0px 1px 1px #D83526 inset, 0px 2px 3px 1px #400000;
|
||||
font-weight: 400;
|
||||
color: #A00000;
|
||||
}
|
||||
.alertify-log-success {
|
||||
background: #5CB811;
|
||||
background: rgba(92,184,17,.9);
|
||||
}
|
||||
|
||||
|
||||
|
||||
p.alertify-message {
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
a#aResetFocus {
|
||||
display: none;
|
||||
}
|
||||
@@ -880,9 +880,13 @@ div.RadToolTip table.rtWrapper td.rtWrapperContent
|
||||
|
||||
/* COLOR SCHEME
|
||||
|
||||
#A2BEFF #476EC7 #1C397E #C8D9FF #E4ECFF -- blue (hue 240)
|
||||
#FFBC37 #C78B15 #7F5500 #FFD580 #FFEDC8 -- orange (hue 60)
|
||||
#A2BEFF #476EC7 #1C397E #C8D9FF #E4ECFF -- blue (hue 222)
|
||||
#FFBC37 #C78B15 #7F5500 #FFD580 #FFEDC8 -- orange (hue 40)
|
||||
|
||||
base dark xdark light xlight
|
||||
|
||||
S36L100 S64-L78 S78-L49 S22B100 S11L100 -- blue (hue 222)
|
||||
S78L100 S89-L78 S100L50 S50L100 S22L100 -- orange (hue 40)
|
||||
|
||||
*/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user