diff --git a/http/SkySpotApplication.cs b/http/SkySpotApplication.cs index 6e09f34..220587d 100644 --- a/http/SkySpotApplication.cs +++ b/http/SkySpotApplication.cs @@ -30,7 +30,7 @@ namespace skyspot.http DirectoryResource templates = new DirectoryResource(TemplatePath); templates.ResourceTypeHook = ResourceTypeHook; - + templates.DefaultResource = templates.GetResource("index.html"); RootResource = templates; } diff --git a/skyspot.csproj b/skyspot.csproj index 10dd5a4..064be72 100644 --- a/skyspot.csproj +++ b/skyspot.csproj @@ -187,6 +187,12 @@ + + PreserveNewest + + + PreserveNewest + \ No newline at end of file diff --git a/www/frame.html b/www/frame.html index bc36fbc..8284f05 100644 --- a/www/frame.html +++ b/www/frame.html @@ -25,6 +25,8 @@ + + diff --git a/www/js/sky.controls.js b/www/js/sky.controls.js new file mode 100644 index 0000000..5cf4b7b --- /dev/null +++ b/www/js/sky.controls.js @@ -0,0 +1,50 @@ + +(function($){ + + $.extend($, { sky: {} } ); + $.extend($.sky, { controls: {} }); + + function IPPool_create(){ + + } + + + $.fn.IPPool = function( opts ){ + alert(this); + var select = this.find("select")[0]; + + if (!select) + throw "IPPool needs an ").IPPool().attr( "id", key ); + }; + + + + +}( jQuery )); + + diff --git a/www/js/sky.dhcp.js b/www/js/sky.dhcp.js index 6730c48..48fb198 100644 --- a/www/js/sky.dhcp.js +++ b/www/js/sky.dhcp.js @@ -47,7 +47,21 @@ function editIPPool(ippool, editable) } -function editDHCPServerInterface(intf, editable) +function editDHCPServerInterface(intf, editable){ + skyapi().getJson( "/DHCP/collections/DHCPServerInterface/" + intf, function(intf){ + $.skyForm( intf, { + title: "DHCP Server Interface", + fields: [ + { key: "Name", label: "Bezeichnung", }, + { key: "InterfaceAddress", label: "Interface IP", }, + { key: "IPPool", label: "IP Pool", type: "IPPool" }, + ] + + } ); + } ); +} + +function __editDHCPServerInterface(intf, editable) { var content = $(`
@@ -68,15 +82,6 @@ function editDHCPServerInterface(intf, editable) .appendTo( $("#Pool", content) ); } ); - skyapi().getJson( "/DHCP/collections/DHCPServerInterface/" + intf, function(intf){ - PopulateForm( intf, { - top: content, - properties: { - "Pool": { transform: function(d){ return d.Name; }, }, - } - } ); - content.dialog( "open" ); - } ); content.dialog({ modal: true, diff --git a/www/js/sky.form.js b/www/js/sky.form.js new file mode 100644 index 0000000..8ca5224 --- /dev/null +++ b/www/js/sky.form.js @@ -0,0 +1,105 @@ + +(function($){ + function log(o){ + console.log(o); + return o; + } + var defaultOptions = { + fields: [ // Object Fields to show in Dialog +/* { + key: "", // Key of the property + label: "", // Label Text + type: "text", // Editor to use + toEditor: function(v){ return v; } // converter function to convert field value to editor value + fromEditor: function(c){ return v; }// converter function to convert editor value to field value + }, + */ + ], + id: null, // Name of field to use as unique identifier for ajax requests to collection, + // alternatively: function(o){ return id; } Method to retrieve ID from object + readonly: false, // default readonly flag + ajax: { + url: null, // ajax collection URLSchnuff17 + + }, + }; + var defaultDialogOptions = { + modal: true, + closeOnEscape: true, + draggable: false, + title: "skyForm", + minWidth: 600, + autoOpen: false, + buttons: [ + { + text: "abbrechen", + click: function(){ $(this).dialog( "close" ); }, + }, + { + text: "OK", + click: function(){ $(this).dialog( "close" ); }, + }, + ] + }; + + function populateForm( o, options = {} ) + { + var opt = Object.assign( { + top: null, + transform: function(v){ return v; }, + properties: {}, + }, options ); + + for (const key in o) + { + var po = Object.assign( { + transform: opt.transform, + }, opt.properties[key]); + + var i = $("#" + key, opt.top); + if (i.length) + i.val( po.transform(o[key]) ); + } + } + + function createControl(type, key) + { + if ($.sky.controls[type]) + { + return $.sky.controls[type](type, key); + } + + switch (type) + { + default: + return $(``); + } + } + + $.skyForm = function(o, options = {} ){ + var opts = Object.assign(defaultOptions, options); + + + var fieldSet = $("
"); + var fields = (opts.fields.length) ? opts.fields : log(Object.keys(o)).map( function(k){ return { key: k, label: k }; } ); + + fields.forEach( function(field){ + fieldSet.append($(``)) + fieldSet.append( + createControl( field.type, field.key ).val( o[field.key] ) + ); + }); + + var dlgOptions = Object.assign( {}, defaultDialogOptions ); + dlgOptions.title = opts.title; + + fieldSet.dialog( dlgOptions ); + fieldSet.dialog( "open" ); + } + + + + +}( jQuery )); + +