X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetstack%2Fcore%2Fxoslib%2Fstatic%2Fjs%2Fxoslib%2Fxos-util.js;h=59fb06ec5fb186c14c8096654ae75ece84dff340;hb=85743c1a683903301d2d69b4a552b56ab6effcba;hp=c1f736ebff96309a051d5d7198ac65c7565e523e;hpb=43e37ab9119107c59488919f67f448c07a0f9a88;p=plstackapi.git diff --git a/planetstack/core/xoslib/static/js/xoslib/xos-util.js b/planetstack/core/xoslib/static/js/xoslib/xos-util.js index c1f736e..59fb06e 100644 --- a/planetstack/core/xoslib/static/js/xoslib/xos-util.js +++ b/planetstack/core/xoslib/static/js/xoslib/xos-util.js @@ -1,5 +1,15 @@ // misc utility functions +function idInArray(id, arr) { + // because sometimes ids are strings and sometimes they're integers + for (index in arr) { + if (id.toString() == arr[index].toString()) { + return true; + } + } + return false; +} + function assert(outcome, description) { if (!outcome) { console.log(description); @@ -14,6 +24,17 @@ function firstCharUpper(s) { return s.charAt(0).toUpperCase() + s.slice(1); } +function toTitleCase(str) +{ + return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); +} + +function fieldNameToHumanReadable(str) +{ + str = str.replace("_", " "); + return toTitleCase(str); +} + // http://stackoverflow.com/questions/2117320/set-maximum-displayed-rows-count-for-html-table function limitTableRows(tableSelector, maxRows) { var table = $(tableSelector)[0] //document.getElementById(tableId); @@ -58,3 +79,54 @@ function validateField(validatorName, value, obj) { return true; } + +function array_diff(a1, a2) +{ + var a=[], diff=[]; + for(var i=0;i= 0) { + result.push(value); + } + } + return result; +} + +function array_pair_lookup(x, names, values) +{ + for (index in values) { + if (values[index] == x) { + return names[index]; + } + } + return "object #" + x; +} + +function all_options(selector) { + el = $(selector); + result = []; + _.each(el.find("option"), function(option) { + result.push($(option).val()); + }); + return result; +} + +function make_same_width(containerSelector, itemSelector) { + var maxWidth = 0; + $(containerSelector).find(itemSelector).each( function(index) { maxWidth = Math.max(maxWidth, $(this).width()); }); + console.log(maxWidth); + $(containerSelector).find(itemSelector).each( function(index) { $(this).width(maxWidth); }); +}