Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Wald committed Oct 11, 2017
2 parents a8e3bec + 5fa7afe commit e426c58
Show file tree
Hide file tree
Showing 7 changed files with 272 additions and 102 deletions.
22 changes: 19 additions & 3 deletions BBjGridExWidget.bbj
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,12 @@ class public BBjGridExWidget extends BBjWidget
case Types.INTEGER
case Types.DECIMAL
case Types.DOUBLE
case Types.NUMERIC
cdef$=cdef$+",""type"":""numericColumn"",""filter"":""number"""
break
case Types.DATE
case Types.TIMESTAMP

cdef$=cdef$+",""filter"":""date"""
break

Expand Down Expand Up @@ -342,10 +344,24 @@ class public BBjGridExWidget extends BBjWidget
close (ch)
#HTMLView!.injectScript(script$,1)
fi

ch=unt
open (ch)"BBjGridExWidget/js/format.js"
read record (ch,siz=5512000)script$
close (ch)
#HTMLView!.injectScript(script$)


ch=unt
open (ch)"BBjGridExWidget/js/masks.js"
read record (ch,siz=5512000)script$
close (ch)
#HTMLView!.injectScript(script$)


ch=unt
open (ch)"BBjGridExWidget/js/BBjGridExWidget.js"
read record (ch,siz=1521000)script$
read record (ch,siz=5512000)script$
close (ch)

if INFO(3,6)="5" then
Expand All @@ -354,7 +370,7 @@ class public BBjGridExWidget extends BBjWidget
else
p_script! = script$
p_script! = p_script!.replaceAll("\$doc","document")
p_script! = p_script!.replaceAll("\$wnd","window")
p_script! = p_script!.replaceAll("\$win","window")
#HTMLView!.injectScript(str(p_script!),1)
#HTMLView!.injectScript(str(p_script!))
fi
Expand Down Expand Up @@ -476,7 +492,7 @@ rem --------------------api methods--------------------------------
#ColumnDefinition! = new DataRow()
fi

#ColumnDefinition!.setFieldValue(Field$,Type!,"")
#ColumnDefinition!.setFieldValue(Field$,Type!,null())
#ColumnDefinition!.setFieldAttribute(Field$,"LABEL",Label$)
#ColumnDefinition!.setFieldAttribute(Field$,"EDITABLE",STR(Editable!))

Expand Down
4 changes: 3 additions & 1 deletion Demo/Demo.bbj
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use ::BBjGridExWidget/BBjGridExWidget.bbj::BBjGridExWidget
use com.basiscomponents.bc.SqlQueryBC
? 'HIDE'

declare auto BBjTopLevelWindow wnd!
declare auto BBjListButton lb_db!
Expand Down Expand Up @@ -106,6 +105,9 @@ doQuery:

rs! = bc!.retrieve("SELECT * FROM "+tbl$)
grid!.setData(rs!)

rs!.setAttribute(23,"MASK","%Y-%Mz-%Dz")
rs!.setAttribute(24,"MASK","%Y/%Mz/%Dz")
fi
return

Expand Down
8 changes: 7 additions & 1 deletion Demo/GridColumnsStateDemo.bbj
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ fillGrid:
declare SqlQueryBC sbc!
sbc! = new SqlQueryBC(BBjAPI().getJDBCConnection("CDStore"))
rs! = sbc!.retrieve("SELECT * FROM CDINVENTORY")


print rs!.get(0).toJson()
grid!.addColumn("CDNUMBER","Item#")
grid!.addColumn("COST","COST",2)
grid!.addColumn("ARTIST","Artist Name")
grid!.addColumn("TITLE","Record Title")
grid!.addColumn("LABEL","Publisher")
Expand All @@ -49,8 +51,12 @@ fillGrid:
grid!.setMultipleSelection(1)


rs!.setAttribute(10,"MASK","$#,##00")

grid!.setData(rs!)



grid!.setCallback(grid!.ON_GRID_SELECT_ROW(),"onRowSelect")
grid!.setCallback(grid!.ON_GRID_DOUBLE_CLICK(),"onRowDoubleclick")

Expand Down
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
],
"dependencies": {
"ag-grid-enterprise": "^12.0.2",
"ag-grid": "^12.0.2"
"ag-grid": "^12.0.2",
"number-format.js": "^1.1.11"
}
}
134 changes: 38 additions & 96 deletions js/BBjGridExWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,94 +7,12 @@
*/

bbj_grid_supported_value_formatter = {
'date': bbj_grid_widget_get_value_formatter_date
}

function bbj_formate_date(date, format) {

if (!date || !format) return null;

date = new Date(date);

var year = date.getYear();
var fullYear = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDay();
var hours24 = date.getHours();
var hours12 = hours24 - 12;
hours12 = hours12 <= 12 ? hours12 : hours24;
hours12 = hours12 == 0 ? 12 : hours12;
var minutes = date.getMinutes();
var seconds = date.getSeconds();

var translations = {

// year
"Yz": year,
"Ys": fullYear,
"Yl": fullYear,
"Yp": String.fromCharCode(year),
"Yd": fullYear,
"Y": fullYear,

// month
"Mz": String(month).length == 1 ? "0" + month : month,
"Ms": month,
"Ml": month,
"Mp": String.fromCharCode(month),
"Md": month,
"M": month,

// day
"Dz": String(day).length == 1 ? "0" + day : day,
"Ds": day,
"Dl": day,
"Dp": String.fromCharCode(day),
"Dd": day,
"D": day,

// hour 24
"Hs": hours24,
"Hl": hours24,
"Hp": String.fromCharCode(hours24),
"Hd": hours24,
"H": hours24,

// hour 12
"hs": String(hours12).length == 1 ? "0" + hours12 : hours12,
"hl": hours12,
"hp": String.fromCharCode(hours12),
"hd": hours12,
"h": hours12,

// minutes
"ms": String(minutes).length == 1 ? "0" + minutes : minutes,
"ml": minutes,
"mp": String.fromCharCode(minutes),
"md": minutes,
"m": minutes,

// seconds
"ss": String(seconds).length == 1 ? "0" + seconds : seconds,
"sl": seconds,
"sp": String.fromCharCode(seconds),
"sd": seconds,
"s": seconds,

'pd': hours24 > 12 ? 'PM' : 'AM',
'p': hours24 > 12 ? 'PM' : 'AM',
};

var result = format;
for (var k in translations) {
result = result.replace(new RegExp('(%' + k + ')', 'g'), translations[k]);
}

return result;
'date': bbj_grid_widget_get_value_formatter_date,
'number': bbj_grid_widget_get_value_formatter_number
}

function bbj_grid_widget_post_event(ev) {
window.basisDispatchCustomEvent(ev,ev.payload);
window.basisDispatchCustomEvent(ev, ev.payload);
}

function bbj_grid_widget_send_event(payload) {
Expand Down Expand Up @@ -157,9 +75,11 @@ function bbj_grid_widget_init(container, license, data, options) {

onRowDoubleClicked: function (e) {

bbj_grid_widget_send_event(
{ 'type': 'grid-row-doubleclick', 'rows': e.data, 'nodes': e.rowIndex }
);
bbj_grid_widget_send_event({
'type': 'grid-row-doubleclick',
'rows': e.data,
'nodes': e.rowIndex
});
},

onSelectionChanged: function (e) {
Expand All @@ -172,9 +92,11 @@ function bbj_grid_widget_init(container, license, data, options) {
n.push(node_i.id);
}

bbj_grid_widget_send_event(
{ 'type': 'grid-select-row', 'rows': r, 'nodes': n }
);
bbj_grid_widget_send_event({
'type': 'grid-select-row',
'rows': r,
'nodes': n
});
},

getNodeChildDetails: function (rowItem) {
Expand Down Expand Up @@ -227,16 +149,36 @@ function bbj_grid_widget_get_value_formatter(filter) {

function bbj_grid_widget_get_value_formatter_date(data) {

return bbj_formate_date(
data.value,
'%Y-%Mz-%Dz'
);
if (
$doc.bbj_grid_widget_meta.hasOwnProperty(data.colDef.field) &&
$doc.bbj_grid_widget_meta[data.colDef.field].hasOwnProperty('MASK')
) {
return bbj_mask_date(
data.value,
$doc.bbj_grid_widget_meta[data.colDef.field].MASK //'%Y-%Mz-%Dz'
);
} else return data.value;
}

function bbj_grid_widget_get_value_formatter_number(data) {

if (
$doc.bbj_grid_widget_meta.hasOwnProperty(data.colDef.field) &&
$doc.bbj_grid_widget_meta[data.colDef.field].hasOwnProperty('MASK')
) {
return bbj_mask_number(
data.value,
$doc.bbj_grid_widget_meta[data.colDef.field].MASK
);
} else return data.value;
}

function bbj_grid_widget_set_data(json, options) {

var container = $doc.getElementById('grid');
container.innerHTML = '';
$doc.bbj_grid_widget_instance = bbj_grid_widget_init(container, '', json, options);

$doc.bbj_grid_widget_meta = json[0].meta;
$doc.bbj_grid_widget = options;
$doc.bbj_grid_widget_instance = bbj_grid_widget_init(container, '', json, options);
}
117 changes: 117 additions & 0 deletions js/format.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/**
* javascript-number-formatter
* Lightweight & Fast JavaScript Number Formatter
*
* @preserve IntegraXor Web SCADA - JavaScript Number Formatter (http://www.integraxor.com/)
* @author KPL
* @maintainer Rob Garrison
* @copyright 2017 ecava
* @license MIT
* @link http://mottie.github.com/javascript-number-formatter/
* @version 1.1.11
*/
/*jshint browser:true */
/* global define, module */
(function ( root, factory ) {
if ( typeof define === 'function' && define.amd ) {
define( [], factory );
} else if ( typeof module === 'object' ) {
module.exports = factory();
} else {
root.format = factory();
}
}( this, function () {

return function ( mask, value ) {
'use strict';
if ( !mask || isNaN( +value ) ) {
return value; // return as it is.
}

var isNegative, result, decimal, group, posLeadZero, posTrailZero, posSeparator,
part, szSep, integer,

// find prefix/suffix
len = mask.length,
start = mask.search( /[0-9\-\+#]/ ),
prefix = start > 0 ? mask.substring( 0, start ) : '',
// reverse string: not an ideal method if there are surrogate pairs
str = mask.split( '' ).reverse().join( '' ),
end = str.search( /[0-9\-\+#]/ ),
offset = len - end,
substr = mask.substring( offset, offset + 1 ),
indx = offset + ( ( substr === '.' || ( substr === ',' )) ? 1 : 0 ),
suffix = end > 0 ? mask.substring( indx, len ) : '';

// mask with prefix & suffix removed
mask = mask.substring( start, indx );

// convert any string to number according to formation sign.
value = mask.charAt( 0 ) === '-' ? -value : +value;
isNegative = value < 0 ? value = -value : 0; // process only abs(), and turn on flag.

// search for separator for grp & decimal, anything not digit, not +/- sign, not #.
result = mask.match( /[^\d\-\+#]/g );
decimal = ( result && result[ result.length - 1 ] ) || '.'; // treat the right most symbol as decimal
group = ( result && result[ 1 ] && result[ 0 ] ) || ','; // treat the left most symbol as group separator

// split the decimal for the format string if any.
mask = mask.split( decimal );
// Fix the decimal first, toFixed will auto fill trailing zero.
value = value.toFixed( mask[ 1 ] && mask[ 1 ].length );
value = +( value ) + ''; // convert number to string to trim off *all* trailing decimal zero(es)

// fill back any trailing zero according to format
posTrailZero = mask[ 1 ] && mask[ 1 ].lastIndexOf( '0' ); // look for last zero in format
part = value.split( '.' );
// integer will get !part[1]
if ( !part[ 1 ] || ( part[ 1 ] && part[ 1 ].length <= posTrailZero ) ) {
value = ( +value ).toFixed( posTrailZero + 1 );
}
szSep = mask[ 0 ].split( group ); // look for separator
mask[ 0 ] = szSep.join( '' ); // join back without separator for counting the pos of any leading 0.

posLeadZero = mask[ 0 ] && mask[ 0 ].indexOf( '0' );
if ( posLeadZero > -1 ) {
while ( part[ 0 ].length < ( mask[ 0 ].length - posLeadZero ) ) {
part[ 0 ] = '0' + part[ 0 ];
}
} else if ( +part[ 0 ] === 0 ) {
part[ 0 ] = '';
}

value = value.split( '.' );
value[ 0 ] = part[ 0 ];

// process the first group separator from decimal (.) only, the rest ignore.
// get the length of the last slice of split result.
posSeparator = ( szSep[ 1 ] && szSep[ szSep.length - 1 ].length );
if ( posSeparator ) {
integer = value[ 0 ];
str = '';
offset = integer.length % posSeparator;
len = integer.length;
for ( indx = 0; indx < len; indx++ ) {
str += integer.charAt( indx ); // ie6 only support charAt for sz.
// -posSeparator so that won't trail separator on full length
/*jshint -W018 */
if ( !( ( indx - offset + 1 ) % posSeparator ) && indx < len - posSeparator ) {
str += group;
}
}
value[ 0 ] = str;
}
value[ 1 ] = ( mask[ 1 ] && value[ 1 ] ) ? decimal + value[ 1 ] : '';

// remove negative sign if result is zero
result = value.join( '' );
if ( result === '0' || result === '' ) {
// remove negative sign if result is zero
isNegative = false;
}

// put back any negation, combine integer and fraction, and add back prefix & suffix
return prefix + ( ( isNegative ? '-' : '' ) + result ) + suffix;
};

} ));

0 comments on commit e426c58

Please sign in to comment.