Jump to content

About Listview ?


Luciano França

Recommended Posts

  • 2 weeks later...
  • 3 weeks later...

1. uses

    uniGUIJSUtils, System.JSON

2. 

procedure TMainForm.UniFormCreate(Sender: TObject);
begin
  with UniPanel1, UniPanel1.JSInterface do
  begin
    AutoScroll := True;
    Caption := '';

    JSInterface.JSConfigObject(
      'items',
      [
        'xtype','dataview',
        'reference', 'dataview',
        'loadMask', True,
        'plugins', JSObject(['ux-animated-dataview', True]),
        'itemSelector', 'div.dataview-multisort-item',
        'tpl',
        '<tpl for=".">'+
        '<div style="float:left;padding: 8px;margin: 8px 8px 4px 8px;" class="dataview-multisort-item">'+
        '<img id="{name}" class="_img" height="60" width="auto" src="{thumb}" oncontextmenu="document.getElementById(event.target.id).click(); return false"/>'+
        '<h3>{name}</h3>'+
        '</div>'+
        '</tpl>',

        'emptyText', '<span style="color: black; font-size: 14px;">There are no records to display',

        'allowDeselect', True,

        'listeners', JSObject([
            'select', JSFunction('sender, selected, eOpts', 'ajaxRequest('+ JSName +', "selected", {filename: selected.data.name, fileurl: selected.data.thumb})'),
            'deselect', JSFunction('sender, records, eOpts', 'ajaxRequest('+ JSName +', "deselected", {})')
        ]),

        'store', JSObject([
            'pageSize', 0,
            'limit', 0,
            'autoLoad', True,
            'sortOnLoad', True,
            'fields', JSArray(['name', 'thumb', 'url', 'type']),
            'proxy', JSObject([
                'type', 'ajax',
                'url', JSStatement(GetDataEventUrl(JSControl)),
                'reader', JSObject([
                    'type', 'json',
                    'rootProperty', ''
                ])
            ])
        ])
      ])
  end;
end;

 

  • Like 1
Link to comment
Share on other sites

3. 

procedure TMainForm.UniPanel1AjaxEvent(Sender: TComponent; EventName: string;
  Params: TUniStrings);
begin
  if EventName = 'data' then
  begin
    UniSession.SendResponse(LoadImagesToJson('images'))
  end
  else if EventName = 'selected' then
  begin
    (Sender as TUniPanel).Title := Params.Values['filename'] +  ' selected';
    UniImage1.Url := Params.Values['fileurl']
  end
  else if EventName = 'deselected' then
  begin
    (Sender as TUniPanel).Title := 'Not selected...';
    UniImage1.Url := ''
  end;

end;

4.

initialization
  UniAddJSLibrary('build/packages/ux/classic/ux.js', False, [upoFolderJS, upoPlatformDesktop]);

 

  • Like 1
Link to comment
Share on other sites

5.

function TMainForm.LoadImagesToJson(APath: string): string;
var
  ja: TJSONArray;
  jo: TJSONObject;

  procedure ProcessFileType(AJsonArray: TJSONArray; AFileMask: String);
  var
    _sr: TSearchRec;
    jo_file: TJSONObject;
    userImageFolder: String;
  begin
    userImageFolder := '.\files\' + APath + '\';
    if FindFirst(userImageFolder + AFileMask, faAnyFile, _sr) =0 then
    begin
      repeat
        jo_file := TJSONObject.Create;
        jo_file.AddPair('name', _sr.Name);
        jo_file.AddPair('thumb', 'files/'+APath+'/'+_sr.Name);
        jo_file.AddPair('url', ReplaceStr(userImageFolder, '\', '/') + _sr.Name);
        AJsonArray.Add(jo_file);
      until FindNext(_sr) <> 0;

      FindClose(_sr);
    end;
  end;

begin
  ja := TJSONArray.Create;

  ProcessFileType(ja, '*.gif');
  ProcessFileType(ja, '*.jpg');
  ProcessFileType(ja, '*.jpeg');
  ProcessFileType(ja, '*.png');
  ProcessFileType(ja, '*.svg');

  if ja.Size > 0  then
  begin
    Result := ja.ToString;
    ja.Free;
  end
  else
    Result := '""';
end;

 

  • Like 2
Link to comment
Share on other sites

On 2/10/2023 at 2:36 AM, Sherzod said:

5.

function TMainForm.LoadImagesToJson(APath: string): string;
var
  ja: TJSONArray;
  jo: TJSONObject;

  procedure ProcessFileType(AJsonArray: TJSONArray; AFileMask: String);
  var
    _sr: TSearchRec;
    jo_file: TJSONObject;
    userImageFolder: String;
  begin
    userImageFolder := '.\files\' + APath + '\';
    if FindFirst(userImageFolder + AFileMask, faAnyFile, _sr) =0 then
    begin
      repeat
        jo_file := TJSONObject.Create;
        jo_file.AddPair('name', _sr.Name);
        jo_file.AddPair('thumb', 'files/'+APath+'/'+_sr.Name);
        jo_file.AddPair('url', ReplaceStr(userImageFolder, '\', '/') + _sr.Name);
        AJsonArray.Add(jo_file);
      until FindNext(_sr) <> 0;

      FindClose(_sr);
    end;
  end;

begin
  ja := TJSONArray.Create;

  ProcessFileType(ja, '*.gif');
  ProcessFileType(ja, '*.jpg');
  ProcessFileType(ja, '*.jpeg');
  ProcessFileType(ja, '*.png');
  ProcessFileType(ja, '*.svg');

  if ja.Size > 0  then
  begin
    Result := ja.ToString;
    ja.Free;
  end
  else
    Result := '""';
end;

 

Very grateful for the solution,

However, since I am on the Roadmap, I would like to know if there will be a TListView component in the near future, if yes, in how long approximately ?
 

Link to comment
Share on other sites

×
×
  • Create New...