Permalink
Browse files

fixed categories filter/ add vehicle form

  • Loading branch information...
1 parent 073d707 commit e47459825cdbff33ae1817da86eecc3b552bf154 Iuri Sampaio committed Feb 2, 2012
Showing with 758 additions and 64 deletions.
  1. +2 −2 packages/cnauto-assurance/www/index.xql
  2. +2 −2 packages/cnauto-core/cnauto-core.info
  3. +91 −0 packages/cnauto-core/sql/postgresql/upgrade/upgrade-0.1d-0.2d.sql
  4. +39 −5 packages/cnauto-core/tcl/cnauto-core-procs.tcl
  5. +23 −0 packages/cnauto-core/www/categories-delete.tcl
  6. +12 −1 packages/cnauto-core/www/categories.adp
  7. +49 −9 packages/cnauto-core/www/categories.tcl
  8. +30 −0 packages/cnauto-core/www/categories.xql
  9. +17 −1 packages/cnauto-core/www/category-ae.tcl
  10. +18 −0 packages/cnauto-core/www/category-bulk-delete.adp
  11. +38 −0 packages/cnauto-core/www/category-bulk-delete.tcl
  12. +2 −2 packages/cnauto-resources/cnauto-resources.info
  13. +46 −22 packages/cnauto-resources/sql/postgresql/cnauto-resources-create.sql
  14. +1 −1 packages/cnauto-resources/sql/postgresql/upgrade/upgrade-0.12d-0.13d.sql
  15. +17 −0 packages/cnauto-resources/sql/postgresql/upgrade/upgrade-0.13d-0.14d.sql
  16. +103 −0 packages/cnauto-resources/sql/postgresql/upgrade/upgrade-0.14d-0.15d.sql
  17. +6 −0 packages/cnauto-resources/sql/postgresql/upgrade/upgrade-0.15d-0.16d.sql
  18. +9 −0 packages/cnauto-resources/sql/postgresql/upgrade/upgrade-0.16d-0.17d.sql
  19. +79 −0 packages/cnauto-resources/sql/postgresql/upgrade/upgrade-0.17d-0.18d.sql
  20. +46 −1 packages/cnauto-resources/tcl/cnauto-resources-procs.tcl
  21. +6 −3 packages/cnauto-resources/www/index.adp
  22. +10 −0 packages/cnauto-resources/www/resource-ae.adp
  23. +59 −0 packages/cnauto-resources/www/resource-ae.tcl
  24. +17 −0 packages/cnauto-resources/www/resource-ae.tcl[]
  25. +6 −5 packages/cnauto-resources/www/vehicles/index.adp
  26. +1 −7 packages/cnauto-resources/www/vehicles/index.tcl
  27. +2 −2 packages/cnauto-resources/www/vehicles/index.xql
  28. +14 −1 packages/cnauto-resources/www/vehicles/vehicle-ae.tcl
  29. +13 −0 packages/cnauto-resources/www/vehicles/vehicle-models.adp
@@ -6,7 +6,7 @@
SELECT ca.assurance_id, ca.assurance_number, cv.vehicle_id, cv.vin AS chassis, cp.person_id, cp.pretty_name AS person_name
FROM cn_assurances ca, cn_persons cp, cn_vehicles cv
WHERE ca.vehicle_id = cv.vehicle_id
- AND cp.person_id = cv.person_id
+ AND cp.person_id = cv.owner_id
[template::list::filter_where_clauses -and -name "assurances"]
[template::list::orderby_clause -orderby -name "assurances"]
@@ -19,7 +19,7 @@
SELECT ca.assurance_id, ca.assurance_number, cv.vehicle_id, cv.vin AS chassis, cp.person_id, cp.pretty_name AS person_name
FROM cn_assurances ca, cn_persons cp, cn_vehicles cv
WHERE ca.vehicle_id = cv.vehicle_id
- AND cp.person_id = cv.person_id
+ AND cp.person_id = cv.owner_id
$where_clause
[template::list::filter_where_clauses -and -name "assurances"]
[template::list::page_where_clause -and -name "assurances" -key "ca.assurance_id"]
@@ -9,13 +9,13 @@
<implements-subsite-p>f</implements-subsite-p>
<inherit-templates-p>f</inherit-templates-p>
- <version name="0.1d" url="http://openacs.org/repository/download/apm/cnauto-core-0.1d.apm">
+ <version name="0.2d" url="http://openacs.org/repository/download/apm/cnauto-core-0.2d.apm">
<owner url="mailto:iuri.sampaio@cnauto.com.br">Iuri Sampaio</owner>
<summary>Core package for CNAuto system</summary>
<description format="text/html">Core package for CNAuto system</description>
<maturity>0</maturity>
- <provides url="cnauto-core" version="0.1d"/>
+ <provides url="cnauto-core" version="0.2d"/>
<callbacks>
<callback type="after-install" proc="cnauto_core::install::after_install" />
@@ -0,0 +1,91 @@
+-- /packages/cnauto-core/sql/postgresql/upgrade/upgrade-0.1d-0.2d.sql
+
+SELECT acs_log__debug ('/packages/cnauto-core/sql/postgresql/upgrade/upgrade-0.1d-0.2d.sql','');
+
+
+ALTER TABLE cn_categories ADD COLUMN parent_id integer;
+
+ALTER TABLE cn_categories ADD CONSTRAINT cn_categories_parent_id_fk FOREIGN KEY (parent_id) REFERENCES cn_categories (category_id);
+
+
+CREATE OR REPLACE FUNCTION cn_category__new (
+ integer, -- category_id
+ integer, -- package_id
+ integer, -- parent_id
+ varchar, -- name
+ varchar, -- pretty_name
+ varchar -- object_type
+) RETURNS integer AS '
+ DECLARE
+ p_category_id ALIAS FOR $1;
+ p_package_id ALIAS FOR $2;
+ p_parent_id ALIAS FOR $3;
+ p_name ALIAS FOR $4;
+ p_pretty_name ALIAS FOR $5;
+ p_object_type ALIAS FOR $6;
+ BEGIN
+
+ INSERT INTO cn_categories (
+ category_id,
+ package_id,
+ parent_id,
+ name,
+ pretty_name,
+ object_type
+ ) VALUES (
+ p_category_id,
+ p_package_id,
+ p_parent_id,
+ p_name,
+ p_pretty_name,
+ p_object_type
+ );
+
+ RETURN 0;
+
+ END;' language 'plpgsql';
+
+
+CREATE OR REPLACE FUNCTION cn_category__edit (
+ integer, -- category_id
+ integer, -- package_id
+ integer, -- parent_id
+ varchar, -- name
+ varchar, -- pretty_name
+ varchar -- object_type
+) RETURNS integer AS '
+ DECLARE
+ p_category_id ALIAS FOR $1;
+ p_package_id ALIAS FOR $2;
+ p_parent_id ALIAS FOR $3;
+ p_name ALIAS FOR $4;
+ p_pretty_name ALIAS FOR $5;
+ p_object_type ALIAS FOR $6;
+ BEGIN
+
+ UPDATE cn_categories SET
+ package_id = p_package_id,
+ parent_id = p_parent_id,
+ name = p_name,
+ pretty_name = p_prety_name,
+ object_type = p_object_type
+ WHERE category_id = p_category_id;
+
+ RETURN 0;
+
+ END;' language 'plpgsql';
+
+
+CREATE OR REPLACE FUNCTION cn_category__delete (
+ integer -- category_id
+) RETURNS integer AS '
+ DECLARE
+ p_category_id ALIAS FOR $1;
+
+ BEGIN
+
+ DELETE FROM cn_categories WHERE category_id = p_category_id;
+
+ RETURN 0;
+
+ END;' language 'plpgsql';
@@ -13,8 +13,42 @@ namespace eval cnauto_core {}
namespace eval cn_core {}
namespace eval cn_core::util {}
+
+
namespace eval cn_categories {}
+namespace eval cn_categories::category {}
+ad_proc -public cn_categories::category::delete {
+ category_id
+} {
+ Deletes category
+} {
+
+ # If category is parent of others remove the children first
+
+
+
+ set children_ids [db_list select_children_ids {
+ SELECT category_id FROM cn_categories WHERE parent_id = :category_id
+ }]
+
+ if {[exists_and_not_null children_ids]} {
+ foreach child_id $children_ids {
+ cn_categories::category::delete $child_id
+ }
+ }
+
+ #if category is a leaf node just remove it
+ db_dml delete_category {
+ DELETE FROM cn_categories WHERE category_id = :category_id
+ }
+
+
+ return
+}
+
+
+
ad_proc -public cn_categories::get_category_id {
{-name}
{-type ""}
@@ -28,7 +62,7 @@ ad_proc -public cn_categories::get_category_id {
-ad_proc -public cnauto_core::item_exists {
+ad_proc -public cn_core::item_exists {
{-items}
{-chassi}
} {
@@ -50,7 +84,7 @@ ad_proc -public cnauto_core::item_exists {
}
-ad_proc -public cnauto_core::format_output_line {
+ad_proc -public cn_core::format_output_line {
{-line}
} {
Format output line to BA standards
@@ -74,7 +108,7 @@ ad_proc -public cnauto_core::format_output_line {
-ad_proc -public cnauto_core::mount_output_line {
+ad_proc -public cn_core::mount_output_line {
{-line}
} {
Prepare input line to output
@@ -158,7 +192,7 @@ ad_proc -public cnauto_core::mount_output_line {
}
-ad_proc -public cnauto_core::export_csv_to_txt {
+ad_proc -public cn_core::export_csv_to_txt {
{-input_file}
{-output_file}
} {
@@ -200,7 +234,7 @@ ad_proc -public cnauto_core::export_csv_to_txt {
lappend items [lindex $output_line 5]
# format output to BA standards
- set output_line [cnauto_core::format_output_line -line $output_line]
+ set output_line [cn_core::format_output_line -line $output_line]
#inserts line within output file
puts $output_file $output_line
@@ -0,0 +1,23 @@
+
+ad_page_contract {
+ Delete categories
+} {
+ category_id:notnull
+ {return_url ""}
+ {cancel.x:optional}
+}
+
+
+if {![info exists cancel.x]} {
+
+
+ foreach element $category_id {
+# ad_require_permission $element order_delete
+ if { [catch { cn_categories::category::delete $element } errmsg] } {
+ ad_return_complaint 1 "[_ cn-order.Delete_order_failed]: $errmsg"
+ }
+ }
+}
+ad_returnredirect $return_url
+
+
@@ -8,4 +8,15 @@
<li><a href="category-ae">#cnauto-core.Add_category#</a></li>
<li><a href="categories-import-csv-file">#cnauto-resources.Import_person_cat_lt#</a></li>
</ul>
-<listtemplate name="categories"></listtemplate>
+
+ <table cellpadding="3" cellspacing="3">
+ <tr>
+ <td class="list-filter-pane" valign="top" style="width:200px">
+ <listfilters name="categories"></listfilters>
+ </td>
+ <td class="list-list-pane" valign="top">
+ <listtemplate name="categories"></listtemplate>
+ </td>
+ </tr>
+ </table>
+
@@ -1,6 +1,10 @@
ad_page_contract {
Categories main page
+} {
+ {object_type ""}
+ {orderby "pretty_name,asc"}
+ page:optional
} -properties {
context:onevalue
title:onevalue
@@ -10,30 +14,66 @@ ad_page_contract {
set title "[_ cnauto-resources.Add_category]"
set context [list $title]
+set object_type_options [list]
+
+db_foreach category_type {
+ SELECT cc.object_type AS type, COUNT(cc.category_id) AS num, ot.pretty_name
+ FROM cn_categories cc, acs_object_types ot
+ WHERE cc.object_type = ot.object_type
+ GROUP BY cc.object_type, ot.pretty_name
+} {
+ lappend category_type_options \
+ [list \
+ $pretty_name \
+ $type \
+ [lc_numeric $num]]
+}
+
+
+
+set bulk_actions {"#cnauto-core.Delete#" "category-bulk-delete" "#cnauto-core.Delete_selected_cat#"}
template::list::create \
-name categories \
-multirow categories \
+ -key category_id \
+ -bulk_actions $bulk_actions \
+ -bulk_action_export_vars { return_url } \
+ -row_pretty_plural "categories" \
+ -page_size 10 \
+ -page_flush_p t \
+ -page_query_name categories_pagination \
-elements {
pretty_name {
label "[_ cnauto-core.Name]"
display_template {
<a href="@categories.category_ae_url@">@categories.pretty_name;noquote@</a>
}
}
- type {
+ pretty_type {
label "[_ cnauto-core.Class]"
}
- }
-
+ } -filters {
+ object_type {
+ label "[_ cnauto-core.Type]"
+ values $category_type_options
+ where_clause {
+ cc.object_type = :object_type
+ }
+ default_value ""
+ }
+ } -orderby {
+ pretty_name {
+ label "[_ cnauto-core.Name]"
+ orderby category_id
+ orderby_asc {cc.pretty_name asc}
+ orderby_desc {cc.pretty_name desc}
+ }
+ }
+
-db_multirow -extend {category_ae_url} categories select_categories {
- SELECT cc.category_id, cc.pretty_name, ot.pretty_name AS type
- FROM cn_categories cc, acs_object_types ot
- WHERE ot.object_type = cc.object_type
- ORDER BY cc.pretty_name
-} {
+db_multirow -extend {category_ae_url} categories select_categories {} {
set category_ae_url [export_vars -base "category-ae" {category_id return_url}]
}
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+
+<queryset>
+
+<fullquery name="categories_pagination">
+ <querytext>
+
+ SELECT cc.category_id, cc.pretty_name, ot.pretty_name AS prety_type
+ FROM cn_categories cc, acs_object_types ot
+ WHERE ot.object_type = cc.object_type
+ [template::list::filter_where_clauses -and -name "categories"]
+ [template::list::orderby_clause -orderby -name "categories"]
+
+ </querytext>
+</fullquery>
+
+<fullquery name="select_categories">
+ <querytext>
+
+ SELECT cc.category_id, cc.pretty_name, ot.pretty_name AS pretty_type
+ FROM cn_categories cc, acs_object_types ot
+ WHERE ot.object_type = cc.object_type
+ [template::list::filter_where_clauses -and -name "categories"]
+ [template::list::page_where_clause -and -name "categories" -key "cc.category_id"]
+ [template::list::orderby_clause -orderby -name "categories"]
+
+ </querytext>
+</fullquery>
+
+</queryset>
Oops, something went wrong.

0 comments on commit e474598

Please sign in to comment.