{block "action"}{/block}

{$messages_types =[
'success' => ['icon' => 'ok', 'descr' => {'successDescription'|translate}],
'warning' => ['icon' => 'warning-sign', 'descr' => {'warningDescription'|translate}]
]}

{block "messages"}
   <hr>
   <div class="form-group">
      <label class="col-md-2 control-label">{'warning'|translate}</label>
      <div class="col-md-4">
         <div class="dropdown">
            <a class="btn btn-sm btn-block dropdown-toggle" data-toggle="dropdown">
               <span class="glyphicon glyphicon-plus"></span> {'addMessage'|translate}
            </a>
            <ul class="dropdown-menu" style="margin-top: 0px;">
                {foreach $messages_types as $type => $message_type}
                   <li>
                      <a onclick="addActionMessage('{$type}', '{$name}');">
                         <span class="glyphicon glyphicon-{$message_type.icon} text-{$type}"
                               style="padding-right: 5px;"></span> {$message_type.descr}
                      </a>
                   </li>
                {/foreach}
            </ul>
         </div>
      </div>
   </div>
    {foreach $messages_types as $type => $message_type}
        {$message = $data.messages[$type]}
       <div class="form-group" id="messages_{$type}" data-name="{$name}" {if !$message}style="display:none;"{/if}>
          <div class="col-md-2 control-label text-{$type}" title="{$message_type.descr}"><span
                     class="glyphicon glyphicon-{$message_type.icon}"></span></div>
          <div class="col-md-8">
             <input type="text" class="form-control input-sm" name="{$name}[data][messages][{$type}]"
                    value="{$message}">
          </div>
          <div class="col-md-2">
             <a class="btn btn-sm btn-danger" onclick="removeActionMessage('{$type}', '{$name}');">
                <span class="glyphicon glyphicon-remove"></span>
             </a>
          </div>
       </div>
    {/foreach}
   <script>
      function addActionMessage($type, $name) {
         $('#messages_' + $type + '[data-name=\'' + $name + '\']').show();
      }

      function removeActionMessage($type, $name) {
         $('#messages_' + $type + '[data-name=\'' + $name + '\']').find('input[type=\'text\']').val('');
         $('#messages_' + $type + '[data-name=\'' + $name + '\']').hide();
      }
   </script>
{/block}
