Revision | 66 (tree) |
---|---|
Zeit | 2021-11-24 04:10:04 |
Autor | derekwildstar |
Criada a função PrepareCommentForEdition que prepara um comentário para ser usado na sua edição e passado para o TinyMCE via string JS
Criado o método NewComment para facilitar a abertura e edição de novo comentário
Código para uso do POST com o TEdgeBrowser comentado até que eu consiga usá-lo
@@ -115,7 +115,7 @@ | ||
115 | 115 | <VerInfo_MinorVer>0</VerInfo_MinorVer> |
116 | 116 | <VerInfo_Release>0</VerInfo_Release> |
117 | 117 | <VerInfo_Locale>1033</VerInfo_Locale> |
118 | - <VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.49;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=;ProgramID=com.embarcadero.$(MSBuildProjectName)</VerInfo_Keys> | |
118 | + <VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.104;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=;ProgramID=com.embarcadero.$(MSBuildProjectName)</VerInfo_Keys> | |
119 | 119 | <Debugger_RunParams>/desenvolvimento</Debugger_RunParams> |
120 | 120 | <VerInfo_AutoGenVersion>false</VerInfo_AutoGenVersion> |
121 | 121 | <VerInfo_AutoIncVersion>true</VerInfo_AutoIncVersion> |
@@ -122,7 +122,7 @@ | ||
122 | 122 | <DCC_DebugInformation>2</DCC_DebugInformation> |
123 | 123 | <DCC_SymbolReferenceInfo>2</DCC_SymbolReferenceInfo> |
124 | 124 | <DCC_DebugInfoInExe>true</DCC_DebugInfoInExe> |
125 | - <VerInfo_Build>49</VerInfo_Build> | |
125 | + <VerInfo_Build>104</VerInfo_Build> | |
126 | 126 | <DCC_MapFile>3</DCC_MapFile> |
127 | 127 | </PropertyGroup> |
128 | 128 | <ItemGroup> |
@@ -225,7 +225,7 @@ | ||
225 | 225 | function TaskDetails(AHandle: Cardinal; var ATask: TTask): Boolean; |
226 | 226 | function GetAttachmentData(AHandle: Cardinal; AId: Cardinal; out AData: TMemoryStream): Boolean; |
227 | 227 | function GetCommentForEdition(AHandle: Cardinal; ACommentId: Cardinal; out AComment: String): Boolean; |
228 | -//function GetTinyMCEInitializationCode(AHandle: Cardinal): String; | |
228 | +function PrepareCommentForEdition(AComment: String): String; | |
229 | 229 | |
230 | 230 | implementation |
231 | 231 |
@@ -1460,44 +1460,96 @@ | ||
1460 | 1460 | |
1461 | 1461 | Req.AutoClearSSLState := True; |
1462 | 1462 | |
1463 | - Req.Content := TStringStream.Create('bugnote_id=' + ACommentId.ToString); | |
1463 | + Req.InternetOpenParams.Agent := 'MantisBT Monitor'; | |
1464 | + Req.InternetOpenParams.AccessType := INTERNET_OPEN_TYPE_PRECONFIG; | |
1465 | + Req.InternetConnectParams.ServerName := PChar(Configurations.MantisBTBaseUrl + '/mantis/bugnote_edit_page.php?bugnote_id=' + ACommentId.ToString); | |
1466 | + Req.InternetConnectParams.Service := INTERNET_SERVICE_HTTP; | |
1467 | + Req.InternetConnectParams.Context := AHandle; | |
1468 | + | |
1469 | + Req.HttpOpenRequestParams.Verb := 'GET'; | |
1470 | + Req.HttpOpenRequestParams.AcceptTypes := TStringList.Create; | |
1464 | 1471 | try |
1465 | - Req.InternetOpenParams.Agent := 'MantisBT Monitor'; | |
1466 | - Req.InternetOpenParams.AccessType := INTERNET_OPEN_TYPE_PRECONFIG; | |
1467 | - Req.InternetConnectParams.ServerName := PChar(Configurations.MantisBTBaseUrl + '/mantis/bugnote_edit_page.php'); | |
1468 | - Req.InternetConnectParams.Service := INTERNET_SERVICE_HTTP; | |
1469 | - Req.InternetConnectParams.Context := AHandle; | |
1472 | + Req.HttpOpenRequestParams.AcceptTypes.Add('*/*'); | |
1473 | + Req.HttpOpenRequestParams.Context := AHandle; | |
1474 | + Req.HttpOpenRequestParams.AutoDetectHTTPS := True; | |
1475 | + Req.HttpOpenRequestParams.IgnoreInvalidCertificates := True; | |
1476 | + Req.HttpOpenRequestParams.Headers := TStringList.Create; | |
1477 | + try | |
1478 | + Req.HttpOpenRequestParams.Headers.Add('Content-Type: application/x-www-form-urlencoded'); | |
1479 | + Req.HttpSendRequestParams.IgnoreInvalidCertificateCA := True; | |
1470 | 1480 | |
1471 | - Req.HttpOpenRequestParams.Verb := 'POST'; | |
1472 | - Req.HttpOpenRequestParams.AcceptTypes := TStringList.Create; | |
1473 | - try | |
1474 | - Req.HttpOpenRequestParams.AcceptTypes.Add('*/*'); | |
1475 | - Req.HttpOpenRequestParams.Context := AHandle; | |
1476 | - Req.HttpOpenRequestParams.AutoDetectHTTPS := True; | |
1477 | - Req.HttpOpenRequestParams.IgnoreInvalidCertificates := True; | |
1478 | - Req.HttpOpenRequestParams.Headers := TStringList.Create; | |
1481 | + Res.Content := TStringStream.Create('',TEncoding.UTF8); | |
1479 | 1482 | try |
1480 | - Req.HttpOpenRequestParams.Headers.Add('Content-Type: application/x-www-form-urlencoded'); | |
1481 | - Req.HttpSendRequestParams.IgnoreInvalidCertificateCA := True; | |
1483 | + Request(Req,Res); | |
1482 | 1484 | |
1483 | - Res.Content := TStringStream.Create('',TEncoding.UTF8); | |
1484 | - try | |
1485 | - Request(Req,Res); | |
1485 | + HTMLDocument := coHTMLDocument.Create as IHTMLDocument; | |
1486 | 1486 | |
1487 | - HTMLDocument := coHTMLDocument.Create as IHTMLDocument; | |
1487 | + (HTMLDocument as IHTMLDocument2).DesignMode := 'On'; | |
1488 | + (HTMLDocument as IHTMLDocument2).charset := 'utf-8'; | |
1489 | + (HTMLDocument as IHTMLDocument2Disp).Write(TStringStream(Res.Content).DataString); | |
1490 | + (HTMLDocument as IHTMLDocument2).Close; | |
1488 | 1491 | |
1489 | - (HTMLDocument as IHTMLDocument2).DesignMode := 'On'; | |
1490 | - (HTMLDocument as IHTMLDocument2).charset := 'utf-8'; | |
1491 | - (HTMLDocument as IHTMLDocument2Disp).Write(TStringStream(Res.Content).DataString); | |
1492 | - (HTMLDocument as IHTMLDocument2).Close; | |
1492 | + AComment := ((HTMLDocument as IHTMLDocument3).getElementById('bugnote_text') as IHTMLElement).innerText; | |
1493 | 1493 | |
1494 | - AComment := ((HTMLDocument as IHTMLDocument3).getElementById('bugnote_text') as IHTMLElement).innerText; | |
1494 | + Result := True; | |
1495 | + finally | |
1496 | + Res.Content.Free; | |
1497 | + end; | |
1498 | + finally | |
1499 | + Req.HttpOpenRequestParams.Headers.Free; | |
1500 | + end; | |
1501 | + finally | |
1502 | + Req.HttpOpenRequestParams.AcceptTypes.Free; | |
1503 | + end; | |
1504 | + finally | |
1505 | + Screen.Cursor := crDefault; | |
1506 | + end; | |
1507 | +end; | |
1508 | +{$WARN SYMBOL_PLATFORM ON} | |
1495 | 1509 | |
1496 | - é necessário trabalhar no innerhtml fazendo o que está explicado abaixo, provavelmente de forma invertida | |
1497 | - existem quebras de linha fisicas 1310, que precisam ser transformadas em <br> apenas dentro de tags pre | |
1498 | - basicamente o que deve ser feito é dentro dos pre, pegar tudo qu for quebra fisica 1310, 13 10 e converter para <BR> | |
1499 | - (* | |
1510 | +{$WARN SYMBOL_PLATFORM OFF} | |
1511 | +function PrepareCommentForEdition(AComment: String): String; | |
1512 | +var | |
1513 | + HTMLDocument: IHTMLDocument; | |
1514 | + HTMLElementCollection: IHTMLElementCollection; | |
1515 | + HTMLElement: IHTMLElement; | |
1516 | +begin | |
1517 | + Result := AComment; | |
1500 | 1518 | |
1519 | + HTMLDocument := coHTMLDocument.Create as IHTMLDocument; | |
1520 | + | |
1521 | + (HTMLDocument as IHTMLDocument2).DesignMode := 'On'; | |
1522 | + (HTMLDocument as IHTMLDocument2).charset := 'utf-8'; | |
1523 | + (HTMLDocument as IHTMLDocument2Disp).Write(AComment); | |
1524 | + (HTMLDocument as IHTMLDocument2).Close; | |
1525 | + | |
1526 | + HTMLElementCollection := (HTMLDocument as IHTMLDocument3).getElementsByTagName('pre'); | |
1527 | + | |
1528 | + if HTMLElementCollection.length > 0 then | |
1529 | + for var i: Word := 0 to Pred(HTMLElementCollection.length) do | |
1530 | + begin | |
1531 | + HTMLElement := (HTMLElementCollection as IHTMLelementCollection4).item(i) as IHTMLElement; | |
1532 | + HTMLElement.innerHTML := StringReplace(HTMLElement.innerHTML,#13#10,'<br>',[rfReplaceAll]); | |
1533 | + HTMLElement.innerHTML := StringReplace(HTMLElement.innerHTML,#13,'<br>',[rfReplaceAll]); | |
1534 | + HTMLElement.innerHTML := StringReplace(HTMLElement.innerHTML,#10,'<br>',[rfReplaceAll]); | |
1535 | + end; | |
1536 | + | |
1537 | + // Como a string com o fonte contém apenas um trecho de HTML, não um HTML | |
1538 | + // completo, o MSHTML automaticamente cria um fonte completo para si e coloca | |
1539 | + // nosso trecho em seu <body>, por isso, para obter o nosso trecho apenas, | |
1540 | + // basta obter o conteúdo do <body> como é visto abaixo | |
1541 | + Result := (HTMLDocument as IHTMLDocument2).body.innerHTML; | |
1542 | + // Como esse conteúdo será processado via string JavaScript, precisamos | |
1543 | + // escapar todas as aspas duplas existentes | |
1544 | + Result := StringReplace(Result,'"','\"',[rfReplaceAll]); | |
1545 | +end; | |
1546 | +{$WARN SYMBOL_PLATFORM ON} | |
1547 | + | |
1548 | +// é necessário trabalhar no innerhtml fazendo o que está explicado abaixo, provavelmente de forma invertida | |
1549 | +// existem quebras de linha fisicas 1310, que precisam ser transformadas em <br> apenas dentro de tags pre | |
1550 | +// basicamente o que deve ser feito é dentro dos pre, pegar tudo qu for quebra fisica 1310, 13 10 e converter para <BR> | |
1551 | + (* | |
1552 | + | |
1501 | 1553 | Este texto está pré-formatado e pode ser usado para exibir qualquer texto que |
1502 | 1554 | não pode perder'#$D#$A'seu formato, isto é, espaços em branco. Ele é renderizado |
1503 | 1555 | em fonte monoespaçada e precisa ter'#$D#$A'quebras de linha adicionadas de forma |
@@ -1508,53 +1560,35 @@ | ||
1508 | 1560 | tags'#$D#$A'PRE, mas o Mantis ignora este fato e termina por incluir quebras de |
1509 | 1561 | linha adicionais, fazendo'#$D#$A'com que hajam duas quebras para cada linha quebrada. |
1510 | 1562 | |
1511 | - let html = (new DOMParser()).parseFromString(aEventData.content,"text/html"); | |
1512 | - let pres = html.getElementsByTagName("pre"); | |
1563 | + let html = (new DOMParser()).parseFromString(aEventData.content,"text/html"); | |
1564 | + let pres = html.getElementsByTagName("pre"); | |
1513 | 1565 | |
1514 | - // Protege o conteúdo dos tags preformatados convertendo | |
1515 | - // tags br ou quebras de linha físicas por um tag | |
1516 | - // inexistente. Após este loop apenas vão existir | |
1517 | - // quebras de linha físicas fora de tags, as quais serão | |
1518 | - // removidas mais adiante. | |
1519 | - for (let pre of pres) { | |
1520 | - pre.innerHTML = pre.innerHTML.replaceAll("<br>","[br]"); | |
1521 | - pre.innerHTML = pre.innerHTML.replaceAll("<br />","[br]"); | |
1522 | - pre.innerHTML = pre.innerHTML.replaceAll("\\r\\n","[br]"); | |
1523 | - pre.innerHTML = pre.innerHTML.replaceAll("\\r","[br]"); | |
1524 | - pre.innerHTML = pre.innerHTML.replaceAll("\\n","[br]"); | |
1525 | - } | |
1566 | + // Protege o conteúdo dos tags preformatados convertendo | |
1567 | + // tags br ou quebras de linha físicas por um tag | |
1568 | + // inexistente. Após este loop apenas vão existir | |
1569 | + // quebras de linha físicas fora de tags, as quais serão | |
1570 | + // removidas mais adiante. | |
1571 | + for (let pre of pres) { | |
1572 | + pre.innerHTML = pre.innerHTML.replaceAll("<br>","[br]"); | |
1573 | + pre.innerHTML = pre.innerHTML.replaceAll("<br />","[br]"); | |
1574 | + pre.innerHTML = pre.innerHTML.replaceAll("\\r\\n","[br]"); | |
1575 | + pre.innerHTML = pre.innerHTML.replaceAll("\\r","[br]"); | |
1576 | + pre.innerHTML = pre.innerHTML.replaceAll("\\n","[br]"); | |
1577 | + } | |
1526 | 1578 | |
1527 | - // Serializa o html com os tags protetores | |
1528 | - aEventData.content = html.body.innerHTML; | |
1579 | + // Serializa o html com os tags protetores | |
1580 | + aEventData.content = html.body.innerHTML; | |
1529 | 1581 | |
1530 | - // Remove as quebras de linha físicas que são incluídas | |
1531 | - // automaticamente no código html | |
1532 | - aEventData.content = aEventData.content.replaceAll("\\r",""); | |
1533 | - aEventData.content = aEventData.content.replaceAll("\\n",""); | |
1582 | + // Remove as quebras de linha físicas que são incluídas | |
1583 | + // automaticamente no código html | |
1584 | + aEventData.content = aEventData.content.replaceAll("\\r",""); | |
1585 | + aEventData.content = aEventData.content.replaceAll("\\n",""); | |
1534 | 1586 | |
1535 | - // Substitui os tags protetores pelo seu valor real | |
1536 | - aEventData.content = aEventData.content.replaceAll("[br]","\\n"); | |
1587 | + // Substitui os tags protetores pelo seu valor real | |
1588 | + aEventData.content = aEventData.content.replaceAll("[br]","\\n"); | |
1537 | 1589 | |
1538 | - *) | |
1590 | + *) | |
1539 | 1591 | |
1540 | - Result := True; | |
1541 | - finally | |
1542 | - Res.Content.Free; | |
1543 | - end; | |
1544 | - finally | |
1545 | - Req.HttpOpenRequestParams.Headers.Free; | |
1546 | - end; | |
1547 | - finally | |
1548 | - Req.HttpOpenRequestParams.AcceptTypes.Free; | |
1549 | - end; | |
1550 | - finally | |
1551 | - Req.Content.Free; | |
1552 | - end; | |
1553 | - finally | |
1554 | - Screen.Cursor := crDefault; | |
1555 | - end; | |
1556 | -end; | |
1557 | -{$WARN SYMBOL_PLATFORM ON} | |
1558 | 1592 | |
1559 | 1593 | { TUserInfo } |
1560 | 1594 |
@@ -1745,58 +1779,4 @@ | ||
1745 | 1779 | end; |
1746 | 1780 | end; |
1747 | 1781 | |
1748 | -//function GetTinyMCEInitializationCode(AHandle: Cardinal): String; | |
1749 | -//var | |
1750 | -// Req: TRequestOptions; | |
1751 | -// Res: TResponse; | |
1752 | -//begin | |
1753 | -// Result := ''; | |
1754 | -// | |
1755 | -// Screen.Cursor := crHourGlass; | |
1756 | -// try | |
1757 | -// ZeroMemory(@Req,SizeOf(Req)); | |
1758 | -// ZeroMemory(@Res,SizeOf(Res)); | |
1759 | -// | |
1760 | -// Req.AutoClearSSLState := True; | |
1761 | -// | |
1762 | -// Req.InternetOpenParams.Agent := 'MantisBT Monitor'; | |
1763 | -// Req.InternetOpenParams.AccessType := INTERNET_OPEN_TYPE_PRECONFIG; | |
1764 | -// Req.InternetConnectParams.Service := INTERNET_SERVICE_HTTP; | |
1765 | -// Req.InternetConnectParams.Context := AHandle; | |
1766 | -// | |
1767 | -// Req.HttpOpenRequestParams.Verb := 'GET'; | |
1768 | -// Req.HttpOpenRequestParams.AcceptTypes := TStringList.Create; | |
1769 | -// try | |
1770 | -// Req.HttpOpenRequestParams.AcceptTypes.Add('*/*'); | |
1771 | -// Req.HttpOpenRequestParams.Context := AHandle; | |
1772 | -// Req.HttpOpenRequestParams.AutoDetectHTTPS := True; | |
1773 | -// Req.HttpOpenRequestParams.IgnoreInvalidCertificates := True; | |
1774 | -// Req.HttpSendRequestParams.IgnoreInvalidCertificateCA := True; | |
1775 | -// | |
1776 | -// Req.InternetConnectParams.ServerName := PChar(Configurations.MantisBTBaseUrl + '/mantis/config/TinyMCEInitializationCode.php'); | |
1777 | -// Res.Content := TStringStream.Create('',TEncoding.UTF8); | |
1778 | -// try | |
1779 | -// Request(Req,Res); | |
1780 | -// | |
1781 | -// Result := (Res.Content as TStringStream).DataString; | |
1782 | -// // O código do TinyMCE está ajustado para trabalhar dentro do Mantis e | |
1783 | -// // por isso usa caminhos relativos e absolutos de acordo com o servidor | |
1784 | -// // do Mantis. Precisamos, pois, usar caminhos absolutos sempre | |
1785 | -// Result := StringReplace(Result,'src="js/','src="' + Configurations.MantisBTBaseUrl + '/mantis/js/',[]); | |
1786 | -// | |
1787 | -// Result := StringReplace(Result,'https://desenvolvimento.tjpe.gov.br/mantis/js/tinymce/tinymce.min.js','https://cdn.tiny.cloud/1/f015pbciy4iq7tzpvossjylof3tpkcy89bmwcdkd321qfsj4/tinymce/5/tinymce.min.js',[]); | |
1788 | -// | |
1789 | -// | |
1790 | -// | |
1791 | -// finally | |
1792 | -// Res.Content.Free; | |
1793 | -// end; | |
1794 | -// finally | |
1795 | -// Req.HttpOpenRequestParams.AcceptTypes.Free; | |
1796 | -// end; | |
1797 | -// finally | |
1798 | -// Screen.Cursor := crDefault; | |
1799 | -// end; | |
1800 | -//end; | |
1801 | - | |
1802 | 1782 | end. |
@@ -373,7 +373,7 @@ | ||
373 | 373 | ShowInfoBalloon('Eu sou o ' + Application.Title + ' e irei monitorar as suas tarefas. Dentro de alguns segundos mostrarei suas atribuições. Aguarde...' |
374 | 374 | ,'Olá ' + Configurations.UserInfo.FirstName + '!'); |
375 | 375 | // teste |
376 | - //TFormIssue.ShowMe(65196); | |
376 | + TFormTask.ShowMe(83766); | |
377 | 377 | |
378 | 378 | StartTasksChecking(Configurations.NotificationTimeOut); |
379 | 379 | end; |
@@ -66,6 +66,7 @@ | ||
66 | 66 | private |
67 | 67 | { Private declarations } |
68 | 68 | FTask: TTask; |
69 | + procedure NewComment; | |
69 | 70 | public |
70 | 71 | { Public declarations } |
71 | 72 | procedure EditComment(ACommentId: Cardinal); |
@@ -132,7 +133,7 @@ | ||
132 | 133 | |
133 | 134 | procedure TDamoTask.ACTNNoteNewExecute(Sender: TObject); |
134 | 135 | begin |
135 | - TFormManageNote.ShowMeModal(TForm(Owner),FTask.Id,0); | |
136 | + NewComment; | |
136 | 137 | end; |
137 | 138 | |
138 | 139 | procedure TDamoTask.ACTNNoteReplyExecute(Sender: TObject); |
@@ -183,9 +184,19 @@ | ||
183 | 184 | end; |
184 | 185 | |
185 | 186 | procedure TDamoTask.EditComment(ACommentId: Cardinal); |
187 | +var | |
188 | + Comment: String; | |
186 | 189 | begin |
187 | - if TFormManageNote.ShowMeModal(TForm(Owner),FTask.Id,ACommentId) = mrOk then | |
188 | -// Refresh; | |
190 | + if TFormManageNote.ShowMeModal(TForm(Owner),FTask.Id,ACommentId,Comment) = mrOk then | |
191 | + Application.MessageBox('Código para salvar comentário editado','A fazer',MB_ICONINFORMATION); | |
189 | 192 | end; |
190 | 193 | |
194 | +procedure TDamoTask.NewComment; | |
195 | +var | |
196 | + Comment: String; | |
197 | +begin | |
198 | + if TFormManageNote.ShowMeModal(TForm(Owner),FTask.Id,0,Comment) = mrOk then | |
199 | + Application.MessageBox('Código para salvar novo comentário','A fazer',MB_ICONINFORMATION); | |
200 | +end; | |
201 | + | |
191 | 202 | end. |
@@ -11,18 +11,18 @@ | ||
11 | 11 | TFormManageNote = class(TFormBasicDialog) |
12 | 12 | EDBR: TEdgeBrowser; |
13 | 13 | procedure EDBRExecuteScript(Sender: TCustomEdgeBrowser; AResult: HRESULT; const AResultObjectAsJson: string); |
14 | + procedure EDBRCreateWebViewCompleted(Sender: TCustomEdgeBrowser; AResult: HRESULT); | |
15 | + procedure FormCreate(Sender: TObject); | |
16 | + procedure EDBRWebResourceRequested(Sender: TCustomEdgeBrowser; Args: TWebResourceRequestedEventArgs); | |
14 | 17 | procedure EDBRNavigationCompleted(Sender: TCustomEdgeBrowser; IsSuccess: Boolean; WebErrorStatus: TOleEnum); |
15 | - procedure FormShow(Sender: TObject); | |
16 | - procedure PNBBSaveClick(Sender: TObject); | |
17 | 18 | private |
18 | 19 | { Private declarations } |
19 | - FCommentId: Cardinal; | |
20 | 20 | FComment: String; |
21 | 21 | protected |
22 | 22 | procedure ValidateOk; override; |
23 | 23 | public |
24 | 24 | { Public declarations } |
25 | - class function ShowMeModal(AOwner: TComponent; ATaskNumber, ACommentId: Cardinal): TModalResult; reintroduce; | |
25 | + class function ShowMeModal(AOwner: TComponent; ATaskNumber, ACommentId: Cardinal; out AComment: String): TModalResult; reintroduce; | |
26 | 26 | end; |
27 | 27 | |
28 | 28 | implementation |
@@ -30,10 +30,22 @@ | ||
30 | 30 | {$R *.dfm} |
31 | 31 | |
32 | 32 | uses |
33 | - JSON, UFunctions, UScrapFunctions; | |
33 | + JSON, UFunctions, UScrapFunctions, KRK.Internet.WebView2, AxCtrls, EncdDecd; | |
34 | 34 | |
35 | 35 | { TFormManageNote } |
36 | 36 | |
37 | +procedure TFormManageNote.EDBRCreateWebViewCompleted(Sender: TCustomEdgeBrowser; AResult: HRESULT); | |
38 | +begin | |
39 | + inherited; | |
40 | + // Adiciona um filtro que, se satisfeito, executa o evento | |
41 | + // OnWebResourceRequested, no qual podemos alterar várias propriedades da | |
42 | + // requisição que está sendo feita, como o método (POST ou GET), cabeçalhos e | |
43 | + // conteúdo da requisição (requerido pelo método POST) | |
44 | +// EDBR.AddWebResourceRequestedFilter('*',COREWEBVIEW2_WEB_RESOURCE_CONTEXT_ALL); | |
45 | + | |
46 | + EDBR.Navigate('https://desenvolvimento.tjpe.gov.br/mantis/config/TinyMCEEditor.php'); | |
47 | +end; | |
48 | + | |
37 | 49 | procedure TFormManageNote.EDBRExecuteScript(Sender: TCustomEdgeBrowser; AResult: HRESULT; const AResultObjectAsJson: string); |
38 | 50 | begin |
39 | 51 | // A execução de scripts na página atual com ExecuteJavaScript retorna sempre |
@@ -45,7 +57,7 @@ | ||
45 | 57 | |
46 | 58 | if FunctionName = 'getComment' then |
47 | 59 | begin |
48 | - ShowMessage(GetValue<String>('result')); | |
60 | + FComment := GetValue<String>('result'); | |
49 | 61 | inherited ValidateOk; |
50 | 62 | end |
51 | 63 |
@@ -60,23 +72,102 @@ | ||
60 | 72 | EDBR.ExecuteScript('setComment("' + FComment + '")'); |
61 | 73 | end; |
62 | 74 | |
63 | -procedure TFormManageNote.FormShow(Sender: TObject); | |
75 | +//type | |
76 | +// TInterfaceStream = class(TMemoryStream) | |
77 | +// public | |
78 | +// procedure LoadFromIStream(Source: IStream); | |
79 | +// function GetIStream: IStream; | |
80 | +// end; | |
81 | +// | |
82 | +// | |
83 | +//Procedure TInterfaceStream.LoadFromIStream(Source : IStream); | |
84 | +//var | |
85 | +// Adapt : TOLEStream; | |
86 | +// Buff : Byte; | |
87 | +// I : Integer; | |
88 | +//begin | |
89 | +//ADapt := TOLEStream.Create(Source); | |
90 | +//Adapt.Position := 0; | |
91 | +//Self.Clear; | |
92 | +//Self.Position := 0; | |
93 | +//For I := 0 to Adapt.Size do | |
94 | +// begin | |
95 | +// Adapt.Read(Buff, 1); | |
96 | +// Self.Write(Buff, 1); | |
97 | +// end; | |
98 | +//Self.Position := 0; | |
99 | +//end; | |
100 | +// | |
101 | +//Function TInterfaceStream.GetIStream : IStream; | |
102 | +//var | |
103 | +// Adapt : TStreamAdapter; | |
104 | +// tPos : UInt64; | |
105 | +//begin | |
106 | +// Self.Position := 0; | |
107 | +// Adapt := TStreamAdapter.Create(Self); | |
108 | +//// Adapt.Seek(0, 0, tPos); | |
109 | +// Result := Adapt as IStream; | |
110 | +//end; | |
111 | + | |
112 | + | |
113 | +procedure TFormManageNote.EDBRWebResourceRequested(Sender: TCustomEdgeBrowser; Args: TWebResourceRequestedEventArgs); | |
114 | +//var | |
115 | +// r: ICoreWebView2WebResourceRequest; | |
116 | +// h: ICoreWebView2HttpRequestHeaders; | |
117 | +// S: TStringStream; | |
118 | +// i, j: IStream; | |
119 | +// x: Uint64; | |
120 | +// &IS: TInterfaceStream; | |
121 | +// u: Pchar; | |
64 | 122 | begin |
65 | - inherited; | |
66 | - EDBR.Navigate('http://desenvolvimento.tjpe.gov.br/mantis/config/TinyMCEEditor.php'); | |
123 | +// inherited; | |
124 | +// | |
125 | +// Args.ArgsInterface.Get_Request(r); | |
126 | +// r.Get_uri(u); | |
127 | +// if u = 'https://desenvolvimento.tjpe.gov.br/favicon.ico' then | |
128 | +// exit; | |
129 | +// | |
130 | +// r.Set_Method('POST'); | |
131 | +// | |
132 | +// var xx: String := EncodeString('comment=deucertoporrra!'); | |
133 | +// | |
134 | +// S := TStringStream.Create(xx); | |
135 | +// | |
136 | +// &IS := TInterfaceStream.Create; | |
137 | +// try | |
138 | +// &IS.CopyFrom(S,S.Size); | |
139 | +// | |
140 | +// i := &IS.GetIStream; | |
141 | +// i.SetSize(Length(xx)); | |
142 | +// r.Set_Content(i); | |
143 | +// | |
144 | +// | |
145 | +// r.Get_Headers(h); | |
146 | +// h.SetHeader('content-type','text/plain'{'application/x-www-form-urlencoded'}); | |
147 | +// h.SetHeader('content-length','23'); | |
148 | +// finally | |
149 | +// &IS.Free; | |
150 | +// end; | |
151 | + | |
67 | 152 | end; |
68 | 153 | |
69 | -procedure TFormManageNote.PNBBSaveClick(Sender: TObject); | |
154 | +procedure TFormManageNote.FormCreate(Sender: TObject); | |
70 | 155 | begin |
71 | -// inherited; | |
72 | - EDBR.ExecuteScript('setComment("' + FComment + '")'); | |
156 | + inherited; | |
157 | + // Cria a instância interna do WebView2 no TEdgeBrowser, permitindo que os | |
158 | + // métodos Navigate e NavigateToString sejam executados. O método Navigate já | |
159 | + // executa CreateWebView, mas o NavigateToString não. Mantive essa forma de | |
160 | + // utilização apenas para poder explicar isso. O Método CreateWebView dispara | |
161 | + // o evento OnCreateWebViewCompleted, no qual podemos seguramente executar | |
162 | + // Navigate ou NavigateToString | |
163 | + EDBR.CreateWebView; | |
73 | 164 | end; |
74 | 165 | |
75 | -class function TFormManageNote.ShowMeModal(AOwner: TComponent; ATaskNumber, ACommentId: Cardinal): TModalResult; | |
166 | +class function TFormManageNote.ShowMeModal(AOwner: TComponent; ATaskNumber, ACommentId: Cardinal; out AComment: String): TModalResult; | |
76 | 167 | begin |
77 | 168 | with Self.Create(AOwner) do |
78 | 169 | begin |
79 | - FCommentId := ACommentId; | |
170 | + AComment := ''; | |
80 | 171 | FComment := ''; |
81 | 172 | |
82 | 173 | AutoCaption := False; |
@@ -84,11 +175,11 @@ | ||
84 | 175 | Caption := 'Gerenciador de anotações - ' + Application.Title; |
85 | 176 | |
86 | 177 | if ACommentId > 0 then |
87 | - LABECaption.Caption := 'Editando a anotação #' + IntToStr(FCommentId) | |
178 | + LABECaption.Caption := 'Editando a anotação #' + IntToStr(ACommentId) | |
88 | 179 | else |
89 | 180 | LABECaption.Caption := 'Redigindo uma nova anotação para a tarefa #' + IntToStr(ATaskNumber); |
90 | 181 | |
91 | - if (ACommentId > 0) and not GetCommentForEdition(Handle,FCommentId,FComment) then | |
182 | + if (ACommentId > 0) and not GetCommentForEdition(Handle,ACommentId,FComment) then | |
92 | 183 | begin |
93 | 184 | Application.MessageBox('Não foi possível obter o comentário para edição. Por favor, tente novamente!','Erro ao obter o comentário',MB_ICONERROR); |
94 | 185 | Result := mrAbort; |
@@ -95,9 +186,12 @@ | ||
95 | 186 | end |
96 | 187 | else |
97 | 188 | begin |
98 | - FComment := StringReplace(FComment,#13#10,'<br>',[rfReplaceAll]); | |
99 | - FComment := StringReplace(FComment,'"','\"',[rfReplaceAll]); | |
189 | + // Caso se consiga usar o TEdgeBrowser com Post, a função abaixo não mais | |
190 | + // será necessária, porque FComment não precisará ser manipulado via | |
191 | + // JavaScript | |
192 | + FComment := PrepareCommentForEdition(FComment); | |
100 | 193 | Result := ShowModal; |
194 | + AComment := FComment; | |
101 | 195 | end; |
102 | 196 | end; |
103 | 197 | end; |