1
0
mirror of https://github.com/dkmstr/openuds.git synced 2024-12-22 13:34:04 +03:00

* Fixed a bunch of javascript things

* Added "gui" method to api, so we can get a description of what fields are needed for an specific item.
Added REST capacity to process gui requests
Updated translations
This commit is contained in:
Adolfo Gómez 2013-11-20 03:16:56 +00:00
parent 805b225552
commit 2bf0c3e59a
29 changed files with 4866 additions and 1449 deletions

View File

@ -37,7 +37,7 @@ from django.views.decorators.csrf import csrf_exempt
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.utils.translation import ugettext as _, activate from django.utils.translation import ugettext as _, activate
from django.conf import settings from django.conf import settings
from handlers import Handler, HandlerError, AccessDenied from handlers import Handler, HandlerError, AccessDenied, NotFound
import time import time
import logging import logging
@ -150,6 +150,10 @@ class Dispatcher(View):
return response return response
except HandlerError as e: except HandlerError as e:
return http.HttpResponseBadRequest(unicode(e)) return http.HttpResponseBadRequest(unicode(e))
except AccessDenied as e:
return http.HttpResponseForbidden(unicode(e))
except NotFound as e:
return http.Http404(unicode(e))
except Exception as e: except Exception as e:
logger.exception('Error processing request') logger.exception('Error processing request')
return http.HttpResponseServerError(unicode(e)) return http.HttpResponseServerError(unicode(e))

View File

@ -46,6 +46,9 @@ AUTH_TOKEN_HEADER = 'HTTP_X_AUTH_TOKEN'
class HandlerError(Exception): class HandlerError(Exception):
pass pass
class NotFound(HandlerError):
pass
class AccessDenied(HandlerError): class AccessDenied(HandlerError):
pass pass

View File

@ -38,7 +38,7 @@ from uds.core import auths
from users import Users from users import Users
from uds.REST import Handler, HandlerError from uds.REST import Handler, NotFound
from uds.REST.mixins import ModelHandlerMixin, ModelTypeHandlerMixin, ModelTableHandlerMixin from uds.REST.mixins import ModelHandlerMixin, ModelTypeHandlerMixin, ModelTableHandlerMixin
import logging import logging
@ -66,6 +66,13 @@ class Types(ModelTypeHandlerMixin, Handler):
def enum_types(self): def enum_types(self):
return auths.factory().providers().values() return auths.factory().providers().values()
def getGui(self, type_):
try:
return auths.factory().lookup(type_).guiDescription()
except:
raise NotFound('type not found')
class TableInfo(ModelTableHandlerMixin, Handler): class TableInfo(ModelTableHandlerMixin, Handler):
path = 'authenticators' path = 'authenticators'
detail = { 'users': Users } detail = { 'users': Users }

View File

@ -32,6 +32,7 @@
''' '''
from __future__ import unicode_literals from __future__ import unicode_literals
from handlers import NotFound
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
import logging import logging
@ -85,7 +86,7 @@ class ModelHandlerMixin(object):
detail = detailCls(self, path, parent = item) detail = detailCls(self, path, parent = item)
return getattr(detail, self._operation)() return getattr(detail, self._operation)()
except: except:
return {'error': 'method not found' } raise NotFound('method not found')
def get(self): def get(self):
logger.debug('method GET for {0}, {1}'.format(self.__class__.__name__, self._args)) logger.debug('method GET for {0}, {1}'.format(self.__class__.__name__, self._args))
@ -97,10 +98,9 @@ class ModelHandlerMixin(object):
return self.processDetail() return self.processDetail()
try: try:
item = list(self.getItems(pk=self._args[0]))[0] return list(self.getItems(pk=self._args[0]))[0]
except: except:
return {'error': 'not found' } raise NotFound('item not found')
class ModelTypeHandlerMixin(object): class ModelTypeHandlerMixin(object):
''' '''
@ -122,14 +122,32 @@ class ModelTypeHandlerMixin(object):
def getTypes(self, *args, **kwargs): def getTypes(self, *args, **kwargs):
for type_ in self.enum_types(): for type_ in self.enum_types():
try:
yield self.type_as_dict(type_) yield self.type_as_dict(type_)
except:
logger.exception('Exception enumerating types')
def get(self): def get(self):
logger.debug(self._args)
nArgs = len(self._args)
if nArgs == 0:
return list(self.getTypes()) return list(self.getTypes())
found = None
for v in self.getTypes():
if v['type'] == self._args[0]:
found = v
break
if found is None:
raise NotFound('type not found')
logger.debug('Found type {0}'.format(v))
if nArgs == 1:
return found
if self._args[1] == 'gui':
gui = self.getGui(self._args[0])
logger.debug("GUI: {0}".format(gui))
return gui
class ModelTableHandlerMixin(object): class ModelTableHandlerMixin(object):
authenticated = True authenticated = True

View File

@ -32,7 +32,7 @@
''' '''
from __future__ import unicode_literals from __future__ import unicode_literals
from django.utils.translation import ugettext as _ from django.utils.translation import get_language, ugettext as _
import cPickle import cPickle
import logging import logging
@ -255,8 +255,8 @@ class gui(object):
alter original values. alter original values.
''' '''
data = self._data.copy() data = self._data.copy()
data['label'] = _(data['label']) data['label'] = data['label'] != '' and _(data['label']) or ''
data['tooltip'] = _(data['tooltip']) data['tooltip'] = data['tooltip'] != '' and _(data['tooltip']) or ''
return data return data
@property @property
@ -816,6 +816,7 @@ class UserInterface(object):
object: If not none, object that will get its "initGui" invoked object: If not none, object that will get its "initGui" invoked
This will only happen (not to be None) in Services. This will only happen (not to be None) in Services.
''' '''
logger.debug('Active languaje for gui translation: {0}'.format(get_language()))
if obj is not None: if obj is not None:
obj.initGui() # We give the "oportunity" to fill necesary gui data before providing it to client obj.initGui() # We give the "oportunity" to fill necesary gui data before providing it to client

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-11-17 04:21+0100\n" "POT-Creation-Date: 2013-11-20 04:05+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -18,14 +18,10 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: static/adm/js/gui-elements.js:7 #: static/adm/js/gui-elements.js:33
msgid "Service Providers" msgid "Service Providers"
msgstr "Service-Provider" msgstr "Service-Provider"
#: static/adm/js/gui-elements.js:81
msgid "Connectivity"
msgstr "Konnektivität"
#: static/adm/js/gui.js:18 #: static/adm/js/gui.js:18
msgid "_MENU_ records per page" msgid "_MENU_ records per page"
msgstr "_MENU_ Datensätze pro Seite" msgstr "_MENU_ Datensätze pro Seite"
@ -70,19 +66,19 @@ msgstr "Nächste"
msgid "Previous" msgid "Previous"
msgstr "Vorherige" msgstr "Vorherige"
#: static/adm/js/gui.js:80 #: static/adm/js/gui.js:75
msgid "Deployed services" msgid "Deployed services"
msgstr "Bereitgestellten Dienste" msgstr "Bereitgestellten Dienste"
#: static/adm/js/gui.js:349 #: static/adm/js/gui.js:360
msgid "Edit" msgid "Edit"
msgstr "Bearbeiten" msgstr "Bearbeiten"
#: static/adm/js/gui.js:358 #: static/adm/js/gui.js:369
msgid "Delete" msgid "Delete"
msgstr "Löschen" msgstr "Löschen"
#: static/adm/js/gui.js:367 #: static/adm/js/gui.js:378
msgid "Refresh" msgid "Refresh"
msgstr "Aktualisieren" msgstr "Aktualisieren"
@ -161,3 +157,7 @@ msgstr "November"
#: static/adm/js/strftime.js:35 #: static/adm/js/strftime.js:35
msgid "December" msgid "December"
msgstr "Dezember" msgstr "Dezember"
#: static/adm/js/tools.js:46
msgid "Just a moment..."
msgstr "Einen Moment..."

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-11-17 04:21+0100\n" "POT-Creation-Date: 2013-11-20 04:05+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -18,14 +18,10 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: static/adm/js/gui-elements.js:7 #: static/adm/js/gui-elements.js:33
msgid "Service Providers" msgid "Service Providers"
msgstr "Proveedores de servicios" msgstr "Proveedores de servicios"
#: static/adm/js/gui-elements.js:81
msgid "Connectivity"
msgstr "Conectividad"
#: static/adm/js/gui.js:18 #: static/adm/js/gui.js:18
msgid "_MENU_ records per page" msgid "_MENU_ records per page"
msgstr "Registros _MENU_ por página" msgstr "Registros _MENU_ por página"
@ -70,19 +66,19 @@ msgstr "Próxima"
msgid "Previous" msgid "Previous"
msgstr "Anterior" msgstr "Anterior"
#: static/adm/js/gui.js:80 #: static/adm/js/gui.js:75
msgid "Deployed services" msgid "Deployed services"
msgstr "Servicios desplegados" msgstr "Servicios desplegados"
#: static/adm/js/gui.js:349 #: static/adm/js/gui.js:360
msgid "Edit" msgid "Edit"
msgstr "Editar" msgstr "Editar"
#: static/adm/js/gui.js:358 #: static/adm/js/gui.js:369
msgid "Delete" msgid "Delete"
msgstr "Borrar" msgstr "Borrar"
#: static/adm/js/gui.js:367 #: static/adm/js/gui.js:378
msgid "Refresh" msgid "Refresh"
msgstr "Actualización" msgstr "Actualización"
@ -161,3 +157,7 @@ msgstr "Noviembre"
#: static/adm/js/strftime.js:35 #: static/adm/js/strftime.js:35
msgid "December" msgid "December"
msgstr "Diciembre" msgstr "Diciembre"
#: static/adm/js/tools.js:46
msgid "Just a moment..."
msgstr "Un momento..."

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-11-17 04:21+0100\n" "POT-Creation-Date: 2013-11-20 04:05+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -18,14 +18,10 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n"
#: static/adm/js/gui-elements.js:7 #: static/adm/js/gui-elements.js:33
msgid "Service Providers" msgid "Service Providers"
msgstr "Fournisseurs de services" msgstr "Fournisseurs de services"
#: static/adm/js/gui-elements.js:81
msgid "Connectivity"
msgstr "Connectivité"
#: static/adm/js/gui.js:18 #: static/adm/js/gui.js:18
msgid "_MENU_ records per page" msgid "_MENU_ records per page"
msgstr "Documents _MENU_ par page" msgstr "Documents _MENU_ par page"
@ -70,19 +66,19 @@ msgstr "Prochaine"
msgid "Previous" msgid "Previous"
msgstr "Précédent" msgstr "Précédent"
#: static/adm/js/gui.js:80 #: static/adm/js/gui.js:75
msgid "Deployed services" msgid "Deployed services"
msgstr "Services déployés" msgstr "Services déployés"
#: static/adm/js/gui.js:349 #: static/adm/js/gui.js:360
msgid "Edit" msgid "Edit"
msgstr "Edit" msgstr "Edit"
#: static/adm/js/gui.js:358 #: static/adm/js/gui.js:369
msgid "Delete" msgid "Delete"
msgstr "Supprimer" msgstr "Supprimer"
#: static/adm/js/gui.js:367 #: static/adm/js/gui.js:378
msgid "Refresh" msgid "Refresh"
msgstr "Actualisation" msgstr "Actualisation"
@ -161,3 +157,7 @@ msgstr "Novembre"
#: static/adm/js/strftime.js:35 #: static/adm/js/strftime.js:35
msgid "December" msgid "December"
msgstr "Décembre" msgstr "Décembre"
#: static/adm/js/tools.js:46
msgid "Just a moment..."
msgstr "Un instant..."

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-11-17 04:21+0100\n" "POT-Creation-Date: 2013-11-20 04:05+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -18,14 +18,10 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: static/adm/js/gui-elements.js:7 #: static/adm/js/gui-elements.js:33
msgid "Service Providers" msgid "Service Providers"
msgstr "Fornitori di servizi" msgstr "Fornitori di servizi"
#: static/adm/js/gui-elements.js:81
msgid "Connectivity"
msgstr "Connettività"
#: static/adm/js/gui.js:18 #: static/adm/js/gui.js:18
msgid "_MENU_ records per page" msgid "_MENU_ records per page"
msgstr "Record _MENU_ per pagina" msgstr "Record _MENU_ per pagina"
@ -70,19 +66,19 @@ msgstr "Prossimo"
msgid "Previous" msgid "Previous"
msgstr "Precedente" msgstr "Precedente"
#: static/adm/js/gui.js:80 #: static/adm/js/gui.js:75
msgid "Deployed services" msgid "Deployed services"
msgstr "Servizi distribuiti" msgstr "Servizi distribuiti"
#: static/adm/js/gui.js:349 #: static/adm/js/gui.js:360
msgid "Edit" msgid "Edit"
msgstr "Modifica" msgstr "Modifica"
#: static/adm/js/gui.js:358 #: static/adm/js/gui.js:369
msgid "Delete" msgid "Delete"
msgstr "Eliminare" msgstr "Eliminare"
#: static/adm/js/gui.js:367 #: static/adm/js/gui.js:378
msgid "Refresh" msgid "Refresh"
msgstr "Aggiornamento" msgstr "Aggiornamento"
@ -161,3 +157,7 @@ msgstr "Novembre"
#: static/adm/js/strftime.js:35 #: static/adm/js/strftime.js:35
msgid "December" msgid "December"
msgstr "Dicembre" msgstr "Dicembre"
#: static/adm/js/tools.js:46
msgid "Just a moment..."
msgstr "Solo un momento..."

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-11-17 04:21+0100\n" "POT-Creation-Date: 2013-11-20 04:05+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -18,14 +18,10 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: static/adm/js/gui-elements.js:7 #: static/adm/js/gui-elements.js:33
msgid "Service Providers" msgid "Service Providers"
msgstr "Prestadores de serviços" msgstr "Prestadores de serviços"
#: static/adm/js/gui-elements.js:81
msgid "Connectivity"
msgstr "Conectividade"
#: static/adm/js/gui.js:18 #: static/adm/js/gui.js:18
msgid "_MENU_ records per page" msgid "_MENU_ records per page"
msgstr "Registros _MENU_ por página" msgstr "Registros _MENU_ por página"
@ -70,19 +66,19 @@ msgstr "Próxima"
msgid "Previous" msgid "Previous"
msgstr "Anterior" msgstr "Anterior"
#: static/adm/js/gui.js:80 #: static/adm/js/gui.js:75
msgid "Deployed services" msgid "Deployed services"
msgstr "Serviços implantados" msgstr "Serviços implantados"
#: static/adm/js/gui.js:349 #: static/adm/js/gui.js:360
msgid "Edit" msgid "Edit"
msgstr "Editar" msgstr "Editar"
#: static/adm/js/gui.js:358 #: static/adm/js/gui.js:369
msgid "Delete" msgid "Delete"
msgstr "Excluir" msgstr "Excluir"
#: static/adm/js/gui.js:367 #: static/adm/js/gui.js:378
msgid "Refresh" msgid "Refresh"
msgstr "Atualização" msgstr "Atualização"
@ -161,3 +157,7 @@ msgstr "Novembro"
#: static/adm/js/strftime.js:35 #: static/adm/js/strftime.js:35
msgid "December" msgid "December"
msgstr "Dezembro de" msgstr "Dezembro de"
#: static/adm/js/tools.js:46
msgid "Just a moment..."
msgstr "Só um momento..."

View File

@ -1,5 +1,6 @@
/* jshint strict: true */
(function(api, $, undefined) { (function(api, $, undefined) {
"use strict";
// "public" methods // "public" methods
api.doLog = function(data) { api.doLog = function(data) {
if (api.debug) { if (api.debug) {
@ -17,8 +18,11 @@
return new Cache(cacheName); return new Cache(cacheName);
}; };
api.getJson = function(path, success_fnc) { api.getJson = function(path, options) {
url = api.url_for(path); options = options || {};
var success_fnc = options.success || function(){};
var url = api.url_for(path);
api.doLog('Ajax GET Json for "' + url + '"'); api.doLog('Ajax GET Json for "' + url + '"');
$.ajax({ $.ajax({
url : url, url : url,
@ -27,10 +31,7 @@
success : function(data) { success : function(data) {
api.doLog('Success on "' + url + '".'); api.doLog('Success on "' + url + '".');
api.doLog('Received ' + JSON.stringify(data)); api.doLog('Received ' + JSON.stringify(data));
if (success_fnc !== undefined) {
api.doLog('Executing success method');
success_fnc(data); success_fnc(data);
}
}, },
beforeSend : function(request) { beforeSend : function(request) {
request.setRequestHeader(api.auth_header, api.token); request.setRequestHeader(api.auth_header, api.token);
@ -39,12 +40,13 @@
}; };
// Public attributes // Public attributes
api.debug = false; api.debug = true;
}(window.api = window.api || {}, jQuery)); }(window.api = window.api || {}, jQuery));
// Cache related // Cache related
function Cache(cacheName) { function Cache(cacheName) {
"use strict";
api.cacheTable = api.cacheTable || {}; api.cacheTable = api.cacheTable || {};
api.cacheTable[cacheName] = api.cacheTable[cacheName] || {}; api.cacheTable[cacheName] = api.cacheTable[cacheName] || {};
@ -55,6 +57,7 @@ function Cache(cacheName) {
Cache.prototype = { Cache.prototype = {
get: function(key, not_found_fnc){ get: function(key, not_found_fnc){
"use strict";
not_found_fnc = not_found_fnc || function() { return undefined; }; not_found_fnc = not_found_fnc || function() { return undefined; };
if( this.cache[key] === undefined ) { if( this.cache[key] === undefined ) {
@ -64,6 +67,7 @@ Cache.prototype = {
}, },
put: function(key, value) { put: function(key, value) {
"use strict";
this.cache[key] = value; this.cache[key] = value;
}, },
}; };
@ -74,6 +78,7 @@ Cache.prototype = {
// code :-) // code :-)
function BasicModelRest(path, options) { function BasicModelRest(path, options) {
"use strict";
options = options || {}; options = options || {};
path = path || ''; path = path || '';
// Requests paths // Requests paths
@ -85,34 +90,70 @@ function BasicModelRest(path, options) {
} }
BasicModelRest.prototype = { BasicModelRest.prototype = {
// options:
// cacheKey: '.' --> do not cache
// undefined -- > use path as key
// success: success fnc to execute in case of success
_requestPath: function(path, options) {
"use strict";
options = options || {};
var success_fnc = options.success || function(){api.doLog('success not provided for '+path);};
var cacheKey = options.cacheKey || path;
if( path == '.' ) {
success_fnc({});
return;
}
if (cacheKey != '.' && this.cache.get(cacheKey)) {
success_fnc(this.cache.get(cacheKey));
} else {
var $this = this;
api.getJson(path, {
success: function(data) {
if( cacheKey != '.' ) {
$this.cache.put(cacheKey, data);
}
success_fnc(data);
},
});
}
},
get : function(options) { get : function(options) {
"use strict";
options = options || {}; options = options || {};
var path = this.getPath; var path = this.getPath;
if (options.id !== undefined) if (options.id !== undefined)
path += '/' + options.id; path += '/' + options.id;
api.getJson(path, options.success); return this._requestPath(path, {
}, cacheKey: '.', // Right now, do not cache this
types : function(success_fnc) { success: options.success,
// Cache types locally, will not change unless new broker version
sucess_fnc = success_fnc || function(data){}; });
if( this.typesPath == '.' ) { },
success_fnc({}); types : function(options) {
return; "use strict";
} options = options || {};
if (this.cache.get('types')) { return this._requestPath(this.typesPath, {
success_fnc(this.cache.get('types')); cacheKey: 'type',
} else { success: options.success,
var $this = this; });
var path = this.typesPath; },
api.getJson(path, function(data) { gui: function(typeName, options) {
$this.cache.put('types', data); "use strict";
success_fnc(data); options = options || {};
}); var path = [this.typesPath, typeName, 'gui'].join('/');
} return this._requestPath(path, {
}, cacheKey: typeName + '-gui',
success: options.success,
});
},
tableInfo : function(options) {
"use strict";
options = options || {};
var success_fnc = options.success || function(){api.doLog('success not provided for tableInfo');};
tableInfo : function(success_fnc) {
var path = this.tableInfoPath; var path = this.tableInfoPath;
// Cache types locally, will not change unless new broker version // Cache types locally, will not change unless new broker version
if( this.cache.get(path) ) { if( this.cache.get(path) ) {
@ -123,14 +164,17 @@ BasicModelRest.prototype = {
} }
var $this = this; var $this = this;
api.getJson(path, function(data) { api.getJson(path, {
success: function(data) {
$this.cache.put(path, data); $this.cache.put(path, data);
success_fnc(data); success_fnc(data);
},
}); });
}, },
detail: function(id, child) { detail: function(id, child) {
"use strict";
return new DetailModelRestApi(this, id, child); return new DetailModelRestApi(this, id, child);
} }
@ -138,6 +182,7 @@ BasicModelRest.prototype = {
// For REST of type /auth/[id]/users, /services/[id]/users, ... // For REST of type /auth/[id]/users, /services/[id]/users, ...
function DetailModelRestApi(parentApi, parentId, model) { function DetailModelRestApi(parentApi, parentId, model) {
"use strict";
this.base = new BasicModelRest(undefined, { this.base = new BasicModelRest(undefined, {
getPath: [parentApi.path, parentId, model].join('/'), getPath: [parentApi.path, parentId, model].join('/'),
typesPath: '.', // We do not has this on details typesPath: '.', // We do not has this on details
@ -148,13 +193,16 @@ function DetailModelRestApi(parentApi, parentId, model) {
DetailModelRestApi.prototype = { DetailModelRestApi.prototype = {
// Generates a basic model with fixed methods for "detail" models // Generates a basic model with fixed methods for "detail" models
get: function(options) { get: function(options) {
"use strict";
return this.base.get(options); return this.base.get(options);
}, },
types: function(success_fnc) { types: function(options) {
return this.base.types(success_fnc); "use strict";
return this.base.types(options);
}, },
tableInfo: function(success_fnc) { tableInfo: function(options) {
return this.base.tableInfo(success_fnc); "use strict";
return this.base.tableInfo(options);
}, },
}; };

View File

@ -1,31 +0,0 @@
(function(api, $, undefined) {
api.cache = function(cacheName) {
return new Cache(cacheName);
};
}(window.api = window.api || {}, jQuery));
function Cache(cacheName) {
api.cacheTable = api.cacheTable || {};
api.cacheTable[cacheName] = api.cacheTable[cacheName] || {};
this.name = cacheName;
this.cache = api.cacheTable[cacheName];
}
Cache.prototype = {
get: function(key, not_found_fnc){
not_found_fnc = not_found_fnc || function() { return undefined; };
if( this.cache[key] === undefined ) {
this.cache[key] = not_found_fnc();
}
return this.cache[key];
},
put: function(key, value) {
this.cache[key] = value;
},
};

View File

@ -136,7 +136,8 @@ GuiElement.prototype = {
"use strict"; "use strict";
gui.doLog('Initializing ' + this.name); gui.doLog('Initializing ' + this.name);
var $this = this; var $this = this;
this.rest.types(function(data) { this.rest.types({
success: function(data) {
var styles = ''; var styles = '';
$.each(data, function(index, value) { $.each(data, function(index, value) {
var className = $this.name + '-' + value.type; var className = $this.name + '-' + value.type;
@ -154,6 +155,7 @@ GuiElement.prototype = {
styles = '<style media="screen">' + styles + '</style>'; styles = '<style media="screen">' + styles + '</style>';
$(styles).appendTo('head'); $(styles).appendTo('head');
} }
},
}); });
}, },
table : function(options) { table : function(options) {
@ -211,7 +213,8 @@ GuiElement.prototype = {
}; };
}; };
this.rest.tableInfo(function(data) { this.rest.tableInfo({
success: function(data) {
var title = data.title; var title = data.title;
var columns = []; var columns = [];
$.each(data.fields, function(index, value) { $.each(data.fields, function(index, value) {
@ -417,35 +420,12 @@ GuiElement.prototype = {
// window.location.href = uri + base64(api.templates.evaluate(tmpl, ctx)); // window.location.href = uri + base64(api.templates.evaluate(tmpl, ctx));
setTimeout( function() { setTimeout( function() {
saveAs(new Blob([api.templates.evaluate(tmpl, ctx)], saveAs(new Blob([api.templates.evaluate(tmpl, ctx)],
{type: 'application/vnd.ms-excel'} ), title + '.xls') {type: 'application/vnd.ms-excel'} ), title + '.xls');
}, 20); }, 20);
}); });
}, },
"sButtonClass" : "btn3d-info btn3d btn3d-tables" "sButtonClass" : "btn3d-info btn3d btn3d-tables"
}; };
/*case 'csv':
btn = {
"sExtends" : "csv",
"sTitle" : title,
"sFileName" : title + '.csv',
};
break;*/
/*case 'pdf':
btn = {
"sExtends" : "pdf",
"sTitle" : title,
"sPdfMessage" : "Summary Info",
"fnCellRender": function(value, col, node, dattaIndex) {
// All tables handled by this needs an "id" on col 0
// So, we return empty values for col 0
if(col === 0)
return '';
return value.toString().replace(/(<([^>]+)>)/ig, '');
},
"sFileName" : title + '.pdf',
"sPdfOrientation" : "portrait"
};
break;*/
} }
if (btn !== undefined) if (btn !== undefined)
@ -492,6 +472,8 @@ GuiElement.prototype = {
} }
} }
}); });
},
}); });
return '#' + tableId; return '#' + tableId;
} }

View File

@ -43,7 +43,7 @@
}; };
tools.blockUI = function(message) { tools.blockUI = function(message) {
message = message || '<h1><span class="fa fa-spinner fa-spin"></span> ' + gettext('Just a moment...') + '</h1>' message = message || '<h1><span class="fa fa-spinner fa-spin"></span> ' + gettext('Just a moment...') + '</h1>';
$.blockUI({ message: message }); $.blockUI({ message: message });
}; };