From 895ef25b77c7eede6ef8072b275cbd9d384f33d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez?= Date: Wed, 11 Dec 2013 22:59:26 +0000 Subject: [PATCH] Basic transport new/edit done (easy this time, using all previous work... :-) ) --- server/src/uds/REST/methods/transports.py | 40 +++++++++++++------ server/src/uds/REST/model.py | 6 +++ server/src/uds/static/adm/js/api-templates.js | 2 +- .../uds/static/adm/js/gui-d-connectivity.js | 4 +- server/src/uds/templates/uds/admin/index.html | 2 + 5 files changed, 40 insertions(+), 14 deletions(-) diff --git a/server/src/uds/REST/methods/transports.py b/server/src/uds/REST/methods/transports.py index e92153bf..e0d08243 100644 --- a/server/src/uds/REST/methods/transports.py +++ b/server/src/uds/REST/methods/transports.py @@ -33,7 +33,7 @@ from __future__ import unicode_literals from django.utils.translation import ugettext_lazy as _, ugettext -from uds.models import Transport +from uds.models import Transport, Network from uds.core.transports import factory from uds.REST import Handler, NotFound @@ -62,17 +62,24 @@ class Transports(ModelHandler): def getGui(self, type_): try: - return self.addField(self.addDefaultFields(factory().lookup(type_).guiDescription(), ['name', 'comments']), { - 'name': 'priority', - 'required': True, - 'value': '1', - 'label': ugettext('Priority'), - 'tooltip': ugettext('Priority of this transport'), - 'type': 'numeric', - 'order': -50, # At end - }) + return self.addField(self.addField(self.addDefaultFields(factory().lookup(type_).guiDescription(), ['name', 'comments', 'priority']), { + 'name': 'nets_positive', + 'value': True, + 'label': ugettext('Network access'), + 'tooltip': ugettext('If ACTIVE, the transport will be enabled for the selected networks.If INACTIVE, trans port will be disabled for selected networks'), + 'type': 'checkbox', + 'order': 100, # At end + }), { + 'name': 'networks', + 'value': [], + 'values': sorted([{'id': x.id, 'text': x.name} for x in Network.objects.all()], key=lambda x: x['text'].lower()), # TODO: We will fix this behavior after current admin client is fully removed + 'label': ugettext('Networks'), + 'tooltip': ugettext('Networks associated with this transport. If No network selected, will mean "all networks"'), + 'type': 'multichoice', + 'order': 101 + }) except: - raise NotFound('type not found') + self.invalidItemException() def item_as_dict(self, item): type_ = item.getType() @@ -81,7 +88,16 @@ class Transports(ModelHandler): 'comments': item.comments, 'priority': item.priority, 'nets_positive': item.nets_positive, - 'networks': [ n.id for n in item.networks.all() ], + 'networks': [ { 'id': n.id } for n in item.networks.all() ], 'deployed_count': item.deployedServices.count(), 'type': type_.type(), } + + def afterSave(self, item): + try: + networks = self._params['networks'] + except: # No networks passed in, this is ok + return + + logger.debug('Params: {0}'.format(networks)) + item.networks = Network.objects.filter(id__in=networks) diff --git a/server/src/uds/REST/model.py b/server/src/uds/REST/model.py index 590e5b4f..cf6c7b6c 100644 --- a/server/src/uds/REST/model.py +++ b/server/src/uds/REST/model.py @@ -374,6 +374,10 @@ class ModelHandler(BaseModelHandler): def checkSave(self, item): pass + # Invoked right after saved an item (no matter if new or edition) + def afterSave(self, item): + pass + # End overridable # Helper to process detail @@ -513,6 +517,8 @@ class ModelHandler(BaseModelHandler): if deleteOnError: item.delete() raise + + self.afterSave(item) return res diff --git a/server/src/uds/static/adm/js/api-templates.js b/server/src/uds/static/adm/js/api-templates.js index 3ffea050..61ecfdd3 100644 --- a/server/src/uds/static/adm/js/api-templates.js +++ b/server/src/uds/static/adm/js/api-templates.js @@ -73,7 +73,7 @@ success_fnc = success_fnc || function(){}; api.doLog('Getting template ' + name); if (name.indexOf('?') == -1) { - if ($this.cache.get(name+'-------') ) { + if ($this.cache.get(name) ) { success_fnc($this.cache.get(name)); return; // Let's check if a "preloaded template" exists diff --git a/server/src/uds/static/adm/js/gui-d-connectivity.js b/server/src/uds/static/adm/js/gui-d-connectivity.js index 160862b4..2c24121a 100644 --- a/server/src/uds/static/adm/js/gui-d-connectivity.js +++ b/server/src/uds/static/adm/js/gui-d-connectivity.js @@ -21,7 +21,9 @@ gui.connectivity.link = function(event) { rowSelect : 'single', container : 'transports-placeholder', buttons : [ 'new', 'edit', 'delete', 'xls' ], - + onNew : gui.methods.typedNew(gui.connectivity.transports, gettext('New transport'), gettext('Error creating transport')), + onEdit: gui.methods.typedEdit(gui.connectivity.transports, gettext('Edit transport'), gettext('Error processing transport')), + onDelete: gui.methods.del(gui.connectivity.transports, gettext('Delete transport'), gettext('Error deleting transport')), }); gui.connectivity.networks.table({ rowSelect : 'multi', diff --git a/server/src/uds/templates/uds/admin/index.html b/server/src/uds/templates/uds/admin/index.html index 955a26e5..9e15160f 100644 --- a/server/src/uds/templates/uds/admin/index.html +++ b/server/src/uds/templates/uds/admin/index.html @@ -108,6 +108,8 @@ {% else %} + {% endif %}