From: Lebbeous Fogle-Weekley Date: Mon, 24 Sep 2012 17:24:04 +0000 (-0400) Subject: Session cloning, working and rather tested X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=5ce3e8a05e1f4fd93b3ce339d478067c783f8032;p=evergreen%2Fequinox.git Session cloning, working and rather tested Signed-off-by: Lebbeous Fogle-Weekley --- diff --git a/Open-ILS/src/templates/url_verify/create_session.tt2 b/Open-ILS/src/templates/url_verify/create_session.tt2 index 493c3218ff..72983e90ab 100644 --- a/Open-ILS/src/templates/url_verify/create_session.tt2 +++ b/Open-ILS/src/templates/url_verify/create_session.tt2 @@ -56,7 +56,7 @@
- [% l("This will only be used if your search doesn't contain a hand-entered filter such as site(BR1)") %] + [% l("This will only be used if your search doesn't contain an explicit filter such as site(BR1)") %] @@ -84,7 +84,11 @@ constant load time regardless of dataset size. --> - [% l("Optionally select one or more to combine with 'Search' field above.") %] + +

[% l("Optionally select one or more to combine with 'Search' field above.") %]

+ @@ -102,16 +106,16 @@ - [% l('Tags and subfields possibly containing URLs:') %] + [% l('Tags and subfields to search for URLs:') %]
[% l("Tag") %] - + [% l("Subfield(s)") %] - + [% l('Add') %]
diff --git a/Open-ILS/web/js/dojo/openils/URLVerify/CreateSession.js b/Open-ILS/web/js/dojo/openils/URLVerify/CreateSession.js index e0c16193a0..c17681caf9 100644 --- a/Open-ILS/web/js/dojo/openils/URLVerify/CreateSession.js +++ b/Open-ILS/web/js/dojo/openils/URLVerify/CreateSession.js @@ -3,6 +3,7 @@ if (!dojo._hasResource["openils.URLVerify.CreateSession"]) { dojo.require("dojox.jsonPath"); dojo.require("fieldmapper.OrgUtils"); dojo.require("openils.Util"); + dojo.require("openils.CGI"); dojo.require("openils.PermaCrud"); dojo.require("openils.widget.FilteringTreeSelect"); dojo.require("openils.URLVerify.Verify"); @@ -203,8 +204,9 @@ if (!dojo._hasResource["openils.URLVerify.CreateSession"]) { * fewer moving parts that can go haywire anyway. */ module._populate_saved_searches = function(node) { - var pcrud = new openils.PermaCrud(); - var list = pcrud.retrieveAll("asq", {"order_by": {"asq": "label"}}); + var list = module.pcrud.retrieveAll( + "asq", {"order_by": {"asq": "label"}} + ); dojo.forEach( list, function(o) { @@ -217,8 +219,6 @@ if (!dojo._hasResource["openils.URLVerify.CreateSession"]) { ); } ); - - pcrud.disconnect(); }; /* set up an all-org-units-in-the-tree selector */ @@ -234,7 +234,34 @@ if (!dojo._hasResource["openils.URLVerify.CreateSession"]) { module.org_selector = widget; }; + /* Can only be called by setup() */ + module._clone = function(id) { + module.progress_dialog.attr("title", localeStrings.CLONING); + var old_session = module.pcrud.retrieve( + "uvs", id, {"flesh": 1, "flesh_fields": {"uvs": ["selectors"]}} + ); + + /* Set name to "Copy of [old name]" */ + uv_session_name.attr( + "value", dojo.string.substitute( + localeStrings.CLONE_SESSION_NAME, [old_session.name()] + ) + ); + + /* Set search field. */ + uv_search.attr("value", old_session.search()); + + /* Explain to user why we don't affect the saved searches picker. */ + if (old_session.search().match(/saved_query/)) + openils.Util.show("clone-saved-search-warning"); + + /* Add related xpaths (URL selectors) to TagAndSubfieldsMgr. */ + module.tag_and_subfields.add_xpaths(old_session.selectors()); + }; + module.setup = function(saved_search_id, org_selector_id, progress_dialog) { + module.pcrud = new openils.PermaCrud(); /* only used for setup */ + module.progress_dialog = progress_dialog; module.progress_dialog.attr("title", localeStrings.INTERFACE_SETUP); @@ -243,6 +270,12 @@ if (!dojo._hasResource["openils.URLVerify.CreateSession"]) { module._populate_saved_searches(dojo.byId(saved_search_id)); module._prepare_org_selector(dojo.byId(org_selector_id)); + var cgi = new openils.CGI(); + if (cgi.param("clone")) + module._clone(cgi.param("clone")); + + module.pcrud.disconnect(); + module.progress_dialog.hide(); }; @@ -286,8 +319,37 @@ if (!dojo._hasResource["openils.URLVerify.CreateSession"]) { "innerHTML": "[X]" /* XXX i18n */ }, div, "last" ); + }; + + this.add_xpaths = function(xpaths) { + if (!dojo.isArray(xpaths)) { + console.info("No xpaths to add"); + return; + } - this.counter++; + dojo.forEach( + xpaths, dojo.hitch(this, function(xpath) { + var newid = "t-and-s-row-" + String(this.counter++); + var div = dojo.create( + "div", { + "id": newid, + "innerHTML": localeStrings.XPATH + + " " + + xpath.xpath() + "" + }, this.container_id, "last" + ); + dojo.create( + "a", { + "href": "javascript:void(0);", + "onclick": function() { + var me = dojo.byId(newid); + me.parentNode.removeChild(me); + }, + "innerHTML": "[X]" /* XXX i18n */ + }, div, "last" + ); + }) + ); }; /* return a boolean indicating whether or not we have any rows */ @@ -307,27 +369,52 @@ if (!dojo._hasResource["openils.URLVerify.CreateSession"]) { '[id^="t-and-s-row-"]', dojo.byId(this.container_id) ).forEach( function(row) { - var tag = dojo.query(".t-and-s-tag", row)[0].innerHTML; - var subfield = dojo.query(".t-and-s-subfields", row)[0].innerHTML; - - var existing; - if ((existing = uniquely_grouped[tag])) { /* sic, assignment */ - existing = openils.Util.uniqueElements( - (existing + subfield).split("") - ).sort().join(""); + var holds_xpath = dojo.query(".t-and-s-xpath", row); + if (holds_xpath.length) { + uniquely_grouped.xpath = uniquely_grouped.xpath || []; + uniquely_grouped.xpath.push(holds_xpath[0].innerHTML); } else { - uniquely_grouped[tag] = subfield; + var tag = dojo.query(".t-and-s-tag", row)[0].innerHTML; + var subfield = + dojo.query(".t-and-s-subfields", row)[0].innerHTML; + + var existing; + if ((existing = uniquely_grouped[tag])) { // assignment + existing = openils.Util.uniqueElements( + (existing + subfield).split("") + ).sort().join(""); + } else { + uniquely_grouped[tag] = subfield; + } } } ); var uvus_list = []; + /* Handle things that are already in XPath form first (these + * come from cloning link checker sessions. */ + if (uniquely_grouped.xpath) { + dojo.forEach( + uniquely_grouped.xpath, + function(xpath) { + var obj = new uvus(); + + obj.session(session_id); + obj.xpath(xpath); + uvus_list.push(obj); + } + ); + delete uniquely_grouped.xpath; + } + + /* Now handle anything entered by hand. */ for (var tag in uniquely_grouped) { var obj = new uvus(); obj.session(session_id); - /* XXX TODO handle control fields (no subfields) */ + /* XXX TODO Handle control fields (No subfields. but would + * control fields ever contain URLs? Don't know.) */ obj.xpath( "//*[@tag='" + tag + "']/*[" + uniquely_grouped[tag].split("").map( diff --git a/Open-ILS/web/js/dojo/openils/URLVerify/nls/URLVerify.js b/Open-ILS/web/js/dojo/openils/URLVerify/nls/URLVerify.js index 2fc04c2e0b..d1ca998691 100644 --- a/Open-ILS/web/js/dojo/openils/URLVerify/nls/URLVerify.js +++ b/Open-ILS/web/js/dojo/openils/URLVerify/nls/URLVerify.js @@ -12,5 +12,8 @@ "NOTHING_SELECTED": "No rows are selected, so no action will be taken.", "REVIEW_ATTEMPT": "Review this verification attempt", "CLONE_SESSION": "Clone", - "REREVIEW": "Review / Verify" + "REREVIEW": "Review / Verify", + "CLONING": "Cloning existing session ...", + "CLONE_SESSION_NAME": "Copy of ${0}", + "XPATH": "XPath" }