[Bps-public-commit] r8756 - in SVKUI: . trunk/lib/SVKUI/Model trunk/share/web/templates trunk/t

clsung at bestpractical.com clsung at bestpractical.com
Tue Aug 28 04:07:38 EDT 2007


Author: clsung
Date: Tue Aug 28 04:07:37 2007
New Revision: 8756

Added:
   SVKUI/trunk/lib/SVKUI/Action/CreateNewProject.pm
   SVKUI/trunk/t/00-action-CreateNewProject.t
Modified:
   SVKUI/   (props changed)
   SVKUI/trunk/lib/SVKUI/Model/Project.pm
   SVKUI/trunk/share/web/templates/addproject

Log:
 r8814 at going04:  clsung | 2007-08-28 10:11:53 +0800
 - adjust type before create
 r8815 at going04:  clsung | 2007-08-28 14:50:30 +0800
 - add action CreateNewProject, use it to handle new projects
 r8816 at going04:  clsung | 2007-08-28 16:05:27 +0800
 - implement CreateNewProject, now it really CreateProject
 r8817 at going04:  clsung | 2007-08-28 16:06:03 +0800
 - this check (svn type) is performed in Action::CreateNewProject
 r8818 at going04:  clsung | 2007-08-28 16:07:11 +0800
 - the canonicalize_url is now performed in Action::CreateNewProject, too
 - make Model::Project pure.


Added: SVKUI/trunk/lib/SVKUI/Action/CreateNewProject.pm
==============================================================================
--- (empty file)
+++ SVKUI/trunk/lib/SVKUI/Action/CreateNewProject.pm	Tue Aug 28 04:07:37 2007
@@ -0,0 +1,125 @@
+use strict;
+use warnings;
+
+=head1 NAME
+
+SVKUI::Action::CreateNewProject
+
+=cut
+
+package SVKUI::Action::CreateNewProject;
+use base qw/SVKUI::Action Jifty::Action/;
+
+use Jifty::Param::Schema;
+use Jifty::Action schema {
+
+# possible field type => 
+# Button         Combobox       InlineButton   ResetButton    Textarea       
+# Checkbox       Date           Password       Select         Unrendered     
+# Collection     Hidden         Radio          Text           Upload        
+param
+    name => type is 'text',
+    label is _('Name'),
+    hints is 'name for the Project',
+    is distinct,
+    is mandatory;
+
+param
+    type => type is 'select',
+    valid are qw(http https svn+https svn),
+    label is _('Connect Type'),
+    is mandatory;
+
+param
+    url => type is 'text',
+    label is _('URL'),
+    hints is 'URL of the mirror path',
+    ajax canonicalizes,
+    is mandatory;
+
+param
+    authuser => type is 'text',
+    label is _('Username'),
+    ajax canonicalizes,
+    hints is 'Username for the site, if required';
+
+param
+    authpass => type is 'password',
+    label is _('Password'),
+    hints is 'Password for the site, If required';
+
+param
+    description => type is 'textarea',
+    label is _('DESCRIPTION'),
+    hints is 'Description for this mirror site';
+
+};
+
+=head2 take_action
+
+=cut
+
+sub take_action {
+    my $self = shift;
+    
+    # Custom action code
+    my $project = SVKUI::Model::Project->new;
+    $project->create( name => $self->argument_value('name'), 
+	url => $self->argument_value('url'),
+	type => $self->argument_value('type'),
+	authuser => $self->argument_value('authuser'),
+	authpass => $self->argument_value('authpass'),
+	authpass_confirm => $self->argument_value('authpass_confirm'),
+	description => $self->argument_value('description')
+    );
+    
+    $self->report_success if not $self->result->failure;
+    
+    return 1;
+}
+
+=head2 report_success
+
+=cut
+
+sub report_success {
+    my $self = shift;
+    # Your success message here
+    $self->result->message('Success');
+}
+
+=head2 canonicalize_XXX
+
+=cut
+
+sub canonicalize_url {
+    my ($self, $value) = @_;
+
+    $value =~ s/^ *//;
+    my $type = substr($value, 0, index($value,'://'));
+    if ($type eq 'http' || $type eq 'https'
+	||
+	$type eq 'svn+https' || $type eq 'svn') {
+	    $self->argument_value( type => $type )
+    } else {
+	$self->canonicalization_note(
+	    url => _('URL values should start with one of these type: http, https, svn+https, svn.'))
+    }
+
+    return $value;
+}
+
+sub canonicalize_authuser {
+    my ($self, $value) = @_;
+    if ($value ne '') {
+	# warn "Adding two field for auth";
+	# not working
+	#$self->form_field('authpass');
+	#$self->form_field('authpass_confirm');
+    }
+
+    return $value;
+}
+
+1;
+

Modified: SVKUI/trunk/lib/SVKUI/Model/Project.pm
==============================================================================
--- SVKUI/trunk/lib/SVKUI/Model/Project.pm	(original)
+++ SVKUI/trunk/lib/SVKUI/Model/Project.pm	Tue Aug 28 04:07:37 2007
@@ -182,14 +182,6 @@
     return 1;    # true return value will allow delete to continue
 }
 
-sub canonicalize_url {
-    my ($self, $value) = @_;
-
-    $value =~ s/^ *//;
-
-    return $value;
-}
-
 sub pullyu {
     my ($self, $value) = @_;
     return 1 unless defined($self->repospath);

Modified: SVKUI/trunk/share/web/templates/addproject
==============================================================================
--- SVKUI/trunk/share/web/templates/addproject	(original)
+++ SVKUI/trunk/share/web/templates/addproject	Tue Aug 28 04:07:37 2007
@@ -1,5 +1,5 @@
 <%init>
-my $action = Jifty->web->new_action(class => 'CreateProject');
+my $action = Jifty->web->new_action(class => 'CreateNewProject');
 </%init>
 
 <&| /_elements/wrapper, title => "Create a new mirror site" &>
@@ -7,8 +7,8 @@
 <% Jifty->web->form->start() %>
 <% Jifty->web->form->next_page( url => '/') %>
 <% $action->form_field('name', default_value => $name) %>
-<% $action->form_field('type', default_value => $type) %>
 <% $action->form_field('url', default_value => $url) %>
+<% $action->form_field('type', default_value => $type) %>
 <% $action->form_field('authuser') %>
 <% $action->form_field('authpass') %>
 <% $action->form_field('authpass_confirm') %>
@@ -20,6 +20,6 @@
 <%ARGS>
 $name => undef
 $url => undef
-$type => 'http'
+$type => 'https'
 $desc => undef
 </%ARGS>

Added: SVKUI/trunk/t/00-action-CreateNewProject.t
==============================================================================
--- (empty file)
+++ SVKUI/trunk/t/00-action-CreateNewProject.t	Tue Aug 28 04:07:37 2007
@@ -0,0 +1,15 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+
+=head1 DESCRIPTION
+
+A (very) basic test harness for the CreateNewProject action.
+
+=cut
+
+use Jifty::Test tests => 1;
+
+# Make sure we can load the action
+use_ok('SVKUI::Action::CreateNewProject');
+



More information about the Bps-public-commit mailing list