mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-08-17 22:09:05 +02:00
* Split fields/arrays
This commit is contained in:
parent
f1c419e71b
commit
f245c1ce31
@ -10,17 +10,31 @@ type
|
|||||||
|
|
||||||
TCustomDBBootstrapTableWidget = Class;
|
TCustomDBBootstrapTableWidget = Class;
|
||||||
|
|
||||||
TColumnRenderMode = (crmText, crmNumeric, crmDateTime, crmTransformedValue, crmCheckBox, crmButton, crmCustom);
|
TColumnRenderMode = (crmText, crmNumeric, crmDateTime, crmTransformedValue, crmCheckBox, crmButton, crmCustom, crmSelect);
|
||||||
TColumnButtonType = (cbtInfo, cbtEdit, cbtDelete, cbtCustom);
|
TColumnButtonType = (cbtInfo, cbtEdit, cbtDelete, cbtCustom);
|
||||||
|
|
||||||
TDataTablesFieldMap = Class(TObject)
|
TDataTablesFieldMap = Class(TObject)
|
||||||
Private
|
Private
|
||||||
FRow: TJSArray;
|
|
||||||
FFieldDefs: TFieldDefs;
|
FFieldDefs: TFieldDefs;
|
||||||
Public
|
Public
|
||||||
Function GetValueByName(S: String): JSValue;
|
Function GetValueByName(S: String): JSValue; virtual; abstract;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
TArrayDataTablesFieldMap = Class(TDataTablesFieldMap)
|
||||||
|
Private
|
||||||
|
FRow: TJSArray;
|
||||||
|
Public
|
||||||
|
Function GetValueByName(S: String): JSValue; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TObjectDataTablesFieldMap = Class(TDataTablesFieldMap)
|
||||||
|
Private
|
||||||
|
FRow: TJSObject;
|
||||||
|
Public
|
||||||
|
Function GetValueByName(S: String): JSValue; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
TOnCustomValueEvent = procedure(Sender: TObject; Fields: TDataTablesFieldMap; out aOutput: String) of object;
|
TOnCustomValueEvent = procedure(Sender: TObject; Fields: TDataTablesFieldMap; out aOutput: String) of object;
|
||||||
TOnFormatEvent = procedure(Sender: TObject; Data: JSValue; row: TJSObject; RowIndex : Integer; Field : string; out aOutput: JSValue);
|
TOnFormatEvent = procedure(Sender: TObject; Data: JSValue; row: TJSObject; RowIndex : Integer; Field : string; out aOutput: JSValue);
|
||||||
TSortOrderMethod = function(Sender: TObject; Data: JSValue): Integer;
|
TSortOrderMethod = function(Sender: TObject; Data: JSValue): Integer;
|
||||||
@ -149,6 +163,7 @@ type
|
|||||||
|
|
||||||
TOnCreatedRowEvent = reference to function(row: TJSNode; Data: TJSArray; dataIndex: Integer): JSValue;
|
TOnCreatedRowEvent = reference to function(row: TJSNode; Data: TJSArray; dataIndex: Integer): JSValue;
|
||||||
TRowSelectEvent = Procedure(Sender : TObject; aRow : TJSObject; aField : String) of object;
|
TRowSelectEvent = Procedure(Sender : TObject; aRow : TJSObject; aField : String) of object;
|
||||||
|
TCheckRowEvent = Procedure(Sender : TObject; aRow : TJSObject) of object;
|
||||||
|
|
||||||
{ TTableDataLink }
|
{ TTableDataLink }
|
||||||
|
|
||||||
@ -188,6 +203,7 @@ type
|
|||||||
TCustomDBBootstrapTableWidget = class(TWebWidget)
|
TCustomDBBootstrapTableWidget = class(TWebWidget)
|
||||||
private
|
private
|
||||||
FAfterBodyDraw: TNotifyEvent;
|
FAfterBodyDraw: TNotifyEvent;
|
||||||
|
FOnCheckRow: TCheckRowEvent;
|
||||||
FOnDoubleClickRow: TRowSelectEvent;
|
FOnDoubleClickRow: TRowSelectEvent;
|
||||||
FStylingClasses: TStylingClasses;
|
FStylingClasses: TStylingClasses;
|
||||||
FLink : TTableDataLink;
|
FLink : TTableDataLink;
|
||||||
@ -202,8 +218,9 @@ type
|
|||||||
FTableViewOptions: TBSTableViewOptions;
|
FTableViewOptions: TBSTableViewOptions;
|
||||||
FShowSearch: Boolean;
|
FShowSearch: Boolean;
|
||||||
FReadOnly: Boolean;
|
FReadOnly: Boolean;
|
||||||
procedure DoDoubleClickRow(aRow: TJSOBject; El: TJSHTMLElement;
|
FTableCreated : Boolean;
|
||||||
aField: String);
|
procedure DoDoubleClickRow(aRow: TJSOBject; El: TJSHTMLElement; aField: String);
|
||||||
|
procedure DoCheckRow(aRow: TJSOBject; El: TJSHTMLElement);
|
||||||
function GetData: TJSArray;
|
function GetData: TJSArray;
|
||||||
function GetDataFromDataset: TJSArray;
|
function GetDataFromDataset: TJSArray;
|
||||||
function GetDataset: TDataset;
|
function GetDataset: TDataset;
|
||||||
@ -228,6 +245,7 @@ type
|
|||||||
Procedure ActiveChanged; virtual;
|
Procedure ActiveChanged; virtual;
|
||||||
function HTMLTag: String; override;
|
function HTMLTag: String; override;
|
||||||
procedure DoAfterBodyDraw(aData : JSValue);
|
procedure DoAfterBodyDraw(aData : JSValue);
|
||||||
|
procedure ApplyOtherOptions(aOptions: TBootstrapTableOptions);
|
||||||
procedure ApplyPaginationOptions(aOptions: TBootstrapTableOptions); virtual;
|
procedure ApplyPaginationOptions(aOptions: TBootstrapTableOptions); virtual;
|
||||||
procedure ApplySearchOptions(aOptions: TBootstrapTableOptions); virtual;
|
procedure ApplySearchOptions(aOptions: TBootstrapTableOptions); virtual;
|
||||||
procedure ApplyViewOptions(aOptions: TBootstrapTableOptions); virtual;
|
procedure ApplyViewOptions(aOptions: TBootstrapTableOptions); virtual;
|
||||||
@ -299,6 +317,8 @@ type
|
|||||||
Property AfterBodyDraw : TNotifyEvent Read FAfterBodyDraw Write FAfterBodyDraw;
|
Property AfterBodyDraw : TNotifyEvent Read FAfterBodyDraw Write FAfterBodyDraw;
|
||||||
// Called when the user double-clicks a row
|
// Called when the user double-clicks a row
|
||||||
Property OnDoubleClickRow : TRowSelectEvent Read FOnDoubleClickRow Write FOnDoubleClickRow;
|
Property OnDoubleClickRow : TRowSelectEvent Read FOnDoubleClickRow Write FOnDoubleClickRow;
|
||||||
|
// Called when the user selects a record
|
||||||
|
Property OnCheckRow : TCheckRowEvent Read FOnCheckRow Write FOnCheckRow;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TDBBootstrapTableWidget = class(TCustomDBBootstrapTableWidget)
|
TDBBootstrapTableWidget = class(TCustomDBBootstrapTableWidget)
|
||||||
@ -314,6 +334,7 @@ type
|
|||||||
property DisplayReadOnly;
|
property DisplayReadOnly;
|
||||||
Property AfterBodyDraw;
|
Property AfterBodyDraw;
|
||||||
Property OnDoubleClickRow;
|
Property OnDoubleClickRow;
|
||||||
|
Property OnCheckRow;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Const
|
Const
|
||||||
@ -502,7 +523,12 @@ Var
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
if Datasource.Dataset is TBaseJSONDataset then
|
if Datasource.Dataset is TBaseJSONDataset then
|
||||||
Result:=TRowsDataset(Datasource.Dataset).Rows
|
begin
|
||||||
|
Result:=TJSArray(TRowsDataset(Datasource.Dataset).Rows).filter(function (el : jsvalue; Index : NativeInt; aArr : TJSArray) : boolean
|
||||||
|
begin
|
||||||
|
Result:=isDefined(el);
|
||||||
|
end);
|
||||||
|
end
|
||||||
else
|
else
|
||||||
With Datasource.Dataset do
|
With Datasource.Dataset do
|
||||||
begin
|
begin
|
||||||
@ -557,11 +583,17 @@ end;
|
|||||||
procedure TCustomDBBootstrapTableWidget.DoDoubleClickRow(aRow: TJSOBject;
|
procedure TCustomDBBootstrapTableWidget.DoDoubleClickRow(aRow: TJSOBject;
|
||||||
El: TJSHTMLElement; aField: String);
|
El: TJSHTMLElement; aField: String);
|
||||||
begin
|
begin
|
||||||
Writeln('In double click of row');
|
|
||||||
if Assigned(FOnDoubleClickRow) then
|
if Assigned(FOnDoubleClickRow) then
|
||||||
FOnDoubleClickRow(Self,aRow,aField);
|
FOnDoubleClickRow(Self,aRow,aField);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCustomDBBootstrapTableWidget.DoCheckRow(aRow: TJSOBject;
|
||||||
|
El: TJSHTMLElement);
|
||||||
|
begin
|
||||||
|
if Assigned(FOnCheckRow) then
|
||||||
|
FOnCheckRow(Self,aRow);
|
||||||
|
end;
|
||||||
|
|
||||||
function TCustomDBBootstrapTableWidget.GetDatasource : TDataSource;
|
function TCustomDBBootstrapTableWidget.GetDatasource : TDataSource;
|
||||||
begin
|
begin
|
||||||
Result:=FLink.DataSource;
|
Result:=FLink.DataSource;
|
||||||
@ -628,7 +660,7 @@ end;
|
|||||||
function TCustomDBBootstrapTableWidget.MakeTransformValueCol(aCol: TBootstrapTableColumn; aTableCol: TBSTableColumn): TBootstrapTableColumn;
|
function TCustomDBBootstrapTableWidget.MakeTransformValueCol(aCol: TBootstrapTableColumn; aTableCol: TBSTableColumn): TBootstrapTableColumn;
|
||||||
|
|
||||||
var
|
var
|
||||||
F:TDataTablesFieldMap;
|
F : TObjectDataTablesFieldMap;
|
||||||
|
|
||||||
function renderCallBack(Data: JSValue; row: TJSObject; RowIndex : Integer; Field : string): JSValue;
|
function renderCallBack(Data: JSValue; row: TJSObject; RowIndex : Integer; Field : string): JSValue;
|
||||||
|
|
||||||
@ -637,6 +669,7 @@ var
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
Res:='';
|
Res:='';
|
||||||
|
F.FRow:=Row;
|
||||||
if Assigned(aTableCol.OnTransformValue) then
|
if Assigned(aTableCol.OnTransformValue) then
|
||||||
aTableCol.OnTransformValue(aTableCol, F, Res);
|
aTableCol.OnTransformValue(aTableCol, F, Res);
|
||||||
Result:=Res;
|
Result:=Res;
|
||||||
@ -644,7 +677,7 @@ var
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
Result:=aCol;
|
Result:=aCol;
|
||||||
F:=TDataTablesFieldMap.Create;
|
F:=TObjectDataTablesFieldMap.Create;
|
||||||
F.FFieldDefs:=Datasource.DataSet.FieldDefs;
|
F.FFieldDefs:=Datasource.DataSet.FieldDefs;
|
||||||
Result.Formatter := @renderCallBack;
|
Result.Formatter := @renderCallBack;
|
||||||
end;
|
end;
|
||||||
@ -911,6 +944,8 @@ begin
|
|||||||
MakeDateTimeRenderCol(aColumn, aCol);
|
MakeDateTimeRenderCol(aColumn, aCol);
|
||||||
crmNumeric:
|
crmNumeric:
|
||||||
MakeNumericRenderCol(aColumn, aCol);
|
MakeNumericRenderCol(aColumn, aCol);
|
||||||
|
crmSelect:
|
||||||
|
aColumn.checkbox:=True;
|
||||||
end;
|
end;
|
||||||
Result[I] := aColumn;
|
Result[I] := aColumn;
|
||||||
end;
|
end;
|
||||||
@ -968,6 +1003,21 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCustomDBBootstrapTableWidget.ApplyOtherOptions(
|
||||||
|
aOptions: TBootstrapTableOptions);
|
||||||
|
|
||||||
|
begin
|
||||||
|
aOptions.clickToSelect:=(btoClickToSelect in Options);
|
||||||
|
aOptions.escape:=(btoEscapeHTML in Options);
|
||||||
|
aOptions.singleSelect:=(btoSingleSelect in Options);
|
||||||
|
aOptions.resizable:=(btoResizable in Options);
|
||||||
|
aOptions.multipleSelectRow:=(btoMultipleSelectRow in Options);
|
||||||
|
aOptions.rememberOrder:=(btoRememberOrder in Options);
|
||||||
|
aOptions.resizable:=(btoResizable in Options);
|
||||||
|
aOptions.detailViewByClick:=(btoDetailViewByClick in Options);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TCustomDBBootstrapTableWidget.ConfigureOptions(
|
procedure TCustomDBBootstrapTableWidget.ConfigureOptions(
|
||||||
aOptions: TBootstrapTableOptions);
|
aOptions: TBootstrapTableOptions);
|
||||||
Var
|
Var
|
||||||
@ -978,9 +1028,11 @@ begin
|
|||||||
ApplySearchOptions(aOptions);
|
ApplySearchOptions(aOptions);
|
||||||
ApplyPaginationOptions(aOptions);
|
ApplyPaginationOptions(aOptions);
|
||||||
ApplyViewOptions(aOptions);
|
ApplyViewOptions(aOptions);
|
||||||
|
ApplyOtherOptions(aOptions);
|
||||||
aOptions.Data := Data;
|
aOptions.Data := Data;
|
||||||
aOptions.onPostBody:=@DoAfterBodyDraw;
|
aOptions.onPostBody:=@DoAfterBodyDraw;
|
||||||
aOptions.onDblClickRow:=@DoDoubleClickRow;
|
aOptions.onDblClickRow:=@DoDoubleClickRow;
|
||||||
|
aOptions.onCheck:=@DoCheckRow;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -1101,8 +1153,9 @@ end;
|
|||||||
|
|
||||||
procedure TCustomDBBootstrapTableWidget.RefreshData;
|
procedure TCustomDBBootstrapTableWidget.RefreshData;
|
||||||
begin
|
begin
|
||||||
Data:=Nil;
|
FData:=Nil; // Force re-fetch at next occasion
|
||||||
Refresh;
|
if IsRendered then
|
||||||
|
JQuery('#'+ElementID).BootstrapTable('load',GetData)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -1110,6 +1163,7 @@ procedure TCustomDBBootstrapTableWidget.UnRender;
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
JQuery('#'+ElementID).BootstrapTable('destroy');
|
JQuery('#'+ElementID).BootstrapTable('destroy');
|
||||||
|
FTableCreated:=False;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomDBBootstrapTableWidget.ApplyWidgetSettings(aElement: TJSHTMLElement);
|
procedure TCustomDBBootstrapTableWidget.ApplyWidgetSettings(aElement: TJSHTMLElement);
|
||||||
@ -1120,8 +1174,11 @@ var
|
|||||||
begin
|
begin
|
||||||
aOptions:=TBootstrapTableOptions.New;
|
aOptions:=TBootstrapTableOptions.New;
|
||||||
ConfigureOptions(aOptions);
|
ConfigureOptions(aOptions);
|
||||||
JQuery(aElement).BootstrapTable(aOptions);
|
if FTableCreated then
|
||||||
// JQuery('#'+ElementID).BootstrapTable('refresh');
|
JQuery('#'+aElement.ID).BootstrapTable('refreshOptions',aOptions)
|
||||||
|
else
|
||||||
|
JQuery(aElement).BootstrapTable(aOptions);
|
||||||
|
FTableCreated:=True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCustomDBBootstrapTableWidget.IsOptionsStored: Boolean;
|
function TCustomDBBootstrapTableWidget.IsOptionsStored: Boolean;
|
||||||
@ -1149,17 +1206,29 @@ begin
|
|||||||
Result:=ViewOptions<>DefaultViewOptions;
|
Result:=ViewOptions<>DefaultViewOptions;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TDataTablesFieldMap }
|
{ TArrayDataTablesFieldMap }
|
||||||
|
|
||||||
function TDataTablesFieldMap.GetValueByName(S: String): JSValue;
|
function TArrayDataTablesFieldMap.GetValueByName(S: String): JSValue;
|
||||||
Var
|
Var
|
||||||
fld: TFieldDef;
|
fld: TFieldDef;
|
||||||
begin
|
begin
|
||||||
fld:=FFieldDefs.Find(S);
|
fld:=FFieldDefs.Find(S);
|
||||||
if Assigned(fld) then
|
if Assigned(fld) and assigned(FRow) then
|
||||||
Result:=FRow[fld.Index]
|
Result:=FRow[fld.Index]
|
||||||
else
|
else
|
||||||
Result:=Null;
|
Result:=Null;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TObjectDataTablesFieldMap.GetValueByName(S: String): JSValue;
|
||||||
|
Var
|
||||||
|
fld: TFieldDef;
|
||||||
|
begin
|
||||||
|
fld:=FFieldDefs.Find(S);
|
||||||
|
if Assigned(fld) and assigned(FRow) then
|
||||||
|
Result:=FRow[fld.name]
|
||||||
|
else
|
||||||
|
Result:=Null;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user