This commit is contained in:
Adolfo Gómez 2013-12-02 15:17:01 +00:00
parent 888f125dc6
commit 3ec517c90f
5 changed files with 67 additions and 17 deletions

View File

@ -61,7 +61,7 @@ class Services(DetailHandler):
} for k in parent.services.all() ]
else:
k = parent.services.get(pk=item)
return {
val = {
'id':k.id,
'name': k.name,
'comments': k.comments,
@ -69,7 +69,9 @@ class Services(DetailHandler):
'typeName' : _(k.getType().name()),
'deployed_services_count' : k.deployedServices.count(),
}
return self.fillIntanceFields(k, val)
except:
logger.exception('getItems')
return { 'error': 'not found' }
def saveItem(self, parent, item):

View File

@ -121,6 +121,15 @@ class BaseModelHandler(Handler):
raise RequestError('needed parameter not found in data {0}'.format(unicode(e)))
return args
def fillIntanceFields(self, item, res):
if hasattr(item, 'getInstance'):
for key, value in item.getInstance().valuesDict().iteritems():
if type(value) in (unicode, str):
value = {"true":True, "false":False}.get(value, value) # Translate "true" & "false" to True & False (booleans)
logger.debug('{0} = {1}'.format(key, value))
res[key] = value
return res
# Exceptions
def invalidRequestException(self):
@ -164,20 +173,22 @@ class DetailHandler(BaseModelHandler):
if nArgs == 1:
if self._args[0] == OVERVIEW:
return self.getItems(parent, None)
elif self._args[0] == 'gui':
return self.getGui(parent, None)
elif self._args[0] == 'types':
elif self._args[0] == GUI:
gui = self.getGui(parent, None)
return sorted(gui, key=lambda f: f['gui']['order'])
elif self._args[0] == TYPES:
return self.getTypes(parent, None)
elif self._args[0] == 'tableinfo':
elif self._args[0] == TABLEINFO:
return self.processTableFields(self.getTitle(parent), self.getFields(parent))
# try to get id
return self.getItems(parent, self._args[0])
if nArgs == 2:
if self._args[0] == 'gui':
return self.getGui(parent, self._args[1])
elif self._args[0] == 'types':
if self._args[0] == GUI:
gui = self.getGui(parent, self._args[1])
return sorted(gui, key=lambda f: f['gui']['order'])
elif self._args[0] == TYPES:
return self.getTypes(parent, self._args[1])
return self.fallbackGet()
@ -330,13 +341,6 @@ class ModelHandler(BaseModelHandler):
except:
logger.exception('Exception getting item from {0}'.format(self.model))
def fillIntanceFields(self, item, res):
if hasattr(item, 'getInstance'):
for key, value in item.getInstance().valuesDict().iteritems():
value = {"true":True, "false":False}.get(value, value)
logger.debug('{0} = {1}'.format(key, value))
res[key] = value
def get(self):
logger.debug('method GET for {0}, {1}'.format(self.__class__.__name__, self._args))
nArgs = len(self._args)

View File

@ -54,6 +54,10 @@ table.dataTable tr.even td.sorting_3 { background-color: blue; }*/
cursor: pointer;
}
.cursor-pointer {
cursor: pointer !important;
}
#minimized {
margin-top: 0.6em;
margin-bottom: 0.3em;

View File

@ -35,6 +35,22 @@
options.data['_counter_'+id] += 1;
});
// For inserting "inline" javascript scripts, due to the fact that we cannot
// Insert "<script>...</script>" inside inline elements (they are already scripts)
Handlebars.registerHelper('javascript', function(options) {
return new Handlebars.SafeString('<script>' + options.fn(this) + '</script>');
});
// Truncate chars, like django "truncatechars" filter
Handlebars.registerHelper('truncatechars', function(len, value) {
var val = value.toString(); // For Array objects, the toString method joins the array and returns one string containing each array element separated by commas
if(val.length > len) {
return val.substring(0, len-3) + "...";
} else {
return val;
}
});
api.templates = {};
// Now initialize templates api
api.templates.cache = new api.cache('tmpls'); // Will cache templates locally. If name contains

View File

@ -1,5 +1,29 @@
{% extends "uds/admin/tmpl/fld/form-group.html" %}
{% load i18n %}
{% block field %}
{% verbatim %}<input type="text" id="{{ name }}_field" class="form-control cursor-pointer" value="{{ truncatechars 64 value }}" readonly>{% endverbatim %}
{% verbatim %}
{% endverbatim %}
<input type="hidden" class="{{ css }}" name="{{ name }}" value="{{ value }}">
{% endverbatim %}{% comment %}<script>/*This is a little trick to make IDE recognize sintax hightlight, will not be show on render :-)*/{% endcomment %}
{% verbatim %}{{# javascript }}{% endverbatim %}
(function(){
"use strict";
{% verbatim %}var id = '#{{ name }}_field';{% endverbatim %}
$(id).tooltip({
placement: 'bottom',
title: "{% trans 'Click to edit list' %}",
delay: { show: 500, hide: 100 },
});
$(id).click(function(){
var modalId = gui.launchModal(gettext('Edit list'), '');
$(modalId + ' .button-accept').click(function(){
alert('Save');
$(modalId).modal('hide');
})
});
}());
{% verbatim %}{{/ javascript }}{% endverbatim %}
{% comment %}</script>{% endcomment %}
{% endblock %}