forked from shaba/openuds
Basic transport new/edit done (easy this time, using all previous work... :-) )
This commit is contained in:
parent
453be53125
commit
895ef25b77
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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',
|
||||
|
@ -108,6 +108,8 @@
|
||||
<script src="{% get_static_prefix %}adm/js/gui-d-osmanagers.js"></script>
|
||||
<script src="{% get_static_prefix %}adm/js/gui-d-connectivity.js"></script>
|
||||
{% else %}
|
||||
<!-- minified js from: 'jquery.cookie', 'bootstrap.min', 'bootstrap-switch.min', 'bootstrap-select.min', 'jquery.validate.min', 'jquery.blockUI',
|
||||
'jquery.dataTables.min', 'TableTools.min', 'Blob', 'FileSaver', 'ZeroClipboard', 'dataTables.bootstrap', 'handlebars-v1.1.2', UDS admin JS's -->
|
||||
<script src="{% get_static_prefix %}adm/js/admin.min.js"></script>
|
||||
{% endif %}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user