Skip to content

Commit

Permalink
widgetified the grid initialise select
Browse files Browse the repository at this point in the history
  • Loading branch information
open768 committed Dec 8, 2022
1 parent eb7f4c6 commit c01aec6
Show file tree
Hide file tree
Showing 4 changed files with 240 additions and 91 deletions.
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
<script src="js/widgets/components/cajson.js"></script>
<script src="js/widgets/components/caremotecontrol.js"></script>
<script src="js/widgets/components/cachart.js"></script>
<script src="js/widgets/components/castatus.js"></script>
<script src="js/widgets/components/cagridinit.js"></script>
<script src="js/widgets/index/camachine.js"></script>
<script src="js/widgets/index/cacontrolsl.js"></script>
<script src="js/widgets/index/cacontrolsr.js"></script>
Expand Down
100 changes: 100 additions & 0 deletions js/widgets/components/cagridinit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
"use strict";
/**************************************************************************
Copyright (C) Chicken Katsu 2013-2022
This code is protected by copyright under the terms of the
Creative Commons Attribution 4.0 International License
https://creativecommons.org/licenses/by/4.0/legalcode
For licenses that allow for commercial use please contact [email protected]
// USE AT YOUR OWN RISK - NO GUARANTEES OR ANY FORM ARE EITHER EXPRESSED OR IMPLIED
**************************************************************************/


//###################################################################
//#
//###################################################################
class cCAGridInit{
element = null;
grid_name = null;

//***************************************************************
constructor(poOptions, poElement){
this.element = poElement;
this.grid_name = poOptions.grid_name;

var oThis = this;
var oElement = this.element;

//set basic stuff
oElement.uniqueId();
oElement.addClass("ui-widget");

//check dependencies
if (!bean ) $.error("bean is missing , chack includes");

//put something in the widget
oElement.empty();
this.pr__init();

}

//***************************************************************
//* Events
//***************************************************************
onInitClick(poEvent){
var oElement = this.element;

var iSelected = parseInt($(poEvent.target).val());

//---------tell subscribers to init
var oEvent = new cCAEvent( cCAEvent.types.action, cCAActionEvent.actions.grid_init, iSelected);
oEvent.trigger(document);
}



//***************************************************************
//* Privates
//***************************************************************
pr__init(){
var oElement = this.element;
var oThis = this;

var oDiv = $("<DIV>",{class:"ui-widget-header"});
oDiv.append("initialise");
oElement.append(oDiv);

oDiv = $("<DIV>",{class:"ui-widget-content"});
var oSelect = $("<SELECT>",{width:200,title:"choose a pattern to initialise the grid with"});
oSelect.append( $("<option>",{selected:1,disabled:1,value:-1}).append("Initialise"));
for (var sName in cCAGridTypes.init){
var oItem = cCAGridTypes.init[sName];
var oOption = $("<option>",{value:oItem.id}).append(oItem.label);
oSelect.append ( oOption);
}
oDiv.append(oSelect);
oSelect.selectmenu({
select:function(poEvent){oThis.onInitClick(poEvent)}
});
oElement.append(oDiv);
}

}

//###################################################################
//#
//###################################################################
$.widget(
"ck.cagridinit",
{
options:{
grid_name:null
},
_create: function(){
//checks
var oOptions = this.options;
if (!oOptions.grid_name) $.error("grid name not provided");

var oControls = new cCAGridInit(oOptions ,this.element);
}
}
);
130 changes: 130 additions & 0 deletions js/widgets/components/castatus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
"use strict";
/**************************************************************************
Copyright (C) Chicken Katsu 2013-2022
This code is protected by copyright under the terms of the
Creative Commons Attribution 4.0 International License
https://creativecommons.org/licenses/by/4.0/legalcode
For licenses that allow for commercial use please contact [email protected]
// USE AT YOUR OWN RISK - NO GUARANTEES OR ANY FORM ARE EITHER EXPRESSED OR IMPLIED
**************************************************************************/

class cCAStatusTypes {
static ACTIVE_ID ="A";
static CHANGED_ID ="C";
static RUNS_ID ="R";
}

//###################################################################
//#
//###################################################################
class cCAStatus{
element = null;
grid_name = null;

//***************************************************************
constructor(poOptions, poElement){
this.element = poElement;
this.grid_name = poOptions.grid_name;

var oThis = this;
var oElement = this.element;

//set basic stuff
oElement.uniqueId();
oElement.addClass("ui-widget");

//check dependencies
if (!bean ) $.error("bean is missing , chack includes");

//subscribe to CAEvents
bean.on (document, cCAEvent.hook, function(poEvent){ oThis.onCAEvent(poEvent)} );

//put something in the widget
oElement.empty();
this.pr__init();

}

//****************************************************************************
onCAEvent(poEvent){
var oElement;
var oTarget;

oElement = this.element;

if (poEvent.type === cCAEvent.types.canvas)
if (poEvent.data.grid_name === this.grid_name)
switch(poEvent.action){
case cCACanvasEvent.actions.grid_status:
if (!poEvent.data) return;

oTarget = $("#"+cJquery.child_ID(oElement, cCAStatusTypes.ACTIVE_ID));
oTarget.html(poEvent.data.data.active);
oTarget = $("#"+cJquery.child_ID(oElement, cCAStatusTypes.CHANGED_ID));
oTarget.html(poEvent.data.data.changed);
oTarget = $("#"+cJquery.child_ID(oElement, cCAStatusTypes.RUNS_ID));
oTarget.html(poEvent.data.data.runs);
break;
}
}

//***************************************************************
//* Privates
//***************************************************************
pr__init(){
var oDiv, oTable, oRow, oCell;
var oElement;

oElement = this.element;

//--input-------------------------------------------------
oDiv = $("<DIV>",{class:"ui-widget-header"}).append("Status");
oElement.append(oDiv);

oDiv = $("<DIV>",{class:"ui-widget-content"});
oTable = $("<Table>",{cellpadding:2});
oRow = $("<tr>");
oCell = $("<td>", {align:"right"}).append("Active");
oRow.append(oCell);
oCell = $("<td>",{id:cJquery.child_ID(oElement, cCAStatusTypes.ACTIVE_ID)});
oCell.append("??");
oRow.append(oCell);
oTable.append(oRow);
oRow = $("<tr>");
oCell = $("<td>", {align:"right"}).append("Changed");
oRow.append(oCell);
oCell = $("<td>",{id:cJquery.child_ID(oElement, cCAStatusTypes.CHANGED_ID)});
oCell.append("??");
oRow.append(oCell);
oTable.append(oRow);
oRow = $("<tr>");
oCell = $("<td>", {align:"right"}).append("Runs");
oRow.append(oCell);
oCell = $("<td>",{id:cJquery.child_ID(oElement, cCAStatusTypes.RUNS_ID)});
oCell.append("??");
oRow.append(oCell);
oTable.append(oRow);
oDiv.append(oTable);
oElement.append(oDiv);
}

}

//###################################################################
//#
//###################################################################
$.widget(
"ck.castatus",
{
options:{
grid_name:null
},
_create: function(){
//checks
var oOptions = this.options;
if (!oOptions.grid_name) $.error("grid name not provided");

var oControls = new cCAStatus(oOptions ,this.element);
}
}
);
99 changes: 8 additions & 91 deletions js/widgets/index/cacontrolsr.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ For licenses that allow for commercial use please contact [email protected].
// USE AT YOUR OWN RISK - NO GUARANTEES OR ANY FORM ARE EITHER EXPRESSED OR IMPLIED
**************************************************************************/

class cCAControlRTypes {
static ACTIVE_ID ="A";
static CHANGED_ID ="C";
static RUNS_ID ="R";
static CHART_ID="CHI";
}

//###################################################################
//#
Expand All @@ -34,59 +28,22 @@ class cCAControlsR{
//set basic stuff
oElement.uniqueId();
oElement.addClass("ui-widget");
$(oElement).tooltip();

//check dependencies
if (!bean ) $.error("bean is missing , chack includes");
if (!oElement.cagridinit) $.error("cainit is missing , chack includes");
if (!oElement.castatus) $.error("castatus is missing , chack includes");
if (!oElement.cachart) $.error("caChart is missing , chack includes");
if (!oElement.caremotecontrols) $.error("caremotecontrols is missing , chack includes");

//subscribe to CAEvents
bean.on (document, cCAEvent.hook, function(poEvent){ oThis.onCAEvent(poEvent)} );

//put something in the widget
oElement.empty();
this.pr__init();

}

//***************************************************************
//* Events
//***************************************************************
onInitClick(poEvent){
var oElement = this.element;

var iSelected = parseInt($(poEvent.target).val());

//---------tell subscribers to init
var oEvent = new cCAEvent( cCAEvent.types.action, cCAActionEvent.actions.grid_init, iSelected);
oEvent.trigger(document);
}


//****************************************************************************
onCAEvent(poEvent){
var oElement;
var oTarget;

oElement = this.element;

if (poEvent.type === cCAEvent.types.canvas)
if (poEvent.data.grid_name === this.grid_name)
switch(poEvent.action){
case cCACanvasEvent.actions.grid_status:
if (!poEvent.data) return;

oTarget = $("#"+cJquery.child_ID(oElement, cCAControlRTypes.ACTIVE_ID));
oTarget.html(poEvent.data.data.active);
oTarget = $("#"+cJquery.child_ID(oElement, cCAControlRTypes.CHANGED_ID));
oTarget.html(poEvent.data.data.changed);
oTarget = $("#"+cJquery.child_ID(oElement, cCAControlRTypes.RUNS_ID));
oTarget.html(poEvent.data.data.runs);
break;
}
}

//***************************************************************
//* Privates
//***************************************************************
Expand All @@ -97,60 +54,20 @@ class cCAControlsR{
oElement = this.element;

//--input-------------------------------------------------
oDiv = $("<DIV>",{class:"ui-widget-header"}).append("Status");
oElement.append(oDiv);

oDiv = $("<DIV>",{class:"ui-widget-content"});
oTable = $("<Table>",{cellpadding:2});
oRow = $("<tr>");
oCell = $("<td>", {align:"right"}).append("Active");
oRow.append(oCell);
oCell = $("<td>",{id:cJquery.child_ID(oElement, cCAControlRTypes.ACTIVE_ID)});
oCell.append("??");
oRow.append(oCell);
oTable.append(oRow);
oRow = $("<tr>");
oCell = $("<td>", {align:"right"}).append("Changed");
oRow.append(oCell);
oCell = $("<td>",{id:cJquery.child_ID(oElement, cCAControlRTypes.CHANGED_ID)});
oCell.append("??");
oRow.append(oCell);
oTable.append(oRow);
oRow = $("<tr>");
oCell = $("<td>", {align:"right"}).append("Runs");
oRow.append(oCell);
oCell = $("<td>",{id:cJquery.child_ID(oElement, cCAControlRTypes.RUNS_ID)});
oCell.append("??");
oRow.append(oCell);
oTable.append(oRow);
oDiv.append(oTable);
oDiv = $("<DIV>");
oDiv.castatus({grid_name:this.grid_name});
oElement.append(oDiv);
oElement.append("<P>");

//-------------------------------------------------------------
oDiv = $("<DIV>",{id:cJquery.child_ID(oElement, cCAControlRTypes.CHART_ID)});
oDiv = $("<DIV>");
oDiv.cachart({grid_name:this.grid_name});
oElement.append(oDiv);
oElement.append("<P>");
oElement.append("<P>");

//--initialise------------------------------------------------
oDiv = $("<DIV>",{class:"ui-widget-header"});
oDiv.append("Initialise");
oElement.append(oDiv);

var oThis = this;
oDiv = $("<DIV>",{class:"ui-widget-content"});
var oSelect = $("<SELECT>",{width:200,title:"choose a pattern to initialise the grid with"});
oSelect.append( $("<option>",{selected:1,disabled:1,value:-1}).append("Initialise"));
for (var sName in cCAGridTypes.init){
var oItem = cCAGridTypes.init[sName];
var oOption = $("<option>",{value:oItem.id}).append(oItem.label);
oSelect.append ( oOption);
}
oDiv.append(oSelect);
oSelect.selectmenu({
select:function(poEvent){oThis.onInitClick(poEvent)}
});
oDiv = $("<DIV>");
oDiv.cagridinit({grid_name:this.grid_name});
oElement.append(oDiv);
oElement.append("<P>");

Expand Down

0 comments on commit c01aec6

Please sign in to comment.