[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[2339] trunk
- Subject: SF.net SVN: ledger-smb:[2339] trunk
- From: ..hidden..
- Date: Tue, 23 Sep 2008 23:23:03 +0000
Revision: 2339
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2339&view=rev
Author: aurynn_cmd
Date: 2008-09-23 23:23:03 +0000 (Tue, 23 Sep 2008)
Log Message:
-----------
Lots of fixes for editing users. Minor changes to Person.sql, specifically person__save_contact.
Modified Paths:
--------------
trunk/LedgerSMB/DBObject/Admin.pm
trunk/LedgerSMB/DBObject/Location.pm
trunk/LedgerSMB/DBObject/User.pm
trunk/UI/Admin/edit_user.html
trunk/scripts/admin.pl
trunk/sql/modules/Person.sql
Modified: trunk/LedgerSMB/DBObject/Admin.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Admin.pm 2008-09-23 21:06:27 UTC (rev 2338)
+++ trunk/LedgerSMB/DBObject/Admin.pm 2008-09-23 23:23:03 UTC (rev 2339)
@@ -264,4 +264,11 @@
$self->debug({file => '/tmp/user'});
return $self->{countries};
}
-1;
+sub get_contact_classes {
+
+ my $self = shift @_;
+ my $sth = $self->{dbh}->prepare("select id, class as classname from contact_class");
+ my $code = $sth->execute();
+ return $sth->fetchall_arrayref({});
+}
+1;
\ No newline at end of file
Modified: trunk/LedgerSMB/DBObject/Location.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Location.pm 2008-09-23 21:06:27 UTC (rev 2338)
+++ trunk/LedgerSMB/DBObject/Location.pm 2008-09-23 23:23:03 UTC (rev 2339)
@@ -69,5 +69,6 @@
my $type = shift @_;
my @locations = $self->exec_method(funcname=>$type."__all_locations", args=>[$user_id]);
+ return ..hidden..;
}
1;
\ No newline at end of file
Modified: trunk/LedgerSMB/DBObject/User.pm
===================================================================
--- trunk/LedgerSMB/DBObject/User.pm 2008-09-23 21:06:27 UTC (rev 2338)
+++ trunk/LedgerSMB/DBObject/User.pm 2008-09-23 23:23:03 UTC (rev 2339)
@@ -141,4 +141,20 @@
}
+sub save_contact {
+
+ my $self = shift @_;
+ my $id = shift @_;
+ my $contact = shift @_;
+
+ my @ret = $self->exec_method(funcname=>"person__save_contact",
+ args=>[
+ $self->{entity_id},
+ $self->{contacts}->[$id]->{contact_class},
+ $self->{contacts}->[$id]->{contact},
+ $contact
+ ]
+ );
+}
+
1;
Modified: trunk/UI/Admin/edit_user.html
===================================================================
--- trunk/UI/Admin/edit_user.html 2008-09-23 21:06:27 UTC (rev 2338)
+++ trunk/UI/Admin/edit_user.html 2008-09-23 23:23:03 UTC (rev 2339)
@@ -195,11 +195,13 @@
<tr>
<td></td>
<td>
- <select name="class">
- <?lsmb FOREACH class IN contact_classes?>
- <option name="<?lsmb class.id?>" <?lsmb IF contact.contact_class_id == class.id?>selected<?lsmb END?>><?lsmb class.contact?></option>
- <?lsmb END?>
- </select>
+ <?lsmb PROCESS select element_data = {
+ name = "contact_class"
+ options = contact_classes
+ default_values = [contact.contact_class_id]
+ value_attr = "id"
+ text_attr = "classname"
+ } ?>
</td>
<td>
<input type="textarea" name="contact" value="<?lsmb contact.contact?>"/>
Modified: trunk/scripts/admin.pl
===================================================================
--- trunk/scripts/admin.pl 2008-09-23 21:06:27 UTC (rev 2338)
+++ trunk/scripts/admin.pl 2008-09-23 23:23:03 UTC (rev 2339)
@@ -62,9 +62,9 @@
# uses the same page as create_user, only pre-populated.
my ($request) = @_;
my $admin = LedgerSMB::DBObject::Admin->new(base=>$request, copy=>'user_id');
- my $user = LedgerSMB::DBObject::User->new(base=>$request, copy=>'user_id');
-
- $user->get($request->{user_id});
+ my $user_obj = LedgerSMB::DBObject::User->new(base=>$request, copy=>'user_id');
+ $user_obj->{company} = $request->{company};
+ $user_obj->get($request->{user_id});
my @all_roles = $admin->get_roles();
@@ -75,16 +75,19 @@
format => 'HTML',
path=>'UI'
);
-
+ my $location = LedgerSMB::DBObject::Location->new(base=>$request);
my $template_data =
{
- user=>$user,
+ user=>$user_obj,
roles=>@all_roles,
countries=>$admin->get_countries(),
- user_roles=>$user->{roles},
+ user_roles=>$user_obj->{roles},
salutations=>$admin->get_salutations(),
- locations=>$location->get_all($u_id,"person"),
+ contact_classes=>$admin->get_contact_classes(),
+ locations=>$location->get_all($user_obj->{entity_id},"person"),
};
+ print STDERR Dumper($template_data->{contact_classes});
+ print STDERR Dumper($template_data->{user_roles});
if ($request->type() eq 'POST') {
$admin->save_user();
@@ -94,10 +97,8 @@
else {
# print STDERR Dumper($user);
# print STDERR Dumper(@all_roles);
- my $loc;
- my $location = LedgerSMB::DBObject::Location->new(base=>$request);
if ($request->{location_id}) {
- $loc = $location->get($request->{location_id});
+ $template_data->{location} = $location->get($request->{location_id});
}
$template->render($template_data);
}
@@ -248,7 +249,7 @@
$template->render( { users=>$user->{users} } );
}
-sub edit_contact {
+sub save_contact {
my $request = shift @_;
@@ -258,13 +259,39 @@
# We have a contact ID, ie, something we made up.
my $c_id = $request->{contact_id};
my $u_id = $request->{user_id};
- my $user = LedgerSMB::DBObject::User->new(base=>$request, copy=>'user_id');
- $user->get($u_id);
+ my $user_obj = LedgerSMB::DBObject::User->new(base=>$request, copy=>'list', merge=>['user_id','company']);
+ $user_obj->get($u_id);
# so we have a user object.
# ->{contacts} is an arrayref to the list of contacts this user has
# $request->{contact_id} is a reference to this structure.
+ $user_obj->save_contact($c_id);
+
+ my $admin = LedgerSMB::DBObject::Admin->new(base=>$request, copy=>'user_id');
+
+ $user_obj->get($request->{user_id});
+
+ my @all_roles = $admin->get_roles();
+
+ my $template = LedgerSMB::Template->new(
+ user => $user,
+ template => 'Admin/edit_user',
+ language => $user->{language},
+ format => 'HTML',
+ path=>'UI'
+ );
+ my $template_data =
+ {
+ user=>$user_obj,
+ roles=>@all_roles,
+ countries=>$admin->get_countries(),
+ user_roles=>$user_obj->{roles},
+ salutations=>$admin->get_salutations(),
+ contact_classes=>$admin->get_contact_classes(),
+ locations=>$location->get_all($user_obj->{entity_id},"person"),
+ };
+ $template->render($template_data);
}
}
@@ -293,13 +320,6 @@
}
}
-sub new_contact {
-
- my $request = shift @_;
-
-
-}
-
sub save_location {
my $request = shift @_;
Modified: trunk/sql/modules/Person.sql
===================================================================
--- trunk/sql/modules/Person.sql 2008-09-23 21:06:27 UTC (rev 2338)
+++ trunk/sql/modules/Person.sql 2008-09-23 23:23:03 UTC (rev 2339)
@@ -117,32 +117,49 @@
END;
$$ LANGUAGE plpgsql;
+--
+
CREATE OR REPLACE FUNCTION person__save_contact
-(in_entity_id int, in_contact_class int, in_contact text)
+(in_entity_id int, in_contact_class int, in_contact_orig text, in_contact_new TEXT)
RETURNS INT AS
$$
-DECLARE out_id int;
+DECLARE
+ out_id int;
+ v_orig person_to_contact;
BEGIN
- INSERT INTO person_to_contact(person_id, contact_class_id, contact)
- SELECT id, in_contact_class, in_contact FROM person
- WHERE entity_id = in_entity_id;
-
- RETURN 1;
+
+ SELECT cc.* into v_orig
+ FROM contact_class cc, person p
+ WHERE p.entity_id = in_entity_id
+ and contact_class = in_contact_class
+ AND contact = in_contact_orig
+ AND cc.person_id = p.id;
+ IF NOT FOUND THEN
+
+ -- create
+ INSERT INTO person_to_contact(person_id, contact_class_id, contact)
+ VALUES (
+ (SELECT id FROM person WHERE entity_id = in_entity_id),
+ in_contact_class,
+ in_contact_new
+ );
+ return 1;
+ ELSE
+ -- edit.
+ UPDATE person_to_contact
+ SET contact = in_contact_new
+ WHERE
+ contact = in_contact_orig
+ AND person_id = v_orig.person_id
+ AND contact_class = in_contact_class;
+ return 0;
+ END IF;
+
END;
$$ LANGUAGE PLPGSQL;
+--
-/*(
- unknown,
- unknown,
- unknown,
- unknown,
- unknown,
- unknown,
- unknown,
- unknown)
-
-*/
create or replace function person__save_location(
in_entity_id int,
in_location_id int,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.