[open-ils-commits] r8352 - in trunk/Open-ILS/xul/staff_client/server: admin cat circ

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Jan 8 14:52:42 EST 2008


Author: phasefx
Date: 2008-01-08 14:28:15 -0500 (Tue, 08 Jan 2008)
New Revision: 8352

Modified:
   trunk/Open-ILS/xul/staff_client/server/admin/transit_list.js
   trunk/Open-ILS/xul/staff_client/server/cat/copy_browser.js
   trunk/Open-ILS/xul/staff_client/server/cat/copy_buckets.js
   trunk/Open-ILS/xul/staff_client/server/cat/copy_editor.js
   trunk/Open-ILS/xul/staff_client/server/cat/util.js
   trunk/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js
   trunk/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.xul
   trunk/Open-ILS/xul/staff_client/server/circ/checkin.js
   trunk/Open-ILS/xul/staff_client/server/circ/copy_status.js
Log:
refactor spawn_copy_editor and perm check

Modified: trunk/Open-ILS/xul/staff_client/server/admin/transit_list.js
===================================================================
--- trunk/Open-ILS/xul/staff_client/server/admin/transit_list.js	2008-01-08 19:12:45 UTC (rev 8351)
+++ trunk/Open-ILS/xul/staff_client/server/admin/transit_list.js	2008-01-08 19:28:15 UTC (rev 8352)
@@ -433,11 +433,9 @@
 	
 	'spawn_copy_editor' : function(which_list) {
 
-		/* FIXME -  a lot of redundant calls here */
-
 		var obj = this;
 
-		JSAN.use('util.widgets'); JSAN.use('util.functional');
+		JSAN.use('util.functional');
 
 		var list = which_list == 0 ? obj.selection_list : obj.selection_list2;
 
@@ -448,36 +446,8 @@
 			}
 		);
 
-		var copies = util.functional.map_list(
-			list,
-			function (acp_id) {
-				return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]);
-			}
-		);
+		JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } );
 
-		var edit = 0;
-		try {
-			edit = obj.network.request(
-				api.PERM_MULTI_ORG_CHECK.app,
-				api.PERM_MULTI_ORG_CHECK.method,
-				[ 
-					ses(), 
-					obj.data.list.au[0].id(), 
-					util.functional.map_list(
-						copies,
-						function (o) {
-							return o.call_number() == -1 ? o.circ_lib() : obj.network.simple_request('FM_ACN_RETRIEVE',[o.call_number()]).owning_lib();
-						}
-					),
-					copies.length == 1 ? [ 'UPDATE_COPY' ] : [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
-				]
-			).length == 0 ? 1 : 0;
-		} catch(E) {
-			obj.error.sdump('D_ERROR','batch permission check: ' + E);
-		}
-
-		JSAN.use('cat.util'); cat.util.spawn_copy_editor(list,edit);
-
 	},
 
 }

Modified: trunk/Open-ILS/xul/staff_client/server/cat/copy_browser.js
===================================================================
--- trunk/Open-ILS/xul/staff_client/server/cat/copy_browser.js	2008-01-08 19:12:45 UTC (rev 8351)
+++ trunk/Open-ILS/xul/staff_client/server/cat/copy_browser.js	2008-01-08 19:28:15 UTC (rev 8352)
@@ -295,33 +295,7 @@
 										}
 									);
 
-									var edit = 0;
-									try {
-										edit = obj.network.request(
-											api.PERM_MULTI_ORG_CHECK.app,
-											api.PERM_MULTI_ORG_CHECK.method,
-											[ 
-												ses(), 
-												obj.data.list.au[0].id(), 
-												util.functional.map_list(
-													list,
-													function (o) {
-														var o_acp = obj.map_acp[ 'acp_' + o ];
-														if (o_acp.call_number() == -1) {
-															return o_acp.circ_lib();
-														} else {
-															return obj.map_acn[ 'acn_' + o_acp.call_number() ].owning_lib();
-														}
-													}
-												),
-												list.length == 1 ? [ 'UPDATE_COPY' ] : [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
-											]
-										).length == 0 ? 1 : 0;
-									} catch(E) {
-										obj.error.sdump('D_ERROR','batch permission check: ' + E);
-									}
-
-									JSAN.use('cat.util'); cat.util.spawn_copy_editor(list,edit);
+									JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } );
 									obj.refresh_list();
 
 								} catch(E) {

Modified: trunk/Open-ILS/xul/staff_client/server/cat/copy_buckets.js
===================================================================
--- trunk/Open-ILS/xul/staff_client/server/cat/copy_buckets.js	2008-01-08 19:12:45 UTC (rev 8351)
+++ trunk/Open-ILS/xul/staff_client/server/cat/copy_buckets.js	2008-01-08 19:28:15 UTC (rev 8352)
@@ -390,40 +390,11 @@
 									}
 								);
 
-								var copies = util.functional.map_list(
-									list,
-									function (acp_id) {
-										return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]);
-									}
-								);
+								JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } );
 
-								var edit = 0;
-								try {
-									edit = obj.network.request(
-										api.PERM_MULTI_ORG_CHECK.app,
-										api.PERM_MULTI_ORG_CHECK.method,
-										[ 
-											ses(), 
-											obj.data.list.au[0].id(), 
-											util.functional.map_list(
-												copies,
-												function (o) {
-													return o.call_number() == -1 ? o.circ_lib() : obj.network.simple_request('FM_ACN_RETRIEVE',[o.call_number()]).owning_lib();
-												}
-											),
-											copies.length == 1 ? [ 'UPDATE_COPY' ] : [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
-										]
-									).length == 0 ? 1 : 0;
-								} catch(E) {
-									obj.error.sdump('D_ERROR','batch permission check: ' + E);
-								}
-
-								JSAN.use('cat.util'); cat.util.spawn_copy_editor(list,edit);
-
 								obj.render_pending_copies(); // FIXME -- need a generic refresh for lists
 								setTimeout(
 									function() {
-										JSAN.use('util.widgets'); 
 										util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
 									}, 0
 								);

Modified: trunk/Open-ILS/xul/staff_client/server/cat/copy_editor.js
===================================================================
--- trunk/Open-ILS/xul/staff_client/server/cat/copy_editor.js	2008-01-08 19:12:45 UTC (rev 8351)
+++ trunk/Open-ILS/xul/staff_client/server/cat/copy_editor.js	2008-01-08 19:28:15 UTC (rev 8352)
@@ -1,4 +1,5 @@
 var g = {};
+g.map_acn = {};
 
 var xulG = {};
 
@@ -54,10 +55,47 @@
 		/* Is the interface an editor or a viewer, single or multi copy, existing copies or new copies? */
 
 		if (xul_param('edit',{'modal_xulG':true}) == '1') { 
-			g.edit = true;
-			document.getElementById('caption').setAttribute('label','Copy Editor'); 
-			document.getElementById('save').setAttribute('hidden','false'); 
-			g.retrieve_templates();
+
+            // Editor desired, but let's check permissions
+			g.edit = false;
+
+            try {
+                var check = g.network.simple_request(
+                    'PERM_MULTI_ORG_CHECK',
+                    [ 
+                        ses(), 
+                        g.data.list.au[0].id(), 
+                        util.functional.map_list(
+                            g.copies,
+                            function (o) {
+                                var lib;
+                                var cn_id = o.call_number();
+                                if (cn_id == -1) {
+                                    lib = o.circ_lib(); // base perms on circ_lib instead of owning_lib if pre-cat
+                                } else {
+                                    if (! g.map_acn[ cn_id ]) {
+                                        g.map_acn[ cn_id ] = g.network.simple_request('FM_ACN_RETRIEVE',[ cn_id ]);
+                                    }
+                                    lib = g.map_acn[ cn_id ].owning_lib();
+                                }
+                                return lib;
+                            }
+                        ),
+                        g.copies.length == 1 ? [ 'UPDATE_COPY' ] : [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
+                    ]
+                );
+                g.edit = check.length == 0;
+            } catch(E) {
+                g.error.standard_unexpected_error_alert('batch permission check',E);
+            }
+
+			if (g.edit) {
+                document.getElementById('caption').setAttribute('label','Copy Editor'); 
+    			document.getElementById('save').setAttribute('hidden','false'); 
+    			g.retrieve_templates();
+            } else {
+			    $('top_nav').setAttribute('hidden','true');
+            }
 		} else {
 			$('top_nav').setAttribute('hidden','true');
 		}
@@ -381,7 +419,6 @@
 /******************************************************************************************************/
 /* 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');
 	for (var i = 0; i < g.copies.length; i++) {

Modified: trunk/Open-ILS/xul/staff_client/server/cat/util.js
===================================================================
--- trunk/Open-ILS/xul/staff_client/server/cat/util.js	2008-01-08 19:12:45 UTC (rev 8351)
+++ trunk/Open-ILS/xul/staff_client/server/cat/util.js	2008-01-08 19:28:15 UTC (rev 8352)
@@ -217,39 +217,36 @@
 	);
 }
 
-cat.util.spawn_copy_editor = function(list,edit) {
+cat.util.spawn_copy_editor = function(params) {
 	try {
+        if (!params.copy_ids && !params.copies) return;
+		if (params.copy_ids && params.copy_ids.length == 0) return;
+		if (params.copies && params.copies.length == 0) return;
+        if (params.copy_ids) params.copy_ids = js2JSON(params.copy_ids); // legacy
+        if (!params.caller_handles_update) params.handle_update = 1; // legacy
+
 		var obj = {};
 		JSAN.use('util.network'); obj.network = new util.network();
 		JSAN.use('util.error'); obj.error = new util.error();
 	
-		if (list.length == 0) return;
-	
-		var title = list.length == 1 ? '' : 'Batch '; 
-		title += edit == 1 ? 'Edit' : 'View';
+		var title = '';
+		if ((params.copy_ids && params.copy_ids.length > 1) || (params.copies && params.copies.length > 1 )) title += 'Batch ';
+		title += params.edit == 1 ? 'Edit' : 'View';
 		title += ' Copy Attributes';
 	
 		JSAN.use('util.window'); var win = new util.window();
-		//JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
-		//obj.data.temp_copies = undefined; obj.data.stash('temp_copies');
-		//obj.data.temp_callnumbers = undefined; obj.data.stash('temp_callnumbers');
-		//obj.data.temp_copy_ids = js2JSON(list); obj.data.stash('temp_copy_ids');
 		var my_xulG = win.open(
-			//window.xulG.url_prefix(urls.XUL_COPY_EDITOR),
 			(urls.XUL_COPY_EDITOR),
-			//	+'?handle_update=1&edit='+edit,
 			title,
 			'chrome,modal,resizable',
-			{
-				'handle_update' : 1,
-				'edit' : edit,
-				'copy_ids' : js2JSON(list),
-			}
+            params
 		);
-		//obj.data.stash_retrieve();
-		if (!my_xulG.copies) alert('Copies not modified.');
-		//if (!obj.data.temp_copies) alert('Copies not modified.');
-		//obj.data.temp_copies = undefined; obj.data.stash('temp_copies');
+		if (!my_xulG.copies && params.edit) {
+            alert(typeof params.no_copies_modified_msg != 'undefined' ? params.no_copies_modified_msg : 'Copies not modified.');
+        } else {
+            return my_xulG.copies;
+        }
+        return [];
 	} catch(E) {
 		JSAN.use('util.error'); var error = new util.error();
 		error.standard_unexpected_error_alert('error in cat.util.spawn_copy_editor',E);

Modified: trunk/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js
===================================================================
--- trunk/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js	2008-01-08 19:12:45 UTC (rev 8351)
+++ trunk/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js	2008-01-08 19:28:15 UTC (rev 8352)
@@ -1,4 +1,6 @@
 const g_max_copies_that_can_be_added_at_a_time_per_volume = 100;
+var g = {};
+
 function my_init() {
 	try {
 
@@ -377,48 +379,26 @@
 
 		JSAN.use('util.window'); var win = new util.window();
 		if (copies.length > 0) {
-			//g.data.temp_copies = js2JSON(copies); g.data.stash('temp_copies');
-			//g.data.temp_copy_ids = undefined; g.data.stash('temp_copy_ids');
-			////g.data.temp_callnumbers = js2JSON(volume_labels); g.data.stash('temp_callnumbers');
-			//g.data.temp_callnumbers = undefined; g.data.stash('temp_callnumbers');
-			var my_xulG = win.open(
-				urls.XUL_COPY_EDITOR,
-					//+'?edit=1&handle_update=1&docid='+window.escape(g.doc_id),
-				title,
-				'chrome,modal,resizable',
-				{ 'edit' : 1, 'handle_update' : 1, 'docid' : g.doc_id, 'copies' : copies }
-			);
-			/* FIXME -- need to unique the temp space, and not rely on modalness of window */
-			//g.data.stash_retrieve();
-			//copies = JSON2js( g.data.temp_copies );
-			copies = my_xulG.copies;
-			//g.data.temp_copy_ids = undefined; g.data.stash('temp_copy_ids');
-			//g.data.temp_copies = undefined; g.data.stash('temp_copies');
-			//g.data.temp_callnumbers = undefined; g.data.stash('temp_callnumbers');
-			if (!copies) {
-				alert('Items were not created.');
-				return;
-			} else {
-				try {
-					//case 1706 /* ITEM_BARCODE_EXISTS */ :
-					if (copies.length > 0 && $('print_labels').checked) {
-						JSAN.use('util.functional');
-						JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.stash_retrieve();
-						data.temp_barcodes_for_labels = util.functional.map_list( copies, function(o){return o.barcode();}) ; 
-						data.stash('temp_barcodes_for_labels');
-						var w = win.open(
-							urls.XUL_SPINE_LABEL,
-							'spine_labels',
-							'chrome,resizable,width=750,height=550'
-						);
-					}
-				} catch(E) {
-					g.error.standard_unexpected_error_alert('volume tree update 2',E);
-				}
+			JSAN.use('cat.util');
+            copies = cat.util.spawn_copy_editor( { 'edit' : 1, 'docid' : g.doc_id, 'copies' : copies });
+            try {
+                //case 1706 /* ITEM_BARCODE_EXISTS */ :
+                if (copies && copies.length > 0 && $('print_labels').checked) {
+                    JSAN.use('util.functional');
+                    JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.stash_retrieve();
+                    data.temp_barcodes_for_labels = util.functional.map_list( copies, function(o){return o.barcode();}) ; 
+                    data.stash('temp_barcodes_for_labels');
+                    var w = win.open(
+                        urls.XUL_SPINE_LABEL,
+                        'spine_labels',
+                        'chrome,resizable,width=750,height=550'
+                    );
+                }
+            } catch(E) {
+                g.error.standard_unexpected_error_alert('volume tree update 2',E);
+            }
+	}
 
-			}
-		}
-
 		if (typeof window.refresh == 'function') window.refresh();
 
 		window.close();

Modified: trunk/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.xul
===================================================================
--- trunk/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.xul	2008-01-08 19:12:45 UTC (rev 8351)
+++ trunk/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.xul	2008-01-08 19:28:15 UTC (rev 8352)
@@ -27,7 +27,7 @@
 	<!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
 	<!-- BEHAVIOR -->
         <script type="text/javascript">
-		var myPackageDir = 'open_ils_staff_client'; var IAMXUL = true; var g = {};
+		var myPackageDir = 'open_ils_staff_client'; var IAMXUL = true; 
 	</script>
         <scripts id="openils_util_scripts"/>
 

Modified: trunk/Open-ILS/xul/staff_client/server/circ/checkin.js
===================================================================
--- trunk/Open-ILS/xul/staff_client/server/circ/checkin.js	2008-01-08 19:12:45 UTC (rev 8351)
+++ trunk/Open-ILS/xul/staff_client/server/circ/checkin.js	2008-01-08 19:28:15 UTC (rev 8352)
@@ -418,11 +418,9 @@
 	
 	'spawn_copy_editor' : function() {
 
-		/* FIXME -  a lot of redundant calls here */
-
 		var obj = this;
 
-		JSAN.use('util.widgets'); JSAN.use('util.functional');
+		JSAN.use('util.functional');
 
 		var list = obj.selection_list;
 
@@ -433,36 +431,8 @@
 			}
 		);
 
-		var copies = util.functional.map_list(
-			list,
-			function (acp_id) {
-				return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]);
-			}
-		);
+		JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } );
 
-		var edit = 0;
-		try {
-			edit = obj.network.request(
-				api.PERM_MULTI_ORG_CHECK.app,
-				api.PERM_MULTI_ORG_CHECK.method,
-				[ 
-					ses(), 
-					obj.data.list.au[0].id(), 
-					util.functional.map_list(
-						copies,
-						function (o) {
-							return o.call_number() == -1 ? o.circ_lib() : obj.network.simple_request('FM_ACN_RETRIEVE',[o.call_number()]).owning_lib();
-						}
-					),
-					copies.length == 1 ? [ 'UPDATE_COPY' ] : [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
-				]
-			).length == 0 ? 1 : 0;
-		} catch(E) {
-			obj.error.sdump('D_ERROR','batch permission check: ' + E);
-		}
-
-		JSAN.use('cat.util'); cat.util.spawn_copy_editor(list,edit);
-
 	},
 
 }

Modified: trunk/Open-ILS/xul/staff_client/server/circ/copy_status.js
===================================================================
--- trunk/Open-ILS/xul/staff_client/server/circ/copy_status.js	2008-01-08 19:12:45 UTC (rev 8351)
+++ trunk/Open-ILS/xul/staff_client/server/circ/copy_status.js	2008-01-08 19:28:15 UTC (rev 8352)
@@ -1017,11 +1017,9 @@
 	
 	'spawn_copy_editor' : function() {
 
-		/* FIXME -  a lot of redundant calls here */
-
 		var obj = this;
 
-		JSAN.use('util.widgets'); JSAN.use('util.functional');
+		JSAN.use('util.functional');
 
 		var list = obj.selection_list;
 
@@ -1032,36 +1030,8 @@
 			}
 		);
 
-		var copies = util.functional.map_list(
-			list,
-			function (acp_id) {
-				return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]);
-			}
-		);
+		JSAN.use('cat.util'); cat.util.spawn_copy_editor( { 'copy_ids' : list, 'edit' : 1 } );
 
-		var edit = 0;
-		try {
-			edit = obj.network.request(
-				api.PERM_MULTI_ORG_CHECK.app,
-				api.PERM_MULTI_ORG_CHECK.method,
-				[ 
-					ses(), 
-					obj.data.list.au[0].id(), 
-					util.functional.map_list(
-						copies,
-						function (o) {
-							return o.call_number() == -1 ? o.circ_lib() : obj.network.simple_request('FM_ACN_RETRIEVE',[o.call_number()]).owning_lib();
-						}
-					),
-					copies.length == 1 ? [ 'UPDATE_COPY' ] : [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
-				]
-			).length == 0 ? 1 : 0;
-		} catch(E) {
-			obj.error.sdump('D_ERROR','batch permission check: ' + E);
-		}
-
-		JSAN.use('cat.util'); cat.util.spawn_copy_editor(list,edit);
-
 	},
 
 }



More information about the open-ils-commits mailing list