Source: paferafilechooser.js

// ********************************************************************
/** A version of PaferaChooser which is used by the system to let
 * the user choose from uploaded files.
 * 
 * @param {object} config - The same as PaferaChooser with the addition
 *    of filetype, which can be one of the following:
 */
class PaferaFileChooser extends PaferaChooser
{
  // ------------------------------------------------------------------
  constructor(config)
  {
    super(config);
    
    this.filetype  = config.filetype  || 'all';
    
    this.extrabuttons  = `
      <select class="FileChooserFilter">
        <option value="0">My Files</option>
        <option value="1">All Files</option>
      </select>
    `;
  }
  
  // ------------------------------------------------------------------
  OnGetAvailable(start, resultsdiv, searchterm)
  {
    let self  = this;
    
    P.LoadingAPI(
      '.' + self.div + ' .AvailableCards',
      '/system/fileapi',
      {
        command:      'search',
        filetype:      self.filetype,
        filename:      searchterm ? searchterm : '',
        start:         start,
        showallfiles:  E('.FileChooserFilter').value
      },
      {
        dontshowsuccess:  1
      }
    ).then(
      function(returned)
      {
        let d = returned.json;
        
        self.available        = d.data;
        self.availablecount   = d.count;
        
        self.DisplayAvailable();
      }
    );    
  }
  
  // ------------------------------------------------------------------
  RenderItem(r)
  {
    return P.RenderFileInfo(r);
  }
  
  // ------------------------------------------------------------------
  OnChosenAdded(dbid, obj)
  {
    let self  = this;
    
    if (!self.multipleselect)
    {
      P.RemoveFullScreen();
      self.OnFinished();
    }
  }
}