From: Bill Erickson Date: Thu, 23 Aug 2012 21:29:42 +0000 (-0400) Subject: Improvements to custom org tree UI X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=e50d4cef406bee50dbb5ea780a0f06807736e38f;p=evergreen%2Fpines.git Improvements to custom org tree UI This replaced the PermaCrud.js create() calls with inline transaction begin, creates, and commit. We do this to solve a number of problems: * Create all new nodes within the same transaction so that a failure gracefully rolls back. * PermaCrud.js does not currently disconnect opensrf client sessions (though it has a disconnect() method). We can manage that locally. Signed-off-by: Bill Erickson Signed-off-by: Kathy Lussier --- diff --git a/Open-ILS/web/js/ui/default/conify/global/actor/org_unit_custom_tree.js b/Open-ILS/web/js/ui/default/conify/global/actor/org_unit_custom_tree.js index 88d35dca49..b4fd42aeaa 100644 --- a/Open-ILS/web/js/ui/default/conify/global/actor/org_unit_custom_tree.js +++ b/Open-ILS/web/js/ui/default/conify/global/actor/org_unit_custom_tree.js @@ -162,12 +162,19 @@ function applyChanges() { } function applyChanges2() { + + // pcrud.disconnect() exits before disconnecting the session. + // Clean up the session here. TODO: fix pcrud + pcrud.session.disconnect(); + pcrud.session.cleanup(); + ctNodes = []; var newCtNodes = []; var nodeList = []; var sorder = 0; var prevTn; var progress = 0; + var session = new OpenSRF.ClientSession('open-ils.pcrud'); // flatten child nodes into a level-order (by parent) list var nodeList = [magicTree.rootNode]; @@ -178,6 +185,19 @@ function applyChanges2() { } flatten(magicTree.rootNode); + // called after all nodes are processed + function finishUp() { + // commit the transaction + session.request({ + method : 'open-ils.pcrud.transaction.commit', + params : [ openils.User.authtoken ], + oncomplete : function (r) { + session.disconnect(); + location.href = location.href; + } + }).send(); + } + // traverse the nodes, creating new aoucnt's as we go function traverseAndCreate(node) { var item = node.item; @@ -199,25 +219,36 @@ function applyChanges2() { tn.sibling_order(++sorder); } else { sorder = 0; } - console.log("Creating new node for org unit " + tn.org_unit()); - - // create the new node, then process the children - pcrud.create(tn, { - oncomplete : function(r, objs) { - var newTn = objs[0]; + // create the new node, then process the children (async) + session.request({ + method : 'open-ils.pcrud.create.aouctn', + params : [ openils.User.authtoken, tn ], + oncomplete : function (r) { + var newTn = openils.Util.readResponse(r); + console.log("Created new node for org " + newTn.org_unit() + " => " + newTn.id()); ctNodes.push(newTn); prevTn = newTn; if (nodeList.length == 0) { - progressDialog.hide(); - location.href = location.href; + finishUp(); } else { progressDialog.update({maximum : nodeList.length, progress : ++progress}); traverseAndCreate(nodeList.shift()); } } - }); + }).send(); } - traverseAndCreate(nodeList.shift()); + + // kick things off... + session.connect(); + + // start the transaction + session.request({ + method : 'open-ils.pcrud.transaction.begin', + params : [ openils.User.authtoken ], + oncomplete : function (r) { + traverseAndCreate(nodeList.shift()); + } + }).send(); } function deleteSelected() {