[open-ils-commits] r7914 - branches/rel_1_2/Open-ILS/xul/staff_client/server/cat

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Oct 22 02:08:36 EDT 2007


Author: phasefx
Date: 2007-10-22 01:55:11 -0400 (Mon, 22 Oct 2007)
New Revision: 7914

Modified:
   branches/rel_1_2/Open-ILS/xul/staff_client/server/cat/copy_editor.js
   branches/rel_1_2/Open-ILS/xul/staff_client/server/cat/copy_editor.xul
Log:
better stat cat and shelving location handling for cross-branch/cross-system item editing

Modified: branches/rel_1_2/Open-ILS/xul/staff_client/server/cat/copy_editor.js
===================================================================
--- branches/rel_1_2/Open-ILS/xul/staff_client/server/cat/copy_editor.js	2007-10-22 05:54:08 UTC (rev 7913)
+++ branches/rel_1_2/Open-ILS/xul/staff_client/server/cat/copy_editor.js	2007-10-22 05:55:11 UTC (rev 7914)
@@ -99,69 +99,8 @@
 		/******************************************************************************************************/
 		/* Add stat cats to the panes_and_field_names.right_pane4 */
 
-		g.stat_cat_seen = {};
+        g.populate_stat_cats();
 
-		function add_stat_cat(sc) {
-
-			if (typeof g.data.hash.asc == 'undefined') { g.data.hash.asc = {}; g.data.stash('hash'); }
-
-			var sc_id = sc;
-
-			if (typeof sc == 'object') {
-
-				sc_id = sc.id();
-			}
-
-			if (typeof g.stat_cat_seen[sc_id] != 'undefined') { return; }
-
-			g.stat_cat_seen[ sc_id ] = 1;
-
-			if (typeof sc != 'object') {
-
-				sc = g.network.simple_request(
-					'FM_ASC_BATCH_RETRIEVE',
-					[ ses(), [ sc_id ] ]
-				)[0];
-
-			}
-
-			g.data.hash.asc[ sc.id() ] = sc; g.data.stash('hash');
-
-			var label_name = g.data.hash.aou[ sc.owner() ].shortname() + " : " + sc.name();
-
-			var temp_array = [
-				label_name,
-				{
-					render: 'var l = util.functional.find_list( fm.stat_cat_entries(), function(e){ return e.stat_cat() == ' 
-						+ sc.id() + '; } ); l ? l.value() : "<Unset>";',
-					input: 'c = function(v){ g.apply_stat_cat(' + sc.id() + ',v); if (typeof post_c == "function") post_c(v); }; x = util.widgets.make_menulist( [ [ "<Remove Stat Cat>", -1 ] ].concat( util.functional.map_list( g.data.hash.asc[' + sc.id() 
-						+ '].entries(), function(obj){ return [ obj.value(), obj.id() ]; } ) ).sort() ); '
-					//input: 'c = function(v){ g.apply_stat_cat(' + sc.id() + ',v); if (typeof post_c == "function") post_c(v); }; x = util.widgets.make_menulist( [ [ "<Remove Stat Cat>", null ] ].concat( util.functional.map_list( g.data.hash.asc[' + sc.id() 
-					//	+ '].entries(), function(obj){ return [ obj.value(), obj.id() ]; } ).sort() ) ); '
-						+ 'x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c),false);',
-				}
-			];
-
-			dump('temp_array = ' + js2JSON(temp_array) + '\n');
-
-			g.panes_and_field_names.right_pane4.push( temp_array );
-		}
-
-		/* The stat cats for the pertinent library */
-		for (var i = 0; i < g.data.list.my_asc.length; i++) {
-			add_stat_cat( g.data.list.my_asc[i] );	
-		}
-
-		/* Other stat cats present on these copies */
-		for (var i = 0; i < g.copies.length; i++) {
-			var entries = g.copies[i].stat_cat_entries();
-			if (!entries) entries = [];
-			for (var j = 0; j < entries.length; j++) {
-				var sc_id = entries[j].stat_cat();
-				add_stat_cat( sc_id );
-			}
-		}
-
 		/******************************************************************************************************/
 		/* Backup copies :) */
 
@@ -217,7 +156,13 @@
 		var list = util.functional.map_object_to_list( g.templates, function(obj,i) { return [i, i]; } );
 
 		g.template_menu = util.widgets.make_menulist( list );
+        g.template_menu.setAttribute('id','template_menu');
 		$('template_placeholder').appendChild(g.template_menu);
+        g.template_menu.addEventListener(
+            'command',
+            function() { g.copy_editor_prefs[ 'template_menu' ] = { 'value' : g.template_menu.value }; g.save_attributes(); },
+            false
+        );
 	} catch(E) {
 		g.error.standard_unexpected_error_alert('Error retrieving templates',E);
 	}
@@ -406,7 +351,7 @@
 				var list = util.functional.map_object_to_list( g.templates, function(obj,i) { return [i, i]; } );
 				g.template_menu = util.widgets.make_menulist( list );
 				$('template_placeholder').appendChild(g.template_menu);
-				alert("Note: These imported templates will get saved along with any new template you try to create, but if that doesn't happen, then these templates will dissappear with the next invocation of the item attribute editor.");
+				alert("Note: These imported templates will get saved along with any new template you try to create, but if that doesn't happen, then these templates will disappear with the next invocation of the item attribute editor.");
 			}
 
 		} else {
@@ -482,21 +427,21 @@
 /******************************************************************************************************/
 /* Apply an "owning lib" to all the copies being edited.  That is, change and auto-vivicating volumes */
 
+g.map_acn = {};
 g.apply_owning_lib = function(ou_id) {
 	g.error.sdump('D_TRACE','ou_id = ' + ou_id + '\n');
-	var map_acn = {};
 	for (var i = 0; i < g.copies.length; i++) {
 		var copy = g.copies[i];
 		try {
-			if (!map_acn[copy.call_number()]) {
+			if (!g.map_acn[copy.call_number()]) {
 				var volume = g.network.simple_request('FM_ACN_RETRIEVE',[ copy.call_number() ]);
 				if (typeof volume.ilsevent != 'undefined') {
 					g.error.standard_unexpected_error_alert('Error retrieving Volume information for copy ' + copy.barcode() + ".  The owning library for this copy won't be changed.",volume);
 					continue;
 				}
-				map_acn[copy.call_number()] = volume;
+				g.map_acn[copy.call_number()] = volume;
 			}
-			var old_volume = map_acn[copy.call_number()];
+			var old_volume = g.map_acn[copy.call_number()];
 			var acn_id = g.network.simple_request(
 				'FM_ACN_FIND_OR_CREATE',
 				[ses(),old_volume.label(),old_volume.record(),ou_id]
@@ -578,7 +523,7 @@
 		JSAN.use('util.functional');
 
 		function get(lib_id,only_these) {
-			g.data.stash_retrieve();
+            g.data.stash_retrieve();
 			var label = 'acpl_list_for_lib_'+lib_id;
 			if (typeof g.data[label] == 'undefined') {
 				var robj = g.network.simple_request('FM_ACPL_RETRIEVE', [ lib_id ]);
@@ -590,7 +535,8 @@
 						g.data.hash.acpl[ my_acpl.id() ] = my_acpl;
 						g.data.list.acpl.push( my_acpl );
 					}
-					if (only_these.indexOf( String( my_acpl.owning_lib() ) ) != -1) {
+                    var only_this_lib = my_acpl.owning_lib(); if (typeof only_this_lib == 'object') only_this_lib = only_this_lib.id();
+					if (only_these.indexOf( String( only_this_lib ) ) != -1) {
 						temp_list.push( my_acpl );
 					}
 				}
@@ -599,33 +545,73 @@
 			return g.data[label];
 		}
 
-		var libs = []; var map_acn = {};
+        var temp_acpl_list = [];
+
+        /* find acpl's based on owning_lib */
+
+		var libs = []; 
 		for (var i = 0; i < g.copies.length; i++) {
 			var cn_id = g.copies[i].call_number();
 			if (cn_id > 0) {
-				if (! map_acn[ cn_id ]) {
-					map_acn[ cn_id ] = g.network.simple_request('FM_ACN_RETRIEVE',[ cn_id ]);
-					libs.push( map_acn[ cn_id ].owning_lib() );
+				if (! g.map_acn[ cn_id ]) {
+					g.map_acn[ cn_id ] = g.network.simple_request('FM_ACN_RETRIEVE',[ cn_id ]);
 				}
+                var consider_lib = g.map_acn[ cn_id ].owning_lib();
+                if ( libs.indexOf( String( consider_lib ) ) > -1 ) { /* already in list */ } else { libs.push( consider_lib ); }
 			}
 		}
 		if (g.callnumbers) {
 			for (var i in g.callnumbers) {
-				if ( ( libs.indexOf( g.callnumbers[i].owning_lib ) > -1 ) || ( libs.indexOf( String( g.callnumbers[i].owning_lib ) ) > -1 ) ) { /* already in list */ } else { libs.push( g.callnumbers[i].owning_lib ); }
+                var consider_lib = g.callnumbers[i].owning_lib;
+                if (typeof consider_lib == 'object') consider_lib = consider_lib.id();
+				if ( libs.indexOf( String( consider_lib ) ) > -1 ) { /* already in list */ } else { libs.push( consider_lib ); }
 			}
 		}
 		JSAN.use('util.fm_utils');
 		var ancestor = util.fm_utils.find_common_aou_ancestor( libs );
 		if (typeof ancestor == 'object' && ancestor != null) ancestor = ancestor.id();
 
-		var ancestors = util.fm_utils.find_common_aou_ancestors( libs );
-
 		if (ancestor) {
-			return get(ancestor, ancestors);
-		} else {
-			return [];
+		    var ancestors = util.fm_utils.find_common_aou_ancestors( libs );
+			var acpl_list = get(ancestor, ancestors);
+            if (acpl_list) for (var i = 0; i < acpl_list.length; i++) {
+                if (acpl_list[i] != null) {
+                    temp_acpl_list.push(acpl_list[i]);
+                }
+            }
 		}
+        
+        /* find acpl's based on circ_lib */
 
+        var circ_libs = [];
+
+        for (var i = 0; i < g.copies.length; i++) {
+            var consider_lib = g.copies[i].circ_lib();
+            if (typeof consider_lib == 'object') consider_lib = consider_lib.id();
+			if ( circ_libs.indexOf( String( consider_lib ) ) > -1 ) { /* already in list */ } else { circ_libs.push( consider_lib ); }
+        }
+
+        if (circ_libs.length > 0) {
+    		var circ_ancestor = util.fm_utils.find_common_aou_ancestor( circ_libs );
+    		if (typeof circ_ancestor == 'object' && circ_ancestor != null) circ_ancestor = circ_ancestor.id();
+
+    		if (circ_ancestor) {
+    		    var circ_ancestors = util.fm_utils.find_common_aou_ancestors( circ_libs );
+    			var circ_acpl_list = get(circ_ancestor, circ_ancestors);
+                var flat_acpl_list = util.functional.map_list( temp_acpl_list, function(o){return o.id();} );
+                for (var i = 0; i < circ_acpl_list.length; i++) {
+                    var consider_acpl = circ_acpl_list[i].id();
+                    if ( flat_acpl_list.indexOf( String( consider_acpl ) ) > -1 ) { 
+                        /* already in list */ 
+                    } else { 
+                        if (circ_acpl_list[i] != null) temp_acpl_list.push( circ_acpl_list[i] ); 
+                    }
+                }
+            }
+        }
+
+        return temp_acpl_list;
+	
 	} catch(E) {
 		g.error.standard_unexpected_error_alert('get_acpl_list',E);
 		return [];
@@ -920,6 +906,7 @@
 
 		var field_name = g.field_names[i][0];
 		var render = g.field_names[i][1].render;
+        var attr = g.field_names[i][1].attr;
 		g.summary[ field_name ] = {};
 
 		/******************************************************************************************************/
@@ -972,6 +959,29 @@
 	}
 
 	/******************************************************************************************************/
+	/* Populate the library filter menu for stat cats */
+
+    var sc_libs = {};
+    for (var i = 0; i < g.panes_and_field_names.right_pane4.length; i++) {
+        sc_libs[ g.panes_and_field_names.right_pane4[i][1].attr.sc_lib ] = true;
+    }
+    var sc_libs2 = [];
+    for (var i in sc_libs) { sc_libs2.push( [ g.data.hash.aou[ i ].shortname(), i ] ); }
+    sc_libs2.sort();
+    var x = document.getElementById("stat_cat_lib_filter_menu").firstChild;
+    JSAN.use('util.widgets'); util.widgets.remove_children(x);
+    for (var i = 0; i < sc_libs2.length; i++) {
+        var menuitem = document.createElement('menuitem');
+        menuitem.setAttribute('id','filter_'+sc_libs2[i][1]);
+        menuitem.setAttribute('type','checkbox');
+        menuitem.setAttribute('checked','true');
+        menuitem.setAttribute('label',sc_libs2[i][0]);
+        menuitem.setAttribute('value',sc_libs2[i][1]);
+        menuitem.setAttribute('oncommand','try{g.toggle_stat_cat_display(this);}catch(E){alert(E);}');
+        x.appendChild(menuitem);
+    }
+
+	/******************************************************************************************************/
 	/* Prepare the panes */
 
 	var groupbox; var caption; var vbox; var grid; var rows;
@@ -983,8 +993,13 @@
 		if (!document.getElementById(h)) continue;
 		for (var i = 0; i < g.panes_and_field_names[h].length; i++) {
 			try {
-				var f = g.panes_and_field_names[h][i]; var fn = f[0];
+				var f = g.panes_and_field_names[h][i]; var fn = f[0]; var attr = f[1].attr;
 				groupbox = document.createElement('groupbox'); document.getElementById(h).appendChild(groupbox);
+                if (attr) {
+                    for (var a in attr) {
+                        groupbox.setAttribute(a,attr[a]);
+                    }
+                }
 				if (typeof g.changed[fn] != 'undefined') groupbox.setAttribute('class','copy_editor_field_changed');
 				caption = document.createElement('caption'); groupbox.appendChild(caption);
 				caption.setAttribute('label',fn); caption.setAttribute('id','caption_'+fn);
@@ -1028,6 +1043,22 @@
 			}
 		}
 	}
+    
+    
+	/******************************************************************************************************/
+	/* Synchronize stat cat visibility with library filter menu, and default template selection */
+    JSAN.use('util.file'); 
+	var file = new util.file('copy_editor_prefs.'+g.data.server_unadorned);
+	g.copy_editor_prefs = util.widgets.load_attributes(file);
+    for (var i in g.copy_editor_prefs) {
+        if (i.match(/filter_/) && g.copy_editor_prefs[i].checked == '') {
+            try { 
+                g.toggle_stat_cat_display( document.getElementById(i) ); 
+            } catch(E) { alert(E); }
+        }
+    }
+    g.template_menu.value = g.template_menu.getAttribute('value');
+
 }
 
 /******************************************************************************************************/
@@ -1044,6 +1075,7 @@
 
 		var input_cmd = blob.input;
 		var render_cmd = blob.render;
+        var attr = blob.attr;
 
 		var block = false; var first = true;
 
@@ -1176,3 +1208,177 @@
 	);
 }
 
+/******************************************************************************************************/
+/* hides or unhides stat cats based on library stat cat filter menu */
+g.toggle_stat_cat_display = function(el) {
+    var visible = el.getAttribute('checked');
+    var nl = document.getElementsByAttribute('sc_lib',el.getAttribute('value'));
+    for (var n = 0; n < nl.length; n++) {
+        if (visible) {
+            nl[n].setAttribute('hidden','false');
+        } else {
+            nl[n].setAttribute('hidden','true');
+        }
+    }
+    g.copy_editor_prefs[ el.getAttribute('id') ] = { 'checked' : visible };
+    g.save_attributes();
+}
+
+/******************************************************************************************************/
+/* This adds a stat cat definition to the stat cat pane for rendering */
+g.save_attributes = function() {
+	JSAN.use('util.widgets'); JSAN.use('util.file'); var file = new util.file('copy_editor_prefs.'+g.data.server_unadorned);
+    var what_to_save = {};
+    for (var i in g.copy_editor_prefs) {
+        what_to_save[i] = [];
+        for (var j in g.copy_editor_prefs[i]) what_to_save[i].push(j);
+    }
+	util.widgets.save_attributes(file, what_to_save );
+}
+
+/******************************************************************************************************/
+/* This adds a stat cat definition to the stat cat pane for rendering */
+g.add_stat_cat = function(sc) {
+    try {
+		if (typeof g.data.hash.asc == 'undefined') { g.data.hash.asc = {}; g.data.stash('hash'); }
+
+		var sc_id = sc;
+
+		if (typeof sc == 'object') {
+
+			sc_id = sc.id();
+		}
+
+		if (typeof g.stat_cat_seen[sc_id] != 'undefined') { return; }
+
+		g.stat_cat_seen[ sc_id ] = 1;
+
+		if (typeof sc != 'object') {
+
+			sc = g.network.simple_request(
+				'FM_ASC_BATCH_RETRIEVE',
+				[ ses(), [ sc_id ] ]
+			)[0];
+
+		}
+
+		g.data.hash.asc[ sc.id() ] = sc; g.data.stash('hash');
+
+		var label_name = g.data.hash.aou[ sc.owner() ].shortname() + " : " + sc.name();
+
+		var temp_array = [
+			label_name,
+			{
+				render: 'var l = util.functional.find_list( fm.stat_cat_entries(), function(e){ return e.stat_cat() == ' 
+					+ sc.id() + '; } ); l ? l.value() : "<Unset>";',
+				input: 'c = function(v){ g.apply_stat_cat(' + sc.id() + ',v); if (typeof post_c == "function") post_c(v); }; x = util.widgets.make_menulist( [ [ "<Remove Stat Cat>", -1 ] ].concat( util.functional.map_list( g.data.hash.asc[' + sc.id() 
+					+ '].entries(), function(obj){ return [ obj.value(), obj.id() ]; } ) ).sort() ); '
+					+ 'x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c),false);',
+                attr: {
+                    sc_lib: sc.owner(),
+                }
+			}
+		];
+
+		g.panes_and_field_names.right_pane4.push( temp_array );
+	} catch(E) {
+		g.error.standard_unexpected_error_alert('Error adding stat cat to display definition',E);
+    }
+}
+
+/******************************************************************************************************/
+/* Add stat cats to the panes_and_field_names.right_pane4 */
+g.populate_stat_cats = function() {
+    try {
+        g.data.stash_retrieve();
+		g.stat_cat_seen = {};
+
+		function get(lib_id,only_these) {
+            g.data.stash_retrieve();
+			var label = 'asc_list_for_lib_'+lib_id;
+			if (typeof g.data[label] == 'undefined') {
+				var robj = g.network.simple_request('FM_ASC_RETRIEVE_VIA_AOU', [ ses(), lib_id ]);
+				if (typeof robj.ilsevent != 'undefined') throw(robj);
+				var temp_list = [];
+				for (var j = 0; j < robj.length; j++) {
+					var my_asc = robj[j];
+                    if (typeof g.data.hash.asc == 'undefined') { g.data.hash.asc = {}; }
+					if (typeof g.data.hash.asc[ my_asc.id() ] == 'undefined') {
+						g.data.hash.asc[ my_asc.id() ] = my_asc;
+					}
+                    var only_this_lib = my_asc.owner(); if (typeof only_this_lib == 'object') only_this_lib = only_this_lib.id();
+					if (only_these.indexOf( String( only_this_lib ) ) != -1) {
+						temp_list.push( my_asc );
+					}
+				}
+				g.data[label] = temp_list; g.data.stash(label,'hash','list');
+			}
+			return g.data[label];
+		}
+
+		/* The stat cats for the pertinent library -- this is based on workstation ou */
+        var label = 'asc_list_for_' + typeof g.data.ws_ou == 'object' ? g.data.ws_ou.id() : g.data.ws_ou;
+        g.data[ label ] = g.data.list.my_asc; g.data.stash('label');
+		for (var i = 0; i < g.data.list.my_asc.length; i++) {
+			g.add_stat_cat( g.data.list.my_asc[i] );
+		}
+
+        /* For the others, we want to consider the owning libs, circ libs, and any libs that have stat cats already on the copies,
+            however, if batch editing, we only want to show the ones they have in common.  So let's compile the libs  */
+
+        function add_common_ancestors(sc_libs) {
+            JSAN.use('util.fm_utils'); 
+            var libs = []; for (var i in sc_libs) libs.push(i);
+            var ancestor = util.fm_utils.find_common_aou_ancestor( libs );
+            if (typeof ancestor == 'object' && ancestor != null) ancestor = ancestor.id();
+            if (ancestor) {
+                var ancestors = util.fm_utils.find_common_aou_ancestors( libs );
+                var asc_list = get(ancestor, ancestors);
+                for (var i = 0; i < asc_list.length; i++) {
+                    g.add_stat_cat( asc_list[i] );
+                }
+            }
+        }
+
+		/* stat cats based on stat cat entries present on these copies */
+        var sc_libs = {};
+		for (var i = 0; i < g.copies.length; i++) {
+			var entries = g.copies[i].stat_cat_entries();
+			if (!entries) entries = [];
+			for (var j = 0; j < entries.length; j++) {
+                var lib = entries[j].owner(); if (typeof lib == 'object') lib = lib.id();
+				sc_libs[ lib ] = true;
+			}
+        }
+        add_common_ancestors(sc_libs); // CAVEAT - if a copy has no stat_cat_entries, it basically gets no vote here
+
+        /* stat cats based on Circ Lib */
+        sc_libs = {};
+		for (var i = 0; i < g.copies.length; i++) {
+            var circ_lib = g.copies[i].circ_lib(); if (typeof circ_lib == 'object') circ_lib = circ_lib.id();
+            sc_libs[ circ_lib ] = true;
+        }
+        add_common_ancestors(sc_libs);
+
+        /* stat cats based on Owning Lib */
+        sc_libs = {};
+		for (var i = 0; i < g.copies.length; i++) {
+            var cn_id = g.copies[i].call_number();
+			if (cn_id > 0) {
+				if (! g.map_acn[ cn_id ]) {
+					g.map_acn[ cn_id ] = g.network.simple_request('FM_ACN_RETRIEVE',[ cn_id ]);
+				}
+                var owning_lib = g.map_acn[ cn_id ].owning_lib(); if (typeof owning_lib == 'object') owning_lib = owning_lib.id();
+                sc_libs[ owning_lib ] = true;
+			}
+		}
+        add_common_ancestors(sc_libs); // CAVEAT - if a copy is a pre-cat, it basically gets no vote here
+
+        g.panes_and_field_names.right_pane4.sort();
+
+    } catch(E) {
+        g.error.standard_unexpected_error_alert('Error populating stat cats for display',E);
+    }
+}
+
+

Modified: branches/rel_1_2/Open-ILS/xul/staff_client/server/cat/copy_editor.xul
===================================================================
--- branches/rel_1_2/Open-ILS/xul/staff_client/server/cat/copy_editor.xul	2007-10-22 05:54:08 UTC (rev 7913)
+++ branches/rel_1_2/Open-ILS/xul/staff_client/server/cat/copy_editor.xul	2007-10-22 05:55:11 UTC (rev 7914)
@@ -76,6 +76,9 @@
 			<splitter><grippy /></splitter>
 			<vbox flex="1">
 				<button style="font-weight: bold; font-size: normal" label="Statistics" accesskey="4" oncommand="document.getElementById('right_pane4').firstChild.firstChild.focus();"/>
+                <menu label="Library Filter" id="stat_cat_lib_filter_menu">
+                    <menupopup />
+                </menu>
 				<vbox id="right_pane4" flex="1"/>
 			</vbox>
 		</hbox>



More information about the open-ils-commits mailing list