Ignore:
Timestamp:
Oct 8, 2012, 8:48:16 AM (12 years ago)
Author:
chronos
Message:
  • Upraveno: TWebSession zobecněno pro možnost implementace více modulů s obsluhou vstupní stránky.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/UWebSession.pas

    r102 r103  
    77uses
    88  Classes, SysUtils, UHTTPServer, USqlDatabase, UHTTPSessionMySQL, UUser,
    9   UHtmlClasses, UWebPage;
     9  UHtmlClasses, UWebPage, UUtils, UXmlClasses, DateUtils;
    1010
    1111type
     
    1414  TWebSession = class(THTTPHandlerData)
    1515  private
    16     procedure TopMenu;
    17     procedure Footer;
    1816  public
    1917    MainModule: TObject;
     
    2725    procedure LoadUserInfo;
    2826    procedure InitDatabase;
    29     procedure GeneratePage(Page: TWebPage);
    3027    constructor Create; override;
    3128    destructor Destroy; override;
     29    procedure GeneratePage(Page: TWebPage);
    3230  end;
    3331
     32  TGeneratePageEvent = procedure (Session: TWebSession; Page: TWebPage) of object;
    3433
    3534implementation
     35
     36uses
     37  UCore;
    3638
    3739{ TWebSession }
     
    6062end;
    6163
     64procedure TWebSession.GeneratePage(Page: TWebPage);
     65begin
     66  with TCore(MainModule) do
     67  if Assigned(GeneratePage) then GeneratePage(Self, Page)
     68    else GeneratePageDefault(Self, Page);
     69end;
     70
    6271procedure TWebSession.InitDatabase;
    6372var
     
    6574begin
    6675  with Database do begin
     76    Encoding := 'utf8';
    6777    Connect;
    68   end;
    69   try
    70     DbRows := TDbRows.Create;
    71     Database.Query(DbRows, 'SET NAMES utf8');
    72   finally
    73     DbRows.Free;
    7478  end;
    7579end;
     
    7781procedure TWebSession.LoadUserInfo;
    7882begin
    79   if MainModule.ModuleManager.ModuleRunning('User') then begin
     83  if TCore(MainModule).ModuleManager.ModuleRunning('User') then begin
    8084    User.HandlerData := Self;
    8185    UserOnline.HandlerData := Self;
     
    8690end;
    8791
    88 procedure TWebSession.GeneratePage(Page: TWebPage);
    89 var
    90   I: Integer;
    91   TitleTag: THtmlString;
    92 begin
    93     HtmlDocument.ContentLanguage := 'cs';
    94     GlobalTitle := 'ZděchovNET';
    95     HtmlDocument.Styles.Add(NavigationLink('/Style/' + MainModule.Style + '/Style.css'));
    96     HtmlDocument.Scripts.Add(NavigationLink('/Style/' + MainModule.Style + '/Global.js'));
    97     HtmlDocument.Scripts.Add(NavigationLink('/Style/' + MainModule.Style + '/jquery.js'));
    98 
    99       TitleTag := THtmlString.Create;
    100       HtmlDocument.Body.SubItems.Insert(0, TitleTag);
    101       TopMenu;
    102       //Page.Page.OnProduce(HandlerData);
    103       HtmlDocument.Title := Page.Caption;
    104       TitleTag.Text := '<div class="TitlePanel"><span class="GlobalTitle">' + GlobalTitle +
    105         '</span> - ' + HtmlDocument.Title + '</div>';
    106       HtmlDocument.Title := GlobalTitle + ' - ' + HtmlDocument.Title;
    107       with HtmlDocument.AsXmlDocument do
    108       try
    109         Formated := MainModule.FormatHTML;
    110         Response.Content.WriteString(AsString);
    111       finally
    112         Free;
    113       end;
    114 end;
    115 
    11692end.
    11793
Note: See TracChangeset for help on using the changeset viewer.