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 __future__ import unicode_literals
|
||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _, ugettext
|
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.core.transports import factory
|
||||||
|
|
||||||
from uds.REST import Handler, NotFound
|
from uds.REST import Handler, NotFound
|
||||||
@ -62,17 +62,24 @@ class Transports(ModelHandler):
|
|||||||
|
|
||||||
def getGui(self, type_):
|
def getGui(self, type_):
|
||||||
try:
|
try:
|
||||||
return self.addField(self.addDefaultFields(factory().lookup(type_).guiDescription(), ['name', 'comments']), {
|
return self.addField(self.addField(self.addDefaultFields(factory().lookup(type_).guiDescription(), ['name', 'comments', 'priority']), {
|
||||||
'name': 'priority',
|
'name': 'nets_positive',
|
||||||
'required': True,
|
'value': True,
|
||||||
'value': '1',
|
'label': ugettext('Network access'),
|
||||||
'label': ugettext('Priority'),
|
'tooltip': ugettext('If ACTIVE, the transport will be enabled for the selected networks.If INACTIVE, trans port will be disabled for selected networks'),
|
||||||
'tooltip': ugettext('Priority of this transport'),
|
'type': 'checkbox',
|
||||||
'type': 'numeric',
|
'order': 100, # At end
|
||||||
'order': -50, # 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:
|
except:
|
||||||
raise NotFound('type not found')
|
self.invalidItemException()
|
||||||
|
|
||||||
def item_as_dict(self, item):
|
def item_as_dict(self, item):
|
||||||
type_ = item.getType()
|
type_ = item.getType()
|
||||||
@ -81,7 +88,16 @@ class Transports(ModelHandler):
|
|||||||
'comments': item.comments,
|
'comments': item.comments,
|
||||||
'priority': item.priority,
|
'priority': item.priority,
|
||||||
'nets_positive': item.nets_positive,
|
'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(),
|
'deployed_count': item.deployedServices.count(),
|
||||||
'type': type_.type(),
|
'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):
|
def checkSave(self, item):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# Invoked right after saved an item (no matter if new or edition)
|
||||||
|
def afterSave(self, item):
|
||||||
|
pass
|
||||||
|
|
||||||
# End overridable
|
# End overridable
|
||||||
|
|
||||||
# Helper to process detail
|
# Helper to process detail
|
||||||
@ -513,6 +517,8 @@ class ModelHandler(BaseModelHandler):
|
|||||||
if deleteOnError:
|
if deleteOnError:
|
||||||
item.delete()
|
item.delete()
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
self.afterSave(item)
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@
|
|||||||
success_fnc = success_fnc || function(){};
|
success_fnc = success_fnc || function(){};
|
||||||
api.doLog('Getting template ' + name);
|
api.doLog('Getting template ' + name);
|
||||||
if (name.indexOf('?') == -1) {
|
if (name.indexOf('?') == -1) {
|
||||||
if ($this.cache.get(name+'-------') ) {
|
if ($this.cache.get(name) ) {
|
||||||
success_fnc($this.cache.get(name));
|
success_fnc($this.cache.get(name));
|
||||||
return;
|
return;
|
||||||
// Let's check if a "preloaded template" exists
|
// Let's check if a "preloaded template" exists
|
||||||
|
@ -21,7 +21,9 @@ gui.connectivity.link = function(event) {
|
|||||||
rowSelect : 'single',
|
rowSelect : 'single',
|
||||||
container : 'transports-placeholder',
|
container : 'transports-placeholder',
|
||||||
buttons : [ 'new', 'edit', 'delete', 'xls' ],
|
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({
|
gui.connectivity.networks.table({
|
||||||
rowSelect : 'multi',
|
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-osmanagers.js"></script>
|
||||||
<script src="{% get_static_prefix %}adm/js/gui-d-connectivity.js"></script>
|
<script src="{% get_static_prefix %}adm/js/gui-d-connectivity.js"></script>
|
||||||
{% else %}
|
{% 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>
|
<script src="{% get_static_prefix %}adm/js/admin.min.js"></script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user