From a3c1a4365005db3ffa5ea17b82770cf9db5fd114 Mon Sep 17 00:00:00 2001 From: phasefx Date: Mon, 14 Aug 2006 16:22:51 +0000 Subject: [PATCH] safer copy editor with copy status git-svn-id: svn://svn.open-ils.org/ILS/trunk@5487 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../staff_client/chrome/content/main/constants.js | 10 ++++++++++ Open-ILS/xul/staff_client/server/cat/copy_editor.js | 20 +++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Open-ILS/xul/staff_client/chrome/content/main/constants.js b/Open-ILS/xul/staff_client/chrome/content/main/constants.js index be4edc56fb..3794bbc682 100644 --- a/Open-ILS/xul/staff_client/chrome/content/main/constants.js +++ b/Open-ILS/xul/staff_client/chrome/content/main/constants.js @@ -1,4 +1,14 @@ dump('Loading constants.js\n'); + +const my_constants = { + 'magical_statuses' : { + '1' : 't', /* | Checked out | t */ + '3' : 't', /* | Lost | f */ + '6' : 't', /* | In transit | t */ + '8' : 't', /* | On holds shelf | t */ + } +} + const api = { 'AUTH_INIT' : { 'app' : 'open-ils.auth', 'method' : 'open-ils.auth.authenticate.init' }, 'AUTH_COMPLETE' : { 'app' : 'open-ils.auth', 'method' : 'open-ils.auth.authenticate.complete' }, diff --git a/Open-ILS/xul/staff_client/server/cat/copy_editor.js b/Open-ILS/xul/staff_client/server/cat/copy_editor.js index 9c0bd963e0..9ba013d025 100644 --- a/Open-ILS/xul/staff_client/server/cat/copy_editor.js +++ b/Open-ILS/xul/staff_client/server/cat/copy_editor.js @@ -75,7 +75,8 @@ function my_init() { "Status", { render: 'typeof fm.status() == "object" ? fm.status().name() : g.data.hash.ccs[ fm.status() ].name()', - input: 'c = function(v){ g.apply("status",v); if (typeof post_c == "function") post_c(v); }; x = util.widgets.make_menulist( util.functional.map_list( g.data.list.ccs, function(obj) { return [ obj.name(), obj.id() ]; } ).sort() ); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);', + input: g.safe_to_edit_copy_status() ? 'c = function(v){ g.apply("status",v); if (typeof post_c == "function") post_c(v); }; x = util.widgets.make_menulist( util.functional.map_list( g.data.list.ccs, function(obj) { return [ obj.name(), obj.id(), typeof my_constants.magical_statuses[obj.id()] != "undefined" ? true : false ]; } ).sort() ); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);' : undefined, + //input: 'c = function(v){ g.apply("status",v); if (typeof post_c == "function") post_c(v); }; x = util.widgets.make_menulist( util.functional.map_list( util.functional.filter_list( g.data.list.ccs, function(obj) { return typeof my_constants.magical_statuses[obj.id()] == "undefined"; } ), function(obj) { return [ obj.name(), obj.id() ]; } ).sort() ); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);', } ] ].concat(g.panes_and_field_names.left_pane); @@ -349,6 +350,23 @@ g.apply_stat_cat = function(sc_id,entry_id) { } /******************************************************************************************************/ +/* This returns true if none of the copies being edited have a magical status found in my_constants.magical_statuses */ + +g.safe_to_edit_copy_status = function() { + try { + var safe = true; + for (var i = 0; i < g.copies.length; i++) { + var status = g.copies[i].status(); if (typeof status == 'object') status = status.id(); + if (typeof my_constants.magical_statuses[ status ] != 'undefined') safe = false; + } + return safe; + } catch(E) { + g.error.standard_unexpected_error_alert('safe_to_edit_copy_status?',E); + return false; + } +} + +/******************************************************************************************************/ /* This concats and uniques all the alert messages for use as the default value for a new alert message */ g.populate_alert_message_input = function(tb) { -- 2.11.0