sky.js/sky.controls.js

166 lines
2.7 KiB
JavaScript

(function(SKY){
class SKYControl extends SKY.prototypes.SKYBase {
constructor(typeName){
super();
this.typeName = typeName;
}
getIdentity(o){
return null;
}
render(o){
return o.toString();
}
editor(){
return null;
}
createSelector(){
return this.createEditor();
}
}
SKY.prototypes.SKYControl = SKYControl;
}(SKY));
(function(SKY){
class StringEditor extends SKY.prototypes.SKYEditor{
constructor(){
this.html(
$("<input>")
.attr("type","text")
.data("sky-editor", this)
.addClass("skyeditor skyeditor-string")
.on("change", function(e){
$(this).data("sky-editor").changed(true);
})
);
}
value(val){
if (arguments.length)
{
this.html().val( val );
this.changed(false);
return this;
}
return this.html().val();
}
}
class StringType extends SKY.prototypes.SKYControl {
constructor(){
super("string")
}
createEditor(){
return new StringEditor();
}
}
new StringType();
}(SKY));
(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 ));