[Jifty-commit] r2331 - jifty/trunk/share/web/templates/__jifty/admin/fragments/list

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Tue Dec 5 04:50:46 EST 2006


Author: yves
Date: Tue Dec  5 04:50:45 2006
New Revision: 2331

Added:
   jifty/trunk/share/web/templates/__jifty/admin/fragments/list/header
Modified:
   jifty/trunk/share/web/templates/__jifty/admin/fragments/list/list
   jifty/trunk/share/web/templates/__jifty/admin/fragments/list/new_item
   jifty/trunk/share/web/templates/__jifty/admin/fragments/list/update
   jifty/trunk/share/web/templates/__jifty/admin/fragments/list/view

Log:
Administration manage model : 
 * add sortable capabilities in header table
 * bug fix in delete item
 * begining of modularity


Added: jifty/trunk/share/web/templates/__jifty/admin/fragments/list/header
==============================================================================
--- (empty file)
+++ jifty/trunk/share/web/templates/__jifty/admin/fragments/list/header	Tue Dec  5 04:50:45 2006
@@ -0,0 +1,57 @@
+<%args>
+$object_type
+$mask_val => ""
+$mask_field => ""
+$list_path
+</%args>
+<%init>
+my $record_class = Jifty->app_class("Model", $object_type);
+my $record = $record_class->new();
+ my $update = Jifty->web->new_action(class => 'Update'.$object_type);
+</%init>
+<div class="jifty_admin">
+
+% foreach my $argument ($update->argument_names) {
+% unless( $argument eq $mask_field ||  $argument eq 'id' || $argument =~ /_confirm$/i
+%        && lc $update->arguments->{$argument}{render_as} eq 'password') {
+<%
+    Jifty->web->link(
+        label   => "[A]",
+        onclick => 
+            { 
+            replace_with => $list_path.'list' ,
+            args   => {
+                object_type => $object_type,
+                limit_val => $mask_val,
+                limit_field => $mask_field,
+                list_path => $list_path,
+                sort_by => $argument,
+                order => undef
+                },
+            },
+        #as_button => 1
+        )
+%>
+<%
+    Jifty->web->link(
+        label   => "[D]",
+        onclick => 
+            {
+            replace_with => $list_path.'list',
+            args   => {
+                object_type => $object_type,
+                limit_val => $mask_val,
+                limit_field => $mask_field,
+                list_path => $list_path,
+                sort_by => $argument,
+                order => 'D'
+                },
+            },
+        #as_button => 1
+        )
+%>
+ <%$argument%>
+% }
+% }
+<hr />
+</div>

Modified: jifty/trunk/share/web/templates/__jifty/admin/fragments/list/list
==============================================================================
--- jifty/trunk/share/web/templates/__jifty/admin/fragments/list/list	(original)
+++ jifty/trunk/share/web/templates/__jifty/admin/fragments/list/list	Tue Dec  5 04:50:45 2006
@@ -1,25 +1,58 @@
+<%doc>
+
+You can copy this fragment directory to your app.
+And use it in a page like this :
+
+<% Jifty->web->region(name => "admin-subdomain",
+                      path => "/admin/fragments/list/list",
+                      defaults => { object_type => 'SubDomain',
+                                    list_path => '/admin/fragments/list/',
+                                    limit_field => 'domain',
+                                    limit_val => $domain,
+                                    search_slot => 0
+                                    per_page => 5,
+                                    render_submit => 1 }) %>
+
+limit_field, limit_val allow add to your sql query 
+ ... WHERE $limit_field = $limit_val
+
+</%doc>
 <%args>
 $object_type
 $page => 1
 $new_slot => 1
+$search_slot => 1
 $item_path => "/__jifty/admin/fragments/list/view"
+$list_path => "/__jifty/admin/fragments/list/"
+$limit_field => ""
+$limit_val => ""
+$per_page => 25
+$sort_by => undef
+$order => undef
 </%args>
 <%init>
 my $collection_class = Jifty->app_class("Model", $object_type."Collection");
 my $search = Jifty->web->response->result('search');
-my $collection;
+my $collection = $collection_class->new();
+
 if(!$search) {
-    $collection = $collection_class->new();
-    $collection->unlimit();
+   if ( $limit_field && $limit_val ) {
+      $collection->limit(column => $limit_field, value => $limit_val);
+   } else {
+      $collection->unlimit();
+   }
+   $collection->order_by(column => $sort_by, order=>'ASC') if ($sort_by && !$order);
+   $collection->order_by(column => $sort_by, order=>'DESC') if ($sort_by && $order);
 } else {
     $collection = $search->content('search');
     warn $collection->build_select_query;
 }
 
 $collection->set_page_info( current_page => $page,
-                            per_page     => 25
+                            per_page     => $per_page
                            );
 </%init>
+% if ($search_slot) {
 <%perl>    
 my $search_region = Jifty::Web::PageRegion->new(
    name     => 'search',
@@ -30,7 +63,7 @@
 <% Jifty->web->link(
     onclick => [{
         region       => $search_region->qualified_name,
-        replace_with => '/__jifty/admin/fragments/list/search',
+        replace_with => $list_path.'search',
         toggle       => 1,
         args         => { object_type => $object_type }
     },
@@ -40,6 +73,7 @@
 %>
 
 <% $search_region->render %>
+% }
 
 % if ($collection->pager->last_page > 1) {
     <span class="page-count"><%_('Page %1 of %2', $page, $collection->pager->last_page) %></span>   
@@ -50,12 +84,15 @@
 % }
 
 <div class="list">
+<& $list_path.'header', object_type => $object_type, list_path => $list_path, 
+    mask_field => $limit_field, mask_val => $limit_val &>
 <%perl>
 while ( my $item = $collection->next ) {
     Jifty->web->region(
         name     => 'item-' . $item->id,
         path     => $item_path,
-        defaults => { id => $item->id, object_type => $object_type }
+        defaults => { id => $item->id, object_type => $object_type, list_path => $list_path,
+                      mask_field => $limit_field , mask_val => $limit_val }
     );
 }
 
@@ -78,8 +115,9 @@
 % if ($new_slot) {
 <% Jifty->web->region(
         name => 'new_item',
-        path => "/__jifty/admin/fragments/list/new_item",
-        defaults => {   object_type => $object_type },
+        path => $list_path.'new_item',
+        defaults => {   object_type => $object_type, list_path => $list_path,
+                     mask_field => $limit_field , mask_val => $limit_val },
         ) %>
 
 % }

Modified: jifty/trunk/share/web/templates/__jifty/admin/fragments/list/new_item
==============================================================================
--- jifty/trunk/share/web/templates/__jifty/admin/fragments/list/new_item	(original)
+++ jifty/trunk/share/web/templates/__jifty/admin/fragments/list/new_item	Tue Dec  5 04:50:45 2006
@@ -1,14 +1,22 @@
 <%args>
 $object_type 
 $region
+$mask_field => ""
+$mask_val => ""
+$list_path
 </%args>
 <%init>
 my $record_class = Jifty->app_class("Model", $object_type);
- my $create = Jifty->web->new_action(class => 'Create'.$object_type);
+my $create = Jifty->web->new_action(class => 'Create'.$object_type);
 </%init>
+% if ($mask_field) {
+  <% $create->hidden($mask_field,$mask_val) %>
+% }
 <div class="jifty_admin create item inline">
 % foreach my $argument ($create->argument_names) {
+%  if ( $argument ne $mask_field ) {
         <%$create->form_field($argument)%>
+%  }
 %}
 </div>
 <%
@@ -20,9 +28,10 @@
                  { refresh_self => 1 },
                  {
                    element => $region->parent->get_element('div.list'),
-                   append => '/__jifty/admin/fragments/list/view',
+                   append => $list_path.'view',
                    args   => { 
                               object_type => $object_type,
+                              list_path => $list_path,
                               id          => { result_of => $create, name => 'id' },
                              },
                  },

Modified: jifty/trunk/share/web/templates/__jifty/admin/fragments/list/update
==============================================================================
--- jifty/trunk/share/web/templates/__jifty/admin/fragments/list/update	(original)
+++ jifty/trunk/share/web/templates/__jifty/admin/fragments/list/update	Tue Dec  5 04:50:45 2006
@@ -1,6 +1,9 @@
 <%args>
 $id => undef
 $object_type
+$mask_field => ""
+$mask_val => ""
+$list_path
 </%args>
 <%init>
 my $record_class = Jifty->app_class("Model", $object_type);
@@ -18,8 +21,8 @@
       label   => _("Save"),
       onclick => [
           { submit => $update },
-          {   replace_with => '/__jifty/admin/fragments/list/view',
-              args         => { object_type => $object_type, id => $id }
+          {   replace_with => $list_path.'view',
+              args         => { object_type => $object_type, id => $id, list_path => $list_path }
           }
       ]
       ) %>
@@ -27,16 +30,21 @@
   <% Jifty->web->link(
       label     => _("Cancel"),
       onclick   => {
-          replace_with => '/__jifty/admin/fragments/list/view',
-          args         => { object_type => $object_type, id => $id }
+          replace_with => $list_path.'view',
+          args         => { object_type => $object_type, id => $id, list_path => $list_path }
         },
       as_button => 1
   ) %>
 
 </div>
 
+% if ($mask_field) {
+<% $update->hidden($mask_field, $mask_val) %>
+% }
 % foreach my $argument ($update->argument_names) {
+%  if ( $argument ne $mask_field ) {
 <%$update->form_field($argument)%>
+%  }
 %}
 
 <hr />

Modified: jifty/trunk/share/web/templates/__jifty/admin/fragments/list/view
==============================================================================
--- jifty/trunk/share/web/templates/__jifty/admin/fragments/list/view	(original)
+++ jifty/trunk/share/web/templates/__jifty/admin/fragments/list/view	Tue Dec  5 04:50:45 2006
@@ -1,6 +1,9 @@
 <%args>
 $id => undef
 $object_type
+$mask_field => ""
+$mask_val => ""
+$list_path
 </%args>
 <%init>
 my $record_class = Jifty->app_class("Model", $object_type);
@@ -23,12 +26,12 @@
 <%
     Jifty->web->form->submit(
         class   => "editlink",
-        label   => _("Delete"),
-        submit => $delete,
-        onclick => { 
-         confirm => _("Confirm delete?"), 
-         delete =>  Jifty->web->current_region->qualified_name
-        },
+        label   => "Delete",
+        onclick => [
+         { confirm => _("Confirm delete?")},
+         { submit => $delete },
+         { delete =>  Jifty->web->current_region->qualified_name }
+        ]
         )
 %> 
 
@@ -37,16 +40,17 @@
         label   => _("Edit"),
         class   => "editlink",
         onclick => {
-            replace_with => "/__jifty/admin/fragments/list/update",
-            args         => { object_type => $object_type, id => $id }
+            replace_with => $list_path.'update',
+            args         => { object_type => $object_type, id => $id, list_path => $list_path,
+                            mask_field => $mask_field, mask_val => $mask_val }
             },
-        as_button => 1
+   #     as_button => 1
         )
 %>
 
 <% $delete->hidden('id',$id) %>
 % foreach my $argument ($update->argument_names) {
-% unless(   $argument =~ /_confirm$/
+% unless( $argument eq $mask_field ||  $argument =~ /_confirm$/
 %        && lc $update->arguments->{$argument}{render_as} eq 'password') {
   <%$update->form_field($argument, render_mode => 'read')%>
 % }


More information about the Jifty-commit mailing list