#*
 * Aipo is a groupware program developed by Aimluck,Inc.
 * Copyright (C) 2004-2011 Aimluck,Inc.
 * http://www.aipo.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *#

#*
Copyright 2004 The Apache Software Foundation

Licensed 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.
*#

<script>
<!--
  function validateAddPortlet() {
    var result = true;
  
    var f= document.AddPortletForm;
    if(f.portlet_name.value.length == 0)
    {
      result = false;
      alert("$l10n.REGISTRY_EDITOR_PORTLET_MISSING_NAME");
    }
    
    var className = f.class_name.value;
    
    var index = f.portlet_type.selectedIndex;
    var portletType = f.portlet_type.options[index].value;
    if((portletType == "instance" || portletType == "abstract") && className.length == 0)
    {
      result = false;
      alert("$l10n.REGISTRY_EDITOR_PORTLET_CLASSNAME_REQUIRED");
    }
    
    var parentIndex = f.parent.selectedIndex;
    var parent = f.parent.options[parentIndex].value;
    if(portletType == "ref" && parent.length == 0) {
    	result = false;
    	alert("$l10n.REGISTRY_EDITOR_PORTLET_PARENT_REQURIED");
    }
    
    return result;
  }

-->
</script>

<table bgcolor="#ffffff" cellpadding="5">
  #if ($msg)
  <tr>
    <td colspan="2">
      <table bgcolor="#ffffff">
        <tr>
          <td>
            $msg
          </td>
        </tr>
      </table>
    </td>
  </tr>
  #end
  #if($reason)
  <tr>
    <td colspan="2">
      <table bgcolor="#ffffff">
        <tr>
          <td>
            $reason
          </td>
        </tr>
      </table>
    </td>
  </tr>
  #end
</table>

#if (($mode == "delete"))
<form name="DeletePortletForm" method="post" action="$jslink.getPaneByName("PortletBrowser").setAction("portlets.PortletUpdateAction")">
  <table>
    <tr>
      <td colspan="2">$l10n.REGISTRY_EDITOR_PORTLET_CONFIRM_DELETE</td>
    </tr>
    <tr>
      #formReadOnlyCell ($l10n.REGISTRY_EDITOR_PORTLET_NAME "portlet_name" $!entry.Name)
    </tr>
  </table>
  <table border="0" cellspacing="0" cellpadding="5" width="30%">
    <tr>
      <td>
        <input type="submit" name="eventSubmit_doDelete" value="$l10n.REGISTRY_EDITOR_PORTLET_DELETE"/>
      </td>
    </tr>
  </table>
</form>

#elseif ($mode == "insert")
<form name="AddPortletForm" method="post" action="$jslink.getPaneByName("PortletForm").setAction("portlets.PortletUpdateAction")" onSubmit="return validateAddPortlet();">
  <table>
    <input type="hidden" name="mode" value="update"/>
    <tr>
      <td bgcolor="$!{skin.TitleBackgroundColor}">
        <b><font face="$ui.sansSerifFonts">$l10n.REGISTRY_EDITOR_PORTLET_NAME</font></b>
      </td>
      <td bgcolor="$!{skin.TitleBackgroundColor}">
        <font face="$ui.sansSerifFonts">
          <input type="text" size="30" name="portlet_name" value="$!data.user.getTemp("portlet_name")"/>
        </font>
     </td>
    </tr>
    <tr>
      <td bgcolor="$!{skin.TitleBackgroundColor}">
        <b><font face="$ui.sansSerifFonts">$l10n.REGISTRY_EDITOR_PORTLET_TYPE</font></b>
      </td>
      <td bgcolor="$!{skin.TitleBackgroundColor}">
        <font face="$ui.sansSerifFonts">
          #set($portletTypes = ["abstract", "ref", "instance"])
          <select name="portlet_type">
              #foreach($portletType in $portletTypes)
                  <option value="$portletType" #if($!data.user.getTemp("portlet_type") == $portletType) selected="true" #end>$portletType</option>
              #end
          </select>
        </font>
      </td>
    </tr>
    <tr>
      <td bgcolor="$!{skin.TitleBackgroundColor}">
        <b><font face="$ui.sansSerifFonts">$l10n.REGISTRY_EDITOR_PORTLET_PARENT</font></b>
      </td>
      <td bgcolor="$!{skin.TitleBackgroundColor}">
        <font face="$ui.sansSerifFonts">
          <select name="parent">
              <option value="">$l10n.REGISTRY_EDITOR_PORTLET_NOPARENT</option>
                #foreach($parent in $parents)
        		  #if($parent.Title)
        		    <option value="$parent.name" #if($!data.user.getTemp("parent") == $parent.name) selected="true" #end>$parent.title</option>
        		  #else
        		    <option value="$parent.name" #if($!data.user.getTemp("parent") == $parent.name) selected="true" #end>$parent.name</option>
        	          #end
        		#end
          </select>
        </font>
      </td>
    </tr>
    <tr>
      <td bgcolor="$!{skin.TitleBackgroundColor}">
        <b><font face="$ui.sansSerifFonts">$l10n.REGISTRY_EDITOR_PORTLET_CLASSNAME</font></b>
      </td>
      <td bgcolor="$!{skin.TitleBackgroundColor}">
        <font face="$ui.sansSerifFonts">
          <input type="text" size="50" name="class_name" value="$!data.user.getTemp("class_name")"/>
        </font>
      </td>
    </tr>
    <tr>
      <td bgcolor="$!{skin.TitleBackgroundColor}">
        <b><font face="$ui.sansSerifFonts">$l10n.REGISTRY_EDITOR_PORTLET_TITLE</font></b>
      </td>
      <td bgcolor="$!{skin.TitleBackgroundColor}">
        <font face="$ui.sansSerifFonts">
          <input type="text" size="50" name="title" value="$!data.user.getTemp("title")">
        </font>
      </td>
    </tr>
    <!--Consider making text area-->
    <tr>
      <td bgcolor="$!{skin.TitleBackgroundColor}">
        <b><font face="$ui.sansSerifFonts">$l10n.REGISTRY_EDITOR_PORTLET_DESCRIPTION</font></b>
      </td>
      <td bgcolor="$!{skin.TitleBackgroundColor}">
       <font face="$ui.sansSerifFonts">
         <textarea rows="10" cols="50" size="50" name="description">$!data.user.getTemp("description")</textarea>
       </font>
      </td>
    </tr>
    <tr>
      <td bgcolor="$!{skin.TitleBackgroundColor}">
        <b><font face="$ui.sansSerifFonts">$l10n.REGISTRY_EDITOR_PORTLET_URL</font></b>
      </td>
      <td bgcolor="$!{skin.TitleBackgroundColor}">
        <font face="$ui.sansSerifFonts">
          <input type="text" size="50" name="url" value="$!data.user.getTemp("url")">
        </font>
      </td>
    </tr>
    <tr>
      <td bgcolor="$!{skin.TitleBackgroundColor}">
        <b><font face="$ui.sansSerifFonts">$l10n.REGISTRY_EDITOR_PORTLET_IMAGE</font></b>
      </td>
      <td bgcolor="$!{skin.TitleBackgroundColor}">
        <font face="$ui.sansSerifFonts">
          <input type="text" size="50" name="image" value="$!data.user.getTemp("image")">
      </font>
      </td>
    </tr>
    <tr>
      <td bgcolor="$!{skin.TitleBackgroundColor}">
        <b><font face="$ui.sansSerifFonts">$l10n.REGISTRY_EDITOR_PORTLET_SECURITYREF</font></b>
      </td>
      <td bgcolor="$!{skin.TitleBackgroundColor}">
        <font face="$ui.sansSerifFonts">
          <select name="security_ref">
              <option value="">${l10n.PORTLET_FORM_NONE_VM}</option>
          #foreach($security in $securitys)
              <option value="$security.name" #if($security.name == $!data.user.getTemp("security_ref")) selected="true" #end>$security.name</option>
          #end
          </select>
        </font>
      </td>
    </tr>

    <!--Boolean checkboxes-->
    <tr>
      <td bgcolor="$!{skin.TitleBackgroundColor}">
        <b><font face="$ui.sansSerifFonts">$l10n.REGISTRY_EDITOR_PORTLET_HIDDEN</font></b>
      </td>
      <td bgcolor="$!{skin.TitleBackgroundColor}">
         <font face="$ui.sansSerifFonts">
           <input type="checkbox" size="30" name="is_hidden" #if($!data.user.getTemp("is_hidden") == "on") checked="true" #end />
         </font>
      </td>
    </tr>
    <tr>
      <td bgcolor="$!{skin.TitleBackgroundColor}">
        <b><font face="$ui.sansSerifFonts">$l10n.REGISTRY_EDITOR_PORTLET_APPLICATION</font></b>
      </td>
      <td bgcolor="$!{skin.TitleBackgroundColor}">
        <font face="$ui.sansSerifFonts">
          <input type="checkbox" size="30" name="is_application" #if($!data.user.getTemp("is_application") == "on") checked="true" #end />
        </font>
      </td>
    </tr>
    <tr>
      <td bgcolor="$!{skin.TitleBackgroundColor}">
        <b><font face="$ui.sansSerifFonts">$l10n.REGISTRY_EDITOR_PORTLET_CACHEDONURL</font></b>
      </td>
      <td bgcolor="$!{skin.TitleBackgroundColor}">
        <font face="$ui.sansSerifFonts">
          <input type="checkbox" size="30" name="is_cached_on_url" #if($!data.user.getTemp("is_cached_on_url") == "on") checked="true" #end />
        </font>
      </td>
    </tr>
  </table>
  <table border="0"  cellspacing="0" cellpadding="5" width="30%">
    <tr>
      <td>
        <input type="submit" name="eventSubmit_doInsert" value="$l10n.REGISTRY_EDITOR_PORTLET_INSERT"/>
      </td>
    </tr>
  </table>
</form>
#elseif($mode == "update")
  #if(! $currentTab)
    #set($currentTab = "info")
  #end
<table cellpadding="0" cellspacing="0" border="0" width="100%" #if (${skin.TabStyleClass}) class="${skin.TabStyleClass}" #end >
  <tr>
    <td valign="top">
      <table cellpadding="0" cellspacing="0" border="0" width="100%" #if (${skin.TabStyleClass}) class="${skin.TabStyleClass}" #end >
        #set($tabs = [[$l10n.REGISTRY_EDITOR_PORTLET_TAB_INFO, "info"], [$l10n.REGISTRY_EDITOR_PORTLET_TAB_MEDIATYPES, "media_types"], [$l10n.REGISTRY_EDITOR_PORTLET_TAB_CATEGORIES, "categories"], [$l10n.REGISTRY_EDITOR_PORTLET_TAB_PARAMETERS, "parameters"]])
        <tr>
          <td valign="top">
            <table align="left" cellspacing="0" border="0" cellpadding="0" #if (${skin.TabTitleStyleClass}) class="${skin.TabTitleStyleClass}" #end >
              <tr width="100%">
                #foreach ( $tab in $tabs )
                  #if ($tab.get(1) == $currentTab )
                    #set ($bgcolor = $!{skin.HighlightBackgroundColor} )
                    #set ($color = $!{skin.HighlightTextColor} )
                    #set ($titleclass = $!{skin.HighlightTitleStyleClass} )
                  #else
                    #set ($bgcolor = $!{skin.TitleBackgroundColor} )
                    #set ($color = $!{skin.TitleTextColor} )
                    #set ($titleclass = $!{skin.TitleStyleClass} )
                  #end

                  #if (${bgcolor})
                    #if (${color})
                      #set ($titlestyle = "background-color: $bgcolor; color: $color;" )
                    #else
                      #set ($titlestyle = "background-color: $bgcolor;" )
                    #end
                  #else
                    #if (${color})
                      #set ($titlestyle = "color: $color;" )
                    #else
                      #set ($titlestyle = "" )
                    #end
                  #end
                  <td valign="middle" #if ($titleclass) class="$titleclass" #end #if ($titlestyle) style="${titlestyle}" #end >
                    #if ($tab.get(1) != $currentTab)
                      <a href="$jslink.getPaneByName("PortletForm").addQueryData("portlet_name",$entry.name).addQueryData("mode","update").addQueryData("tab", $tab.get(1))" #if ($color) style="color: $color" #end>$tab.get(0)</a>
                    #else
                      $tab.get(0)
                    #end
                  </td>
                  <td width="2">&nbsp;</td>
                #end
              </tr>
            </table>
          </td>
        </tr>
      </table>
      <table cellspacing="0" width="100%" border="0" cellpadding="0" #if (${skin.TabStyleClass}) class="${skin.TabStyleClass}" #end >
        <tr><td height="2" #if (${skin.HighlightBackgroundColor}) style="background-color: ${skin.HighlightBackgroundColor}" #end ><img height="2" width="2" src="images/dot.gif" /></td></tr>
        <tr><td height="2" #if (${skin.BackgroundColor}) style="background-color: ${skin.BackgroundColor}" #end ><img height="2" width="2" src="images/dot.gif" /></td></tr>
      </table>
      <table cellspacing="0" width="100%" border="0" cellpadding="0" #if (${skin.TabStyleClass}) class="${skin.TabStyleClass}" #end >
        <tr>
          <td>
            <table cellspacing="0" width="100%" border="0" cellpadding="0" #if (${skin.TabContentStyleClass}) class="${skin.TabContentStyleClass}" #end #if (${skin.BackgroundColor}) style="background-color: ${skin.BackgroundColor}" #end >
              <tr>
                <td valign="top" width="100%">
                  #if($currentTab == "info")
                    #parse("/portlets/html/portlet-info-form.vm")
                  #elseif($currentTab == "media_types")
                    #parse("/portlets/html/portlet-mediatype-form.vm")
                  #elseif($currentTab == "categories")
                    #parse("/portlets/html/portlet-category-form.vm")
                  #elseif($currentTab == "parameters" || $currentTab == "VerboseParameter")
                    #parse("/portlets/html/portlet-parameter-form.vm")
                  #end
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
#end
<table>
  <tr>
    <td>
      <form name="PortletForm" method="post" action="$jslink.getPaneByName("PortletBrowser").setAction("portlets.PortletUpdateAction")">
        <input type="submit" name="eventSubmit_doCancel" value="$l10n.REGISTRY_EDITOR_PORTLET_CANCEL"/>
      </form>
    </td>
    <td>&nbsp;</td>
    <td>
      <form name="HelpForm" method="post" action="$clink.setURI("docs/site/catalog.html")" target="_blank">
    	<input type="submit" value="$l10n.REGISTRY_EDITOR_PORTLET_PORTLETCATALOG"/>
      </form>
    </td>
  </tr>
</table>
