[open-ils-commits] r1135 - in servres/trunk/conifer: . static syrup syrup/views templates templates/admin (gfawcett)

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Dec 28 15:36:14 EST 2010


Author: gfawcett
Date: 2010-12-28 15:36:09 -0500 (Tue, 28 Dec 2010)
New Revision: 1135

Added:
   servres/trunk/conifer/static/fuzzyFinder.js
   servres/trunk/conifer/templates/admin/staff_add.xhtml
Modified:
   servres/trunk/conifer/TODO
   servres/trunk/conifer/static/edit_site.js
   servres/trunk/conifer/syrup/urls.py
   servres/trunk/conifer/syrup/views/admin.py
   servres/trunk/conifer/templates/edit_site.xhtml
Log:
Admin function: add new staff member. Partly refactored fuzzyFinder interface.

The refactored fuzzyFinder is ugly, though. Really there should be a
Genshi-side component.

Modified: servres/trunk/conifer/TODO
===================================================================
--- servres/trunk/conifer/TODO	2010-12-28 20:36:06 UTC (rev 1134)
+++ servres/trunk/conifer/TODO	2010-12-28 20:36:09 UTC (rev 1135)
@@ -2,8 +2,6 @@
 
 * add URL form should have same metadata as ELEC form (except for copyright status)
 
-* add new staff member
-
 * why are .focus() calls not working properly?
 
 * edit URL item fails with error. KeyError: author2
@@ -22,6 +20,8 @@
 
 MAYBE:
 
+* refactor fuzzyFinder into a Genshi component.
+
 * set up a proper issue-tracker?
 
 * if someone has item checked out, show due date/time on item-about page.
@@ -75,3 +75,4 @@
 
 * factor out hardcoded references to the EG server.
 
+* add new staff member

Modified: servres/trunk/conifer/static/edit_site.js
===================================================================
--- servres/trunk/conifer/static/edit_site.js	2010-12-28 20:36:06 UTC (rev 1134)
+++ servres/trunk/conifer/static/edit_site.js	2010-12-28 20:36:09 UTC (rev 1135)
@@ -1,78 +1,4 @@
-var fuzzyLookup = {
-
-	lastText: null,
-	lastPress: null,
-	waiting: false,
-	
-	lookup: function() {
-		var text = $(this).val();
-		if (text != fuzzyLookup.lastText) {
-			fuzzyLookup.lastText = text;
-			if (text.length < 3) {
-				return;
-			}
-			fuzzyLookup.lastPress = new Date();
-		}
-	},
-
-	minWait: 500,
-
-	interval: function() {
-		var now = new Date();
-
-		if (fuzzyLookup.lastPress == null || (now - fuzzyLookup.lastPress) < fuzzyLookup.minWait) {
-			return;
-		}
-
-		if (fuzzyLookup.waiting) {
-			return;
-		}
-
-		fuzzyLookup.waiting = true;
-		$('#fuzzyinput').css({backgroundColor: 'yellow'}); // debugging
-		$.post('site_fuzzy_user_lookup', {'q': fuzzyLookup.lastText},
-			   function(data) {
-				   fuzzyLookup.waiting = false;
-				   fuzzyLookup.lastPress = null;
-				   $('#fuzzyinput').css({backgroundColor: 'white'}); // debugging
-				   $('#fuzzypanel').text('');
-				   if (data.results.length == 0) {
-					   $('#fuzzypanel').append('No matches.');
-				   }
-				   $.each(data.results, function(i,val) {
-					   var link = $('<a class="fuzzychoice" href="#"/>');
-					   link.text(val[1]);
-					   link.data('userid', val[0]);
-					   link.data('display', val[1]);
-					   link.click(fuzzyLookup.pick);
-					   $('#fuzzypanel').append(link);
-				   });
-				   if (data.notshown > 0) {
-					   $('#fuzzypanel').append('<div>and ' + data.notshown + ' more.</div>');
-				   }
-			   }, 'json');
-	},
-
-	pick: function(uid) {
-		$('#fuzzyedit').hide();
-		$('#fuzzyview').show();
-
-		var inp = $('#owner');
-		inp.val($(this).data('userid'));
-
-		$('#fuzzyname').text($(this).data('display'));
-	},
-
-	edit: function() {
-		$('#fuzzyview').hide();
-		$('#fuzzyedit').show();
-		$('#fuzzyinput').focus();
-		fuzzyLookup.lastText = $('#fuzzyinput').val();
-		fuzzyLookup.lastPress = new Date(new Date() - 450);
-	}
-}
-
 $(function() {
-	$('#fuzzyinput').keyup(fuzzyLookup.lookup);
-	setInterval(fuzzyLookup.interval, 250);
+    var fuzzy = fuzzyFinder(
+	'#fuzzyinput', '#fuzzypanel', '#fuzzyedit', '#fuzzyview', '#fuzzyname', '#fuzzychange', '#owner');
 });

Added: servres/trunk/conifer/static/fuzzyFinder.js
===================================================================
--- servres/trunk/conifer/static/fuzzyFinder.js	                        (rev 0)
+++ servres/trunk/conifer/static/fuzzyFinder.js	2010-12-28 20:36:09 UTC (rev 1135)
@@ -0,0 +1,79 @@
+function fuzzyFinder(Search, Matches, EditPanel, ViewPanel, ViewName, Change, Owner) {
+    var here = {
+
+	lastText: null,
+	lastPress: null,
+	waiting: false,
+	minWait: 500,
+	
+	lookup: function() {
+	    var text = $(this).val();
+	    if (text != here.lastText) {
+		here.lastText = text;
+		if (text.length < 3) {
+		    return;
+		}
+		here.lastPress = new Date();
+	    }
+	},
+	
+	interval: function() {
+	    var now = new Date();
+	    
+	    if (here.lastPress == null || (now - here.lastPress) < here.minWait) {
+		return;
+	    }
+	    
+	    if (here.waiting) {
+		return;
+	    }
+	    
+	    here.waiting = true;
+	    $(Search).css({backgroundColor: 'yellow'}); // debugging
+	    $.post(ROOT + '/fuzzy_user_lookup', {'q': here.lastText},
+		   function(data) {
+		       here.waiting = false;
+		       here.lastPress = null;
+		       $(Search).css({backgroundColor: 'white'}); // debugging
+		       $(Matches).text('');
+		       if (data.results.length == 0) {
+			   $(Matches).append('No matches.');
+		       }
+		       $.each(data.results, function(i,val) {
+			   var link = $('<a class="fuzzychoice" href="#"/>');
+			   link.text(val[1]);
+			   link.data('userid', val[0]);
+			   link.data('display', val[1]);
+			   link.click(here.pick);
+			   $(Matches).append(link);
+		       });
+		       if (data.notshown > 0) {
+			   $(Matches).append('<div>and ' + data.notshown + ' more.</div>');
+		       }
+		   }, 'json');
+	},
+	
+	pick: function(uid) {
+	    $(EditPanel).hide();
+	    $(ViewPanel).show();
+	    
+	    var inp = $(Owner);
+	    inp.val($(this).data('userid'));
+	    
+	    $(ViewName).text($(this).data('display'));
+	},
+	
+	edit: function() {
+	    $(ViewPanel).hide();
+	    $(EditPanel).show();
+	    $(Search).focus();
+	    here.lastText = $(Search).val();
+	    here.lastPress = new Date(new Date() - 450);
+	}
+    };
+    setInterval(here.interval, 250);
+    $(Search).keyup(here.lookup);
+    $(Change).click(here.edit);
+    return here;
+}
+    

Modified: servres/trunk/conifer/syrup/urls.py
===================================================================
--- servres/trunk/conifer/syrup/urls.py	2010-12-28 20:36:06 UTC (rev 1134)
+++ servres/trunk/conifer/syrup/urls.py	2010-12-28 20:36:09 UTC (rev 1135)
@@ -34,7 +34,7 @@
     (r'^site/(?P<site_id>\d+)/edit/permission/delete_group/$', 'edit_site_permissions_delete_group'),
     (r'^site/(?P<site_id>\d+)/feeds/(?P<feed_type>.*)$', 'site_feeds'),
     (r'^site/(?P<site_id>\d+)/join/$', 'site_join'),
-    (r'^site/.*fuzzy_user_lookup$', 'site_fuzzy_user_lookup'),
+    (r'^fuzzy_user_lookup$', 'site_fuzzy_user_lookup'),
     (ITEM_PREFIX + r'$', 'item_detail'),
     (ITEM_PREFIX + r'dl/(?P<filename>.*)$', 'item_download'),
     (ITEM_PREFIX + r'meta$', 'item_metadata'),
@@ -53,7 +53,9 @@
     (r'^admin/targets/' + GENERIC_REGEX, 'admin_targets'),
     (r'^admin/update_depts_courses/$', 'admin_update_depts_courses'),
     (r'^admin/update_terms/$', 'admin_update_terms'),
+    (r'^admin/staff/add/$', 'admin_staff_add'),
 
+
     # (r'^phys/$', 'phys_index'),
     # (r'^phys/checkout/$', 'phys_checkout'),
     # (r'^phys/mark_arrived/$', 'phys_mark_arrived'),

Modified: servres/trunk/conifer/syrup/views/admin.py
===================================================================
--- servres/trunk/conifer/syrup/views/admin.py	2010-12-28 20:36:06 UTC (rev 1134)
+++ servres/trunk/conifer/syrup/views/admin.py	2010-12-28 20:36:09 UTC (rev 1135)
@@ -149,3 +149,29 @@
                 code = tcode, 
                 defaults = dict(name=tname, start=start, finish=finish))
         return simple_message('Terms updated.', '')
+
+ at admin_only
+def admin_staff_add(request):
+    if request.method != 'POST':
+        return g.render('admin/staff_add.xhtml', **locals())
+    else:
+        userid = request.POST.get('userid','').strip()
+        message_continue = True
+
+        try:
+            user = User.objects.get(username=userid)
+        except User.DoesNotExist:
+            user = User.objects.create(username=userid)
+            user.maybe_decorate()
+
+        user.is_staff = True
+        user.is_superuser = True # TODO: are we sure they should be superuser?
+        user.save()
+
+        if not userid:
+            message = 'No user selected.'
+            message_continue = False
+        else:
+            message = 'Staff user added: %s [%s].' % (user.get_full_name(), user.username)
+
+        return g.render('admin/staff_add.xhtml', **locals())

Added: servres/trunk/conifer/templates/admin/staff_add.xhtml
===================================================================
--- servres/trunk/conifer/templates/admin/staff_add.xhtml	                        (rev 0)
+++ servres/trunk/conifer/templates/admin/staff_add.xhtml	2010-12-28 20:36:09 UTC (rev 1135)
@@ -0,0 +1,51 @@
+<?python
+title = _('Add new staff user')
+?>
+<html xmlns="http://www.w3.org/1999/xhtml"
+      xmlns:xi="http://www.w3.org/2001/XInclude"
+      xmlns:py="http://genshi.edgewall.org/">
+<xi:include href="../master.xhtml"/>
+<head>
+  <title>${title}</title>
+  <script type="text/javascript" src="${ROOT}/static/fuzzyFinder.js"/>
+  <script>
+    $(function() {
+    var fuzzy = fuzzyFinder(
+    '#fuzzyinput', '#fuzzypanel', '#fuzzyedit', '#fuzzyview', '#fuzzyname', '#fuzzychange', '#userid');
+    });
+  </script>
+  <style>
+	.fuzzychoice { display: block; margin: 0.5em 0;  font-size: 90%; }
+	#fuzzyview { display: block; margin: 0.5em 0;  font-size: 90%; }
+	#message { background-color: #fdd; padding: 12; display: inline-block; }
+  </style>
+  <style type="text/css">
+    ul { margin-bottom: 2em; }
+  </style>
+</head>
+<body>
+  <h1>${title}</h1>
+  <p py:if="defined('message')">
+    <div id="message">${message}</div>
+    <span py:if="message_continue">${go_back_link('../../', 'Continue')}</span>
+  </p>
+  <div>
+    <div id="fuzzyedit" style="display: block">
+      <div style="font-size: 80%; margin: 0.5em 0;">Type a partial name or userid into the box; then select one of the matches.</div>
+      <input type="text" id="fuzzyinput" autocomplete="off" value=""/>
+      <div id="fuzzypanel">
+      </div>
+    </div>
+    <div id="fuzzyview" style="display: none;">
+      <span id="fuzzyname">
+      </span>
+      <input id="fuzzychange" type="button" value="change" onclick="fuzzyLookup.edit();"
+	     style="margin-left: 1em;"/>
+      <form action="." method="POST">
+	<input type="hidden" id="userid" name="userid" value=""/>
+	<p><input type="submit" value="Add this user"/></p>
+      </form>
+    </div>
+  </div>
+</body>
+</html>
\ No newline at end of file

Modified: servres/trunk/conifer/templates/edit_site.xhtml
===================================================================
--- servres/trunk/conifer/templates/edit_site.xhtml	2010-12-28 20:36:06 UTC (rev 1134)
+++ servres/trunk/conifer/templates/edit_site.xhtml	2010-12-28 20:36:09 UTC (rev 1135)
@@ -12,6 +12,7 @@
 <xi:include href="components/site.xhtml"/>
 <head>
   <title>${title}</title>
+  <script type="text/javascript" src="${ROOT}/static/fuzzyFinder.js"/>
   <script type="text/javascript" src="${ROOT}/static/edit_site.js"/>
   <style>
 	.fuzzychoice { display: block; margin: 0.5em 0;  font-size: 90%; }
@@ -58,8 +59,7 @@
 			  ${owner.get_full_name()} [${owner}]
 			</span>
 			</span>
-			<input type="button" value="change" onclick="fuzzyLookup.edit();"
-					 style="margin-left: 1em;"/>
+			<input type="button" value="change" id="fuzzychange" style="margin-left: 1em;"/>
 		  </div>
 		</td>
 	  </tr>



More information about the open-ils-commits mailing list