3 Replies Latest reply on Dec 12, 2016 5:17 AM by try67

    Is it possible, with app.execDialog(), to get the selected parent node of a heir_box_list?

    ZoPaars Level 1

      So when creating a dialogue using app.execDialog(), it is possible to have a hierarchical box list with the element type "hier_box_list".

       

      It is then possible to get a return of the child node that is selected. However, I haven't find a way to get anything returned if I have a parent node selected.

       

      I used the example 4 from the JavaScript API, page 84-87, to create the code below. Unfortunately this just returns a "undefined" when a parent node (like "Chapter 1", "Section 1", or "Section 2") is selected.

       

      var dialog4 = {
          selection : {
              "Chapter 1" : {
                  "Section 1" : {
                      "SubSection 1" : -1,
                      "SubSection 2" : -2,
                  },
                  "Section 2" : {
                      "SubSection 1" : -3,
                      "SubSection 2" : -4,
                  }
              },
              "Chapter 3" : -5,
              "Chapter 4" : -6,
          },
          Return : "",
          initialize : function (dialog) {
              dialog.load({
                  subl : this.selection
              })
          },
          subl : function (dialog) {
              var element = dialog.store()["subl"];
              this.Return = this.getHierChoice(element);
              console.println("\nSelection Box Hit: " + this.Return);
          },
          getHierChoice : function (e) {
              if (typeof e == "object") {
                  for (var i in e) {
                      if (typeof e[i] == "object") {
                          var retn = this.getHierChoice(e[i]);
                          if (retn) {
                              retn = i + ", " + retn;
                              return retn;
                          }
                          // if e[i] > 0, we’ve found the selected item
                      } else if (e[i] > 0)
                          return i;
                  }
              } else {
                  if (e[i] > 0)
                      return e[i];
              }
          },
          commit : function (dialog) {
              this.selection = dialog.store()["subl"];
          },
          cncl : function (dialog) {
              dialog.end("cancel")
          },
          // Dialog box description
          description : {
              name : "My Novel",
              elements :
              [{
                      type : "view",
                      align_children : "align_left",
                      elements :
                      [{
                              type : "cluster",
                              name : "Book Headings",
                              elements :
                              [{
                                      type : "static_text",
                                      name : "Make a selection",
                                  }, {
                                      type : "hier_list_box",
                                      item_id : "subl",
                                      char_width : 20,
                                      height : 200
                                  }
                              ]
                          }, {
                              type : "ok_cancel",
                          }
                      ]
                  }
              ]
          }
      };
      
      function dotheDialog(dialog, doc) {
          dialog.doc = doc;
          var retn = app.execDialog(dialog)
      };
      
      dotheDialog(dialog4, this);
      

       

      Does anybody know how I could have this return something if the user selects a parent node?