You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/BookingWeb/Content/js/common.js

147 lines
3.9 KiB
JavaScript

function checkPwdStrong(pwd) {
var c0 = pwd.length >= 6;
var c1 = /[a-z]+/.test(pwd);
var c2 = /[A-Z]+/.test(pwd);
var c3 = /[0-9]+/.test(pwd);
if (c0 && c1 && c2 && c3) {
return true;
}
return false;
}
$.fn.serializeObject = function () {
var o = {};
var a = this.serializeArray();
$.each(a, function () {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
}
$.fn.toJson = function () {
var self = this,
json = {},
push_counters = {},
patterns = {
"validate": /^[a-zA-Z][a-zA-Z0-9_]*(?:\[(?:\d*|[a-zA-Z0-9_]+)\])*$/,
"key": /[a-zA-Z0-9_]+|(?=\[\])/g,
"push": /^$/,
"fixed": /^\d+$/,
"named": /^[a-zA-Z0-9_]+$/
};
this.build = function (base, key, value) {
base[key] = value;
return base;
};
this.push_counter = function (key) {
if (push_counters[key] === undefined) {
push_counters[key] = 0;
}
return push_counters[key]++;
};
$.each($(this).serializeArray(), function () {
// skip invalid keys
if (!patterns.validate.test(this.name)) {
return;
}
var k,
keys = this.name.match(patterns.key),
merge = this.value,
reverse_key = this.name;
while ((k = keys.pop()) !== undefined) {
// adjust reverse_key
reverse_key = reverse_key.replace(new RegExp("\\[" + k + "\\]$"), '');
// push
if (k.match(patterns.push)) {
merge = self.build([], self.push_counter(reverse_key), merge);
}
// fixed
else if (k.match(patterns.fixed)) {
merge = self.build([], k, merge);
}
// named
else if (k.match(patterns.named)) {
merge = self.build({}, k, merge);
}
}
json = $.extend(true, json, merge);
});
return json;
};
$.fn.loadData = function (obj) {
var key, value, tagName, type, arr;
this.resetForm();
for (var x in obj) {
if (obj.hasOwnProperty(x)) {
key = x;
value = obj[x];
this.find("[name='" + key + "'],[name='" + key + "[]']").each(function () {
tagName = $(this)[0].tagName.toUpperCase();
type = $(this).attr('type');
if (tagName == 'INPUT') {
if (type == 'radio') {
if ($(this).val() == value) {
$(this).attr('checked', true);
}
} else if (type == 'checkbox') {
if (value) {
$(this).prop('checked', true);
} else {
$(this).prop('checked', false);
}
} else {
$(this).val(value);
}
} else if (tagName == 'SELECT' || tagName == 'TEXTAREA') {
$(this).val(value);
}
});
}
}
}
$(function () {
$(document).on('click', 'a.tabs', function () {
var url = $(this).data('url');
if (url != undefined && url.length > 0) {
var title = $(this).data('title');
if (title == undefined) {
title = "New Page";
}
//debugger;
if (url.indexOf('?') > -1) {
url += "&rnd=" + new Date()
} else {
url += "?rnd=" + new Date()
}
parent.addMenuTab(url, title, 0)
}
});
})