diff --git a/apimanager/methodrouting/static/methodrouting/js/methodrouting.js b/apimanager/methodrouting/static/methodrouting/js/methodrouting.js index b16334d..6253f8e 100644 --- a/apimanager/methodrouting/static/methodrouting/js/methodrouting.js +++ b/apimanager/methodrouting/static/methodrouting/js/methodrouting.js @@ -1,14 +1,16 @@ $(document).ready(function($) { - $('.runner button#forSave').click(function() { + $('.runner button.forSave').click(function() { var t = $(this); var runner = $(this).parent().parent().parent(); - method_name = $(runner).find('#method_name').html(); - connector_name = $(runner).find('#connector_name').val(); + method_routing_id = $(runner).find('.method_routing_id').val(); + method_name = $(runner).find('.method_name').text(); + connector_name = $(runner).find('.connector_name').val(); bank_id_pattern = $(runner).find('textarea[name="bank_id_pattern"]').val(); - is_bank_id_exact_match = $(runner).find('#is_bank_id_exact_match').val(); + is_bank_id_exact_match = $(runner).find('.is_bank_id_exact_match').val(); parameters = $(runner).find('textarea[name="parameters"]').val(); $.post('methodrouting/save/method', { + 'method_routing_id': method_routing_id, 'method_name': method_name, 'connector_name': connector_name, 'bank_id_pattern': bank_id_pattern, @@ -18,4 +20,15 @@ $(document).ready(function($) { t.next().show().fadeOut(1000); }); }); + + $('.runner button.forDelete').click(function() { + var t = $(this); + var runner = $(this).parent().parent().parent(); + method_routing_id = $(runner).find('.method_routing_id').val(); + $.post('methodrouting/delete/method', { + 'method_routing_id': method_routing_id + }, function (response) { + t.next().show().fadeOut(1000); + }); + }); }); diff --git a/apimanager/methodrouting/templates/methodrouting/index.html b/apimanager/methodrouting/templates/methodrouting/index.html index dc0e56e..7fb855c 100644 --- a/apimanager/methodrouting/templates/methodrouting/index.html +++ b/apimanager/methodrouting/templates/methodrouting/index.html @@ -29,15 +29,18 @@
- {% for method_routing in method_routings %} -
-
+
+ {% csrf_token %} + {% for method_routing in method_routings %} +
+
+
-
- {{ method_routing.method_name }}
+
{{ method_routing.method_name }}
- @@ -45,28 +48,27 @@
- +
-
- +
- + +
{% endfor %} +
{% endblock %} \ No newline at end of file diff --git a/apimanager/methodrouting/urls.py b/apimanager/methodrouting/urls.py index 749a5d3..69816b3 100644 --- a/apimanager/methodrouting/urls.py +++ b/apimanager/methodrouting/urls.py @@ -5,7 +5,7 @@ URLs for config app from django.conf.urls import url -from .views import IndexView, methodrouting_save +from .views import IndexView, methodrouting_save, methodrouting_delete urlpatterns = [ url(r'^$', @@ -13,4 +13,6 @@ urlpatterns = [ name='methodrouting-index'), url(r'save/method', methodrouting_save, name='methodrouting-save'), + url(r'delete/method', methodrouting_delete, + name='methodrouting-delete'), ] diff --git a/apimanager/methodrouting/views.py b/apimanager/methodrouting/views.py index ec47e27..e1f2712 100644 --- a/apimanager/methodrouting/views.py +++ b/apimanager/methodrouting/views.py @@ -55,20 +55,46 @@ def methodrouting_save(request): bank_id_pattern = request.POST.get('bank_id_pattern') is_bank_id_exact_match = request.POST.get('is_bank_id_exact_match') parameters = request.POST.get('parameters') + method_routing_id = request.POST.get('method_routing_id') payload = { 'method_name' : method_name, 'connector_name': connector_name, 'is_bank_id_exact_match': bool(is_bank_id_exact_match), 'bank_id_pattern':bank_id_pattern, - 'parameters':eval(parameters) + 'parameters':eval(parameters), + 'method_routing_id':method_routing_id } + api = API(request.session.get('obp')) + try: + if(""==method_routing_id): # if method_routing_id=="". we will create a new method routing . + urlpath = '/management/method_routings' + result = api.post(urlpath, payload=payload) + else: # if method_routing_id not empty. we will update the current method routing .. + urlpath = '/management/method_routings/{}'.format(method_routing_id) + result = api.put(urlpath, payload=payload) + except APIError as err: + error_once_only(request, APIError(Exception("OBP-API server is not running or do not response properly. " + "Please check OBP-API server. Details: " + str(err)))) + except Exception as err: + error_once_only(request, "Unknown Error. Details: " + str(err)) + if 'code' in result and result['code'] >= 400: + error_once_only(request, result['message']) + msg = 'Submission successfully!' + messages.success(request, msg) + return JsonResponse({'state': True}) + + +@csrf_exempt +def methodrouting_delete(request): + method_routing_id = request.POST.get('method_routing_id') + api = API(request.session.get('obp')) try: - urlpath = '/management/method_routings' - result = api.post(urlpath, payload=payload) + urlpath = '/management/method_routings/{}'.format(method_routing_id) + result = api.delete(urlpath) except APIError as err: error_once_only(request, APIError(Exception("OBP-API server is not running or do not response properly. " "Please check OBP-API server. Details: " + str(err))))