Changeset 49 for trunk/Application


Ignore:
Timestamp:
Mar 28, 2011, 9:40:06 AM (14 years ago)
Author:
george
Message:
  • Upraveno: Seznam registrovaných stránek předělán na samostatnou třídu s funkcí FindByName.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/UCustomApplication.pas

    r48 r49  
    1818    Name: string;
    1919    Producer: TPageProducer;
     20  end;
     21
     22  { TRegistredPageList }
     23
     24  TRegistredPageList = class(TListObject)
     25    function FindByName(Name: string): TRegistredPage;
    2026  end;
    2127
     
    4147    Keywords: string;
    4248    HtmlDocument: THtmlDocument;
    43     Pages: TListObject; // TListObject<TRegistredPage>
     49    Pages: TRegistredPageList;
    4450    Database: TSqlDatabase;
    4551    PageName: string;
     
    6167  SPageNotFound = 'Page not found';
    6268
     69{ TRegistredPageList }
     70
     71function TRegistredPageList.FindByName(Name: string): TRegistredPage;
     72var
     73  I: Integer;
     74begin
     75  I := 0;
     76  while (I < Count) and (TRegistredPage(Items[I]).Name <> Name) do Inc(I);
     77  if I < Count then Result := TRegistredPage(Items[I])
     78    else Result := nil;
     79end;
     80
    6381{ TCustomApplication }
    6482
     
    97115  I: Integer;
    98116  TitleTag: THtmlString;
     117  Page: TRegistredPage;
    99118begin
    100119  User.HandlerData := HandlerData;
     
    102121  UserOnline.Update;
    103122  with HandlerData do begin
    104   Style := Config.Style;
    105   BaseURL := Config.BaseURL;
    106 
    107   HtmlDocument.ContentLanguage := 'cs';
    108   GlobalTitle := 'ZděchovNET';
    109   HtmlDocument.Styles.Add(NavigationLink('/Style/' + Style + '/Style.css'));
    110   HtmlDocument.Scripts.Add(NavigationLink('/Style/' + Style + '/Global.js'));
    111   HtmlDocument.Scripts.Add(NavigationLink('/Style/' + Style + '/jquery.js'));
    112 
    113   Request.QueryParts.Count := 2;
    114   Request.QueryParts[0] := 'uzivatel';
    115   Request.QueryParts[1] := 'prihlaseni';
    116 
    117   if Request.QueryParts.Count > 0 then PageName := Request.QueryParts[0]
    118     else PageName := '';
    119   I := 0;
    120   while (I < Pages.Count) and (TRegistredPage(Pages[I]).Name <> PageName) do Inc(I);
    121   if (I < Pages.Count) then begin
    122     TitleTag := THtmlString.Create;
    123     HtmlDocument.Body.SubItems.Add(TitleTag);
    124     TopMenu;
    125     TRegistredPage(Pages[I]).Producer(Self, HandlerData);
    126     TitleTag.Text := '<div class="TitlePanel"><span class="GlobalTitle">' + GlobalTitle +
    127     '</span> - ' + HtmlDocument.Title + '</div>';
    128     HtmlDocument.Title := GlobalTitle + ' - ' + HtmlDocument.Title;
    129     with HtmlDocument.AsXmlDocument do try
    130       Formated := Config.FormatHTML;
    131       Response.Stream.WriteString(AsString);
    132     finally
    133       Free;
    134     end;
    135   end else Response.Stream.WriteString(SPageNotFound);
     123    Style := Config.Style;
     124    BaseURL := Config.BaseURL;
     125
     126    HtmlDocument.ContentLanguage := 'cs';
     127    GlobalTitle := 'ZděchovNET';
     128    HtmlDocument.Styles.Add(NavigationLink('/Style/' + Style + '/Style.css'));
     129    HtmlDocument.Scripts.Add(NavigationLink('/Style/' + Style + '/Global.js'));
     130    HtmlDocument.Scripts.Add(NavigationLink('/Style/' + Style + '/jquery.js'));
     131
     132    Request.QueryParts.Count := 2;
     133    Request.QueryParts[0] := 'uzivatel';
     134    Request.QueryParts[1] := 'prihlaseni';
     135
     136    if Request.QueryParts.Count > 0 then PageName := Request.QueryParts[0]
     137      else PageName := '';
     138    Page := Pages.FindByName(PageName);
     139    if Assigned(Page) then begin
     140      TitleTag := THtmlString.Create;
     141      HtmlDocument.Body.SubItems.Add(TitleTag);
     142      TopMenu;
     143      Page.Producer(Self, HandlerData);
     144      TitleTag.Text := '<div class="TitlePanel"><span class="GlobalTitle">' + GlobalTitle +
     145        '</span> - ' + HtmlDocument.Title + '</div>';
     146      HtmlDocument.Title := GlobalTitle + ' - ' + HtmlDocument.Title;
     147      with HtmlDocument.AsXmlDocument do
     148      try
     149        Formated := Config.FormatHTML;
     150        Response.Stream.WriteString(AsString);
     151      finally
     152        Free;
     153      end;
     154    end else Response.Stream.WriteString(SPageNotFound);
    136155  end;
    137156end;
     
    141160  inherited;
    142161  Database := TSqlDatabase.Create;
    143   Pages := TListObject.Create;
     162  Pages := TRegistredPageList.Create;
    144163  HtmlDocument := THtmlDocument.Create;
    145164  User := TWebUser.Create;
Note: See TracChangeset for help on using the changeset viewer.