﻿<?xml version="1.0" encoding="UTF-8" ?>
<Module>
    <ModulePrefs title="Recent WorkoutDump.com Activity" height="250" >
        <Require feature="dynamic-height"/>
    </ModulePrefs>
    
  <UserPref name="user_name" display_name="User Name" />
    <UserPref name="show_date" display_name="Show Dates?" default_value="true" datatype="bool"/>
    <UserPref name="show_summ" display_name="Show Summaries?" default_value="true" datatype="bool"/>
    <UserPref name="num_entries" display_name="Number of Entries:"  default_value="5" />
    <Content type="html">
    <![CDATA[
      <div id="wd_container"></div>  
      <script type="text/javascript">
       
       var wd = {
          prefs : {},
          config : 
          {
            //__UP_user_name__'s 
              urlBase : "http://www.workoutdump.com/callbacks/api.ashx",
              urlAll : "http://www.workoutdump.com/rssfeed.ashx"
          },
          
          get_prefs: function()
          {
              return new _IG_Prefs();
          },
          
          createContent : function(feed, numToShow)
          {
            var container = _gel("wd_container");
          
            if (feed == null)
            { 
                 container.appendChild(document.createTextNode("No Data Found"));
                 return;
            }
            
            

            // Start building HTML string that will be displayed in gadget.
            var html = "";

            // Access the fields in the feed
            //html += "<div><b>" + feed.Title + "</b></div>";
            //html += "<div>" + feed.Description + "</div><br>";

            // Access the data for a given entry
            if (feed.Entry) 
            {
                            //"<a target='_blank' border='0' class='image' href='" + feed.Entry[i].Link + "'>"
                            //+ "<img src='"+ feed.Entry[i].Author +"' height='32' width='32' border='0' />"
                            //+ "</a>"
                
                
                for (var i = 0; i < feed.Entry.length; i++)
                {
                    html += "<div class='act'>";
                    
                    html += "<a target='_blank' border='0' class='title' href='" + feed.Entry[i].Link + "'>"
                            + feed.Entry[i].Title
                            
                        
                    if(prefs.getBool("show_summ"))
                    {
                        html += "<p>" + feed.Entry[i].Summary + "</p>";
                    }                         
                        
                    html += "</a> ";

                    if(prefs.getBool("show_date"))
                    {

                        html += "<a class='date'>";
                        var milliseconds = (feed.Entry[i].Date) * 1000; 
                        var date = new Date(milliseconds); 
                        html += date.toLocaleDateString();
                        html += " ";
                        html += date.toLocaleTimeString(); 
                        html += "</a>";
                    }
                    
                    html += "</div>";
                    
                }
                
            }

              
              /*
              var ul = document.createElement("ul");

              for (var i = 0; i < activities.length ; i++) {
                var li = document.createElement("li");
                var unameTxt = prefs.getString("myname");
                var text = document.createTextNode(unameTxt);
                
                li.appendChild(text);
                ul.appendChild(li);
              }
              container.appendChild(ul);
              */
              
              container.innerHTML = html;
                _IG_AdjustIFrameHeight();
          
          },
              
            init: function() 
            {
                //document.write('<style type=text/css>@import url(' +  _IG_GetCachedUrl('http://www.workoutdump.com/app_themes/blue/googlegadget.css') +');</style>');
                document.write('<style type=text/css>@import url(http://www.workoutdump.com/app_themes/blue/googlegadget.css);</style>');
                prefs = this.get_prefs();
                var showdate = prefs.getBool("show_date");
                var summary = prefs.getBool("show_summ");
                var entries = prefs.getInt("num_entries");

                if (entries > 100)
                {
                    alert("You cannot display more than 100 entries.");
                    entries = 100;
                }

                _IG_FetchFeedAsJSON(
                    this.config.urlAll,
                    _IG_Callback(this.createContent),
                    entries,
                    summary
                );
            }
        }; 
       
      //gadgets.util.registerOnLoadHandler(wd.init); 
      wd.init();
       
      </script>
    ]]>
  </Content>
</Module>
