Author: david
Date: Tue Sep 15 13:57:03 2009
New Revision: 3319

Log:
Update user/edit action & template to match current design. Add user 
permissions tables.

Added:
   trunk/apps/qubit/modules/user/config/view.yml
Modified:
   trunk/apps/qubit/modules/user/actions/editAction.class.php
   trunk/apps/qubit/modules/user/templates/editSuccess.php

Modified: trunk/apps/qubit/modules/user/actions/editAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/user/actions/editAction.class.php  Tue Sep 15 
12:56:23 2009        (r3318)
+++ trunk/apps/qubit/modules/user/actions/editAction.class.php  Tue Sep 15 
13:57:03 2009        (r3319)
@@ -19,19 +19,100 @@
 
 class UserEditAction extends sfAction
 {
+  public static $NAMES = array(
+    'username',
+    'email',
+    'password',
+    'groups'
+  );
+
+  protected function addField($name)
+  {
+    switch ($name)
+    {
+      case 'username':
+        $this->form->setDefault($name, $this->user[$name]);
+        $this->form->setValidator($name, new sfValidatorString);
+        $this->form->setWidget($name, new sfWidgetFormInput);
+        break;
+      case 'email':
+        $this->form->setDefault($name, $this->user[$name]);
+        $this->form->setValidator($name, new sfValidatorEmail);
+        $this->form->setWidget($name, new sfWidgetFormInput);
+        break;
+      case 'password':
+        $this->form->setDefault($name, null);
+        $this->form->setValidator($name, new sfValidatorString);
+        $this->form->setWidget($name, new sfWidgetFormInputPassword);
+        break;
+      case 'groups':
+        $criteria = new Criteria;
+        $this->user->addaclUserGroupsCriteria($criteria);
+
+        $values = array();
+        $choices = array();
+        foreach ($this->userGroups = QubitAclUserGroup::get($criteria) as 
$userGroup)
+        {
+          $values[] = $this->context->routing->generate(null, array('module' 
=> 'aclGroup', 'action' => 'show', 'id' => $userGroup->groupId));
+          $choices[$this->context->routing->generate(null, array('module' => 
'aclGroup', 'action' => 'show', 'id' => $userGroup->groupId))] = 
$userGroup->group->name;
+        }
+
+        $this->form->setDefault('groups', $values);
+        $this->form->setValidator('groups', new sfValidatorPass);
+        $this->form->setWidget('groups', new 
sfWidgetFormSelect(array('choices' => $choices, 'multiple' => true)));
+
+        break;
+    }
+  }
+
   public function execute($request)
   {
-    $this->user = QubitUser::getById($this->getRequestParameter('id'));
-    $this->forward404Unless($this->user);
+    $this->user = new QubitUser;
+
+    if (isset($this->request->id))
+    {
+      $this->user = QubitUser::getById($this->request->id);
 
-    $this->newRoleRelation = new QubitUserRoleRelation;
+      if (!isset($this->user))
+      {
+        $this->forward404();
+      }
+    }
 
+    $this->form = new sfForm;
+    $this->form->getValidatorSchema()->setOption('allow_extra_fields', true);
+
+    // HACK: Use static::$NAMES in PHP 5.3,
+    // http://php.net/oop5.late-static-bindings
+    $class = new ReflectionClass($this);
+    foreach ($class->getStaticPropertyValue('NAMES') as $name)
+    {
+      $this->addField($name);
+    }
+
+    $this->permissions = $this->user->getAclPermissions();
+
+    $this->credentials = $this->user->getUserCredentials();
     $this->isAdministrator = false;
     if ($this->getUser()->hasCredential('administrator'))
-      {
+    {
       $this->isAdministrator = true;
+    }
+
+    if ($request->isMethod('post'))
+    {
+      $this->form->bind($request->getPostParameters());
+
+      if ($this->form->isValid())
+      {
+        $this->processForm();
+        $this->redirect(array('module' => 'user', 'action' => 'show', 'id' => 
$this->user->id));
       }
+    }
+  }
 
-   $this->credentials = $this->user->getUserCredentials();
+  protected function processForm()
+  {
+    return $this;
   }
 }

Added: trunk/apps/qubit/modules/user/config/view.yml
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/apps/qubit/modules/user/config/view.yml       Tue Sep 15 13:57:03 
2009        (r3319)
@@ -0,0 +1,2 @@
+editSuccess:
+  javascripts: [autocomplete, /sfDrupalPlugin/vendor/drupal/misc/collapse, 
/sfDrupalPlugin/vendor/drupal/misc/textarea]
\ No newline at end of file

Modified: trunk/apps/qubit/modules/user/templates/editSuccess.php
==============================================================================
--- trunk/apps/qubit/modules/user/templates/editSuccess.php     Tue Sep 15 
12:56:23 2009        (r3318)
+++ trunk/apps/qubit/modules/user/templates/editSuccess.php     Tue Sep 15 
13:57:03 2009        (r3319)
@@ -1,66 +1,149 @@
-<div class="pageTitle"><?php echo __('edit user'); ?></div>
+<?php use_helper('Javascript') ?>
+<?php 
$sf_response->addStylesheet('/vendor/yui/autocomplete/assets/skins/sam/autocomplete')
 ?>
 
-<?php echo form_tag('user/update') ?>
+<?php $sf_response->addJavaScript('/vendor/yui/datasource/datasource-min') ?>
+<?php $sf_response->addJavaScript('/vendor/yui/connection/connection-min') ?>
+<?php $sf_response->addJavaScript('/vendor/yui/animation/animation-min') ?>
+<?php $sf_response->addJavaScript('/vendor/yui/json/json-min') ?>
+<?php $sf_response->addJavaScript('/vendor/yui/autocomplete/autocomplete-min') 
?>
+<?php $sf_response->addJavaScript('/js/qubit') ?>
+
+<div class="pageTitle">
+  <?php if (isset($sf_request->id)): ?>
+  <?php echo __('Edit user') ?>
+  <?php else: ?>
+  <?php echo __('Create new user') ?>
+  <?php endif; ?>
+</div>
+
+<form method="post" action="<?php echo url_for(array('module' => 'user', 
'action' => 'edit', 'id' => $user->id)) ?>">
 
-<?php echo object_input_hidden_tag($user, 'getId') ?>
+<div class="formHeader">
+  <?php if (isset($sf_request->id)): ?>
+  <?php echo link_to(__('%1% profile', array('%1%' => $user->username)), 
array('module' => 'user', 'action' => 'show', 'id' => $user->id)) ?>
+  <?php else: ?>
+  <?php echo __('new user') ?>
+  <?php endif; ?>
+</div>
 
-<table class="detail">
-<tbody>
+<fieldset class="collapsible" id="detailsArea">
+  <legend><?php echo __('basic info')?></legend>
 
-<tr><td colspan="2" class="headerCell"><?php echo link_to(__('%1% profile', 
array('%1%' => $user)), array('module' => 'user', 'action' => 'show', 'id' => 
$user->id)) ?></td></tr>
-<tr>
-
-<tr>
-  <th><?php echo __('user name'); ?></th>
-  <td>
-      <?php echo object_input_tag($user, 'getUsername', array ('size' => 20)) 
?>
-   </td>
-</tr>
-
-<tr>
-  <th><?php echo __('email'); ?></th>
-  <td><?php echo object_input_tag($user, 'getEmail', array ('size' => 20)) 
?></td>
-</tr>
-
-<tr>
-  <th><?php echo __('password'); ?></th>
-<td><?php echo link_to(__('reset password'), 
'user/passwordEdit?id='.$user->getId()) ?></td>
-</tr>
-
-<tr><th><?php echo __('user roles'); ?></th><td style="font: normal 12px/12px 
Verdana, Arial, Sans-Serif;">
-      <?php foreach ($user->getUserRoleRelations() as $roleRelation): ?>
-      <?php echo $roleRelation->getRole() ?>&nbsp;
-      <?php echo link_to(image_tag('delete', 'align=top'), 
'user/deleteRoleRelation?role_relation_id='.$roleRelation->getId()) ?>
-      <br />
-      <?php endforeach; ?>
+  <?php echo render_field($form->username, $user) ?>
+  <?php echo render_field($form->email, $user) ?>
 
-     <?php echo object_select_tag($newRoleRelation, 'getRoleId', 
array('related_class' => 'QubitRole', 'include_blank' => true, 'peer_method' => 
'getAll')) ?>
-</td></tr>
+  <div class="form-item">
+    <?php echo $form->password->label(__('change password'))->renderLabel() ?>
+    <?php echo $form->password->render() ?>
+  </div>
+</fieldset>
+
+<fieldset class="collapsible collapsed" id="groupsAndPermissions">
+  <legend><?php echo __('groups and permissions')?></legend>
+
+  <div class="form-item">
+    <div style="width: 98%">
+      <?php echo $form->groups->label(__('groups'))->renderLabel() ?>
+      <?php echo $form->groups->render(array('class' => 'form-autocomplete')) 
?>
+      <input class="list" type="hidden" value="<?php echo 
url_for(array('module' => 'aclGroup', 'action' => 'list')) ?>"/>
+    </div>
+  </div>
+
+  <table class="inline">
+    <caption><?php echo __('Existing permissions'); ?></caption>
+    <thead>
+      <tr>
+        <th style="width: 20%"><?php echo __('action') ?></th>
+        <th style="width: 15%"><?php echo __('grant/deny') ?></th>
+        <th style="width: 60%"><?php echo __('repository') ?></th>
+        <th style="width: 5%"><?php echo image_tag('delete', array('align' => 
'top', 'class' => 'deleteIcon')) ?></th>
+      </tr>
+    </thead>
+    <tbody>
+      <?php foreach ($permissions as $permission): ?>
+        <?php $parameters = array() ?>
+        <tr id="<?php echo 'permission_'.$permission->id ?>" class="<?php echo 
'related_obj_'.$permission->id ?>">
+          <td><?php echo 
$permission->getAction()->getName(array('cultureFallback' => true)) ?></td>
+          <td>
+            <ul class="radio_list">
+              <li><?php echo 
radiobutton_tag('permission['.$permission->id.'][grantDeny]', '1', ('1' == 
$permission->grantDeny)) ?>&nbsp;<label><?php echo __('grant')?></label></li>
+              <li><?php echo 
radiobutton_tag('permission['.$permission->id.'][grantDeny]', '0', ('1' != 
$permission->grantDeny)) ?>&nbsp;<label><?php echo __('deny')?></label></li>
+            </ul>
+          </td>
+          <td>
+            <div style="width: 100%">
+            <select name="permission[<?php echo $permission->id 
?>][repository]" class="form-autocomplete" id="repository">
+            <?php if (null !== ($repository = $permission->getRepository())): 
?>
+              <option value="<?php echo 
$this->context->routing->generate(null, array('module' => 'repository', 
'action' => 'show', 'id' => $repository->id)) ?>" selected="selected"><?php 
echo $repository->getAuthorizedFormOfName(array('cultureFallback' => true)) 
?></option>
+            <?php endif; ?>
+            </select>
+            <input class="list" type="hidden" value="<?php echo 
$this->context->routing->generate(null, array('module' => 'repository', 
'action' => 'list')) ?>" />
+            </div>
+          </td>
+          <td>
+            <input type="checkbox" name="deletePermission[<?php echo 
$permission->id ?>]" value="delete" class="multiDelete" />
+          </td>
+        </tr>
+      <?php endforeach; ?>
+    </tbody>
+  </table>
 
-</tbody>
-</table>
+  <table class="inline">
+    <caption><?php echo __('Add a new permission'); ?></caption>
+    <thead>
+      <tr>
+        <th style="width: 20%"><?php echo __('action') ?></th>
+        <th style="width: 15%"><?php echo __('grant/deny') ?></th>
+        <th style="width: 60%"><?php echo __('repository') ?></th>
+        <th style="width: 5%">&nbsp;</th>
+      </tr>
+    </thead>
+    <tbody>
+      <tr>
+        <td>
+          <?php echo object_select_tag('', '',
+            array('name' => 'permission[new][actionId]', 'id' => 
'permission_new_actionId', 'related_class' => 'QubitAclAction', 'include_blank' 
=> true)) ?>
+        </td>
+        <td>
+          <ul class="radio_list">
+            <li><?php echo radiobutton_tag('permission[new][grantDeny]', '1', 
true) ?>&nbsp;<label><?php echo __('grant')?></label></li>
+            <li><?php echo radiobutton_tag('permission[new][grantDeny]', '0', 
false) ?>&nbsp;<label><?php echo __('deny')?></label></li>
+          </ul>
+        </td>
+        <td>
+          <div style="width: 100%">
+          <select name="permission[new][repository]" class="form-autocomplete" 
id="newRepository"></select>
+          <input class="list" type="hidden" value="<?php echo 
$this->context->routing->generate(null, array('module' => 'repository', 
'action' => 'list')) ?>" />
+          </div>
+        </td>
+        <td>&nbsp;</td>
+      </tr>
+    </tbody>
+  </table>
+</fieldset>
 
 <!-- include empty div at bottom of form to bump the fixed button-block and 
allow user to scroll past it -->
 <div id="button-block-bump"></div>
 
 <div id="button-block">
-<div class="menu-action">
-<?php if (SecurityCheck::HasPermission($sf_user, array('module' => 'user', 
'action' => 'delete'))): ?>
-  <?php if ($user->getId()): ?>
-  &#160;<?php echo link_to(__('delete'), 'user/delete?id='.$user->getId(), 
'post=true&confirm='.__('are you sure?')) ?>
-  <?php endif; ?>
-<?php endif; ?>
-&#160;<?php echo link_to(__('cancel'), 'user/show?id='.$user->getId()) ?>
-<?php if ($user->getId()): ?>
-  <?php echo submit_tag(__('save')) ?>
-<?php else: ?>
-  <?php echo submit_tag(__('create')) ?>
-<?php endif; ?>
+  <div class="menu-action">
+    <?php if (SecurityCheck::HasPermission($sf_user, array('module' => 'user', 
'action' => 'delete'))): ?>
+      <?php if ($user->getId()): ?>
+      &#160;<?php echo link_to(__('delete'), 'user/delete?id='.$user->getId(), 
'post=true&confirm='.__('are you sure?')) ?>
+      <?php endif; ?>
+    <?php endif; ?>
+    &#160;<?php echo link_to(__('cancel'), 'user/show?id='.$user->getId()) ?>
+    <?php if ($user->getId()): ?>
+      <?php echo submit_tag(__('save')) ?>
+    <?php else: ?>
+      <?php echo submit_tag(__('create')) ?>
+    <?php endif; ?>
+  </div>
+
+  <div class="menu-extra">
+    <?php echo link_to(__('add new'), 'user/create'); ?>
+    <?php echo link_to(__('list all users'), 'user/list'); ?>
+  </div>
 </div>
-</form>
 
-<div class="menu-extra">
-  <?php echo link_to(__('add new'), 'user/create'); ?>
-  <?php echo link_to(__('list all users'), 'user/list'); ?>
-</div>
-</div>
+</form>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.ca/group/qubit-commits?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to