Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Count number of files in multiupload

    SmartClient Version: v10.1p_2016-02-26/Pro Deployment (built 2016-02-26)

    Is it in any way possible to count the number of files curently in a multifileuploaditem?

    In the screenshot from your showcase this would result in 2.
    Click image for larger version

Name:	Selection_666.png
Views:	98
Size:	10.8 KB
ID:	235875

    Also is there a way to get a callback when uploading/deleting a file in the multifileuploaditem?

    Thanks
    Last edited by Niels_EMP; 16 Mar 2016, 03:37.

    #2
    MultiUploadPicker, which is the "picker" AutoChild uses by MultiFileItem, allows you to set maxUploadFields and minUploadFields to control the number of files that can be added. There is no current way to get the number of files that the user has chosen (at least, not until they actually do the upload). What would you use this for?

    Comment


      #3
      I have a TabSet with a lot of different data and one of these tabs holds the files, I want the title of tab to reflect how many files are currently there so the user doesn't have to click on the tab to see if anyone has uploaded files for that particular instance.
      Click image for larger version

Name:	filesTab.PNG
Views:	92
Size:	15.1 KB
ID:	235906

      Now I can easily get the number of files when I fetch the initial form data, but I would like this value in the tab title to update when the user uploads a new files or deletes an existing one, and I can't find any handlers or callbacks for these actions.

      Comment


        #4
        Since adding or removing files requires a DataSource request, you could use DataSource.transformResponse (or equivalently a ResponseTransformer) to watch for successful "add" and "remove" requests.

        Comment


          #5
          Awesome, that works great.

          I could even use that to set number of files from the initial fetch.

          Code:
          DataSource fileDS = DataSource.get("scrum_backlog_userStoryFiles", null, new ResponseTransformer() {
                      
                      @Override
                      protected void transformResponse(DSResponse response, DSRequest request, Object data) {
                          switch (response.getOperationType()) {
                          case ADD:
                              numOfFiles++;
                              break;
                          case REMOVE:
                              numOfFiles--;
                              break;
                          case FETCH:
                              if(response.getData() != null)
                                  numOfFiles = response.getData().length;
                              break;
                          default:
                              break;
                          }
                          updateFilesAndLinksTabTitle();
                      }
                  });

          Comment

          Working...
          X