Commit b05cb446 authored by Sven Franck's avatar Sven Franck

replaced JIO with AJAX, added validation, themes

parent 59aeb853
html body .ui-input-text.invalid {
border: 1px solid red !important;
}
.bold {
font-weight: bold;
}
......
......@@ -311,6 +311,246 @@ html .ui-page-theme-aide-white .ui-collapsible-set .ui-collapsible h1 a.ui-btn:h
background: -ms-linear-gradient(bottom, #fff, #e8e8e8);
}
/* aide-brown */
/*-----------------------------------------------------------------------------------------------------------*/
/* Bar: Toolbars, dividers, slider track */
hr {
display: block;
height: 1px;
border: 0;
border-top: 1px solid #aaa;
margin: 1em 0;
padding: 0;
}
.ui-bar-aide-brown,
.ui-page-theme-aide-brown .ui-bar-inherit,
html .ui-bar-aide-brown.ui-table-wrapper-top,
html .ui-bar-aide-brown.ui-table-wrapper-bottom,
html .ui-bar-aide-brown .ui-bar-inherit,
html .ui-body-aide-brown .ui-bar-inherit,
html body .ui-group-theme-aide-brown .ui-bar-inherit {
background: 0 none;
background-color: #ECE4C9;
color: #000;
text-shadow: none;
border-color: #ECE4C9;
font-weight: normal;
}
.ui-bar-aide-brown {
border-width: 1px;
border-style: solid;
}
/* tables & controlbar & tabs */
html .ui-page-theme-aide-brown .ui-table-wrapper.ui-table-wrapper-top .ui-btn,
html .ui-page-theme-aide-brown .ui-table-wrapper.ui-table-wrapper-top .ui-plain-text,
html .ui-page-theme-aide-brown .ui-table-wrapper.ui-table-wrapper-bottom .ui-btn,
html .ui-page-theme-aide-brown .ui-table-wrapper.ui-table-wrapper-bottom .ui-plain-text,
html .ui-page-theme-aide-brown .ui-controlbar .ui-btn,
html .ui-page-theme-aide-brown .ui-collapsible-set .ui-collapsible h1 a.ui-btn,
html .ui-page-theme-aide-brown .ui-table thead a.ui-btn,
html .ui-page-theme-aide-brown .ui-table thead label{
color: #000;
text-shadow: #ccc 0px 1px 0px;
}
html .ui-page-theme-aide-brown .ui-table {
background-color: #ECE4C9;
border-color: #ECE4C9;
}
html .ui-page-theme-aide-brown .ui-table-wrapper,
html .ui-page-theme-aide-brown .ui-popup .ui-header,
html .ui-page-theme-aide-brown .ui-popup .ui-footer,
html .ui-page-theme-aide-brown .ui-table-wrapper .ui-btn,
html .ui-page-theme-aide-brown .ui-collapsible-set .ui-collapsible h1 a.ui-btn {
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#ECE4C9), to(#E9DDB5));
background: -webkit-linear-gradient(bottom, #ECE4C9, #E9DDB5);
background: linear-gradient(bottom, #ECE4C9, #E9DDB5);
background: -moz-linear-gradient(bottom, #ECE4C9, #E9DDB5);
background: -o-linear-gradient(bottom, #ECE4C9, #E9DDB5);
background: -ms-linear-gradient(bottom, #ECE4C9, #E9DDB5);
border-color: #ECE4C9;
}
/* Page: background */
.ui-page-theme-aide-brown,
.ui-page-theme-aide-brown .ui-panel-wrapper {
color: #000;
text-shadow: none;
background: #ECE4C9;
}
/* Body: Read-only lists, text inputs, collapsible content */
.ui-body-aide-brown,
.ui-page-theme-aide-brown .ui-body-inherit,
html .ui-bar-aide-brown .ui-body-inherit,
html .ui-body-aide-brown .ui-body-inherit,
html body .ui-group-theme-aide-brown .ui-body-inherit,
.ui-overlay-aide-brown {
background-image: none;
background: #ECE4C9;
border-color: #aaa;
color: #000;
text-shadow: none;
}
.ui-body-aide-brown {
border-width: 1px;
border-style: solid;
}
/* Links */
.ui-page-theme-aide-brown a,
html .ui-bar-aide-brown a,
html .ui-body-aide-brown a
/* visited */
.ui-page-theme-aide-brown a:visited,
html .ui-bar-aide-brown a:visited,
html .ui-body-aide-brown a:visited,
html body .ui-group-theme-aide-brown a:visited,
/* hover */
.ui-overlay-aide-brown a:hover,
.ui-page-theme-aide-brown a:hover,
html .ui-bar-aide-brown a:hover,
html .ui-body-aide-brown a:hover,
html body .ui-group-theme-aide-brown a:hover,
.ui-overlay-aide-brown .ui-btn:hover,
.ui-page-theme-aide-brown .ui-btn:hover,
html .ui-bar-aide-brown .ui-btn:hover,
html .ui-body-aide-brown .ui-btn:hover,
html body .ui-group-theme-aide-brown .ui-btn:hover,
/* texts */
html body .ui-group-theme-aide-brown p, /* overwritten by ui-btn */
html body .ui-group-theme-aide-brown h1,
html body .ui-group-theme-aide-brown h2,
html body .ui-group-theme-aide-brown h3,
html body .ui-group-theme-aide-brown h4,
html body .ui-group-theme-aide-brown h5,
html body .ui-group-theme-aide-brown h6 {
color: #000;
}
.ui-page-theme-aide-brown .ui-btn:active,
html .ui-bar-aide-brown .ui-btn:active,
html .ui-body-aide-brown .ui-btn:active,
html body .ui-group-theme-aide-brown .ui-btn:active {
color: #000;
}
/* Button up */
.ui-page-theme-aide-brown .ui-btn,
html .ui-bar-aide-brown .ui-btn,
html .ui-body-aide-brown .ui-btn,
html body .ui-btn.ui-btn-aide-brown,
html body .ui-group-theme-aide-brown .ui-btn,
[class*="ui-group-theme-"] .ui-btn.ui-btn-aide-brown,
.ui-page-theme-aide-brown .ui-bar-plain,
/* Button visited */
.ui-page-theme-aide-brown .ui-btn:visited,
html .ui-bar-aide-brown .ui-btn:visited,
html .ui-body-aide-brown .ui-btn:visited,
html body .ui-btn.ui-btn-aide-brown:visited,
html body .ui-group-theme-aide-brown .ui-btn:visited,
[class*="ui-group-theme-"] .ui-btn.ui-btn-aide-brown:visited,
/* table wrappers
html .ui-page-theme-aide-brown .ui-table-wrapper-top,
html .ui-page-theme-aide-brown .ui-table-wrapper-bottom,*/
html .ui-page-theme-aide-brown .ui-table-wrapper-top ~ table,
html .ui-page-theme-aide-brown .ui-table-wrapper-bottom ~ table,
html .ui-page-theme-aide-brown table tr td a:visited {
background: #ECE4C9;
color: #000;
text-shadow: none;
border-color: #ECE4C9;
}
html .ui-page-theme-aide-brown .ui-input-clear:active,
html .ui-page-theme-aide-brown .ui-input-clear.ui-btn-active,
html .ui-page-theme-aide-brown .ui-input-action:active,
html .ui-page-theme-aide-brown .ui-input-action.ui-btn-active {
background: #ECE4C9 !important;
}
/* Header Buttons */
.ui-page-theme-aide-brown .ui-header .ui-btn,
html .ui-bar-aide-brown .ui-header .ui-btn,
html .ui-bar-aide-brown.ui-header .ui-btn,
html .ui-body-aide-brown .ui-header .ui-btn,
html body .ui-header .ui-btn.ui-btn-aide-brown,
html body .ui-header .ui-group-theme-aide-brown .ui-btn,
.ui-header [class*="ui-group-theme-"] .ui-btn.ui-btn-aide-brown,
/* Button visited */
.ui-page-theme-aide-brown .ui-header .ui-btn:visited,
html .ui-bar-aide-brown .ui-header .ui-btn:visited,
html .ui-body-aide-brown .ui-header .ui-btn:visited,
html body .ui-header .ui-btn.ui-btn-aide-brown:visited,
html body .ui-header .ui-group-theme-aide-brown .ui-btn:visited,
.ui-header [class*="ui-group-theme-"] .ui-btn.ui-btn-aide-brown:visited,
.ui-page-theme-aide-brown .ui-header a:visited,
html .ui-bar-aide-brown .ui-header a:visited,
html .ui-body-aide-brown .ui-header a:visited,
html body .ui-header a.ui-btn-aide-brown:visited,
html body .ui-header .ui-group-theme-aide-brown a:visited,
.ui-header [class*="ui-group-theme-"] a.ui-btn-aide-brown:visited {
background: none repeat scroll 0 center transparent;
border: 0 none;
-webkit-border-radius: 0 0 0 0 /* iOS3 */ !important;
border-radius: 0 0 0 0 /* iOS3 */ !important;
-webkit-box-shadow: none /* iOS3 */ !important;
box-shadow: none /* iOS3 */ !important;
color: rgb(129, 137, 138);
color: rgba(0, 0, 0, 0.25);
text-shadow: none;
font-weight: normal;
line-height: 325% /* could also be 3.25em, but this is more flexible, while being crap! */;
}
/* Button special handling: panel listitems */
.ui-page-theme-aide-brown .ui-panel-inner li .ui-btn,
html .ui-bar-aide-brown .ui-panel-inner li .ui-btn,
html .ui-body-aide-brown .ui-panel-inner li .ui-btn,
html body .ui-panel-inner li .ui-btn.ui-btn-aide-brown,
html body .ui-panel-inner li .ui-group-theme-aide-brown .ui-btn,
[class*="ui-group-theme-"] .ui-panel-inner li .ui-btn.ui-btn-aide-brown,
/* Button visited */
.ui-page-theme-aide-brown .ui-panel-inner li .ui-btn:visited,
html .ui-bar-aide-brown .ui-panel-inner li .ui-btn:visited,
html .ui-body-aide-brown .ui-panel-inner li .ui-btn:visited,
html body .ui-panel-inner li .ui-btn.ui-btn-aide-brown:visited,
html body .ui-panel-inner li .ui-group-theme-aide-brown .ui-btn:visited,
[class*="ui-group-theme-"] .ui-panel-inner li .ui-btn.ui-btn-aide-brown:visited {
background: none repeat scroll 0 0 transparent;
border-color: #ECE4C9;
}
/* dropshadow */
html body .ui-group-theme-aide-brown li {
border-top: 1px solid #111;
}
html body .ui-group-theme-aide-brown li.ui-last-child {
border-top: 1px solid #111;
border-bottom: 1px solid #111;
}
html body .ui-group-theme-aide-orange li.ui-last-child a.ui-btn {
border-bottom: none
}
/* Button background hover */
.ui-page-theme-aide-brown .ui-btn:hover,
html .ui-bar-aide-brown .ui-btn:hover,
html .ui-body-aide-brown .ui-btn:hover,
html body .ui-btn.ui-btn-aide-brown:hover,
html body .ui-group-theme-aide-brown .ui-btn:hover,
[class*="ui-group-theme-"] .ui-btn.ui-btn-aide-brown:hover,
/* table wrapper buttons */
html .ui-page-theme-aide-brown .ui-table-wrapper .ui-btn:hover,
/* table rows */
html .ui-page-theme-aide-brown table tr th:hover ~ td,
/* controlbars */
html .ui-page-theme-aide-brown .ui-controlbar .ui-btn:hover,
/* tabs */
html .ui-page-theme-aide-brown .ui-collapsible-set .ui-collapsible h1 a.ui-btn:hover {
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#ECE4C9), to(#E9DDB5));
background: -webkit-linear-gradient(bottom, #ECE4C9, #E9DDB5);
background: linear-gradient(bottom, #ECE4C9, #E9DDB5);
background: -moz-linear-gradient(bottom, #ECE4C9, #E9DDB5);
background: -o-linear-gradient(bottom, #ECE4C9, #E9DDB5);
background: -ms-linear-gradient(bottom, #ECE4C9, #E9DDB5);
border-color: #ECE4C9;
}
......@@ -1576,7 +1816,18 @@ html .ui-select .ui-btn-icon-right:after {
background: transparent;
}
/* header logo, careful, no more buttons possible! */
html .ui-header .ui-header-logo img {
max-height: 37px;
padding: 2px 0.5em;
vertical-align: middle;
}
@media (max-width: 40em) {
html .ui-header .ui-header-logo ~ h1 {
margin-right: 1em;
text-align: right;
}
}
/* breadcrumbs - need work!
......
......@@ -296,7 +296,7 @@
"enabled": true,
"editable": true,
"external_validator": null,
"required": null,
"required": true,
"preserve_whitespace": null,
"unicode": null,
"maximum_length": null,
......@@ -337,7 +337,7 @@
"enabled": true,
"editable": true,
"external_validator": null,
"required": null,
"required": true,
"preserve_whitespace": null,
"unicode": null,
"maximum_length": null,
......@@ -378,7 +378,7 @@
"enabled": true,
"editable": true,
"external_validator": undefined,
"required": undefined,
"required": true,
"preserve_whitespace": undefined,
"truncate": undefined,
"start": undefined,
......@@ -423,7 +423,7 @@
"enabled": true,
"editable": true,
"external_validator": undefined,
"required": undefined,
"required": true,
"preserve_whitespace": undefined,
"truncate": undefined,
"start": undefined,
......@@ -452,9 +452,10 @@
};
/* ====================================================================== */
/* GADGET Configuration */
/* APP Configuration */
/* ====================================================================== */
// Everything loosely definable as a gadget...
// Everything that eventually should be a gadget!
priv.gadget_properties = {
/* ******************************************************************** */
......@@ -470,7 +471,13 @@
"fixed": true,
"global": true,
"theme": "aide-orange",
"controls": []
"controls": [],
"logo": {
"wrap":"left",
"src": "img/aea.png",
"alt": "Aide et Action",
"alt_i18n": ""
}
},
/* ==================================================================== */
......@@ -484,9 +491,16 @@
"datasource": "Persons",
"portal_type_title":"person",
"type": "default",
"form": true,
"form_id": null,
"form_validation": false,
// hm...
"form": {
"direct":{
"id": "form_get_subscriptions",
"className": "jio_trigger validate"
},
"attributes": {
"data-reference": "getSomeSubscriptions"
}
},
"layout": [
{
"blocks": [
......@@ -508,10 +522,12 @@
"type": "a",
"direct": {
"href": "payments.html",
"className": "translate action_new ui-link ui-btn ui-btn-inline ui-shadow ui-corner-all ui-icon-signout ui-btn-active ui-corner-all ui-btn-icon-right ui-first-child ui-last-child"
"className": "ui-btn-aide-brown translate action_submit ui-link ui-btn ui-btn-inline ui-shadow ui-corner-all ui-icon-signout ui-corner-all ui-btn-icon-right ui-first-child ui-last-child"
},
"attributes": {
"data-type": "networks",
"data-theme": "aide-brown",
"data-type": "person",
"data-form": "form_get_subscriptions",
"data-role":"button",
"data-icon":"signout",
"data-i18n":"",
......@@ -576,9 +592,10 @@
"type": "a",
"direct": {
"href": "update.html",
"className": "translate action_new ui-link ui-btn ui-btn-inline ui-shadow ui-corner-all ui-btn-active ui-corner-all ui-first-child ui-last-child"
"className": "translate action_new ui-link ui-btn ui-btn-inline ui-shadow ui-corner-all ui-btn-aide-brown ui-corner-all ui-first-child ui-last-child"
},
"attributes": {
"data-theme": "aide-brown",
"data-role":"button",
"data-rel": "back",
"data-i18n":"",
......@@ -590,6 +607,7 @@
}
};
/* ====================================================================== */
/* METHODS */
/* ====================================================================== */
......@@ -1033,33 +1051,6 @@
return string.charAt(0).toUpperCase() + string.slice(1);
};
/* ********************************************************************** */
/* JIO Setup & Access */
/* ********************************************************************** */
priv.url = "http://192.168.242.86:12002/erp5";
priv.mode = "generic";
priv.auth_type = "none";
priv.username = "zope";
priv.password = "insecure";
priv.encoded_login = null;
// // ERP5 connect
// priv.erp5 = jIO.newJio({
// "type": "erp5",
// "url": priv.url,
// "username": priv.username,
// "password": priv.password
// });
priv.erp5 = jIO.createJIO({
"type": "local",
"username": "erp5",
"application_name": "dump"
}, {
"workspace": {}
});
/* ====================================================================== */
/* GENERATORS */
......@@ -1334,7 +1325,15 @@
"data-position": config.fixed ? "fixed" : undefined
}
);
if (config.logo) {
wrap = priv.generateElement("div", {"className":"ui-header-logo wrap " + config.logo.wrap});
wrap.appendChild(priv.generateElement(
"img",
{"src": config.logo.src, "alt":config.logo.alt},
{"data-i18n":"[alt]"}
));
header.appendChild(wrap);
}
if (config.controls && config.controls.length > 0) {
for (i = 0; i < config.controls.length; i += 1) {
direction = i === 0 ? "left" : "right";
......@@ -1610,7 +1609,7 @@
wrap.appendChild(priv.generateElement(
priv.mapFieldType(overrides.type || config.type),
{
"className": (overrides.css_class || config.widget.css_class || "") + ((overrides.required || config.widget.required) ? "required" : ""),
"className": (overrides.css_class || config.widget.css_class || "") + " " + ((overrides.required || config.validator.required) ? "required" : ""),
"id": overrides.id || config.widget.id
},
{},
......@@ -1652,22 +1651,28 @@
priv.constructFieldlist = function (element) {
var i,
k,
l,
m,
j,
field,
config,
overrides,
content,
box,
action,
section,
fragment = window.document.createDocumentFragment(),
fragment,
gadget_id = element.getAttribute("data-gadget-id"),
settings = priv.gadget_properties[gadget_id],
portal_type = settings.portal_type_title,
$parent = $(element.parentNode);
if (settings !== undefined) {
if (settings.form !== undefined) {
fragment = priv.generateElement(
"form", settings.form.direct, (settings.form.attributes || undefined), (settings.form.logic || undefined)
);
} else {
fragment = window.document.createDocumentFragment();
}
for (i = 0; i < settings.layout.length; i += 1) {
section = settings.layout[i];
if (section.blocks) {
......@@ -1708,24 +1713,44 @@
/**
* Create listbox table
* @method constructListbox
* @param {object} element Base table to enhance
* @param {object} properties for internal use
* @param {object} element Base element to replace with table/listbox
* @param {object} answer Data to build the gadget
* @param {string} internal id where to place element
*/
priv.constructListbox = function (element, internal) {
var no_data_body,
priv.constructListbox = function (element, answer, internal) {
var i,
j,
l,
opts = [],
config,
shortcut,
fragment_container,
search_popup,
controlbar,
caption_slot,
group_slot,
detail_slot,
configure_slot,
pagination_wrap,
pagination_slot,
// table
table,
table_header,
table_body,
table_settings,
page,
// mh
no_data_body,
no_data_cell,
portable,
limit,
$parent,
gadget_id = element.getAttribute("data-gadget-id") || internal,
settings = priv.gadget_properties[gadget_id],
portal_type = settings ? settings.portal_type_title : undefined,
// wrapper
$parent,
parent = element.parentNode,
// deferred
dfd = new $.Deferred();
portal_type = settings ? settings.portal_type_title : undefined;
if (internal) {
// only used for bindings
$parent = $(document);
} else {
$parent = $(element.parentNode);
......@@ -1733,396 +1758,356 @@
// TODO: fetch default/user specified configuration
if (settings !== undefined) {
if (settings.configuration.pagination.show) {
limit = settings.configuration.pagination.items_per_page_select[0];
} else {
limit = 30;
}
// fetch data
portable = priv.erp5.allDocs({
"query": "type: \"" + settings.datasource + "\"",
"limit": [0, limit],
"wildcard_character": "%",
"include_docs": true
}).always(function (answer) {
var i,
j,
l,
opts = [],
config,
shortcut,
fragment_container,
search_popup,
controlbar,
caption_slot,
group_slot,
detail_slot,
configure_slot,
pagination_wrap,
pagination_slot,
// table
table,
table_header,
table_body,
table_settings,
page;
// fragment container
fragment_container = window.document.createDocumentFragment();
shortcut = settings.configuration;
// ==================== controlbar ===============================
controlbar = priv.generateElement("div", {"className":"ui-controlbar"},{},{});
// global_search
if (shortcut.global_search.show) {
controlbar.appendChild(priv.generateElement("input",
{
"id": shortcut.global_search.search_field_reference_id || "",
"type": "search"
}, {
"placeholder": "Search " + priv.capitaliseFirstLetter(portal_type),
"data-icon": "search",
"data-action-btn": "true"
}, {}
));
}
controlbar.appendChild(priv.generateElement("span",
{"className":"ui-plain-text"},{},{}
// fragment container
fragment_container = window.document.createDocumentFragment();
shortcut = settings.configuration;
// ==================== controlbar ===============================
controlbar = priv.generateElement("div", {"className":"ui-controlbar"},{},{});
// global_search
if (shortcut.global_search.show) {
controlbar.appendChild(priv.generateElement("input",
{
"id": shortcut.global_search.search_field_reference_id || "",
"type": "search"
}, {
"placeholder": "Search " + priv.capitaliseFirstLetter(portal_type),
"data-icon": "search",
"data-action-btn": "true"
}, {}
));
// record_info
if (shortcut.record_info.show) {
controlbar.lastChild.appendChild(priv.generateElement("span",
{"className":"erp5_" + portal_type + "_records_info"},{},{}
));
}
// select_info
if (shortcut.select_info.show) {
controlbar.lastChild.appendChild(priv.generateElement("span",
{"className":"erp5_" + portal_type + "_select_info"},{},{}
));
}
// filter_info
if (shortcut.group_search.show) {
controlbar.lastChild.appendChild(priv.generateElement("span",
{"className":"erp5_" + portal_type + "_filter_info"},{},{}
));
}
fragment_container.appendChild(controlbar);
}
controlbar.appendChild(priv.generateElement("span",
{"className":"ui-plain-text"},{},{}
));
// record_info
if (shortcut.record_info.show) {
controlbar.lastChild.appendChild(priv.generateElement("span",
{"className":"erp5_" + portal_type + "_records_info"},{},{}
));
}
// select_info
if (shortcut.select_info.show) {
controlbar.lastChild.appendChild(priv.generateElement("span",
{"className":"erp5_" + portal_type + "_select_info"},{},{}
));
}
// filter_info
if (shortcut.group_search.show) {
controlbar.lastChild.appendChild(priv.generateElement("span",
{"className":"erp5_" + portal_type + "_filter_info"},{},{}
));
}
fragment_container.appendChild(controlbar);
// ==================== wrapper elements ===============================
// TODO: bundle...
// caption
if (shortcut.caption.show) {
caption_slot = priv.generateElement("div",
{},
{"data-slot": true, "data-slot-id": shortcut.caption.slot}
);
caption_slot.appendChild(priv.generateElement("p",
{},
{"data-i18n": shortcut.caption.title_i18n},
{"text": shortcut.caption.title}
));
fragment_container.appendChild( caption_slot );
}
// group-filter
if (shortcut.group_search.show) {
search_popup = true;
group_slot = priv.generateElement("div",
{},
{"data-slot": "true", "data-slot-id":shortcut.group_search.slot}
);
group_slot.appendChild(priv.generateElement("a",
{"className": "extended_search", "href": "#search_" + portal_type},
{"data-reference":"groups", "data-rel":"popup", "data-transition":"pop","data-position-to":"window", "data-role":"button", "data-icon":"sitemap"},
{"text":"Group"}
));
fragment_container.appendChild( group_slot );
}
// ==================== wrapper elements ===============================
// TODO: bundle...
// caption
if (shortcut.caption.show) {
caption_slot = priv.generateElement("div",
{},
{"data-slot": true, "data-slot-id": shortcut.caption.slot}
);
caption_slot.appendChild(priv.generateElement("p",
{},
{"data-i18n": shortcut.caption.title_i18n},
{"text": shortcut.caption.title}
));
fragment_container.appendChild( caption_slot );
}
// group-filter
if (shortcut.group_search.show) {
search_popup = true;
group_slot = priv.generateElement("div",
{},
{"data-slot": "true", "data-slot-id":shortcut.group_search.slot}
);
group_slot.appendChild(priv.generateElement("a",
{"className": "extended_search", "href": "#search_" + portal_type},
{"data-reference":"groups", "data-rel":"popup", "data-transition":"pop","data-position-to":"window", "data-role":"button", "data-icon":"sitemap"},
{"text":"Group"}
));
fragment_container.appendChild( group_slot );
}
// detail search
if (shortcut.detail_search.show) {
search_popup = true;
detail_slot = priv.generateElement("div",
{},
{"data-slot": "true", "data-slot-id":shortcut.detail_search.slot}
);
detail_slot.appendChild(priv.generateElement("a",
{"className": "extended_search", "href": "#search_" + portal_type},
{"data-reference":"details", "data-rel":"popup", "data-transition":"pop","data-position-to":"window", "data-role":"button", "data-icon":"filter"},
{"text":"Extended Search"}
));
fragment_container.appendChild( detail_slot );
}
// detail search
if (shortcut.detail_search.show) {
search_popup = true;
detail_slot = priv.generateElement("div",
{},
{"data-slot": "true", "data-slot-id":shortcut.detail_search.slot}
);
detail_slot.appendChild(priv.generateElement("a",
{"className": "extended_search", "href": "#search_" + portal_type},
{"data-reference":"details", "data-rel":"popup", "data-transition":"pop","data-position-to":"window", "data-role":"button", "data-icon":"filter"},
{"text":"Extended Search"}
));
fragment_container.appendChild( detail_slot );
}
// configure search
if (shortcut.configure_search.show) {
search_popup = true;
configure_slot = priv.generateElement("div",
{},
{"data-slot": "true", "data-slot-id":shortcut.configure_search.slot}
);
configure_slot.appendChild(priv.generateElement("a",
{"className": "extended_search", "href": "#search_" + portal_type},
{"data-reference":"configure", "data-rel":"popup", "data-transition":"pop","data-position-to":"window", "data-role":"button", "data-icon":"cog"},
{"text":"Configuration"}
));
fragment_container.appendChild( configure_slot );
}
// configure search
if (shortcut.configure_search.show) {
search_popup = true;
configure_slot = priv.generateElement("div",
{},
{"data-slot": "true", "data-slot-id":shortcut.configure_search.slot}
);
configure_slot.appendChild(priv.generateElement("a",
{"className": "extended_search", "href": "#search_" + portal_type},
{"data-reference":"configure", "data-rel":"popup", "data-transition":"pop","data-position-to":"window", "data-role":"button", "data-icon":"cog"},
{"text":"Configuration"}
));
fragment_container.appendChild( configure_slot );
}
// ==================== wrapper popup ===============================
if (search_popup) {
fragment_container.appendChild(priv.generateElement("div",
{"id": "search_" + portal_type, "className": "ui-popup-wide"},
{"data-role":"popup", "data-tolerance":"30,30,30,30","data-theme":"aide-white"},
{}
));
}
// ==================== wrapper popup ===============================
if (search_popup) {
fragment_container.appendChild(priv.generateElement("div",
{"id": "search_" + portal_type, "className": "ui-popup-wide"},
{"data-role":"popup", "data-tolerance":"30,30,30,30","data-theme":"aide-white"},
{}
));
}
// ==================== pagination ===============================
if (shortcut.pagination.show) {
pagination_wrap = priv.generateElement("div",
{"className":"ui-controlgroup ui-controlgroup-horizontal"},
{"data-role":"controlgroup", "data-type":"horizontal"},
{}
);
for (i = 0; i < 5; i += 1) {
if (i !== 2) {
pagination_wrap.appendChild(priv.generateElement("a",
{"href":"#"},
{"data-role":"button", "data-iconpos":"notext", "data-icon": shortcut.pagination.icons[i]},
{"text":shortcut.pagination.icons[i]}
));
} else {
for (j = 0; j < shortcut.pagination.items_per_page_select.length; j += 1) {
opts.push({
"value":shortcut.pagination.items_per_page_select[j],
"text":shortcut.pagination.items_per_page_select[j]
});
}
pagination_wrap.appendChild(priv.generateElement("label",
{"className":"ui-hidden-accessible"},
{"for": portal_type + "_number_of_records"},
{"text":"Number of records"}
));
pagination_wrap.appendChild(priv.generateElement("select",
{"id":portal_type + "_number_of_records","name":portal_type + "_number_of_records"},
{"data-iconpos":"notext", "data-icon":shortcut.pagination.icons[i]},
{"options":opts}
));
// ==================== pagination ===============================
if (shortcut.pagination.show) {
pagination_wrap = priv.generateElement("div",
{"className":"ui-controlgroup ui-controlgroup-horizontal"},
{"data-role":"controlgroup", "data-type":"horizontal"},
{}
);
for (i = 0; i < 5; i += 1) {
if (i !== 2) {
pagination_wrap.appendChild(priv.generateElement("a",
{"href":"#"},
{"data-role":"button", "data-iconpos":"notext", "data-icon": shortcut.pagination.icons[i]},
{"text":shortcut.pagination.icons[i]}
));
} else {
for (j = 0; j < shortcut.pagination.items_per_page_select.length; j += 1) {
opts.push({
"value":shortcut.pagination.items_per_page_select[j],
"text":shortcut.pagination.items_per_page_select[j]
});
}
pagination_wrap.appendChild(priv.generateElement("label",
{"className":"ui-hidden-accessible"},
{"for": portal_type + "_number_of_records"},
{"text":"Number of records"}
));
pagination_wrap.appendChild(priv.generateElement("select",
{"id":portal_type + "_number_of_records","name":portal_type + "_number_of_records"},
{"data-iconpos":"notext", "data-icon":shortcut.pagination.icons[i]},
{"options":opts}
));
}
pagination_slot = priv.generateElement("div",
{},
{"data-slot":"true", "data-slot-id":shortcut.pagination.slot},
{}
);
pagination_slot.appendChild(pagination_wrap);
fragment_container.appendChild( pagination_slot );
}
pagination_slot = priv.generateElement("div",
{},
{"data-slot":"true", "data-slot-id":shortcut.pagination.slot},
{}
);
pagination_slot.appendChild(pagination_wrap);
fragment_container.appendChild( pagination_slot );
}
// ==================== table header ===============================
table_header = priv.generateTableHeader(settings, portal_type);
// ==================== table header ===============================
table_header = priv.generateTableHeader(settings, portal_type);
// ==================== table body ==================================
table_body = priv.generateTableBody(settings, answer, portal_type);
// ==================== table body ==================================
table_body = priv.generateTableBody(settings, answer, portal_type);
// ==================== table footer ================================
// TODO: add
// ==================== table footer ================================
// TODO: add
// reset config
table_settings = settings.layout.jqm_table_properties;
config = {};
config["data-role"] = "table";
config["data-mode"] = table_settings.view;
if (shortcut.global_search.show) {
config["data-filter"] = "true";
config["data-input"] = "#" + shortcut.global_search.search_field_reference_id || "";
}
if (table_settings.toggle) {
if (table_settings.view === "columntoggle") {
config["data-column-btn-text"] = table_settings.text;
config["data-column-btn-icon"] = table_settings.icon;
config["data-column-btn-theme"] = table_settings.theme;
}
} else {
config["data-column-btn-show"] = false;
}
if (settings.layout.wrappers) {
config["data-wrapper-theme"] = settings.layout.wrappers.theme || shortcut.theme;
config["data-wrap"] = settings.layout.wrappers.type;
config["data-top-grid"] = settings.layout.wrappers.top || 1;
config["data-bottom-grid"] = settings.layout.wrappers.bottom || 1;
config["data-embedded"] = settings.layout.wrappers.embedded || null;
}
if (shortcut.sorting) {
config["data-sort"] = "true";
// reset config
table_settings = settings.layout.jqm_table_properties;
config = {};
config["data-role"] = "table";
config["data-mode"] = table_settings.view;
if (shortcut.global_search.show) {
config["data-filter"] = "true";
config["data-input"] = "#" + shortcut.global_search.search_field_reference_id || "";
}
if (table_settings.toggle) {
if (table_settings.view === "columntoggle") {
config["data-column-btn-text"] = table_settings.text;
config["data-column-btn-icon"] = table_settings.icon;
config["data-column-btn-theme"] = table_settings.theme;
}
} else {
config["data-column-btn-show"] = false;
}
if (settings.layout.wrappers) {
config["data-wrapper-theme"] = settings.layout.wrappers.theme || shortcut.theme;
config["data-wrap"] = settings.layout.wrappers.type;
config["data-top-grid"] = settings.layout.wrappers.top || 1;
config["data-bottom-grid"] = settings.layout.wrappers.bottom || 1;
config["data-embedded"] = settings.layout.wrappers.embedded || null;
}
if (shortcut.sorting) {
config["data-sort"] = "true";
}
table = priv.generateElement(
"table",
{
"id":portal_type + "_1",
"className": "table-stroke ui-responsive" + (table_settings.highlight ? " ui-tr-highlight" : "")
},
config,
{}
);
table.appendChild(table_header);
table.appendChild(table_body);
// done
fragment_container.appendChild( table );
table = priv.generateElement(
"table",
{
"id":portal_type + "_1",
"className": "table-stroke ui-responsive" + (table_settings.highlight ? " ui-tr-highlight" : "")
},
config,
{}
);
table.appendChild(table_header);
table.appendChild(table_body);
if (settings.actions) {
for (l = 0; l < settings.actions.length; l += 1) {
fragment_container.appendChild(priv.generateControlgroup(settings.actions[l]));
}
}
// done
fragment_container.appendChild( table );
// popup content handling
if (search_popup) {
$parent.on("click", "a.extended_search", function (e) {
priv.generatePopupContents(e, "self", portal_type, settings.view, gadget_id);
});
if (settings.actions) {
for (l = 0; l < settings.actions.length; l += 1) {
fragment_container.appendChild(priv.generateControlgroup(settings.actions[l]));
}
}
// table actions
if (search_popup) {
// NOTE: can't bind to $parent, because JQM moves the popup
// outside of $parent
page = $parent.closest("div.ui-page");
if (page.data("bindings") === undefined) {
page.data("bindings", {});
}
if (page.data("bindings")["table_action"] === undefined) {
page.data("bindings")["table_action"] = true;
// popup content handling
if (search_popup) {
$parent.on("click", "a.extended_search", function (e) {
priv.generatePopupContents(e, "self", portal_type, settings.view, gadget_id);
});
}
$(document).on("click", "a.table_action", function (e) {
var target,
action = e.target.getAttribute("data-action"),
popup = $(e.target).closest(".ui-popup"),
form = popup.find("form");
// table actions
if (search_popup) {
// NOTE: can't bind to $parent, because JQM moves the popup
// outside of $parent
page = $parent.closest("div.ui-page");
if (form.length === 0) {
target = popup.find(".ui-content");
} else {
target = form;
}
switch (action) {
case "add_criteria_search":
target.append(priv.generateSearchCriteria(e.target))
.enhanceWithin();
break;
case "add_criteria_config":
target.append(priv.generateConfigCriteria(e.target))
.enhanceWithin();
break;
case "delete_criteria":
$(e.target).closest("div.ui-grid-row").remove();
break;
}
});
}
if (page.data("bindings") === undefined) {
page.data("bindings", {});
}
if (page.data("bindings")["table_action"] === undefined) {
page.data("bindings")["table_action"] = true;
// check all 3-state (none|all visible|all)
if (shortcut.checkbox.show) {
$parent.on("change", ".tick_all", function (e) {
var checkbox = e.target,
label = checkbox.previousSibling;
$(document).on("click", "a.table_action", function (e) {
var target,
action = e.target.getAttribute("data-action"),
popup = $(e.target).closest(".ui-popup"),
form = popup.find("form");
if (checkbox.checked) {
if (checkbox.indeterminate === false) {
checkbox.setAttribute("flag", true);
}
if (form.length === 0) {
target = popup.find(".ui-content");
} else {
if (checkbox.getAttribute("flag")) {
checkbox.removeAttribute("flag");
checkbox.indeterminate = true;
checkbox.checked = true;
label.className = label.className.replace(priv.filterForClass("ui-icon-checkbox-on"), ' ui-icon-globe');
e.preventDefault();
return false;
} else {
checkbox.indeterminate = false;
label.className = label.className.replace(priv.filterForClass("ui-icon-globe") , '');
}
target = form;
}
});
}
switch (action) {
case "add_criteria_search":
target.append(priv.generateSearchCriteria(e.target))
.enhanceWithin();
break;
// sorting 5-states (none|abc_asc|123_asc|abc_desc|123_desc)
if (shortcut.sorting) {
$parent.on("click", "a.ui-sorting", function (e) {
var button = e.target,
direction = button.getAttribute("data-direction"),
swapSortingState = function (direction, prev, next) {
button.setAttribute("data-direction", direction);
button.setAttribute("data-icon", next);
button.className = button.className.replace(
priv.filterForClass("ui-icon-" + prev), " ui-icon-" + next
);
};
switch (direction) {
case "descending_abc":
// parameters state | previous icon | new icon
swapSortingState(
"descending_123",
"sort-by-alphabet-alt",
"sort-by-order-alt"
);
break;
case "descending_123":
swapSortingState(
"ascending_abc",
"sort-by-order-alt",
"sort-by-alphabet"
);
break;
case "ascending_abc":
swapSortingState(
"ascending_123",
"sort-by-alphabet",
"sort-by-order"
);
break;
case "ascending_123":
swapSortingState(
undefined,
"sort-by-order",
"sort"
);
break;
default:
swapSortingState(
"descending_abc",
"sort",
"sort-by-alphabet-alt"
);
break;
case "add_criteria_config":
target.append(priv.generateConfigCriteria(e.target))
.enhanceWithin();
break;
case "delete_criteria":
$(e.target).closest("div.ui-grid-row").remove();
break;
}
});
}
}
// finish
// return to calling function
if (internal) {
dfd.resolve({message:"You did it!", element: fragment_container, target: element});
} else {
// or la viola - we touch the DOM once!!
// TODO: could be done with replaceChild but no way to call enhanceWithin on the parent
$parent.empty().append( fragment_container ).enhanceWithin();
//$(parent.replaceChild(fragment_container, element)).enhanceWithin();
// $parent.append( fragment_container ).remove( element ).enhanceWithin();
}
});
} else {
// check all 3-state (none|all visible|all)
if (shortcut.checkbox.show) {
$parent.on("change", ".tick_all", function (e) {
var checkbox = e.target,
label = checkbox.previousSibling;
if (checkbox.checked) {
if (checkbox.indeterminate === false) {
checkbox.setAttribute("flag", true);
}
} else {
if (checkbox.getAttribute("flag")) {
checkbox.removeAttribute("flag");
checkbox.indeterminate = true;
checkbox.checked = true;
label.className = label.className.replace(priv.filterForClass("ui-icon-checkbox-on"), ' ui-icon-globe');
e.preventDefault();
return false;
} else {
checkbox.indeterminate = false;
label.className = label.className.replace(priv.filterForClass("ui-icon-globe") , '');
}
}
});
}
// sorting 5-states (none|abc_asc|123_asc|abc_desc|123_desc)
if (shortcut.sorting) {
$parent.on("click", "a.ui-sorting", function (e) {
var button = e.target,
direction = button.getAttribute("data-direction"),
swapSortingState = function (direction, prev, next) {
button.setAttribute("data-direction", direction);
button.setAttribute("data-icon", next);
button.className = button.className.replace(
priv.filterForClass("ui-icon-" + prev), " ui-icon-" + next
);
};
switch (direction) {
case "descending_abc":
// parameters state | previous icon | new icon
swapSortingState(
"descending_123",
"sort-by-alphabet-alt",
"sort-by-order-alt"
);
break;
case "descending_123":
swapSortingState(
"ascending_abc",
"sort-by-order-alt",
"sort-by-alphabet"
);
break;
case "ascending_abc":
swapSortingState(
"ascending_123",
"sort-by-alphabet",
"sort-by-order"
);
break;
case "ascending_123":
swapSortingState(
undefined,
"sort-by-order",
"sort"
);
break;
default:
swapSortingState(
"descending_abc",
"sort",
"sort-by-alphabet-alt"
);
break;
}
});
}
// or la viola - we touch the DOM once!!
// TODO: not slottable as of now!
if (internal) {
dfd.reject({result:"Error: No data available"});
return fragment_container;
} else {
$parent.empty().append( fragment_container ).enhanceWithin();
}
} else {
// works...not!
element.appendChild(priv.generateElement("tbody")
.appendChild(priv.generateElement("tr")
......@@ -2133,8 +2118,6 @@
)
);
}
// end
return dfd.promise();
};
/*
......@@ -2397,17 +2380,10 @@
error,
table_body = priv.generateElement("tbody",{},{},{});
// TODO: still need a handler for no matching results
if (answer.data && answer.data.total_rows === 0) {
// HACK: provide static records
answer.data.rows = priv.getFakeRecords[portal_type]
answer.data.total_rows = answer.data.rows.length;
}
// data
if (answer.data && answer.data.total_rows > 0) {
for (l = 0; l < answer.data.total_rows; l += 1) {
item = answer.data.rows[l].doc;
if (answer && answer.length > 0) {
for (l = 0; l < answer.length; l += 1) {
item = answer[l].doc;
row = priv.generateTableRow(settings, item, portal_type);
table_body.appendChild(row);
}
......@@ -2416,10 +2392,10 @@
row = priv.generateElement("tr");
l = 0;
if (answer.data.total_rows === 0) {
if (answer === undefined) {
error = "Error retrieving Data";
} else if (answer.length === 0 ) {
error = "No records found. Please modify your search!";
} else {
error = "Error retrieving Data! Code: "+ error.status + ". Message: " + error.message + "."
}
if (settings.configuration.checkbox.show) {
......@@ -3327,15 +3303,96 @@
if (!set) {
document.documentElement.className += " init";
// append global popup
// NOTE: missing
// append global panel
// NOTE: must be before global toolbars!
if (priv.gadget_properties["application_menu"] !== undefined) {
document.body.appendChild(priv.generatePanel(
priv.gadget_properties["application_menu"]
));
}
// append global footer
if (priv.gadget_properties["application_footer"] !== undefined) {
document.body.appendChild(priv.generateFooter(
priv.gadget_properties["application_footer"]
));
}
// append global header
document.body.appendChild(priv.generateHeader(
priv.gadget_properties["application_header"]
));
if (priv.gadget_properties["application_header"] !== undefined) {
document.body.appendChild(priv.generateHeader(
priv.gadget_properties["application_header"]
));
}
// enhance
// NOTE: update layout and set .... (hey Romain: bindings)
$(document)
.enhanceWithin()
.off(".init");
.off(".init")
// global popup handler & content shuffle/caching
.on("click", "." + handler, function (e) {
var link = e.target,
reference = link.getAttribute("data-reference"),
rebuild = link.getAttribute("data-rebuild"),
id = link.getAttribute("href").replace("#",""),
pop = document.getElementById(id),
state = pop.getAttribute("data-reference");
if (reference !== state) {
pop.setAttribute("data-reference", reference);
}
// force rebuild of content
if (rebuild) {
pop.setAttribute("data-rebuild", "true");
}
})
// global form submit and client validation
// TODO: change as pleased
.on("click", ".action_submit", function (e) {
var valid,
form = document.getElementById(e.target.getAttribute("data-form")),
target = e.target.href,
id = form.id,
pointer = "response:" + id,
proceed = function (data, target) {
// changePage with fragment_cache pointer
$.mobile.changePage(target, {"transition": "slide", "data": data});
};
// stop
e.preventDefault();
// validate
// TODO testForClass not working
if ($(form).hasClass("validate")) {
valid = $( form ).triggerHandler( "submitForm" );
} else {
valid = $( form ).serialize();
}
// fetch and proceed
if (valid !== false) {
$.ajax({
"type":"POST",
"url": "foo.php",
"data": valid
}).done(function(data) {
// overwrite cache
// NOTE: FAKE data until working
priv.fragment_cache[id] = priv.getFakeRecords["payment"];
proceed(pointer, target);
}).fail(function(jqXHR) {
// fake it
priv.fragment_cache[id] = priv.getFakeRecords["payment"];
proceed(pointer, target);
});
}
});
}
});
......@@ -3345,7 +3402,7 @@
header,
config = priv.page_setup[e.target.id];
// page configuration
// set title
if (config) {
// global header
header = document.getElementById("global_header");
......@@ -3356,12 +3413,40 @@
}
}
// "gadget" loading
// gadget loading
// TODO: not nice to pass data on URL-pointers, but eventually the
// way to go with the router
$(".erp5_gadget").each(function (index, element) {
var method = "construct" + priv.capitaliseFirstLetter(
var data,
method = "construct" + priv.capitaliseFirstLetter(
element.getAttribute("data-gadget")
);
priv[method](element);
),
path = location.href.split("?");
if (path[1]) {
data = priv.fragment_cache[path[1].split(":")[1]];
}
priv[method](element, data);
});
// form validation
$("form")
.filter(function () { return this.getAttribute("data-bound") !== true; })
.each(function (i, element) {
element.setAttribute("data-bound", true);
// TODO: how to add custom validations here? Global configuration passed
// for all instances?
$(element).validVal({
validate: {
onKeyup: "valid",
onBlur: "valid"
},
form: {
onInvalid: function() { return;}
}
});
});
});
}(window, document, jQuery));
/*
* Copyright 2013, Nexedi SA
* Released under the LGPL license.
* http://www.gnu.org/licenses/lgpl.html
*/
/**
* Provides some function to use complex queries with item list
*
* @module complex_queries
*/
// define([module_name], [dependencies], module);
(function (dependencies, module) {
"use strict";
if (typeof define === 'function' && define.amd) {
return define(dependencies, module);
}
if (typeof exports === 'object') {
return module(exports);
}
window.complex_queries = {};
module(window.complex_queries);
}(['exports'], function (to_export) {
"use strict";
/**
* Add a secured (write permission denied) property to an object.
*
* @param {Object} object The object to fill
* @param {String} key The object key where to store the property
* @param {Any} value The value to store
*/
function _export(key, value) {
Object.defineProperty(to_export, key, {
"configurable": false,
"enumerable": true,
"writable": false,
"value": value
});
}
/**
* Parse a text request to a json query object tree
*
* @param {String} string The string to parse
* @return {Object} The json query tree
*/
function parseStringToObject(string) {
/*
Default template driver for JS/CC generated parsers running as
browser-based JavaScript/ECMAScript applications.
WARNING: This parser template will not run as console and has lesser
features for debugging than the console derivates for the
various JavaScript platforms.
Features:
- Parser trace messages
- Integrated panic-mode error recovery
Written 2007, 2008 by Jan Max Meyer, J.M.K S.F. Software Technologies
This is in the public domain.
*/
var NODEJS__dbg_withtrace = false;
var NODEJS__dbg_string = new String();
function __NODEJS_dbg_print( text )
{
NODEJS__dbg_string += text + "\n";
}
function __NODEJS_lex( info )
{
var state = 0;
var match = -1;
var match_pos = 0;
var start = 0;
var pos = info.offset + 1;
do
{
pos--;
state = 0;
match = -2;
start = pos;
if( info.src.length <= start )
return 19;
do
{
switch( state )
{
case 0:
if( ( info.src.charCodeAt( pos ) >= 0 && info.src.charCodeAt( pos ) <= 8 ) || ( info.src.charCodeAt( pos ) >= 10 && info.src.charCodeAt( pos ) <= 31 ) || info.src.charCodeAt( pos ) == 33 || ( info.src.charCodeAt( pos ) >= 35 && info.src.charCodeAt( pos ) <= 39 ) || ( info.src.charCodeAt( pos ) >= 42 && info.src.charCodeAt( pos ) <= 57 ) || info.src.charCodeAt( pos ) == 59 || ( info.src.charCodeAt( pos ) >= 63 && info.src.charCodeAt( pos ) <= 64 ) || ( info.src.charCodeAt( pos ) >= 66 && info.src.charCodeAt( pos ) <= 77 ) || ( info.src.charCodeAt( pos ) >= 80 && info.src.charCodeAt( pos ) <= 254 ) ) state = 1;
else if( info.src.charCodeAt( pos ) == 9 ) state = 2;
else if( info.src.charCodeAt( pos ) == 40 ) state = 3;
else if( info.src.charCodeAt( pos ) == 41 ) state = 4;
else if( info.src.charCodeAt( pos ) == 60 || info.src.charCodeAt( pos ) == 62 ) state = 5;
else if( info.src.charCodeAt( pos ) == 34 ) state = 11;
else if( info.src.charCodeAt( pos ) == 79 ) state = 12;
else if( info.src.charCodeAt( pos ) == 32 ) state = 13;
else if( info.src.charCodeAt( pos ) == 61 ) state = 14;
else if( info.src.charCodeAt( pos ) == 65 ) state = 18;
else if( info.src.charCodeAt( pos ) == 78 ) state = 19;
else state = -1;
break;
case 1:
if( ( info.src.charCodeAt( pos ) >= 0 && info.src.charCodeAt( pos ) <= 31 ) || info.src.charCodeAt( pos ) == 33 || ( info.src.charCodeAt( pos ) >= 35 && info.src.charCodeAt( pos ) <= 39 ) || ( info.src.charCodeAt( pos ) >= 42 && info.src.charCodeAt( pos ) <= 57 ) || ( info.src.charCodeAt( pos ) >= 59 && info.src.charCodeAt( pos ) <= 254 ) ) state = 1;
else if( info.src.charCodeAt( pos ) == 58 ) state = 6;
else state = -1;
match = 10;
match_pos = pos;
break;
case 2:
if( ( info.src.charCodeAt( pos ) >= 0 && info.src.charCodeAt( pos ) <= 31 ) || info.src.charCodeAt( pos ) == 33 || ( info.src.charCodeAt( pos ) >= 35 && info.src.charCodeAt( pos ) <= 39 ) || ( info.src.charCodeAt( pos ) >= 42 && info.src.charCodeAt( pos ) <= 57 ) || ( info.src.charCodeAt( pos ) >= 59 && info.src.charCodeAt( pos ) <= 254 ) ) state = 1;
else if( info.src.charCodeAt( pos ) == 58 ) state = 6;
else state = -1;
match = 1;
match_pos = pos;
break;
case 3:
state = -1;
match = 3;
match_pos = pos;
break;
case 4:
state = -1;
match = 4;
match_pos = pos;
break;
case 5:
if( info.src.charCodeAt( pos ) == 61 ) state = 14;
else state = -1;
match = 11;
match_pos = pos;
break;
case 6:
state = -1;
match = 8;
match_pos = pos;
break;
case 7:
state = -1;
match = 9;
match_pos = pos;
break;
case 8:
if( ( info.src.charCodeAt( pos ) >= 0 && info.src.charCodeAt( pos ) <= 31 ) || info.src.charCodeAt( pos ) == 33 || ( info.src.charCodeAt( pos ) >= 35 && info.src.charCodeAt( pos ) <= 39 ) || ( info.src.charCodeAt( pos ) >= 42 && info.src.charCodeAt( pos ) <= 57 ) || ( info.src.charCodeAt( pos ) >= 59 && info.src.charCodeAt( pos ) <= 254 ) ) state = 1;
else if( info.src.charCodeAt( pos ) == 58 ) state = 6;
else state = -1;
match = 6;
match_pos = pos;
break;
case 9:
if( ( info.src.charCodeAt( pos ) >= 0 && info.src.charCodeAt( pos ) <= 31 ) || info.src.charCodeAt( pos ) == 33 || ( info.src.charCodeAt( pos ) >= 35 && info.src.charCodeAt( pos ) <= 39 ) || ( info.src.charCodeAt( pos ) >= 42 && info.src.charCodeAt( pos ) <= 57 ) || ( info.src.charCodeAt( pos ) >= 59 && info.src.charCodeAt( pos ) <= 254 ) ) state = 1;
else if( info.src.charCodeAt( pos ) == 58 ) state = 6;
else state = -1;
match = 5;
match_pos = pos;
break;
case 10:
if( ( info.src.charCodeAt( pos ) >= 0 && info.src.charCodeAt( pos ) <= 31 ) || info.src.charCodeAt( pos ) == 33 || ( info.src.charCodeAt( pos ) >= 35 && info.src.charCodeAt( pos ) <= 39 ) || ( info.src.charCodeAt( pos ) >= 42 && info.src.charCodeAt( pos ) <= 57 ) || ( info.src.charCodeAt( pos ) >= 59 && info.src.charCodeAt( pos ) <= 254 ) ) state = 1;
else if( info.src.charCodeAt( pos ) == 58 ) state = 6;
else state = -1;
match = 7;
match_pos = pos;
break;
case 11:
if( info.src.charCodeAt( pos ) == 34 ) state = 7;
else if( ( info.src.charCodeAt( pos ) >= 0 && info.src.charCodeAt( pos ) <= 33 ) || ( info.src.charCodeAt( pos ) >= 35 && info.src.charCodeAt( pos ) <= 91 ) || ( info.src.charCodeAt( pos ) >= 93 && info.src.charCodeAt( pos ) <= 254 ) ) state = 11;
else if( info.src.charCodeAt( pos ) == 92 ) state = 15;
else state = -1;
break;
case 12:
if( ( info.src.charCodeAt( pos ) >= 0 && info.src.charCodeAt( pos ) <= 31 ) || info.src.charCodeAt( pos ) == 33 || ( info.src.charCodeAt( pos ) >= 35 && info.src.charCodeAt( pos ) <= 39 ) || ( info.src.charCodeAt( pos ) >= 42 && info.src.charCodeAt( pos ) <= 57 ) || ( info.src.charCodeAt( pos ) >= 59 && info.src.charCodeAt( pos ) <= 81 ) || ( info.src.charCodeAt( pos ) >= 83 && info.src.charCodeAt( pos ) <= 254 ) ) state = 1;
else if( info.src.charCodeAt( pos ) == 58 ) state = 6;
else if( info.src.charCodeAt( pos ) == 82 ) state = 8;
else state = -1;
match = 10;
match_pos = pos;
break;
case 13:
state = -1;
match = 1;
match_pos = pos;
break;
case 14:
state = -1;
match = 11;
match_pos = pos;
break;
case 15:
if( ( info.src.charCodeAt( pos ) >= 0 && info.src.charCodeAt( pos ) <= 254 ) ) state = 11;
else state = -1;
break;
case 16:
if( ( info.src.charCodeAt( pos ) >= 0 && info.src.charCodeAt( pos ) <= 31 ) || info.src.charCodeAt( pos ) == 33 || ( info.src.charCodeAt( pos ) >= 35 && info.src.charCodeAt( pos ) <= 39 ) || ( info.src.charCodeAt( pos ) >= 42 && info.src.charCodeAt( pos ) <= 57 ) || ( info.src.charCodeAt( pos ) >= 59 && info.src.charCodeAt( pos ) <= 67 ) || ( info.src.charCodeAt( pos ) >= 69 && info.src.charCodeAt( pos ) <= 254 ) ) state = 1;
else if( info.src.charCodeAt( pos ) == 58 ) state = 6;
else if( info.src.charCodeAt( pos ) == 68 ) state = 9;
else state = -1;
match = 10;
match_pos = pos;
break;
case 17:
if( ( info.src.charCodeAt( pos ) >= 0 && info.src.charCodeAt( pos ) <= 31 ) || info.src.charCodeAt( pos ) == 33 || ( info.src.charCodeAt( pos ) >= 35 && info.src.charCodeAt( pos ) <= 39 ) || ( info.src.charCodeAt( pos ) >= 42 && info.src.charCodeAt( pos ) <= 57 ) || ( info.src.charCodeAt( pos ) >= 59 && info.src.charCodeAt( pos ) <= 83 ) || ( info.src.charCodeAt( pos ) >= 85 && info.src.charCodeAt( pos ) <= 254 ) ) state = 1;
else if( info.src.charCodeAt( pos ) == 58 ) state = 6;
else if( info.src.charCodeAt( pos ) == 84 ) state = 10;
else state = -1;
match = 10;
match_pos = pos;
break;
case 18:
if( ( info.src.charCodeAt( pos ) >= 0 && info.src.charCodeAt( pos ) <= 31 ) || info.src.charCodeAt( pos ) == 33 || ( info.src.charCodeAt( pos ) >= 35 && info.src.charCodeAt( pos ) <= 39 ) || ( info.src.charCodeAt( pos ) >= 42 && info.src.charCodeAt( pos ) <= 57 ) || ( info.src.charCodeAt( pos ) >= 59 && info.src.charCodeAt( pos ) <= 77 ) || ( info.src.charCodeAt( pos ) >= 79 && info.src.charCodeAt( pos ) <= 254 ) ) state = 1;
else if( info.src.charCodeAt( pos ) == 58 ) state = 6;
else if( info.src.charCodeAt( pos ) == 78 ) state = 16;
else state = -1;
match = 10;
match_pos = pos;
break;
case 19:
if( ( info.src.charCodeAt( pos ) >= 0 && info.src.charCodeAt( pos ) <= 31 ) || info.src.charCodeAt( pos ) == 33 || ( info.src.charCodeAt( pos ) >= 35 && info.src.charCodeAt( pos ) <= 39 ) || ( info.src.charCodeAt( pos ) >= 42 && info.src.charCodeAt( pos ) <= 57 ) || ( info.src.charCodeAt( pos ) >= 59 && info.src.charCodeAt( pos ) <= 78 ) || ( info.src.charCodeAt( pos ) >= 80 && info.src.charCodeAt( pos ) <= 254 ) ) state = 1;
else if( info.src.charCodeAt( pos ) == 58 ) state = 6;
else if( info.src.charCodeAt( pos ) == 79 ) state = 17;
else state = -1;
match = 10;
match_pos = pos;
break;
}
pos++;
}
while( state > -1 );
}
while( 1 > -1 && match == 1 );
if( match > -1 )
{
info.att = info.src.substr( start, match_pos - start );
info.offset = match_pos;
}
else
{
info.att = new String();
match = -1;
}
return match;
}
function __NODEJS_parse( src, err_off, err_la )
{
var sstack = new Array();
var vstack = new Array();
var err_cnt = 0;
var act;
var go;
var la;
var rval;
var parseinfo = new Function( "", "var offset; var src; var att;" );
var info = new parseinfo();
/* Pop-Table */
var pop_tab = new Array(
new Array( 0/* begin' */, 1 ),
new Array( 13/* begin */, 1 ),
new Array( 12/* search_text */, 1 ),
new Array( 12/* search_text */, 2 ),
new Array( 12/* search_text */, 3 ),
new Array( 14/* and_expression */, 1 ),
new Array( 14/* and_expression */, 3 ),
new Array( 15/* boolean_expression */, 2 ),
new Array( 15/* boolean_expression */, 1 ),
new Array( 16/* expression */, 3 ),
new Array( 16/* expression */, 2 ),
new Array( 16/* expression */, 1 ),
new Array( 17/* value */, 2 ),
new Array( 17/* value */, 1 ),
new Array( 18/* string */, 1 ),
new Array( 18/* string */, 1 )
);
/* Action-Table */
var act_tab = new Array(
/* State 0 */ new Array( 7/* "NOT" */,5 , 3/* "LEFT_PARENTHESE" */,7 , 8/* "COLUMN" */,8 , 11/* "OPERATOR" */,10 , 10/* "WORD" */,12 , 9/* "STRING" */,13 ),
/* State 1 */ new Array( 19/* "$" */,0 ),
/* State 2 */ new Array( 19/* "$" */,-1 ),
/* State 3 */ new Array( 6/* "OR" */,14 , 7/* "NOT" */,5 , 3/* "LEFT_PARENTHESE" */,7 , 8/* "COLUMN" */,8 , 11/* "OPERATOR" */,10 , 10/* "WORD" */,12 , 9/* "STRING" */,13 , 19/* "$" */,-2 , 4/* "RIGHT_PARENTHESE" */,-2 ),
/* State 4 */ new Array( 5/* "AND" */,16 , 19/* "$" */,-5 , 7/* "NOT" */,-5 , 3/* "LEFT_PARENTHESE" */,-5 , 8/* "COLUMN" */,-5 , 11/* "OPERATOR" */,-5 , 10/* "WORD" */,-5 , 9/* "STRING" */,-5 , 6/* "OR" */,-5 , 4/* "RIGHT_PARENTHESE" */,-5 ),
/* State 5 */ new Array( 3/* "LEFT_PARENTHESE" */,7 , 8/* "COLUMN" */,8 , 11/* "OPERATOR" */,10 , 10/* "WORD" */,12 , 9/* "STRING" */,13 ),
/* State 6 */ new Array( 19/* "$" */,-8 , 7/* "NOT" */,-8 , 3/* "LEFT_PARENTHESE" */,-8 , 8/* "COLUMN" */,-8 , 11/* "OPERATOR" */,-8 , 10/* "WORD" */,-8 , 9/* "STRING" */,-8 , 6/* "OR" */,-8 , 5/* "AND" */,-8 , 4/* "RIGHT_PARENTHESE" */,-8 ),
/* State 7 */ new Array( 7/* "NOT" */,5 , 3/* "LEFT_PARENTHESE" */,7 , 8/* "COLUMN" */,8 , 11/* "OPERATOR" */,10 , 10/* "WORD" */,12 , 9/* "STRING" */,13 ),
/* State 8 */ new Array( 3/* "LEFT_PARENTHESE" */,7 , 8/* "COLUMN" */,8 , 11/* "OPERATOR" */,10 , 10/* "WORD" */,12 , 9/* "STRING" */,13 ),
/* State 9 */ new Array( 19/* "$" */,-11 , 7/* "NOT" */,-11 , 3/* "LEFT_PARENTHESE" */,-11 , 8/* "COLUMN" */,-11 , 11/* "OPERATOR" */,-11 , 10/* "WORD" */,-11 , 9/* "STRING" */,-11 , 6/* "OR" */,-11 , 5/* "AND" */,-11 , 4/* "RIGHT_PARENTHESE" */,-11 ),
/* State 10 */ new Array( 10/* "WORD" */,12 , 9/* "STRING" */,13 ),
/* State 11 */ new Array( 19/* "$" */,-13 , 7/* "NOT" */,-13 , 3/* "LEFT_PARENTHESE" */,-13 , 8/* "COLUMN" */,-13 , 11/* "OPERATOR" */,-13 , 10/* "WORD" */,-13 , 9/* "STRING" */,-13 , 6/* "OR" */,-13 , 5/* "AND" */,-13 , 4/* "RIGHT_PARENTHESE" */,-13 ),
/* State 12 */ new Array( 19/* "$" */,-14 , 7/* "NOT" */,-14 , 3/* "LEFT_PARENTHESE" */,-14 , 8/* "COLUMN" */,-14 , 11/* "OPERATOR" */,-14 , 10/* "WORD" */,-14 , 9/* "STRING" */,-14 , 6/* "OR" */,-14 , 5/* "AND" */,-14 , 4/* "RIGHT_PARENTHESE" */,-14 ),
/* State 13 */ new Array( 19/* "$" */,-15 , 7/* "NOT" */,-15 , 3/* "LEFT_PARENTHESE" */,-15 , 8/* "COLUMN" */,-15 , 11/* "OPERATOR" */,-15 , 10/* "WORD" */,-15 , 9/* "STRING" */,-15 , 6/* "OR" */,-15 , 5/* "AND" */,-15 , 4/* "RIGHT_PARENTHESE" */,-15 ),
/* State 14 */ new Array( 7/* "NOT" */,5 , 3/* "LEFT_PARENTHESE" */,7 , 8/* "COLUMN" */,8 , 11/* "OPERATOR" */,10 , 10/* "WORD" */,12 , 9/* "STRING" */,13 ),
/* State 15 */ new Array( 19/* "$" */,-3 , 4/* "RIGHT_PARENTHESE" */,-3 ),
/* State 16 */ new Array( 7/* "NOT" */,5 , 3/* "LEFT_PARENTHESE" */,7 , 8/* "COLUMN" */,8 , 11/* "OPERATOR" */,10 , 10/* "WORD" */,12 , 9/* "STRING" */,13 ),
/* State 17 */ new Array( 19/* "$" */,-7 , 7/* "NOT" */,-7 , 3/* "LEFT_PARENTHESE" */,-7 , 8/* "COLUMN" */,-7 , 11/* "OPERATOR" */,-7 , 10/* "WORD" */,-7 , 9/* "STRING" */,-7 , 6/* "OR" */,-7 , 5/* "AND" */,-7 , 4/* "RIGHT_PARENTHESE" */,-7 ),
/* State 18 */ new Array( 4/* "RIGHT_PARENTHESE" */,23 ),
/* State 19 */ new Array( 19/* "$" */,-10 , 7/* "NOT" */,-10 , 3/* "LEFT_PARENTHESE" */,-10 , 8/* "COLUMN" */,-10 , 11/* "OPERATOR" */,-10 , 10/* "WORD" */,-10 , 9/* "STRING" */,-10 , 6/* "OR" */,-10 , 5/* "AND" */,-10 , 4/* "RIGHT_PARENTHESE" */,-10 ),
/* State 20 */ new Array( 19/* "$" */,-12 , 7/* "NOT" */,-12 , 3/* "LEFT_PARENTHESE" */,-12 , 8/* "COLUMN" */,-12 , 11/* "OPERATOR" */,-12 , 10/* "WORD" */,-12 , 9/* "STRING" */,-12 , 6/* "OR" */,-12 , 5/* "AND" */,-12 , 4/* "RIGHT_PARENTHESE" */,-12 ),
/* State 21 */ new Array( 19/* "$" */,-4 , 4/* "RIGHT_PARENTHESE" */,-4 ),
/* State 22 */ new Array( 19/* "$" */,-6 , 7/* "NOT" */,-6 , 3/* "LEFT_PARENTHESE" */,-6 , 8/* "COLUMN" */,-6 , 11/* "OPERATOR" */,-6 , 10/* "WORD" */,-6 , 9/* "STRING" */,-6 , 6/* "OR" */,-6 , 4/* "RIGHT_PARENTHESE" */,-6 ),
/* State 23 */ new Array( 19/* "$" */,-9 , 7/* "NOT" */,-9 , 3/* "LEFT_PARENTHESE" */,-9 , 8/* "COLUMN" */,-9 , 11/* "OPERATOR" */,-9 , 10/* "WORD" */,-9 , 9/* "STRING" */,-9 , 6/* "OR" */,-9 , 5/* "AND" */,-9 , 4/* "RIGHT_PARENTHESE" */,-9 )
);
/* Goto-Table */
var goto_tab = new Array(
/* State 0 */ new Array( 13/* begin */,1 , 12/* search_text */,2 , 14/* and_expression */,3 , 15/* boolean_expression */,4 , 16/* expression */,6 , 17/* value */,9 , 18/* string */,11 ),
/* State 1 */ new Array( ),
/* State 2 */ new Array( ),
/* State 3 */ new Array( 12/* search_text */,15 , 14/* and_expression */,3 , 15/* boolean_expression */,4 , 16/* expression */,6 , 17/* value */,9 , 18/* string */,11 ),
/* State 4 */ new Array( ),
/* State 5 */ new Array( 16/* expression */,17 , 17/* value */,9 , 18/* string */,11 ),
/* State 6 */ new Array( ),
/* State 7 */ new Array( 12/* search_text */,18 , 14/* and_expression */,3 , 15/* boolean_expression */,4 , 16/* expression */,6 , 17/* value */,9 , 18/* string */,11 ),
/* State 8 */ new Array( 16/* expression */,19 , 17/* value */,9 , 18/* string */,11 ),
/* State 9 */ new Array( ),
/* State 10 */ new Array( 18/* string */,20 ),
/* State 11 */ new Array( ),
/* State 12 */ new Array( ),
/* State 13 */ new Array( ),
/* State 14 */ new Array( 12/* search_text */,21 , 14/* and_expression */,3 , 15/* boolean_expression */,4 , 16/* expression */,6 , 17/* value */,9 , 18/* string */,11 ),
/* State 15 */ new Array( ),
/* State 16 */ new Array( 14/* and_expression */,22 , 15/* boolean_expression */,4 , 16/* expression */,6 , 17/* value */,9 , 18/* string */,11 ),
/* State 17 */ new Array( ),
/* State 18 */ new Array( ),
/* State 19 */ new Array( ),
/* State 20 */ new Array( ),
/* State 21 */ new Array( ),
/* State 22 */ new Array( ),
/* State 23 */ new Array( )
);
/* Symbol labels */
var labels = new Array(
"begin'" /* Non-terminal symbol */,
"WHITESPACE" /* Terminal symbol */,
"WHITESPACE" /* Terminal symbol */,
"LEFT_PARENTHESE" /* Terminal symbol */,
"RIGHT_PARENTHESE" /* Terminal symbol */,
"AND" /* Terminal symbol */,
"OR" /* Terminal symbol */,
"NOT" /* Terminal symbol */,
"COLUMN" /* Terminal symbol */,
"STRING" /* Terminal symbol */,
"WORD" /* Terminal symbol */,
"OPERATOR" /* Terminal symbol */,
"search_text" /* Non-terminal symbol */,
"begin" /* Non-terminal symbol */,
"and_expression" /* Non-terminal symbol */,
"boolean_expression" /* Non-terminal symbol */,
"expression" /* Non-terminal symbol */,
"value" /* Non-terminal symbol */,
"string" /* Non-terminal symbol */,
"$" /* Terminal symbol */
);
info.offset = 0;
info.src = src;
info.att = new String();
if( !err_off )
err_off = new Array();
if( !err_la )
err_la = new Array();
sstack.push( 0 );
vstack.push( 0 );
la = __NODEJS_lex( info );
while( true )
{
act = 25;
for( var i = 0; i < act_tab[sstack[sstack.length-1]].length; i+=2 )
{
if( act_tab[sstack[sstack.length-1]][i] == la )
{
act = act_tab[sstack[sstack.length-1]][i+1];
break;
}
}
if( NODEJS__dbg_withtrace && sstack.length > 0 )
{
__NODEJS_dbg_print( "\nState " + sstack[sstack.length-1] + "\n" +
"\tLookahead: " + labels[la] + " (\"" + info.att + "\")\n" +
"\tAction: " + act + "\n" +
"\tSource: \"" + info.src.substr( info.offset, 30 ) + ( ( info.offset + 30 < info.src.length ) ?
"..." : "" ) + "\"\n" +
"\tStack: " + sstack.join() + "\n" +
"\tValue stack: " + vstack.join() + "\n" );
}
//Panic-mode: Try recovery when parse-error occurs!
if( act == 25 )
{
if( NODEJS__dbg_withtrace )
__NODEJS_dbg_print( "Error detected: There is no reduce or shift on the symbol " + labels[la] );
err_cnt++;
err_off.push( info.offset - info.att.length );
err_la.push( new Array() );
for( var i = 0; i < act_tab[sstack[sstack.length-1]].length; i+=2 )
err_la[err_la.length-1].push( labels[act_tab[sstack[sstack.length-1]][i]] );
//Remember the original stack!
var rsstack = new Array();
var rvstack = new Array();
for( var i = 0; i < sstack.length; i++ )
{
rsstack[i] = sstack[i];
rvstack[i] = vstack[i];
}
while( act == 25 && la != 19 )
{
if( NODEJS__dbg_withtrace )
__NODEJS_dbg_print( "\tError recovery\n" +
"Current lookahead: " + labels[la] + " (" + info.att + ")\n" +
"Action: " + act + "\n\n" );
if( la == -1 )
info.offset++;
while( act == 25 && sstack.length > 0 )
{
sstack.pop();
vstack.pop();
if( sstack.length == 0 )
break;
act = 25;
for( var i = 0; i < act_tab[sstack[sstack.length-1]].length; i+=2 )
{
if( act_tab[sstack[sstack.length-1]][i] == la )
{
act = act_tab[sstack[sstack.length-1]][i+1];
break;
}
}
}
if( act != 25 )
break;
for( var i = 0; i < rsstack.length; i++ )
{
sstack.push( rsstack[i] );
vstack.push( rvstack[i] );
}
la = __NODEJS_lex( info );
}
if( act == 25 )
{
if( NODEJS__dbg_withtrace )
__NODEJS_dbg_print( "\tError recovery failed, terminating parse process..." );
break;
}
if( NODEJS__dbg_withtrace )
__NODEJS_dbg_print( "\tError recovery succeeded, continuing" );
}
/*
if( act == 25 )
break;
*/
//Shift
if( act > 0 )
{
if( NODEJS__dbg_withtrace )
__NODEJS_dbg_print( "Shifting symbol: " + labels[la] + " (" + info.att + ")" );
sstack.push( act );
vstack.push( info.att );
la = __NODEJS_lex( info );
if( NODEJS__dbg_withtrace )
__NODEJS_dbg_print( "\tNew lookahead symbol: " + labels[la] + " (" + info.att + ")" );
}
//Reduce
else
{
act *= -1;
if( NODEJS__dbg_withtrace )
__NODEJS_dbg_print( "Reducing by producution: " + act );
rval = void(0);
if( NODEJS__dbg_withtrace )
__NODEJS_dbg_print( "\tPerforming semantic action..." );
switch( act )
{
case 0:
{
rval = vstack[ vstack.length - 1 ];
}
break;
case 1:
{
result = vstack[ vstack.length - 1 ];
}
break;
case 2:
{
rval = vstack[ vstack.length - 1 ];
}
break;
case 3:
{
rval = mkComplexQuery('OR',[vstack[ vstack.length - 2 ],vstack[ vstack.length - 1 ]]);
}
break;
case 4:
{
rval = mkComplexQuery('OR',[vstack[ vstack.length - 3 ],vstack[ vstack.length - 1 ]]);
}
break;
case 5:
{
rval = vstack[ vstack.length - 1 ] ;
}
break;
case 6:
{
rval = mkComplexQuery('AND',[vstack[ vstack.length - 3 ],vstack[ vstack.length - 1 ]]);
}
break;
case 7:
{
rval = mkNotQuery(vstack[ vstack.length - 1 ]);
}
break;
case 8:
{
rval = vstack[ vstack.length - 1 ];
}
break;
case 9:
{
rval = vstack[ vstack.length - 2 ];
}
break;
case 10:
{
simpleQuerySetKey(vstack[ vstack.length - 1 ],vstack[ vstack.length - 2 ].split(':').slice(0,-1).join(':')); rval = vstack[ vstack.length - 1 ];
}
break;
case 11:
{
rval = vstack[ vstack.length - 1 ];
}
break;
case 12:
{
vstack[ vstack.length - 1 ].operator = vstack[ vstack.length - 2 ] ; rval = vstack[ vstack.length - 1 ];
}
break;
case 13:
{
rval = vstack[ vstack.length - 1 ];
}
break;
case 14:
{
rval = mkSimpleQuery('',vstack[ vstack.length - 1 ]);
}
break;
case 15:
{
rval = mkSimpleQuery('',vstack[ vstack.length - 1 ].split('"').slice(1,-1).join('"'));
}
break;
}
if( NODEJS__dbg_withtrace )
__NODEJS_dbg_print( "\tPopping " + pop_tab[act][1] + " off the stack..." );
for( var i = 0; i < pop_tab[act][1]; i++ )
{
sstack.pop();
vstack.pop();
}
go = -1;
for( var i = 0; i < goto_tab[sstack[sstack.length-1]].length; i+=2 )
{
if( goto_tab[sstack[sstack.length-1]][i] == pop_tab[act][0] )
{
go = goto_tab[sstack[sstack.length-1]][i+1];
break;
}
}
if( act == 0 )
break;
if( NODEJS__dbg_withtrace )
__NODEJS_dbg_print( "\tPushing non-terminal " + labels[ pop_tab[act][0] ] );
sstack.push( go );
vstack.push( rval );
}
if( NODEJS__dbg_withtrace )
{
alert( NODEJS__dbg_string );
NODEJS__dbg_string = new String();
}
}
if( NODEJS__dbg_withtrace )
{
__NODEJS_dbg_print( "\nParse complete." );
alert( NODEJS__dbg_string );
}
return err_cnt;
}
var arrayExtend = function () {
var j, i, newlist = [], list_list = arguments;
for (j = 0; j < list_list.length; j += 1) {
for (i = 0; i < list_list[j].length; i += 1) {
newlist.push(list_list[j][i]);
}
}
return newlist;
}, mkSimpleQuery = function (key, value, operator) {
return {"type": "simple", "operator": "=", "key": key, "value": value};
}, mkNotQuery = function (query) {
if (query.operator === "NOT") {
return query.query_list[0];
}
return {"type": "complex", "operator": "NOT", "query_list": [query]};
}, mkComplexQuery = function (operator, query_list) {
var i, query_list2 = [];
for (i = 0; i < query_list.length; i += 1) {
if (query_list[i].operator === operator) {
query_list2 = arrayExtend(query_list2, query_list[i].query_list);
} else {
query_list2.push(query_list[i]);
}
}
return {type:"complex",operator:operator,query_list:query_list2};
}, simpleQuerySetKey = function (query, key) {
var i;
if (query.type === "complex") {
for (i = 0; i < query.query_list.length; ++i) {
simpleQuerySetKey (query.query_list[i],key);
}
return true;
}
if (query.type === "simple" && !query.key) {
query.key = key;
return true;
}
return false;
},
error_offsets = [],
error_lookaheads = [],
error_count = 0,
result;
if ((error_count = __NODEJS_parse(string, error_offsets, error_lookaheads)) > 0) {
var i;
for (i = 0; i < error_count; i += 1) {
throw new Error("Parse error near \"" +
string.substr(error_offsets[i]) +
"\", expecting \"" +
error_lookaheads[i].join() + "\"");
}
}
return result;
} // parseStringToObject
_export('parseStringToObject', parseStringToObject);
/*jslint indent: 2, maxlen: 80, sloppy: true */
var query_class_dict = {};
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true */
/*global Query: true, query_class_dict: true, inherits: true,
_export: true, QueryFactory: true */
/**
* The ComplexQuery inherits from Query, and compares one or several metadata
* values.
*
* @class ComplexQuery
* @extends Query
* @param {Object} [spec={}] The specifications
* @param {String} [spec.operator="AND"] The compare method to use
* @param {String} spec.key The metadata key
* @param {String} spec.value The value of the metadata to compare
*/
function ComplexQuery(spec) {
Query.call(this);
/**
* Logical operator to use to compare object values
*
* @attribute operator
* @type String
* @default "AND"
* @optional
*/
this.operator = spec.operator || "AND";
/**
* The sub Query list which are used to query an item.
*
* @attribute query_list
* @type Array
* @default []
* @optional
*/
this.query_list = spec.query_list || [];
this.query_list = this.query_list.map(QueryFactory.create);
}
inherits(ComplexQuery, Query);
/**
* #crossLink "Query/match:method"
*/
ComplexQuery.prototype.match = function (item, wildcard_character) {
return this[this.operator](item, wildcard_character);
};
/**
* #crossLink "Query/toString:method"
*/
ComplexQuery.prototype.toString = function () {
var str_list = ["("], this_operator = this.operator;
this.query_list.forEach(function (query) {
str_list.push(query.toString());
str_list.push(this_operator);
});
str_list.pop(); // remove last operator
str_list.push(")");
return str_list.join(" ");
};
/**
* #crossLink "Query/serialized:method"
*/
ComplexQuery.prototype.serialized = function () {
var s = {
"type": "complex",
"operator": this.operator,
"query_list": []
};
this.query_list.forEach(function (query) {
s.query_list.push(query.serialized());
});
return s;
};
/**
* Comparison operator, test if all sub queries match the
* item value
*
* @method AND
* @param {Object} item The item to match
* @param {String} wildcard_character The wildcard character
* @return {Boolean} true if all match, false otherwise
*/
ComplexQuery.prototype.AND = function (item, wildcard_character) {
var i;
for (i = 0; i < this.query_list.length; i += 1) {
if (!this.query_list[i].match(item, wildcard_character)) {
return false;
}
}
return true;
};
/**
* Comparison operator, test if one of the sub queries matches the
* item value
*
* @method OR
* @param {Object} item The item to match
* @param {String} wildcard_character The wildcard character
* @return {Boolean} true if one match, false otherwise
*/
ComplexQuery.prototype.OR = function (item, wildcard_character) {
var i;
for (i = 0; i < this.query_list.length; i += 1) {
if (this.query_list[i].match(item, wildcard_character)) {
return true;
}
}
return false;
};
/**
* Comparison operator, test if the sub query does not match the
* item value
*
* @method NOT
* @param {Object} item The item to match
* @param {String} wildcard_character The wildcard character
* @return {Boolean} true if one match, false otherwise
*/
ComplexQuery.prototype.NOT = function (item, wildcard_character) {
return !this.query_list[0].match(item, wildcard_character);
};
query_class_dict.complex = ComplexQuery;
_export("ComplexQuery", ComplexQuery);
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true */
/*global parseStringToObject: true, emptyFunction: true, sortOn: true, limit:
true, select: true, _export: true, stringEscapeRegexpCharacters: true,
deepClone: true */
/**
* The query to use to filter a list of objects.
* This is an abstract class.
*
* @class Query
* @constructor
*/
function Query() {
/**
* Called before parsing the query. Must be overridden!
*
* @method onParseStart
* @param {Object} object The object shared in the parse process
* @param {Object} option Some option gave in parse()
*/
this.onParseStart = emptyFunction;
/**
* Called when parsing a simple query. Must be overridden!
*
* @method onParseSimpleQuery
* @param {Object} object The object shared in the parse process
* @param {Object} option Some option gave in parse()
*/
this.onParseSimpleQuery = emptyFunction;
/**
* Called when parsing a complex query. Must be overridden!
*
* @method onParseComplexQuery
* @param {Object} object The object shared in the parse process
* @param {Object} option Some option gave in parse()
*/
this.onParseComplexQuery = emptyFunction;
/**
* Called after parsing the query. Must be overridden!
*
* @method onParseEnd
* @param {Object} object The object shared in the parse process
* @param {Object} option Some option gave in parse()
*/
this.onParseEnd = emptyFunction;
}
/**
* Filter the item list with matching item only
*
* @method exec
* @param {Array} item_list The list of object
* @param {Object} [option] Some operation option
* @param {String} [option.wildcard_character="%"] The wildcard character
* @param {Array} [option.select_list] A object keys to retrieve
* @param {Array} [option.sort_on] Couples of object keys and "ascending"
* or "descending"
* @param {Array} [option.limit] Couple of integer, first is an index and
* second is the length.
*/
Query.prototype.exec = function (item_list, option) {
var i = 0;
if (!Array.isArray(item_list)) {
throw new TypeError("Query().exec(): Argument 1 is not of type 'array'");
}
if (option === undefined) {
option = {};
}
if (typeof option !== 'object') {
throw new TypeError("Query().exec(): " +
"Optional argument 2 is not of type 'object'");
}
if (option.wildcard_character === undefined) {
option.wildcard_character = '%';
}
while (i < item_list.length) {
if (!this.match(item_list[i], option.wildcard_character)) {
item_list.splice(i, 1);
} else {
i += 1;
}
}
if (option.sort_on) {
sortOn(option.sort_on, item_list);
}
if (option.limit) {
limit(option.limit, item_list);
}
select(option.select_list || [], item_list);
};
/**
* Test if an item matches this query
*
* @method match
* @param {Object} item The object to test
* @param {String} wildcard_character The wildcard character to use
* @return {Boolean} true if match, false otherwise
*/
Query.prototype.match = function () {
return true;
};
/**
* Browse the Query in deep calling parser method in each step.
*
* `onParseStart` is called first, on end `onParseEnd` is called.
* It starts from the simple queries at the bottom of the tree calling the
* parser method `onParseSimpleQuery`, and go up calling the
* `onParseComplexQuery` method.
*
* @method parse
* @param {Object} option Any options you want (except 'parsed')
* @return {Any} The parse result
*/
Query.prototype.parse = function (option) {
var that = this, object;
/**
* The recursive parser.
*
* @param {Object} object The object shared in the parse process
* @param {Object} options Some options usable in the parseMethods
* @return {Any} The parser result
*/
function recParse(object, option) {
var i, query = object.parsed;
if (query.type === "complex") {
for (i = 0; i < query.query_list.length; i += 1) {
object.parsed = query.query_list[i];
recParse(object, option);
query.query_list[i] = object.parsed;
}
object.parsed = query;
that.onParseComplexQuery(object, option);
} else if (query.type === "simple") {
that.onParseSimpleQuery(object, option);
}
}
object = {"parsed": JSON.parse(JSON.stringify(that.serialized()))};
that.onParseStart(object, option);
recParse(object, option);
that.onParseEnd(object, option);
return object.parsed;
};
/**
* Convert this query to a parsable string.
*
* @method toString
* @return {String} The string version of this query
*/
Query.prototype.toString = function () {
return "";
};
/**
* Convert this query to an jsonable object in order to be remake thanks to
* QueryFactory class.
*
* @method serialized
* @return {Object} The jsonable object
*/
Query.prototype.serialized = function () {
return undefined;
};
_export("Query", Query);
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true */
/*global _export, ComplexQuery, SimpleQuery, Query, parseStringToObject,
query_class_dict */
/**
* Provides static methods to create Query object
*
* @class QueryFactory
*/
function QueryFactory() {
return;
}
/**
* Creates Query object from a search text string or a serialized version
* of a Query.
*
* @method create
* @static
* @param {Object,String} object The search text or the serialized version
* of a Query
* @return {Query} A Query object
*/
QueryFactory.create = function (object) {
if (object === "") {
return new Query();
}
if (typeof object === "string") {
object = parseStringToObject(object);
}
if (typeof (object || {}).type === "string" &&
query_class_dict[object.type]) {
return new query_class_dict[object.type](object);
}
throw new TypeError("QueryFactory.create(): " +
"Argument 1 is not a search text or a parsable object");
};
_export("QueryFactory", QueryFactory);
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true */
/*global _export: true, to_export: true */
function objectToSearchText(query) {
var str_list = [];
if (query.type === "complex") {
str_list.push("(");
(query.query_list || []).forEach(function (sub_query) {
str_list.push(objectToSearchText(sub_query));
str_list.push(query.operator);
});
str_list.length -= 1;
str_list.push(")");
return str_list.join(" ");
}
if (query.type === "simple") {
return query.id + (query.id ? ": " : "") + (query.operator || "=") + ' "' +
query.value + '"';
}
throw new TypeError("This object is not a query");
}
_export("objectToSearchText", objectToSearchText);
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true */
/*global Query: true, inherits: true, query_class_dict: true, _export: true,
convertStringToRegExp: true */
/**
* The SimpleQuery inherits from Query, and compares one metadata value
*
* @class SimpleQuery
* @extends Query
* @param {Object} [spec={}] The specifications
* @param {String} [spec.operator="="] The compare method to use
* @param {String} spec.key The metadata key
* @param {String} spec.value The value of the metadata to compare
*/
function SimpleQuery(spec) {
Query.call(this);
/**
* Operator to use to compare object values
*
* @attribute operator
* @type String
* @default "="
* @optional
*/
this.operator = spec.operator || "=";
/**
* Key of the object which refers to the value to compare
*
* @attribute key
* @type String
*/
this.key = spec.key;
/**
* Value is used to do the comparison with the object value
*
* @attribute value
* @type String
*/
this.value = spec.value;
}
inherits(SimpleQuery, Query);
/**
* #crossLink "Query/match:method"
*/
SimpleQuery.prototype.match = function (item, wildcard_character) {
return this[this.operator](item[this.key], this.value, wildcard_character);
};
/**
* #crossLink "Query/toString:method"
*/
SimpleQuery.prototype.toString = function () {
return (this.key ? this.key + ": " : "") + (this.operator || "=") + ' "' +
this.value + '"';
};
/**
* #crossLink "Query/serialized:method"
*/
SimpleQuery.prototype.serialized = function () {
return {
"type": "simple",
"operator": this.operator,
"key": this.key,
"value": this.value
};
};
/**
* Comparison operator, test if this query value matches the item value
*
* @method =
* @param {String} object_value The value to compare
* @param {String} comparison_value The comparison value
* @param {String} wildcard_character The wildcard_character
* @return {Boolean} true if match, false otherwise
*/
SimpleQuery.prototype["="] = function (object_value, comparison_value,
wildcard_character) {
var value, i;
if (!Array.isArray(object_value)) {
object_value = [object_value];
}
for (i = 0; i < object_value.length; i += 1) {
value = object_value[i];
if (typeof value === 'object') {
value = value.content;
}
if (comparison_value === undefined) {
if (value === undefined) {
return true;
}
return false;
}
if (value === undefined) {
return false;
}
if (
convertStringToRegExp(
comparison_value.toString(),
wildcard_character
).test(value.toString())
) {
return true;
}
}
return false;
};
/**
* Comparison operator, test if this query value does not match the item value
*
* @method !=
* @param {String} object_value The value to compare
* @param {String} comparison_value The comparison value
* @param {String} wildcard_character The wildcard_character
* @return {Boolean} true if not match, false otherwise
*/
SimpleQuery.prototype["!="] = function (object_value, comparison_value,
wildcard_character) {
var value, i;
if (!Array.isArray(object_value)) {
object_value = [object_value];
}
for (i = 0; i < object_value.length; i += 1) {
value = object_value[i];
if (typeof value === 'object') {
value = value.content;
}
if (comparison_value === undefined) {
if (value === undefined) {
return false;
}
return true;
}
if (value === undefined) {
return true;
}
if (
convertStringToRegExp(
comparison_value.toString(),
wildcard_character
).test(value.toString())
) {
return false;
}
}
return true;
};
/**
* Comparison operator, test if this query value is lower than the item value
*
* @method <
* @param {Number, String} object_value The value to compare
* @param {Number, String} comparison_value The comparison value
* @return {Boolean} true if lower, false otherwise
*/
SimpleQuery.prototype["<"] = function (object_value, comparison_value) {
var value;
if (!Array.isArray(object_value)) {
object_value = [object_value];
}
value = object_value[0];
if (typeof value === 'object') {
value = value.content;
}
return value < comparison_value;
};
/**
* Comparison operator, test if this query value is equal or lower than the
* item value
*
* @method <=
* @param {Number, String} object_value The value to compare
* @param {Number, String} comparison_value The comparison value
* @return {Boolean} true if equal or lower, false otherwise
*/
SimpleQuery.prototype["<="] = function (object_value, comparison_value) {
var value;
if (!Array.isArray(object_value)) {
object_value = [object_value];
}
value = object_value[0];
if (typeof value === 'object') {
value = value.content;
}
return value <= comparison_value;
};
/**
* Comparison operator, test if this query value is greater than the item
* value
*
* @method >
* @param {Number, String} object_value The value to compare
* @param {Number, String} comparison_value The comparison value
* @return {Boolean} true if greater, false otherwise
*/
SimpleQuery.prototype[">"] = function (object_value, comparison_value) {
var value;
if (!Array.isArray(object_value)) {
object_value = [object_value];
}
value = object_value[0];
if (typeof value === 'object') {
value = value.content;
}
return value > comparison_value;
};
/**
* Comparison operator, test if this query value is equal or greater than the
* item value
*
* @method >=
* @param {Number, String} object_value The value to compare
* @param {Number, String} comparison_value The comparison value
* @return {Boolean} true if equal or greater, false otherwise
*/
SimpleQuery.prototype[">="] = function (object_value, comparison_value) {
var value;
if (!Array.isArray(object_value)) {
object_value = [object_value];
}
value = object_value[0];
if (typeof value === 'object') {
value = value.content;
}
return value >= comparison_value;
};
query_class_dict.simple = SimpleQuery;
_export("SimpleQuery", SimpleQuery);
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true */
/*global _export: true */
/**
* Escapes regexp special chars from a string.
*
* @param {String} string The string to escape
* @return {String} The escaped string
*/
function stringEscapeRegexpCharacters(string) {
if (typeof string === "string") {
return string.replace(/([\\\.\$\[\]\(\)\{\}\^\?\*\+\-])/g, "\\$1");
}
throw new TypeError("complex_queries.stringEscapeRegexpCharacters(): " +
"Argument no 1 is not of type 'string'");
}
_export("stringEscapeRegexpCharacters", stringEscapeRegexpCharacters);
/**
* Convert metadata values to array of strings. ex:
*
* "a" -> ["a"],
* {"content": "a"} -> ["a"]
*
* @param {Any} value The metadata value
* @return {Array} The value in string array format
*/
function metadataValueToStringArray(value) {
var i, new_value = [];
if (value === undefined) {
return undefined;
}
if (!Array.isArray(value)) {
value = [value];
}
for (i = 0; i < value.length; i += 1) {
if (typeof value[i] === 'object') {
new_value[i] = value[i].content;
} else {
new_value[i] = value[i];
}
}
return new_value;
}
/**
* A sort function to sort items by key
*
* @param {String} key The key to sort on
* @param {String} [way="ascending"] 'ascending' or 'descending'
* @return {Function} The sort function
*/
function sortFunction(key, way) {
if (way === 'descending') {
return function (a, b) {
// this comparison is 5 times faster than json comparison
var i, l;
a = metadataValueToStringArray(a[key]) || [];
b = metadataValueToStringArray(b[key]) || [];
l = a.length > b.length ? a.length : b.length;
for (i = 0; i < l; i += 1) {
if (a[i] === undefined) {
return 1;
}
if (b[i] === undefined) {
return -1;
}
if (a[i] > b[i]) {
return -1;
}
if (a[i] < b[i]) {
return 1;
}
}
return 0;
};
}
if (way === 'ascending') {
return function (a, b) {
// this comparison is 5 times faster than json comparison
var i, l;
a = metadataValueToStringArray(a[key]) || [];
b = metadataValueToStringArray(b[key]) || [];
l = a.length > b.length ? a.length : b.length;
for (i = 0; i < l; i += 1) {
if (a[i] === undefined) {
return -1;
}
if (b[i] === undefined) {
return 1;
}
if (a[i] > b[i]) {
return 1;
}
if (a[i] < b[i]) {
return -1;
}
}
return 0;
};
}
throw new TypeError("complex_queries.sortFunction(): " +
"Argument 2 must be 'ascending' or 'descending'");
}
/**
* Clones all native object in deep. Managed types: Object, Array, String,
* Number, Boolean, null.
*
* @param {A} object The object to clone
* @return {A} The cloned object
*/
function deepClone(object) {
var i, cloned;
if (Array.isArray(object)) {
cloned = [];
for (i = 0; i < object.length; i += 1) {
cloned[i] = deepClone(object[i]);
}
return cloned;
}
if (typeof object === "object") {
cloned = {};
for (i in object) {
if (object.hasOwnProperty(i)) {
cloned[i] = deepClone(object[i]);
}
}
return cloned;
}
return object;
}
/**
* Inherits the prototype methods from one constructor into another. The
* prototype of `constructor` will be set to a new object created from
* `superConstructor`.
*
* @param {Function} constructor The constructor which inherits the super one
* @param {Function} superConstructor The super constructor
*/
function inherits(constructor, superConstructor) {
constructor.super_ = superConstructor;
constructor.prototype = Object.create(superConstructor.prototype, {
"constructor": {
"configurable": true,
"enumerable": false,
"writable": true,
"value": constructor
}
});
}
/**
* Does nothing
*/
function emptyFunction() {
return;
}
/**
* Filter a list of items, modifying them to select only wanted keys. If
* `clone` is true, then the method will act on a cloned list.
*
* @param {Array} select_option Key list to keep
* @param {Array} list The item list to filter
* @param {Boolean} [clone=false] If true, modifies a clone of the list
* @return {Array} The filtered list
*/
function select(select_option, list, clone) {
var i, j, new_item;
if (!Array.isArray(select_option)) {
throw new TypeError("complex_queries.select(): " +
"Argument 1 is not of type Array");
}
if (!Array.isArray(list)) {
throw new TypeError("complex_queries.select(): " +
"Argument 2 is not of type Array");
}
if (clone === true) {
list = deepClone(list);
}
for (i = 0; i < list.length; i += 1) {
new_item = {};
for (j = 0; j < select_option.length; j += 1) {
new_item[select_option[j]] = list[i][select_option[j]];
}
for (j in new_item) {
if (new_item.hasOwnProperty(j)) {
list[i] = new_item;
break;
}
}
}
return list;
}
_export('select', select);
/**
* Sort a list of items, according to keys and directions. If `clone` is true,
* then the method will act on a cloned list.
*
* @param {Array} sort_on_option List of couples [key, direction]
* @param {Array} list The item list to sort
* @param {Boolean} [clone=false] If true, modifies a clone of the list
* @return {Array} The filtered list
*/
function sortOn(sort_on_option, list, clone) {
var sort_index;
if (!Array.isArray(sort_on_option)) {
throw new TypeError("complex_queries.sortOn(): " +
"Argument 1 is not of type 'array'");
}
if (clone) {
list = deepClone(list);
}
for (sort_index = sort_on_option.length - 1; sort_index >= 0;
sort_index -= 1) {
list.sort(sortFunction(
sort_on_option[sort_index][0],
sort_on_option[sort_index][1]
));
}
return list;
}
_export('sortOn', sortOn);
/**
* Limit a list of items, according to index and length. If `clone` is true,
* then the method will act on a cloned list.
*
* @param {Array} limit_option A couple [from, length]
* @param {Array} list The item list to limit
* @param {Boolean} [clone=false] If true, modifies a clone of the list
* @return {Array} The filtered list
*/
function limit(limit_option, list, clone) {
if (!Array.isArray(limit_option)) {
throw new TypeError("complex_queries.limit(): " +
"Argument 1 is not of type 'array'");
}
if (!Array.isArray(list)) {
throw new TypeError("complex_queries.limit(): " +
"Argument 2 is not of type 'array'");
}
if (clone) {
list = deepClone(list);
}
list.splice(0, limit_option[0]);
if (limit_option[1]) {
list.splice(limit_option[1]);
}
return list;
}
_export('limit', limit);
/**
* Convert a search text to a regexp.
*
* @param {String} string The string to convert
* @param {String} [wildcard_character=undefined] The wildcard chararter
* @return {RegExp} The search text regexp
*/
function convertStringToRegExp(string, wildcard_character) {
if (typeof string !== 'string') {
throw new TypeError("complex_queries.convertStringToRegExp(): " +
"Argument 1 is not of type 'string'");
}
if (wildcard_character === undefined ||
wildcard_character === null || wildcard_character === '') {
return new RegExp("^" + stringEscapeRegexpCharacters(string) + "$");
}
if (typeof wildcard_character !== 'string' || wildcard_character.length > 1) {
throw new TypeError("complex_queries.convertStringToRegExp(): " +
"Optional argument 2 must be a string of length <= 1");
}
return new RegExp("^" + stringEscapeRegexpCharacters(string).replace(
new RegExp(stringEscapeRegexpCharacters(wildcard_character), 'g'),
'.*'
) + "$");
}
_export('convertStringToRegExp', convertStringToRegExp);
return to_export;
}));
This source diff could not be displayed because it is too large. You can view the blob instead.
/*
* Copyright 2013, Nexedi SA
* Released under the LGPL license.
* http://www.gnu.org/licenses/lgpl.html
*/
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, regexp: true */
/*global jIO, localStorage, setTimeout, complex_queries, window, define,
exports, require */
/**
* JIO Local Storage. Type = 'local'.
* Local browser "database" storage.
*
* Storage Description:
*
* {
* "type": "local",
* "mode": <string>,
* // - "localStorage" // default
* // - "memory"
* "username": <non empty string>, // to define user space
* "application_name": <string> // default 'untitled'
* }
*
* Document are stored in path
* 'jio/localstorage/username/application_name/document_id' like this:
*
* {
* "_id": "document_id",
* "_attachments": {
* "attachment_name": {
* "length": data_length,
* "digest": "md5-XXX",
* "content_type": "mime/type"
* },
* "attachment_name2": {..}, ...
* },
* "metadata_name": "metadata_value"
* "metadata_name2": ...
* ...
* }
*
* Only "_id" and "_attachments" are specific metadata keys, other one can be
* added without loss.
*
* @class LocalStorage
*/
// define([module_name], [dependencies], module);
(function (dependencies, module) {
"use strict";
if (typeof define === 'function' && define.amd) {
return define(dependencies, module);
}
if (typeof exports === 'object') {
return module(exports, require('jio'), require('complex_queries'));
}
window.local_storage = {};
module(window.local_storage, jIO, complex_queries);
}([
'exports',
'jio',
'complex_queries'
], function (exports, jIO, complex_queries) {
"use strict";
/**
* Checks if an object has no enumerable keys
*
* @param {Object} obj The object
* @return {Boolean} true if empty, else false
*/
function objectIsEmpty(obj) {
var k;
for (k in obj) {
if (obj.hasOwnProperty(k)) {
return false;
}
}
return true;
}
var ram = {}, memorystorage, localstorage;
/*
* Wrapper for the localStorage used to simplify instion of any kind of
* values
*/
localstorage = {
getItem: function (item) {
var value = localStorage.getItem(item);
return value === null ? null : JSON.parse(value);
},
setItem: function (item, value) {
return localStorage.setItem(item, JSON.stringify(value));
},
removeItem: function (item) {
return localStorage.removeItem(item);
}
};
/*
* Wrapper for the localStorage used to simplify instion of any kind of
* values
*/
memorystorage = {
getItem: function (item) {
var value = ram[item];
return value === undefined ? null : JSON.parse(value);
},
setItem: function (item, value) {
ram[item] = JSON.stringify(value);
},
removeItem: function (item) {
delete ram[item];
}
};
/**
* The JIO LocalStorage extension
*
* @class LocalStorage
* @constructor
*/
function LocalStorage(spec) {
if (typeof spec.username !== 'string' && !spec.username) {
throw new TypeError("LocalStorage 'username' must be a string " +
"which contains more than one character.");
}
this._localpath = 'jio/localstorage/' + spec.username + '/' + (
spec.application_name === null || spec.application_name ===
undefined ? 'untitled' : spec.application_name.toString()
);
switch (spec.mode) {
case "memory":
this._database = ram;
this._storage = memorystorage;
this._mode = "memory";
break;
default:
this._database = localStorage;
this._storage = localstorage;
this._mode = "localStorage";
break;
}
}
/**
* Create a document in local storage.
*
* @method post
* @param {Object} command The JIO command
* @param {Object} metadata The metadata to store
* @param {Object} options The command options
*/
LocalStorage.prototype.post = function (command, metadata) {
var doc, doc_id = metadata._id;
if (!doc_id) {
doc_id = jIO.util.generateUuid();
}
doc = this._storage.getItem(this._localpath + "/" + doc_id);
if (doc === null) {
// the document does not exist
doc = jIO.util.deepClone(metadata);
doc._id = doc_id;
delete doc._attachments;
this._storage.setItem(this._localpath + "/" + doc_id, doc);
command.success({"id": doc_id});
} else {
// the document already exists
command.error(
"conflict",
"document exists",
"Cannot create a new document"
);
}
};
/**
* Create or update a document in local storage.
*
* @method put
* @param {Object} command The JIO command
* @param {Object} metadata The metadata to store
* @param {Object} options The command options
*/
LocalStorage.prototype.put = function (command, metadata) {
var doc, tmp, status;
doc = this._storage.getItem(this._localpath + "/" + metadata._id);
if (doc === null) {
// the document does not exist
doc = jIO.util.deepClone(metadata);
delete doc._attachments;
status = "created";
} else {
// the document already exists
tmp = jIO.util.deepClone(metadata);
tmp._attachments = doc._attachments;
doc = tmp;
status = "no_content";
}
// write
this._storage.setItem(this._localpath + "/" + metadata._id, doc);
command.success(status);
};
/**
* Add an attachment to a document
*
* @method putAttachment
* @param {Object} command The JIO command
* @param {Object} param The given parameters
* @param {Object} options The command options
*/
LocalStorage.prototype.putAttachment = function (command, param) {
var that = this, doc, status = "ok";
doc = this._storage.getItem(this._localpath + "/" + param._id);
if (doc === null) {
// the document does not exist
return command.error(
"not_found",
"missing",
"Impossible to add attachment"
);
}
// the document already exists
// download data
jIO.util.readBlobAsBinaryString(param._blob).then(function (e) {
doc._attachments = doc._attachments || {};
if (doc._attachments[param._attachment]) {
status = "created";
}
doc._attachments[param._attachment] = {
"content_type": param._blob.type,
"digest": jIO.util.makeBinaryStringDigest(e.target.result),
"length": param._blob.size
};
that._storage.setItem(that._localpath + "/" + param._id + "/" +
param._attachment, e.target.result);
that._storage.setItem(that._localpath + "/" + param._id, doc);
command.success(status,
{"digest": doc._attachments[param._attachment].digest});
}, function (e) {
command.error(
"request_timeout",
"blob error",
"Error " + e.status + ", unable to get blob content"
);
}, function (e) {
command.notify((e.loaded / e.total) * 100);
});
};
/**
* Get a document
*
* @method get
* @param {Object} command The JIO command
* @param {Object} param The given parameters
* @param {Object} options The command options
*/
LocalStorage.prototype.get = function (command, param) {
var doc = this._storage.getItem(
this._localpath + "/" + param._id
);
if (doc !== null) {
command.success({"data": doc});
} else {
command.error(
"not_found",
"missing",
"Cannot find document"
);
}
};
/**
* Get an attachment
*
* @method getAttachment
* @param {Object} command The JIO command
* @param {Object} param The given parameters
* @param {Object} options The command options
*/
LocalStorage.prototype.getAttachment = function (command, param) {
var doc;
doc = this._storage.getItem(this._localpath + "/" + param._id);
if (doc === null) {
return command.error(
"not_found",
"missing document",
"Cannot find document"
);
}
if (typeof doc._attachments !== 'object' ||
typeof doc._attachments[param._attachment] !== 'object') {
return command.error(
"not_found",
"missing attachment",
"Cannot find attachment"
);
}
command.success({
"data": this._storage.getItem(
this._localpath + "/" + param._id +
"/" + param._attachment
) || "",
"content_type": doc._attachments[param._attachment].content_type || ""
});
};
/**
* Remove a document
*
* @method remove
* @param {Object} command The JIO command
* @param {Object} param The given parameters
* @param {Object} options The command options
*/
LocalStorage.prototype.remove = function (command, param) {
var doc, i, attachment_list;
doc = this._storage.getItem(this._localpath + "/" + param._id);
attachment_list = [];
if (doc !== null && typeof doc === "object") {
if (typeof doc._attachments === "object") {
// prepare list of attachments
for (i in doc._attachments) {
if (doc._attachments.hasOwnProperty(i)) {
attachment_list.push(i);
}
}
}
} else {
return command.error(
"not_found",
"missing",
"Document not found"
);
}
this._storage.removeItem(this._localpath + "/" + param._id);
// delete all attachments
for (i = 0; i < attachment_list.length; i += 1) {
this._storage.removeItem(this._localpath + "/" + param._id +
"/" + attachment_list[i]);
}
command.success();
};
/**
* Remove an attachment
*
* @method removeAttachment
* @param {Object} command The JIO command
* @param {Object} param The given parameters
* @param {Object} options The command options
*/
LocalStorage.prototype.removeAttachment = function (command, param) {
var doc = this._storage.getItem(this._localpath + "/" + param._id);
if (typeof doc !== 'object') {
return command.error(
"not_found",
"missing document",
"Document not found"
);
}
if (typeof doc._attachments !== "object" ||
typeof doc._attachments[param._attachment] !== "object") {
return command.error(
"not_found",
"missing attachment",
"Attachment not found"
);
}
delete doc._attachments[param._attachment];
if (objectIsEmpty(doc._attachments)) {
delete doc._attachments;
}
this._storage.setItem(this._localpath + "/" + param._id, doc);
this._storage.removeItem(this._localpath + "/" + param._id +
"/" + param._attachment);
command.success();
};
/**
* Get all filenames belonging to a user from the document index
*
* @method allDocs
* @param {Object} command The JIO command
* @param {Object} param The given parameters
* @param {Object} options The command options
*/
LocalStorage.prototype.allDocs = function (command, param, options) {
var i, row, path_re, rows, document_list, document_object;
param.unused = true;
rows = [];
document_list = [];
path_re = new RegExp(
"^" + complex_queries.stringEscapeRegexpCharacters(this._localpath) +
"/[^/]+$"
);
if (options.query === undefined && options.sort_on === undefined &&
options.select_list === undefined &&
options.include_docs === undefined) {
rows = [];
for (i in this._database) {
if (this._database.hasOwnProperty(i)) {
// filter non-documents
if (path_re.test(i)) {
row = { value: {} };
row.id = i.split('/').slice(-1)[0];
row.key = row.id;
if (options.include_docs) {
row.doc = JSON.parse(this._storage.getItem(i));
}
rows.push(row);
}
}
}
command.success({"data": {"rows": rows, "total_rows": rows.length}});
} else {
// create complex query object from returned results
for (i in this._database) {
if (this._database.hasOwnProperty(i)) {
if (path_re.test(i)) {
document_list.push(this._storage.getItem(i));
}
}
}
options.select_list = options.select_list || [];
options.select_list.push("_id");
if (options.include_docs === true) {
document_object = {};
document_list.forEach(function (meta) {
document_object[meta._id] = meta;
});
}
complex_queries.QueryFactory.create(options.query || "").
exec(document_list, options);
document_list = document_list.map(function (value) {
var o = {
"id": value._id,
"key": value._id
};
if (options.include_docs === true) {
o.doc = document_object[value._id];
delete document_object[value._id];
}
delete value._id;
o.value = value;
return o;
});
command.success({"data": {
"total_rows": document_list.length,
"rows": document_list
}});
}
};
/**
* Check the storage or a specific document
*
* @method check
* @param {Object} command The JIO command
* @param {Object} param The command parameters
* @param {Object} options The command options
*/
LocalStorage.prototype.check = function (command, param) {
this.genericRepair(command, param, false);
};
/**
* Repair the storage or a specific document
*
* @method repair
* @param {Object} command The JIO command
* @param {Object} param The command parameters
* @param {Object} options The command options
*/
LocalStorage.prototype.repair = function (command, param) {
this.genericRepair(command, param, true);
};
/**
* A generic method that manage check or repair command
*
* @method genericRepair
* @param {Object} command The JIO command
* @param {Object} param The command parameters
* @param {Boolean} repair If true then repair else just check
*/
LocalStorage.prototype.genericRepair = function (command, param, repair) {
var that = this, result;
function referenceAttachment(param, attachment) {
if (jIO.util.indexOf(param.referenced_attachments, attachment) !== -1) {
return;
}
var i = jIO.util.indexOf(param.unreferenced_attachments, attachment);
if (i !== -1) {
param.unreferenced_attachments.splice(i, 1);
}
param.referenced_attachments[param.referenced_attachments.length] =
attachment;
}
function attachmentFound(param, attachment) {
if (jIO.util.indexOf(param.referenced_attachments, attachment) !== -1) {
return;
}
if (jIO.util.indexOf(param.unreferenced_attachments, attachment) !== -1) {
return;
}
param.unreferenced_attachments[param.unreferenced_attachments.length] =
attachment;
}
function repairOne(param, repair) {
var i, doc, modified;
doc = that._storage.getItem(that._localpath + "/" + param._id);
if (doc === null) {
return; // OK
}
// check document type
if (typeof doc !== 'object') {
// wrong document
if (!repair) {
return {"error": true, "answers": [
"conflict",
"corrupted",
"Document is unrecoverable"
]};
}
// delete the document
that._storage.removeItem(that._localpath + "/" + param._id);
return; // OK
}
// good document type
// repair json document
if (!repair) {
if (!(new jIO.Metadata(doc).check())) {
return {"error": true, "answers": [
"conflict",
"corrupted",
"Some metadata might be lost"
]};
}
} else {
modified = jIO.util.uniqueJSONStringify(doc) !==
jIO.util.uniqueJSONStringify(new jIO.Metadata(doc).format()._dict);
}
if (doc._attachments !== undefined) {
if (typeof doc._attachments !== 'object') {
if (!repair) {
return {"error": true, "answers": [
"conflict",
"corrupted",
"Attachments are unrecoverable"
]};
}
delete doc._attachments;
that._storage.setItem(that._localpath + "/" + param._id, doc);
return; // OK
}
for (i in doc._attachments) {
if (doc._attachments.hasOwnProperty(i)) {
// check attachment existence
if (that._storage.getItem(that._localpath + "/" + param._id + "/" +
i) !== 'string') {
if (!repair) {
return {"error": true, "answers": [
"conflict",
"missing attachment",
"Attachment \"" + i + "\" of \"" + param._id + "\" is missing"
]};
}
delete doc._attachments[i];
if (objectIsEmpty(doc._attachments)) {
delete doc._attachments;
}
modified = true;
} else {
// attachment exists
// check attachment metadata
// check length
referenceAttachment(param, param._id + "/" + doc._attachments[i]);
if (doc._attachments[i].length !== undefined &&
typeof doc._attachments[i].length !== 'number') {
if (!repair) {
return {"error": true, "answers": [
"conflict",
"corrupted",
"Attachment metadata length corrupted"
]};
}
// It could take a long time to get the length, no repair.
// length can be omited
delete doc._attachments[i].length;
}
// It could take a long time to regenerate the hash, no check.
// Impossible to discover the attachment content type.
}
}
}
}
if (modified) {
that._storage.setItem(that._localpath + "/" + param._id, doc);
}
// OK
}
function repairAll(param, repair) {
var i, result;
for (i in that._database) {
if (that._database.hasOwnProperty(i)) {
// browsing every entry
if (i.slice(0, that._localpath.length) === that._localpath) {
// is part of the user space
if (/^[^\/]+\/[^\/]+$/.test(i.slice(that._localpath.length + 1))) {
// this is an attachment
attachmentFound(param, i.slice(that._localpath.length + 1));
} else if (/^[^\/]+$/.test(i.slice(that._localpath.length + 1))) {
// this is a document
param._id = i.slice(that._localpath.length + 1);
result = repairOne(param, repair);
if (result) {
return result;
}
} else {
// this is pollution
that._storage.removeItem(i);
}
}
}
}
// remove unreferenced attachments
for (i = 0; i < param.unreferenced_attachments.length; i += 1) {
that._storage.removeItem(that._localpath + "/" +
param.unreferenced_attachments[i]);
}
}
param.referenced_attachments = [];
param.unreferenced_attachments = [];
if (typeof param._id === 'string') {
result = repairOne(param, repair) || {};
} else {
result = repairAll(param, repair) || {};
}
if (result.error) {
return command.error.apply(command, result.answers || []);
}
command.success.apply(command, result.answers || []);
};
jIO.addStorage('local', LocalStorage);
//////////////////////////////////////////////////////////////////////
// Tools
/**
* Tool to help users to create local storage description for JIO
*
* @param {String} username The username
* @param {String} [application_name] The application_name
* @return {Object} The storage description
*/
function createDescription(username, application_name) {
var description = {
"type": "local",
"username": username.toString()
};
if (application_name !== undefined) {
description.application_name = application_name.toString();
}
return description;
}
exports.createDescription = createDescription;
function clear() {
var k;
for (k in localStorage) {
if (localStorage.hasOwnProperty(k)) {
if (/^jio\/localstorage\//.test(k)) {
localStorage.removeItem(k);
}
}
}
}
exports.clear = clear;
exports.clearLocalStorage = clear;
function clearMemoryStorage() {
jIO.util.dictClear(ram);
}
exports.clearMemoryStorage = clearMemoryStorage;
}));
(function (dependencies, module) {
if (typeof define === 'function' && define.amd) {
return define(dependencies, module);
}
if (typeof exports === 'object') {
return module(exports);
}
module(window);
}(['exports'], function (window) {
/* A JavaScript implementation of the Secure Hash Algorithm, SHA-256
* Version 0.3 Copyright Angel Marin 2003-2004 - http://anmar.eu.org/
* Distributed under the BSD License
* Some bits taken from Paul Johnston's SHA-1 implementation
*/
(function () {
var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */
function safe_add (x, y) {
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
return (msw << 16) | (lsw & 0xFFFF);
}
function S (X, n) {return ( X >>> n ) | (X << (32 - n));}
function R (X, n) {return ( X >>> n );}
function Ch(x, y, z) {return ((x & y) ^ ((~x) & z));}
function Maj(x, y, z) {return ((x & y) ^ (x & z) ^ (y & z));}
function Sigma0256(x) {return (S(x, 2) ^ S(x, 13) ^ S(x, 22));}
function Sigma1256(x) {return (S(x, 6) ^ S(x, 11) ^ S(x, 25));}
function Gamma0256(x) {return (S(x, 7) ^ S(x, 18) ^ R(x, 3));}
function Gamma1256(x) {return (S(x, 17) ^ S(x, 19) ^ R(x, 10));}
function newArray (n) {
var a = [];
for (;n>0;n--) {
a.push(undefined);
}
return a;
}
function core_sha256 (m, l) {
var K = [0x428A2F98,0x71374491,0xB5C0FBCF,0xE9B5DBA5,0x3956C25B,0x59F111F1,0x923F82A4,0xAB1C5ED5,0xD807AA98,0x12835B01,0x243185BE,0x550C7DC3,0x72BE5D74,0x80DEB1FE,0x9BDC06A7,0xC19BF174,0xE49B69C1,0xEFBE4786,0xFC19DC6,0x240CA1CC,0x2DE92C6F,0x4A7484AA,0x5CB0A9DC,0x76F988DA,0x983E5152,0xA831C66D,0xB00327C8,0xBF597FC7,0xC6E00BF3,0xD5A79147,0x6CA6351,0x14292967,0x27B70A85,0x2E1B2138,0x4D2C6DFC,0x53380D13,0x650A7354,0x766A0ABB,0x81C2C92E,0x92722C85,0xA2BFE8A1,0xA81A664B,0xC24B8B70,0xC76C51A3,0xD192E819,0xD6990624,0xF40E3585,0x106AA070,0x19A4C116,0x1E376C08,0x2748774C,0x34B0BCB5,0x391C0CB3,0x4ED8AA4A,0x5B9CCA4F,0x682E6FF3,0x748F82EE,0x78A5636F,0x84C87814,0x8CC70208,0x90BEFFFA,0xA4506CEB,0xBEF9A3F7,0xC67178F2];
var HASH = [0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19];
var W = newArray(64);
var a, b, c, d, e, f, g, h, i, j;
var T1, T2;
/* append padding */
m[l >> 5] |= 0x80 << (24 - l % 32);
m[((l + 64 >> 9) << 4) + 15] = l;
for ( var i = 0; i<m.length; i+=16 ) {
a = HASH[0]; b = HASH[1]; c = HASH[2]; d = HASH[3];
e = HASH[4]; f = HASH[5]; g = HASH[6]; h = HASH[7];
for ( var j = 0; j<64; j++) {
if (j < 16) {
W[j] = m[j + i];
} else {
W[j] = safe_add(safe_add(safe_add(Gamma1256(
W[j - 2]), W[j - 7]), Gamma0256(W[j - 15])), W[j - 16]);
}
T1 = safe_add(safe_add(safe_add(
safe_add(h, Sigma1256(e)), Ch(e, f, g)), K[j]), W[j]);
T2 = safe_add(Sigma0256(a), Maj(a, b, c));
h = g; g = f; f = e; e = safe_add(d, T1);
d = c; c = b; b = a; a = safe_add(T1, T2);
}
HASH[0] = safe_add(a, HASH[0]); HASH[1] = safe_add(b, HASH[1]);
HASH[2] = safe_add(c, HASH[2]); HASH[3] = safe_add(d, HASH[3]);
HASH[4] = safe_add(e, HASH[4]); HASH[5] = safe_add(f, HASH[5]);
HASH[6] = safe_add(g, HASH[6]); HASH[7] = safe_add(h, HASH[7]);
}
return HASH;
}
function str2binb (str) {
var bin = Array();
var mask = (1 << chrsz) - 1;
for(var i = 0; i < str.length * chrsz; i += chrsz)
bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (24 - i%32);
return bin;
}
function binb2hex (binarray) {
var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
var str = "";
for (var i = 0; i < binarray.length * 4; i++) {
str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) +
hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8 )) & 0xF);
}
return str;
}
function hex_sha256(s){
return binb2hex(core_sha256(str2binb(s),s.length * chrsz));
}
window.hex_sha256 = hex_sha256;
}());
}));
/*
* jQuery validVal version 5.0.1
* demo's and documentation:
* validval.frebsite.nl
*
* Copyright (c) 2013 Fred Heusschen
* www.frebsite.nl
*
* Dual licensed under the MIT and GPL licenses.
* http://en.wikipedia.org/wiki/MIT_License
* http://en.wikipedia.org/wiki/GNU_General_Public_License
*/
(function( $ )
{
var _PLUGIN_ = 'validVal',
_FIELD_ = 'validValField',
_VERSION_ = '5.0.1',
_INPUTS_ = 'textarea, select, input:not( [type="button"], [type="submit"], [type="reset"] )';
// validVal already excists
if ( $.fn[ _PLUGIN_ ] )
{
return;
}
function ValidVal( form, opts )
{
this.form = form;
this.opts = $.extend( true, {}, $.fn[ _PLUGIN_ ].defaults, opts );
this._gatherValidation();
this._bindEvents();
this._bindCustomEvents();
this.addField( this.opts.validate.fields.filter( $(_INPUTS_, this.form) ) );
}
ValidVal.prototype = {
// Public methods
addField: function( $field )
{
if ( isHtmlElement( $field ) || typeof $field == 'string' )
{
$field = $( $field );
}
if ( !( $field instanceof $ ) )
{
$.fn[ _PLUGIN_ ].debug( 'Not a valid argument for "$field"' );
return this;
}
var that = this;
return $field.each(
function()
{
var $f = $(this),
vf = $f.data( _FIELD_ );
if ( vf )
{
vf.destroy();
}
$f.data( _FIELD_, new ValidValField( $f, that ) );
}
);
},
validate: function( body, callCallback )
{
var that = this;
// Complement arguments
if ( typeof body == 'undefined' )
{
body = this.form;
callCallback = true;
}
else if ( typeof callCallback != 'boolean' )
{
callCallback = false;
}
if ( typeof this.opts.form.onValidate == 'function' )
{
this.opts.form.onValidate.call( this.form[ 0 ], this.opts.language );
}
// Set varialbes
var miss_arr = $(),
data_obj = {};
// Validate fields
this.opts.validate.fields.filter( $(_INPUTS_, body) ).each(
function()
{
var $f = $(this),
vf = $f.data( _FIELD_ );
if ( vf )
{
vf.validate( that.opts.validate.onSubmit )
if ( vf.valid )
{
var v = $f.val();
if ( $f.is( '[type="radio"]' ) || $f.is( '[type="checkbox"]' ) )
{
if ( !$f.is( ':checked' ) )
{
v = '';
}
}
if ( typeof v == 'undefined' || v == null )
{
v = '';
}
data_obj[ $f.attr( 'name' ) ] = v;
}
else
{
if ( that.opts.validate.onSubmit !== false )
{
miss_arr = miss_arr.add( $f );
}
}
}
}
);
// Not valid
if ( miss_arr.length > 0 )
{
if ( typeof this.opts.form.onInvalid == 'function' && callCallback )
{
this.opts.form.onInvalid.call( this.form[ 0 ], miss_arr, this.opts.language );
}
return false;
}
// Valid
else
{
if ( typeof this.opts.form.onValid == 'function' && callCallback )
{
this.opts.form.onValid.call( this.form[ 0 ], this.opts.language );
}
return data_obj;
}
},
submitForm: function()
{
var result = this.validate();
if ( result )
{
this.opts.validate.fields.filter( $(_INPUTS_, this.form) ).each(
function()
{
var vf = $(this).data( _FIELD_ );
if ( vf )
{
vf.clearPlaceholderValue();
}
}
);
}
return result;
},
resetForm: function()
{
var that = this;
if ( typeof this.opts.form.onReset == 'function' )
{
this.opts.form.onReset.call( this.form[ 0 ], this.opts.language );
}
this.opts.validate.fields.filter( $(_INPUTS_, this.form) ).each(
function()
{
var $f = $(this),
vf = $f.data( _FIELD_ );
if ( vf )
{
if ( vf.placeholderValue !== false )
{
$f.addClass( 'inactive' );
$f.val( vf.placeholderValue );
}
else
{
$f.val( vf.originalValue );
}
vf.isValid( true, true );
}
}
);
return true;
},
options: function( o )
{
if ( typeof o == 'object' )
{
this.opts = $.extend( this.opts, o );
}
return this.opts;
},
destroy: function()
{
this.form.unbind( '.vv' );
this.form.data( _PLUGIN_, null );
this.opts.validate.fields.filter( $(_INPUTS_, this.form) ).each(
function()
{
var vf = $(this).data( _FIELD_ );
if ( vf )
{
vf.destroy();
}
}
);
return true;
},
// Protected methods
_gatherValidation: function()
{
this.opts.validations = {};
if ( $.fn[ _PLUGIN_ ].customValidations )
{
this.opts.validations = $.extend( this.opts.validations, $.fn[ _PLUGIN_ ].customValidations );
}
if ( this.opts.customValidations )
{
this.opts.validations = $.extend( this.opts.validations, this.opts.customValidations );
}
this.opts.validations = $.extend( this.opts.validations, $.fn[ _PLUGIN_ ].defaultValidations );
return this;
},
_bindEvents: function ()
{
var that = this;
if ( this.form.is( 'form' ) )
{
this.form.attr( 'novalidate', 'novalidate' );
this.form.bind(
namespace( 'submit' ),
function( event, validate )
{
if ( typeof validate != 'boolean' )
{
validate = true;
}
return ( validate )
? that.submitForm()
: true;
}
);
this.form.bind(
namespace( 'reset' ),
function( event )
{
return that.resetForm();
}
);
}
return this;
},
_bindCustomEvents: function()
{
var that = this;
this.form.bind(
namespace([
'addField',
'destroy',
'validate',
'submitForm',
'resetForm',
'options'
]),
function()
{
arguments = Array.prototype.slice.call( arguments );
var event = arguments.shift(),
type = event.type;
event.stopPropagation();
if ( typeof that[ type ] != 'function' )
{
$.fn.validVal.debug( 'Public method "' + type + '" not found.' );
return false;
}
return that[ type ].apply( that, arguments );
}
);
return this;
}
};
function ValidValField( field, form )
{
this.field = field;
this.form = form;
this.originalValue = this.field.attr( 'value' ) || '';
this._gatherValidations();
this._bindEvents();
this._bindCustomEvents();
this._init();
}
ValidValField.prototype = {
// Public methods
validate: function( onEvent, fixPlaceholder )
{
var that = this;
if ( onEvent === false )
{
return;
}
if ( typeof fixPlaceholder != 'boolean' )
{
fixPlaceholder = true;
}
this.valid = true;
if ( ( this.field.is( ':hidden' ) && !this.form.opts.validate.fields.hidden ) ||
( this.field.is( ':disabled' ) && !this.form.opts.validate.fields.disabled )
) {
return true;
}
if ( fixPlaceholder )
{
this.clearPlaceholderValue();
}
if ( typeof this.form.opts.fields.onValidate == 'function' )
{
this.form.opts.fields.onValidate.call( this.field[ 0 ], this.form.form, this.form.opts.language );
}
var invalid_check = false,
val = trim( this.field.val() );
for ( var v in this.form.opts.validations )
{
var f = this.form.opts.validations[ v ];
if ( typeof f == 'function' && $.inArray( v, this.validations ) != -1 )
{
if ( !f.call( this.field[ 0 ], val ) )
{
invalid_check = v;
break;
}
}
}
this.valid = ( invalid_check ) ? false : true;
var callCallback = ( this.valid )
? ( onEvent !== 'invalid' )
: ( onEvent !== 'valid' );
this.isValid( this.valid, callCallback, invalid_check );
if ( this.validationgroup !== false )
{
$(_INPUTS_).not( this.field ).each(
function()
{
var vf = $(this).data( _FIELD_ );
if ( vf && vf.validationgroup == that.validationgroup )
{
vf.isValid( that.valid, true );
}
}
);
}
if ( fixPlaceholder )
{
this.restorePlaceholderValue();
}
if ( invalid_check )
{
$.fn[ _PLUGIN_ ].debug( 'invalid validation: ' + invalid_check );
}
return this.valid;
},
isValid: function( valid, callCallback )
{
if ( typeof valid == 'boolean' )
{
this.valid = valid;
if ( callCallback )
{
var fn = ( valid ) ? 'onValid' : 'onInvalid';
if ( typeof this.form.opts.fields[ fn ] == 'function' )
{
this.form.opts.fields[ fn ].call( this.field[ 0 ], this.form.form, this.form.opts.language );
}
}
}
return this.valid;
},
getValidations: function()
{
return this.validations;
},
setValidations: function( validations )
{
if ( typeof validations == 'string' )
{
this.validations = validations.split( ' ' );
}
else if ( validations instanceof Array )
{
this.validations = validations;
}
else
{
$.fn.validVal.debug( 'Argument "validations" should be an array.' );
}
return this.validations;
},
addValidation: function( validation )
{
if ( typeof validation == 'string' )
{
validation = validation.split( ' ' );
}
for( var v in validation )
{
this.validations.push( validation[ v ] );
}
return this.validations;
},
removeValidation: function( validation )
{
if ( typeof validation == 'string' )
{
validation = validation.split( ' ' );
}
for( var v in validation )
{
var pos = $.inArray( validation[ v ], this.validations );
if ( pos != -1 )
{
this.validations.splice( pos, 1 );
}
}
return this.validations;
},
clearPlaceholderValue: function()
{
this._togglePlaceholderValue( 'clear' );
return true;
},
restorePlaceholderValue: function()
{
this._togglePlaceholderValue( 'restore' );
return true;
},
destroy: function()
{
this.field.unbind( '.vv' );
this.field.data( _FIELD_, null );
return true;
},
// Protected methods
_gatherValidations: function()
{
this.autotab = false;
this.corresponding = false;
this.requiredgroup = false;
this.validationgroup = false;
this.placeholderValue = false;
this.placeholderNumber = false;
this.passwordplaceholder = false;
this.validations = [];
if ( this.field.is( 'select' ) )
{
this.originalValue = this.field.find( 'option:first' ).attr( 'value' ) || '';
}
else if ( this.field.is( 'textarea' ) )
{
this.originalValue = this.field.text();
}
// Refactor HTML5 usage
if ( this.form.opts.supportHtml5 )
{
var valids = this.field.data( 'vv-validations' );
if ( valids )
{
this.validations.push( valids );
this.__removeAttr( 'data-vv-validations' );
}
// Placeholder attribute, only use if placeholder not supported by browser or placeholder not in keepAttributes-option
if ( this.__hasHtml5Attr( 'placeholder' ) && this.field.attr( 'placeholder' ).length > 0 )
{
if ( !$.fn[ _PLUGIN_ ].support.placeholder || $.inArray( 'placeholder', this.form.opts.keepAttributes ) == -1 )
{
this.placeholderValue = this.field.attr( 'placeholder' );
}
}
if ( this.placeholderValue !== false )
{
this.__removeAttr( 'placeholder' );
}
// Pattern attribute
if ( this.__hasHtml5Attr( 'pattern' ) && this.field.attr( 'pattern' ).length > 0 )
{
this.pattern = this.field.attr( 'pattern' );
this.validations.push( 'pattern' );
this.__removeAttr( 'pattern' );
}
// Corresponding, required group and validation group
var dts = [ 'corresponding', 'requiredgroup', 'validationgroup' ];
for ( var d = 0, l = dts.length; d < l; d++ )
{
var dt = this.field.data( 'vv-' + dts[ d ] );
if ( dt )
{
this[ dts[ d ] ] = dt;
this.validations.push( dts[ d ] );
this.__removeAttr( 'data-vv-' + dts[ d ] );
}
}
// Attributes
var atr = [ 'required', 'autofocus' ];
for ( var a = 0, l = atr.length; a < l; a++ )
{
if ( this.__hasHtml5Attr( atr[ a ] ) )
{
this.validations.push( atr[ a ] );
this.__removeAttr( atr[ a ] );
}
}
// Type-values
var typ = [ 'number', 'email', 'url' ];
for ( var t = 0, l = typ.length; t < l; t++ )
{
if ( this.__hasHtml5Type( typ[ t ] ) )
{
this.validations.push( typ[ t ] );
}
}
// Autotab
if ( this.field.data( 'vv-autotab' ) )
{
this.autotab = true;
this.__removeAttr( 'data-vv-autotab' );
}
}
// Refactor non-HTML5 usage
var classes = this.field.attr( 'class' );
if ( classes && classes.length )
{
// Placeholder
if ( this.field.hasClass( 'placeholder' ) )
{
if ( this.field.is( 'select' ) )
{
var num = 0,
opt = this.field.data( 'vv-placeholder-number' );
if ( opt )
{
num = opt;
this.__removeAttr( 'data-vv-placeholder-number' );
}
else if ( typeof this.form.opts.selectPlaceholder == 'number' )
{
num = this.form.opts.selectPlaceholder;
}
else
{
var $options = this.field.find( 'option' ),
selected = $options.index( $options.filter( '[selected]' ) );
if ( selected > -1 )
{
num = selected;
}
}
this.placeholderNumber = num;
this.originalValue = this.field.find( 'option:eq( ' + num + ' )' ).attr( 'value' ) || '';
}
this.placeholderValue = this.originalValue;
this.originalValue = '';
this.__removeClass( 'placeholder' );
}
// Corresponding
var corsp = 'corresponding:',
start = classes.indexOf( corsp );
if ( start != -1 )
{
var corrcls = classes.substr( start ).split( ' ' )[ 0 ],
corresp = corrcls.substr( corsp.length );
if ( corresp.length )
{
this.corresponding = corresp;
this.validations.push( 'corresponding' );
this.field.removeClass( corrcls );
}
}
// Pattern
// still uses alt-attribute...
if ( this.field.hasClass( 'pattern' ) )
{
this.pattern = this.field.attr( 'alt' ) || '';
this.validations.push( 'pattern' );
this.__removeAttr( 'alt' );
this.__removeClass( 'pattern' );
}
// Groups
var grp = [ 'requiredgroup', 'validationgroup' ];
for ( var g = 0, l = grp.length; g < l; g++ )
{
var group = grp[ g ] + ':',
start = classes.indexOf( group );
if ( start != -1 )
{
var groupclass = classes.substr( start ).split( ' ' )[ 0 ],
groupname = groupclass.substr( group.length );
if ( groupname.length )
{
this[ grp[ g ] ] = groupname;
this.validations.push( grp[ g ]);
this.field.removeClass( groupclass );
}
}
}
// Autotab
if ( this.field.hasClass( 'autotab' ) )
{
this.autotab = true;
this.__removeClass( 'autotab' );
}
}
// Password placeholder
if ( this.placeholderValue !== false && this.field.is( '[type="password"]' ) )
{
this.passwordplaceholder = true;
}
// Add all remaining classes
var classes = this.field.attr( 'class' );
if ( classes && classes.length )
{
this.validations.push( classes );
}
this.validations = unique( this.validations.join( ' ' ).split( ' ' ) );
return this;
},
_bindEvents: function()
{
var that = this;
this.field.bind(
namespace( 'focus' ),
function( event )
{
$(this).addClass( 'focus' );
that.clearPlaceholderValue();
}
);
this.field.bind(
namespace( 'blur' ),
function( event )
{
$(this).removeClass( 'focus' );
that.validate( that.form.opts.validate.onBlur );
}
);
this.field.bind(
namespace( 'keyup' ),
function( event )
{
if ( !preventkeyup( event.keyCode ) )
{
that.validate( that.form.opts.validate.onKeyup, false );
}
}
);
if ( this.field.is( 'select, input[type="checkbox"], input[type="radio"]' ) )
{
this.field.bind(
namespace( 'change' ),
function( event )
{
$(this).trigger( namespace( 'blur' ) );
}
);
}
return this;
},
_bindCustomEvents: function()
{
var that = this;
this.field.bind(
namespace([
'validate',
'isValid',
'destroy',
'addValidation',
'removeValidation'
]),
function()
{
arguments = Array.prototype.slice.call( arguments );
var event = arguments.shift(),
type = event.type;
event.stopPropagation();
if ( typeof that[ type ] != 'function' )
{
$.fn.validVal.debug( 'Public method "' + type + '" not found.' );
return false;
}
return that[ type ].apply( that, arguments );
}
);
this.field.bind(
namespace([ 'validations' ]),
function( event, validations, callCallback )
{
if ( typeof validations == 'undefined' )
{
return this.getValidations();
}
else
{
return this.setValidations( validations, callCallback );
}
}
);
return this;
},
_init: function()
{
var that = this;
// Placeholder
if ( this.placeholderValue !== false )
{
if ( this.field.val() == '' )
{
this.field.val( this.placeholderValue );
}
if ( this.passwordplaceholder )
{
if ( this.field.val() == this.placeholderValue ) try
{
this.field[ 0 ].type = 'text';
}
catch( err ) {};
}
if ( this.field.val() == this.placeholderValue )
{
this.field.addClass( 'inactive' );
}
if ( this.field.is( 'select' ) )
{
this.field.find( 'option:eq(' + this.placeholderNumber + ')' ).addClass( 'inactive' );
this.field.bind(
namespace( 'change' ),
function( event )
{
$(this)[ that.field.val() == that.placeholderValue ? 'addClass' : 'removeClass' ]( 'inactive' );
}
);
}
}
// Corresponding
if ( this.corresponding !== false )
{
$(_INPUTS_).filter('[name="' + this.corresponding + '"]').bind(
namespace( 'blur' ),
function( event )
{
that.validate( that.form.opts.validate.onBlur );
}
).bind(
namespace( 'keyup' ),
function( event )
{
if ( !preventkeyup( event.keyCode ) )
{
that.validate( that.form.opts.validate.onKeyup, false );
}
}
);
}
// Autotabbing
if ( this.autotab )
{
var max = this.field.attr( 'maxlength' ),
tab = this.field.attr( 'tabindex' ),
$next = $(_INPUTS_).filter('[tabindex="' + ( parseInt( tab ) + 1 ) + '"]');
if ( this.field.is( 'select' ) )
{
if ( tab )
{
this.field.bind(
namespace( 'change' ),
function( event )
{
if ( $next.length )
{
$next.focus();
}
}
);
}
}
else
{
if ( max && tab )
{
this.field.bind(
namespace( 'keyup' ),
function( event )
{
if ( $(this).val().length == max )
{
if ( !preventkeyup( event.keyCode ) )
{
$(this).trigger( namespace( 'blur' ) );
if ( $next.length )
{
$next.focus();
}
}
}
}
);
}
}
}
// Autofocus
if ( $.inArray( 'autofocus', this.validations ) != -1 && !this.field.is( ':disabled' ) )
{
this.field.focus();
}
return this;
},
_togglePlaceholderValue: function( toggle )
{
if ( this.placeholderValue !== false )
{
if ( toggle == 'clear' )
{
var v1 = this.placeholderValue,
v2 = '',
cl = 'removeClass',
tp = 'password';
}
else
{
var v1 = '',
v2 = this.placeholderValue,
cl = 'addClass',
tp = 'text';
}
if ( this.field.val() == v1 && !this.field.is( 'select' ) )
{
this.field.val( v2 );
this.field[ cl ]( 'inactive' );
if ( this.passwordplaceholder ) try
{
this.field[ 0 ].type = tp;
}
catch( err ) {};
}
}
return this;
},
// Private methods
__hasHtml5Attr: function( a )
{
// non HTML5 browsers
if ( typeof this.field.attr( a ) == 'undefined' )
{
return false;
}
// HTML5 browsers
if ( this.field.attr( a ) === 'false' || this.field.attr( a ) === false )
{
return false;
}
return true;
},
__hasHtml5Type: function( t )
{
// cool HTML5 browsers
if ( this.field.attr( 'type' ) == t )
{
return true;
}
// non-HTML5 but still cool browsers
if ( this.field.is( 'input[type="' + t + '"]' ) )
{
return true;
}
// non-HTML5, non-cool browser
var $c = $( '<div />' ).append( this.field.clone() ).html()
if ( $c.indexOf( 'type="' + t + '"' ) != -1 || $c.indexOf( 'type=\'' + t + '\'' ) != -1 || $c.indexOf( 'type=' + t + '' ) != -1 )
{
return true;
}
return false;
},
__removeAttr: function( a )
{
if ( $.inArray( a, this.form.opts.keepAttributes ) == -1 )
{
this.field.removeAttr( a );
}
return this;
},
__removeClass: function( c )
{
if ( $.inArray( c, this.form.opts.keepClasses ) == -1 )
{
this.field.removeClass( c );
}
return this;
}
};
$.fn[ _PLUGIN_ ] = function( o, c )
{
return this.each(
function()
{
var $t = $(this);
if ( $t.data( _PLUGIN_ ) )
{
$t.data( _PLUGIN_ ).destroy();
}
$t.data( _PLUGIN_, new ValidVal( $t, o, c ) );
}
);
};
$.fn[ _PLUGIN_ ].version = _VERSION_;
$.fn[ _PLUGIN_ ].defaults = {
'selectPlaceholder' : 0,
'supportHtml5' : true,
'language' : 'en',
'customValidations' : {},
'validate' : {
'onBlur' : true,
'onSubmit' : true,
'onKeyup' : false,
'fields' : {
'hidden' : false,
'disabled' : false,
'filter' : function( $i )
{
return $i;
}
}
},
'fields' : {
'onValidate' : null,
'onValid' : function()
{
$(this).add( $(this).parent() ).removeClass( 'invalid' );
},
'onInvalid' : function()
{
$(this).add( $(this).parent() ).addClass( 'invalid' );
}
},
'form' : {
'onReset' : null,
'onValidate': null,
'onValid' : null,
'onInvalid' : function( fieldArr, language )
{
switch ( language )
{
case 'nl':
msg = 'Let op, niet alle velden zijn correct ingevuld.';
break;
case 'de':
msg = 'Achtung, nicht alle Felder sind korrekt ausgefuellt.';
break;
case 'es':
msg = 'Atención, no se han completado todos los campos correctamente.';
break;
case 'en':
default:
msg = 'Attention, not all fields have been filled out correctly.';
break;
}
alert( msg );
fieldArr.first().focus();
}
},
'keepClasses' : [ 'required' ],
'keepAttributes': [ 'pattern', 'placeholder' ]
};
$.fn[ _PLUGIN_ ].defaultValidations = {
'required': function( v )
{
var $f = $(this);
if ( $f.is( '[type="radio"]' ) || $f.is( '[type="checkbox"]' ) )
{
if ( $f.is( '[type="radio"]' ) )
{
var name = $f.attr( 'name' );
if ( name && name.length > 0 )
{
$f = $( 'input[name="' + name + '"]' );
}
}
if ( !$f.is( ':checked' ) )
{
return false;
}
}
else if ( $f.is( 'select' ) )
{
var vf = $f.data( _FIELD_ );
if ( vf && vf.placeholderValue !== false )
{
if ( $f.val() == vf.placeholderValue )
{
return false;
}
}
else
{
if ( v.length == 0 )
{
return false;
}
}
}
else
{
if ( v.length == 0 )
{
return false;
}
}
return true;
},
'Required': function( v )
{
return $.fn[ _PLUGIN_ ].defaultValidations.required.call( this, v );
},
'requiredgroup': function( v )
{
var $f = $(this),
vf = $f.data( _FIELD_ );
if ( vf && vf.requiredgroup !== false )
{
$f = $();
$(_INPUTS_).each(
function()
{
var tf = $(this).data( _FIELD_ );
if ( tf && tf.requiredgroup == vf.requiredgroup )
{
$f = $f.add( this );
}
}
);
}
var result = false;
$f.each(
function()
{
var f = this;
if ( $.fn[ _PLUGIN_ ].defaultValidations.required.call( f, trim( $(f).val() ) ) )
{
result = true;
}
}
);
return result;
},
'corresponding': function( v )
{
var org = '',
vf = $(this).data( _FIELD_ );
if ( vf && vf.corresponding !== false )
{
var $f = $(_INPUTS_).filter('[name="' + vf.corresponding + '"]'),
vf = $f.data( _FIELD_ );
if ( vf )
{
vf.clearPlaceholderValue();
org = trim( $f.val() );
vf.restorePlaceholderValue();
}
return ( v == org );
}
return false;
},
'number': function( v )
{
v = stripWhitespace( v );
if ( v.length == 0 )
{
return true;
}
if ( isNaN( v ) )
{
return false;
}
return true;
},
'email': function( v )
{
if ( v.length == 0 )
{
return true;
}
var r = /^([a-zA-Z0-9_\.\-+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
return r.test( v );
},
'url': function( v )
{
if ( v.length == 0 )
{
return true;
}
if ( v.match(/^www\./) )
{
v = "http://" + v;
}
return v.match(/^(http\:\/\/|https\:\/\/)(.{4,})$/);
},
'pattern': function( v )
{
if ( v.length == 0 )
{
return true;
}
var $f = $(this),
vf = $f.data( 'validVal' );
if ( vf )
{
var p = vf.pattern;
if ( p.slice( 0, 1 ) == '/' )
{
p = p.slice( 1 );
}
if ( p.slice( 1 ) == '/' )
{
p = p.slice( 0, -1 );
}
return new RegExp( p ).test( v );
}
}
};
// test for borwser support
$.fn[ _PLUGIN_ ].support = {
touch: (function()
{
return 'ontouchstart' in document.documentElement;
})(),
placeholder: (function()
{
return 'placeholder' in document.createElement( 'input' );
})()
};
$.fn[ _PLUGIN_ ].debug = function( msg ) {};
$.fn[ _PLUGIN_ ].deprecated = function( func, alt )
{
if ( typeof console != 'undefined' )
{
if ( typeof console.error != 'undefined' )
{
console.error( func + ' is DEPRECATED, use ' + alt + ' instead.' );
}
}
};
// Create debugger is it doesn't already excists
if ( !$.fn.validValDebug )
{
$.fn.validValDebug = function( b )
{
$.fn[ _PLUGIN_ ].debug( 'validVal debugger not installed!' );
return this;
}
}
function isHtmlElement( field )
{
if ( typeof HTMLElement != 'undefined' )
{
return field instanceof HTMLElement;
}
return ( field.nodeType && field.nodeType == Node.ELEMENT_NODE );
}
function namespace( events )
{
if ( typeof events == 'string' )
{
events = events.split( ' ' );
}
return events.join( '.vv ' ) + '.vv';
}
function unique( arr )
{
return $.grep(
arr,
function( v, k )
{
return $.inArray( v, arr ) === k;
}
);
}
function trim( str )
{
if ( str === null )
{
return '';
}
if ( typeof str == 'object' )
{
var arr = [];
for ( var a in str )
{
arr[ a ] = trim( str[ a ] );
}
return arr;
}
if ( typeof str != 'string' )
{
return '';
}
if ( str.length == 0 )
{
return '';
}
return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}
function stripWhitespace( str )
{
if ( str === null )
{
return '';
}
if ( typeof str == 'object' )
{
for ( var a in str )
{
str[ a ] = stripWhitespace( str[ a ] );
}
return str;
}
if ( typeof str != 'string' )
{
return '';
}
if ( str.length == 0 )
{
return '';
}
str = trim( str );
var r = [ ' ', '-', '+', '(', ')', '/', '\\' ];
for ( var i = 0, l = r.length; i < l; i++ )
{
str = str.split( r[ i ] ).join( '' );
}
return str;
}
function preventkeyup( kc )
{
switch( kc ) {
case 9: // tab
case 13: // enter
case 16: // shift
case 17: // control
case 18: // alt
case 37: // left
case 38: // up
case 39: // right
case 40: // down
case 224: // command
return true;
break;
default:
return false;
break;
}
}
})( jQuery );
\ No newline at end of file
......@@ -38,10 +38,7 @@
<script src="js/libs/jquery/jquery.js"></script>
<script src="js/libs/jquery-mobile/jquery-mobile.js"></script>
<script src="js/extensions.js"></script>
<script src="js/libs/jio/sha256.amd.js"></script>
<script src="js/libs/jio/jio.js"></script>
<script src="js/libs/jio/complex_queries.js"></script>
<script src="js/libs/jio/localstorage.js"></script>
<script src="js/plugins/validval/jquery.validVal.js"></script>
<!-- stuff happens here -->
<script src="js/erp5_loader.js"></script>
......
......@@ -38,10 +38,7 @@
<script src="js/libs/jquery/jquery.js"></script>
<script src="js/libs/jquery-mobile/jquery-mobile.js"></script>
<script src="js/extensions.js"></script>
<script src="js/libs/jio/sha256.amd.js"></script>
<script src="js/libs/jio/jio.js"></script>
<script src="js/libs/jio/complex_queries.js"></script>
<script src="js/libs/jio/localstorage.js"></script>
<script src="js/plugins/validval/jquery.validVal.js"></script>
<!-- stuff happens here -->
<script src="js/erp5_loader.js"></script>
......
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 to comment