From 4c638f750e0fb4392f05a98c452ec8c194c6565e Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Wed, 28 Feb 2018 15:45:07 -0500 Subject: [PATCH] LP#1680566 - WIP follow-up - pcrud CUD != permacrud This patch partially accounts for the fact that open-ils.pcrud.{create|delete|update}.foo is /not/ a drop-in replacement for the open-ils.permacrud equivalents, as open-ils.pcrud requires that the client establish a session and begin a transaction first. This patch addresses the following: - creating, updating, and deleting bib and authority record display attributes in Vandelay - saving records when the XUL MARC editor is invoked from Vandelay - the translator popup-dialog (e.g., as used by the copy status admin page) Left TODO: - deleting MFHDs and invoking the MARC editor on them Signed-off-by: Galen Charlton --- .../web/js/dojo/openils/widget/TranslatorPopup.js | 76 +++++++++++++--------- Open-ILS/web/js/ui/default/vandelay/vandelay.js | 73 +++++++++------------ 2 files changed, 75 insertions(+), 74 deletions(-) diff --git a/Open-ILS/web/js/dojo/openils/widget/TranslatorPopup.js b/Open-ILS/web/js/dojo/openils/widget/TranslatorPopup.js index 6f1599c697..6f85911f9d 100644 --- a/Open-ILS/web/js/dojo/openils/widget/TranslatorPopup.js +++ b/Open-ILS/web/js/dojo/openils/widget/TranslatorPopup.js @@ -220,40 +220,52 @@ if(!dojo._hasResource["openils.widget.TranslatorPopup"]) { } } - OpenSRF.CachedClientSession('open-ils.pcrud').request({ - method : 'open-ils.pcrud.' + method + '.i18n', - timeout: 10, - params : [ ses, trans_obj ], - onerror: function (r) { - //highlighter.editor_pane.red.play(); - if ((typeof status_update != "undefined") && status_update) status_update( 'Problem saving translation for ' + _trans_dijit._targetObject[_trans_dijit.field]() ); - }, - oncomplete : function (r) { - var res = r.recv(); - if ( res && res.content() ) { - //highlighter.editor_pane.green.play(); - if ((typeof status_update != "undefined") && status_update) status_update( 'Saved changes to translation for ' + _trans_dijit._targetObject[_trans_dijit.field]() ); - - if (method == 'delete') { - dojo.NodeList(dojo.byId('translation_row_' + trans_obj.id())).orphan(); - } else if (method == 'create') { - var node = dojo.byId(_trans_dijit.field + '_translation_tooltip_' + _trans_dijit.unique); - dijit.byId('i18n_new_locale_' + _trans_dijit._targetObject.classname + '.' + _trans_dijit.field + _trans_dijit.unique).setValue(null); - dijit.byId('i18n_new_translation_' + _trans_dijit._targetObject.classname + '.' + _trans_dijit.field + _trans_dijit.unique).setValue(null); - _trans_dijit.renderTranslatorPopup(); - } - - } else { - //highlighter.editor_pane.red.play(); - if ((typeof status_update != "undefined") && status_update) status_update( 'Problem saving translation for ' + _trans_dijit._targetObject[_trans_dijit.field]() ); - } - }, - }).send(); - } + var pcrud = new OpenSRF.ClientSession("open-ils.pcrud"); + pcrud.connect(); + pcrud.request({ + method : 'open-ils.pcrud.transaction.begin', + params : [ ses ], + oncomplete : function(r) { + pcrud.request({ + method : 'open-ils.pcrud.' + method + '.i18n', + timeout: 10, + params : [ ses, trans_obj ], + onerror: function (r) { + //highlighter.editor_pane.red.play(); + if ((typeof status_update != "undefined") && status_update) status_update( 'Problem saving translation for ' + _trans_dijit._targetObject[_trans_dijit.field]() ); + }, + oncomplete : function (r) { + var res = r.recv(); + if ( res && res.content() ) { + // fire off a commit + pcrud.request({ + method : 'open-ils.pcrud.transaction.commit', + params : [ ses ] + }).send(); + //highlighter.editor_pane.green.play(); + if ((typeof status_update != "undefined") && status_update) status_update( 'Saved changes to translation for ' + _trans_dijit._targetObject[_trans_dijit.field]() ); + + if (method == 'delete') { + dojo.NodeList(dojo.byId('translation_row_' + trans_obj.id())).orphan(); + } else if (method == 'create') { + var node = dojo.byId(_trans_dijit.field + '_translation_tooltip_' + _trans_dijit.unique); + dijit.byId('i18n_new_locale_' + _trans_dijit._targetObject.classname + '.' + _trans_dijit.field + _trans_dijit.unique).setValue(null); + dijit.byId('i18n_new_translation_' + _trans_dijit._targetObject.classname + '.' + _trans_dijit.field + _trans_dijit.unique).setValue(null); + _trans_dijit.renderTranslatorPopup(); + } + + } else { + //highlighter.editor_pane.red.play(); + if ((typeof status_update != "undefined") && status_update) status_update( 'Problem saving translation for ' + _trans_dijit._targetObject[_trans_dijit.field]() ); + } + }, + }).send() } + }).send(); + } - } + } - ); + ); openils.widget.TranslatorPopup._unique = 1; diff --git a/Open-ILS/web/js/ui/default/vandelay/vandelay.js b/Open-ILS/web/js/ui/default/vandelay/vandelay.js index c45918ff34..3e04e44a04 100644 --- a/Open-ILS/web/js/ui/default/vandelay/vandelay.js +++ b/Open-ILS/web/js/ui/default/vandelay/vandelay.js @@ -1750,11 +1750,7 @@ function vlOpenMarcEditWindow(rec, postReloadHTMLHandler) { type = 'are'; } - function onsave(r) { - // after the record is saved, reload the HTML display - var stat = r.recv().content(); - if(e = openils.Event.parse(stat)) - return alert(e); + function onsave() { alert(dojo.byId('vl-marc-edit-complete-label').innerHTML); win.close(); vlLoadMARCHtml(rec.id(), false, postReloadHTMLHandler); @@ -1765,15 +1761,11 @@ function vlOpenMarcEditWindow(rec, postReloadHTMLHandler) { save : { label: dojo.byId('vl-marc-edit-save-label').innerHTML, func: function(xmlString) { - var method = 'open-ils.pcrud.update.' + rec.classname; + var pcrud = new openils.PermaCrud(); rec.marc(xmlString); - fieldmapper.standardRequest( - ['open-ils.pcrud', method], - { async: true, - params: [authtoken, rec], - oncomplete: onsave - } - ); + pcrud.update(rec, { + oncomplete: onsave + }); }, }, 'lock_tab' : typeof xulG != 'undefined' ? (typeof xulG['lock_tab'] != 'undefined' ? xulG.lock_tab : undefined) : undefined, @@ -1915,26 +1907,27 @@ function vlSaveAttrDefinition(data) { var isAuth = (ATTR_EDIT_GROUP == 'auth'); var isCreate = (ATTR_EDIT_ID == null); var rad = isAuth ? new vqarad() : new vqbrad() ; - var method = 'open-ils.pcrud' + (isCreate ? '.create.' : '.update.') + (isAuth ? 'vqarad' : 'vqbrad'); var _data = rad.fromStoreItem(data); - _data.ischanged(1); - - fieldmapper.standardRequest( - ['open-ils.pcrud', method], - { async: true, - params: [authtoken, _data ], - onresponse: function(r) { }, - oncomplete: function(r) { - attrEditorFetchAttrDefs(vlShowAttrEditor); - ATTR_EDIT_ID = null; - }, - onerror: function(r) { - alert('vlSaveAttrDefinition comms error: ' + r); - } + var pcrud = new openils.PermaCrud(); + var postreq = { + oncomplete : function() { + attrEditorFetchAttrDefs(vlShowAttrEditor); + ATTR_EDIT_ID = null; + }, + onerror: function(r) { + alert('vlSaveAttrDefinition comms error: ' + r); } - ); + }; + if (isCreate) { + _data.isnew(1); + pcrud.create(_data, postreq); + } else { + _data.ischanged(1); + pcrud.update(_data, postreq); + } + } function attrEditorFetchAttrDefs(callback) { @@ -1947,22 +1940,18 @@ function vlAttrDelete() { idShow('vl-generic-progress'); var isAuth = (ATTR_EDIT_GROUP == 'auth'); - var method = 'open-ils.pcrud.delete.' + (isAuth ? 'vqarad' : 'vqbrad'); var rad = isAuth ? new vqarad() : new vqbrad() ; - fieldmapper.standardRequest( - ['open-ils.pcrud', method], - { async: true, - params: [authtoken, rad.fromHash({ id : ATTR_EDIT_ID }), ], + var pcrud = new openils.PermaCrud(); + pcrud.eliminate(rad.fromHash({ id : ATTR_EDIT_ID }), { oncomplete: function() { - dijit.byId('attr-editor-dialog').onCancel(); // close the dialog - attrEditorFetchAttrDefs(vlShowAttrEditor); - ATTR_EDIT_ID = null; - }, - onerror: function(r) { - alert('vlAttrDelete comms error: ' + r); - } + dijit.byId('attr-editor-dialog').onCancel(); // close the dialog + attrEditorFetchAttrDefs(vlShowAttrEditor); + ATTR_EDIT_ID = null; + }, + onerror: function(r) { + alert('vlAttrDelete comms error: ' + r); } - ); + }); } // ------------------------------------------------------------ -- 2.11.0