|
@@ -21,7 +21,7 @@ unit dbhtmlwidgets;
|
|
interface
|
|
interface
|
|
|
|
|
|
uses
|
|
uses
|
|
- Classes, SysUtils, db, web, htmlwidgets;
|
|
|
|
|
|
+ JS, Classes, SysUtils, db, web, htmlwidgets;
|
|
|
|
|
|
Type
|
|
Type
|
|
|
|
|
|
@@ -132,6 +132,7 @@ Type
|
|
|
|
|
|
TCustomDBSelectWidget = class(TCustomSelectWidget)
|
|
TCustomDBSelectWidget = class(TCustomSelectWidget)
|
|
Private
|
|
Private
|
|
|
|
+ FItemTemplate: String;
|
|
FLink : TSelectLink;
|
|
FLink : TSelectLink;
|
|
FItemField: String;
|
|
FItemField: String;
|
|
FNullIsNotValue: Boolean;
|
|
FNullIsNotValue: Boolean;
|
|
@@ -142,6 +143,7 @@ Type
|
|
procedure SetDatasource(AValue: TDatasource);
|
|
procedure SetDatasource(AValue: TDatasource);
|
|
function GetDatasource: TDatasource;
|
|
function GetDatasource: TDatasource;
|
|
procedure SetItemField(AValue: String);
|
|
procedure SetItemField(AValue: String);
|
|
|
|
+ procedure SetItemTemplate(AValue: String);
|
|
procedure SetNullIsNotValue(AValue: Boolean);
|
|
procedure SetNullIsNotValue(AValue: Boolean);
|
|
procedure SetValue(AValue: String);
|
|
procedure SetValue(AValue: String);
|
|
procedure SetValueField(AValue: String);
|
|
procedure SetValueField(AValue: String);
|
|
@@ -153,6 +155,7 @@ Type
|
|
FDS : TDataset;
|
|
FDS : TDataset;
|
|
FTextField : TField;
|
|
FTextField : TField;
|
|
FValueField : TField;
|
|
FValueField : TField;
|
|
|
|
+ FItemTemplate : String;
|
|
FCheckValue : Boolean;
|
|
FCheckValue : Boolean;
|
|
constructor Create(ASelect : TCustomSelectWidget); override;
|
|
constructor Create(ASelect : TCustomSelectWidget); override;
|
|
Function OptionText : String; override;
|
|
Function OptionText : String; override;
|
|
@@ -169,6 +172,7 @@ Type
|
|
Property Datasource : TDatasource Read GetDatasource write SetDatasource;
|
|
Property Datasource : TDatasource Read GetDatasource write SetDatasource;
|
|
Property ItemField : String Read FItemField Write SetItemField;
|
|
Property ItemField : String Read FItemField Write SetItemField;
|
|
Property ValueField : String Read FValueField Write SetValueField;
|
|
Property ValueField : String Read FValueField Write SetValueField;
|
|
|
|
+ Property ItemTemplate: String Read FItemTemplate Write SetItemTemplate;
|
|
Property NullIsNotValue : Boolean Read FNullIsNotValue Write SetNullIsNotValue;
|
|
Property NullIsNotValue : Boolean Read FNullIsNotValue Write SetNullIsNotValue;
|
|
Property Value : String Read GetValue Write SetValue;
|
|
Property Value : String Read GetValue Write SetValue;
|
|
Public
|
|
Public
|
|
@@ -190,6 +194,7 @@ Type
|
|
Property SelectElement;
|
|
Property SelectElement;
|
|
Property ItemCount;
|
|
Property ItemCount;
|
|
Published
|
|
Published
|
|
|
|
+ Property ItemTemplate;
|
|
Property Datasource;
|
|
Property Datasource;
|
|
Property ItemField;
|
|
Property ItemField;
|
|
Property ValueField;
|
|
Property ValueField;
|
|
@@ -243,8 +248,25 @@ begin
|
|
end;
|
|
end;
|
|
|
|
|
|
function TCustomDBSelectWidget.TDBSelectOptionEnumerator.OptionText: String;
|
|
function TCustomDBSelectWidget.TDBSelectOptionEnumerator.OptionText: String;
|
|
|
|
+Var
|
|
|
|
+ E : TJSRegexp;
|
|
|
|
+ F : TField;
|
|
|
|
+
|
|
begin
|
|
begin
|
|
- Result:=FTextField.DisplayText;
|
|
|
|
|
|
+ if FItemTemplate='' then
|
|
|
|
+ Result:=FTextField.DisplayText
|
|
|
|
+ else
|
|
|
|
+ begin
|
|
|
|
+ E:=TJSRegexp.New('{{([_\w]*)}}','g');
|
|
|
|
+ Result:=TJSString(FItemTemplate).Replace(E,Function (Const match,p1 : string; offset : Integer; AString : String) : string
|
|
|
|
+ begin
|
|
|
|
+ F:=FDS.FindField(P1);
|
|
|
|
+ if Assigned(F) then
|
|
|
|
+ Result:=F.DisplayText
|
|
|
|
+ else
|
|
|
|
+ Result:='';
|
|
|
|
+ end);
|
|
|
|
+ end;
|
|
end;
|
|
end;
|
|
|
|
|
|
function TCustomDBSelectWidget.TDBSelectOptionEnumerator.HasValue: boolean;
|
|
function TCustomDBSelectWidget.TDBSelectOptionEnumerator.HasValue: boolean;
|
|
@@ -302,6 +324,12 @@ begin
|
|
FItemField:=AValue;
|
|
FItemField:=AValue;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+procedure TCustomDBSelectWidget.SetItemTemplate(AValue: String);
|
|
|
|
+begin
|
|
|
|
+ if FItemTemplate=AValue then Exit;
|
|
|
|
+ FItemTemplate:=AValue;
|
|
|
|
+end;
|
|
|
|
+
|
|
procedure TCustomDBSelectWidget.SetNullIsNotValue(AValue: Boolean);
|
|
procedure TCustomDBSelectWidget.SetNullIsNotValue(AValue: Boolean);
|
|
begin
|
|
begin
|
|
if FNullIsNotValue=AValue then Exit;
|
|
if FNullIsNotValue=AValue then Exit;
|
|
@@ -325,6 +353,7 @@ end;
|
|
function TCustomDBSelectWidget.CreateOptionEnumerator: TSelectOptionEnumerator;
|
|
function TCustomDBSelectWidget.CreateOptionEnumerator: TSelectOptionEnumerator;
|
|
begin
|
|
begin
|
|
Result:=TDBSelectOptionEnumerator.Create(Self);
|
|
Result:=TDBSelectOptionEnumerator.Create(Self);
|
|
|
|
+ TDBSelectOptionEnumerator(Result).FItemTemplate:=Self.FItemTemplate;
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TCustomDBSelectWidget.ActiveChanged;
|
|
procedure TCustomDBSelectWidget.ActiveChanged;
|