easyappointments/doc/code/js/general_functions.js.html
alextselegidis@gmail.com f0fd08e444 * Updated database structure and added new sample data.
* Regenerated code docs (js + php).
* Added custom error 404 page.
* Added service price and description in the appointment booking wizard.
* Completed Issue #21 - devide services in categories in the appointment booking wizard.
* Completed the backend user management page.
2013-09-13 13:21:03 +00:00

277 lines
9.6 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: general_functions.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: general_functions.js</h1>
<section>
<article>
<pre class="prettyprint source"><code>/**
* This file contains the General Functions javascript namespace.
* It contains functions that apply both on the front and back
* end of the application.
*
* @namespace GeneralFunctions
*/
var GeneralFunctions = {
/**
* This functions displays a message box in
* the admin array. It is usefull when user
* decisions or verifications are needed.
*
* @param {string} title The title of the message box.
* @param {string} message The message of the dialog.
* @param {array} messageButtons Contains the dialog
* buttons along with their functions.
*/
displayMessageBox: function(title, message, messageButtons) {
// Check arguments integrity.
if (title == undefined || title == "") {
title = "&lt;No Title Given>";
}
if (message == undefined || message == "") {
message = "&lt;No Message Given>";
}
if (messageButtons == undefined) {
messageButtons = {
Close: function() {
jQuery("#message_box").dialog("close");
}
};
}
// Destroy previous dialog instances.
jQuery("#message_box").dialog("destroy");
jQuery("#message_box").remove();
// Create the html of the message box.
jQuery("body").append(
"&lt;div id='message_box' title='" + title + "'>" +
"&lt;p>" + message + "&lt;/p>" +
"&lt;/div>"
);
jQuery("#message_box").dialog({
autoOpen: false,
modal: true,
resize: "auto",
width: 400,
height: "auto",
resizable: false,
buttons: messageButtons,
closeOnEscape: false
});
jQuery("#message_box").dialog("open");
jQuery("#message_box .ui-dialog-titlebar-close").hide();
},
/**
* This method centers a DOM element vertically and horizontally
* on the page.
*
* @param {object} elementHandle The object that is going to be
* centered.
*/
centerElementOnPage: function(elementHandle) {
// Center main frame vertical middle
$(window).resize(function() {
var elementLeft = ($(window).width() - elementHandle.outerWidth()) / 2;
var elementTop = ($(window).height() - elementHandle.outerHeight()) / 2;
elementTop = (elementTop > 0 ) ? elementTop : 20;
elementHandle.css({
position: 'absolute',
left: elementLeft,
top: elementTop
});
});
$(window).resize();
},
/**
* This function retrieves a parameter from a "GET" formed url.
*
* @link http://www.netlobo.com/url_query_string_javascript.html
*
* @param {string} url The selected url.
* @param {string} name The parameter name.
* @returns {String} Returns the parameter value.
*/
getUrlParameter: function(url, parameterName) {
parameterName = parameterName.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\#&]"+parameterName+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( url );
if( results == null )
return "";
else
return results[1];
},
/**
* This function creates a RFC 3339 date string. This string is needed
* by the Google Calendar API in order to pass dates as parameters.
*
* @param {date} dt The given date that will be transformed
* @returns {String} Returns the transformed string.
*/
ISODateString: function(dt){
function pad(n){return n&lt;10 ? '0'+n : n;}
return dt.getUTCFullYear()+'-'
+ pad(dt.getUTCMonth()+1)+'-'
+ pad(dt.getUTCDate())+'T'
+ pad(dt.getUTCHours())+':'
+ pad(dt.getUTCMinutes())+':'
+ pad(dt.getUTCSeconds())+'Z';
},
/**
* This method creates and returns an exact copy of the provided object.
* It is very usefull whenever changes need to be made to an object without
* modyfing the original data.
*
* @link http://stackoverflow.com/questions/728360/most-elegant-way-to-clone-a-javascript-object
*
* @param {object} originalObject Object to be copied.
* @returns {object} Returns an exact copy of the provided element.
*/
clone: function(originalObject) {
// Handle the 3 simple types, and null or undefined
if (null == originalObject || "object" != typeof originalObject)
return originalObject;
// Handle Date
if (originalObject instanceof Date) {
var copy = new Date();
copy.setTime(originalObject.getTime());
return copy;
}
// Handle Array
if (originalObject instanceof Array) {
var copy = [];
for (var i = 0, len = originalObject.length; i &lt; len; i++) {
copy[i] = GeneralFunctions.clone(originalObject[i]);
}
return copy;
}
// Handle Object
if (originalObject instanceof Object) {
var copy = {};
for (var attr in originalObject) {
if (originalObject.hasOwnProperty(attr))
copy[attr] = GeneralFunctions.clone(originalObject[attr]);
}
return copy;
}
throw new Error("Unable to copy obj! Its type isn't supported.");
},
/**
* This method validates an email address. If the address is not on the proper
* form then the result is FALSE.
*
* @param {string} email The email address to be checked.
* @returns {bool} Returns the validation result.
*/
validateEmail: function(email) {
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
return reg.test(email);
},
/**
* This method returns the exception html display for javascript ajax calls.
* It uses the Bootstrap collapse module to show exception messages when the
* user opens the "Details" collapse component.
*
* @param {array} exceptions Contains the exceptions to be displayed.
* @returns {String} Returns the html markup for the exceptions.
*/
exceptionsToHtml: function(exceptions) {
var html =
'&lt;div class="accordion" id="error-accordion">' +
'&lt;div class="accordion-group">' +
'&lt;div class="accordion-heading">' +
'&lt;a class="accordion-toggle" data-toggle="collapse" ' +
'data-parent="#error-accordion" href="#error-technical">' +
'Details' +
'&lt;/a>' +
'&lt;/div>';
$.each(exceptions, function(index, exception) {
html +=
'&lt;div id="error-technical" class="accordion-body collapse">' +
'&lt;div class="accordion-inner">' +
'&lt;pre>' + exception['message'] + '&lt;/pre>' +
'&lt;/div>' +
'&lt;/div>';
});
html += '&lt;/div>&lt;/div>';
return html;
},
/**
* This method parse the json encoded strings that are fetched by ajax calls.
*
* @param {array} exceptions Exception array returned by an ajax call.
* @returns {Array} Returns the parsed js objects.
*/
parseExceptions: function(exceptions) {
var parsedExceptions = new Array();
$.each(exceptions, function(index, exception) {
parsedExceptions.push(jQuery.parseJSON(exception));
});
return parsedExceptions;
}
};</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Index</a></h2><h3>Classes</h3><ul><li><a href="AdminsHelper.html">AdminsHelper</a></li><li><a href="CategoriesHelper.html">CategoriesHelper</a></li><li><a href="ProvidersHelper.html">ProvidersHelper</a></li><li><a href="SecretariesHelper.html">SecretariesHelper</a></li><li><a href="ServicesHelper.html">ServicesHelper</a></li></ul><h3>Namespaces</h3><ul><li><a href="Backend.html">Backend</a></li><li><a href="Customers.html">Backend Customers</a></li><li><a href="BackendCalendar.html">BackendCalendar</a></li><li><a href="BackendServices.html">BackendServices</a></li><li><a href="BackendUsers..html">BackendUsers.</a></li><li><a href="FrontendBook.html">FrontendBook</a></li><li><a href="GeneralFunctions.html">GeneralFunctions</a></li></ul>
</nav>
<br clear="both">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.2.0-dev</a> on Fri Sep 13 2013 11:50:16 GMT+0300 (EEST)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>