/[A3C]/lib/A3C/Model/StrixInstanceSelection.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /lib/A3C/Model/StrixInstanceSelection.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 186 - (hide annotations)
Mon Jun 16 22:56:14 2008 UTC (15 years, 11 months ago) by dpavlin
File size: 1139 byte(s)
I feel good enought for this version to have it bump [0.05]

- dispatcher will automatically take first selected instance
- check if we can connect to database when adding instances to selection
- removed bunch of debug warn output
- display validation error messages in selector
- show selected instance in selector
- variable instance is now used for current user instance, and op_instace for selector
- dim layout link
1 dpavlin 157 use strict;
2     use warnings;
3    
4 dpavlin 174 package A3C::Model::StrixInstanceSelection;
5 dpavlin 157 use Jifty::DBI::Schema;
6    
7     use Data::Dump qw/dump/;
8    
9     use A3C::Record schema {
10    
11 dpavlin 174 column instance =>
12     label is _('Instance identifier'),
13 dpavlin 157 is mandatory,
14     type is 'text',
15 dpavlin 186 is ajax_validates,
16 dpavlin 174 refers_to A3C::Model::StrixInstance by 'instance';
17 dpavlin 157
18     column by_user =>
19     label is ('Selected by user'),
20     is mandatory,
21     refers_to A3C::Model::User by 'id',
22     default is defer { Jifty->web->current_user->id };
23    
24     };
25    
26     # Your model-specific methods go here.
27    
28     sub since { '0.0.4' };
29    
30 dpavlin 174 sub validate_instance {
31 dpavlin 157 my $self = shift;
32 dpavlin 174 my $instance = shift;
33 dpavlin 157
34 dpavlin 174 my $strix = A3C::Model::StrixInstanceSelection->new;
35     $strix->load_by_cols( instance => $instance );
36 dpavlin 157
37 dpavlin 186 if ( $strix->id ) {
38     return ( 0, _('Instance %1 allready selected', $instance) );
39     } else {
40     eval {
41     Strix->dbh( $instance );
42     };
43     return 1 unless $@;
44     return ( 0, $@ );
45     }
46 dpavlin 157 }
47    
48     sub current_user_can {
49     my $self = shift;
50 dpavlin 158 my $op = shift;
51    
52     if ( $op eq 'create' ) {
53     my %args = @_;
54     return 1 if $args{by_user} == $self->current_user->id;
55     }
56    
57     return 1 if $self->by_user->id == $self->current_user->id;
58    
59 dpavlin 157 return 0;
60     }
61    
62     1;
63    

  ViewVC Help
Powered by ViewVC 1.1.26