]> git.andy128k.dev Git - ipf.git/commitdiff
move admin js to bottom
authorAndrey Kutejko <andy128k@gmail.com>
Tue, 7 May 2013 20:13:08 +0000 (23:13 +0300)
committerAndrey Kutejko <andy128k@gmail.com>
Tue, 7 May 2013 20:13:08 +0000 (23:13 +0300)
ipf/admin/app.php
ipf/admin/model.php
ipf/admin/templates/admin/change.html
ipf/admin/templates/admin/changepassword.html
ipf/admin/templates/admin/login.html
ipf/admin/views.php
ipf/auth/models/User.php
ipf/form.php

index d74e91adaaa4d38a4a26e7085564773b847423f7..4e4d786a8993c5f24cb49663f6e1be12e20e34a1 100644 (file)
@@ -1,16 +1,20 @@
 <?php
 
-class IPF_Admin_App extends IPF_Application{
-    public function __construct(){
+class IPF_Admin_App extends IPF_Application
+{
+    public function __construct()
+    {
         parent::__construct(array(
            'models'=>array('AdminLog')
         ));
     }
-    public static function urls(){
+
+    public static function urls()
+    {
         return array(
             array('regex'=>'fb_rename/$#', 'func'=>'IPF_Admin_Views_FileBrowserRename'),
-               array('regex'=>'filebrowser(.+)#', 'func'=>'IPF_Admin_Views_FileBrowser'),
-               array('regex'=>'$#', 'func'=>'IPF_Admin_Views_Index'),
+            array('regex'=>'filebrowser(.+)#', 'func'=>'IPF_Admin_Views_FileBrowser'),
+            array('regex'=>'$#', 'func'=>'IPF_Admin_Views_Index'),
             array('regex'=>'([\w\_\-]+)/([\w\_\-]+)/$#i', 'func'=>'IPF_Admin_Views_ListItems'),
             array('regex'=>'([\w\_\-]+)/([\w\_\-]+)/reorder/$#i', 'func'=>'IPF_Admin_Views_Reorder'),
             array('regex'=>'([\w\_\-]+)/([\w\_\-]+)/add/$#i', 'func'=>'IPF_Admin_Views_AddItem'),
@@ -22,33 +26,30 @@ class IPF_Admin_App extends IPF_Application{
         );
     }
 
-       static function checkAdminAuth($request){
-           $ok = true;
-           if ($request->user->isAnonymous())
-               $ok = false;
-           elseif ( (!$request->user->is_staff) && (!$request->user->is_superuser) )
-               $ok = false;
+    static function checkAdminAuth($request)
+    {
+        $ok = true;
+        if ($request->user->isAnonymous())
+            $ok = false;
+        elseif ( (!$request->user->is_staff) && (!$request->user->is_superuser) )
+            $ok = false;
 
-           if ($ok)
-               return true;
-           else
-               return new IPF_HTTP_Response_Redirect(IPF_HTTP_URL_urlForView('IPF_Admin_Views_Login'));
-       }
+        if ($ok)
+            return true;
+        else
+            return new IPF_HTTP_Response_Redirect(IPF_HTTP_URL_urlForView('IPF_Admin_Views_Login'));
+    }
 
     static function GetAppModelFromSlugs($lapp, $lmodel)
     {
-        foreach (IPF_Project::getInstance()->appList() as $app)
-        {
-            if ($app->getSlug() == $lapp)
-            {
-                foreach($app->modelList() as $m)
-                {
+        foreach (IPF_Project::getInstance()->appList() as $app) {
+            if ($app->getSlug() == $lapp) {
+                foreach($app->modelList() as $m) {
                     if (strtolower($m) == $lmodel)
                         return array('app' => $app, 'modelname' => $m);
                 }
             }
         }
-
         return null;
     }
     
@@ -72,12 +73,24 @@ class IPF_Admin_App extends IPF_Application{
             
         $perms = array();
         
-        foreach (IPF_Auth_App::checkPermissions($request, $app, $m, $adminPerms) as $permName=>$permValue)
-        {
+        foreach (IPF_Auth_App::checkPermissions($request, $app, $m, $adminPerms) as $permName=>$permValue) {
             if ($permValue)
                 $perms[] = $permName;
         }
         
         return $perms;
     }
+
+    public static function renderForm($form)
+    {
+        return $form->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 class="form-group-title">%s</div>',
+            false);
+    }
 }
+
index d0d49c7f570dcd28950dbfd749182083a703b266..43f60ad663b65ee3e5805d5ee6a2a7bf12aea4f6 100644 (file)
@@ -559,7 +559,9 @@ class IPF_Admin_Model
             'mode'=>'add',
             'page_title'=>$this->titleAdd(),
             'classname'=>$this->verbose_name(),
-            'form'=>$form,
+            'form' => $form,
+            'form_html' => IPF_Admin_App::renderForm($form),
+            'extra_js' => $form->extra_js(),
             'inlineInstances'=>$this->inlineInstances,
             'lapp'=>$lapp,
             'perms'=>$perms,
@@ -656,7 +658,9 @@ class IPF_Admin_Model
             'page_title'=>$this->titleEdit(),
             'classname'=>$this->verbose_name(),
             'object'=>$o,
-            'form'=>$form,
+            'form' => $form,
+            'form_html' => IPF_Admin_App::renderForm($form),
+            'extra_js' => $form->extra_js(),
             'inlineInstances'=>$this->inlineInstances,
             'lapp'=>$lapp,
             'perms'=>$perms,
index c4a230c2fa509404dbea11c49ef754fb6e3b84f3..58e107f130b04b825f7c664b45bfb04402a3deed 100644 (file)
@@ -17,7 +17,7 @@
             {/if}
             <fieldset class="module aligned">
               {block form}
-                {$form.render_admin()}
+                {$form_html}
               {/block}
             </fieldset>
             {if $inlineInstances}
@@ -89,5 +89,8 @@ $(document).ready(function(){
 });
 {/literal}
 </script>
+{foreach $extra_js as $js}
+{$js|safe}
+{/foreach}
 {/block}
 
index 77198387fa9146970f19741e9adee2be349c7e9c..c9fd71c0d5f5d79391ea06c0dde0025fe3934aad 100644 (file)
@@ -5,26 +5,30 @@
 {block breadcrumbs}<div class="breadcrumbs"><a href="{url 'IPF_Admin_Views_Index'}">Home</a> &raquo; <a href="{url 'IPF_Admin_Views_ListItems', array($lapp, $lmodel)}">{$classname}</a> &raquo; <a href="{url 'IPF_Admin_Views_EditItem', array($lapp, $lmodel, $object.id)}">{$object}</a> &raquo; Change Password</div>{/block}
 
 {block content}
-
 <div id="content" class="colM">
-    <h1>{$page_title}</h1>
-       <div id="content-main">
-           <form method="post" action="">
-           <div>
-               {if $form.errors}
-            <p class="errornote">Please correct the error below.</p>
-            {/if}
-               <fieldset class="module aligned">
-               {$form.render_admin()}
-                       </fieldset>
-               <div class="submit-row">
-                   <input type="submit" value="Change password" class="default" />
-                <input type="button" value="Cancel" onclick="javascript:history.back();" />
-               </div>
-           </div>
-           </form>
-       </div>    
+  <h1>{$page_title}</h1>
+  <div id="content-main">
+    <form method="post" action="">
+      <div>
+        {if $form.errors}
+          <p class="errornote">Please correct the error below.</p>
+        {/if}
+        <fieldset class="module aligned">
+          {$form_html}
+        </fieldset>
+        <div class="submit-row">
+          <input type="submit" value="Change password" class="default" />
+          <input type="button" value="Cancel" onclick="javascript:history.back();" />
+        </div>
+      </div>
+    </form>
+  </div>
 </div>
+{/block}
 
+{block scripts}
+{foreach $extra_js as $js}
+{$js|safe}
+{/foreach}
 {/block}
 
index 55e98fa9b953ab47d03cd919e1aa2c347184e9e3..c347baf95087827b6fb951be30c13e0216ecfdf3 100644 (file)
@@ -5,18 +5,25 @@
 {block usertools}{/block}
 
 {block content}
-    <div id="content" class="colM">
-        <div id="content-main">    
-                   <form method="post">
-                   {if $form.message}<ul class="errorlist"><li>{$form.message}</li></ul>{/if}
-                   {$form.render_admin()}
-                   <div class="submit-row">
-                       <input type="submit" value="Sign In" class="default" />
-                   </div>
-                   </form>    
-        </div>
-    </div>
-    <script type="text/javascript">
-        document.getElementById('id_username').focus();
-    </script>
+<div id="content" class="colM">
+  <div id="content-main">
+    <form method="post">
+      {if $form.message}<ul class="errorlist"><li>{$form.message}</li></ul>{/if}
+      {$form_html}
+      <div class="submit-row">
+        <input type="submit" value="Sign In" class="default" />
+      </div>
+    </form>
+  </div>
+</div>
 {/block}
+
+{block scripts}
+{foreach $extra_js as $js}
+{$js|safe}
+{/foreach}
+<script type="text/javascript">
+  document.getElementById('id_username').focus();
+</script>
+{/block}
+
index 2d64b99d9338f0497d1ad05890ee5da25e54f4bf..4afe2da85797ffbd73b38cc6d89b818146025b14 100644 (file)
@@ -259,7 +259,8 @@ function IPF_Admin_Views_ChangePassword($request, $match)
                 'page_title'=>'Change Password: '.$user->username,
                 'classname'=>'User',
                 'object'=>$user,
-                'form'=>$form,
+                'form' => $form,
+                'form_html' => IPF_Admin_App::renderForm($form),
                 'lapp'=>$lapp,
                 'lmodel'=>$lmodel,
                 'admin_title' => IPF::get('admin_title'),
@@ -273,7 +274,8 @@ function IPF_Admin_Views_ChangePassword($request, $match)
     return new IPF_HTTP_Response_NotFound();
 }
 
-function IPF_Admin_Views_Login($request, $match){
+function IPF_Admin_Views_Login($request, $match)
+{
     $success_url = '';
     if (!empty($request->REQUEST['next']))
         $success_url = $request->REQUEST['next'];
@@ -282,7 +284,7 @@ function IPF_Admin_Views_Login($request, $match){
 
     if ($request->method == 'POST') {
         $form = new IPF_Auth_Forms_Login($request->POST);
-        if ($form->isValid()){
+        if ($form->isValid()) {
             $users = new User();
             if (false === ($user = $users->checkCreditentials($form->cleaned_data['username'], $form->cleaned_data['password']))) {
                 $form->message = __('The login or the password is not valid. The login and the password are case sensitive.');
@@ -291,19 +293,21 @@ function IPF_Admin_Views_Login($request, $match){
                 return new IPF_HTTP_Response_Redirect($success_url);
             }
         }
-    }
-    else
+    } else {
         $form = new IPF_Auth_Forms_Login(array('next'=>$success_url));
+    }
     $context = array(
-       'page_title' => IPF::get('admin_title'),
-       'form' => $form,
-       'admin_title' => IPF::get('admin_title'),
-       'indexpage_url'=>IPF::get('indexpage_url','/'),
+        'page_title' => IPF::get('admin_title'),
+        'form' => $form,
+        'form_html' => IPF_Admin_App::renderForm($form),
+        'admin_title' => IPF::get('admin_title'),
+        'indexpage_url'=>IPF::get('indexpage_url','/'),
     );
     return IPF_Shortcuts::RenderToResponse('admin/login.html', $context, $request);
 }
 
-function IPF_Admin_Views_Logout($request, $match){
+function IPF_Admin_Views_Logout($request, $match)
+{
     IPF_Auth_App::logout($request);
     $context = array(
        'page_title' => IPF::get('admin_title'),
@@ -313,14 +317,15 @@ function IPF_Admin_Views_Logout($request, $match){
     return IPF_Shortcuts::RenderToResponse('admin/logout.html', $context, $request);
 }
 
-function cmp($a, $b){
-    if ($a['name'] == $b['name']) {
+function cmp($a, $b)
+{
+    if ($a['name'] == $b['name'])
         return 0;
-    }
     return ($a['name'] < $b['name']) ? -1 : 1;
 }
 
-function dir_recursive($dir, $path=DIRECTORY_SEPARATOR, $level=''){
+function dir_recursive($dir, $path=DIRECTORY_SEPARATOR, $level='')
+{
     $dirtree = array();
     if ($level=='')
         $dirtree[] = array('path'=>'', 'name'=>'Root Folder');
index 2edb48a284cbae391ff5e7b0d962d87b3e4faaf2..a09afc4df815e0b64733f6e694afca8ea69b6549 100644 (file)
@@ -45,24 +45,25 @@ class IPFAuthAdminUserForm extends IPF_Form_Extra_CheckGroup
             
             $account = array('username', 'password');
         }
-        
-        if (IPF_Auth_App::ArePermissionsEnabled())
-        {
+
+        $permissions = array('is_active', 'is_staff', 'is_superuser');
+        if (IPF_Auth_App::ArePermissionsEnabled()) {
+            $permissions[] = 'Permissions';
+            $permissions[] = 'Roles';
+
             $this->fields['Roles']->label = 'Groups';
             $this->fields['Roles']->help_text = 'In addition to the permissions manually assigned, this user will also get all permissions granted to each group he/she is in.';
 
             parent::SetupForm($this);            
-        }
-        else
-        {
+        } else {
             unset($this->fields['Permissions']);
             unset($this->fields['Roles']);
         }
-        
+
         $this->field_groups = array(
             array('fields' => $account),
             array('fields' => array('email', 'first_name', 'last_name'), 'label' => 'Personal info'),
-            array('fields' => array('is_active', 'is_staff', 'is_superuser','Permissions','Roles'), 'label' => 'Permissions'),
+            array('fields' => $permissions, 'label' => 'Permissions'),
         );
     }
     
index c490ca97752a3f3b6442ede89e1098358219d986..3d4e93d8b5ab015a1195d0455638316e24c6e100 100644 (file)
@@ -122,41 +122,32 @@ 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, $group_title=null)
+    public function htmlOutput($normal_row, $error_row, $row_ender,
+                               $help_text_html, $errors_on_separate_row, $group_title=null,
+                               $extra_js=true)
     {
         $top_errors = (isset($this->errors['__all__'])) ? $this->errors['__all__'] : array();
         array_walk($top_errors, 'IPF_Form_htmlspecialcharsArray');
         $output = array();
         $hidden_fields = array();
-        
-        $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;
-                    }
-                }
-            }
+
+        foreach ($this->field_groups as $field_group) {
+            if (!$field_group['fields'])
+                throw new IPF_Exception('Empty field group.');
+            foreach ($field_group['fields'] as $field_name)
+                if (!array_key_exists($field_name, $this->fields))
+                    throw new IPF_Exception('Unknown field "' . $field_name . '".');
+        }
+
+        $groups = array();
+        foreach ($this->field_groups as $field_group) {
+            $_fields = array();
+            foreach ($field_group['fields'] as $field_name)
+                $_fields[$field_name] = $this->fields[$field_name];
+            $groups[] = array(
+                'fields' => $_fields,
+                'label' => @$field_group['label'],
+            );
         }
         
         if (count($groups)) {
@@ -167,7 +158,7 @@ class IPF_Form implements Iterator
         }
 
         foreach ($groups as $group) {
-            if ($render_group_title && array_key_exists('label', $group))
+            if ($render_group_title && isset($group['label']))
                 $output[] = sprintf($group_title, $group['label']);
 
             foreach ($group['fields'] as $name=>$field) {
@@ -236,15 +227,20 @@ class IPF_Form implements Iterator
             }
         }
 
-        $extra_js = array();
-        foreach ($groups as $group)
-            foreach ($group['fields'] as $name => $field)
-                $extra_js = array_merge($extra_js, $field->widget->extra_js());
-        $output[] = implode("\n", array_unique($extra_js));
+        if ($extra_js)
+            $output = array_merge($output, $this->extra_js());
 
         return new IPF_Template_SafeString($this->before_render . implode("\n", $output) . $this->after_render, true);
     }
 
+    public function extra_js()
+    {
+        $extra_js = array();
+        foreach ($this->fields as $name => $field)
+            $extra_js = array_merge($extra_js, $field->widget->extra_js());
+        return array_unique($extra_js);
+    }
+
     public function render_p()
     {
         return $this->htmlOutput('<p>%1$s%2$s %3$s%4$s</p>', '%s', '</p>', ' %s', true);