1 // misc utility functions
3 function assert(outcome, description) {
5 console.log(description);
9 function templateFromId(id) {
10 return _.template($(id).html());
13 function firstCharUpper(s) {
14 return s.charAt(0).toUpperCase() + s.slice(1);
17 // http://stackoverflow.com/questions/2117320/set-maximum-displayed-rows-count-for-html-table
18 function limitTableRows(tableSelector, maxRows) {
19 var table = $(tableSelector)[0] //document.getElementById(tableId);
20 var wrapper = table.parentNode;
21 var rowsInTable = table.rows.length;
23 var border = getComputedStyle(table.rows[0].cells[0], '').getPropertyValue('border-top-width');
24 border = border.replace('px', '') * 1;
26 var border = table.rows[0].cells[0].currentStyle.borderWidth;
27 border = (border.replace('px', '') * 1) / 2;
30 if (rowsInTable > maxRows) {
31 for (var i = 0; i < maxRows; i++) {
32 height += table.rows[i].clientHeight + border;
33 //console.log("XXX " + height + " " + table.rows[i].clientHeight + " " + border);
35 wrapper.style.height = height + "px";
39 function validateField(validatorName, value, obj) {
40 if (validatorName=="notBlank") {
41 if ((value==undefined) || (value=="")) {
42 return "can not be blank";
46 // if notBlank wasn't set, and the field is blank, then we can return
47 if ((value==undefined) || (value=="")) {
51 switch (validatorName) {
53 if (! /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value)) {
54 return "must be a valid url";