0 Replies Latest reply on Oct 10, 2014 9:52 AM by creativejoan0425

    Script UI dialog (Scroll bar with checkbox and editcontent)

    creativejoan0425 Level 1

      Hi expert,

       

      I have 10 indd files called 1.indd, 2.indd, 3.indd, 4.indd, 5.indd, 6.idd, 7.indd, 8.indd, 9.indd, 10.indd

      and each file have different pages 1.indd (1 page), 2.indd (2 pages), 3.indd (3 pages), 4.indd (4 pages), 5.indd (5 pages), 6.idd (6 pages), 7.indd (7 pages), 8.indd (8 pages), 9.indd (9 pages), 10.indd (10 pages)

       

      and I open those 10 files and run the script

       

      For Row1 editcontent, I change 9 to 20 and Row 2 change from 8 to 21

      Only Row 1, 3, 5 Checkbox value is true

       

      so If I alert all editcontent it should be 20, 21, 7, 6, 5, 4, 3, 2, 10, 1

      but the result is 9, 8, 7, 6, 5, 4, 3, 2, 10,1

       

      and for the Checkbox value, the result should be true, false, false, true, true, false, false, false, false, false

      but now the result true, false, false, true, true


      And I found that when I change the row 1 9 to 20 and then I use the scrollbar to scroll down and then scroll up , 20 will change back to 9, can make it when I scroll back the result is 20?


      below is my script:

       

      var DocArray = app.documents.everyItem().name;

      var myPrintFiles =[];

      var myPagesLength =[];

       

       

      for (i = 0; i < DocArray.length; i++){

                                      myPrintFiles.push(app.documents.itemByName(DocArray[i]).name);

                                      myPagesLength.push(app.documents.itemByName(DocArray[i]).pages.length);

                              }

      var call_codes = {myPrintFiles: myPagesLength};

      var rows = 5, number_of_codes = DocArray.length;

      var w = new Window ("dialog");

      var group = w.add ("group {alignChildren: 'fill'}");

      var panel = group.add ("panel {orientation: 'row', alignChildren: 'top'}");

      var sbar = group.add ("scrollbar {preferredSize: [20, undefined], maxvalue: " + String (number_of_codes-rows) + "}");

      var col1 = panel.add ("group {orientation: 'column', margins: 3}");

      var col2 = panel.add ("group {orientation: 'column', alignChildren: 'fill', preferredSize: [150, undefined]}");

      var fields = {}, start = 0, stop = rows, n = -1, myCheck = {};

       

       

               var myPrintFilesJoin =  myPrintFiles.join("\\r");

                          var myPrintFilesSplit =  myPrintFilesJoin.split("\\r");

                                for (j = 0; j < myPrintFilesSplit.length; j++) {

                                         myEachEditContent = myPrintFilesSplit[j];

       

       

      for (var i in call_codes){

      ++n;

      if (n >= start && n < stop){

      myCheck[n]  =col1.add ("checkbox", [0, 0, 300, 22], myPrintFilesSplit[j]);

      fields[n] = col2.add ("edittext", undefined, myPagesLength[j].toString().split(","));

      fields[n].label = i; // Add a label property that contains the letter

      fields[n].onChange = function () {call_codes[this.label] = this.text}

      } // When the edittext is changed, update the call_codes object

      }

      }

      sbar.onChanging = function()

      {

      var start = Math.round (this.value); // Round the sbar's value

      var stop = start+rows, n = 0, r = -1;

      var myPrintFilesSplit =  myPrintFilesJoin.split("\\r");

      for (j = 0; j < myPrintFilesSplit.length; j++) {

       

       

      //~ for (var i in call_codes)

      //~ {

      n++;

       

       

      if (n > start && n <= stop)

      {

      ++r;

      col1.children[r].text = myPrintFilesSplit[j]; // Replace the contents of the statictext

      fields[r].text = myPagesLength[j].toString().split(","); // and the edittext controls

      fields[r].label = i; // and update each edittext's label

       

       

      }

      }

      }

       

       

      w.show();

      for (j = 0; j < 10; j++) {

      alert(myPagesLength[j].toString().split(","));

      }

      for (j = 0; j < 10; j++) {

      alert(col1.children[j].value);

      }

       

      Thanks and Best Regards

      Joan