Permalink
Browse files

GADGETS-46: show the saved service and operations.

  • Loading branch information...
1 parent 9aad9f7 commit d5717405ca3a362ebac429ea5b10c414f262beb9 @jeffyu jeffyu committed Mar 18, 2013
Showing with 59 additions and 11 deletions.
  1. +21 −1 gadgets/src/main/webapp/rt-gadget/g.html
  2. +38 −10 gadgets/src/main/webapp/rt-gadget/gadget.xml
@@ -18,7 +18,7 @@
}
function receiveOnChange(data){
- window.alert(data[0].serviceType);
+ window.alert($("#services").val());
}
function run() {
@@ -33,8 +33,28 @@
receiveOnChange(data);
});
}
+
+ function containsValue(selectId, selectValue) {
+ var exists = false;
+ $("#" + selectId + " option").each(function(){
+ if (this.value == selectValue) {
+ exists = true;
+ }
+ });
+ return exists;
+ }
+
+ function setDefaultValue(selectId, selectValue) {
+ if (!containsValue(selectId, selectValue)) {
+ $("#" + selectId).append($("<option></option>").attr("value", selectValue).text(selectValue));
+ }
+ $("#" + selectId).val(selectValue);
+ }
run();
+
+ setDefaultValue("services", "service type");
+
</script>
</body>
</html>
@@ -4,8 +4,8 @@
author="Jeff Yu" author_email="jeff.yuchang@gmail.com">
<Require feature="setprefs" />
</ModulePrefs>
- <UserPref name="services" display_name="Service Types:" datatype="list"></UserPref>
- <UserPref name="operations" display_name="Operations:" datatype="list"></UserPref>
+ <UserPref name="services" display_name="Service Types:" default_value="all" datatype="list"></UserPref>
+ <UserPref name="operations" display_name="Operations:" default_value="all" datatype="list"></UserPref>
<UserPref name="refreshCycle" display_name="Refresh Interval(sec):" default_value="30" datatype="enum">
<EnumValue value="30" />
<EnumValue value="60" />
@@ -83,9 +83,11 @@
}
function updateServiceDefinition(response) {
- var i, theobj, serviceDefs, prefs;
-
+ var i, theobj, serviceDefs, exists;
+ var thesvcValue = getUserPreferenceValue("services");
+ var theopValue = getUserPreferenceValue("operations");
var thesvc = parent.$("#services");
+ exists = false;
thesvc.empty();
thesvc.append($("<option></option>").attr("value","all").text("all"));
if (response.data != undefined){
@@ -95,21 +97,37 @@
theobj.serviceType = response.data[i].value.serviceType;
theobj.operations = response.data[i].value.operations;
serviceDefs[i] = theobj;
+ if (thesvcValue == theobj.serviceType) {
+ exists = true;
+ }
}
$.each(serviceDefs, function(index, value){
thesvc.append($("<option></option>").attr("value",serviceDefs[index].serviceType).text(serviceDefs[index].serviceType));
});
+
+ if (thesvcValue != "all" && !exists) {
+ thesvc.append($("<option></option>").attr("value",thesvcValue).text(thesvcValue));
+ }
+ thesvc.val(thesvcValue);
+
+ refreshOperationsOptions(serviceDefs, theopValue);
+
+ thesvc.on('change', function(){
+ refreshOperationsOptions(serviceDefs);
+ });
+
}
- refreshOperationsOptions(serviceDefs);
- thesvc.on('change', function(){
- refreshOperationsOptions(serviceDefs);
- });
+
}
- function refreshOperationsOptions(serviceDefs) {
- var opdata, i, selectedValue, theop;
+ function refreshOperationsOptions(serviceDefs, defaultValue) {
+ var opdata, i, selectedValue, theop, exists;
+ var thesvcValue = getUserPreferenceValue("services");
+ var theopValue = getUserPreferenceValue("operations");
+
+ exists = false;
selectedValue = parent.$("#services").val();
theop = parent.$("#operations");
@@ -122,10 +140,20 @@
if (selectedValue == serviceDefs[i].serviceType) {
opdata = serviceDefs[i].operations;
$.each(opdata, function(index,value){
+ if (opdata[index].name == theopValue) {
+ exists = true;
+ }
theop.append($("<option></option>").attr("value",opdata[index].name).text(opdata[index].name));
});
}
}
+
+ if (selectedValue == thesvcValue && theopValue != "all" && !exists) {
+ theop.append($("<option></option>").attr("value",theopValue).text(theopValue));
+ }
+ if (defaultValue != "undefined" && defaultValue != undefined) {
+ theop.val(defaultValue);
+ }
}
}

0 comments on commit d571740

Please sign in to comment.