Ignore:
Timestamp:
04/29/15 20:24:15 (9 years ago)
Author:
nanardon
Message:

Merge branch 'jquery'

Location:
trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts
Files:
5 added
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web.pm

    r1302 r1329  
    5151    objects => { 
    5252        user => { 
    53             quick_search => [ qw(cn sn givenName) ], 
     53            quick_search => [ qw(cn sn givenName description) ], 
    5454            list => [ qw(sn givenName mail) ], 
    5555        }, 
     
    5959        }, 
    6060        nethost => { 
    61             quick_search => [ qw(cn description ip cname otherName) ], 
     61            quick_search => [ qw(cn description ip cname otherName macaddr serialNumber) ], 
    6262            list => [ qw(description owner) ], 
    6363        }, 
     
    301301        related => { 
    302302            label => 'Voir aussi:', 
     303        }, 
     304        SerialNumber => { 
     305            label => 'Numéro de série', 
    303306        }, 
    304307    }, 
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Ajax.pm

    r1193 r1329  
    5151    my $attribute = $c->model('Accounts')->db->attribute($otype, $attr) or return; 
    5252    $c->stash->{value} = $attribute->display($c->req->param('id')); 
    53 } 
    54  
    55 sub attrvalues : Local { 
    56     my ($self, $c, $otype, $attr) = @_; 
    57  
    58     my $base = $c->model('Accounts')->db; 
    59     my $val = $c->req->param('val') || ''; 
    60     $c->stash->{values} = [ 
    61         sort 
    62         grep { /^\Q$val\E/ } $base->attributes_summary($otype, $attr) 
    63     ]; 
    64  
    6553} 
    6654 
     
    207195} 
    208196 
    209 sub search_adv : Local { 
    210     my ($self, $c) = @_; 
    211     $c->stash->{db} = $c->model('Accounts')->db; 
    212     $c->stash->{otype} = $c->req->param('otype'); 
    213 } 
    214  
    215197sub end : Private { 
    216198    my ( $self, $c ) = @_; 
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Json.pm

    r1328 r1329  
    1 package LATMOS::Accounts::Web::Controller::Search::Adv; 
     1package LATMOS::Accounts::Web::Controller::Json; 
    22use Moose; 
    33use namespace::autoclean; 
     
    77=head1 NAME 
    88 
    9 LATMOS::Accounts::Web::Controller::Search::Adv - Catalyst Controller 
     9LATMOS::Accounts::Web::Controller::Json - Catalyst Controller 
    1010 
    1111=head1 DESCRIPTION 
     
    2525    my ( $self, $c ) = @_; 
    2626 
    27     $c->stash->{db} = $c->model('Accounts')->db; 
     27    $c->response->body('Matched LATMOS::Accounts::Web::Controller::Json in Json.'); 
    2828} 
    2929 
     30sub end : Private { 
     31    my ( $self, $c ) = @_; 
     32    $c->forward($c->view('Json')); 
     33} 
     34 
     35=encoding utf8 
    3036 
    3137=head1 AUTHOR 
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Search/Adv.pm

    r1191 r1329  
    2626 
    2727    $c->stash->{db} = $c->model('Accounts')->db; 
     28 
     29    if ($c->req->param('otype')) { 
     30        $c->session->{searchOtype} = $c->req->param('otype'); 
     31    } elsif ($c->req->param('attr')) { 
     32        push(@{$c->session->{searchValues}}, sprintf('%s~%s', $c->req->param('attr'), $c->req->param('attrval'))); 
     33    } elsif ($c->req->param('delval')) { 
     34        my @delvals = $c->req->param('delval'); 
     35        my @newvals = (); 
     36        foreach my $v (@{$c->session->{searchValues} || []}) { 
     37            grep { $_ eq $v } @delvals and next; 
     38            push(@newvals, $v); 
     39        } 
     40        $c->session->{searchValues} = \@newvals; 
     41    } elsif(grep { $_ && $_ eq 'new' } $c->req->query_keywords) { 
     42        $c->session->{searchOtype} = undef; 
     43        $c->session->{searchValues} = []; 
     44    } 
     45     
     46    if ($c->session->{searchOtype}) { 
     47        $c->stash->{objs} = [ $c->stash->{db}->search_objects( 
     48            $c->session->{searchOtype}, 
     49            @{ $c->session->{searchValues} || []}, 
     50        ) ]; 
     51    } 
     52 
    2853} 
    2954 
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Model/AttrForms.pm

    r1305 r1329  
    9797            unexported 
    9898            description 
     99            facsimileTelephoneNumber 
    99100        ) ], 
    100101    }, 
     
    217218    $new->{base} = $base || (ref $object ? $object->base : undef) or return $self; 
    218219    $new->{otype} = ref $object ? $object->type : $object; 
     220 
     221 
     222    foreach (@{ $forms->{$form}->{attrs} }) { 
     223        $new->{_attr}{$_} = $c->model('AttrFormsA', $_, ($object 
     224                ? ($object) 
     225                : ($base, $new->{otype}))) 
     226            or die "Cannot get attribute $_"; 
     227    } 
     228 
    219229    bless($new, __PACKAGE__); 
    220230} 
     
    240250    grep { $self->base->attribute($self->otype, $_) } 
    241251    @{ $forms->{$self->{form}}->{attrs} }; 
    242 } 
    243  
    244 sub attr_label { 
    245     my ($self, $attr, $label, $hint) = @_; 
    246     $label ||= ''; 
    247     $hint ||= ''; 
    248     LATMOS::Accounts::Web->config->{attrs} ||= {}; 
    249     my $attribute = $self->base->attribute($self->otype, $attr); 
    250     my $htmlname = $self->escape($self->attr_field_name($attr)); 
    251     if (my $attr_config = LATMOS::Accounts::Web->config->{attrs}{$attr}) { 
    252         $label ||= $attr_config->{label} || ''; 
    253         #utf8::is_utf8($label) && utf8::encode($label); 
    254         $hint ||= $attr_config->{hint} || ''; 
    255         #utf8::is_utf8($hint) && utf8::encode($hint); 
    256     } 
    257     return sprintf('<label %sfor="%s">%s</label>', 
    258         ($hint ? sprintf('title="%s"', $self->escape($hint)) : ''), 
    259         $self->escape($htmlname), 
    260         $self->escape($label || $attr), 
    261     ); 
    262 } 
    263  
    264 sub attr_hint { 
    265     my ($self, $attr) = @_; 
    266     LATMOS::Accounts::Web->config->{attrs} ||= {}; 
    267     if (my $attr_config = LATMOS::Accounts::Web->config->{attrs}{$attr}) { 
    268         return $attr_config->{hint} || ''; 
    269     } 
    270     return; 
    271 } 
    272  
    273 sub attr_raw_value { 
    274     my ($self, $attribute) = @_; 
    275     my @val = grep { $_ }   
    276         ($self->{c}->req->param($attribute->name)) 
    277         || ($self->{object} 
    278             ? ($self->{object}->get_attributes($attribute->name)) 
    279             : ()); 
    280  
    281     if (@val) { 
    282         return @val; 
    283     } else { 
    284         return (grep { $_ } ($attribute->default_value)) 
    285     } 
    286 } 
    287  
    288 sub attr_field_name { 
    289     my ($self, $attr) = @_; 
    290     my $id = $self->{object} 
    291         ? ($self->{object}->id || '') 
    292         : ''; 
    293     $id .= '_' if ($id); 
    294     $id =~ s/\./_/g; 
    295     $id =~ s/-/_/g; 
    296     $id . $attr; 
    297 } 
    298  
    299 sub attr_item { 
    300     my ($self, $attribute, $value, $htmlid) = @_; 
    301  
    302     my $html = $self->_attr_item($attribute, $value, $htmlid); 
    303      
    304     if ($attribute->uniq) { 
    305         $html .= qq|<span class="inputvalidate" id="${htmlid}_uniq"></span>|; 
    306     } 
    307     if (my $ref = $attribute->reference) { 
    308         my $uri_part = $self->_uri_part($ref); 
    309         if ($self->base->attribute($ref, 'displayName')) { 
    310             my $text = ''; 
    311             if ($value && 
    312                 (my $obj = $self->base->get_object($ref, $value))) { 
    313                 $text = $obj->get_attributes('displayName'); 
    314             } 
    315             $html .= sprintf( 
    316                 qq|<span id="${htmlid}_ref" style="margin-left: 1em">$text</span>|, 
    317                 $self->escape($text), 
    318             ); 
    319         } elsif($value && $uri_part) { 
    320             $html .= sprintf( 
    321                 '<a href="%s"><img class="attr" src="%s" title="%s"></a>', 
    322                 $self->{c}->uri_for('/', $uri_part, $value), 
    323                 $self->{c}->uri_for('/static', 'images', 'arrow-right.png'), 
    324                 $value, 
    325             ); 
    326         } 
    327     } 
    328  
    329     $html 
    330 } 
    331  
    332 sub _attr_item { 
    333     my ($self, $attribute, $value, $htmlid) = @_; 
    334  
    335     my $htmlname = $self->escape($self->attr_field_name($attribute->name)); 
    336     $htmlid ||= $htmlname; 
    337  
    338     for ($attribute->form_type) { 
    339             /^textarea$/i and do { 
    340                 return sprintf( 
    341                     '<textarea id="%s" name="%s" cols="40">%s</textarea>', 
    342                     $self->escape($htmlid), 
    343                     $self->escape($htmlname), 
    344                     $self->escape($value || ''), 
    345                 ); 
    346                 last; 
    347             }; 
    348  
    349             /^label$/i and do { 
    350                 $value or last; 
    351                 my $html_field = $self->escape($value); 
    352                 $html_field =~ s/\n/<br>/g; 
    353                 $html_field .= sprintf('<input type="hidden" name="%s" value="%s">', 
    354                     $self->escape($htmlname), ($value || '')); 
    355                 return $html_field; 
    356                 last; 
    357             }; 
    358  
    359             /^date$/i and do { 
    360                 my ($date, $time) = split(/ /, $value || ''); 
    361                 if ($date && $date =~ /^(\d+)-(\d+)-(\d+)$/) { 
    362                     $date = "$3/$2/$1"; 
    363                 } 
    364                 my $html = "\n" . q{<SCRIPT LANGUAGE="JavaScript" ID="js13"> 
    365                 var cal13 = new CalendarPopup(); 
    366                 </SCRIPT>} . "\n"; 
    367                 $html .= sprintf( 
    368                     '<input type="text" id="%s" name="%s" value="%s" size="12">', 
    369                     $self->escape($htmlid), 
    370                     $self->escape($htmlname), 
    371                     $self->escape($date) 
    372                 ); 
    373                 $html .= q{<DIV ID="testdiv1" STYLE="position:absolute;visibility:hidden;background-color:white;layer-background-color:white;"></DIV>}; 
    374                 $html .= qq| 
    375                 <A HREF="#" 
    376                     onClick="cal13.select(document.getElementById('$htmlid'),'${htmlid}_anc','dd/MM/yyyy');return false;" 
    377                     TITLE="Date" 
    378                     NAME="${htmlid}_anc" ID="${htmlid}_anc"> 
    379                     <img class="attr" src="| . $self->{c}->uri_for(qw(/static images view-calendar-day.png)) 
    380                     . qq{" style="ref"></A> 
    381                     } . "\n"; 
    382                 return $html; 
    383                 last; 
    384             }; 
    385  
    386             /^checkbox/i and do { 
    387                 my $options = $1 || ''; 
    388                 my $html = sprintf('<input type="checkbox" id="%s" name="%s"%s>', 
    389                     $htmlid, 
    390                     $self->escape($htmlname), 
    391                     $value ? '  checked="yes"' : '' 
    392                 );  
    393                 $html .= sprintf('<input type="hidden" name="%s">', 
    394                     $self->escape($htmlname)); 
    395                 if ($attribute->form_option('rawvalue')) { 
    396                     $html .= $value 
    397                         ? ' ' . $value 
    398                         : '';  
    399                 } 
    400                 return $html; 
    401                 last; 
    402             }; 
    403  
    404             /^LIST/i and do { 
    405                 my $select = sprintf('<select id="%s" name="%s">', 
    406                     $self->escape($htmlid), 
    407                     $self->escape($htmlname)) . "\n"; 
    408                 $select .= '<option value="">--</option>' . "\n" 
    409                     unless($attribute->mandatory); 
    410                 $value ||= ''; 
    411                 my $initial_observed = ''; 
    412                 my @valslist; 
    413                 foreach my $val (sort $attribute->can_values) { 
    414                     push(@valslist, { 
    415                         val => $val, 
    416                         disp => $attribute->display($val || ''), 
    417                     }); 
    418                 } 
    419                 foreach (sort { $a->{disp} cmp $b->{disp} } @valslist) { 
    420                     $select .= sprintf( 
    421                         '    <option value="%s"%s>%s</option>', 
    422                         $self->escape($_->{val} || ''), 
    423                         $value eq $_->{val} ? ' selected="selected"' : '', 
    424                         $self->escape($_->{disp} || ''), 
    425                     ); 
    426                     $select .= "\n"; 
    427                 } 
    428                 $select .= "</select>\n"; 
    429  
    430                 return $select; 
    431                 last; 
    432             }; 
    433  
    434             /^text/i and do { 
    435                 return sprintf( 
    436                     '<input type="text" id="%s" name="%s" value="%s" size="%d">', 
    437                     $self->escape($htmlid), 
    438                     $self->escape($htmlname), 
    439                     $self->escape($value), 
    440                     $attribute->form_option('length') || 30, 
    441                 ); 
    442                 last; 
    443             }; 
    444         } 
    445     return ''; 
    446252} 
    447253 
     
    458264} 
    459265 
    460 sub attr_js { 
    461     my ($self, $attribute, $value, $htmlid) = @_; 
    462  
    463     my (@js); 
    464  
    465     if (my $ref = $attribute->reference) { 
    466         my $uri_part = $self->_uri_part($ref); 
    467         if ($self->base->attribute($ref, 'displayName')) { 
    468             push(@js,  
    469                 $self->{c}->prototype->observe_field( $htmlid, 
    470                     { 
    471                         update => "${htmlid}_ref", 
    472                         url => $self->{c}->uri_for('/ajax', 'rawattr', $ref), 
    473                         frequency => 1, 
    474                         with   => "'attr=displayName&id=' + element.options[element.selectedIndex].text", 
    475                     } 
    476                 ) 
    477             ) if ($attribute->form_type =~ /list/i); 
    478         } 
    479     } 
    480  
    481     if ($attribute->uniq) { 
    482         push(@js, 
    483             $self->{c}->prototype->observe_field( $htmlid, 
    484                 { 
    485                     update => "${htmlid}_uniq", 
    486                     url => $self->{c}->uri_for('/ajax', 'objattrexist', 
    487                         $self->otype, $attribute->name), 
    488                     frequency => 1, 
    489                     with => "'val='+element.value" . 
    490                     ($self->{object} ? 
    491                         "+'&exclude=" . ($self->{object}->id || '') . "'"  
    492                         : ''), 
    493                 } 
    494             ) 
    495         ); 
    496     } 
    497  
    498     return(join("\n", @js)); 
     266sub attr_label { 
     267    my ($self, $attr, $label, $hint) = @_; 
     268 
     269    if ($label) { 
     270        return $label; 
     271    } elsif (my $hash = LATMOS::Accounts::Web->config->{attrs}{$attr}) { 
     272        return $hash->{label}; 
     273    } else { 
     274       retrun $attr; 
     275    }  
     276} 
     277 
     278sub attr_hint { 
     279    my ($self, $attr) = @_; 
     280 
     281    $self->{_attr}{$attr}->attr_hint; 
    499282} 
    500283 
     
    502285    my ($self, $attr, $type) = @_; 
    503286 
    504     my $attribute; 
    505     if ($type) { 
    506         if (ref $type) { 
    507             $attribute = $self->base->attribute( 
    508                 $self->otype, 
    509                 { %$type, name => $attr }, 
    510             ); 
    511         } else { 
    512             $attribute =  $self->base->attribute( 
    513                 $self->otype, 
    514                 { formtype => $type , name => $attr }, 
    515             ); 
    516         } 
    517     } else { 
    518         if ($self->{object}) { 
    519             $attribute = $self->{object}->attribute($attr); 
    520         } else { 
    521             $attribute = $self->base->attribute( 
    522                 $self->otype, $attr, 
    523                 { formtype => $type } 
    524             ); 
    525         } 
    526     } 
    527     $attribute ||= $self->base->attribute($self->otype, { name => $attr }); 
    528  
    529  
    530     my $htmlname = $self->escape($self->attr_field_name($attr)); 
    531  
    532     my @html_fields; 
    533  
    534     # Force Array context: 
    535     my @attr_raw_value = (); 
    536  
    537     if ($attribute->multiple) { 
    538         @attr_raw_value = grep { $_ } $self->attr_raw_value($attribute); 
    539     } else { 
    540         my ($val) = $self->attr_raw_value($attribute); 
    541         @attr_raw_value = ($val || ''); 
    542     } 
    543  
    544     foreach my $attr_raw_value (@attr_raw_value) { 
    545  
    546         my $html_id = $htmlname . 
    547             (scalar(@html_fields) ? scalar(@html_fields) : ''); 
    548         push(@html_fields, 
    549             join("\n", 
    550                 $self->attr_item( 
    551                     $attribute, $attr_raw_value, $html_id 
    552                 ), 
    553                 $self->attr_js( 
    554                     $attribute, $attr_raw_value, $html_id 
    555                 ) 
    556             ) 
    557         ); 
    558     } 
    559  
    560     if ($attribute->{multiple} && !$attribute->readonly) { 
    561         my $html_id = $htmlname . '_m_SUBID'; 
    562  
    563         my $attr = $self->attr_item($attribute, '', $html_id); 
    564         # JS: string are on the line only 
    565         $attr =~ s/\n//mg; 
    566         $attr =~ s/'/\'/g; 
    567  
    568         my $js = $self->attr_js($attribute, '', 'NANAR'); 
    569         $js =~ s!'NANAR([_\w]*)'!('$html_id$1'.replace(/SUBID/g, cn))!gm; 
    570         $js =~ s!<script[^>]+>!!gm; 
    571         $js =~ s!</script>!!gm; 
    572         $js =~ s!-->!!gm; 
    573         $js =~ s/<!--//gm; 
    574  
    575         my $addempty = sprintf('<div id="%s"></div>', "${htmlname}_div_0"); 
    576         $addempty .= "\n"; 
    577         $addempty .= sprintf(qq# 
    578             <script type="text/javascript"> 
    579             var cn_${htmlname} = 0; 
    580             function add_${htmlname} () { 
    581             cn_${htmlname}++; 
    582             // It work only using temporary variable 
    583             var cn = cn_${htmlname}; 
    584             document.getElementById('${htmlname}_div_' + (cn - 1)).innerHTML += 
    585                 '$attr'.replace(/SUBID/g, cn ); 
    586             document.getElementById('${htmlname}_div_' + (cn - 1)).innerHTML += 
    587                 '<div id="${htmlname}_div_'+ cn +'" style="display:block"></div>'; 
    588             %s 
    589             } 
    590             </script> 
    591             #, $js 
    592         ); 
    593  
    594         $addempty .= "\n"; 
    595         $addempty .= 
    596             qq|<button type="button" style="display:block" onclick="add_${htmlname}()">+</button>|, 
    597  
    598         push(@html_fields, $addempty); 
    599     } 
    600  
    601     return join("<br>\n", @html_fields); 
    602 } 
    603  
    604 sub submit { 
    605     my ($self) = @_; 
    606     return sprintf( 
    607         '<input type="submit" name="%s" value="Enregistrer">', 
    608         $self->escape($self->label), 
    609     ); 
    610 } 
     287    $self->{_attr}{$attr}->attr_field($type); 
     288} 
     289 
    611290 
    612291sub write_attributes { 
    613292    my ($self) = @_; 
    614293    my @attrs; 
    615     foreach ($self->attributes) { 
    616         my $attr = ($self->{object} 
    617             ? $self->{object}->attribute($_) 
    618             : $self->base->attribute($self->otype, $_)) or next; 
    619         $attr->readonly and next; 
     294    foreach (values %{ $self->{_attr} }) { 
     295        $_->readonly and next; 
    620296        push(@attrs, $_); 
    621297    } 
     
    626302    my ($self, $attrs) = @_; 
    627303    $self->{c}->req->param($self->label) || $attrs or return; 
    628     my $prefix = $self->attr_field_name(''); 
    629304    my %fields; 
    630305    foreach ($attrs ? @{ $attrs } : $self->write_attributes) { 
    631         my $attr = ($self->{object} 
    632             ? $self->{object}->attribute($_) 
    633             : $self->base->attribute($self->otype, $_)) or next; 
     306        my $attr = ref $_ ? $_ : $self->{_attr}{$_}; 
    634307        if ($attr->{multiple}) { 
    635             $fields{$_} = [ grep { $_ } $self->{c}->req->param("$prefix$_") ]; 
     308            $fields{$attr->name} = [ grep { $_ } $self->{c}->req->param($attr->htmlname) ]; 
    636309        } else { 
    637             $fields{$_} = $self->{c}->req->param("$prefix$_"); 
     310            $fields{$attr->name} = $self->{c}->req->param($attr->htmlname); 
    638311        } 
    639312    } 
     
    647320} 
    648321 
     322sub submit { 
     323    my ($self) = @_; 
     324    return sprintf( 
     325        '<input type="submit" name="%s" value="Enregistrer">', 
     326        $self->escape($self->label), 
     327    ); 
     328} 
     329 
     330 
    649331=head1 AUTHOR 
    650332 
Note: See TracChangeset for help on using the changeset viewer.