refactor sliceplus core for users, return user ids and names in sliceplus object
[plstackapi.git] / planetstack / core / xoslib / static / js / xoslib / xos-util.js
index 3fd597b..7a57d8a 100644 (file)
@@ -79,3 +79,42 @@ function validateField(validatorName, value, obj) {
 
     return true;
 }
+
+function array_diff(a1, a2)
+{\r
+  var a=[], diff=[];\r
+  for(var i=0;i<a1.length;i++)\r
+    a[a1[i]]=true;\r
+  for(var i=0;i<a2.length;i++)\r
+    if(a[a2[i]]) delete a[a2[i]];\r
+    else a[a2[i]]=true;\r
+  for(var k in a)\r
+    diff.push(k);\r
+  return diff;\r
+}
+
+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()); });\r
+    console.log(maxWidth);\r
+    $(containerSelector).find(itemSelector).each( function(index) { $(this).width(maxWidth); });
+}