Session cloning, working and rather tested
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Mon, 24 Sep 2012 17:24:04 +0000 (13:24 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Mon, 24 Sep 2012 17:24:04 +0000 (13:24 -0400)
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/src/templates/url_verify/create_session.tt2
Open-ILS/web/js/dojo/openils/URLVerify/CreateSession.js
Open-ILS/web/js/dojo/openils/URLVerify/nls/URLVerify.js

index 493c321..72983e9 100644 (file)
@@ -56,7 +56,7 @@
                     <div id="org-selector"></div>
                 </td>
                 <td class="note">
-                    [% 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)") %]
                 </td>
             </tr>
 
                     constant load time regardless of dataset size. -->
                     <select id="saved-searches" multiple="true" size="6"></select>
                 </td>
-                <td class="note">[% l("Optionally select one or more to combine with 'Search' field above.") %]
+                <td class="note">
+                    <p>[% l("Optionally select one or more to combine with 'Search' field above.") %]</p>
+                    <p class="hidden" id="clone-saved-search-warning">
+                        [% l("NOTE: When cloning sessions, any saved searches used in the original session will already be mentioned in the 'Search' field above. You should not need to select them again here.") %]
+                    </p>
                 </td>
             </tr>
 
 
             <tr>
                 <th>
-                    [% l('Tags and subfields possibly containing URLs:') %]
+                    [% l('Tags and subfields to search for URLs:') %]
                 </th>
                 <td>
                     <div id="uv-tags-and-subfields">
                     </div>
                     <div class="tag-and-subfield-add-another">
                         [% l("Tag") %]
-                        <input type="text" size="4" maxlength="3" />
+                        <input type="text" size="3" maxlength="3" />
                         [% l("Subfield(s)") %]
-                        <input type="text" size="15" />
+                        <input type="text" size="8" />
                         <a href="javascript:module.tag_and_subfields.add();">[% l('Add') %]</a>
                     </div>
                 </td>
index e0c1619..c17681c 100644 (file)
@@ -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 +
+                                " <span class='t-and-s-xpath'>" +
+                                xpath.xpath() + "</span>"
+                        }, 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(
index 2fc04c2..d1ca998 100644 (file)
@@ -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"
 }