From 0f223c59aed7212cce1791acf324b7e1bd2fe6f7 Mon Sep 17 00:00:00 2001
From: Tristan Cavelier <tristan.cavelier@tiolive.com>
Date: Wed, 26 Mar 2014 11:12:46 +0100
Subject: [PATCH] dashboard scripts supports more than 1000 times

---
 examples/jio_dashboard.html | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/examples/jio_dashboard.html b/examples/jio_dashboard.html
index db3d8f0..a7fcb64 100644
--- a/examples/jio_dashboard.html
+++ b/examples/jio_dashboard.html
@@ -319,8 +319,9 @@ function command(method, num) {
   }
 }
 
-function doCommandNTimes(method) {
-  var i = -1, n = 0, lock, promise_list = [];
+function doCommandNTimes(method, i) {
+  var n = 0, lock, promise_list = [];
+  i = i > 0 ? i : 0;
   n = parseInt(select("#times").value, 10);
   lock = select("#times-lock").checked;
   if (!lock) {
@@ -329,10 +330,13 @@ function doCommandNTimes(method) {
   if (!isFinite(n)) {
     n = 1;
   }
-  while (++i < n) {
-    promise_list.push(command(method, i));
-  }
-  return RSVP.all(promise_list);
+  return command(method, ++i).
+    then(function (answer) {
+      if (i < n) {
+        return doCommandNTimes(method, i);
+      }
+      return answer;
+    });
 }
 
 function post() {
@@ -376,24 +380,24 @@ function scriptLogLocalStorage() {
 function scriptRemoveAllDocs() {
   var original_metadata_value = select('#metadata').value;
   return command("allDocs").then(function (answer) {
-    return RSVP.all(answer.data.rows.map(function (row) {
+    return jIO.util.forEach(answer.data.rows, function (row) {
       select("#metadata").value = JSON.stringify({"_id": row.id});
       var ret = command("remove");
       select('#metadata').value = original_metadata_value;
       return ret;
-    }));
+    });
   });
 }
 
 function scriptRepairAllDocs() {
   var original_metadata_value = select('#metadata').value;
   return command("allDocs").then(function (answer) {
-    return RSVP.all(answer.data.rows.map(function (row) {
+    return jIO.util.forEach(answer.data.rows, function (row) {
       select("#metadata").value = JSON.stringify({"_id": row.id});
       var ret = command("repair");
-      select('#metadata').value = original_metadata_value;
+      select("#metadata").value = original_metadata_value;
       return ret;
-    }));
+    });
   });
 }
         //-->
-- 
2.30.9