X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetstack%2Fcore%2Fxoslib%2Fstatic%2Fjs%2Fxoslib%2Fxos-util.js;h=1c42e26c5287e9814f71a74ce912d54363b776ea;hb=c2d7c700233884cf21df441192598df8347994ea;hp=638ba9aba52cb66d97c038096e887ed42c940946;hpb=eec2cbc90cc33171609a951fdbe4a67d515e1fb6;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 638ba9a..1c42e26 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); @@ -69,3 +79,60 @@ 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_same_elements(arr1, arr2) +{ + // return true if arrays have same elements, even if order is different + return ($(arr1).not(arr2).length == 0 && $(arr2).not(arr1).length == 0); +} + +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); }); +}