My first widget control, please provide feedback
The following widget does the paging for the grid. This is my first attempt at writing widgets in ActiveWidgets (which I am very impressed with).
Active.Controls.Pager = Active.System.Control.subclass();
Active.Controls.Pager.create = function(){
var obj = this.prototype;
obj.setClass("box", "active");
obj.labelstr = "";
obj.grid = null;
obj.setGrid = function(g) {
obj.grid = g;
}
obj.getGrid = function() {
return obj.grid;
}
// ------------------------------------------------------------
var first = new Active.HTML.INPUT;
first.setAttribute("type", "button");
first.setAttribute("value"," << ");
var prev = new Active.HTML.INPUT;
prev.setAttribute("type", "button");
prev.setAttribute("value"," < ");
var label = new Active.HTML.SPAN;
label.setStyle("display","inline");
label.setStyle("font", "menu");
var next = new Active.HTML.INPUT;
next.setAttribute("type", "button");
next.setAttribute("value"," > ");
var last = new Active.HTML.INPUT;
last.setAttribute("type", "button");
last.setAttribute("value"," >> ");
obj.setContent("first", first);
obj.setContent("prev", prev);
obj.setContent("label", label);
obj.setContent("next", next);
obj.setContent("last", last);
label.setContent(function () {return this.labelstr;});
obj.gotoPage = function (delta) {
var count = this.grid.getProperty("row/pageCount");
var num = this.grid.getProperty("row/pageNumber");
num += delta;
if (num < 0) {num = 0}
if (num > count-1) {num = count-1}
this.labelstr = " Page " + (num+1) + " of " + count;
this.grid.setProperty("row/pageNumber",num);
this.grid.refresh();
this.refresh();
}
var goNext = function (event) {
this.gotoPage(1);
}
var goPrev = function (event) {
this.gotoPage(-1);
}
var goFirst = function (event) {
this.gotoPage(-Infinity);
}
var goLast = function (event) {
this.gotoPage(Infinity);
}
next.setEvent("onclick", goNext);
prev.setEvent("onclick", goPrev);
first.setEvent("onclick", goFirst);
last.setEvent("onclick", goLast);
}
Active.Controls.Pager.create();
Active.Controls.Pager = Active.System.Control.subclass();
Active.Controls.Pager.create = function(){
var obj = this.prototype;
obj.setClass("box", "active");
obj.labelstr = "";
obj.grid = null;
obj.setGrid = function(g) {
obj.grid = g;
}
obj.getGrid = function() {
return obj.grid;
}
// ------------------------------------------------------------
var first = new Active.HTML.INPUT;
first.setAttribute("type", "button");
first.setAttribute("value"," << ");
var prev = new Active.HTML.INPUT;
prev.setAttribute("type", "button");
prev.setAttribute("value"," < ");
var label = new Active.HTML.SPAN;
label.setStyle("display","inline");
label.setStyle("font", "menu");
var next = new Active.HTML.INPUT;
next.setAttribute("type", "button");
next.setAttribute("value"," > ");
var last = new Active.HTML.INPUT;
last.setAttribute("type", "button");
last.setAttribute("value"," >> ");
obj.setContent("first", first);
obj.setContent("prev", prev);
obj.setContent("label", label);
obj.setContent("next", next);
obj.setContent("last", last);
label.setContent(function () {return this.labelstr;});
obj.gotoPage = function (delta) {
var count = this.grid.getProperty("row/pageCount");
var num = this.grid.getProperty("row/pageNumber");
num += delta;
if (num < 0) {num = 0}
if (num > count-1) {num = count-1}
this.labelstr = " Page " + (num+1) + " of " + count;
this.grid.setProperty("row/pageNumber",num);
this.grid.refresh();
this.refresh();
}
var goNext = function (event) {
this.gotoPage(1);
}
var goPrev = function (event) {
this.gotoPage(-1);
}
var goFirst = function (event) {
this.gotoPage(-Infinity);
}
var goLast = function (event) {
this.gotoPage(Infinity);
}
next.setEvent("onclick", goNext);
prev.setEvent("onclick", goPrev);
first.setEvent("onclick", goFirst);
last.setEvent("onclick", goLast);
}
Active.Controls.Pager.create();
Krish
March 13,