Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
413 views
in Technique[技术] by (71.8m points)

jquery - Adding a check or notification to a select box option after a process has been run

I have a select box in a Bootstrap modal. The select box allows the user to select a set of PDF's they want to create. Once the user selects the option and presses the print button a process that creates a lot of individual PDF's (over 500), combines them, then displays the large PDF in another tab. The modal does not go away because they will go to the next set of PDF's they want to create.

What I would like to do is add the text "Printed" to the option once the large PDF is displayed. That way they know which ones they selected.

Below is an example of the code I have tried. Any suggestions would be greatly appreciated. This is purely cosmetic and would be nice but not necessary to the process.

The first set of code is how the select box options are created. The last set of code is how the PDF's are created and how I tried to get the text "Printed onto the option".

function PrintDelinquentLetters(pidnList) {
  var startDate = $("#delinquentLetter_StartDate").val();
  var application = $("#delinquentLetter_Application").val();
  var today = new Date();
  var dd = today.getDate();
  var MM = today.getMonth() + 1; // January is at index 0 so must add one
  var yyyy = today.getFullYear();
  if (MM < 10) {
    MM = '0' + MM;
  }
  today = MM + '/' + dd + '/' + yyyy;
  
  $.ajax({
    type: 'POST',
    url: '@Url.Action("GetDelinquentLetterPageResults", "Employee")',
    data: JSON.stringify({
      "startDate": startDate,
      "application": application,
      "pidnList": pidnList
    }),
    dataType: 'json',
    contentType: "application/json; charset=utf-8",
    beforeSend: function() {
      showLoader();
    },
    success: function(returnData) {
      letterData = returnData;
      splitData = new Array();
      
      var letters = JSON.parse(JSON.stringify(letterData));

      // Divide into groups of 600
      while (letters.length > 0) {
        $(".loader").show();
        var splicedData = letters.splice(0, 600);
        splitData.push(splicedData);
      }

      var options = '<option value="-1">-- Select a Group --</option>';
      for (var i = 0; i < splitData.length; i++) {
        options += '<option value="' + i + '">Group ' + (i + 1) + '</option>';
      }
      $("#letterGroup").html(options);
      $("#printAllModal").modal("show");
      $(".loader").hide();
    },
    complete: function() {
      $(".loader").hide();
    }
  })
}

function PrintAll() {
  pdfCount = 0;
  var selectedGroup = parseInt($("#letterGroup").val());
  createdLetters = new Array();
  copySplitData = JSON.parse(JSON.stringify(splitData[selectedGroup])); // Deep copy of selected group
  var selectedGroupID = '#' + selectedGroup;
  if (selectedGroup != -1) {
    var percent = "0.00";
    ShowProgress(percent);

    var pdfHTML = "";
    var i = 0;

    grouped = _.mapValues(_.groupBy(copySplitData, 'property.PIDN'));
    var totalLength = Object.keys(grouped).length;
    var singlePIDNData = Object.keys(grouped).slice(i, 1);
    pdfHTML = CreateDelinquentLetter(grouped[singlePIDNData[0]]);

    // Create file
    $.ajax({
      type: 'POST',
      url: '@Url.Action("DelinquentLetterPDF", "Utilities")',
      data: JSON.stringify({
        'htmlString': pdfHTML,
        "PIDN": splitData[selectedGroup][i].property.PIDN
      }),
      dataType: 'json',
      contentType: "application/json; charset=utf-8",
      success: function(returnData) {
        createdLetters.push(returnData.FileName);
        var percent = CalculatePercentage(totalLength, (i + 1));
        ShowProgress(percent);

        // Finished?
        if (i < (totalLength - 1)) {
          i++;
          processLetters(i, totalLength, selectedGroup);
        } else {
          $(selectedGroupID).append(' (Printed)');
          combineLetters();
        }
      }
    });
  } else {
    showErrorMessage("Error", "You must select a group to print.");
    return;
  }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...