Author: scottbw
Date: Tue Aug  7 08:06:35 2012
New Revision: 1370136

URL: http://svn.apache.org/viewvc?rev=1370136&view=rev
Log:
Split the "Add New Widget" page into two tabs, with placeholder for adding 
marketplace tab. See RAVE-748.

Added:
    
rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/jsp/views/addwidget.w3c.jsp
Modified:
    
rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/web/util/PortalPreferenceKeys.java
    
rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/controller/WidgetStoreController.java
    
rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/util/ModelKeys.java
    
rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/util/ViewNames.java
    
rave/trunk/rave-components/rave-web/src/test/java/org/apache/rave/portal/web/controller/WidgetStoreControllerTest.java
    
rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/jsp/views/addwidget.jsp

Modified: 
rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/web/util/PortalPreferenceKeys.java
URL: 
http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/web/util/PortalPreferenceKeys.java?rev=1370136&r1=1370135&r2=1370136&view=diff
==============================================================================
--- 
rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/web/util/PortalPreferenceKeys.java
 (original)
+++ 
rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/web/util/PortalPreferenceKeys.java
 Tue Aug  7 08:06:35 2012
@@ -28,4 +28,5 @@ public final class PortalPreferenceKeys 
     public static final String PAGE_SIZE = "pageSize";
     public static final String JAVASCRIPT_DEBUG_MODE = "javaScriptDebugMode";
     public static final String INITIAL_WIDGET_STATUS = "initialWidgetStatus";
+    public static final String EXTERNAL_MARKETPLACE_URL = 
"externalMarketplaceUrl";
 }

Modified: 
rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/controller/WidgetStoreController.java
URL: 
http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/controller/WidgetStoreController.java?rev=1370136&r1=1370135&r2=1370136&view=diff
==============================================================================
--- 
rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/controller/WidgetStoreController.java
 (original)
+++ 
rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/controller/WidgetStoreController.java
 Tue Aug  7 08:06:35 2012
@@ -197,11 +197,41 @@ public class WidgetStoreController {
     public String viewAddWidgetForm(Model model, @RequestParam long 
referringPageId) {
         final Widget widget = new WidgetImpl();
         final String view = ViewNames.ADD_WIDGET_FORM;
+        model.addAttribute(ModelKeys.MARKETPLACE, 
this.preferenceService.getPreference(PortalPreferenceKeys.EXTERNAL_MARKETPLACE_URL));
         model.addAttribute(ModelKeys.WIDGET, widget);
         model.addAttribute(ModelKeys.REFERRING_PAGE_ID, referringPageId);
         ControllerUtils.addNavItemsToModel(view, model, referringPageId, 
userService.getAuthenticatedUser());
         return view;
     }
+    
+    /**
+     * Shows the Add new Widget form
+     *
+     * @param model
+     *            {@link Model}
+     * @param referringPageId
+     *            the source {@link org.apache.rave.portal.model.Page } ID
+     * @param type
+     *            the type of widget add form to display, e.g. W3C or 
OpenSocial (default)
+     * @return the view name of the Add new Widget form
+     */
+    @RequestMapping(method = RequestMethod.GET, value = "widget/add/{type}")
+    public String viewAddWidgetFormByType(Model model, @RequestParam long 
referringPageId, @PathVariable String type) {
+        final Widget widget = new WidgetImpl();
+        String view;
+        if (type != null && type.equalsIgnoreCase("w3c")){
+               view = ViewNames.ADD_WIDGET_W3C;
+        } else {
+               view = ViewNames.ADD_WIDGET_FORM;
+        }
+        model.addAttribute(ModelKeys.MARKETPLACE, 
this.preferenceService.getPreference(PortalPreferenceKeys.EXTERNAL_MARKETPLACE_URL));
+        model.addAttribute(ModelKeys.WIDGET, widget);
+        model.addAttribute(ModelKeys.REFERRING_PAGE_ID, referringPageId);
+        ControllerUtils.addNavItemsToModel(view, model, referringPageId, 
userService.getAuthenticatedUser());
+        return view;
+    }
+    
+    
 
     /**
      * Validates the form input, if valid, tries to store the Widget data
@@ -222,13 +252,55 @@ public class WidgetStoreController {
         User user = userService.getAuthenticatedUser();
         widgetValidator.validate(widget, results);
         if (results.hasErrors()) {
-            final String view = ViewNames.ADD_WIDGET_FORM;
+               final String view = ViewNames.ADD_WIDGET_FORM;
+            model.addAttribute(ModelKeys.WIDGET, widget);
+            model.addAttribute(ModelKeys.REFERRING_PAGE_ID, referringPageId);
+            ControllerUtils.addNavItemsToModel(view, model, referringPageId, 
user);
+            return view;
+        }
+        return finalizeNewWidget(widget,user, referringPageId);
+    }
+    
+    /**
+     * Validates the form input, if valid, tries to store the Widget data
+     *
+     * @param widget
+     *            {@link org.apache.rave.portal.model.Widget} as submitted by 
the user
+     * @param results
+     *            {@link BindingResult}
+     * @param model
+     *            {@link Model}
+     * @param referringPageId
+     *            the source {@link org.apache.rave.portal.model.Page } ID
+     * @return if successful the view name of the widget, otherwise the form
+     */
+    @RequestMapping(method = RequestMethod.POST, value = "widget/add/w3c")
+    public String viewAddWidgetResultW3c(@ModelAttribute WidgetImpl widget, 
BindingResult results, Model model,
+            @RequestParam long referringPageId) {
+        User user = userService.getAuthenticatedUser();
+        widgetValidator.validate(widget, results);
+        if (results.hasErrors()) {
+               final String view = ViewNames.ADD_WIDGET_W3C;
             model.addAttribute(ModelKeys.WIDGET, widget);
             model.addAttribute(ModelKeys.REFERRING_PAGE_ID, referringPageId);
             ControllerUtils.addNavItemsToModel(view, model, referringPageId, 
user);
             return view;
         }
         
+        return finalizeNewWidget(widget,user, referringPageId);
+    }
+    
+    /**
+     * Finalize adding a new widget created from validated form data, and 
redirect to its store detail page
+     * @param widget
+     *            {@link org.apache.rave.portal.model.Widget} as created from 
form input
+     * @param user
+     *            the user submitting the new widget
+     * @param referringPageId
+     *            the source page ID
+     * @return a redirection string for the store detail page.
+     */
+    private String finalizeNewWidget(WidgetImpl widget, User user, long 
referringPageId){
         /*
          * By default, a new widget has a status of "PREVIEW", however this 
can be overridden in portal preferences,
          * skipping the need for an admin to approve a new widget.

Modified: 
rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/util/ModelKeys.java
URL: 
http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/util/ModelKeys.java?rev=1370136&r1=1370135&r2=1370136&view=diff
==============================================================================
--- 
rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/util/ModelKeys.java
 (original)
+++ 
rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/util/ModelKeys.java
 Tue Aug  7 08:06:35 2012
@@ -33,7 +33,8 @@ public class ModelKeys {
     public static final String ERROR_MESSAGE = "errorMessage"; // an error 
message to be reported to the user
     public static final String WIDGETS = "widgets"; // a list of widget objects
     public static final String WIDGET = "widget";
-    public static final String REGION_WIDGET = "regionWidget";    
+    public static final String REGION_WIDGET = "regionWidget"; 
+    public static final String MARKETPLACE = "marketplace"; // whether there 
is an external widget marketplace configured
     public static final String WIDGET_STATISTICS = "widgetStatistics"; 
//statistics for a single widget
     public static final String WIDGETS_STATISTICS = "widgetsStatistics"; 
//list of statistics for a list of widgets
     public static final String CATEGORY = "category"; //category

Modified: 
rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/util/ViewNames.java
URL: 
http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/util/ViewNames.java?rev=1370136&r1=1370135&r2=1370136&view=diff
==============================================================================
--- 
rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/util/ViewNames.java
 (original)
+++ 
rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/util/ViewNames.java
 Tue Aug  7 08:06:35 2012
@@ -37,6 +37,8 @@ public final class ViewNames {
     public static final String NEW_ACCOUNT = USER_PREFIX + "newaccount";
     public static final String USER_PROFILE = USER_PREFIX + "userProfile";
     public static final String PERSON_PROFILE = USER_PREFIX + "personProfile";
+    public static final String ADD_WIDGET_MARKETPLACE = ADD_WIDGET_FORM + 
".marketplace";
+    public static final String ADD_WIDGET_W3C = ADD_WIDGET_FORM + ".w3c";
 
     public static final String ADMIN_HOME = ADMIN_PREFIX + "home";
     public static final String ADMIN_NEW_ACCOUNT = ADMIN_PREFIX + "newaccount";

Modified: 
rave/trunk/rave-components/rave-web/src/test/java/org/apache/rave/portal/web/controller/WidgetStoreControllerTest.java
URL: 
http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-web/src/test/java/org/apache/rave/portal/web/controller/WidgetStoreControllerTest.java?rev=1370136&r1=1370135&r2=1370136&view=diff
==============================================================================
--- 
rave/trunk/rave-components/rave-web/src/test/java/org/apache/rave/portal/web/controller/WidgetStoreControllerTest.java
 (original)
+++ 
rave/trunk/rave-components/rave-web/src/test/java/org/apache/rave/portal/web/controller/WidgetStoreControllerTest.java
 Tue Aug  7 08:06:35 2012
@@ -85,6 +85,7 @@ public class WidgetStoreControllerTest {
         PortalPreferenceService preferenceService = 
createMock(PortalPreferenceService.class);
         
expect(preferenceService.getPreference(PortalPreferenceKeys.INITIAL_WIDGET_STATUS)).andReturn(null);
         
expect(preferenceService.getPreference(PortalPreferenceKeys.PAGE_SIZE)).andReturn(null);
+        
expect(preferenceService.getPreference(PortalPreferenceKeys.EXTERNAL_MARKETPLACE_URL)).andReturn(null);
         replay(preferenceService);
 
         NewWidgetValidator widgetValidator = new 
NewWidgetValidator(widgetService);

Modified: 
rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/jsp/views/addwidget.jsp
URL: 
http://svn.apache.org/viewvc/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/jsp/views/addwidget.jsp?rev=1370136&r1=1370135&r2=1370136&view=diff
==============================================================================
--- 
rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/jsp/views/addwidget.jsp
 (original)
+++ 
rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/jsp/views/addwidget.jsp
 Tue Aug  7 08:06:35 2012
@@ -22,8 +22,17 @@
 <fmt:message key="page.addwidget.title" var="pagetitle"/>
 <rave:navbar pageTitle="${pagetitle}"/>
 
-<div class="container">
-    <h2><fmt:message key="page.addwidget.form.header"/></h2>
+<div class="container-fluid navbar-spacer">
+    <div class="row-fluid">
+    <ul class="nav nav-tabs">
+          <li class="active"><a href="<spring:url 
value="/app/store/widget/add?referringPageId=${referringPageId}" 
/>">OpenSocial</a></li>
+          <li><a href="<spring:url 
value="/app/store/widget/add/w3c?referringPageId=${referringPageId}" 
/>">W3C</a></li>
+          
+          <c:if test="${not empty marketplace}">
+          <li><a href="<spring:url 
value="/app/marketplace?referringPageId=${referringPageId}" 
/>">Marketplace</a></li>
+          </c:if>
+    </ul> 
+    
     <form:errors path="widget" cssClass="error" element="p"/>
     <form:form cssClass="form-horizontal" id="newWidgetForm" 
action="add?referringPageId=${referringPageId}" commandName="widget" 
method="POST">
         <fieldset>
@@ -38,28 +47,14 @@
                 </spring:bind>
                 <form:errors path="url" cssClass="error"/>
             </div>
-
-            <div class="control-group">
-                <label class="control-label" for="type1"><fmt:message 
key="widget.type"/> *</label>
-            </div>
-            <div class="control-group">
-                <label class="control-label" for="type1"><fmt:message 
key="widget.type.OpenSocial"/></label>
-                <div class="controls"><form:radiobutton path="type" 
value="OpenSocial"/></div>
-            </div>
-            <div class="control-group">
-                <label class="control-label" for="type2"><fmt:message 
key="widget.type.W3C"/></label>
-
-                <div class="controls"><form:radiobutton path="type" 
value="W3C"/>
-                    <a id="w3cBrowseLink" style="margin-left: 10px;" 
href="#"><fmt:message key="page.general.browse"/></a>
-                </div>
-                <form:errors path="type" cssClass="error"/>
-            </div>
+            
+            <form:hidden path="type" value="OpenSocial"/>
 
             <a href="#" class="btn btn-primary"
                id="fetchMetadataButton"
                onclick="rave.api.rpc.getWidgetMetadata({
                                 url: $('#url').get(0).value,
-                                providerType: 
$('input:radio[name=type]:checked').val(),
+                                providerType: 'OpenSocial',
                                 successCallback: function(result) {
                                     var widget = result.result;
                                     $('#title').val(widget.title);
@@ -71,12 +66,6 @@
                                     $('#authorEmail').val(widget.authorEmail);
                                     $('#addWidgetForm').show();
                                     $('#addWidgetFormSubmit').show();
-                                    // update this field so we can pass 
widgets by key
-                                    // (soon to be superseeded in wookie by 
using the guid instead)
-                                    // remove when using 0.10.0 of wookie
-                                    
if($('input[name=type]:checked').val()=='W3C'){
-                                        $('#url').val(widget.url);
-                                    }
                                 }
                             });">
                 <fmt:message key="page.getWidgetMetadata.button"/>
@@ -84,7 +73,6 @@
 
             <div class="row clearfix" id="addWidgetForm">
 
-
                 <div class="control-group">
                     <form:label cssClass="control-label" path="title"> 
<fmt:message key="widget.title"/> *</form:label>
                     <div class="controls">
@@ -152,10 +140,6 @@
         </div>
     </form:form>
 </div>
-<div id="w3cBrowseForm" title="<fmt:message key="page.general.browse"/>">
-    <ul id="w3cwidgetsList" class="storeItems">
-    </ul>
-</div>
 
 <portal:register-init-script location="${'AFTER_RAVE'}">
 <script>
@@ -163,154 +147,9 @@
         if ($('#url').val().length === 0) {
             $('#addWidgetForm').hide();
             $('#addWidgetFormSubmit').hide();
-            $('input[name=type]:first').attr('checked', true);
-        }
-        if ($('input[name=type]:checked').val() != 'W3C') {
-            $('#w3cBrowseLink').hide();
         }
-        $('input[name=type]').change(function(){
-            if($('input[name=type]:checked').val()=='W3C'){
-                $('#w3cBrowseLink').show();
-            }
-            else{
-                $('#w3cBrowseLink').hide();
-            }
-        });
-
-        $("#w3cBrowseForm").dialog({
-            autoOpen: false,
-            height: 300,
-            width: 350,
-            modal: true,
-            buttons: {
-                Cancel: function(){
-                    $(this).dialog("close");
-                }
-            },
-            close: function(){
-                // clear contents
-                $('#w3cwidgetsList').empty();
-            }
-        });
-
-        $("#w3cBrowseLink").click(function() {
-            rave.api.rpc.getWidgetMetadataGroup({
-                url: "?all=true",
-                providerType: "W3C",
-                successCallback: function(result) {
-                var i=0;
-                var widgets = result.result;
-                PostLoadW3cWidgets.setList(widgets);
-                jQuery.each(widgets, function() {
-                    $('#w3cwidgetsList')
-                        .append(
-                            $("<li/>")
-                            .addClass("storeItem")
-                            .append( // container
-                                $("<div/>")
-                                .css('overflow','hidden')
-                                .append(
-                                    $("<div/>")
-                                    .css('float','left')
-                                    .css('width','50%')
-                                    .append(
-                                        $("<div/>")
-                                        .attr("id", "w3cImageHolder"+i)
-                                    )
-                                    .append(
-                                        $("<div/>")
-                                        .attr("id", "widgetAdded")
-                                        .addClass("storeButton")
-                                        .append(
-                                            $("<button/>")
-                                            .addClass("btn btn-small 
btn-primary")
-                                            .attr("id", this.url)
-                                            .attr("onclick", 
"updateRaveMetadata("+i+");")
-                                            
.text(rave.getClientMessage("get.metadata"))
-                                        )
-                                    )
-                                )
-                                .append(
-                                    $("<div/>")
-                                    .css('float','left')
-                                    .css('width','50%')
-                                    .css('margin-right','-1px')
-                                    .append(
-                                        $("<div/>")
-                                        .addClass("secondaryPageItemTitle")
-                                        .css('padding', '2px')
-                                        .text(this.title)
-                                    )
-                                    .append(
-                                        $("<div/>")
-                                        .addClass("storeWidgetAuthor")
-                                        .css('padding', '2px')
-                                        .text(this.author)
-                                    )
-                                    .append(
-                                        $("<div/>")
-                                        .addClass("storeWidgetDesc")
-                                        .css('padding', '2px')
-                                        .text(this.description)
-                                    )
-                                )
-                                .append(
-                                    $("<div/>")
-                                    .addClass("clear-float")
-                                )
-                            )
-                        )
-                        // add the thumbnail image if found
-                        if(this.thumbnailUrl!=null){
-                            $('#w3cImageHolder'+i)
-                            .append(
-                                $("<img/>")
-                                .addClass("storeWidgetThumbnail")
-                                .attr("src", this.thumbnailUrl)
-                                .attr("title", this.title)
-                                .attr("alt", "")
-                                .attr("width", "80")
-                                .attr("height", "80")
-                            )
-                        }
-                    i++;
-                    });
-                    $("#w3cBrowseForm").dialog("open");
-                }
-            })
-        });
-    });
 
-   // use this object to hold the choices of w3c widgets after the page has 
loaded.
-    var PostLoadW3cWidgets = new function PostLoadW3cWidgets() {
-        this.list = null;
-        this.setList = function (list) {
-            this.list = list;
-        }
-        this.getList = function () {
-            return this.list;
-        }
-        this.getListItemByIndex = function(idx){
-            return this.list[idx];
-        }
-    }
-
-    function updateRaveMetadata(id){
-        if(id != null){
-            widget = PostLoadW3cWidgets.getListItemByIndex(id);
-            $('#title').val(widget.title);
-            $('#description').val(widget.description);
-            $('#thumbnailUrl').val(widget.thumbnailUrl);
-            $('#screenshotUrl').val(widget.screenshotUrl);
-            $('#titleUrl').val(widget.titleUrl);
-            $('#author').val(widget.author);
-            $('#authorEmail').val(widget.authorEmail);
-            $('#url').val(widget.url);
-            $('#addWidgetForm').show();
-            $('#addWidgetFormSubmit').show();
-        }
-        $("#w3cBrowseForm").dialog("close");
-    }
+    });
 </script>
 </portal:register-init-script>
 

Added: 
rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/jsp/views/addwidget.w3c.jsp
URL: 
http://svn.apache.org/viewvc/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/jsp/views/addwidget.w3c.jsp?rev=1370136&view=auto
==============================================================================
--- 
rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/jsp/views/addwidget.w3c.jsp
 (added)
+++ 
rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/jsp/views/addwidget.w3c.jsp
 Tue Aug  7 08:06:35 2012
@@ -0,0 +1,279 @@
+<%--
+  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.
+  --%>
+<%@ page language="java" trimDirectiveWhitespaces="true" %>
+<%@ include file="/WEB-INF/jsp/includes/taglibs.jsp" %>
+<fmt:setBundle basename="messages"/>
+<fmt:message key="page.addwidget.title" var="pagetitle"/>
+<rave:navbar pageTitle="${pagetitle}"/>
+
+<div class="container-fluid navbar-spacer">
+    <div class="row-fluid">
+    <ul class="nav nav-tabs">
+          <li><a href="<spring:url 
value="/app/store/widget/add?referringPageId=${referringPageId}" 
/>">OpenSocial</a></li>
+          <li class="active"><a href="#w3c">W3C</a></li>
+          <c:if test="${not empty marketplace}">
+          <li><a href="<spring:url 
value="/app/marketplace?referringPageId=${referringPageId}" 
/>">Marketplace</a></li>
+          </c:if>
+    </ul> 
+    </div>
+    
+    <div class="row-fluid">
+    <a class="btn btn-primary" id="w3cBrowseLink" href="#"><fmt:message 
key="page.general.browse"/></a>
+    
+    <form:errors path="widget" cssClass="error" element="p"/>
+    <form:form cssClass="form-horizontal" id="newWidgetForm" 
action="w3c?referringPageId=${referringPageId}" commandName="widget" 
method="POST">
+        <fieldset>
+
+            <form:hidden path="type" value="W3C"/>
+
+            <div id="addWidgetForm">
+                <div class="control-group label label-important"><fmt:message 
key="form.some.fields.required"/></div>
+
+            
+                <div class="control-group">
+                    <spring:bind path="url">
+                    <label class="control-label" for="url"><fmt:message 
key="widget.url"/> *</label>
+                    <div class="controls"><input class="input-xlarge" 
type="url" name="url" id="url"
+                                                 
placeholder="http://example.com/widget.xml"; required="required"
+                                                 value="<c:out 
value="${widget.url}"/>"/></div>
+                    </spring:bind>
+                    <form:errors path="url" cssClass="error"/>
+                </div>
+
+                <div class="control-group">
+                    <form:label cssClass="control-label" path="title"> 
<fmt:message key="widget.title"/> *</form:label>
+                    <div class="controls">
+                        <form:input path="title" cssClass="input-xlarge" 
required="required" autofocus="autofocus"/></div>
+                    <form:errors path="title" cssClass="error"/>
+                </div>
+
+                <div class="control-group">
+                    <form:label cssClass="control-label" 
path="description"><fmt:message key="widget.description"/> *</form:label>
+                    <div class="controls"><form:textarea path="description" 
required="required" cssClass="input-xlarge"/></div>
+                    <form:errors path="description" cssClass="error"/>
+                </div>
+
+                <div class="control-group">
+                    <spring:bind path="thumbnailUrl">
+                        <label class="control-label" 
for="thumbnailUrl"><fmt:message key="widget.thumbnailUrl"/></label>
+                        <div class="controls"><input type="url" 
name="thumbnailUrl" id="thumbnailUrl"
+                                                     
placeholder="http://example.com/thumbnail.png"; class="input-xlarge"
+                                                     value="<c:out 
value="${widget.thumbnailUrl}"/>"/></div>
+                    </spring:bind>
+                    <form:errors path="thumbnailUrl" cssClass="error"/>
+                </div>
+
+                <div class="control-group">
+                    <spring:bind path="screenshotUrl">
+                        <label class="control-label" 
for="screenshotUrl"><fmt:message key="widget.screenshotUrl"/></label>
+                        <div class="controls">
+                            <input type="url" name="screenshotUrl" 
id="screenshotUrl" placeholder="http://example.com/screenshot.png"; 
class="input-xlarge"
+                                   value="<c:out 
value="${widget.screenshotUrl}"/>"/></div>
+                    </spring:bind>
+                    <form:errors path="screenshotUrl" cssClass="error"/>
+                </div>
+
+                <div class="control-group">
+                    <spring:bind path="titleUrl">
+                        <label class="control-label" 
for="titleUrl"><fmt:message key="widget.titleUrl"/></label>
+                        <div class="controls"><input type="url" 
name="titleUrl" id="titleUrl"
+                                                     class="input-xlarge" 
value="<c:out value="${widget.titleUrl}"/>"/></div>
+                    </spring:bind>
+                    <form:errors path="titleUrl" cssClass="error"/>
+                </div>
+
+                <div class="control-group">
+                    <form:label cssClass="control-label" 
path="author"><fmt:message key="widget.author"/></form:label>
+                    <div class="controls"><form:input path="author" 
cssClass="input-xlarge"/>
+                        <form:errors path="author" cssClass="error"/>
+                    </div>
+
+                </div>
+                <div class="control-group">
+                    <spring:bind path="authorEmail">
+                        <label class="control-label" 
for="authorEmail"><fmt:message key="widget.authorEmail"/></label>
+                        <div class="controls"><input type="email" 
name="authorEmail" id="authorEmail" class="input-xlarge"
+                                                     value="<c:out 
value="${widget.authorEmail}"/>"/></div>
+                    </spring:bind>
+                    <form:errors path="titleUrl" cssClass="error"/>
+                </div>
+            </div>
+        </fieldset>
+        <div id="addWidgetFormSubmit">
+            <fieldset>
+                <fmt:message key="page.addwidget.form.submit" var="submit"/>
+                <button class="btn btn-primary" type="submit" 
value="${submit}">${submit}</button>
+            </fieldset>
+        </div>
+    </form:form>
+    </div>
+</div>
+
+<div id="w3cBrowseForm" title="<fmt:message key="page.general.browse"/>">
+    <ul id="w3cwidgetsList" class="storeItems">
+    </ul>
+</div>
+
+<portal:register-init-script location="${'AFTER_RAVE'}">
+<script>
+    $(function() {
+        if ($('#url').val().length === 0) {
+            $('#addWidgetForm').hide();
+            $('#addWidgetFormSubmit').hide();
+        }
+
+        $('#w3cBrowseLink').show();
+
+        $("#w3cBrowseForm").dialog({
+            autoOpen: false,
+            height: 300,
+            width: 350,
+            modal: true,
+            buttons: {
+                Cancel: function(){
+                    $(this).dialog("close");
+                }
+            },
+            close: function(){
+                // clear contents
+                $('#w3cwidgetsList').empty();
+            }
+        });
+
+        $("#w3cBrowseLink").click(function() {
+            rave.api.rpc.getWidgetMetadataGroup({
+                url: "?all=true",
+                providerType: "W3C",
+                successCallback: function(result) {
+                var i=0;
+                var widgets = result.result;
+                PostLoadW3cWidgets.setList(widgets);
+                jQuery.each(widgets, function() {
+                    $('#w3cwidgetsList')
+                        .append(
+                            $("<li/>")
+                            .addClass("storeItem")
+                            .append( // container
+                                $("<div/>")
+                                .css('overflow','hidden')
+                                .append(
+                                    $("<div/>")
+                                    .css('float','left')
+                                    .css('width','50%')
+                                    .append(
+                                        $("<div/>")
+                                        .attr("id", "w3cImageHolder"+i)
+                                    )
+                                    .append(
+                                        $("<div/>")
+                                        .attr("id", "widgetAdded")
+                                        .addClass("storeButton")
+                                        .append(
+                                            $("<button/>")
+                                            .addClass("btn btn-small 
btn-primary")
+                                            .attr("id", this.url)
+                                            .attr("onclick", 
"updateRaveMetadata("+i+");")
+                                            
.text(rave.getClientMessage("get.metadata"))
+                                        )
+                                    )
+                                )
+                                .append(
+                                    $("<div/>")
+                                    .css('float','left')
+                                    .css('width','50%')
+                                    .css('margin-right','-1px')
+                                    .append(
+                                        $("<div/>")
+                                        .addClass("secondaryPageItemTitle")
+                                        .css('padding', '2px')
+                                        .text(this.title)
+                                    )
+                                    .append(
+                                        $("<div/>")
+                                        .addClass("storeWidgetAuthor")
+                                        .css('padding', '2px')
+                                        .text(this.author)
+                                    )
+                                    .append(
+                                        $("<div/>")
+                                        .addClass("storeWidgetDesc")
+                                        .css('padding', '2px')
+                                        .text(this.description)
+                                    )
+                                )
+                                .append(
+                                    $("<div/>")
+                                    .addClass("clear-float")
+                                )
+                            )
+                        )
+                        // add the thumbnail image if found
+                        if(this.thumbnailUrl!=null){
+                            $('#w3cImageHolder'+i)
+                            .append(
+                                $("<img/>")
+                                .addClass("storeWidgetThumbnail")
+                                .attr("src", this.thumbnailUrl)
+                                .attr("title", this.title)
+                                .attr("alt", "")
+                                .attr("width", "80")
+                                .attr("height", "80")
+                            )
+                        }
+                    i++;
+                    });
+                    $("#w3cBrowseForm").dialog("open");
+                }
+            })
+        });
+    });
+
+   // use this object to hold the choices of w3c widgets after the page has 
loaded.
+    var PostLoadW3cWidgets = new function PostLoadW3cWidgets() {
+        this.list = null;
+        this.setList = function (list) {
+            this.list = list;
+        }
+        this.getList = function () {
+            return this.list;
+        }
+        this.getListItemByIndex = function(idx){
+            return this.list[idx];
+        }
+    }
+
+    function updateRaveMetadata(id){
+        if(id != null){
+            widget = PostLoadW3cWidgets.getListItemByIndex(id);
+            $('#title').val(widget.title);
+            $('#description').val(widget.description);
+            $('#thumbnailUrl').val(widget.thumbnailUrl);
+            $('#screenshotUrl').val(widget.screenshotUrl);
+            $('#titleUrl').val(widget.titleUrl);
+            $('#author').val(widget.author);
+            $('#authorEmail').val(widget.authorEmail);
+            $('#url').val(widget.url);
+            $('#addWidgetForm').show();
+            $('#addWidgetFormSubmit').show();
+        }
+        $("#w3cBrowseForm").dialog("close");
+    }
+</script>
+</portal:register-init-script>
+


Reply via email to