diff --git a/server/src/uds/static/adm/js/templates.js b/server/src/uds/static/adm/js/api-templates.js similarity index 60% rename from server/src/uds/static/adm/js/templates.js rename to server/src/uds/static/adm/js/api-templates.js index 7b445e797..8cada6096 100644 --- a/server/src/uds/static/adm/js/templates.js +++ b/server/src/uds/static/adm/js/api-templates.js @@ -3,33 +3,37 @@ // Inserted into api // for the admin app // ------------------------------- -(function(templates, $) { - templates.cache = {}; // Will cache templates locally. If name contains +(function(api, $) { + api.templates = {}; + + api.templates.cache = new api.cache('tmpls'); // Will cache templates locally. If name contains // '?', data will not be cached and always // re-requested. We do not care about lang, because page will reload on language change - templates.get = function(name, success_fnc) { + api.templates.get = function(name, success_fnc) { var $this = this; + success_fnc = success_fnc || function(){}; api.doLog('Getting tempkate ' + name); if (name.indexOf('?') == -1) { - if ($this.cache[name] !== undefined) { - if (success_fnc !== undefined) { - success_fnc($this.cache[name]); - } + if ($this.cache.get(name) ) { + success_fnc($this.cache.get(name)); + return; + // Let's check if a "preloaded template" exists + } else if( document.getElementById('tmpl_' + name) ) { + success_fnc('tmpl_' + name); return; } } $.ajax({ - url : '/adm/tmpl/' + name, + url : api.template_url + name, type : "GET", dataType : "text", success : function(data) { - $this.cache[name] = data; + var cachedId = name; + $this.cache.put('_' + cachedId, $this.evaluate(data)); + $this.cache.put(name, cachedId); api.doLog('Success getting template "' + name + '".'); api.doLog('Received: ' + data); - if (success_fnc !== undefined) { - api.doLog('Executing success method'); - success_fnc(data); - } + success_fnc(cachedId); }, fail: function( jqXHR, textStatus, errorThrown ) { api.doLog(jqXHR); @@ -41,10 +45,20 @@ // Simple JavaScript Templating // Based on John Resig - http://ejohn.org/ - MIT Licensed - templates.evaluate = function tmpl(str, data) { + api.templates.evaluate = function (str, data) { // Figure out if we're getting a template, or if we need to // load the template - and be sure to cache the result. - var fn = + var cached; + if( !/\W/.test(str) ) { + cached = this.cache.get('_'+str); + if( cached === undefined ) { + cached = api.templates.evaluate(document.getElementById(str).innerHTML); + this.cache.put('_'+str, cached); + } + + } + // If cached, get cached first + var fn = cached || // Generate a reusable function that will serve as a template // generator (and which will be cached). new Function("obj", "var p=[],print=function(){p.push.apply(p,arguments);};" + @@ -60,4 +74,4 @@ // Provide some basic currying to the user return data ? fn(data) : fn; }; -}(api.templates = api.templates || {}, jQuery)); +}(window.api = window.api || {}, jQuery)); diff --git a/server/src/uds/static/adm/js/gui-elements.js b/server/src/uds/static/adm/js/gui-elements.js index 36dba8448..1dc8b1a08 100644 --- a/server/src/uds/static/adm/js/gui-elements.js +++ b/server/src/uds/static/adm/js/gui-elements.js @@ -34,10 +34,12 @@ gui.providers.link = function(event) { var tableId = gui.providers.table({ rowSelect : 'multi', - rowSelectFnc : function(data) { - gui.doLog(data); - gui.doLog(this); - gui.doLog(this.fnGetSelectedData()); + onEdit: function(value, event, table) { + gui.providers.rest.gui(value.type, { + success: function(data){ + gui.fields(data); + }, + }); }, buttons : [ 'edit', 'delete', 'xls' ], }); diff --git a/server/src/uds/static/adm/js/gui-fields.js b/server/src/uds/static/adm/js/gui-fields.js index e897dac2d..66c91ee88 100644 --- a/server/src/uds/static/adm/js/gui-fields.js +++ b/server/src/uds/static/adm/js/gui-fields.js @@ -1,42 +1,44 @@ /* jshint strict: true */ (function(gui, $, undefined) { "use strict"; - + // Returns a form that will manage a gui description (new or edit) gui.fields = function(item_description) { $.each(item_description, function(index, field){ gui.doLog(field); }); }; + + gui.fields.config = { + text: { + css: 'form-control' + + }, + textbox: { + css: 'form-control' + }, + numeric: { + css: 'form-control' + }, + password: { + css: 'form-control' + }, + hidden: { + css: '' + }, + choice: { + css: '' + }, + multichoice: { + css: '' + }, + editlist: { + css: '' + }, + checkbox: { + css: 'form-control' + }, + }; }(window.gui = window.gui || {}, jQuery)); -gui.fields.options = { - text: { - css: 'form-control' - }, - textbox: { - - }, - numeric: { - css: 'form-control' - }, - password: { - css: 'form-control' - }, - hidden: { - css: '' - }, - choice: { - css: '' - }, - multichoice: { - css: '' - }, - editlist: { - css: '' - }, - checkbox: { - css: 'form-control' - }, -}; \ No newline at end of file diff --git a/server/src/uds/static/adm/js/gui.js b/server/src/uds/static/adm/js/gui.js index 5ff77a769..19cad9e68 100644 --- a/server/src/uds/static/adm/js/gui.js +++ b/server/src/uds/static/adm/js/gui.js @@ -9,7 +9,6 @@ } catch (e) { // nothing can be logged } - } }; @@ -59,20 +58,16 @@ gui.table = function(title, table_id, options) { options = options || {}; var size = options.size || 12; - var icon = options.icon || 'table'; var panelId = 'panel-' + table_id; return { - text: '