Ignore:
Timestamp:
Jan 4, 2010, 8:02:21 AM (15 years ago)
Author:
Kevin Toppenberg
Message:

Added HTML templating

Location:
cprs/branches/tmg-cprs/CPRS-Chart/Templates
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cprs/branches/tmg-cprs/CPRS-Chart/Templates/fTemplateDialog.pas

    r453 r654  
    66uses
    77  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
    8   StdCtrls, ExtCtrls, ORCtrls, ORFn, AppEvnts, uTemplates, DKLang;
     8  StdCtrls, StrUtils, ExtCtrls, ORCtrls, ORFn, AppEvnts, uTemplates, DKLang;
    99
    1010type
     
    4444    FCheck4Required: boolean;
    4545    FSilent: boolean;
     46    FHTMLMode : boolean; //kt added 12/28/09
     47    FAnswerOpenTag : string; //kt added 12/28/09
     48    FAnswerCloseTag : string; //kt added 12/28/09
    4649    procedure SizeFormToCancelBtn();
    4750    procedure ChkAll(Chk: boolean);
     
    5962    procedure ParentCBEnter(Sender: TObject);
    6063    procedure ParentCBExit(Sender: TObject);
     64    procedure SetAnswerHTMLTag(Value : string); //kt 12/28/09
    6165  public
    6266    property Silent: boolean read FSilent write FSilent ;
     67    property HTMLMode : boolean read FHTMLMode write FHTMLMode; //kt added 12/28/09
     68    property HTMLAnswerOpenTag : string read FAnswerOpenTag write SetAnswerHTMLTag;  //kt added 12/28/09
     69    property HTMLAnswerCloseTag : string read FAnswerCloseTag write SetAnswerHTMLTag;  //kt added 12/28/09
    6370  published
    6471  end;
     
    6673// Returns True if Cancel button is pressed
    6774function DoTemplateDialog(SL: TStrings; const CaptionText: string; PreviewMode: boolean = FALSE): boolean;
     75function RemoveHTMLTags(Txt : string) : string;
     76function FormatHTMLTags(Txt : string): string;
    6877procedure CheckBoilerplate4Fields(SL: TStrings; const CaptionText: string = ''; PreviewMode: boolean = FALSE); overload;
    6978procedure CheckBoilerplate4Fields(var AText: string; const CaptionText: string = ''; PreviewMode: boolean = FALSE); overload;
     
    8190  Gap = 4;
    8291  IndentGap = 18;
     92  HTMLBEGINNINGTAG = '{HTML:';   //kt
     93  HTMLENDINGTAG = '}';       //kt
     94  HTMLBEGINNINGTAGLEN = length(HTMLBEGINNINGTAG);  //kt
     95  HTMLENDINGTAGLEN = length(HTMLENDINGTAG);   //kt
    8396
    8497
     
    89102  Save, Hidden: boolean;
    90103  TmpCtrl: TStringList;
    91 
     104  HTMLMode : boolean; //kt added 12/28/09
     105  HTMLOpenTag,HTMLCloseTag : string; //kt added 12/28/09
    92106begin
    93107  Txt := SL.Text;
    94108  SL.Clear;
    95109  TmpCtrl := TStringList.Create;
     110  HTMLMode := frmTemplateDialog.HTMLMode; //kt added 12/28/09
     111  HTMLOpenTag := frmTemplateDialog.HTMLAnswerOpenTag;  //kt added 12/28/09
     112  HTMLCloseTag := frmTemplateDialog.HTMLAnswerCloseTag; //kt added 12/28/09
     113  //kt added 12/28/09
    96114  try
    97115    for i := 0 to frmTemplateDialog.sbMain.ControlCount-1 do
     
    117135        p2 := StrToInt(Piece(tmp,'~',2));
    118136        Hidden := (copy(Piece(tmp,'~',3),2,1)=BOOLCHAR[TRUE]);
    119         SL.Text := SL.Text + ResolveTemplateFields(Copy(Txt,p1,p2), FALSE, Hidden, IncludeEmbeddedFields);
     137        //kt original line 12/28/09 --> SL.Text := SL.Text + ResolveTemplateFields(Copy(Txt,p1,p2), FALSE, Hidden, IncludeEmbeddedFields);
     138        SL.Text := SL.Text + ResolveTemplateFields(Copy(Txt,p1,p2), FALSE, Hidden, IncludeEmbeddedFields,
     139                                                   HTMLMode, HTMLOpenTag, HTMLCloseTag );
    120140      end;
    121141    end;
     
    195215    DlgIDCounts.Duplicates := dupError;
    196216    frmTemplateDialog.Caption := CaptionText;
     217    frmTemplateDialog.HTMLMode := uTemplates.bUsingHTMLMode; //kt
     218    frmTemplateDialog.HTMLAnswerOpenTag := '<I>'; //kt 12/28/09
     219    //SL.Text := RemoveHTMLTags(SL.Text);  //elh
    197220    AssignFieldIDs(SL);
    198221    frmTemplateDialog.SL := SL;
     
    237260      end;
    238261      frmTemplateDialog.BuildAllControls;
    239       repeat                     
     262      repeat
    240263         frmTemplateDialog.ShowModal;
    241          if(frmTemplateDialog.ModalResult = mrOK) then
    242            GetText(SL, TRUE)     {TRUE = Include embedded fields}
    243          else
     264         if(frmTemplateDialog.ModalResult = mrOK) then begin
     265           GetText(SL, TRUE);     {TRUE = Include embedded fields}
     266           if uTemplates.bUsingHTMLMode then begin
     267              SL.Text := FormatHTMLTags(SL.Text);
     268           end else begin
     269              SL.Text := RemoveHTMLTags(SL.Text);
     270           end;
     271         end else begin
    244272          if (not PreviewMode) and (not frmTemplateDialog.Silent) and (not uInit.TimedOut) then
    245273            begin
     
    262290              CancelDlg := TRUE;
    263291            end;
     292         end;     
    264293      until CancelDlg or (frmTemplateDialog.ModalResult = mrOK)
    265294    end
     
    281310end;
    282311
     312function RemoveHTMLTags(Txt : string): string;
     313var
     314  beginning,ending : integer;
     315  tempString,tempResult : string;
     316begin
     317  tempString := Txt;
     318  //here we will strip out all HTML formatting tags  //elh
     319  beginning := pos(HTMLBEGINNINGTAG, tempString);
     320  if beginning = 0 then begin
     321     Result := Txt;
     322  end else begin
     323    while beginning > 0 do
     324    begin
     325      tempResult := tempResult + Leftstr(tempString,beginning-1);
     326      tempString := Rightstr(tempString,length(tempString)-beginning-HTMLBEGINNINGTAGLEN);
     327      ending := pos(HTMLENDINGTAG, tempString);
     328      tempString := Rightstr(tempString,length(tempString)-ending);
     329      beginning := pos(HTMLBEGINNINGTAG, tempString);
     330  //    tempString := Midstr(Txt,i,HTMLBEGINNINGTAGLEN);
     331    end;
     332    Result := tempResult + tempString;
     333  end;
     334end;
     335
     336function FormatHTMLTags(Txt : string): string;
     337var
     338  beginning,ending : integer;
     339  tempString,tempResult : string;
     340begin
     341  tempString := Txt;
     342  //here we will strip out all HTML formatting tags  //elh
     343  beginning := pos(HTMLBEGINNINGTAG, tempString);
     344  if beginning = 0 then begin
     345     Result := Txt;
     346  end else begin
     347    while beginning > 0 do
     348    begin
     349      tempResult := tempResult + Leftstr(tempString,beginning-1);
     350      tempString := Rightstr(tempString,length(tempString)-beginning-HTMLBEGINNINGTAGLEN+1);
     351      ending := pos(HTMLENDINGTAG, tempString);
     352      tempResult := tempResult + Leftstr(tempString,ending-1);
     353      tempString := Rightstr(tempString,length(tempString)-ending);
     354      beginning := pos(HTMLBEGINNINGTAG, tempString);
     355  //    tempString := Midstr(Txt,i,HTMLBEGINNINGTAGLEN);
     356    end;
     357    Result := tempResult + tempString;
     358  end;
     359end;
     360
    283361procedure CheckBoilerplate4Fields(SL: TStrings; const CaptionText: string = ''; PreviewMode: boolean = FALSE);
    284362begin
     
    307385  finally
    308386    tmp.free;
     387  end;
     388end;
     389
     390procedure TfrmTemplateDialog.SetAnswerHTMLTag(Value : string);
     391//kt 12/28/09 Added entire function
     392begin
     393  if Value='' then begin
     394    FAnswerOpenTag :='';
     395    FAnswerCloseTag := '';
     396  end else begin
     397    if Pos('<',Value)>0 then Value := Piece(Value,'<',2);
     398    if Pos('>',Value)>0 then Value := Piece(Value,'>',1);
     399    if Pos('/',Value)>0 then Value := Piece(Value,'/',2);
     400    FAnswerOpenTag :='<'+Value+'>';
     401    FAnswerCloseTag := '</' + Value + '>';
    309402  end;
    310403end;
     
    460553  end;
    461554  tmp := copy(SL.Text, p1, p2);
     555  tmp := RemoveHTMLTags(tmp);
    462556  if(copy(tmp, length(tmp)-1, 2) = CRLF) then
    463557    delete(tmp, length(tmp)-1, 2);
     
    637731procedure TfrmTemplateDialog.FormCreate(Sender: TObject);
    638732begin
     733  FHTMLMode := false; //kt added 12/28/09
    639734  BuildIdx := TStringList.Create;
    640735  Entries := TStringList.Create;
  • cprs/branches/tmg-cprs/CPRS-Chart/Templates/uTemplateFields.pas

    r453 r654  
    4444    FPanelDying: boolean;
    4545    FOnDestroy: TNotifyEvent;
     46    FHTMLMode : boolean; //kt added 12/28/09
     47    FAnswerOpenTag : string; //kt added 12/28/09
     48    FAnswerCloseTag : string; //kt added 12/28/09
    4649    procedure KillLabels;
    4750    function GetFieldValues: string;
    4851    procedure SetFieldValues(const Value: string);
    4952    procedure SetAutoDestroyOnPanelFree(const Value: boolean);
     53    procedure SetAnswerHTMLTag(Value : string); //kt 12/28/09
     54
    5055  protected
    5156    procedure UpDownChange(Sender: TObject);
     
    6772    property OnDestroy: TNotifyEvent read FOnDestroy write FOnDestroy;
    6873    property FieldValues: string read GetFieldValues write SetFieldValues;
     74    property HTMLMode : boolean read FHTMLMode write FHTMLMode; //kt added 12/28/09
     75    property AnswerHTMLTag : string read FAnswerOpenTag write SetAnswerHTMLTag;  //kt added 12/28/09
    6976    property AutoDestroyOnPanelFree: boolean read FAutoDestroyOnPanelFree
    7077                                             write SetAutoDestroyOnPanelFree;
     
    161168procedure AssignFieldIDs(var Txt: string); overload;
    162169procedure AssignFieldIDs(SL: TStrings); overload;
    163 function ResolveTemplateFields(Text: string; AutoWrap: boolean; Hidden: boolean = FALSE; IncludeEmbedded: boolean = FALSE): string;
     170//kt 12/28/09 originial --> function ResolveTemplateFields(Text: string; AutoWrap: boolean; Hidden: boolean = FALSE; IncludeEmbedded: boolean = FALSE): string;
     171function ResolveTemplateFields(Text: string;
     172                               AutoWrap: boolean;
     173                               Hidden: boolean = FALSE;
     174                               IncludeEmbedded: boolean = FALSE;
     175                               HTMLMode : boolean = FALSE; //kt added 12/28/09
     176                               HTMLAnswerOpenTag : string = ''; //kt added 12/28/09
     177                               HTMLAnswerCloseTag : string = '' //kt added 12/28/09
     178                               ): string;
    164179function AreTemplateFieldsRequired(const Text: string; FldValues: TORStringList =  nil): boolean;
    165180function HasTemplateField(txt: string): boolean;
     
    179194  TemplateFieldBeginSignature = '{FLD:';
    180195  TemplateFieldEndSignature = '}';
     196  HTMLBEGINNINGTAG = '{HTML:';
     197  HTMLENDINGTAG = '}';
     198  HTMLBEGINNINGTAGLEN = length(HTMLBEGINNINGTAG);
     199  HTMLENDINGTAGLEN = length(HTMLENDINGTAG);
    181200  //MissingFieldsTxt = 'One or more required fields must still be entered.';  <-- original line.  //kt 8/8/2007
    182201  function MissingFieldsTxt : string;  //kt added
     
    519538                               AutoWrap: boolean;
    520539                               Hidden: boolean = FALSE;
    521                                IncludeEmbedded: boolean = FALSE): string;
     540                               IncludeEmbedded: boolean = FALSE;
     541                               HTMLMode : boolean = FALSE; //kt added 12/28/09
     542                               HTMLAnswerOpenTag : string = ''; //kt added 12/28/09
     543                               HTMLAnswerCloseTag : string = '' //kt added 12/28/09
     544                               ): string;
    522545var
    523546  flen, CtrlID, i, j: integer;
     
    526549  FoundEntry: boolean;
    527550  TmplFld: TTemplateField;
     551  tempSL : TStringList;
    528552
    529553  procedure AddNewTxt;
     
    584608            if (assigned(TmplFld)) and (TmplFld.DateType in DateComboTypes) then {if this is a TORDateBox}
    585609               NewTxt := Piece(NewTxt,':',1);          {we only want the first piece of NewTxt}
     610            //kt 12/28/09 --- Start mod to wrap answers in custom HTML tag ---
     611            if (HTMLMode=true) and (NewTxt <> '') then begin
     612              NewTxt := HTMLAnswerOpenTag + NewTxt + HTMLAnswerCloseTag;   //kt 12/29/09
     613            end;
     614            //kt --- End mod to wrap answers in custom HTML tag ---
    586615            AddNewTxt;
    587616          end;
     
    594623        end;
    595624      end;
     625    end else begin
     626      if HTMLMode=true then begin
     627        tempSL := TStringList.create;
     628        tempSL.Text := Result;
     629        if tempSL.Count < 3 then begin
     630          Result := HTMLAnswerOpenTag + Result + HTMLAnswerCloseTag;
     631        end;
     632        tempSL.Free;
     633      end;
    596634    end;
    597635  until(i = 0);
    598636  if not AutoWrap then
    599637    WordWrapText(Result);
     638
    600639end;
    601640
     
    18011840  FID := AID;
    18021841  FText := Text;
     1842  FHTMLMode := false; //kt added 12/28/09
    18031843  FControls := TStringList.Create;
    18041844  FIndents := TStringList.Create;
     
    22232263end;
    22242264
     2265procedure TTemplateDialogEntry.SetAnswerHTMLTag(Value : string);
     2266//kt 12/28/09 Added entire function
     2267begin
     2268  if Value='' then begin
     2269    FAnswerOpenTag :='';
     2270    FAnswerCloseTag := '';
     2271  end else begin
     2272    if Pos('<',Value)>0 then Value := Piece(Value,'<',2);
     2273    if Pos('>',Value)>0 then Value := Piece(Value,'>',1);
     2274    FAnswerOpenTag :='<'+Value+'>';
     2275    FAnswerCloseTag := '</' + Value + '>';
     2276  end;
     2277end;
     2278
    22252279function TTemplateDialogEntry.GetText: string;
    22262280begin
    2227   Result := ResolveTemplateFields(FText, FALSE);
     2281  //kt Result := ResolveTemplateFields(FText, FALSE);
     2282  Result := ResolveTemplateFields(FText, FALSE, FALSE, FALSE, FHTMLMode, FAnswerOpenTag, FAnswerCloseTag); //kt 12/29/09
    22282283end;
    22292284
  • cprs/branches/tmg-cprs/CPRS-Chart/Templates/uTemplates.pas

    r541 r654  
    18861886  Itm: string;
    18871887begin
    1888   Result := GetBoilerplate;
     1888  Result := GetBoilerplate; //ELH
    18891889  if FIsReminderDialog or FIsCOMObject then exit;
    18901890  Itm := ItemBoilerplate;
     
    19521952          TmpSL.Text := rHTMLTools.Text2HTML(TmpSL);                //kt 8/09
    19531953        end;                                                        //kt 8/09
    1954         bUsingHTMLMode := false; //force reset each call.           //kt 8/09
     1954        //kt 12/28/09   bUsingHTMLMode := false; //force reset each call.           //kt 8/09
    19551955      end;                                                          //kt 8/09
    19561956      Result := TmpSL.Text;
Note: See TracChangeset for help on using the changeset viewer.