incubator-esme-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vdic...@apache.org
Subject svn commit: r784972 - in /incubator/esme/branches/access-pools/server/src/main: scala/org/apache/esme/lib/AccessPoolMgr.scala webapp/pools_view/index.html
Date Mon, 15 Jun 2009 20:53:21 GMT
Author: vdichev
Date: Mon Jun 15 20:53:20 2009
New Revision: 784972

URL: http://svn.apache.org/viewvc?rev=784972&view=rev
Log:
Display pools to administer via ajax.

Modified:
    incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/lib/AccessPoolMgr.scala
    incubator/esme/branches/access-pools/server/src/main/webapp/pools_view/index.html

Modified: incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/lib/AccessPoolMgr.scala
URL: http://svn.apache.org/viewvc/incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/lib/AccessPoolMgr.scala?rev=784972&r1=784971&r2=784972&view=diff
==============================================================================
--- incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/lib/AccessPoolMgr.scala
(original)
+++ incubator/esme/branches/access-pools/server/src/main/scala/org/apache/esme/lib/AccessPoolMgr.scala
Mon Jun 15 20:53:20 2009
@@ -52,9 +52,13 @@
   val menuItems =
   Menu(Loc("accessPools", List("pools_view", "index"), "Manage Access Pools", ifIsLoggedIn,
            Loc.Snippet("addPool", addPool),
-           Loc.Snippet("editPool", editPool))) ::
+           Loc.Snippet("editPool", editPool),
+           Loc.Snippet("poolUsers", displayPoolUsers))) ::
   Nil
 
+  object updatePool extends RequestVar[() => JsCmd](() => Noop)
+  object poolId extends RequestVar[Long](0)
+
   def addPool(in: NodeSeq): NodeSeq = {
     val theInput = "new_pool"
     val user = User.currentUser
@@ -72,6 +76,7 @@
                 S.notice("New pool added")
               else
                 S.error("Could not add pool!")
+            case _ => S.error("Could not add pool!")
           }
         }
       }
@@ -85,6 +90,8 @@
   }
 
   def editPool(in: NodeSeq): NodeSeq = {
+    val redisplayPool = updatePool.is
+    
     var pool = ""
     var username = ""
     val editPoolName = "edit_pool"
@@ -92,15 +99,16 @@
     val editPermission = "edit_permission"
     val adminUser = User.currentUser
     
-    val adminPools = adminUser match {
+    val adminPools = ("0", "--choose pool--") ::
+    (adminUser match {
       case Full(u)=> Privilege.findAdminPools(u.id).map(
         p => (p.toString, AccessPool.find(p).get.getName))
       case _ => Nil
-    }
+    })
       
     val permissions = Permission.map(perm => (perm.id.toString, perm.toString)).collect
     
-    def addUserPool(permission: String) = {
+    def addPoolUser(permission: String): JsCmd = {
       val r: Box[Boolean] = 
       for (admin <- adminUser;
            p <- AccessPool.find(pool) ?~ "Pool not found";
@@ -113,15 +121,45 @@
       r match {
         case Failure(m,_,_) => S.error(m)
         case Full(true) => S.notice("Successfully set user privileges in pool")
-        case Full(false) => S.error("Could not set user privileges in pool")
+        case _ => S.error("Could not set user privileges in pool")
       }
+      
+      poolId.set(pool.toLong)
+      redisplayPool() & SetValById(editUsername, "")
     }
 
     bind("edit", in,
-         "pool" -> select(adminPools, Empty, pool = _, "id" -> editPoolName),
+         "pool" -> ajaxSelect(adminPools, Empty, p => {pool = p;
+                                                       poolId.set(p.toLong);
+                                                       redisplayPool()},
+                                                 "id" -> editPoolName),
          "username" -> text(username, username = _, "id" -> editUsername),
-         "permission" -> select(permissions, Empty, addUserPool, "id" -> editPermission)
+         "permission" -> select(permissions, Empty, addPoolUser, "id" -> editPermission)
     )
     
   }
+  
+  def displayPoolUsers(in: NodeSeq): NodeSeq = {
+    // get the span name to update
+    val spanName = S.attr("the_id") openOr "PoolSpan"
+    // get the current user
+    val user = User.currentUser
+
+    def doRender(): NodeSeq =
+    Privilege.findAll(By(Privilege.pool, poolId.is)) match {
+      case Nil => NodeSeq.Empty
+      case xs => bind("pool", in,
+                      "user" -> 
+                      (lst => xs.flatMap(i => bind("user", lst,
+                                                   "name" -> User.find(i.user).get.nickname.is,
+                                                   "privilege" -> i.permission.is.toString
+                      ))))
+    }
+    
+
+    def updateSpan(): JsCmd = SetHtml(spanName, doRender())
+
+    updatePool.set(updateSpan)
+    doRender
+ }
 }

Modified: incubator/esme/branches/access-pools/server/src/main/webapp/pools_view/index.html
URL: http://svn.apache.org/viewvc/incubator/esme/branches/access-pools/server/src/main/webapp/pools_view/index.html?rev=784972&r1=784971&r2=784972&view=diff
==============================================================================
--- incubator/esme/branches/access-pools/server/src/main/webapp/pools_view/index.html (original)
+++ incubator/esme/branches/access-pools/server/src/main/webapp/pools_view/index.html Mon
Jun 15 20:53:20 2009
@@ -9,13 +9,35 @@
     </lift:addPool>
   </lift:form>
   
+  <span id="PoolSpan">
+    <lift:ignore>
+      <!--
+      The poolUsers snippet *MUST* appear on the page before
+      the editPool snippet
+      -->
+    </lift:ignore>
+    <lift:poolUsers the_id="PoolSpan">
+      <table>
+        <thead>
+          <tr> <th>User</th>  <th>Privilege</th> </tr>
+        </thead>
+        
+        <tbody>
+          <pool:user>
+            <tr> <td><user:name/></td>  <td><user:privilege/></td>
</tr>
+          </pool:user>
+        </tbody>
+      </table>
+    </lift:poolUsers>
+  </span>
+
+
   <lift:form>
     <lift:editPool>
-      Edit user permissions within pool: <edit:pool/>
-      User name: <edit:username/> <edit:permission/>
+      Edit user permissions within pool: <edit:pool/> <br/>
+      User name: <edit:username/> <edit:permission/> <br/>
       <input type="submit" value="Edit" />
     </lift:editPool>
   </lift:form>
   
-
 </lift:surround>



Mime
View raw message