unit ResponsiveListDB;

interface

uses
  Classes, SysUtils, IWAppForm, IWApplication, IWTypes, IWTMSCC,
  IWCompEdit, Controls, IWBaseControl, IWControl, IWCompLabel, LeftFrame,
  Forms, TopFrame, IWVCLBaseControl, IWBaseHTMLControl, IWAutoFormFill,
  IWTMSCtrls, IWContinuousScroll, IWBaseComponent, IWBaseHTMLComponent,
  IWBaseHTML40Component, IWCompExtCtrls, IWListEditor, IWCompButton,
  IWCompListbox, IWVCLBaseContainer, IWContainer, IWHTMLContainer,
  IWHTML40Container, IWRegion, IWResponsiveList, IWTMSBase, Main, IWColor,
  IWDBResponsiveList, Data.DB, Data.Win.ADODB, IWDBStdCtrls, IWCompCheckbox;

type
  TformResponsiveListDB1 = class(TIWAppForm)
    FrameTopFrame1: TFrameTopFrame;
    IWLabel4: TIWLabel;
    IWRegion1: TIWRegion;
    IWLabel7: TIWLabel;
    TIWClientCode1: TTIWClientCode;
    btHome: TIWButton;
    ADOQuery1: TADOQuery;
    DataSource1: TDataSource;
    ADOConnection1: TADOConnection;
    btUpdate: TIWButton;
    IWLabel1: TIWLabel;
    IWLabel2: TIWLabel;
    IWDBLabel1: TIWDBLabel;
    IWDBLabel2: TIWDBLabel;
    IWDBCheckBox1: TIWDBCheckBox;
    IWLabel3: TIWLabel;
    TIWDBResponsiveList1: TTIWDBResponsiveList;
    procedure IWAppFormCreate(Sender: TObject);
    procedure btHomeClick(Sender: TObject);
    procedure TIWDBResponsiveList1GetDataTemplate(Sender: TObject;
      ItemIndex: Integer; FieldName: string; var Data: string;
      var DisplayType: TIWDisplayType);
    procedure TIWDBResponsiveList1AsyncUpdated(Sender: TObject;
      ItemIndex: Integer);
    procedure btUpdateAsyncClick(Sender: TObject; EventParams: TStringList);
    procedure TIWDBResponsiveList1GetListDataEvent(Sender: TObject;
      FieldName: string; var ListItems: TStringList);
  public
    NewOrder: boolean;
  end;

implementation

{$R *.dfm}

uses
  ServerController;


procedure TformResponsiveListDB1.btHomeClick(Sender: TObject);
begin
  TIWAppForm(WebApplication.ActiveForm).Release;
  TformMain.Create(WebApplication).Show;
end;

procedure TformResponsiveListDB1.btUpdateAsyncClick(Sender: TObject;
  EventParams: TStringList);
begin
  if TIWDBResponsiveList1.ItemIndex >= 0 then
  begin
    TIWDBResponsiveList1.DataSource.DataSet.Edit;
    TIWDBResponsiveList1.UpdateRecord;
  end;
end;

procedure TformResponsiveListDB1.IWAppFormCreate(Sender: TObject);
begin
  TIWDBResponsiveList1.Title := 'Contact List';
  TIWDBResponsiveList1.MultiSelect := false;
  TIWDbResponsiveList1.DefaultItem.RoundedBorderRadius := 4;
  TIWDBResponsiveList1.ItemHeight := 150;
  TIWDBResponsiveList1.DefaultItem.SelectBorderColor := clWebDODGERBLUE;
  TIWDBResponsiveList1.DefaultItem.SelectColor := clWebWHITESMOKE;

  TIWDBResponsiveList1.DataTemplate.Add('<label class="Label">Contact <#ID></label>');
  TIWDBResponsiveList1.DataTemplate.Add('<br><label class="Label">Name:</label><input type="text" id="last_name" value="<#last_name>">');
  TIWDBResponsiveList1.DataTemplate.Add('<br><label class="Label">First name:</label><input type="text" id="first_name" value="<#first_name>">');
  TIWDBResponsiveList1.DataTemplate.Add('<br><label class="Label">Category:</label><select id="category"><#category></select>');
  TIWDBResponsiveList1.DataTemplate.Add('<br><label class="Label">Email:</label><a href="mailto:<#email>"><#email></a>');
  TIWDBResponsiveList1.DataTemplate.Add('<br><label class="Label">&nbsp;</label><input type="checkbox" id="mailing" <#mailing>> In mailing list');

  TIWDBResponsiveList1.DataSource := DataSource1;
  TIWDBResponsiveList1.DataSource.DataSet.Active := false;

  ADOConnection1.ConnectionString :=
    'Provider=Microsoft.Jet.OLEDB.4.0;Password="";Persist Security Info=True;Data Source= ' +
  WebApplication.ApplicationPath + 'contacts.mdb';

  TIWDBResponsiveList1.DataSource.DataSet.Active := true;
  TIWDBResponsiveList1.ItemIndex := 0;
end;

procedure TformResponsiveListDB1.TIWDBResponsiveList1AsyncUpdated(
  Sender: TObject; ItemIndex: Integer);
begin
  TIWDBResponsiveList1.DataSource.DataSet.Post;
end;

procedure TformResponsiveListDB1.TIWDBResponsiveList1GetDataTemplate(
  Sender: TObject; ItemIndex: Integer; FieldName: string; var Data: string;
  var DisplayType: TIWDisplayType);
begin
  if FieldName = 'mailing' then
    DisplayType := dtCheckBox;

  if FieldName = 'category' then
    DisplayType := dtList;
end;

procedure TformResponsiveListDB1.TIWDBResponsiveList1GetListDataEvent(
  Sender: TObject; FieldName: string; var ListItems: TStringList);
begin
  if FieldName = 'category' then
  begin
    ListItems.Add('Customer=0');
    ListItems.Add('Colleague=1');
    ListItems.Add('Friend=2');
    ListItems.Add('Family=3');
  end;
end;

initialization
  TformResponsiveListDB1.SetAsMainForm


end.
