blob: 3dbafbe47795fb02b0a33b18245d5dab1015c04a [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<Module>
<ModulePrefs title="User Prefs Demo"
description="An example gadget which demos some of the different capabilities of user preferences."
author="Anthony Carlucci"
author_email="acarlucci@mitre.org">
<Require feature="dynamic-height" />
<Require feature="setprefs" />
</ModulePrefs>
<UserPref name="age"
display_name="Age"
default_value="0"
datatype="string"/>
<UserPref name="full_name"
display_name="Full Name"
required="true"
datatype="string"/>
<UserPref name="bool_test"
display_name="Boolean Type"
datatype="bool"/>
<UserPref name="hidden_test"
display_name="Hidden Value"
default_value="secret value"
datatype="hidden"/>
<UserPref name="color"
display_name="Color (Enum)"
default_value="yellow"
datatype="enum">
<EnumValue value="red" display_value="Red (first)" />
<EnumValue value="aqua" display_value="Aqua (second)" />
<EnumValue value="lime" display_value="Lime (third)" />
<EnumValue value="yellow" display_value="Yellow (fourth)" />
<EnumValue value="pink" display_value="Pink (fifth)" />
<EnumValue value="orange" display_value="Orange (sixth)" />
<EnumValue value="white" display_value="White (seventh)" />
</UserPref>
<UserPref name="drinks"
display_name="Drinks (List Type With Defaults)"
datatype="list"
required="false"
default_value="coke|pepsi|fruit punch"/>
<UserPref name="movies"
display_name="Movies (Required List Type With Defaults)"
datatype="list"
required="true"
default_value="Terminator|Forrest Gump|Predator"/>
<UserPref name="openlist"
display_name="List Type No Defaults"
datatype="list"
required="false" />
<Content type="html">
<![CDATA[
<div style="padding-bottom: 10px;">Below is a list of User Prefs for this gadget. Click the Edit Prefs icon in the gadget titlebar to change the values.</div>
<div id="content_div"></div>
<div>
<div>Click the button below to demo saving user prefs inline. It will save the "Age" to 999 and the "Drinks" to "lemonade,tea".</div>
<button onClick="saveInlinePref();">Save Inline</button>
</div>
<script type="text/javascript">
function saveInlinePref() {
var prefs = new gadgets.Prefs();
prefs.set("age", "999");
prefs.setArray("drinks",["lemonade","tea"]);
renderContent();
}
function renderContent() {
var prefs = new gadgets.Prefs();
var age = prefs.getString("age");
var fullName = prefs.getString("full_name");
var boolType = prefs.getBool("bool_test");
var hiddenType = prefs.getString("hidden_test");
var enumType = prefs.getString("color");
var drinksArray = prefs.getArray("drinks");
var moviesArray = prefs.getArray("movies");
var openListArray = prefs.getArray("openlist");
var drinksHtml = "<ul>";
for (var i=0; i < drinksArray.length; i++) {
drinksHtml += "<li>" + drinksArray[i];
}
drinksHtml += "</ul>";
var moviesHtml = "<ul>";
for (var i=0; i < moviesArray.length; i++) {
moviesHtml += "<li>" + moviesArray[i];
}
moviesHtml += "</ul>";
var openListHtml = "<ul>";
for (var i=0; i < openListArray.length; i++) {
openListHtml += "<li>" + openListArray[i];
}
openListHtml += "</ul>";
var gadgetHtml = "<ul>" +
"<li>Your age is: " + age +
"<li>Your name is: " + fullName +
"<li>Bool Type: " + boolType +
"<li>Hidden Type: " + hiddenType +
"<li>Color (enum): " + enumType +
"<li>Drinks (List w/defaults): " + drinksHtml +
"<li>Movies (List w/defaults and required): " + moviesHtml +
"<li>Open List (List w/o defaults): " + openListHtml +
"</ul>";
document.getElementById('content_div').innerHTML = gadgetHtml;
gadgets.window.adjustHeight();
}
gadgets.util.registerOnLoadHandler(function() {
renderContent();
});
</script>
]]>
</Content>
</Module>