- $isBlacklist = $plateList->mode == PlateList::MODE_BLACK_LIST
- if($isBlacklist)
  - $imgurl = $plateList->getImageUrl('/images/list_black.png')
- else
  - $imgurl = $plateList->getImageUrl('/images/list_white.png')

- $listType = $isBlacklist ? 'Blacklist' : 'Whitelist';

- $customValidityPeriods = PlateAuthorizationController::getCustomValidityPeriods()

- $gates = array('-1' => t('Every gate')) + PlateAuthorizationController::getGateObjects()
- $times = array('-1' => t('Always')) + TimeSchedule::getTimeScheduleArrayForPlateAuths()
- $types = paramdeep('plateAuthorizations','types')
- $vehicleSources = paramdeep('plateAuthorizations','vehicleSources')
- if($vehicleSources == null || count($vehicleSources) <= 0)
  - $vehicleSources = array()
- else
  - $vehicleSources = array_merge(array('' => ''), $vehicleSources)
  
-if(isEmpty($plateAuthorization->source))
  -$plateAuthorization->source = paramdeep('plateAuthorizations','default','vehicleSource')
  
-if(count($vehicleSources)>0)
  - if(!array_key_exists(paramdeep('plateAuthorizations','default','vehicleSource'),$vehicleSources))
    -$vehicleSources[paramdeep('plateAuthorizations','default','vehicleSource')] = paramdeep('plateAuthorizations','default','vehicleSource')

- if(!array_key_exists(paramdeep('plateAuthorizations','default','plateAuthType'),$types))
  -$types[paramdeep('plateAuthorizations','default','plateAuthType')] = paramdeep('plateAuthorizations','default','plateAuthType')

- if(!array_key_exists(paramdeep('plateAuthorizations','default','time'),$times))
  -$times[paramdeep('plateAuthorizations','default','time')] = paramdeep('plateAuthorizations','default','time')

- if(!array_key_exists(paramdeep('plateAuthorizations','default','gate'),$gates))
  -$gates[paramdeep('plateAuthorizations','default','gate')] = paramdeep('plateAuthorizations','default','gate')

#plate-authorization-page
  .page-header
    %table(width="100%")
      %tr
        %td
          %h2
            %i.icon-ok-circle
            -if(user()->checkAccess('plate_auth_confirmed') || $isBlacklist)
              = Yii::t('app', "Add vehicle").': '.$plateList->getListTitle()
            -else
              = Yii::t('app', "Request to add vehicle").': '.$plateList->getListTitle()
        %td
          -if(!empty($imgurl))
            %img(src="#{$imgurl}" width="100" align="right")
      
  .row
    .sidebar.span12
      - $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', |
        array(                                                       |
          'type' => 'horizontal',                                    |
          'action' => array("/plateAuthorization/new".$listType."/".$plateList->id),             |
          'htmlOptions' => array(                                    |
            'id' => 'new-blacklist-form',                      |
          ),                                                         |
        ))                                                           |
      #plate-authorization-data.row
        %fieldset
          .plate-authorization-container
            .row
              .vehicle-data.span4
                %h4 
                  = t("Vehicle")
                -$plates = $plateAuthorization->getPlates()
                -$platesCount = count($plates)
                -$platesCount = $platesCount <= 0 ? 1 : $platesCount
                != $form->textAreaRow($plateAuthorization, 'plate', array('class' => 'span2 touppercase', 'rows'=>$platesCount))
                -if(!paramdeep('plateAuthorizations','rapidInsert','hideVehicleModel'))
                  != $form->textFieldRow($plateAuthorization, 'vehicleModel', array('class' => 'span2'))
                != $form->dropDownListRow($plateAuthorization,'vehicleNationality', array_merge(array('' => ''), CountryList::localized()), array('class'=>'span2  chzn-select', 'data-placeholder' => Yii::t('app', 'Country...')));
                -if(!paramdeep('plateAuthorizations','rapidInsert','hideVehicleType'))
                  != $form->dropDownListRow($plateAuthorization,'vehicleType',array_merge(array('' => ''), VehicleTypes::localized()), array('class'=>'span2 chzn-select', 'data-placeholder' => Yii::t('app', 'Class...')));
                -if($isBlacklist)
                  != $form->dropDownListRow($plateAuthorization,'vehicleCategory',array_merge(array('' => ''), VehicleCategory::getCategoryList()), array('class'=>'span2 chzn-select', 'data-placeholder' => Yii::t('app', 'Category...')));
                %h4
                  = t("Vehicle Owner") 
                != $form->textFieldRow($plateAuthorization, 'name', array('class' => 'span2'))
                != $form->textFieldRow($plateAuthorization, 'surname', array('class' => 'span2'))
                -if(!$isBlacklist)
                  -if(user()->checkAccess('vehicle_owner_management_contacts') || user()->checkAccess('vehicle_owner_management_identity') || user()->checkAccess('vehicle_owner_management_full') || user()->checkAccess('vehicle_owner_create'))
                    -if(!paramdeep('plateAuthorizations','rapidInsert','hideEmail') || !paramdeep('plateAuthorizations','rapidInsert','hidePhone') || !paramdeep('plateAuthorizations','rapidInsert','hideAddress') || !paramdeep('plateAuthorizations','rapidInsert','hideCity'))
                      -if(!paramdeep('plateAuthorizations','rapidInsert','hideEmail'))
                        != $form->textFieldRow($plateAuthorization, 'email', array('class' => 'span2'))
                      -if(!paramdeep('plateAuthorizations','rapidInsert','hidePhone'))
                        != $form->textFieldRow($plateAuthorization, 'phone', array('class' => 'span2'))
                      -if(!paramdeep('plateAuthorizations','rapidInsert','hideAddress'))
                        != $form->textFieldRow($plateAuthorization, 'address', array('class' => 'span2'))
                      -if(!paramdeep('plateAuthorizations','rapidInsert','hideCity'))
                        != $form->textFieldRow($plateAuthorization, 'city', array('class' => 'span2'))
                    != $form->checkBoxRow($plateAuthorization, 'overwriteVehicleOwner')
                  %h4
                    = t("Plate authorization")
                    -if(!paramdeep('plateAuthorizations','rapidInsert','hideAuthType'))
                      != $form->dropDownListRow($plateAuthorization,'type', $types, array('class'=>'span2 chzn-select', 'data-placeholder' => Yii::t('app', 'Type...')));
                    -else
                      != $form->hiddenField($plateAuthorization,'type')
                    != $form->dropDownListRow($plateAuthorization,'filterGate', $gates, array('class'=>'span2 chzn-select', 'data-placeholder' => Yii::t('app', 'Gate...')));
                    != $form->dropDownListRow($plateAuthorization,'filterTime', $times, array('class'=>'span2 chzn-select', 'data-placeholder' => Yii::t('app', 'Time...')));
              .management-data.span8
                %h4
                  = t($isBlacklist ? "Alert duration" : "Validity Period")
                .control-group     
                  .btn-group#when-buttons
                    %button.btn(type='button' data-behavior='DateRangeSetter' data-daterange-setter-when='today' data-daterange-setter-start-date='#startDate' data-daterange-setter-start-time='#startTime' data-daterange-setter-end-date='#endDate' data-daterange-setter-end-time='#endTime')
                      = t('Today')
                    %button.btn(type='button' data-behavior='DateRangeSetter' data-daterange-setter-when='thisweek' data-daterange-setter-start-date='#startDate' data-daterange-setter-start-time='#startTime' data-daterange-setter-end-date='#endDate' data-daterange-setter-end-time='#endTime')
                      = t('This week')
                    %button.btn(type='button' data-behavior='DateRangeSetter' data-daterange-setter-when='thismonth' data-daterange-setter-start-date='#startDate' data-daterange-setter-start-time='#startTime' data-daterange-setter-end-date='#endDate' data-daterange-setter-end-time='#endTime')
                      = t('This month')
                    %button.btn(type='button' data-behavior='DateRangeSetter' data-daterange-setter-when='thisyear' data-daterange-setter-start-date='#startDate' data-daterange-setter-start-time='#startTime' data-daterange-setter-end-date='#endDate' data-daterange-setter-end-time='#endTime')
                      = t('This year')
                    %button.btn(type='button' data-behavior='DateRangeSetter' data-daterange-setter-when='always' data-daterange-setter-start-date='#startDate' data-daterange-setter-start-time='#startTime' data-daterange-setter-end-date='#endDate' data-daterange-setter-end-time='#endTime' id="alwaysButton")
                      = t('Always')
                -if(!$isBlacklist)
                  .control-group     
                    .btn-group#when-buttons
                      %button.btn(type='button' data-behavior='DateRangeSetter' data-daterange-setter-when='tomorrow' data-daterange-setter-start-date='#startDate' data-daterange-setter-start-time='#startTime' data-daterange-setter-end-date='#endDate' data-daterange-setter-end-time='#endTime')
                        = t('Tomorrow')
                      %button.btn(type='button' data-behavior='DateRangeSetter' data-daterange-setter-when='nextweek' data-daterange-setter-start-date='#startDate' data-daterange-setter-start-time='#startTime' data-daterange-setter-end-date='#endDate' data-daterange-setter-end-time='#endTime')
                        = t('Next week')
                      %button.btn(type='button' data-behavior='DateRangeSetter' data-daterange-setter-when='nextmonth' data-daterange-setter-start-date='#startDate' data-daterange-setter-start-time='#startTime' data-daterange-setter-end-date='#endDate' data-daterange-setter-end-time='#endTime')
                        = t('Next month')
                      %button.btn(type='button' data-behavior='DateRangeSetter' data-daterange-setter-when='nextyear' data-daterange-setter-start-date='#startDate' data-daterange-setter-start-time='#startTime' data-daterange-setter-end-date='#endDate' data-daterange-setter-end-time='#endTime')
                        = t('Next year')
                -if(is_array_ex($customValidityPeriods,true))
                  .control-group     
                    .btn-group#when-buttons
                      -$btnCVPindex=0
                      -foreach($customValidityPeriods as $cvpLabel => $cvpDate)
                        %button.btn(type='button' data-behavior='DateRangeSetter' data-daterange-setter-when="#{$cvpDate}" data-daterange-setter-start-date='#startDate' data-daterange-setter-start-time='#startTime' data-daterange-setter-end-date='#endDate' data-daterange-setter-end-time='#endTime')
                          =$cvpLabel
                        -$btnCVPindex++
                        -if($btnCVPindex % 4 == 0 && $btnCVPindex > 0)
                          %br

                =t('From')
                %br
                
                .control-group
                  %input#datepicker-end-date.date-picker.span2(id='startDate' type='text' name='NewBlacklistForm[startDate]' value="#{$plateAuthorization->startDate}" readonly='true')
                  %input#end-timestamp(type="hidden")
                  %span.add-on.icon-calendar
            
                  #datepicker-start-time.input-prepend.input-append.time-picker
                    %span.add-on
                    %input.span1(data-format="#{Yii::app()->params['timeselect_format'][Yii::app()->language]['view']}" type="text" id="startTime" name="NewBlacklistForm[startTime]" value="#{$plateAuthorization->startTime}")
                    %span.add-on
                      %i(data-time-icon="icon-time" data-date-icon="icon-calendar")

                =t('To')
                %br
            
                .control-group
                  -if($isBlackList)
                    %input#datepicker-start-date.date-picker.span2(id='endDate' type='text' name='NewBlacklistForm[endDate]' value="#{$plateAuthorization->endDate}" readonly='true')
                  -else
                    %input#datepicker-start-date.date-picker.span2(id='endDate' type='text' name='NewBlacklistForm[endDate]' value="#{$plateAuthorization->endDate}" readonly='true')
                  %input#start-timestamp(type="hidden")
                  %span.add-on.icon-calendar
            
                  #datepicker-end-time.input-prepend.input-append.time-picker
                    %span.add-on
                    %input.span1(data-format="#{Yii::app()->params['timeselect_format'][Yii::app()->language]['view']}" type="text" id="endTime" name="NewBlacklistForm[endTime]" value="#{$plateAuthorization->endTime}")
                    %span.add-on
                      %i(data-time-icon="icon-time" data-date-icon="icon-calendar")
                -if(!paramdeep('plateAuthorizations','rapidInsert','hideSource') || !paramdeep('plateAuthorizations','rapidInsert','hideAction') || !paramdeep('plateAuthorizations','rapidInsert','hideNote'))
                  %h4
                    = t("Additional informations")
                  -if(!$isBlacklist)
                    -if(!paramdeep('plateAuthorizations','rapidInsert','hideSource'))
                      -if(count($vehicleSources)>0)
                        != $form->dropDownListRow($plateAuthorization,'source', $vehicleSources, array('class'=>'span2  chzn-select', 'data-placeholder' => Yii::t('app', 'Source...')));
                      -else
                        != $form->textFieldRow($plateAuthorization, 'source', array('class' => 'span2'))
                    -if(!paramdeep('plateAuthorizations','rapidInsert','hideAction'))
                      != $form->textAreaRow($plateAuthorization, 'action', array('class' => 'span2', 'maxlength' => '250'))
                  -if(!paramdeep('plateAuthorizations','rapidInsert','hideNote'))
                    -$scriptNote = $this->getSuggestionsJSForWLT('note', $plateList->code)
                    -if($scriptNote!=null)
                      != $scriptNote
                      != $form->textAreaRow($plateAuthorization, 'note', array('class' => 'auto_note span2', 'maxlength' => '250'))
                    -else
                      != $form->textAreaRow($plateAuthorization, 'note', array('class' => 'span2', 'maxlength' => '250'))

        -echo $form->errorSummary($plateAuthorization)
      - $this->endWidget()

      %button#save-btn.btn(type="button" data-confirm-text="#{Yii::t('app', 'Confirm')}"
      data-form-action=Yii::app()->createUrl('plateAuthorization/new'.$listType, array('plateListId'=> $plateList->id))
      data-target="#new-blacklist-form")= Yii::t('app', 'Create')
      
      
-if(!empty($plateAuthorization->startDate))
  %input(type="hidden" value="#{$plateAuthorization->startDate}" id="tmpSetStartDate")
  :javascript
    setTimeout(function(){
      $('#startDate').val($('#tmpSetStartDate').val());
    }, 500);
-if(!empty($plateAuthorization->endDate))
  %input(type="hidden" value="#{$plateAuthorization->endDate}" id="tmpSetEndDate")
  :javascript
    setTimeout(function(){
      $('#endDate').val($('#tmpSetEndDate').val());
    }, 500);

- if($isBlacklist)
  %script{:type => "text/javascript"}
    !="$('#alwaysButton').addClass('active')"