98 lines
1.7 KiB
JavaScript
98 lines
1.7 KiB
JavaScript
|
|
(function($){
|
|
|
|
$.extend($, { sky: {} } );
|
|
$.extend($.sky, { controls: {} });
|
|
|
|
$.widget( "sky.IPPool", {
|
|
options: {
|
|
url: "/DHCP/collections/IPPool",
|
|
},
|
|
|
|
_create: function(){
|
|
this.refresh();
|
|
},
|
|
|
|
refresh: function(){
|
|
var element = this.element;
|
|
|
|
$.ajax( this.options.url, {
|
|
error: function(x,status,error){
|
|
alert(`sky.IPPool: Error fetching list of IPPools from Server ${status} ${error}`);
|
|
},
|
|
success: function(data,status,x){
|
|
data.forEach( function(e){
|
|
$("<option></option>")
|
|
.attr("value", e.Name)
|
|
.text( e.Name )
|
|
.appendTo( element );
|
|
} );
|
|
},
|
|
});
|
|
},
|
|
|
|
_destroy: function(){
|
|
|
|
},
|
|
|
|
});
|
|
$.widget( "sky.IPv4", {
|
|
options: {
|
|
mask: '099.099.099.099',
|
|
placeholder: '000.000.000.000',
|
|
},
|
|
|
|
_create: function(){
|
|
this.element.mask( this.options.mask, {
|
|
placeholder: this.options.placeholder,
|
|
} );
|
|
},
|
|
|
|
value: function(v){
|
|
if (arguments.length == 0){
|
|
return this.element.val();
|
|
}
|
|
this.element.val(v);
|
|
},
|
|
|
|
_destroy: function(){
|
|
},
|
|
|
|
});
|
|
|
|
|
|
$.fn.___IPPool = function( opts ){
|
|
var select = this.filter("select")[0];
|
|
|
|
if (!select)
|
|
throw "IPPool needs an <select> element to be instantiated on";
|
|
|
|
return $(select);
|
|
}
|
|
|
|
|
|
me = function(opts){
|
|
return this.filter("select").map( function(){
|
|
var ctrl = this;
|
|
var pools = skyapi().getJson("/DHCP/collections/IPPool");
|
|
|
|
ctrl.val = function(v){ alert(v); }
|
|
|
|
return ctrl;
|
|
});
|
|
}
|
|
|
|
$.sky.controls.IPPool = function(type,key){
|
|
return $("<select></select>").attr( "id", key ).IPPool();
|
|
};
|
|
$.sky.controls.IPv4 = function(type,key){
|
|
return $("<input></input>").attr( "id", key ).IPv4();
|
|
};
|
|
|
|
|
|
|
|
|
|
}( jQuery ));
|
|
|
|
|