kjartanvalur / angular-kendo-window

Angular Kendo Window
MIT License
25 stars 9 forks source link

Fixed: Issue with using length when creating / deleting windows #4

Closed mgpetryk closed 8 years ago

mgpetryk commented 9 years ago

To see issue in the angular-kendo-window plunk, do the following:

1.) change the window modal property to false 2.) open two new windows 3.) close the first window 4.) open a new window

The new window will reuse the name of the second window opened since the window name is based off of the number of stacked windows (length). One solution would be to introduce a counter variable in $$stackedMap that is used to name the new windows and is incremented so that window names are never reused. something like "nextId" :

     createNew: function () {
          var stack = [];
          var nextId = 0;
          return {
              add: function (key, value) {
                  stack.push({
                      key: key,
                      value: value
                  });
              },
              get: function (key) {
                  for (var i = 0; i < stack.length; i++) {
                      if (key == stack[i].key) {
                          return stack[i];
                      }
                  }
              },
              keys: function () {
                  var keys = [];
                  for (var i = 0; i < stack.length; i++) {
                      keys.push(stack[i].key);
                  }
                  return keys;
              },
              top: function () {
                  return stack[stack.length - 1];
              },
              remove: function (key) {
                  var idx = -1;
                  for (var i = 0; i < stack.length; i++) {
                      if (key == stack[i].key) {
                          idx = i;
                          break;
                      }
                  }
                  return stack.splice(idx, 1)[0];
              },
              removeTop: function () {
                  return stack.splice(stack.length - 1, 1)[0];
              },
              length: function () {
                  return stack.length;
              },
              nextId: function () {
                  return nextId++;
              }
          };
      }
kjartanvalur commented 8 years ago

Can you try out the v 1.2

kjartanvalur commented 8 years ago

Fixed

mgpetryk commented 8 years ago

Thank you