Revision 523
- Date:
- 2015/11/03 18:33:17
- Files:
Legend:
- Added
- Removed
- Modified
-
utf8/plugins/users/comps/contenido/ajax/credential_phone_valid.html
1 <% $json %> 2 <%once> 3 4 use JSON::XS; 5 6 </%once> 7 <%args> 8 9 $id => undef 10 $phone => undef 11 12 </%args> 13 <%init> 14 15 my %result; 16 if ( $phone ) { 17 if ( $keeper->{users}->_phone_format( $phone ) ) { 18 my $phone_r = $keeper->{users}->_phone_reduction( $phone ); 19 if ( $id && $id =~ /^\d+$/) { 20 my $object = $keeper->{users}->get_profile( id => $id ); 21 if ( ref $object ) { 22 my ($cred) = $keeper->get_documents( 23 name => $phone_r, 24 class => 'users::Phone', 25 limit => 1, 26 ); 27 if ( ref $cred && $cred->uid != $object->id ) { 28 $result{error} = 'Phone already registered for another user'; 29 } 30 } else { 31 $result{error} = 'User not found'; 32 } 33 } else { 34 $result{error} = 'User ID is not valid or not defined'; 35 } 36 } else { 37 $result{error} = 'Phone is not valid'; 38 } 39 } else { 40 $result{nothing} = 1; 41 } 42 $result{ok} = 1 unless exists $result{error} || exists $result{nothing}; 43 44 my $json = encode_json \%result; 45 46 </%init> -
utf8/plugins/users/comps/contenido/components/inputs/phones.msn
1 % if ( $state->{users}->use_credentials && $object->id ) { 2 <script type="text/javascript"> 3 <!-- 4 function check_<% $name %>_valid( nID ){ 5 } 6 7 $(document).ready(function(){ 8 9 % foreach my $cred ( @credentials ) { 10 $('#<% $name %>_name_<% $cred->id %>_text').focusout(function(){ 11 var oPhone = $(this); 12 $.get('/contenido/ajax/credential_phone_valid.html', { 'id' : '<% $object->id %>', 'phone' : $(oPhone).val() }, function(data){ 13 if ( data.error ) { 14 $('#<% $name %>_<% $cred->id %>_check').attr('title', data.error).html('<span style="color:red">Error</span>'); 15 } else { 16 $('#<% $name %>_<% $cred->id %>_check').attr('title', '').html('<span style="color:green">Ok</span>'); 17 } 18 }, 'json'); 19 }); 20 % } 21 22 $('#<% $name %>_name__text').focusout(function(){ 23 var oPhone = $(this); 24 $.get('/contenido/ajax/credential_phone_valid.html', { 'id' : '<% $object->id %>', 'phone' : $(oPhone).val() }, function(data){ 25 if ( data.error ) { 26 $('#<% $name %>_new_check').attr('title', data.error).html('<span style="color:red">Error</span>'); 27 } else if ( data.nothing ) { 28 $('#<% $name %>_new_check').attr('title', '').html(''); 29 } else { 30 $('#<% $name %>_new_check').attr('title', '').html('<span style="color:green">Ok</span>'); 31 } 32 }, 'json'); 33 }); 34 35 }); 36 //--> 37 </script> 38 <div style="border:1px solid gray; padding:2px; width:95%;"> 39 <table width="100%" cellpadding="5" cellspacing="0"> 40 <tr bgcolor="white"> 41 <th>Main</th> 42 <th>Телефон</th> 43 <th></th> 44 <th>Активен</th> 45 <th>Удалить</th> 46 <th></th> 47 </tr> 48 % foreach my $cred ( @credentials ) { 49 % my $checked = $cred->main ? ' checked' : ''; 50 % my $bgcolor = $i++ % 2 ? 'white' : '#e0e0e0'; 51 % my $active = $cred->status == 1 ? ' checked' : ''; 52 <tr bgcolor="<% $bgcolor %>"> 53 <td width="1%"><input type="radio" name="<% $name %>.main" value="<% $cred->id %>"<% $checked %>></td> 54 <td width="86%"><& /contenido/components/inputs/string.msn, name => $name.'_name_'.$cred->id, prop => $prop, check => $cred->name, object => $object &></td> 55 <td width="10%"><& /contenido/components/inputs/string.msn, name => $name.'_name_'.$cred->id, prop => $prop, check => $cred->name_orig, object => $object &></td> 56 <td width="1%"><input type="checkbox" name="<% $name %>_active_<% $cred->id %>" value="1"<% $active %>></td> 57 <td width="1%"><input type="checkbox" name="<% $name %>.delete" value="<% $cred->id %>"></td> 58 <td width="1%" id="<% $name %>_<% $cred->id %>_check"><span style="color:green">Ok</span></td> 59 </tr> 60 % } 61 <tr bgcolor="<% $i++ % 2 ? 'white' : '#e0e0e0' %>"> 62 <td><input type="radio" name="<% $name %>.main" value=""></td> 63 <td><& /contenido/components/inputs/string.msn, name => $name.'_name_', prop => $prop, check => '', object => $object &></td> 64 <td></td> 65 <td><input type="checkbox" name="<% $name %>_active_" value="1"></td> 66 <td></td> 67 <td id="<% $name %>_new_check"></td> 68 </tr> 69 </table> 70 </div> 71 % } else { 72 <& /contenido/components/inputs/string.msn, %ARGS &> 73 % } 74 <%args> 75 76 $name => undef 77 $check => undef 78 $prop => {} 79 $object => undef 80 81 </%args> 82 <%init> 83 84 my @credentials; 85 if ( $state->{users}->use_credentials ) { 86 @credentials = $keeper->get_documents( 87 class => 'users::Phone', 88 uid => $object->id, 89 order_by => 'main desc, name', 90 ); 91 } 92 my $i = 0; 93 94 </%init> -
utf8/plugins/users/comps/contenido/components/outputs/phones.msn
1 <%args> 2 3 $object 4 $name => undef 5 $SETS => undef 6 7 </%args> 8 <%init> 9 10 return undef unless ref $SETS; 11 return undef unless $name; 12 13 my @props = $object->structure(); 14 my ($prop) = grep { $_->{attr} eq $name } @props; 15 return undef unless ref $prop; 16 17 if ( $state->{users}->use_credentials && $object->id ) { 18 my %struct; 19 while ( my ($key, $val) = each %$SETS ) { 20 my $template = $name.'_name_'; 21 if ( $key =~ /^$template/ ) { 22 my $id = $key =~ /(\d+)/ ? $1 : 'new'; 23 if ( $keeper->{users}->_phone_format( $val ) ) { 24 $struct{$id}{orig} = $val; 25 $struct{$id}{name} = $keeper->{users}->_phone_reduction($val); 26 $struct{$id}{format} = $keeper->{users}->_phone_format($val); 27 $struct{$id}{id} = $id; 28 } 29 } 30 $template = $name.'_active_'; 31 if ( $key =~ /^$template/ ) { 32 my $id = $key =~ /(\d+)/ ? $1 : 'new'; 33 if ( $val ) { 34 $struct{$id}{status} = 1; 35 $struct{$id}{id} = $id; 36 } 37 } 38 } 39 if ( exists $SETS->{$name.'.delete'} ) { 40 if ( ref $SETS->{$name.'.delete'} eq 'ARRAY' ) { 41 map { $struct{$_}{delete} = 1 } @{$SETS->{$name.'.delete'}}; 42 } elsif ( $SETS->{$name.'.delete'} ) { 43 $struct{$SETS->{$name.'.delete'}}{delete} = 1; 44 } 45 } 46 if ( exists $SETS->{$name.'.main'} && $SETS->{$name.'.main'} && exists $struct{$SETS->{$name.'.main'}} && !exists $struct{$SETS->{$name.'.main'}}{delete} ) { 47 $struct{$SETS->{$name.'.main'}}{main} = 1; 48 } elsif ( exists $struct{new} ) { 49 $struct{new}{main} = 1; 50 } else { 51 my @main = grep { exists $_->{name} && exists $_->{main} && $_->{main} && !exists $_->{delete} } values %struct; 52 unless ( @main ) { 53 my @valid = grep { exists $_->{name} && !exists $_->{delete} } values %struct; 54 if ( @valid ) { 55 $valid[0]->{main} = 1; 56 } 57 } 58 } 59 my @delete_ids = map { $_->{id} } grep { $_->{id} && exists $_->{delete} } values %struct; 60 if ( @delete_ids ) { 61 my $sql = $keeper->SQL->prepare('delete from profile_credentials where class = ? and uid = ? and id in ('.join(',', map {'?'} @delete_ids).')'); 62 $sql->execute( 'users::Phone', $object->id, @delete_ids ); 63 $sql->finish; 64 } 65 my @credentials = $keeper->get_documents( 66 class => 'users::Phone', 67 uid => $object->id, 68 order_by => 'main desc, name', 69 ); 70 foreach my $cred ( @credentials ) { 71 my $check = exists $struct{$cred->id} ? $struct{$cred->id} : undef; 72 my $store = 0; 73 if ( ref $check && exists $check->{name} && ($cred->name ne $check->{name} || $cred->name_orig ne $check->{orig}) ) { 74 my $exists_foreign = $keeper->get_documents( class => 'users::Phone', name => $check->{name}, uid_not => $object->id, count => 1 ); 75 unless ( $exists_foreign ) { 76 $cred->name( $check->{name} ); 77 $cred->name_orig( $check->{orig} ); 78 $cred->name_format( $check->{format} ); 79 $store = 1; 80 } 81 } 82 if ( ref $check && int($check->{main}) != int($cred->main) ) { 83 $cred->main( int($check->{main}) ); 84 $store = 1; 85 } 86 if ( ref $check && int($check->{status}) != int($cred->status) ) { 87 $cred->status( int($check->{status}) ); 88 $store = 1; 89 } 90 if ( $store ) { 91 $cred->store; 92 } 93 } 94 if ( exists $struct{new} && exists $struct{new}{name} ) { 95 my @found = grep { $_->name eq $struct{new}{name} } @credentials; 96 unless ( @found ) { 97 my $check = $struct{new}; 98 my $exists_foreign = $keeper->get_documents( class => 'users::Phone', name => $check->{name}, count => 1 ); 99 unless ( $exists_foreign ) { 100 my $cred = $object->create_credential( phone => $check->{orig}, main => $check->{main}, status => ($check->{status} || 0) ); 101 push @credentials, $cred if ref $cred; 102 } 103 } 104 } 105 my ($main) = grep { $_->main } @credentials; 106 $object->{$name.'s'} = \@credentials; 107 return $main; 108 } else { 109 return $keeper->{users}->_phone_format( $SETS->{$name} ); 110 } 111 112 </%init>