#*
-- Required action variables:
- $space - the current space in which the page is located
- $newSpaceKey - String representation of the new spaceKey
- $parentPageString - String representation of the parent page name
- $availableSpaces - List of all availabel spaces the user has permissions for
- $hasChildren - boolean whether or not the current page has children
- $moveHierarchy - boolean to indicate whether the whole hierarchy should be moved

-- Required action methods:
- $action.hasPermittedChildren() - Determines whether the page has permitted children
- $action.getParentPage()

-- Required velocity variables:
- $formname - determines the form in which the textfield is has to be set
- $mode           - determines the mode of the editor (currently 'edit' or 'create' supported)
*#

#requireResource("confluence.web.resources:page-ordering-tree")
#requireResource("confluence.web.resources:ajs")
#requireResource("confluence.web.resources:page-location-editor")

#if ($mode == "edit")
    #set ($pageToExpand = $page)
#else
    #set ($pageToExpand = $parentPage)
#end

<fieldset class="hidden parameters">
    <input type="hidden" title="editLabel" value="$action.getText('edit.name')">
    <input type="hidden" title="doneLabel" value="$action.getText('done.name')">
    <input type="hidden" title="showLocation" value="$action.locationShowing">
    <input type="hidden" title="hasChildren" value="$!helper.action.page.hasChildren()">
    <input type="hidden" title="availableSpacesSize" value="$action.availableSpaces.size()">
    <input type="hidden" title="spaceKey" value="$action.space.key">
    <input type="hidden" title="pageId" value="$pageId">
    <input type="hidden" title="actionMode" value="$mode">
    <input type="hidden" title="parentPageId" value="$!parentPage.id">
    #foreach ($node in $pageToExpand.ancestors)
    <input type="hidden" title="expandedNodes" class="list" value="$node.id">
    #end
</fieldset>

<span class="formtitle">$action.getText("location.name"):</span>
<span id="location_info">
    <span id="space_info" #if(!$space.name)class="hidden"#end>
        <span id="space_content">$generalUtil.htmlEncode($spaceManager.getSpace($newSpaceKey).name)</span>
    </span>
    <span id="parent_info" #if(!$parentPageString)class="hidden"#end>
        &gt; <span id="parent_content">$generalUtil.htmlEncode($parentPageString)</span>
    </span>
    <a href="" class="inline-control-link" id="location_edit_link">$action.getText('edit.name')</a>
</span>

<a name="locationSection"/>
<div id="location_div" class="toggleFormDiv editor-panel hidden">
    #fielderrorExecuteFunction ('parentPageString' 'showLocationDiv()')

    #if ($mode == "create" || $permissionHelper.canRemove($remoteUser, $action.page))
      <div class="smalltext" style="float:right">$action.getText("tip.edit.movepage")</div>
      <div>
          <label id="currentLocation" class="formtitle">$action.getText('space-title')</label>

      #if ($availableSpaces.size() > 1)
          <select id="newSpaceKey" name="newSpaceKey" tabindex="3">
          #foreach ($space in $availableSpaces)
              <option value="$space.getKey()" #if( $newSpaceKey == $space.getKey() ) selected#end>$webwork.htmlEncode($space.name)</option>
          #end
          </select>
      #else
          $webwork.htmlEncode($space.name)
          <input type="hidden" value="$space.getKey()" name="newSpaceKey" id="newSpaceKey" />
      #end
      </div>
   #else
      <div class="smalltext" style="float:right">$action.getText("tip.cannot.move.page.between.spaces")<br>
      $action.getText("tip.edit.movepage")</div>
   #end

    <div id="resultsDiv"></div>
    <div style="padding: 10px" id="outer-container"><div id="tree-div" style="min-height:150px"></div></div>
    <input id="parentPageString" type="hidden" value="$generalUtil.htmlEncode($!parentPageString)" name="parentPageString"/>
	<input id="hierarchy_checkbox" type="hidden" name="moveHierarchy" value="true" />
    <input id="position" type="hidden" value="" name="position"/>
    <input id="targetId" type="hidden" value="" name="targetId"/>
</div>
