Commits

André Walker committed bd8e1d3

Several fixes for job form to work again

Comments (0)

Files changed (7)

lib/PerlPro/Schema/ResultSet/Job.pm

                 company             => { required => 1, type => Str },
                 title               => { required => 1, type => Str },
                 description         => { required => 1, type => Str },
-                vacancies           => { required => 0, type => Int },
                 phone               => { required => 0, type => Str },
                 email               => { required => 0, type => EmailAddress },
                 wages               => { required => 1, type => Money },
                 hours               => { required => 1, type => Int },
                 hours_by            => { required => 1, type => HoursBy },
                 is_at_office        => { required => 0, type => Bool },
+                address             => { required => 0, type => Str },
+                city                => { required => 0, type => Str },
+                state               => { required => 0, type => Str },
                 contract_type       => { required => 0, type => ContractType }, # if it's not set, it's "no-contract"
                 desired_attributes  => { required => 0, type => AttributeArray, coerce => 1 },
                 required_attributes => { required => 0, type => AttributeArray, coerce => 1 },
         create_or_update => sub {
             my %values = shift->valid_values;
             my (%row_values, $row);
-            for (qw/status company title description vacancies phone email wages wages_for hours hours_by contract_type/) {
+            for (qw/status company title description phone email wages wages_for hours hours_by contract_type/) {
                 $row_values{$_} = $values{$_} if $values{$_};
             }
             $row_values{is_telecommute} = $values{is_at_office} ? 0 : 1;
                 $row = $self->create(\%row_values);
             }
 
+            if ($values{state} && $values{city}) {
+                if ($row->job_location) {
+                    $row->job_location->update({
+                        address => $values{address},
+                        city    => $values{city},
+                        state   => $values{state},
+                    });
+                }
+                else {
+                    $row->create_related('job_location', {
+                        address => $values{address},
+                        city    => $values{city},
+                        state   => $values{state},
+                        country => 'Brazil',
+                    });
+                }
+            }
+
             for my $type (qw/required desired/) {
                 for my $attr (@{ $values{"${type}_attributes"} }) {
                     $row->add_to_attributes({
 
     my $job = $self->find($id, {
         join => 'job_location',
-        '+select' => ['job_location.city'],
-        '+as' => ['city'],
+        '+select' => ['job_location.address', 'job_location.city', 'job_location.state'],
+        '+as' => ['address', 'city', 'state'],
     });
 
     return unless $job;
 
     my $company = $job->company;
 
-    my @websites = map { $_->url } $company->company_websites->search({}, {
+    my @websites = map {
+        $_->url
+    } $company->company_websites->search({}, {
         order_by => { -desc => 'is_main_website' }
     })->all;
-    my @phones = map { $_->phone } $company->company_phones->search({}, {
+
+    my @phones = map {
+        $_->phone
+    } $company->company_phones->search({ is_public => 1 }, {
         order_by => { -desc => 'is_main_phone' }
     })->all;
-    my @emails = map { $_->email } $company->company_emails->search({}, {
-        order_by => { -desc => 'is_main_address' }
-    })->all;
-    my @locations = map {
-        $_->address . ", "  .
-        $_->city    . " - " .
-        $_->state
-    } $company->company_locations->search({}, {
+
+    my @emails = map {
+        $_->email
+    } $company->company_emails->search({ is_public => 1 }, {
         order_by => { -desc => 'is_main_address' }
     })->all;
 
         job => {
             id                  => $id,
             title               => $job->title,
+            phone               => $job->phone,
+            email               => $job->email,
             salary              => $job->wages . '/' . _l($job->wages_for),
             hours               => $job->hours . 'h ' . _lh($job->hours_by),
             contract_type       => $job->contract_type,
+            address             => $job->get_column('address'),
             city                => $job->get_column('city'),
+            state               => $job->get_column('state'),
             description         => $job->description,
             required_attributes => $job->required_attributes,
             desired_attributes  => $job->desired_attributes,
             websites          => \@websites,
             emails            => \@emails,
             phones            => \@phones,
-            addresses         => \@locations,
             other_jobs        => $other_jobs,
         },
     };
         $item = $self->find($id);
     }
 
+    my $location = $item->job_location;
+    my %l;
+
+    %l = (
+        address => $location->address,
+        city    => $location->city,
+        state   => $location->state,
+    ) if $location;
+
     my %job = (
         id                  => $id,
         status              => $item->get_column('status'),
         hours_by            => $item->get_column('hours_by'),
         is_at_office        => !$item->get_column('is_telecommute'),
         contract_type       => $item->get_column('contract_type'),
+        address             => $l{address},
+        city                => $l{city},
+        state               => $l{state},
         required_attributes => $item->required_attributes,
         desired_attributes  => $item->desired_attributes,
     );

lib/PerlPro/Web/Controller/Company/Job.pm

 sub add_job :Chained('base') PathPart('job/new') Does('DisplayExecute') Args(0) {
     my ( $self, $ctx ) = @_;
 
-    if (ref $ctx->req->params->{job}) {
-        $ctx->req->params->{job}{create_or_update}{company} = $ctx->stash->{company};
-    }
-
     my $uri = $ctx->req->uri;
 
     $ctx->stash(
         template        => 'company/add_or_update_job.tx',
         current_page    => 'add_job',
         form_action_uri => "$uri",
+        is_update       => 0,
     );
 }
 
 sub add_job_display {
     my ( $self, $ctx ) = @_;
 
-    _flatten_attributes($ctx->stash->{fields});
+    my $fields = $ctx->stash->{fields} ||= {};
+
+    my $company         = $ctx->model('DB::Company')->find($ctx->stash->{company});
+    my $public_phone    = $company->company_phones->search({ is_public => 1 })->first;
+    my $public_email    = $company->company_emails->search({ is_public => 1 })->first;
+    my $public_location = $company->company_locations->search({ is_public => 1 })->first;
+
+    $fields->{'job.create_or_update.address'} = $public_location ? $public_location->address : '';
+    $fields->{'job.create_or_update.city'}    = $public_location ? $public_location->city : '';
+    $fields->{'job.create_or_update.state'}   = $public_location ? $public_location->state : '';
+
+    $fields->{'job.create_or_update.email'} = $public_email ? $public_email->email : '';
+    $fields->{'job.create_or_update.phone'} = $public_phone ? $public_phone->phone : '';
+
+    _flatten_attributes($fields);
+}
+
+sub add_job_execute {
+    my ( $self, $ctx ) = @_;
+
+    if (ref $ctx->req->params->{job}) {
+        my $p = $ctx->req->params->{job}{create_or_update};
+        $p->{company} = $ctx->stash->{company};
+        $p->{status}  = 'active';
+    }
 }
 
 sub update :Chained('item') PathPart('') Does('DisplayExecute') Args(0) GET POST {
         desired_attributes  => $fields->{'job.create_or_update.desired_attributes'},
         form_action_uri     => "$uri",
         uri_to_redirect     => [ $self->action_for('update'), [ $ctx->stash->{id} ] ],
+        is_update           => 1,
     );
 }
 

root/src/company/add_or_update_job.tx

 
 :block main_form | fif($fields) -> {
 <form action="<: $form_action_uri :>" method="post" id="jobs_form">
+
 <input type="hidden" name="job.create_or_update.id" />
 <input type="hidden" name="job.create_or_update.required_attributes" id="required_attributes_field" />
 <input type="hidden" name="job.create_or_update.desired_attributes" id="desired_attributes_field" />
     <div class="col-md-12">
         <div class="page-title">
 
+:           if ($is_update) {
             <div class="pull-right form-inline">
                 <select class="form-control" name="job.create_or_update.status">
                     <option value="active"><: $l('Vaga ativa') :></option>
                     <option value="canceled"><: $l('Vaga inativa') :></option>
                 </select>
             </div>
+:           }
 
             <h1 class="underlined"><: $l('Novo Anúncio') :></h1>
 
 </div><!-- end .row -->
 
 <div id="account-add_job" class="content">
+:   if ($messages && $messages.count()) {
+        <div class="alert alert-danger">
+            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
+            <h4><: $l('Erro ao salvar') :></h4>
+            <ul>
+:           for $messages.messages -> $message {
+                <li><: $lm($message); :></li>
+:           }
+            </ul>
+        </div>
+:   }
+:   if ($is_success) {
+        <div class="alert alert-success">
+            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
+            <h4><: $l('Dados salvos com sucesso') :></h4>
+        </div>
+:   }
+
     <div class="row">
 
         <div class="col-md-6">
             <div class="content-block">
-                <h2>Informações Básicas</h2>
+                <h2><: $l('Informações Básicas') :></h2>
                 <hr>
 
                 <div class="form-group">
 
                     <div class="form-group">
                         <label class="sr-only" for="salary">$ Valor</label>
-                        <input type="text" class="form-control" name="job.create_or_update.salary" placeholder="$ Valor">
+                        <input type="text" class="form-control" name="job.create_or_update.wages" placeholder="$ Valor">
                     </div>
 
                     <div class="form-group">&nbsp;por&nbsp;</div>
 
                     <div class="form-group">
                         <label class="sr-only" for="period">Período</label>
-                        <select name="period" class="form-control">
-                            <option>Dia</option>
-                            <option>Semana</option>
-                            <option>Mês</option>
+                        <select name="job.create_or_update.wages_for" class="form-control">
+                            <option value="project">Projeto</option>
+                            <option value="month" selected>Mês</option>
+                            <option value="week">Semana</option>
+                            <option value="day">Dia</option>
                         </select>
                     </div>
                 </div><!-- end .form-inline -->
 
          <div class="col-md-6">
             <div class="content-block">
-                <h2>Descrição</h2>
+                <h2><: $l('Descrição') :></h2>
                 <hr>
 
                 <div class="form-group">
 
         <div class="col-md-6">
             <div class="content-block">
-                <h2>Contrato &amp; Relacionamento</h2>
+                <h2><: $l('Contrato & Relacionamento') :></h2>
                 <hr>
 
                 <p>Tipo de Relacionamento</p>
 
                 <div data-toggle="buttons">
                     <label class="btn btn-danger">
-                        <input type="checkbox" name="relationship" value="clt">CLT
+                        <input type="radio" name="job.create_or_update.contract_type" value="clt">CLT
                     </label>
                     <label class="btn btn-primary">
-                        <input type="checkbox" name="relationship" value="pj">PJ
+                        <input type="radio" name="job.create_or_update.contract_type" value="pj">PJ
                     </label>
                     <label class="btn btn-success">
-                        <input type="checkbox" name="relationship" value="intern">Estágio
+                        <input type="radio" name="job.create_or_update.contract_type" value="internship">Estágio
                     </label>
                     <label class="btn btn-warning">
-                        <input type="checkbox" name="relationship" value="freelance">Freelance
+                        <input type="radio" name="job.create_or_update.contract_type" value="freelance">Freelance
                     </label>
                 </div><!-- end data-toggle -->
 
 
          <div class="col-md-6">
             <div class="content-block">
-                <h2>Local &amp; Horário</h2>
+                <h2><: $l('Local & Horário') :></h2>
                 <hr>
 
                 <span>Horário de trabalho:</span>
 
                     <div class="form-group">
                         <label class="sr-only" for="amount">Quantidade</label>
-                        <input type="text" class="form-control" name="amount" placeholder="Quantidade">
+                        <input type="text" class="form-control" name="job.create_or_update.hours" placeholder="Quantidade">
                     </div>
 
-                    <div class="form-group">
-                        <label class="sr-only" for="time">Tempo</label>
-                        <select name="time" class="form-control">
-                            <option>Horas</option>
-                            <option>Dias</option>
-                            <option>Semanas</option>
-                        </select>
-                    </div>
-
-                    <div class="form-group">&nbsp;por&nbsp;</div>
+                    <div class="form-group"> &nbsp;horas&nbsp;por&nbsp; </div>
 
                     <div class="form-group">
                         <label class="sr-only" for="period">Período</label>
-                        <select name="period" class="form-control">
-                            <option>Dia</option>
-                            <option>Semana</option>
-                            <option>Mês</option>
+                        <select name="job.create_or_update.hours_by" class="form-control">
+                            <option value="day">Dia</option>
+                            <option value="week">Semana</option>
+                            <option value="month">Mês</option>
                         </select>
                     </div>
                 </div><!-- end .form-inline -->
 
                 <br>
 
-                <div class="form-group">
-                    <label class="sr-only" for="job.create_or_update.location">Local de Trabalho</label>
-                    <input type="text" class="form-control" placeholder="Local de trabalho" name="job.create_or_update.location" />
+                <div class="form-horizontal">
+                    <div class="form-group">
+                        <label class="sr-only" for="address">Local de Trabalho</label>
+                        <div class="col-lg-12">
+                            <input type="text" class="form-control" placeholder="Local de trabalho" name="job.create_or_update.address" id="address" />
+                        </div>
+                    </div>
+
+                    <div class="form-group">
+                        <div class="col-lg-6">
+                            <input type="text" class="form-control" placeholder="Cidade" name="job.create_or_update.city" id="city" />
+                        </div>
+                        <div class="col-lg-6">
+                            <select name="job.create_or_update.state" class="form-control">
+                                <option value="">Estado</option>
+                                <option value="ac">Acre</option>
+                                <option value="al">Alagoas</option>
+                                <option value="ap">Amapá</option>
+                                <option value="am">Amazonas</option>
+                                <option value="ba">Bahia</option>
+                                <option value="ce">Ceará</option>
+                                <option value="df">Distrito Federal</option>
+                                <option value="es">Espírito Santo</option>
+                                <option value="go">Goiás</option>
+                                <option value="ma">Maranhão</option>
+                                <option value="mt">Mato Grosso</option>
+                                <option value="ms">Mato Grosso do Sul</option>
+                                <option value="mg">Minas Gerais</option>
+                                <option value="pa">Pará</option>
+                                <option value="pb">Paraíba</option>
+                                <option value="pr">Paraná</option>
+                                <option value="pe">Pernambuco</option>
+                                <option value="pi">Piauí</option>
+                                <option value="rj">Rio de Janeiro</option>
+                                <option value="rn">Rio Grande do Norte</option>
+                                <option value="rs">Rio Grande do Sul</option>
+                                <option value="ro">Rondônia</option>
+                                <option value="rr">Roraima</option>
+                                <option value="sc">Santa Catarina</option>
+                                <option value="sp">São Paulo</option>
+                                <option value="se">Sergipe</option>
+                                <option value="to">Tocantins</option>
+                            </select>
+                        </div>
+                    </div>
                 </div>
 
                 <div class="form-group">
                     <div class="checkbox">
                         <label>
-                            <input type="checkbox"name="job.create_or_update.is_at_office" value="1"> Presença obrigatória
+                            <input type="checkbox" name="job.create_or_update.is_at_office" value="1"> Presença obrigatória
                         </label>
                     </div>
                 </div>
 
             </div><!-- end .content-block -->
         </div><!-- end .col-md-6 -->
-
     </div><!-- end .row -->
+</div><!-- end account-add_job -->
+
+</form>
+: }
+
     <div class="row">
 
         <div class="col-md-6">
             <div class="content-block">
-                <h2>Requisitos Obrigatórios</h2>
+                <h2><: $l('Requisitos obrigatórios') :></h2>
                 <hr>
 
                 <p>Necessário conhecimentos em:</p>
 
-                <div class="input-group">
-                    <label class="sr-only" for="requirements">Requisitos obrigatórios</label>
-                    <input type="text" placeholder="Digite separado por vírgula" name="requirements" class="form-control"/>
+                <form class="requirements">
+                <div class="input-group add_requirements">
+                    <label class="sr-only" for="required_attributes">Requisitos obrigatórios</label>
+                    <input type="text" placeholder="Digite separado por vírgula" id="required_attributes" class="form-control"/>
                     <span class="input-group-btn">
-                        <input type="button" class="btn btn-warning add_tags" value="Adicionar"/>
+                        <button type="submit" class="btn btn-warning">Adicionar</button>
                     </span>
                 </div><!-- end .input-group -->
 
-                <ul class="requirements"></ul>
+                <ul class="requirements required_attributes">
+:               for $required_attributes -> $attr {
+                    <li><: $attr :> <a href="#" class="remove-requirement"><i class="icon-remove-sign"></i></a></li>
+:               }
+                </ul>
+                </form>
 
             </div><!-- end .content-block -->
         </div><!-- end .col-md-6 -->
 
          <div class="col-md-6">
             <div class="content-block">
-                <h2>Não obrigatório, mas desejável</h2>
+                <h2><: $l('Não obrigatório, mas desejável') :></h2>
                 <hr>
 
                 <p>Desejável conhecimentos em:</p>
 
-                <div class="input-group">
-                    <label class="sr-only" for="desirable">Requisitos desejaveis</label>
-                    <input type="text" placeholder="Digite separado por vírgula" name="desirable" class="form-control"/>
+                <form class="requirements">
+                <div class="input-group add_requirements">
+                    <label class="sr-only" for="desired_attributes">Requisitos desejaveis</label>
+                    <input type="text" placeholder="Digite separado por vírgula" id="desired_attributes" class="form-control"/>
                     <span class="input-group-btn">
-                        <input type="button" class="btn btn-warning add_tags" value="Adicionar"/>
+                        <button type="submit" class="btn btn-warning">Adicionar</button>
                     </span>
                 </div><!-- end .input-group -->
 
-                <ul class="requirements"></ul>
+                <ul class="requirements desired_attributes">
+:               for $desired_attributes -> $attr {
+                    <li><: $attr :> <a href="#" class="remove-requirement"><i class="icon-remove-sign"></i></a></li>
+:               }
+                </ul>
+                </form>
             </div><!-- end .content-block -->
         </div><!-- end .col-md-6 -->
 
         </div>
 
     </div><!-- end .row -->
-</div><!-- end account-add_job -->
 
 
 : }
-: }

root/src/company/my_jobs.tx

                         </tr>
                     </thead>
                     <tbody>
-                :       for $jobs -> $j {
+:                       for $jobs -> $j {
                         <tr>
                             <td><input type="checkbox" name=""/></td>
-                            <td><strong><: $j.title :></strong> @ <: $j.location :></td>
-                :           if $j.status == 'active' {
+                            <td><strong><: $j.title :></strong><: if $j.location { ' @ '; $j.location; } :></td>
+:                           if $j.status == 'active' {
                             <td class="active">Ativo</td>
-                :           } else {
+:                           } else {
                             <td class="inactive">Inativo</td>
-                :           }
+:                           }
                             <td><: $j.created_at.strftime('%d.%m') :></td>
                             <td>
-                                <a href="#"><span class="glyphicon glyphicon-pencil"></span></a>&nbsp;
-                                <a href="#"><span class="glyphicon glyphicon-trash"></span></a>
+                                <a href="<: $uri('/account/job/' ~ $j.id) :>"><span class="glyphicon glyphicon-pencil"></span></a>&nbsp;
+                                <a href="#" class="remove" data-job-id="<: $j.id :>"><span class="glyphicon glyphicon-trash"></span></a>
                             </td>
                         </tr>
-                :       }
+:                       }
                     </tbody>
                 </table>
 

root/src/company/wrapper.tx

 
         <script src="//code.jquery.com/jquery-1.10.1.min.js"></script>
         <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
-        <script src="<: $static_uri :>/js/main.js"></script>
+        <script src="<: $static_uri :>/js/company.js"></script>
 
     </body>
 </html>

root/src/public/job/view.tx

 :                       for $c.websites -> $website {
                             <li><span class="glyphicon glyphicon-globe"></span> <: $website :></li>
 :                       }
+:                       for $c.phones -> $phone {
+                            <li><span class="glyphicon glyphicon-earphone"></span> <: $phone :></li>
+:                       }
 :                       for $c.emails -> $email {
                             <li><span class="glyphicon glyphicon-envelope"></span> <: $email :></li>
 :                       }
                     </ul>
 
-                    <a href="#" class="btn btn-danger"><: $l('Ver mais') :></a>
+                    <a href="<: $uri('/company/' ~ $c.name_in_url) :>" class="btn btn-danger"><: $l('Ver mais') :></a>
                 </div>
 
                 <div class="clearfix"></div>
 
                 <!--iframe width="100%" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=CZmK8f958A74FQBZKAIdv17U-ik_ePT84GdkiDH0UAfsfeodrg&amp;q=2511+Gallatin+Ave,+Nashville&amp;aq=&amp;sll=36.195542,-86.742978&amp;sspn=0.009386,0.021136&amp;ie=UTF8&amp;hq=&amp;hnear=2511+Gallatin+Ave,+Nashville,+Davidson,+Tennessee+37206&amp;ll=36.195542,-86.742983&amp;spn=0.150156,0.338173&amp;t=m&amp;z=12&amp;output=embed"></iframe-->
 
-:               if $c.formatted_address {
-                <p><span class="glyphicon glyphicon-map-marker"></span> <: $c.formatted_address :></p>
+:               if $j.city || $j.state || $j.address {
+                <p><span class="glyphicon glyphicon-map-marker"></span> <: if $j.address { $j.address; ', '; } $j.city ~ ' - ' ~ $j.state :></p>
 :               } else {
                 <p><: $l('Não especificado.') :></p>
 :               }
 
     <!-- related jobs -->
     <div class="row">
-        <div class="col-md-6">
+        <!--div class="col-md-6">
             <h3 class="underlined"><: $l('Vagas similares') :></h3>
             <ul class="job-list">
                 <li>
                     <span class="city-name">Campinas</span>
                 </li>
             </ul>
-        </div>
+        </div-->
 
         <div class="col-md-6">
 :           if $c.other_jobs.size() {
-            <h3 class="underlined"><: $l('Mais vagas em ') :> <a href="#"><: $c.name :></a></h3>
+            <h3 class="underlined"><: $l('Mais vagas em ') :> <a href="<: $uri('/company/' ~ $c.name_in_url) :>"><: $c.name :></a></h3>
             <ul class="job-list">
 :               for $c.other_jobs -> $oj {
                 <li>

root/static/js/company.js

         return false;
     });
 
-    $('table.my_jobs td.remove a').click(function () {
+    $('table.my_jobs td a.remove').click(function () {
         window.about_to_be_removed = $(this).data('job-id');
         $('#remove_job_modal').modal('show');
         return false;
     var timeout;
     var last;
 
+    /*
     $("#job_location_search").typeahead({
         source: function (query, process) {
             if (query === last) {
             return item;
         }
     });
+    */
 });