Changeset 54 for trunk/Modules


Ignore:
Timestamp:
Jul 20, 2011, 11:52:31 PM (13 years ago)
Author:
george
Message:
  • Upraveno: Přesunuty další části z UMainModule do třídy UWebApp valíku CoolWeb.
Location:
trunk/Modules
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/UMainModule.lfm

    r53 r54  
    55  VerticalOffset = 205
    66  Width = 431
    7   object HTTPServer: THTTPServerCGI
    8     ShowExceptions = False
    9     DocumentRoot = './'
    10     SessionStorage = HTTPSessionStorageMySQL1
    11     OnRequest = HTTPServerRequest
    12     left = 81
    13     top = 32
    14   end
    157  object HTTPSessionStorageMySQL1: THTTPSessionStorageMySQL
    168    Database = Database
  • trunk/Modules/UMainModule.lrs

    r53 r54  
    33LazarusResources.Add('TMainModule','FORMDATA',[
    44  'TPF0'#11'TMainModule'#10'MainModule'#14'OldCreateOrder'#8#6'Height'#3#22#1#16
    5   +'HorizontalOffset'#3#162#1#14'VerticalOffset'#3#205#0#5'Width'#3#175#1#0#14
    6   +'THTTPServerCGI'#10'HTTPServer'#14'ShowExceptions'#8#12'DocumentRoot'#6#2'./'
    7   +#14'SessionStorage'#7#24'HTTPSessionStorageMySQL1'#9'OnRequest'#7#17'HTTPSer'
    8   +'verRequest'#4'left'#2'Q'#3'top'#2' '#0#0#24'THTTPSessionStorageMySQL'#24'HT'
    9   +'TPSessionStorageMySQL1'#8'Database'#7#8'Database'#7'Timeout'#3'0*'#19'Sessi'
    10   +'onIdCookieName'#6#9'SessionId'#4'left'#3'8'#1#3'top'#2#31#0#0#12'TSqlDataba'
    11   +'se'#8'Database'#9'Connected'#8#8'Encoding'#6#4'utf8'#4'left'#2'Q'#3'top'#2
    12   +'V'#0#0#0
     5  +'HorizontalOffset'#3#162#1#14'VerticalOffset'#3#205#0#5'Width'#3#175#1#0#24
     6  +'THTTPSessionStorageMySQL'#24'HTTPSessionStorageMySQL1'#8'Database'#7#8'Data'
     7  +'base'#7'Timeout'#3'0*'#19'SessionIdCookieName'#6#9'SessionId'#4'left'#3'8'#1
     8  +#3'top'#2#31#0#0#12'TSqlDatabase'#8'Database'#9'Connected'#8#8'Encoding'#6#4
     9  +'utf8'#4'left'#2'Q'#3'top'#2'V'#0#0#0
    1310]);
  • trunk/Modules/UMainModule.pas

    r53 r54  
    77uses
    88  Classes, SysUtils, FileUtil, LResources, UHTTPServerCGI, UHTTPSessionMySQL,
    9   UHTTPServer, USqlDatabase, UConfig, DateUtils, UWebPage,
     9  UHTTPServer, USqlDatabase, UConfig, DateUtils, UWebPage, UWebApp,
    1010  UXmlClasses, UHtmlClasses, UCore, UHTTPServerTCP,
    1111  UHTTPSessionFile, UUser, SpecializedList;
    1212
    1313type
    14   TMainModule = class;
    15 
    16   TRegistredPage = class
    17     Name: string;
    18     Page: TWebPage;
    19   end;
    20 
    21   { TRegistredPageList }
    22 
    23   TRegistredPageList = class(TListObject)
    24     function FindByName(Name: string): TRegistredPage;
    25   end;
    26 
    2714  { TMainModule }
    2815
    2916  TMainModule = class(TDataModule)
    30     HTTPServer: THTTPServerCGI;
    3117    HTTPSessionStorageMySQL1: THTTPSessionStorageMySQL;
    3218    Database: TSqlDatabase;
    33     procedure HTTPServerRequest(HandlerData: THTTPHandlerData);
    3419  private
    3520    procedure Footer;
     
    4934    Keywords: string;
    5035    HtmlDocument: THtmlDocument;
    51     Pages: TRegistredPageList;
    5236    PageName: string;
    5337    ModuleName: string;
     
    5539    User: TWebUser;
    5640    UserOnline: TWebOnlineUser;
     41    procedure GeneratePage(HandlerData: THTTPHandlerData; Page: TWebPage);
    5742    procedure Run;
    5843    constructor Create(AOwner: TComponent); override;
    5944    destructor Destroy; override;
    60     procedure RegisterPage(Name: string; Page: TWebPage);
    6145  end;
    6246
     
    6448  MainModule: TMainModule;
    6549
    66  resourcestring
    67   SPageNotFound = 'Page not found';
    68 
    6950
    7051implementation
    7152
    72 { TRegistredPageList }
    73 
    74 function TRegistredPageList.FindByName(Name: string): TRegistredPage;
    75 var
    76   I: Integer;
    77 begin
    78   I := 0;
    79   while (I < Count) and (TRegistredPage(Items[I]).Name <> Name) do Inc(I);
    80   if I < Count then Result := TRegistredPage(Items[I])
    81     else Result := nil;
    82 end;
    83 
    8453{ TMainModule }
    8554
    86 procedure TMainModule.HTTPServerRequest(HandlerData: THTTPHandlerData);
     55procedure TMainModule.GeneratePage(HandlerData: THTTPHandlerData; Page: TWebPage);
    8756var
    8857  I: Integer;
    8958  TitleTag: THtmlString;
    90   Page: TRegistredPage;
    9159begin
    9260  User.HandlerData := HandlerData;
     
    10371    HtmlDocument.Scripts.Add(NavigationLink('/Style/' + Style + '/jquery.js'));
    10472
    105     Request.QueryParts.Count := 2;
    106     Request.QueryParts[0] := 'uzivatel';
    107     Request.QueryParts[1] := 'prihlaseni';
    108 
    109     if Request.QueryParts.Count > 0 then PageName := Request.QueryParts[0]
    110       else PageName := '';
    111     Page := Pages.FindByName(PageName);
    112     if Assigned(Page) then begin
    11373      TitleTag := THtmlString.Create;
    114       HtmlDocument.Body.SubItems.Add(TitleTag);
     74      HtmlDocument.Body.SubItems.Insert(0, TitleTag);
    11575      TopMenu;
    116       Page.Page.OnProduce(HandlerData);
    117       HtmlDocument.Title := Page.Page.Caption;
     76      //Page.Page.OnProduce(HandlerData);
     77      HtmlDocument.Title := Page.Caption;
    11878      TitleTag.Text := '<div class="TitlePanel"><span class="GlobalTitle">' + GlobalTitle +
    11979        '</span> - ' + HtmlDocument.Title + '</div>';
     
    12686        Free;
    12787      end;
    128     end else Response.Stream.WriteString(SPageNotFound);
    129   end;
    130 end;
    131 
    132 procedure TMainModule.RegisterPage(Name: string; Page: TWebPage);
    133 var
    134   NewRegistredPage: TRegistredPage;
    135 begin
    136   NewRegistredPage := TRegistredPage.Create;
    137   NewRegistredPage.Name := Name;
    138   NewRegistredPage.Page := Page;
    139   Pages.Add(NewRegistredPage);
    140 end;
    141 
     88  end;
     89end;
    14290
    14391procedure TMainModule.InitDatabase;
     
    163111begin
    164112  inherited;
    165   Pages := TRegistredPageList.Create;
    166113  HtmlDocument := THtmlDocument.Create;
    167114  User := TWebUser.Create;
     
    174121begin
    175122  HtmlDocument.Free;
    176   Pages.Free;
    177123  User.Free;
    178124  UserOnline.Free;
     
    251197procedure TMainModule.TopMenu;
    252198begin
    253   with THtmlString(HtmlDocument.Body.SubItems.AddNew(THtmlString.Create)) do begin
     199  with THtmlString(HtmlDocument.Body.SubItems.InsertNew(1, THtmlString.Create)) do begin
    254200    Text := '<div class="Navigation">';
    255201    // Visitor
     
    286232begin
    287233  InitDatabase;
    288   MainModule.HTTPServer.ShowExceptions := Config.ShowException;
     234  Application.HTTPServer.ShowExceptions := Config.ShowException;
    289235  //Database.Query('SELECT * FROM ssss');
    290   MainModule.HTTPServer.Run;
    291236end;
    292237
Note: See TracChangeset for help on using the changeset viewer.