Changeset 877 for cprs/branches/tmg-cprs/CPRS-Chart/fImages.pas
- Timestamp:
- Jul 15, 2010, 8:02:17 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cprs/branches/tmg-cprs/CPRS-Chart/fImages.pas
r809 r877 12 12 13 13 type 14 TImgDelMode = (idmNone,idmDelete,idmRetract); //NOTE: DO NOT change order 14 15 TImageInfo = class 15 16 private … … 81 82 PickScanFolder: TMenuItem; 82 83 OpenDialog: TOpenDialog; 84 mnuPopup: TPopupMenu; 85 mnuPopDeleteImage: TMenuItem; 86 mnuDeleteImage: TMenuItem; 83 87 procedure mnuChartTabClick(Sender: TObject); 84 88 procedure mnuActNewClick(Sender: TObject); … … 96 100 procedure EnableAutoScanUploadClick(Sender: TObject); 97 101 procedure PickScanFolderClick(Sender: TObject); 102 procedure TabControlMouseUp(Sender: TObject; Button: TMouseButton; 103 Shift: TShiftState; X, Y: Integer); 104 procedure mnuPopupPopup(Sender: TObject); 105 procedure mnuPopDeleteImageClick(Sender: TObject); 106 procedure mnuDeleteImageClick(Sender: TObject); 98 107 private 99 108 ImageInfoList : TList; 100 109 LastDisplayedTIUIEN : AnsiString; 101 110 ImageIndexLastDownloaded : integer; 111 FDeleteImageIndex : integer; 112 FEditIsActive : boolean; 113 FImageDeleteMode : TImgDelMode; 102 114 procedure EnsureImageListLoaded(); 103 115 procedure ClearImageList(); … … 112 124 function GetImageInfo(Index : integer) : TImageInfo; 113 125 procedure SetupTimer; 126 function CanDeleteImages : boolean; 127 procedure DeleteImageIndex(ImageIndex : integer; DeleteMode : TImgDelMode; boolPromptUser: boolean); 128 procedure DeleteImage(var DeleteSts: TActionRec; ImageFileName: string; ImageIEN, DocIEN: Integer; 129 DeleteMode : TImgDelMode; const Reason: string); 114 130 public 115 131 CacheDir : AnsiString; … … 134 150 procedure EnsureImagesDownloaded(ImagesList : TStringList); 135 151 procedure EnsureALLImagesDownloaded; 152 procedure DeleteAll(DeleteMode: TImgDelMode); 136 153 property ImagesCount : integer read GetImagesCount; 137 154 property ImageInfo[index : integer] : TImageInfo read GetImageInfo; … … 169 186 FIconLegend, fPCEEdit, fNoteIDParents, rSurgery, uSurgery, uTemplates, 170 187 uAccessibleTreeView, uAccessibleTreeNode, fTemplateDialog, DateUtils, 171 StrUtils {//KT added 1-1-05}, 172 mshtml, {//kt added 5-2-05} 173 UploadImages, {//kt added 9/25/05} 174 //ImageTransferForm, {//kt 10-1-05} 188 StrUtils, mshtml, UploadImages, 175 189 uTMGOptions, //kt 3/10/10 176 rHTMLTools, fNotes, frmImageTransferProgress; {//kt added 5-27-05 for IsHTMLDocument} 190 rHTMLTools, fNotes, frmImageTransferProgress, fImagePickExisting; {//kt added 5-27-05 for IsHTMLDocument} 191 192 193 procedure TfrmImages.FormCreate(Sender: TObject); 194 //var i : integer; 195 begin 196 inherited; 197 LastDisplayedTIUIEN := '0'; 198 FDeleteImageIndex := -1; 199 ImageInfoList := TList.Create; 200 ClearImageList(); //sets up other needed variables. 201 DownloadImagesInBackground := true; 202 CacheDir := ExtractFilePath(ParamStr(0))+ 'Cache'; 203 NullImageName := 'about:blank'; 204 if not DirectoryExists(CacheDir) then ForceDirectories(CacheDir); 205 206 TransferMethod := TImgTransferMethod(uTMGOptions.ReadInteger('ImageTransferMethod',2)); 207 DropBoxDir := uTMGOptions.ReadString('Dropbox directory','??'); 208 if DropBoxDir='??' then begin //just on first run. 209 uTMGOptions.WriteBool('Use dropbox directory for transfers',false); 210 uTMGOptions.WriteString('Dropbox directory',''); 211 end; 212 AutoScanUpload.Checked := uTMGOptions.ReadBool('Scan Enabled',false); 213 end; 214 215 procedure TfrmImages.FormDestroy(Sender: TObject); 216 begin 217 inherited; 218 ClearImageList; 219 ImageInfoList.Free; 220 EmptyCache; 221 end; 222 223 procedure TfrmImages.FormShow(Sender: TObject); 224 var TIUIEN : AnsiString; 225 begin 226 inherited; 227 mnuDeleteImage.Enabled := CanDeleteImages; 228 TIUIEN := IntToStr(frmNotes.lstNotes.ItemID); 229 DownloadImagesInBackground := false; 230 SetupTimer; 231 if LastDisplayedTIUIEN <> TIUIEN then begin 232 UpdateNoteInfoMemo(); 233 LastDisplayedTIUIEN := TIUIEN; 234 end; 235 end; 177 236 178 237 … … 266 325 begin 267 326 inherited; 268 end;269 270 procedure TfrmImages.FormCreate(Sender: TObject);271 //var i : integer;272 begin273 inherited;274 LastDisplayedTIUIEN := '0';275 ImageInfoList := TList.Create;276 ClearImageList(); //sets up other needed variables.277 DownloadImagesInBackground := true;278 CacheDir := ExtractFilePath(ParamStr(0))+ 'Cache';279 //NullImageName := ExtractFilePath(ParamStr(0)) + 'images\blank.htm';280 NullImageName := 'about:blank';281 if not DirectoryExists(CacheDir) then ForceDirectories(CacheDir);282 283 TransferMethod := TImgTransferMethod(uTMGOptions.ReadInteger('ImageTransferMethod',2));284 {if uTMGOptions.ReadInteger('ImageTransferMethod',0) = 0 then begin285 UseDropBox := True;286 end else begin287 UseDropBox := False;288 end;}289 DropBoxDir := uTMGOptions.ReadString('Dropbox directory','??');290 if DropBoxDir='??' then begin //just on first run.291 uTMGOptions.WriteBool('Use dropbox directory for transfers',false);292 uTMGOptions.WriteString('Dropbox directory','');293 end;294 AutoScanUpload.Checked := uTMGOptions.ReadBool('Scan Enabled',false);295 end;296 297 procedure TfrmImages.FormDestroy(Sender: TObject);298 begin299 inherited;300 ClearImageList;301 ImageInfoList.Free;302 EmptyCache;303 end;304 305 procedure TfrmImages.FormShow(Sender: TObject);306 var TIUIEN : AnsiString;307 begin308 inherited;309 TIUIEN := IntToStr(frmNotes.lstNotes.ItemID);310 DownloadImagesInBackground := false;311 SetupTimer;312 if LastDisplayedTIUIEN <> TIUIEN then begin313 UpdateNoteInfoMemo();314 LastDisplayedTIUIEN := TIUIEN;315 end;316 327 end; 317 328 … … 475 486 procedure TfrmImages.ClearImageList(); 476 487 //Note: !! This should also clear any visible images/thumbnails etc. 488 //Note: Need to remove thumbnail image from image list. 477 489 var i : integer; 478 490 begin … … 637 649 end; 638 650 639 // CallV('TMG UPLOAD FILE DROPBOX', ...); 651 CallV('TMG UPLOAD FILE DROPBOX', [FPath,FName]); //Move file into dropbox. 652 { 640 653 RPCBrokerV.ClearParameters := true; 641 654 RPCBrokerV.remoteprocedure := 'TMG UPLOAD FILE DROPBOX'; … … 647 660 RPCBrokerV.Param[2].Value := '1'; //see comments in UploadFile re '1' hardcoding 648 661 649 //RPCBrokerV.Call;//Move file into dropbox.650 CallBroker;662 CallBroker; //Move file into dropbox. 663 } 651 664 if RPCBrokerV.Results.Count>0 then begin 652 665 Result := (Piece(RPCBrokerV.Results[0],'^',1)='1'); //1=success, 0=failure … … 700 713 Application.ProcessMessages; 701 714 715 RPCBrokerV.remoteprocedure := 'TMG UPLOAD FILE'; 702 716 RPCBrokerV.ClearParameters := true; 703 717 RPCBrokerV.Param[0].PType := literal; … … 706 720 RPCBrokerV.Param[1].Value := FName; 707 721 RPCBrokerV.Param[2].PType := literal; 708 RPCBrokerV.Param[2].Value := '1'; 709 //Note: the '1' in the line above is hard-coding in to use 710 //IEN=1 in file 2005.2 (NETWORK LOCATION). This file will 711 //instruct the server which relative path to store the file into 712 //If I want to have more than one NETWORK LOCATION, then I would 713 //need to create another RPC call that would determine which IEN 714 //to use. 715 //(This would be the same as the IEN stored in fields# 2, 2.1, 2.2 716 // of file 2005 (IMAGE). This in turn is originally obtained from 717 //file IMAGING SITE PARAMETERS 722 RPCBrokerV.Param[2].Value := ''; //kt 7/11/10 723 //RPCBrokerV.Param[2].Value := '1'; //Specifying a NETWORK LOCATION is now depreciated. 718 724 719 725 RPCBrokerV.Param[3].PType := list; 720 721 726 ParamIndex := 0; 722 727 RefreshCountdown := RefreshInterval; … … 738 743 RefreshCountdown := RefreshInterval; 739 744 end; 740 741 745 end; 742 746 until (ReadCount < BlockSize); 743 744 RPCBrokerV.remoteprocedure := 'TMG UPLOAD FILE';745 747 746 748 SavedCursor := Screen.Cursor; … … 750 752 751 753 CallBroker; 754 752 755 Screen.Cursor := SavedCursor; 753 756 if RPCBrokerV.Results.Count > 0 then begin … … 772 775 ErrMsg : string; 773 776 begin 774 // CallV('TMG DOWNLOAD FILE DROPBOX', ...);775 777 CallV('TMG DOWNLOAD FILE DROPBOX', [FPath,FName]); //Move file into dropbox. 778 {RPCBrokerV.ClearParameters := true; 776 779 RPCBrokerV.remoteprocedure := 'TMG DOWNLOAD FILE DROPBOX'; 777 780 RPCBrokerV.param[0].PType := literal; … … 781 784 RPCBrokerV.Param[2].PType := literal; 782 785 RPCBrokerV.Param[2].Value := '1'; //see comments in UploadFile re '1' hardcoding 783 784 //RPCBrokerV.Call; //Move file into dropbox. 785 CallBroker; 786 CallBroker; } 786 787 if RPCBrokerV.Results.Count > 0 then begin 787 788 Result := (Piece(RPCBrokerV.Results[0],'^',1)='1'); //1=success, 0=failure … … 835 836 DeleteFile(LocalSaveFNamePath); 836 837 end; 837 //if UseDropBox then begin838 838 if TransferMethod = itmDropbox then begin 839 839 Result := DownloadFileViaDropBox(FPath,FName,LocalSaveFNamePath,CurrentImage,TotalImages); … … 843 843 Result := true; //default to success; 844 844 StatusText('Retrieving full image...'); 845 //Note: the '1' in the line below is hard-coding in to use 846 //IEN=1 in file 2005.2 (NETWORK LOCATION). This file will 847 //instruct the server which relative path to store the file into 848 //If I want to have more than one NETWORK LOCATION, then I would 849 //need to create another RPC call that would determine which IEN 850 //to use. 851 //(This would be the same as the IEN stored in fields# 2, 2.1, 2.2 852 // of file 2005 (IMAGE). This in turn is originally obtained from 853 //file IMAGING SITE PARAMETERS 854 CallV('TMG DOWNLOAD FILE', [FPath,FName,'1']); 845 //kt CallV('TMG DOWNLOAD FILE', [FPath,FName,'1']); //kt 7/10/10 Specifying a NETWORK LOCATION is depreciated. 846 CallV('TMG DOWNLOAD FILE', [FPath,FName]); 855 847 Application.ProcessMessages; 856 848 RefreshCountdown := RefreshInterval; … … 965 957 966 958 var 967 //Result : AnsiString; // 968 i : integer; 969 PlainTrio : longword; //RGZ3 970 j : integer; 959 //Result : AnsiString; //RGZ1 //'Result' is implicitly declared by Pascal 960 i : integer; //RGZ2 961 PlainTrio : longword; //RGZ3 //unsigned 32-bit 962 j : integer; //RGZ4 971 963 EncodedChar : char; 972 964 PlainInt : integer; … … 1027 1019 //If user selects images tab, then load will occur without delay. 1028 1020 //Note: OnTimer calls timLoadImagesTimer() 1021 FEditIsActive := EditIsActive; 1029 1022 UploadImagesButton.Enabled := EditIsActive; 1030 1023 UploadImagesMnuAction.Enabled := EditIsActive; … … 1347 1340 1348 1341 1342 procedure TfrmImages.TabControlMouseUp(Sender: TObject; Button: TMouseButton; 1343 Shift: TShiftState; X, Y: Integer); 1344 //kt add 7/6/10 1345 var TabIndex : integer; 1346 P : TPoint; 1347 begin 1348 inherited; 1349 if Button <> mbRight then exit; 1350 TabIndex := TabControl.IndexOfTabAt(X,Y); 1351 if TabIndex < 0 then exit; 1352 FDeleteImageIndex := TabIndex; 1353 P.X := X; P.Y := Y; 1354 P := TabControl.ClientToScreen(P); 1355 TabControl.PopupMenu := mnuPopup; 1356 mnuPopup.Popup(P.X, P.Y); 1357 TabControl.PopupMenu := nil; 1358 end; 1359 1360 procedure TfrmImages.mnuPopupPopup(Sender: TObject); 1361 //Determine here if delete option should be enabled. 1362 begin 1363 inherited; 1364 mnuPopDeleteImage.Enabled := CanDeleteImages; 1365 end; 1366 1367 function TfrmImages.CanDeleteImages : boolean; 1368 //Determine here if image can be deleted. 1369 var 1370 ActionSts: TActionRec; 1371 const 1372 ATTACHED_IMAGES_SERVER_REPLY = 'You must "delete" the Images using the Imaging package before proceeding.'; 1373 begin 1374 FImageDeleteMode := idmNone; 1375 Result := false; //default action 1376 if FEditIsActive then begin 1377 Result := true; 1378 FImageDeleteMode := idmDelete; 1379 exit; 1380 end; 1381 //Will use same user class managment rules for images as for notes. 1382 //So if user can delete a note, then they can also delete images. 1383 ActOnDocument(ActionSts, frmNotes.lstNotes.ItemIEN, 'DELETE RECORD'); 1384 if (ActionSts.Success = false) then begin 1385 if Pos(ATTACHED_IMAGES_SERVER_REPLY, ActionSts.Reason) > 0 then ActionSts.Success := true; 1386 end; 1387 Result := ActionSts.Success; 1388 if Result then begin 1389 if AuthorSignedDocument(frmNotes.lstNotes.ItemIEN) then FImageDeleteMode := idmRetract 1390 else FImageDeleteMode := idmDelete; 1391 end; 1392 end; 1393 1394 procedure TfrmImages.mnuPopDeleteImageClick(Sender: TObject); 1395 begin 1396 inherited; 1397 DeleteImageIndex(FDeleteImageIndex, FImageDeleteMode, True); 1398 end; 1399 1400 procedure TfrmImages.DeleteAll(DeleteMode: TImgDelMode); 1401 begin 1402 EnsureALLImagesDownloaded; 1403 while TabControl.Tabs.Count > 0 do begin 1404 DeleteImageIndex(0,DeleteMode,False); 1405 NewNoteSelected(False); 1406 EnsureALLImagesDownloaded; 1407 frmImages.Formshow(self); 1408 end; 1409 end; 1410 1411 1412 procedure TfrmImages.DeleteImageIndex(ImageIndex : integer; DeleteMode : TImgDelMode; boolPromptUser: boolean); 1413 //Note: permissions must be checked before running this function 1414 var 1415 ImageInfo : TImageInfo; 1416 ReasonForDelete : string; 1417 DeleteSts : TActionRec; 1418 1419 CONST 1420 TMG_PRIVACY = 'FOR PRIVACY'; //Server message (don't translate) 1421 TMG_ADMIN = 'ADMINISTRATIVE'; //Server message (don't translate) 1422 1423 begin 1424 if (ImageIndex<0) or (ImageIndex>=ImagesCount) then begin 1425 MessageDlg('Invalid image index to delete: '+IntToStr(ImageIndex), mtError,[mbOK],0); 1426 exit; 1427 end; 1428 ImageInfo := Self.ImageInfo[ImageIndex]; 1429 if boolPromptUser then begin 1430 ReasonForDelete := SelectDeleteReason(frmNotes.lstNotes.ItemIEN); 1431 if ReasonForDelete = DR_CANCEL then Exit; 1432 if ReasonForDelete = DR_PRIVACY then begin 1433 ReasonForDelete := TMG_PRIVACY; 1434 end else if ReasonForDelete = DR_ADMIN then begin 1435 ReasonForDelete := TMG_ADMIN; 1436 end; 1437 end else begin 1438 ReasonForDelete := 'DeleteAll'; 1439 end; 1440 1441 DeleteImage(DeleteSts, ImageInfo.ServerFName, ImageInfo.IEN, frmNotes.lstNotes.ItemIEN, DeleteMode, ReasonForDelete); 1442 end; 1443 1444 procedure TfrmImages.DeleteImage(var DeleteSts: TActionRec; 1445 ImageFileName: String; 1446 ImageIEN, DocIEN: Integer; 1447 DeleteMode : TImgDelMode; 1448 const Reason: string); //Reason should be 10-60 chars; 1449 1450 function ServerImageDelete(ImageIEN:integer; DeleteMode:tImgDelMode; Reason:String) : boolean; 1451 //Returns success 1452 var RPCResult,IEN,Mode : string; 1453 begin 1454 IEN := IntToStr(ImageIEN); 1455 Mode := IntToStr(Ord(DeleteMode)); 1456 RPCResult := sCallV('TMG IMAGE DELETE', [IEN,Mode,Reason]); 1457 Result := Piece(RPCResult,'^',1)= '1'; 1458 if Result = false then begin 1459 MessageDlg(Piece(RPCResult,'^',2),mtError,[mbOK],0); 1460 end; 1461 end; 1462 1463 procedure NoteImageDelete(DocIEN:integer; FileName: string; DeleteMode:tImgDelMode; Reason:String); 1464 var 1465 NoteText, tempString: string; 1466 Beginning, Ending: integer; 1467 boolFound: boolean; 1468 // <!-- Retracted By: UserName on Date ...;.. --> 1469 // FEditIsActive 1470 begin 1471 if FEditIsActive then begin 1472 Ending := 1; 1473 Beginning := 1; 1474 boolFound := False; 1475 While (boolFound = False) AND (Beginning > 0) Do Begin 1476 NoteText := frmNotes.HtmlEditor.HTMLText; 1477 Beginning := PosEx('<IMG',NoteText, Ending); 1478 Ending := PosEx('>', NoteText, Beginning) + 1; 1479 tempString := MidStr(NoteText, Beginning, Ending-Beginning); 1480 if pos(FileName,tempString) > 0 then boolFound := True; 1481 end; 1482 if boolFound = false then begin 1483 Ending := 1; 1484 Beginning := 1; 1485 boolFound := False; 1486 While (boolFound = False) AND (Beginning > 0) Do Begin 1487 NoteText := frmNotes.HtmlEditor.HTMLText; 1488 Beginning := PosEx('<embed',NoteText, Ending); 1489 Ending := PosEx('>', NoteText, Beginning) + 1; 1490 tempString := MidStr(NoteText, Beginning, Ending-Beginning); 1491 if pos(FileName,tempString) > 0 then boolFound := True; 1492 end; 1493 end; 1494 if boolFound = False then exit; 1495 if DeleteMode = idmDelete then begin 1496 frmnotes.HtmlEditor.HTMLText := AnsiReplaceStr(frmNotes.HtmlEditor.HTMLText, tempString, ''); 1497 end else if DeleteMode = idmRetract then begin 1498 frmnotes.HtmlEditor.HTMLText := AnsiReplaceStr(frmNotes.HtmlEditor.HTMLText, tempString, ' <!-- ' + tempString + ' Retracted By: ' + User.Name + ' on ' + DateToStr(Now)); 1499 end; 1500 //ClearImageList; 1501 //EmptyCache; 1502 //frmImages.FormHide(self); 1503 //LastDisplayedTIUIEN := '0'; 1504 //frmImages.Formshow(self); 1505 NewNoteSelected(True); 1506 frmImages.Formshow(self); 1507 end else begin 1508 //NewNoteSelected(True); 1509 //frmImages.Formshow(self); 1510 end; 1511 end; 1512 1513 begin 1514 //'Permanently delete attached image or file?' 1515 //Create dialog that gives option to export before deleting? 1516 //"You are about to permanently delete this image. Would you like to export before deletion? Yes/No/Cancel 1517 //Yes = export dialog then delete (if export is later cancelled assume cancel was pressed here), No=Only Delete, Cancel = No deletion 1518 if Reason <> 'DeleteAll' then begin 1519 if MessageDlg(DKLangConstW('fImages_ConfirmDelete'),mtConfirmation,mbOKCancel,0) <> mrOK then exit; 1520 end; 1521 if ServerImageDelete(ImageIEN,DeleteMode,Reason) = false then exit; 1522 NoteImageDelete(DocIEN,ImageFileName,DeleteMode,Reason); 1523 if DeleteMode = idmRetract then begin 1524 InfoBox(DKLangConstW('fImages_Retract_1')+CRLF + // 'This image or file will now be RETRACTED. As such, it has been' 1525 DKLangConstW('fImages_Retract_2')+CRLF + // 'removed from public view, and from typical Releases of Information,' 1526 DKLangConstW('fImages_Retract_2'), // ' but will remain indefinitely discoverable to HIMS.' +CRLF +CRLF; 1527 DKLangConstW('fImages_Retraction_Notice'),MB_OK); 1528 end; 1529 end; 1530 1531 1532 procedure TfrmImages.mnuDeleteImageClick(Sender: TObject); 1533 var 1534 SelectedImageTab,i : integer; 1535 ImageInfo : TImageInfo; 1536 begin 1537 inherited; 1538 If TabControl.Tabs.Count < 1 then exit; 1539 frmImagePickExisting := TfrmImagePickExisting.Create(Self); 1540 if frmImagePickExisting.ShowModal = mrOK then begin 1541 //ImageFName := frmImagePickExisting.SelectedImageFName; 1542 if not assigned(frmImagePickExisting.SelectedImageInfo) then exit; 1543 for i := 0 to TabControl.Tabs.Count - 1 do begin 1544 ImageInfo := Self.ImageInfo[i]; 1545 if frmImagePickExisting.SelectedImageInfo.ServerFName = ImageInfo.ServerFName then begin 1546 SelectedImageTab := i; 1547 end; 1548 end; 1549 if frmNotes.HTMLEditor.Active then begin 1550 FEditIsActive := true; 1551 DeleteImageIndex(SelectedImageTab,idmDelete,True); 1552 end else begin 1553 FEditIsActive := false; 1554 DeleteImageIndex(SelectedImageTab,idmRetract,True); 1555 end; 1556 NewNoteSelected(False); 1557 EnsureALLImagesDownloaded; 1558 frmImages.Formshow(self); 1559 end; 1560 FreeAndNil(frmImagePickExisting); 1561 end; 1562 1349 1563 initialization 1350 1564 //put init code here
Note:
See TracChangeset
for help on using the changeset viewer.