Resource

Resource Basics

Resource Name Functional Rating Bar
Resource Version 1.0
Category Custom Thumbnail Info
Downloads 1051
Release Date 3/14/2018 11:45:08 AM
 

Resource Details

Description This custom thumb info line gives you a fully functional rating bar.
Installation Instructions 1. Store the script on the local hard drive
2. Open the script in a text editor
3. Copy/Paste the content of the script to a custom thumb info line
Usage Instructions see installation instructions
Changes in this version na
Special Requirements
 

Author Information

Author Name IDimager Support
 

Available Attachments

Attachment #1 FunctionalRatingBar.png
 

Script

%code
    var
      ACatItem: TCatalogItem;
      ARatingAnchorHref: String;
      ARatingNoColor: String;
      ARatingColor: String;
      ARatingStar: String;
      ARatingOnStar: String;
      ARatingOffStar: String;
      i: Integer;
    begin
      result := '';

      ARatingNoColor := '#CFFF0000'; //#### red color 
      ARatingColor   := '#CFFFFF00'; //#### Yellow color for rating stars
      ARatingStar    := 'M 3.03,4.19883 L 2.996,4.22354 L 3.00909,4.26369 L 2.97501,4.2389 L 2.94086,4.26369 L 2.95394,4.22354 L 2.92,4.19883 L 2.96193,4.19883 L 2.97501,4.1589 L 2.98801,4.19883 L 3.03,4.19883 Z ';
      ARatingReject  := 'M 307.583,420.723 C 307.583,425.969 303.331,430.223 298.083,430.223 ' +
                        'C 292.837,430.223 288.583,425.969 288.583,420.723 C 288.583,415.477 ' +
                        '292.837,411.223 298.083,411.223 C 303.331,411.223 307.583,415.477 ' +
                        '307.583,420.723 Z M 302.900,417.541 L 301.486,416.127 L 298.304,419.309 ' +
                        'L 295.121,416.127 L 293.707,417.541 L 296.890,420.724 L 293.707,423.906 ' +
                        'L 295.121,425.320 L 298.303,422.138 L 301.485,425.320 L 302.900,423.906 ' +
                        'L 299.718,420.723 L 302.900,417.541 Z';

      ARatingAnchorHref := 'code:' +
'  function IsImageItemSelected: Boolean; ' +
'  var ' +
'    i: Integer; ' +
'  begin ' +
'    result := False; ' +
'    for i := 0 to Selected.Count - 1 do ' + 
'    begin ' +
'       if Selected.Items[i].GUID = ImageItem.GUID then ' +
'       begin ' +
'         result := True; ' +
'         exit; ' +
'       end; ' +
'     end; ' +
'  end; ' +
'var ' +
'  i: Integer; ' +
'  ACatItem: TCatalogItem; ' +
'begin ' +
'  if not IsImageItemSelected then ' +
'  begin ' +
'    Selected.Clear; ' +
'    Selected.Add(ImageItem); ' +
'  end; ' +
'' +
'  for i := 0 to Selected.Count - 1 do ' +
'  begin ' +
'     ACatItem := TCatalogItem.Create(nil); ' +
'     if PublicCatalog.FindItemCombinedByGUID(Selected.Items[i].GUID, ACatItem) then ' +
'     begin ' +
'       ACatItem.Rating := #rating#; ' +
'       if PublicCatalog.StoreItemToDataBase(ACatItem, False) then ' +
'         PublicCatalog.UpdateItemSyncState(ACatItem, [], [idcsDBXmp], False, True); ' +
'     end; ' +
'     ACatItem.Free; ' +
'  end; ' +
'end; ' +
'';

      ARatingNoOnStar      := '<a href="' + ARatingAnchorHref + '"><img title="no rating" size="18" path="' + ARatingStar + '" pathfillcolor="' + ARatingNoColor + '" pathstrokestyle="solid" pathstrokecolor="' + ARatingNoColor + '"></a>';
      ARatingNoOffStar     := '<a href="' + ARatingAnchorHref + '"><img size="18" path="' + ARatingStar + '" pathfillstyle="none" pathstrokestyle="solid" pathstrokecolor="' + ARatingNoColor  + '"></a>';
      ARatingOnStar        := '<a href="' + ARatingAnchorHref + '"><img size="18" path="' + ARatingStar + '" pathfillcolor="' + ARatingColor + '" pathstrokestyle="solid" pathstrokecolor="' + ARatingColor + '"></a>';
      ARatingOffStar       := '<a href="' + ARatingAnchorHref + '"><img size="18" path="' + ARatingStar + '" pathfillstyle="none" pathstrokestyle="solid" pathstrokecolor="' + ARatingColor + '"></a>';
      ARatingRejectOnStar  := '<a href="' + ARatingAnchorHref + '"><img title="reject"   size="18" path="' + ARatingReject + '" pathfillstyle="solid" pathstrokestyle="solid" pathstrokecolor="' + '#CCCCCCCC' + '"></a>';
      ARatingRejectOffStar := '<a href="' + ARatingAnchorHref + '"><img title="unreject" size="18" path="' + ARatingReject + '" pathfillstyle="none" pathfillcolor="' + ARatingColor + '" pathstrokestyle="solid" pathstrokecolor="' + ARatingColor + '"></a>';

      ACatItem := TCatalogItem.Create(nil);
      if PublicCatalog.FindImageCombined (ImageItem, ACatItem, False, vptNone) then
      begin
        result := result + '<font color="'+ ARatingColor +'"><ind y="2">';

        {
        if ACatItem.Rating > 0 then
          result := result + StrTran(ARatingNoOnStar, '#rating#', '0')
        else
          result := result + StrTran(ARatingNoOffStar, '#rating#', '0');
        }

        if ACatItem.Rating = -1 then
          result := result + StrTran(ARatingRejectOnStar, '#rating#', '0')
        else
          result := result + StrTran(ARatingRejectOffStar, '#rating#', '-1');

        for i := 1 to ACatItem.Rating do
          result := result + StrTran(ARatingOnStar, '#rating#', iif(ACatItem.Rating = i, '0', IntToStr(i)));
        for i := Max(ACatItem.Rating, 0) + 1 to 5 do
          result := result + StrTran(iif(ACatItem.Rating = -1, ARatingRejectOffStar, ARatingOffStar), '#rating#', IntToStr(i));
        result := result + '</ind></font>';
      end;
      ACatItem.Free;
    end;
    %/code