<?php
/**
 * Copyright © 2012 Alcatel-Lucent.
 *
 * See the NOTICE file distributed with this work for additional information regarding copyright ownership. Licensed 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.
 */

/**
 * View snippet for Properties form elements
 *
 * Date: 8/29/12
 *
 * @var array $properties
 */
$count = 0;
$keys = @array_keys($properties);
$values = @array_values($properties);

$propKeyTip = $translate->translate("Enter a unique key for this property");
$propValueTip = $translate->translate("Enter the value for this property");
$propAddTip = $translate->translate("Add additional property");
$propRemoveTip = $translate->translate("Remove property");

for($i = 0; $i <= count($properties); $i++):
?>

<div class="control-group property <?= !empty($validationErrors['property'][$i])?"error":""?>" count="<?=$i?>" id="propertyGroup<?=$i?>">
    <? if($i === 0): ?>
    <label class="control-label" for="properties<?=$i?>"><? echo $translate->translate("Properties")?></label>
    <? endif ?>
    <div class="controls">
        <input type="text" class="input-small" placeholder="<? echo $translate->translate("Key")?>"
               id="properties<?=$i?>" name="property[<?=$i?>][name]" value="<?=@$keys[$i]?>"
               rel="tooltip" title="<?=$propKeyTip?>">
        <input type="text" class="input-small" placeholder="<? echo $translate->translate("Value")?>"
               name="property[<?=$i?>][value]" value="<?=@$values[$i]?>"
               rel="tooltip" title="<?=$propValueTip?>">
        <? if($i === 0): ?>
        <button class="btn newItem" type="property" title="<?=$propAddTip?>" id="propertyPlus"
                rel="tooltip" data-placement="right"><i class="icon-plus"></i></button>
        <? else: ?>
        <button class="btn removeItem" type="property" number="<?=$i?>" title="<?=$propRemoveTip?>"
                rel="tooltip" data-placement="right"><i class="icon-minus"></i></button>
        <? endif ?>
        <span class="help-inline">
        <?if(!empty($validationErrors['property'][$i])):
            foreach($validationErrors['property'][$i] as $error): ?>
            <?= $error ?><br/>
            <? endforeach ?>
        <? endif ?>
        </span>
    </div>
</div>
<? endfor ?>

