]> git.andy128k.dev Git - ipf.git/commitdiff
IPF_Form is added
authorandrevv <andrey.vusaty@gmail.com>
Thu, 2 Dec 2010 19:52:19 +0000 (21:52 +0200)
committerandrevv <andrey.vusaty@gmail.com>
Thu, 2 Dec 2010 19:52:19 +0000 (21:52 +0200)
ipf/admin/media/css/forms.css
ipf/auth/models/User.php
ipf/form.php

index 0687c11699c1aacf11699e3b94a5f54ad6db5b41..848321de2e7305f037d0de9ac870dbcd096f990a 100644 (file)
@@ -6,6 +6,13 @@
 .form-row img, .form-row input { vertical-align:middle; }
 form .form-row p { padding-left:0; font-size:11px; }
 
+/* FORM GROUP TITLE */
+.form-group-title {
+    background-color:#CFCFCF; 
+    padding:2px 8px 3px 16px; font-size:12px;  color:#006A95;  border-top:1px solid #CCC; border-bottom:1px solid #CCC; text-align:left;
+    font-weight:bold;
+}
+
 /* FORM LABELS */
 form h4 { margin:0 !important; padding:0 !important; border:none !important; }
 label { font-weight:normal !important; color:#666; font-size:12px; }
index 5d3bd96b817cad119d90e9a2dc5324435335a298..6bedd6c57ca89c2e300dbc9ecc3024a39e11d396 100644 (file)
@@ -9,6 +9,22 @@ class AdminUser extends IPF_Admin_Model{
     protected function _setupForm($form){
         $form->fields['username']->help_text = 'Required. 32 characters or less. Alphanumeric characters only (letters, digits and underscores).';
         $form->fields['password']->help_text = "Use '[algo]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>.";
+        
+        $form->fields['email']->label = 'E-mail';
+        
+        $form->fields['is_active']->label    = 'Active';
+        $form->fields['is_staff']->label     = 'Staff status';
+        $form->fields['is_superuser']->label = 'Superuser status';
+
+        $form->fields['is_active']->help_text    = 'Designates whether this user should be treated as active. Unselect this instead of deleting accounts.';
+        $form->fields['is_staff']->help_text     = 'Designates whether the user can log into this admin site.';
+        $form->fields['is_superuser']->help_text = 'Designates that this user has all permissions without explicitly assigning them.';
+        
+        $form->field_groups = array(
+            array('fields'=>array('username', 'password')),
+            array('fields'=>array('email', 'first_name', 'last_name'), 'label'=>'Personal info'),
+            array('fields'=>array('is_active', 'is_staff', 'is_superuser'), 'label'=>'Permissions'),
+        );
     }
 
     public function AddItem($request, $lapp, $lmodel){
index b8f6c452ae4688b0902b6b387ab9906c9ae6ccfe..29f9f61e66173027bffbd71a1097ecd78a2273d0 100644 (file)
@@ -3,6 +3,7 @@
 class IPF_Form implements Iterator
 {
     public $fields = array();
+    public $field_groups = array();
 
     public $prefix = '';
     public $id_fields = 'id_%s';
@@ -121,57 +122,100 @@ class IPF_Form implements Iterator
     {
         return (isset($this->errors['__all__'])) ? $this->errors['__all__'] : array();
     }
-
+    
     protected function htmlOutput($normal_row, $error_row, $row_ender,
-                                  $help_text_html, $errors_on_separate_row)
+                                  $help_text_html, $errors_on_separate_row, $group_title=null)
     {
         $top_errors = (isset($this->errors['__all__'])) ? $this->errors['__all__'] : array();
         array_walk($top_errors, 'IPF_Form_htmlspecialcharsArray');
         $output = array();
         $hidden_fields = array();
-        foreach ($this->fields as $name=>$field) {
-            $bf = new IPF_Form_BoundField($this, $field, $name);
-            $bf_errors = $bf->errors;
-            array_walk($bf_errors, 'IPF_Form_htmlspecialcharsArray');
-            if ($field->widget->is_hidden) {
-                foreach ($bf_errors as $_e) {
-                    $top_errors[] = sprintf(__('(Hidden field %1$s) %2$s'),
-                                            $name, $_e);
-                }
-                $hidden_fields[] = $bf; // Not rendered
-            } else {
-                if ($errors_on_separate_row and count($bf_errors)) {
-                    $output[] = sprintf($error_row, IPF_Form_renderErrorsAsHTML($bf_errors));
-                }
-                if (strlen($bf->label) > 0) {
-                    $label = htmlspecialchars($bf->label, ENT_COMPAT, 'UTF-8');
-                    if ($this->label_suffix) {
-                        if (!in_array(mb_substr($label, -1, 1),
-                                      array(':','?','.','!'))) {
-                            $label .= $this->label_suffix;
-                        }
+        
+        $groups = array();        
+        
+        if (count($this->field_groups))
+        {
+            foreach ($this->field_groups as $field_group)
+            {
+                if (array_key_exists('fields', $field_group) && is_array($field_group['fields']))
+                {
+                    $_fields = array();
+                
+                    foreach ($field_group['fields'] as $field_name)
+                    {
+                        if (array_key_exists($field_name, $this->fields))
+                            $_fields[$field_name] = $this->fields[$field_name];
+                    }
+                    
+                    if (count($_fields))
+                    {
+                        $_group = array('fields'=>$_fields);
+                        
+                        if (array_key_exists('label', $field_group))
+                            $_group['label'] = $field_group['label'];
+                        
+                        $groups[] = $_group;
                     }
-                    if ($field->required)
-                        $label_attrs = array('class'=>'required');
-                    else
-                        $label_attrs = array();
-                    $label = $bf->labelTag($label,$label_attrs);
-                } else {
-                    $label = '';
                 }
-                if ($bf->help_text) {
-                    // $bf->help_text can contains HTML and is not
-                    // escaped.
-                    $help_text = sprintf($help_text_html, $bf->help_text);
+            }
+        }
+        
+        if (!count($groups))
+        {
+            $groups = array(array('fields'=>$this->fields));
+            $render_group_title = false;
+        }
+        else $render_group_title = $group_title ? true : false;
+        
+        foreach ($groups as $group)
+        {
+            if ($render_group_title && array_key_exists('label', $group))
+                $output[] = sprintf($group_title, $group['label']);
+            
+            foreach ($group['fields'] as $name=>$field) {
+                $bf = new IPF_Form_BoundField($this, $field, $name);
+                $bf_errors = $bf->errors;
+                array_walk($bf_errors, 'IPF_Form_htmlspecialcharsArray');
+                if ($field->widget->is_hidden) {
+                    foreach ($bf_errors as $_e) {
+                        $top_errors[] = sprintf(__('(Hidden field %1$s) %2$s'),
+                                                $name, $_e);
+                    }
+                    $hidden_fields[] = $bf; // Not rendered
                 } else {
-                    $help_text = '';
-                }
-                $errors = '';
-                if (!$errors_on_separate_row and count($bf_errors)) {
-                    $errors = IPF_Form_renderErrorsAsHTML($bf_errors);
+                    if ($errors_on_separate_row and count($bf_errors)) {
+                        $output[] = sprintf($error_row, IPF_Form_renderErrorsAsHTML($bf_errors));
+                    }
+                    if (strlen($bf->label) > 0) {
+                        $label = htmlspecialchars($bf->label, ENT_COMPAT, 'UTF-8');
+                        if ($this->label_suffix) {
+                            if (!in_array(mb_substr($label, -1, 1),
+                                        array(':','?','.','!'))) {
+                                $label .= $this->label_suffix;
+                            }
+                        }
+                        if ($field->required)
+                            $label_attrs = array('class'=>'required');
+                        else
+                            $label_attrs = array();
+                        $label = $bf->labelTag($label,$label_attrs);
+                    } else {
+                        $label = '';
+                    }
+                    if ($bf->help_text) {
+                        // $bf->help_text can contains HTML and is not
+                        // escaped.
+                        $help_text = sprintf($help_text_html, $bf->help_text);
+                    } else {
+                        $help_text = '';
+                    }
+                    $errors = '';
+                    if (!$errors_on_separate_row and count($bf_errors)) {
+                        $errors = IPF_Form_renderErrorsAsHTML($bf_errors);
+                    }
+                    $output[] = sprintf($normal_row, $errors, $label,
+                                        $bf->render_w(), $help_text);
                 }
-                $output[] = sprintf($normal_row, $errors, $label,
-                                    $bf->render_w(), $help_text);
             }
         }
         if (count($top_errors)) {
@@ -218,7 +262,8 @@ class IPF_Form implements Iterator
         return $this->htmlOutput(
                        '<div class="form-row"><div>%2$s %1$s%3$s%4$s</div></div>',
             '<div>%s</div>',
-            '</div>', '<p class="help">%s</p>', true
+            '</div>', '<p class="help">%s</p>', true,
+            '<div class="form-group-title">%s</div>'
         );
     }