Skip to content
Browse files

Updated the service type and operations select box.

  • Loading branch information...
1 parent a5e4706 commit ba16b2e655476c3e5cccfa57bd0b5df5d8a2f9ed @jeffyu jeffyu committed Feb 26, 2013
View
1 gadget-web/src/main/java/org/overlord/gadgets/web/client/widgets/Portlet.java
@@ -228,6 +228,7 @@ private Widget createSelectBox(String name, String defaultVal, List<String> opti
private Widget createPrefSettingButtons() {
HorizontalPanel btnPanel = new HorizontalPanel();
Button saveBtn = new Button("Save");
+ saveBtn.getElement().setId("pref-save");
Button cancelBtn = new Button("Cancel");
btnPanel.add(saveBtn);
saveBtn.addClickHandler(new ClickHandler(){
View
3 gadget-web/src/main/webapp/application.js
@@ -1,9 +1,10 @@
+var container;
$(function(){
var containerConfig = {};
containerConfig[osapi.container.ServiceConfig.API_PATH] = "/rpc";
containerConfig[osapi.container.ContainerConfig.RENDER_DEBUG] = "1";
- var container = new osapi.container.Container(containerConfig);
+ container = new osapi.container.Container(containerConfig);
container.rpcRegister('resize_iframe', resizeIframe);
container.rpcRegister('set_pref', setPref);
});
View
40 gadgets/src/main/webapp/rt-gadget/g.html
@@ -0,0 +1,40 @@
+<html>
+ <head>
+ <script type="text/javascript" src="jquery-1.7.2.min.js"></script>
+ </head>
+ <body>
+ test
+ <select name="services" id="services">
+ <option value="1">Service Type1</option>
+ </select>
+
+ <select name="operations" id="operations">
+ <option value="2">Operation Type1 </option>
+ </select>
+ <script type="text/javascript">
+ function getDateTime(theDate) {
+ return theDate.getFullYear() + "-" + (theDate.getMonth() +1) + "-" + theDate.getDate() + " " + theDate.getHours()
+ + ":" + theDate.getMinutes() + ":" + theDate.getSeconds();
+ }
+
+ function receiveOnChange(data){
+ window.alert(data[0].serviceType);
+ }
+
+ function run() {
+ var data = [{"serviceType": "service type 1", "operations":"this is the operation 1"}, {"serviceType":"service type 2", "operations": "This is the operation 2"}];
+
+ var thesvc = $("#services");
+ thesvc.empty();
+ $.each(data, function(key, value){
+ thesvc.append($("<option></option>").attr("value", data[key].serviceType).text(data[key].serviceType));
+ });
+ thesvc.on('change', function(){
+ receiveOnChange(data);
+ });
+ }
+
+ run();
+ </script>
+ </body>
+</html>
View
80 gadgets/src/main/webapp/rt-gadget/gadget.xml
@@ -4,6 +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="refreshCycle" display_name="Refresh Interval(sec):" default_value="30" datatype="enum">
<EnumValue value="30" />
<EnumValue value="60" />
@@ -31,13 +33,26 @@
<script type="text/javascript">
- var serviceDefs;
-
function makeJSONRequest() {
- var prefs, params, restUrl, postdata, svcDef, host;
+ var prefs, params, restUrl, postdata, svcDef, host, service, operation;
prefs = new gadgets.Prefs();
- postdata = "{\"collection\":\"ServiceResponseTimes\"}";
+ service = prefs.getString("services");
+ operation = prefs.getString("operations");
+
+ if (!isNotEmpty(service) && !isNotEmpty(operation)) {
+ postdata = "{\"collection\":\"ServiceResponseTimes\"}";
+ } else {
+ postdata = "{\"parent\":\"ServiceResponseTimes\", \"collection\":\"CustomCollection\",\"predicate\":{\"type\":\"MVEL\",\"expression\":";
+ if (isNotEmpty(service) && isNotEmpty(operation)) {
+ postdata = postdata + "\"serviceType==\\\"" + service + "\\\" && operation == \\\"" + operation + "\\\"\"";
+ } else if (isNotEmpty(service)) {
+ postdata = postdata + "\"serviceType==\\\"" + service + "\\\"\"";
+ } else if (isNotEmpty(operation)) {
+ postdata = postdata + "\"operation == \\\"" + operation + "\\\"\"";
+ }
+ postdata = postdata + "} }";
+ }
params = {};
params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;
@@ -56,27 +71,58 @@
gadgets.io.makeRequest(restUrl, updateServiceDefinition, params);
}
+ function isNotEmpty(value) {
+ if (value != undefined && value != " " && value!= "" && value != "all" );
+ }
+
function getDateTime(theDate) {
return theDate.getFullYear() + "-" + (theDate.getMonth() +1) + "-" + theDate.getDate() + " " + theDate.getHours()
+ ":" + theDate.getMinutes() + ":" + theDate.getSeconds();
}
function updateServiceDefinition(response) {
- if (response.data == undefined) {
- return;
+ var i, theobj, serviceDefs, prefs;
+
+ var thesvc = parent.$("#services");
+ thesvc.empty();
+ thesvc.append($("<option></option>").attr("value","all").text("all"));
+ if (response.data != undefined){
+ serviceDefs = new Array(response.data.length);
+ for (i = 0; i < serviceDefs.length; i++) {
+ theobj = new Object();
+ theobj.serviceType = response.data[i].value.serviceType;
+ theobj.operations = response.data[i].value.operations;
+ serviceDefs[i] = theobj;
+ }
+ $.each(serviceDefs, function(index, value){
+ thesvc.append($("<option></option>").attr("value",serviceDefs[index].serviceType).text(serviceDefs[index].serviceType));
+ });
}
- serviceDefs = response.data;
- var st = new Array(serviceDefs.length);
- var i = 0;
- for (i =0; i < st.length; i++) {
- st[i] = serviceDefs[i].value.serviceType;
+
+ refreshOperationsOptions(serviceDefs);
+ thesvc.on('change', function(){
+ refreshOperationsOptions(serviceDefs);
+ });
+
+ }
+
+ function refreshOperationsOptions(serviceDefs) {
+ var opdata, i, selectedValue;
+ var theop = parent.$("#operations");
+ selectedValue = parent.$("#services").val();
+ theop.empty();
+ theop.append($("<option></option>").attr("value","all").text("all"));
+ if (selectedValue != " " && serviceDefs != undefined) {
+ for (i = 0; i < serviceDefs.length; i++) {
+ if (selectedValue == serviceDefs[i].serviceType) {
+ opdata = serviceDefs[i].operations;
+ $.each(opdata, function(index,value){
+ theop.append($("<option></option>").attr("value",opdata[index].name).text(opdata[index].name));
+ });
+ }
+ }
}
- var prefs = new gadgets.Prefs();
- var testData = new Array(2);
- testData[0] = "test1";
- testData[1] = "test2";
- prefs.setArray("serviceType", testData);
- prefs.setArray("operations", testData);
+
}
function updateUI(response) {

0 comments on commit ba16b2e

Please sign in to comment.
Something went wrong with that request. Please try again.