* Fixed dropdown to include icons (for "new")

* Added Os managers (client & server)
This commit is contained in:
Adolfo Gómez 2013-12-10 23:21:29 +00:00
parent 49dc0eb0c2
commit 3c956e94df
10 changed files with 62 additions and 32 deletions

View File

@ -32,8 +32,10 @@
''' '''
from __future__ import unicode_literals from __future__ import unicode_literals
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext, ugettext_lazy as _
from uds.models import OSManager from uds.models import OSManager
from uds.REST import NotFound, RequestError
from uds.core.osmanagers import factory from uds.core.osmanagers import factory
from uds.REST.model import ModelHandler from uds.REST.model import ModelHandler
@ -46,6 +48,7 @@ logger = logging.getLogger(__name__)
class OsManagers(ModelHandler): class OsManagers(ModelHandler):
model = OSManager model = OSManager
save_fields = ['name', 'comments']
table_title = _('Current OS Managers') table_title = _('Current OS Managers')
table_fields = [ table_fields = [
@ -62,3 +65,23 @@ class OsManagers(ModelHandler):
'type': type_.type(), 'type': type_.type(),
'comments': osm.comments, 'comments': osm.comments,
} }
def checkDelete(self, item):
if item.deployedServices.count() > 0:
raise RequestError(ugettext('Can\'t delete an OSManager with deployed services associated'))
def checkSave(self, item):
if item.deployedServices.count() > 0:
raise RequestError(ugettext('Can\'t modify an OSManager with deployed services associated'))
# Types related
def enum_types(self):
return factory().providers().values()
# Gui related
def getGui(self, type_):
try:
return self.addDefaultFields(factory().lookup(type_).guiDescription(), ['name', 'comments'])
except:
raise NotFound('type not found')

View File

@ -34,7 +34,7 @@ from __future__ import unicode_literals
from django.utils.translation import ugettext, ugettext_lazy as _ from django.utils.translation import ugettext, ugettext_lazy as _
from uds.models import Provider from uds.models import Provider
from services import Services from services import Services as DetailServices
from uds.core import services from uds.core import services
from uds.REST import NotFound, RequestError from uds.REST import NotFound, RequestError
@ -47,7 +47,7 @@ logger = logging.getLogger(__name__)
class Providers(ModelHandler): class Providers(ModelHandler):
model = Provider model = Provider
detail = { 'services': Services } detail = { 'services': DetailServices }
save_fields = ['name', 'comments'] save_fields = ['name', 'comments']
table_title = _('Service providers') table_title = _('Service providers')

View File

@ -369,6 +369,11 @@ class ModelHandler(BaseModelHandler):
def checkDelete(self, item): def checkDelete(self, item):
pass pass
# Save related, checks if the item can be saved
# If it can't be saved, raises an exception
def checkSave(self, item):
pass
# End overridable # End overridable
# Helper to process detail # Helper to process detail
@ -491,6 +496,9 @@ class ModelHandler(BaseModelHandler):
except Exception: except Exception:
raise RequestError('incorrect invocation to PUT') raise RequestError('incorrect invocation to PUT')
if not deleteOnError:
self.checkSave(item) # Will raise an exception if item can't be saved (only for modify operations..)
# Store associated object if needed # Store associated object if needed
try: try:
if self._params.has_key('data_type'): # Needs to store instance if self._params.has_key('data_type'): # Needs to store instance

View File

@ -34,6 +34,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.db import models from django.db import models
from django.db import IntegrityError
from django.db.models import signals from django.db.models import signals
from uds.core.jobs.JobsFactory import JobsFactory from uds.core.jobs.JobsFactory import JobsFactory
from uds.core.Environment import Environment from uds.core.Environment import Environment
@ -364,6 +365,8 @@ class OSManager(models.Model):
:note: If destroy raises an exception, the deletion is not taken. :note: If destroy raises an exception, the deletion is not taken.
''' '''
toDelete = kwargs['instance'] toDelete = kwargs['instance']
if toDelete.deployedServices.count() > 0:
raise IntegrityError('Can\'t remove os managers with assigned deployed services')
# Only tries to get instance if data is not empty # Only tries to get instance if data is not empty
if toDelete.data != '': if toDelete.data != '':
s = toDelete.getInstance() s = toDelete.getInstance()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

@ -0,0 +1,23 @@
//------------------------
// Os managers
//------------------------
gui.osmanagers = new GuiElement(api.osmanagers, 'osm');
gui.osmanagers.link = function(event) {
"use strict";
// Cleans up memory used by other datatables
$.each($.fn.dataTable.fnTables(), function(undefined, tbl){
$(tbl).dataTable().fnDestroy();
});
gui.clearWorkspace();
gui.appendToWorkspace(gui.breadcrumbs('Os Managers'));
gui.osmanagers.table({
rowSelect : 'single',
buttons : [ 'new', 'edit', 'delete', 'xls' ],
onNew : gui.methods.typedNew(gui.osmanagers, gettext('New OSManager'), gettext('Error creating OSManager')),
onEdit: gui.methods.typedEdit(gui.osmanagers, gettext('Edit OSManager'), gettext('Error processing OSManager')),
onDelete: gui.methods.del(gui.osmanagers, gettext('Delete OSManager'), gettext('Error deleting OSManager')),
});
return false;
};

View File

@ -26,28 +26,6 @@ gui.dashboard.link = function(event) {
}; };
//------------------------
// Os managers
//------------------------
gui.osmanagers = new GuiElement(api.osmanagers, 'osm');
gui.osmanagers.link = function(event) {
"use strict";
// Cleans up memory used by other datatables
$.each($.fn.dataTable.fnTables(), function(undefined, tbl){
$(tbl).dataTable().fnDestroy();
});
gui.clearWorkspace();
gui.appendToWorkspace(gui.breadcrumbs('Os Managers'));
gui.osmanagers.table({
rowSelect : 'single',
buttons : [ 'edit', 'delete', 'xls' ],
});
return false;
};
gui.connectivity = { gui.connectivity = {
transports : new GuiElement(api.transports, 'trans'), transports : new GuiElement(api.transports, 'trans'),
networks : new GuiElement(api.networks, 'nets'), networks : new GuiElement(api.networks, 'nets'),

View File

@ -101,6 +101,7 @@
<script src="{% get_static_prefix %}adm/js/gui-definition.js"></script> <script src="{% get_static_prefix %}adm/js/gui-definition.js"></script>
<script src="{% get_static_prefix %}adm/js/gui-d-service-providers.js"></script> <script src="{% get_static_prefix %}adm/js/gui-d-service-providers.js"></script>
<script src="{% get_static_prefix %}adm/js/gui-d-authenticators.js"></script> <script src="{% get_static_prefix %}adm/js/gui-d-authenticators.js"></script>
<script src="{% get_static_prefix %}adm/js/gui-d-osmanagers.js"></script>
<script> <script>
$(function() { $(function() {

View File

@ -1,6 +0,0 @@
{% verbatim %}
<div class="alert alert-dismissable alert-{{ type }}">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
{{ message }}
</div>
{% endverbatim %}

View File

@ -7,7 +7,7 @@
</button> </button>
<ul class="dropdown-menu" role="menu" aria-labelledby=""> <ul class="dropdown-menu" role="menu" aria-labelledby="">
{{# each menu }} {{# each menu }}
<li role="presentation"><a role="menuitem" tabindex="-1" data-toggle="tooltip" title="{{ description }}" href="#" data-type="{{ type }}">{{ name }}</a></li> <li role="presentation"><a role="menuitem" tabindex="-1" data-toggle="tooltip" title="{{ description }}" href="#" data-type="{{ type }}"><span class="{{ css }}"></span> {{ name }}</a></li>
{{/ each }} {{/ each }}
</ul> </ul>
</div> </div>