You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@esme.apache.org by vd...@apache.org on 2009/05/31 22:32:04 UTC

svn commit: r780502 - in /incubator/esme/trunk/server/src/main: scala/bootstrap/liftweb/Boot.scala scala/org/apache/esme/lib/TrackMgr.scala scala/org/apache/esme/view/Track.scala webapp/track_view/ webapp/track_view/index.html

Author: vdichev
Date: Sun May 31 20:32:04 2009
New Revision: 780502

URL: http://svn.apache.org/viewvc?rev=780502&view=rev
Log:
ESME-60 Clean up tracking view into html using binding.

Added:
    incubator/esme/trunk/server/src/main/scala/org/apache/esme/lib/TrackMgr.scala   (with props)
    incubator/esme/trunk/server/src/main/webapp/track_view/
    incubator/esme/trunk/server/src/main/webapp/track_view/index.html   (with props)
Modified:
    incubator/esme/trunk/server/src/main/scala/bootstrap/liftweb/Boot.scala
    incubator/esme/trunk/server/src/main/scala/org/apache/esme/view/Track.scala

Modified: incubator/esme/trunk/server/src/main/scala/bootstrap/liftweb/Boot.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/bootstrap/liftweb/Boot.scala?rev=780502&r1=780501&r2=780502&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/bootstrap/liftweb/Boot.scala (original)
+++ incubator/esme/trunk/server/src/main/scala/bootstrap/liftweb/Boot.scala Sun May 31 20:32:04 2009
@@ -109,7 +109,7 @@
     Menu(Loc("tag", List("info_view", "tag"), "Tag", Hidden, Loc.Snippet("tag_display", TagDisplay.display))) ::
     Menu(Loc("search", List("user_view", "search"), "Search", Hidden)) ::
     User.sitemap :::
-    Track.menuItems :::
+    TrackMgr.menuItems :::
     ActionMgr.menuItems :::
     AuthMgr.menuItems
 

Added: incubator/esme/trunk/server/src/main/scala/org/apache/esme/lib/TrackMgr.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/org/apache/esme/lib/TrackMgr.scala?rev=780502&view=auto
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/org/apache/esme/lib/TrackMgr.scala (added)
+++ incubator/esme/trunk/server/src/main/scala/org/apache/esme/lib/TrackMgr.scala Sun May 31 20:32:04 2009
@@ -0,0 +1,109 @@
+/**
+ * Copyright 2008-2009 WorldWide Conferencing, LLC
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.esme.lib
+
+import net.liftweb._
+import http._
+import SHtml._
+import js._
+import JsCmds._
+import JE._
+
+import sitemap._
+import Loc._
+
+import mapper._
+
+import util._
+import Helpers._
+
+import model._
+
+import scala.xml._
+
+/**
+ * Manage the sitemap and related snippets for Tracking Items
+ */
+object TrackMgr {
+  def loggedIn_? = User.loggedIn_?
+
+  val ifIsLoggedIn = If(loggedIn_? _, strFuncToFailMsg(() => S.?("You must be logged in")))
+
+  val menuItems =
+  Menu(Loc("trackMgt", List("track_view", "index"), "Item Tracking", ifIsLoggedIn,
+           Loc.Snippet("dispayTracking", dispayTracking),
+           Loc.Snippet("main", mainTracking))) ::
+  Nil
+
+  object updateTracking extends RequestVar[() => JsCmd](() => Noop)
+
+  def dispayTracking(in: NodeSeq): NodeSeq = {
+    // get the span name to update
+    val spanName = S.attr("the_id") openOr "TrackSpan"
+    // get the current user
+    val user = User.currentUser
+
+    // bind the dynamic content to the incoming nodeseq
+    def doRender(): NodeSeq =
+    Tracking.findAll(By(Tracking.user, user), By(Tracking.removed, false),
+    OrderBy(Tracking.id, Ascending)) match {
+      case Nil => NodeSeq.Empty
+      case xs => bind("disp", in,
+                      "item" -> 
+                      (lst => xs.flatMap(i => bind("item", lst,
+                                                   "pattern" -> i.pattern,
+                                                   "enabled" -> ajaxCheckbox(!i.disabled,
+                                                                             e => {i.disabled(!e).save; Noop} ),
+                                                   "remove" -> 
+                                                   ((bt: NodeSeq) => 
+                  ajaxButton(bt, () => {i.removed(true).save ; updateSpan()}))
+              ))))
+    }
+
+    def updateSpan(): JsCmd = SetHtml(spanName, doRender())
+
+    updateTracking.set(updateSpan)
+    doRender()
+  }
+
+  def mainTracking(in: NodeSeq): NodeSeq = {
+    val redisplayTracking = updateTracking.is
+    val theInput = "tracking_input"
+    val user = User.currentUser
+    
+    def addTrack(what: String): JsCmd = {
+      what.trim match {
+        case x if x.length < 3 => S.error("Too short")
+        case x => Tracking.create.regex(x).user(user).saveMe
+          S.notice("Now tracking "+x)
+      }
+
+      redisplayTracking() & SetValById(theInput, "")
+    }
+
+    bind("main", in,
+         "track" -> text("", addTrack, "id" -> theInput)
+    )
+    
+  }
+
+}

Propchange: incubator/esme/trunk/server/src/main/scala/org/apache/esme/lib/TrackMgr.scala
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/esme/trunk/server/src/main/scala/org/apache/esme/view/Track.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/org/apache/esme/view/Track.scala?rev=780502&r1=780501&r2=780502&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/org/apache/esme/view/Track.scala (original)
+++ incubator/esme/trunk/server/src/main/scala/org/apache/esme/view/Track.scala Sun May 31 20:32:04 2009
@@ -20,7 +20,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
+/*
 import net.liftweb._
 import http._
 import js._
@@ -104,4 +104,4 @@
 
     </lift:surround>
   }
-}
+}*/

Added: incubator/esme/trunk/server/src/main/webapp/track_view/index.html
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/webapp/track_view/index.html?rev=780502&view=auto
==============================================================================
--- incubator/esme/trunk/server/src/main/webapp/track_view/index.html (added)
+++ incubator/esme/trunk/server/src/main/webapp/track_view/index.html Sun May 31 20:32:04 2009
@@ -0,0 +1,28 @@
+<lift:surround with="default" at="content">
+
+  Manage your tracking items: <br/>
+  <span id="TrackSpan">
+    <lift:ignore>
+      <!--
+      The displayTracking snippet *MUST* appear on the page before
+      the main snippet
+      -->
+    </lift:ignore>
+    <lift:dispayTracking the_id="TrackSpan">
+      <ul>
+        <disp:item>
+          <li><item:pattern/> Enabled: <item:enabled/> <item:remove>Remove</item:remove></li>
+        </disp:item>
+      </ul>
+    </lift:dispayTracking>
+  </span>
+
+  <lift:form>
+    <lift:main>
+      Track something new.<br />
+      What? <main:track/>
+      <input type="submit" value="Add" />
+    </lift:main>
+  </lift:form>
+
+</lift:surround>

Propchange: incubator/esme/trunk/server/src/main/webapp/track_view/index.html
------------------------------------------------------------------------------
    svn:executable = *