unit ResponsiveList;

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, Graphics,
  IW.Browser.SafariMobile, IW.Browser.Android;

type
  TformResponsiveList1 = class(TIWAppForm)
    FrameTopFrame1: TFrameTopFrame;
    IWLabel4: TIWLabel;
    IWRegion1: TIWRegion;
    IWLabel8: TIWLabel;
    IWLabel7: TIWLabel;
    IWLabel1: TIWLabel;
    TIWClientCode1: TTIWClientCode;
    btHome: TIWButton;
    TIWResponsiveList1: TTIWResponsiveList;
    procedure IWAppFormCreate(Sender: TObject);
    procedure btHomeClick(Sender: TObject);
    procedure IWAppFormDestroy(Sender: TObject);
    procedure TIWResponsiveList1AsyncControlEvent(Sender: TObject;
      EventParams: TStringList; EventType, ControlID: string;
      ItemIndex: Integer);
  public
    NewOrder: boolean;
    Websites: TStringList;
    procedure RenderItem(Content: string) overload;
    procedure RenderItem(Content: string; isSection: boolean) overload;
  end;

implementation

{$R *.dfm}

uses
  ServerController;


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

procedure TformResponsiveList1.IWAppFormCreate(Sender: TObject);
var
 si: TIWItemStylesItem;
begin
  ReportMemoryLeaksOnShutdown := true;
  Websites := TStringList.Create;
  TIWResponsiveList1.Title := 'Castles around the world';
  TIWResponsiveList1.ItemHeight := 150;
  TIWResponsiveList1.SectionHeight := 30;
  TIWResponsiveList1.MultiSelect := true;

  TIWResponsiveList1.DefaultItem.BorderWidth := 0;
  TIWResponsiveList1.DefaultItem.Color := clNone;
  TIWResponsiveList1.DefaultItem.SelectColor := clNone;
  TIWResponsiveList1.DefaultItem.BackgroundImage := 'files/bg.png';
  TIWResponsiveList1.DefaultItem.SelectBackgroundImage := 'files/bg_sel.png';
  TIWResponsiveList1.DefaultItem.Font.Color := clWebSlateGray;
  TIWResponsiveList1.DefaultItem.SelectFontColor := clWebSteelBlue;

  TIWResponsiveList1.ItemStyles.Clear;
  si := TIWResponsiveList1.ItemStyles.Add;
  si.ItemStyle.Color := clWebWhite;
  si.ItemStyle.ColorTo := clWebWhite;
  si.ItemStyle.BorderColor := clNone;
  si.ItemStyle.Font.Size := 14;
  si.ItemStyle.Font.Style := [fsBold];
  si.ItemStyle.Font.Color := clBlack;

  TIWResponsiveList1.Items.Clear;
  RenderItem('America', true);
  RenderItem('Bancroft Tower;Massachusetts;USA;1900;Yes;Yes;;Bancroft.png;http://en.wikipedia.org/wiki/Bancroft_Tower');
  RenderItem('Beardslee Castle;New York;USA;1860;Yes;Yes;;BeardsleeCastle.png;http://en.wikipedia.org/wiki/Beardslee_Castle');
  RenderItem('Canterbury Castle;Portland;USA;1929;Yes;Yes;;CanterburyCastle.png;http://en.wikipedia.org/wiki/Canterbury_Castle_(Portland,_Oregon)');
  RenderItem('Wilson Castle;Proctor;USA;1867;Yes;Yes;Dutch neo-renaissance;WilsonCastle.png;http://en.wikipedia.org/wiki/Wilson_Castle');
  RenderItem('Squire''s Castle;Ohio;USA;1890;Yes;Yes;;SquiresCastle.png;http://en.wikipedia.org/wiki/Squire%27s_Castle');

  RenderItem('Asia', true);
  RenderItem('Osaka Castle;Osaka;Japan;16th Century;No;Yes;;OsakaCastle.jpg;http://en.wikipedia.org/wiki/Osaka_Castle');
  RenderItem('Catherine Palace;Tsarskoye Selo;Russia;1717;Yes;Yes;;CatherinePalace.png;http://en.wikipedia.org/wiki/Catherine_Palace');
  RenderItem('Balga Castle;Kaliningrad Oblast;Russia;1239;Yes;Yes;;balga.png;http://en.wikipedia.org/wiki/Balga');
  RenderItem('Ivangorod Fortress;Leningrad Oblast;Russia;1492;Yes;Yes;;IvangorodFortress.png;http://en.wikipedia.org/wiki/Ivangorod');
  RenderItem('Korela Fortress;Leningrad Oblast;Russia;1310;Yes;Yes;;Korela.png;http://en.wikipedia.org/wiki/Korela_Fortress');
  RenderItem('Gyantse Dzong;Tibet;China;1390;Yes;Yes;;GyantseDzong.png;http://en.wikipedia.org/wiki/Gyantse_Dzong');
  RenderItem('Diaoyu Fortress; Heyang Town;China;1127;Yes;Yes;;DiaoyuFortress.png;http://en.wikipedia.org/wiki/Diaoyu_Fortress');

  RenderItem('Europe', true);
  RenderItem('Castle Howard;Yorkshire;UK;1699;Yes;Yes;Baroque;CastleHoward.jpg;http://en.wikipedia.org/wiki/Castle_Howard');
  RenderItem('Schloss Hohenschwangau;Bavaria;Germany;19th Century;Yes;Yes;;SchlossHohenschwangau.jpg;http://en.wikipedia.org/wiki/Hohenschwangau_Castle');
  RenderItem('Neuschwanstein Castle;Bavaria;Germany;1886;Yes;Yes;Romanesque;NeuschwansteinCastle.jpg;http://en.wikipedia.org/wiki/Neuschwanstein_Castle');
  RenderItem('Château de Chambord;;France;17th Century;Yes;Yes;Renaissance;ChateaudeChambord.jpg;http://en.wikipedia.org/wiki/Ch%C3%A2teau_de_Chambord');
  RenderItem('Kilkenny Castle;Kilkenny;Ireland;1195;No;Yes;;KilkennyCastle.jpg;http://en.wikipedia.org/wiki/Kilkenny_Castle');
  RenderItem('MoritzBurg Castle;Saxony;Germany;16th Century;Yes;Yes;Baroque;MoritzBurgCastle.jpg;http://en.wikipedia.org/wiki/Moritzburg_Castle');
  RenderItem('Kronborg Castle;Helsingør;Denmark;1420;Yes;No;Renaissance;KronborgCastle.png;http://en.wikipedia.org/wiki/Kronborg');
  RenderItem('Edinburgh Castle;Edinburgh;Scotland;12th Century;Yes;Yes;;EdinburghCastle.png;http://en.wikipedia.org/wiki/Edinburgh_Castle');
  RenderItem('Palace of Versailles; Versaille;France;1664;Yes;Yes;;Versailles.png;http://en.wikipedia.org/wiki/Palace_of_Versailles');
  RenderItem('Prague Castle;Prague;Czech Republic;;Yes;Yes;;PragueCastle.png;http://en.wikipedia.org/wiki/Prague_Castle');
  RenderItem('Bodiam Castle;East Sussex;UK;14th century;Yes;Yes;;BodiamCastle.png;http://en.wikipedia.org/wiki/Bodiam_Castle');
  RenderItem('Chillon Castle;Lake Geneva;Switzerland;1005;Yes;Yes;;chillon.png;http://en.wikipedia.org/wiki/Ch%C3%A2teau_de_Chillon');
  RenderItem('Corfe Castle;Dorset;UK;11th century;No;Yes;;CorfeCastle.png;http://en.wikipedia.org/wiki/Corfe_Castle');
  RenderItem('Malbork Castle;Malbork;Poland;1406;Yes;Yes;;Malbork.png;http://en.wikipedia.org/wiki/Malbork_Castle');
  RenderItem('Hohenwerfen Castle;Salzach valley;Austria;11th century;Yes;No;;HohenwerfenCastle.png;http://en.wikipedia.org/wiki/Hohenwerfen_Castle');
  RenderItem('Peles Castle;Carpathian Mountains;Romania;1873;Yes;Yes;Neo-Renaissance;PelesCastle.png;http://en.wikipedia.org/wiki/Pele%C8%99_Castle');
  RenderItem('Alnwick Castle;Northumberland;UK;1096;Yes;Yes;;AlnwickCastle.png;http://en.wikipedia.org/wiki/Alnwick_Castle');
  RenderItem('Highclere Castle;Hampshire;UK;19th-century;No;Yes;Jacobethan style;HighclereCastle.png;http://en.wikipedia.org/wiki/Highclere_Castle');
  RenderItem('Kylemore Abbey;Connemara;Ireland;1920;Yes;Yes;;KylemoreAbbey.png;http://en.wikipedia.org/wiki/Kylemore_Abbey');
  RenderItem('Windsor Castle;Berkshire;UK;11th century;Yes;Yes;;windsor.png;http://en.wikipedia.org/wiki/Windsor_Castle');
  RenderItem('Balmoral Castle;Aberdeenshire;Scotland;1852;Yes;Yes;Scots Baronial architecture;BalmoralCastle.png;http://en.wikipedia.org/wiki/Balmoral_Castle');
  RenderItem('Conwy Castle;Conwy;Wales;1283;Yes;No;military architecture;conwy.png;http://en.wikipedia.org/wiki/Conwy_Castle');
  RenderItem('Schwerin Castle;Schwerin;Germany;1845;Yes;Yes;romantic Historicism;SchwerinCastle.png;http://en.wikipedia.org/wiki/Schwerin_Palace');
  RenderItem('Château du Haut-Kœnigsbourg;Orschwiller;France;1147;Yes;Yes;;HautKoennigsbourg.png;http://en.wikipedia.org/wiki/Ch%C3%A2teau_du_Haut-K%C5%93nigsbourg');
  RenderItem('Château de Billy;Billy;France;13th – 14th century;Yes;Yes;;billy.png;http://en.wikipedia.org/wiki/Ch%C3%A2teau_de_Billy');
  RenderItem('Château de Doumely;Doumely-Bégny ;France;15th-century;Yes;Yes;;Doumely.png;http://en.wikipedia.org/wiki/Ch%C3%A2teau_de_Doumely');
  RenderItem('Château de Courcy;Courcy;France;12th-13th century;Yes;Yes;military architecture;Courcy.png;http://en.wikipedia.org/wiki/Ch%C3%A2teau_de_Courcy');
  RenderItem('Château de Boulogne-sur-Mer;Boulogne-sur-Mer;France;13th century;Yes;Yes;;boulogne.png;http://en.wikipedia.org/wiki/Ch%C3%A2teau_de_Boulogne-sur-Mer');
  RenderItem('Cleydael Castle;Aartselaar;Belgium;14th century;Yes;Yes;;Cleydael.png;http://en.wikipedia.org/wiki/Cleydael_Castle');
  RenderItem('Beauvoorde Castle;Wulveringem;Belgium;1408;Yes;Yes;Renaissance style;Beauvoorde.png;http://en.wikipedia.org/wiki/Beauvoorde_Castle');
  RenderItem('Ammersoyen Castle;Ammerzoden;the Netherlands;12th Century;Yes;Yes;;Ammersoyen.png;http://en.wikipedia.org/wiki/Ammersoyen_Castle');
  RenderItem('Biljoen Castle;Velp;the Netherlands;16th Century;Yes;Yes;;biljoen.png;http://en.wikipedia.org/wiki/Biljoen_Castle');
  RenderItem('Doorwerth Castle;Arnhem;the Netherlands;1260;Yes;Yes;;Doorwerth.png;http://en.wikipedia.org/wiki/Doorwerth_Castle');
  RenderItem('New Castle of Ansembourg;Ansembourg;Luxembourg;1639;Yes;Yes;;Ansembourg.png;http://en.wikipedia.org/wiki/New_Castle_of_Ansembourg');
  RenderItem('Aspelt Castle;Aspelt;Luxembourg;1590;Yes;Yes;;aspelt.png;http://en.wikipedia.org/wiki/Aspelt_Castle');
  RenderItem('Bettembourg Castle;Bettembourg;Luxembourg;1733;Yes;Yes;;bettembourg.png;http://en.wikipedia.org/wiki/Bettembourg_Castle');
  RenderItem('Loarre Castle;Loarre;Spain;11th and 12th centuries;Yes;Yes;;LoarreCastle.png;http://en.wikipedia.org/wiki/Loarre_Castle');
  RenderItem('Castle of Sancti Petri;San Fernando;Spain;13th century;Yes;Yes;Moorish style;SanctiPetri.png;http://en.wikipedia.org/wiki/Castle_of_Sancti_Petri');
end;

procedure TformResponsiveList1.IWAppFormDestroy(Sender: TObject);
begin
  Websites.Free;
end;

procedure TformResponsiveList1.RenderItem(Content: string);
begin
  RenderItem(Content, false);
end;

procedure TformResponsiveList1.RenderItem(Content: string; isSection: boolean);
var
  fields: TStringList;
  li: TIWListItem;
  isPrivate, canVisit: string;
  isSelected: integer;
begin
  if isSection then
  begin
    li := TIWResponsiveList1.Items.Add;
    li.Text.Text := Content;
    li.IsSection := true;
    li.ItemStyle := 'Style0';
    Websites.Add('');
  end
  else
  begin
    fields := TStringList.Create;
    Split(';', Content, fields);

    if fields.Count < 9 then
      exit;

    if LowerCase(fields[4]) = 'yes' then
      isPrivate := ' checked'
    else
      isPrivate := '';

    if LowerCase(fields[5]) = 'yes' then
      canVisit := ' checked'
    else
      canVisit := '';

    Randomize;
    isSelected := Random(2) - 1;

    li := TIWResponsiveList1.Items.Add;
    li.Selected := boolean(isSelected);
    li.Text.Clear;
    li.Text.Add('<img src="files/' + fields[7] + '" class="ListItem">');
    li.Text.Add('<b>' + fields[0] + '</b>');
    li.Text.Add('<br>City: ' + fields[1] + ' (' + fields[2] + ')');
    li.Text.Add('<br>Built: ' + fields[3]);
    li.Text.Add('<br>Style: ' + fields[6]);
    li.Text.Add('<br><input type="checkbox" disabled' + isPrivate + '> Privately owned');
    li.Text.Add('<br><input type="checkbox" disabled' + canVisit + '> Open to public');
    if fields[8] <> '' then
    begin
      li.Text.Add('<br><input type="button" value="Website" onclick="'
        + TIWResponsiveList1.HTMLName + 'ControlEventHandler(event, ''Click'')">');
      Websites.Add(fields[8]);
    end;

    fields.Free;
  end;
end;

procedure TformResponsiveList1.TIWResponsiveList1AsyncControlEvent(
  Sender: TObject; EventParams: TStringList; EventType, ControlID: string;
  ItemIndex: Integer);
begin
  if Websites.Count > ItemIndex then
  begin
    if ((WebApplication.Browser is TSafariMobile) or (WebApplication.Browser is TAndroid)) then
      WebApplication.GoToURL(Websites[ItemIndex])
    else
      WebApplication.NewWindow(Websites[ItemIndex]);
  end;
end;

initialization
  TformResponsiveList1.SetAsMainForm


end.
