@@ -, +, @@ --- admin/floating-matrix-api.pl | 10 ++++ .../prog/en/css/admin/floating-matrix.css | 8 +++ .../prog/en/js/admin/floating-matrix.js | 64 ++++++++++++++++++++++ .../prog/en/modules/admin/floating-matrix.tt | 27 +++++++++ 4 files changed, 109 insertions(+) --- a/admin/floating-matrix-api.pl +++ a/admin/floating-matrix-api.pl @@ -25,6 +25,7 @@ use JSON::XS; use C4::Context; use C4::Output; use C4::Auth qw(check_cookie_auth); +use C4::Items; use Koha::FloatingMatrix; @@ -52,6 +53,15 @@ if ($data) { $fm->deleteBranchRule($data->{fromBranch}, $data->{toBranch}); $fm->store(); } + elsif ($data->{test}) { + my $item = C4::Items::GetItem(undef, $data->{barcode}); + if ($data->{barcode} && $item) { + $data->{testResult} = $fm->checkFloating($item, $data->{fromBranch}, $data->{toBranch}); + } + else { + Koha::Exception::BadParameter->throw(error => "No Item found using barcode '".$data->{barcode}."'"); + } + } ##If we are getting a POST-request, we UPSERT else { $fm->upsertBranchRule($data); --- a/koha-tmpl/intranet-tmpl/prog/en/css/admin/floating-matrix.css +++ a/koha-tmpl/intranet-tmpl/prog/en/css/admin/floating-matrix.css @@ -1,6 +1,14 @@ .disabled-transfer { background-color: #FF8888; } + +#testResulDisplay { width: 20px; + height: 22px; + background-color: #B9D8D9; + vertical-align: middle; + display: inline-block; +} + .branchRule select { width: 100%; } .branchRule select {padding: 0px; margin: 5px 0px;} --- a/koha-tmpl/intranet-tmpl/prog/en/js/admin/floating-matrix.js +++ a/koha-tmpl/intranet-tmpl/prog/en/js/admin/floating-matrix.js @@ -1,5 +1,6 @@ ////Create javascript namespace var FloMax = FloMax || {}; +FloMax.Tester = FloMax.Tester || {}; //// DOCUMENT READY INIT SCRIPTS @@ -15,6 +16,13 @@ $(document).ready(function() { FloMax.changeBranchRuleColor(this); }); + //Bind actions to the FloMax Tester + $("#floatingRuleTester input[type='submit']").bind({ + click: function() { + FloMax.Tester.testFloating(); + } + }); + //Bind action listeners to the floating matrix $(".branchRule").bind({ click: function() { @@ -183,4 +191,60 @@ FloMax.persistBranchRule = function (brJSON, branchRule) { alert("Saving floating rule "+brJSON.fromBranch+"-"+brJSON.toBranch+" failed, because of the following error:\n"+data.status+" "+data.statusText+"\n"+"More specific error: "+error.error); }); } +} + +FloMax.Tester.defaultTestResultColor = "#B9D8D9"; + +FloMax.Tester.testFloating = function() { + var testCase = FloMax.Tester.buildTestCaseFromHTML(); + $(".cssload-loader").css('visibility', 'visible'); + + $.ajax('floating-matrix-api.pl', + {method : 'POST', + data : testCase, + dataType : 'json', + }).done(function(data, textStatus, jqXHR){ + + FloMax.Tester.displayTestResult(data.testResult); + + }).fail(function (data, textStatus, jqXHR) { + var error = $.parseJSON(data.responseText); //Pass the error as JSON so we don't trigger the default Koha error pages. + alert("Testing floating rule "+testCase.fromBranch+"-"+testCase.toBranch+" failed, because of the following error:\n"+data.status+" "+data.statusText+"\n"+"More specific error: "+error.error); + FloMax.Tester.displayTestResult("error"); + }); +} +FloMax.Tester.buildTestCaseFromHTML = function () { + var fromBranch = $("#floatingRuleTester #testerFromBranch").val(); + var toBranch = $("#floatingRuleTester #testerToBranch").val(); + var barcode = $("#floatingRuleTester #testerBarcode").val(); + + var testCase = { + 'fromBranch' : fromBranch, + 'toBranch' : toBranch, + 'barcode' : barcode, + 'test': true, + }; + return testCase; +} +FloMax.Tester.displayTestResult = function (testResult) { + $(".cssload-loader").css('visibility', 'hidden'); + var color; + if (testResult == null) { + color = FloMax.branchRuleDisabledColor; + } + else if (testResult == 'ALWAYS') { + color = FloMax.branchRuleAlwaysColor; + } + else if (testResult == 'POSSIBLE') { + color = FloMax.branchRulePossibleColor; + } + else if (testResult == "error") { + color = FloMax.Tester.defaultTestResultColor; + } + else { + color = FloMax.Tester.defaultTestResultColor; + alert("Couldn't display test result '"+testResult+"'. Value is unknown."); + } + + $("#testResulDisplay").css('background-color', color); } --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/floating-matrix.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/floating-matrix.tt @@ -1,6 +1,7 @@ [% INCLUDE 'doc-head-open.inc' %] Koha › Administration › Floating matrix + [% INCLUDE 'doc-head-close.inc' %] @@ -38,6 +39,32 @@ +
+ Floating rule tester +
+ + + + + + + +
+
+
+
+
+
+
+ --
From \ To