couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gar...@apache.org
Subject [15/27] fauxton commit: updated refs/heads/master to 0ca35da
Date Tue, 31 May 2016 07:58:43 GMT
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ca35da7/app/addons/documents/index-results/stores.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/index-results/stores.js b/app/addons/documents/index-results/stores.js
index eedbad9..282df98 100644
--- a/app/addons/documents/index-results/stores.js
+++ b/app/addons/documents/index-results/stores.js
@@ -10,841 +10,833 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
-define([
-  '../../../app',
-  '../../../core/api',
-  './actiontypes',
-  '../header/header.actiontypes',
-  '../pagination/actiontypes',
-
-  '../resources',
-  '../mango/mango.helper',
-  '../resources',
-  '../../databases/resources'
-],
-
-function (app, FauxtonAPI, ActionTypes, HeaderActionTypes, PaginationActionTypes,
-  Documents, MangoHelper, Resources, DatabaseResources) {
+import app from "../../../app";
+import FauxtonAPI from "../../../core/api";
+import ActionTypes from "./actiontypes";
+import HeaderActionTypes from "../header/header.actiontypes";
+import PaginationActionTypes from "../pagination/actiontypes";
+import Documents from "../resources";
+import MangoHelper from "../mango/mango.helper";
+import Resources from "../resources";
+import DatabaseResources from "../../databases/resources";
+
+var Stores = {};
+
+var maxDocLimit = 10000;
+
+Stores.IndexResultsStore = FauxtonAPI.Store.extend({
+
+  initialize: function () {
+    this.reset();
+  },
+
+  reset: function () {
+    this._collection = new Backbone.Collection.extend({
+      url: ''
+    });
+
+    this._filteredCollection = [];
+    this._bulkDeleteDocCollection = new Resources.BulkDeleteDocCollection([], {});
+
+    this.clearSelectedItems();
+    this._isLoading = false;
+    this._textEmptyIndex = 'No Documents Found';
+    this._typeOfIndex = 'view';
+
+    this._tableViewSelectedFields = [];
+    this._isPrioritizedEnabled = false;
+
+    this._tableSchema = [];
+    this._tableView = false;
+
+    this.resetPagination();
+  },
+
+  resetPagination: function () {
+    this._pageStart = 1;
+    this._currentPage = 1;
+    this._enabled = true;
+    this._newView = false;
+    this._docLimit = _.isUndefined(this._docLimit) ? maxDocLimit : this._docLimit;
+
+    this.initPerPage();
+  },
+
+  setDocumentLimit: function (docLimit) {
+    if (docLimit) {
+      this._docLimit = docLimit;
+    } else {
+      this._docLimit = maxDocLimit;
+    }
 
-  var Stores = {};
+    this.initPerPage();
+  },
 
-  var maxDocLimit = 10000;
+  getCollection: function () {
+    return this._collection;
+  },
 
-  Stores.IndexResultsStore = FauxtonAPI.Store.extend({
+  canShowPrevious: function () {
+    if (!this._enabled) { return false; }
+    if (!this._collection || !this._collection.hasPrevious) { return false; }
 
-    initialize: function () {
-      this.reset();
-    },
+    return this._collection.hasPrevious();
+  },
 
-    reset: function () {
-      this._collection = new Backbone.Collection.extend({
-        url: ''
-      });
+  canShowNext: function () {
+    if (!this._enabled) { return this._enabled; }
 
-      this._filteredCollection = [];
-      this._bulkDeleteDocCollection = new Resources.BulkDeleteDocCollection([], {});
+    if ((this._pageStart + this._perPage) >= this._docLimit) {
+      return false;
+    }
 
-      this.clearSelectedItems();
-      this._isLoading = false;
-      this._textEmptyIndex = 'No Documents Found';
-      this._typeOfIndex = 'view';
+    if (!this._collection || !this._collection.hasNext) { return false; }
 
-      this._tableViewSelectedFields = [];
-      this._isPrioritizedEnabled = false;
+    return this._collection.hasNext();
+  },
 
-      this._tableSchema = [];
-      this._tableView = false;
+  paginateNext: function () {
+    this._currentPage += 1;
+    this._pageStart += this.getPerPage();
+    this._collection.paging.pageSize = this.documentsLeftToFetch();
+  },
 
-      this.resetPagination();
-    },
+  paginatePrevious: function () {
+    this._currentPage -= 1;
 
-    resetPagination: function () {
+    this._pageStart = this._pageStart - this.getPerPage();
+    if (this._pageStart < 1) {
       this._pageStart = 1;
-      this._currentPage = 1;
-      this._enabled = true;
-      this._newView = false;
-      this._docLimit = _.isUndefined(this._docLimit) ? maxDocLimit : this._docLimit;
-
-      this.initPerPage();
-    },
-
-    setDocumentLimit: function (docLimit) {
-      if (docLimit) {
-        this._docLimit = docLimit;
-      } else {
-        this._docLimit = maxDocLimit;
-      }
-
-      this.initPerPage();
-    },
-
-    getCollection: function () {
-      return this._collection;
-    },
-
-    canShowPrevious: function () {
-      if (!this._enabled) { return false; }
-      if (!this._collection || !this._collection.hasPrevious) { return false; }
-
-      return this._collection.hasPrevious();
-    },
-
-    canShowNext: function () {
-      if (!this._enabled) { return this._enabled; }
-
-      if ((this._pageStart + this._perPage) >= this._docLimit) {
-        return false;
-      }
-
-      if (!this._collection || !this._collection.hasNext) { return false; }
-
-      return this._collection.hasNext();
-    },
-
-    paginateNext: function () {
-      this._currentPage += 1;
-      this._pageStart += this.getPerPage();
-      this._collection.paging.pageSize = this.documentsLeftToFetch();
-    },
-
-    paginatePrevious: function () {
-      this._currentPage -= 1;
-
-      this._pageStart = this._pageStart - this.getPerPage();
-      if (this._pageStart < 1) {
-        this._pageStart = 1;
-      }
-
-      this._collection.paging.pageSize = this.getPerPage();
-    },
+    }
 
-    getCurrentPage: function () {
-      return this._currentPage;
-    },
+    this._collection.paging.pageSize = this.getPerPage();
+  },
 
-    totalDocsViewed: function () {
-      return this._perPage * this._currentPage;
-    },
+  getCurrentPage: function () {
+    return this._currentPage;
+  },
 
-    documentsLeftToFetch: function () {
-      var documentsLeftToFetch = this._docLimit - this.totalDocsViewed();
+  totalDocsViewed: function () {
+    return this._perPage * this._currentPage;
+  },
 
-      if (documentsLeftToFetch < this.getPerPage() ) {
-        return documentsLeftToFetch;
-      }
+  documentsLeftToFetch: function () {
+    var documentsLeftToFetch = this._docLimit - this.totalDocsViewed();
 
-      return this._perPage;
-    },
+    if (documentsLeftToFetch < this.getPerPage() ) {
+      return documentsLeftToFetch;
+    }
 
-    getPerPage: function () {
-      return this._perPage;
-    },
+    return this._perPage;
+  },
 
-    initPerPage: function () {
-      var perPage = FauxtonAPI.constants.MISC.DEFAULT_PAGE_SIZE;
+  getPerPage: function () {
+    return this._perPage;
+  },
 
-      if (window.localStorage) {
-        var storedPerPage = app.utils.localStorageGet('fauxton:perpage');
+  initPerPage: function () {
+    var perPage = FauxtonAPI.constants.MISC.DEFAULT_PAGE_SIZE;
 
-        if (storedPerPage) {
-          perPage = parseInt(storedPerPage, 10);
-        }
-      }
+    if (window.localStorage) {
+      var storedPerPage = app.utils.localStorageGet('fauxton:perpage');
 
-      if (this._docLimit < perPage) {
-        perPage = this._docLimit;
+      if (storedPerPage) {
+        perPage = parseInt(storedPerPage, 10);
       }
+    }
 
-      this.setPerPage(perPage);
-    },
+    if (this._docLimit < perPage) {
+      perPage = this._docLimit;
+    }
 
-    setPerPage: function (perPage) {
-      this._perPage = perPage;
-      app.utils.localStorageSet('fauxton:perpage', perPage);
+    this.setPerPage(perPage);
+  },
 
-      if (this._collection && this._collection.pageSizeReset) {
-        this._collection.pageSizeReset(perPage, {fetch: false});
-      }
-    },
+  setPerPage: function (perPage) {
+    this._perPage = perPage;
+    app.utils.localStorageSet('fauxton:perpage', perPage);
 
-    getTotalRows: function () {
-      if (!this._collection) { return false; }
+    if (this._collection && this._collection.pageSizeReset) {
+      this._collection.pageSizeReset(perPage, {fetch: false});
+    }
+  },
 
-      return this._collection.length;
-    },
+  getTotalRows: function () {
+    if (!this._collection) { return false; }
 
-    getPageStart: function () {
-      return this._pageStart;
-    },
+    return this._collection.length;
+  },
 
-    getPageEnd: function () {
-      if (!this._collection) { return false; }
-      return this._pageStart + this._collection.length - 1;
-    },
+  getPageStart: function () {
+    return this._pageStart;
+  },
 
-    getUpdateSeq: function () {
-      if (!this._collection) { return false; }
-      if (!this._collection.updateSeq) { return false; }
-      return this._collection.updateSeq();
-    },
+  getPageEnd: function () {
+    if (!this._collection) { return false; }
+    return this._pageStart + this._collection.length - 1;
+  },
 
-    clearSelectedItems: function () {
-      this._bulkDeleteDocCollection.reset([]);
-    },
+  getUpdateSeq: function () {
+    if (!this._collection) { return false; }
+    if (!this._collection.updateSeq) { return false; }
+    return this._collection.updateSeq();
+  },
 
-    newResults: function (options) {
-      this._collection = options.collection;
+  clearSelectedItems: function () {
+    this._bulkDeleteDocCollection.reset([]);
+  },
 
-      this._bulkDeleteDocCollection = options.bulkCollection;
+  newResults: function (options) {
+    this._collection = options.collection;
 
-      if (options.textEmptyIndex) {
-        this._textEmptyIndex = options.textEmptyIndex;
-      }
+    this._bulkDeleteDocCollection = options.bulkCollection;
 
-      if (options.typeOfIndex) {
-        this._typeOfIndex = options.typeOfIndex;
-      }
+    if (options.textEmptyIndex) {
+      this._textEmptyIndex = options.textEmptyIndex;
+    }
 
-      this._cachedSelected = [];
+    if (options.typeOfIndex) {
+      this._typeOfIndex = options.typeOfIndex;
+    }
 
-      this._filteredCollection = this._collection.filter(filterOutGeneratedMangoDocs);
+    this._cachedSelected = [];
 
-      function filterOutGeneratedMangoDocs (doc) {
-        if (doc.get && typeof doc.get === 'function') {
-          return doc.get('language') !== 'query';
-        }
+    this._filteredCollection = this._collection.filter(filterOutGeneratedMangoDocs);
 
-        return doc.language !== 'query';
+    function filterOutGeneratedMangoDocs (doc) {
+      if (doc.get && typeof doc.get === 'function') {
+        return doc.get('language') !== 'query';
       }
-    },
 
-    getTypeOfIndex: function () {
-      return this._typeOfIndex;
-    },
+      return doc.language !== 'query';
+    }
+  },
 
-    isEditable: function (doc) {
-      if (!this._collection) {
-        return false;
-      }
+  getTypeOfIndex: function () {
+    return this._typeOfIndex;
+  },
 
-      if (doc && this.isGhostDoc(doc)) {
-        return false;
-      }
+  isEditable: function (doc) {
+    if (!this._collection) {
+      return false;
+    }
 
-      if (doc && !doc.get('_id')) {
-        return false;
-      }
+    if (doc && this.isGhostDoc(doc)) {
+      return false;
+    }
 
-      if (!this._collection.isEditable) {
-        return false;
-      }
+    if (doc && !doc.get('_id')) {
+      return false;
+    }
 
-      return this._collection.isEditable();
-    },
+    if (!this._collection.isEditable) {
+      return false;
+    }
 
-    isGhostDoc: function (doc) {
-      // ghost docs are empty results where all properties were
-      // filtered away by mango
-      return !doc || !doc.attributes || !Object.keys(doc.attributes).length;
-    },
+    return this._collection.isEditable();
+  },
 
-    isDeletable: function (doc) {
-      if (this.isGhostDoc(doc)) {
-        return false;
-      }
+  isGhostDoc: function (doc) {
+    // ghost docs are empty results where all properties were
+    // filtered away by mango
+    return !doc || !doc.attributes || !Object.keys(doc.attributes).length;
+  },
 
-      return doc.isDeletable();
-    },
+  isDeletable: function (doc) {
+    if (this.isGhostDoc(doc)) {
+      return false;
+    }
 
-    getCollection: function () {
-      return this._collection;
-    },
+    return doc.isDeletable();
+  },
 
-    getBulkDocCollection: function () {
-      return this._bulkDeleteDocCollection;
-    },
+  getCollection: function () {
+    return this._collection;
+  },
 
-    getDocContent: function (originalDoc) {
-      var doc = originalDoc.toJSON();
+  getBulkDocCollection: function () {
+    return this._bulkDeleteDocCollection;
+  },
 
-      return JSON.stringify(doc, null, ' ');
-    },
+  getDocContent: function (originalDoc) {
+    var doc = originalDoc.toJSON();
 
-    getDocId: function (doc) {
+    return JSON.stringify(doc, null, ' ');
+  },
 
-      if (!_.isUndefined(doc.id)) {
-        return doc.id;
-      }
+  getDocId: function (doc) {
 
-      if (doc.get('key')) {
-        return doc.get('key').toString();
-      }
+    if (!_.isUndefined(doc.id)) {
+      return doc.id;
+    }
 
-      return '';
-    },
+    if (doc.get('key')) {
+      return doc.get('key').toString();
+    }
 
-    getMangoDocContent: function (originalDoc) {
-      var doc = originalDoc.toJSON();
+    return '';
+  },
 
-      delete doc.ddoc;
-      delete doc.name;
+  getMangoDocContent: function (originalDoc) {
+    var doc = originalDoc.toJSON();
 
-      return JSON.stringify(doc, null, ' ');
-    },
+    delete doc.ddoc;
+    delete doc.name;
 
-    getMangoDoc: function (doc, index) {
-      var selector,
-          header;
+    return JSON.stringify(doc, null, ' ');
+  },
 
-      if (doc.get('def') && doc.get('def').fields) {
+  getMangoDoc: function (doc, index) {
+    var selector,
+        header;
 
-        header = MangoHelper.getIndexName(doc);
+    if (doc.get('def') && doc.get('def').fields) {
 
-        return {
-          content: this.getMangoDocContent(doc),
-          header: header,
-          id: doc.getId(),
-          keylabel: '',
-          url: doc.isFromView() ? doc.url('app') : doc.url('web-index'),
-          isDeletable: this.isDeletable(doc),
-          isEditable: this.isEditable(doc)
-        };
-      }
+      header = MangoHelper.getIndexName(doc);
 
-      // we filtered away our content with the fields param
       return {
-        content: ' ',
+        content: this.getMangoDocContent(doc),
         header: header,
-        id: this.getDocId(doc) + index,
+        id: doc.getId(),
         keylabel: '',
-        url: this.isEditable(doc) ? doc.url('app') : null,
+        url: doc.isFromView() ? doc.url('app') : doc.url('web-index'),
         isDeletable: this.isDeletable(doc),
         isEditable: this.isEditable(doc)
       };
-    },
+    }
 
-    getResults: function () {
-      var hasBulkDeletableDoc;
-      var res;
+    // we filtered away our content with the fields param
+    return {
+      content: ' ',
+      header: header,
+      id: this.getDocId(doc) + index,
+      keylabel: '',
+      url: this.isEditable(doc) ? doc.url('app') : null,
+      isDeletable: this.isDeletable(doc),
+      isEditable: this.isEditable(doc)
+    };
+  },
+
+  getResults: function () {
+    var hasBulkDeletableDoc;
+    var res;
+
+    // Table sytle view
+    if (this.getIsTableView()) {
+      return this.getTableViewData();
+    }
 
-      // Table sytle view
-      if (this.getIsTableView()) {
-        return this.getTableViewData();
-      }
+    // JSON style views
+    res = this._filteredCollection
+      .map(function (doc, i) {
+        if (doc.get('def') || this.isGhostDoc(doc)) {
+          return this.getMangoDoc(doc, i);
+        }
+        return {
+          content: this.getDocContent(doc),
+          id: this.getDocId(doc),
+          _rev: doc.get('_rev'),
+          header: this.getDocId(doc),
+          keylabel: doc.isFromView() ? 'key' : 'id',
+          url: this.getDocId(doc) ? doc.url('app') : null,
+          isDeletable: this.isDeletable(doc),
+          isEditable: this.isEditable(doc)
+        };
+      }, this);
 
-      // JSON style views
-      res = this._filteredCollection
-        .map(function (doc, i) {
-          if (doc.get('def') || this.isGhostDoc(doc)) {
-            return this.getMangoDoc(doc, i);
-          }
-          return {
-            content: this.getDocContent(doc),
-            id: this.getDocId(doc),
-            _rev: doc.get('_rev'),
-            header: this.getDocId(doc),
-            keylabel: doc.isFromView() ? 'key' : 'id',
-            url: this.getDocId(doc) ? doc.url('app') : null,
-            isDeletable: this.isDeletable(doc),
-            isEditable: this.isEditable(doc)
-          };
-        }, this);
-
-      hasBulkDeletableDoc = this.hasBulkDeletableDoc(this._filteredCollection);
+    hasBulkDeletableDoc = this.hasBulkDeletableDoc(this._filteredCollection);
 
-      return {
-        displayedFields: this.getDisplayCountForTableView(),
-        hasBulkDeletableDoc: hasBulkDeletableDoc,
-        results: res
-      };
-    },
+    return {
+      displayedFields: this.getDisplayCountForTableView(),
+      hasBulkDeletableDoc: hasBulkDeletableDoc,
+      results: res
+    };
+  },
 
-    getPseudoSchema: function (data) {
-      var cache = [];
+  getPseudoSchema: function (data) {
+    var cache = [];
 
-      data.forEach(function (el) {
-        Object.keys(el).forEach(function (k) {
-          cache.push(k);
-        });
+    data.forEach(function (el) {
+      Object.keys(el).forEach(function (k) {
+        cache.push(k);
       });
+    });
 
-      cache = _.uniq(cache);
+    cache = _.uniq(cache);
 
-      // always begin with _id
-      var i = cache.indexOf('_id');
-      if (i !== -1) {
-        cache.splice(i, 1);
-        cache.unshift('_id');
-      }
+    // always begin with _id
+    var i = cache.indexOf('_id');
+    if (i !== -1) {
+      cache.splice(i, 1);
+      cache.unshift('_id');
+    }
 
-      return cache;
-    },
+    return cache;
+  },
 
-    normalizeTableData: function (data, isView) {
-      // filter out cruft
-      if (isView) {
-        return data;
-      }
+  normalizeTableData: function (data, isView) {
+    // filter out cruft
+    if (isView) {
+      return data;
+    }
 
-      return data.map(function (el) {
-        return el.doc || el;
-      });
-    },
+    return data.map(function (el) {
+      return el.doc || el;
+    });
+  },
 
-    isIncludeDocsEnabled: function () {
-      var params = app.getParams();
+  isIncludeDocsEnabled: function () {
+    var params = app.getParams();
 
-      return !!params.include_docs;
-    },
+    return !!params.include_docs;
+  },
 
-    getPrioritizedFields: function (data, max) {
-      var res = data.reduce(function (acc, el) {
-        acc = acc.concat(Object.keys(el));
-        return acc;
-      }, []);
+  getPrioritizedFields: function (data, max) {
+    var res = data.reduce(function (acc, el) {
+      acc = acc.concat(Object.keys(el));
+      return acc;
+    }, []);
 
-      res = _.countBy(res, function (el) {
-        return el;
-      });
+    res = _.countBy(res, function (el) {
+      return el;
+    });
 
-      delete res._id;
-      delete res.id;
-      delete res._rev;
-
-      res = Object.keys(res).reduce(function (acc, el) {
-        acc.push([res[el], el]);
-        return acc;
-      }, []);
-
-      res = this.sortByTwoFields(res);
-      res = res.slice(0, max);
-
-      return res.reduce(function (acc, el) {
-        acc.push(el[1]);
-        return acc;
-      }, []);
-    },
-
-     sortByTwoFields: function (elements) {
-      // given:
-      // var a = [[2, "b"], [3, "z"], [1, "a"], [3, "a"]]
-      // it sorts to:
-      // [[3, "a"], [3, "z"], [2, "b"], [1, "a"]]
-      // note that the arrays with 3 got the first two arrays
-      // _and_ that the second values in the array with 3 are also sorted
-
-      function _recursiveSort (a, b, index) {
-        if (a[index] === b[index]) {
-          return index < 2 ? _recursiveSort(a, b, index + 1) : 0;
-        }
+    delete res._id;
+    delete res.id;
+    delete res._rev;
 
-        // second elements asc
-        if (index === 1) {
-          return (a[index] < b[index]) ? -1 : 1;
-        }
+    res = Object.keys(res).reduce(function (acc, el) {
+      acc.push([res[el], el]);
+      return acc;
+    }, []);
 
-        // first elements desc
-        return (a[index] < b[index]) ? 1 : -1;
+    res = this.sortByTwoFields(res);
+    res = res.slice(0, max);
+
+    return res.reduce(function (acc, el) {
+      acc.push(el[1]);
+      return acc;
+    }, []);
+  },
+
+   sortByTwoFields: function (elements) {
+    // given:
+    // var a = [[2, "b"], [3, "z"], [1, "a"], [3, "a"]]
+    // it sorts to:
+    // [[3, "a"], [3, "z"], [2, "b"], [1, "a"]]
+    // note that the arrays with 3 got the first two arrays
+    // _and_ that the second values in the array with 3 are also sorted
+
+    function _recursiveSort (a, b, index) {
+      if (a[index] === b[index]) {
+        return index < 2 ? _recursiveSort(a, b, index + 1) : 0;
       }
 
-      return elements.sort(function (a, b) {
-        return _recursiveSort(a, b, 0);
-      });
-    },
+      // second elements asc
+      if (index === 1) {
+        return (a[index] < b[index]) ? -1 : 1;
+      }
 
-    hasIdOrRev: function (schema) {
+      // first elements desc
+      return (a[index] < b[index]) ? 1 : -1;
+    }
 
-      return schema.indexOf('_id') !== -1 ||
-        schema.indexOf('id') !== -1 ||
-        schema.indexOf('_rev') !== -1;
-    },
+    return elements.sort(function (a, b) {
+      return _recursiveSort(a, b, 0);
+    });
+  },
 
-    getNotSelectedFields: function (selectedFields, allFields) {
-      var without = _.without.bind(this, allFields);
-      return without.apply(this, selectedFields);
-    },
+  hasIdOrRev: function (schema) {
 
-    getDisplayCountForTableView: function () {
-      var allFieldCount;
-      var shownCount;
+    return schema.indexOf('_id') !== -1 ||
+      schema.indexOf('id') !== -1 ||
+      schema.indexOf('_rev') !== -1;
+  },
 
-      if (!this.getIsTableView()) {
-        return null;
-      }
+  getNotSelectedFields: function (selectedFields, allFields) {
+    var without = _.without.bind(this, allFields);
+    return without.apply(this, selectedFields);
+  },
 
-      if (!this.isIncludeDocsEnabled()) {
-        return null;
-      }
+  getDisplayCountForTableView: function () {
+    var allFieldCount;
+    var shownCount;
 
-      shownCount = _.uniq(this._tableViewSelectedFields).length;
+    if (!this.getIsTableView()) {
+      return null;
+    }
 
-      allFieldCount = this._tableSchema.length;
-      if (_.contains(this._tableSchema, '_id', '_rev')) {
-        allFieldCount = allFieldCount - 1;
-      }
+    if (!this.isIncludeDocsEnabled()) {
+      return null;
+    }
 
-      if (_.contains(this._tableSchema, '_id', '_rev')) {
-        shownCount = shownCount + 1;
-      }
+    shownCount = _.uniq(this._tableViewSelectedFields).length;
 
-      return {shown: shownCount, allFieldCount: allFieldCount};
-    },
-
-    getTableViewData: function () {
-      var res;
-      var schema;
-      var hasIdOrRev;
-      var hasIdOrRev;
-      var prioritizedFields;
-      var hasBulkDeletableDoc;
-      var database = this.getDatabase();
-      var isView = !!this._collection.view;
-
-      // softmigration remove backbone
-      var data;
-      var collectionType = this._collection.collectionType;
-      data = this._filteredCollection.map(function (el) {
-        return fixDocIdForMango(el.toJSON(), collectionType);
-      });
+    allFieldCount = this._tableSchema.length;
+    if (_.contains(this._tableSchema, '_id', '_rev')) {
+      allFieldCount = allFieldCount - 1;
+    }
 
-      function fixDocIdForMango (doc, docType) {
-        if (docType !== 'MangoIndex') {
-          return doc;
-        }
+    if (_.contains(this._tableSchema, '_id', '_rev')) {
+      shownCount = shownCount + 1;
+    }
 
-        doc.id = doc.ddoc;
+    return {shown: shownCount, allFieldCount: allFieldCount};
+  },
+
+  getTableViewData: function () {
+    var res;
+    var schema;
+    var hasIdOrRev;
+    var hasIdOrRev;
+    var prioritizedFields;
+    var hasBulkDeletableDoc;
+    var database = this.getDatabase();
+    var isView = !!this._collection.view;
+
+    // softmigration remove backbone
+    var data;
+    var collectionType = this._collection.collectionType;
+    data = this._filteredCollection.map(function (el) {
+      return fixDocIdForMango(el.toJSON(), collectionType);
+    });
+
+    function fixDocIdForMango (doc, docType) {
+      if (docType !== 'MangoIndex') {
         return doc;
       }
 
-      function isJSONDocEditable (doc, docType) {
+      doc.id = doc.ddoc;
+      return doc;
+    }
 
-        if (!doc) {
-          return;
-        }
+    function isJSONDocEditable (doc, docType) {
 
-        if (docType === 'MangoIndex') {
-          return false;
-        }
+      if (!doc) {
+        return;
+      }
 
-        if (!Object.keys(doc).length) {
-          return false;
-        }
+      if (docType === 'MangoIndex') {
+        return false;
+      }
 
-        if (!doc._id) {
-          return false;
-        }
+      if (!Object.keys(doc).length) {
+        return false;
+      }
 
-        return true;
+      if (!doc._id) {
+        return false;
       }
 
-      function isJSONDocBulkDeletable (doc, docType) {
-        if (docType === 'MangoIndex') {
-          return doc.type !== 'special';
-        }
+      return true;
+    }
 
-        return !!doc._id && !!doc._rev;
+    function isJSONDocBulkDeletable (doc, docType) {
+      if (docType === 'MangoIndex') {
+        return doc.type !== 'special';
       }
 
-      // softmigration end
+      return !!doc._id && !!doc._rev;
+    }
 
-      var isIncludeDocsEnabled = this.isIncludeDocsEnabled();
-      var notSelectedFields = null;
-      if (isIncludeDocsEnabled) {
+    // softmigration end
 
-        data = this.normalizeTableData(data, isView);
-        schema = this.getPseudoSchema(data);
-        hasIdOrRev = this.hasIdOrRev(schema);
+    var isIncludeDocsEnabled = this.isIncludeDocsEnabled();
+    var notSelectedFields = null;
+    if (isIncludeDocsEnabled) {
 
-        if (!this._isPrioritizedEnabled) {
-          this._tableViewSelectedFields = this._cachedSelected || [];
-        }
-
-        if (this._tableViewSelectedFields.length === 0) {
-          prioritizedFields = this.getPrioritizedFields(data, hasIdOrRev ? 4 : 5);
-          this._tableViewSelectedFields = prioritizedFields;
-          this._cachedSelected = this._tableViewSelectedFields;
-        }
+      data = this.normalizeTableData(data, isView);
+      schema = this.getPseudoSchema(data);
+      hasIdOrRev = this.hasIdOrRev(schema);
 
-        var schemaWithoutMetaDataFields = _.without(schema, '_id', '_rev', '_attachment');
-        notSelectedFields = this.getNotSelectedFields(this._tableViewSelectedFields, schemaWithoutMetaDataFields);
+      if (!this._isPrioritizedEnabled) {
+        this._tableViewSelectedFields = this._cachedSelected || [];
+      }
 
-        if (this._isPrioritizedEnabled) {
-          notSelectedFields = null;
-          this._tableViewSelectedFields = schemaWithoutMetaDataFields;
-        }
+      if (this._tableViewSelectedFields.length === 0) {
+        prioritizedFields = this.getPrioritizedFields(data, hasIdOrRev ? 4 : 5);
+        this._tableViewSelectedFields = prioritizedFields;
+        this._cachedSelected = this._tableViewSelectedFields;
+      }
 
+      var schemaWithoutMetaDataFields = _.without(schema, '_id', '_rev', '_attachment');
+      notSelectedFields = this.getNotSelectedFields(this._tableViewSelectedFields, schemaWithoutMetaDataFields);
 
-      } else {
-        schema = this.getPseudoSchema(data);
-        this._tableViewSelectedFields = _.without(schema, '_id', '_rev', '_attachment');
+      if (this._isPrioritizedEnabled) {
+        notSelectedFields = null;
+        this._tableViewSelectedFields = schemaWithoutMetaDataFields;
       }
 
-      this._notSelectedFields = notSelectedFields;
-      this._tableSchema = schema;
 
-      var dbId = database.safeID();
+    } else {
+      schema = this.getPseudoSchema(data);
+      this._tableViewSelectedFields = _.without(schema, '_id', '_rev', '_attachment');
+    }
 
-      res = data.map(function (doc) {
-        var safeId = app.utils.getSafeIdForDoc(doc._id || doc.id); // inconsistent apis for GET between mango and views
-        var url;
+    this._notSelectedFields = notSelectedFields;
+    this._tableSchema = schema;
 
-        if (safeId) {
-          url = FauxtonAPI.urls('document', 'app', dbId, safeId);
-        }
+    var dbId = database.safeID();
 
-        return {
-          content: doc,
-          id: doc._id || doc.id, // inconsistent apis for GET between mango and views
-          _rev: doc._rev,
-          header: '',
-          keylabel: '',
-          url: url,
-          isDeletable: isJSONDocBulkDeletable(doc, collectionType),
-          isEditable: isJSONDocEditable(doc, collectionType)
-        };
-      }.bind(this));
+    res = data.map(function (doc) {
+      var safeId = app.utils.getSafeIdForDoc(doc._id || doc.id); // inconsistent apis for GET between mango and views
+      var url;
 
-      hasBulkDeletableDoc = this.hasBulkDeletableDoc(this._filteredCollection);
+      if (safeId) {
+        url = FauxtonAPI.urls('document', 'app', dbId, safeId);
+      }
 
       return {
-        notSelectedFields: notSelectedFields,
-        hasMetadata: this.getHasMetadata(schema),
-        selectedFields: this._tableViewSelectedFields,
-        hasBulkDeletableDoc: hasBulkDeletableDoc,
-        schema: schema,
-        results: res,
-        displayedFields: this.getDisplayCountForTableView(),
+        content: doc,
+        id: doc._id || doc.id, // inconsistent apis for GET between mango and views
+        _rev: doc._rev,
+        header: '',
+        keylabel: '',
+        url: url,
+        isDeletable: isJSONDocBulkDeletable(doc, collectionType),
+        isEditable: isJSONDocEditable(doc, collectionType)
       };
-    },
-
-    changeTableViewFields: function (options) {
-      var newSelectedRow = options.newSelectedRow;
-      var i = options.index;
+    }.bind(this));
+
+    hasBulkDeletableDoc = this.hasBulkDeletableDoc(this._filteredCollection);
+
+    return {
+      notSelectedFields: notSelectedFields,
+      hasMetadata: this.getHasMetadata(schema),
+      selectedFields: this._tableViewSelectedFields,
+      hasBulkDeletableDoc: hasBulkDeletableDoc,
+      schema: schema,
+      results: res,
+      displayedFields: this.getDisplayCountForTableView(),
+    };
+  },
+
+  changeTableViewFields: function (options) {
+    var newSelectedRow = options.newSelectedRow;
+    var i = options.index;
+
+    this._tableViewSelectedFields[i] = newSelectedRow;
+  },
+
+  getHasMetadata: function (schema) {
+    return _.contains(schema, '_id', '_rev');
+  },
+
+  hasBulkDeletableDoc: function (docs) {
+    var found = false;
+    var length = docs.length;
+    var i;
+
+    // use a for loop here as we can end it once we found the first id
+    for (i = 0; i < length; i++) {
+      if (docs[i].isBulkDeletable()) {
+        found = true;
+        break;
+      }
+    }
 
-      this._tableViewSelectedFields[i] = newSelectedRow;
-    },
+    return found;
+  },
 
-    getHasMetadata: function (schema) {
-      return _.contains(schema, '_id', '_rev');
-    },
+  hasResults: function () {
+    if (this.isLoading()) { return this.isLoading(); }
+    return this._collection.length > 0;
+  },
 
-    hasBulkDeletableDoc: function (docs) {
-      var found = false;
-      var length = docs.length;
-      var i;
+  isLoading: function () {
+    return this._isLoading;
+  },
 
-      // use a for loop here as we can end it once we found the first id
-      for (i = 0; i < length; i++) {
-        if (docs[i].isBulkDeletable()) {
-          found = true;
-          break;
-        }
-      }
+  selectDoc: function (doc, noReset) {
 
-      return found;
-    },
+    if (!doc._id || doc._id === '_all_docs') {
+      return;
+    }
 
-    hasResults: function () {
-      if (this.isLoading()) { return this.isLoading(); }
-      return this._collection.length > 0;
-    },
+    if (!this._bulkDeleteDocCollection.get(doc._id)) {
+      this._bulkDeleteDocCollection.add(doc);
+      return;
+    }
 
-    isLoading: function () {
-      return this._isLoading;
-    },
+    this._bulkDeleteDocCollection.remove(doc._id);
+  },
 
-    selectDoc: function (doc, noReset) {
+  selectAllDocuments: function () {
+    this.deSelectCurrentCollection();
 
-      if (!doc._id || doc._id === '_all_docs') {
-        return;
-      }
+    this._collection.each(function (doc) {
 
-      if (!this._bulkDeleteDocCollection.get(doc._id)) {
-        this._bulkDeleteDocCollection.add(doc);
+      if (!doc.isBulkDeletable()) {
         return;
       }
 
-      this._bulkDeleteDocCollection.remove(doc._id);
-    },
-
-    selectAllDocuments: function () {
-      this.deSelectCurrentCollection();
-
-      this._collection.each(function (doc) {
-
-        if (!doc.isBulkDeletable()) {
-          return;
-        }
-
-        this.selectDoc({
-          _id: doc.id,
-          _rev: doc.get('_rev'),
-          _deleted: true
-        });
-      }, this);
-
-    },
-
-    deSelectCurrentCollection: function () {
-      this._collection.each(function (doc) {
-
-        if (!doc.isBulkDeletable()) {
-          return;
-        }
-
-        this._bulkDeleteDocCollection.remove(doc.id);
-      }, this);
-    },
-
-    toggleSelectAllDocuments: function () {
-      if (this.areAllDocumentsSelected()) {
-        return this.deSelectCurrentCollection();
-      }
+      this.selectDoc({
+        _id: doc.id,
+        _rev: doc.get('_rev'),
+        _deleted: true
+      });
+    }, this);
 
-      return this.selectAllDocuments();
-    },
+  },
 
-    togglePrioritizedTableView: function () {
-      this._isPrioritizedEnabled = !this._isPrioritizedEnabled;
-    },
+  deSelectCurrentCollection: function () {
+    this._collection.each(function (doc) {
 
-    areAllDocumentsSelected: function () {
-      if (this._collection.length === 0) {
-        return false;
+      if (!doc.isBulkDeletable()) {
+        return;
       }
 
-      var foundAllOnThisPage = true;
-
-      var selected = this._bulkDeleteDocCollection.pluck('_id');
+      this._bulkDeleteDocCollection.remove(doc.id);
+    }, this);
+  },
 
-      this._collection.forEach(function (doc) {
-        if (!doc.isBulkDeletable()) {
-          return;
-        }
-
-        if (!_.contains(selected, doc.id)) {
-          foundAllOnThisPage = false;
-        }
-      }.bind(this));
-
-      return foundAllOnThisPage;
-    },
+  toggleSelectAllDocuments: function () {
+    if (this.areAllDocumentsSelected()) {
+      return this.deSelectCurrentCollection();
+    }
 
-    getSelectedItemsLength: function () {
-      return this._bulkDeleteDocCollection.length;
-    },
+    return this.selectAllDocuments();
+  },
 
-    getDatabase: function () {
-      return this._collection.database;
-    },
+  togglePrioritizedTableView: function () {
+    this._isPrioritizedEnabled = !this._isPrioritizedEnabled;
+  },
 
-    getTextEmptyIndex: function () {
-      return this._textEmptyIndex;
-    },
+  areAllDocumentsSelected: function () {
+    if (this._collection.length === 0) {
+      return false;
+    }
 
-    hasSelectedItem: function () {
-      return this.getSelectedItemsLength() > 0;
-    },
+    var foundAllOnThisPage = true;
 
-    toggleTableView: function (options) {
-      var enableTableView = options.enable;
+    var selected = this._bulkDeleteDocCollection.pluck('_id');
 
-      if (enableTableView) {
-        this._tableView = true;
+    this._collection.forEach(function (doc) {
+      if (!doc.isBulkDeletable()) {
         return;
       }
 
-      this._tableView = false;
-    },
+      if (!_.contains(selected, doc.id)) {
+        foundAllOnThisPage = false;
+      }
+    }.bind(this));
 
-    getIsTableView: function () {
-      return this._tableView;
-    },
+    return foundAllOnThisPage;
+  },
 
-    getIsPrioritizedEnabled: function () {
-      return this._isPrioritizedEnabled;
-    },
+  getSelectedItemsLength: function () {
+    return this._bulkDeleteDocCollection.length;
+  },
 
-    getCurrentViewType: function () {
+  getDatabase: function () {
+    return this._collection.database;
+  },
 
-      if (this._tableView) {
-        return 'table';
-      }
+  getTextEmptyIndex: function () {
+    return this._textEmptyIndex;
+  },
 
-      return 'expanded';
-    },
+  hasSelectedItem: function () {
+    return this.getSelectedItemsLength() > 0;
+  },
 
-    getShowPrioritizedFieldToggler: function () {
-      return this.isIncludeDocsEnabled() && this.getIsTableView();
-    },
+  toggleTableView: function (options) {
+    var enableTableView = options.enable;
 
-    clearResultsBeforeFetch: function () {
-      if (this._collection && this._collection.reset) {
-        this._collection.reset();
-      }
-      this._isLoading = true;
-    },
+    if (enableTableView) {
+      this._tableView = true;
+      return;
+    }
 
-    resultsResetFromFetch: function () {
-      this._isLoading = false;
-    },
+    this._tableView = false;
+  },
 
-    dispatch: function (action) {
-      switch (action.type) {
-        case ActionTypes.INDEX_RESULTS_NEW_RESULTS:
-          this.newResults(action.options);
-        break;
-        case ActionTypes.INDEX_RESULTS_RESET:
-          this.resultsResetFromFetch();
-        break;
-        case ActionTypes.INDEX_RESULTS_SELECT_DOC:
-          this.selectDoc(action.options);
-        break;
-        case ActionTypes.INDEX_RESULTS_CLEAR_RESULTS:
-          this.clearResultsBeforeFetch();
-        break;
-        case ActionTypes.INDEX_RESULTS_TOOGLE_SELECT_ALL_DOCUMENTS:
-          this.toggleSelectAllDocuments();
-        break;
-        case ActionTypes.INDEX_RESULTS_SELECT_NEW_FIELD_IN_TABLE:
-          this.changeTableViewFields(action.options);
-        break;
-        case ActionTypes.INDEX_RESULTS_TOGGLE_PRIORITIZED_TABLE_VIEW:
-          this.togglePrioritizedTableView();
-        break;
-
-        case HeaderActionTypes.TOGGLE_TABLEVIEW:
-          this.toggleTableView(action.options);
-        break;
+  getIsTableView: function () {
+    return this._tableView;
+  },
 
-        case PaginationActionTypes.SET_PAGINATION_DOCUMENT_LIMIT:
-          this.setDocumentLimit(action.docLimit);
-        break;
-        case PaginationActionTypes.PAGINATE_NEXT:
-          this.paginateNext();
-        break;
-        case PaginationActionTypes.PAGINATE_PREVIOUS:
-          this.paginatePrevious();
-        break;
-        case PaginationActionTypes.PER_PAGE_CHANGE:
-          this.resetPagination();
-          this.setPerPage(action.perPage);
-        break;
+  getIsPrioritizedEnabled: function () {
+    return this._isPrioritizedEnabled;
+  },
 
-        default:
-        return;
-        // do nothing
-      }
+  getCurrentViewType: function () {
 
-      this.triggerChange();
+    if (this._tableView) {
+      return 'table';
     }
 
-  });
+    return 'expanded';
+  },
 
-  Stores.indexResultsStore = new Stores.IndexResultsStore();
+  getShowPrioritizedFieldToggler: function () {
+    return this.isIncludeDocsEnabled() && this.getIsTableView();
+  },
 
-  Stores.indexResultsStore.dispatchToken = FauxtonAPI.dispatcher.register(Stores.indexResultsStore.dispatch);
+  clearResultsBeforeFetch: function () {
+    if (this._collection && this._collection.reset) {
+      this._collection.reset();
+    }
+    this._isLoading = true;
+  },
+
+  resultsResetFromFetch: function () {
+    this._isLoading = false;
+  },
+
+  dispatch: function (action) {
+    switch (action.type) {
+      case ActionTypes.INDEX_RESULTS_NEW_RESULTS:
+        this.newResults(action.options);
+      break;
+      case ActionTypes.INDEX_RESULTS_RESET:
+        this.resultsResetFromFetch();
+      break;
+      case ActionTypes.INDEX_RESULTS_SELECT_DOC:
+        this.selectDoc(action.options);
+      break;
+      case ActionTypes.INDEX_RESULTS_CLEAR_RESULTS:
+        this.clearResultsBeforeFetch();
+      break;
+      case ActionTypes.INDEX_RESULTS_TOOGLE_SELECT_ALL_DOCUMENTS:
+        this.toggleSelectAllDocuments();
+      break;
+      case ActionTypes.INDEX_RESULTS_SELECT_NEW_FIELD_IN_TABLE:
+        this.changeTableViewFields(action.options);
+      break;
+      case ActionTypes.INDEX_RESULTS_TOGGLE_PRIORITIZED_TABLE_VIEW:
+        this.togglePrioritizedTableView();
+      break;
+
+      case HeaderActionTypes.TOGGLE_TABLEVIEW:
+        this.toggleTableView(action.options);
+      break;
+
+      case PaginationActionTypes.SET_PAGINATION_DOCUMENT_LIMIT:
+        this.setDocumentLimit(action.docLimit);
+      break;
+      case PaginationActionTypes.PAGINATE_NEXT:
+        this.paginateNext();
+      break;
+      case PaginationActionTypes.PAGINATE_PREVIOUS:
+        this.paginatePrevious();
+      break;
+      case PaginationActionTypes.PER_PAGE_CHANGE:
+        this.resetPagination();
+        this.setPerPage(action.perPage);
+      break;
+
+      default:
+      return;
+      // do nothing
+    }
 
-  return Stores;
+    this.triggerChange();
+  }
 
 });
+
+Stores.indexResultsStore = new Stores.IndexResultsStore();
+
+Stores.indexResultsStore.dispatchToken = FauxtonAPI.dispatcher.register(Stores.indexResultsStore.dispatch);
+
+export default Stores;

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ca35da7/app/addons/documents/index-results/tests/index-results.actionsSpec.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/index-results/tests/index-results.actionsSpec.js b/app/addons/documents/index-results/tests/index-results.actionsSpec.js
index f4ee3b1..dd64acf 100644
--- a/app/addons/documents/index-results/tests/index-results.actionsSpec.js
+++ b/app/addons/documents/index-results/tests/index-results.actionsSpec.js
@@ -10,93 +10,89 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
-define([
-  '../../../../core/api',
-  '../actions',
-  '../stores',
-  '../../resources',
-  '../../sidebar/actions',
-  '../../../../../test/mocha/testUtils',
-  '../../tests/document-test-helper',
-
-], function (FauxtonAPI, Actions, Stores, Documents, SidebarActions, testUtils, documentTestHelper) {
-  var assert = testUtils.assert;
-  var restore = testUtils.restore;
-  var store;
-
-  var createDocColumn = documentTestHelper.createDocColumn;
-
-  describe('#deleteSelected', function () {
-    var confirmStub;
-    var bulkDeleteCollection;
-
-    beforeEach(function () {
-      Stores.indexResultsStore = new Stores.IndexResultsStore();
-      Stores.indexResultsStore.dispatchToken = FauxtonAPI.dispatcher.register(Stores.indexResultsStore.dispatch);
-      store = Stores.indexResultsStore;
-      store.reset();
-
-      bulkDeleteCollection = new Documents.BulkDeleteDocCollection([], {databaseId: '1'});
-      store._bulkDeleteDocCollection = bulkDeleteCollection;
-      store._collection = createDocColumn([{_id: 'testId1'}, {_id: 'testId2'}]);
-
-      store._selectedItems = {
-        'testId1': true,
-        'testId2': true
-      };
-
-      confirmStub = sinon.stub(window, 'confirm');
-      confirmStub.returns(true);
-
-    });
-
-    afterEach(function () {
-      restore(window.confirm);
-      restore(FauxtonAPI.addNotification);
-      restore(Actions.reloadResultsList);
-      restore(SidebarActions.refresh);
-      restore(Actions.newResultsList);
-    });
-
-    it('doesn\'t delete if user denies confirmation', function () {
-      window.confirm.restore();
-
-      var stub = sinon.stub(window, 'confirm');
-      stub.returns(false);
-
-      var spy = sinon.spy(bulkDeleteCollection, 'bulkDelete');
-
-      Actions.deleteSelected(bulkDeleteCollection, 1);
-
-      assert.notOk(spy.calledOnce);
-    });
-
-    it('on success notifies all deleted', function (done) {
-      var spy = sinon.spy(FauxtonAPI, 'addNotification');
-      var sidebarSpy = sinon.spy(SidebarActions, 'refresh');
-      var promise = FauxtonAPI.Deferred();
-      var ids = {
-        errorIds: []
-      };
-      var bulkDelete = {
-        bulkDelete: function () {
-          promise.resolve(ids);
-          return promise;
-        },
-        reset: function () {
-          done();
-        }
-      };
-
-      var reloadResultsListStub = sinon.stub(Actions, 'reloadResultsList');
-      var stubPromise = FauxtonAPI.Deferred();
-      stubPromise.resolve();
-      reloadResultsListStub.returns(stubPromise);
-
-      Actions.deleteSelected(bulkDelete, 1);
-
-      assert.ok(spy.calledOnce);
-      assert.ok(sidebarSpy.calledOnce);
-    });
+import FauxtonAPI from "../../../../core/api";
+import Actions from "../actions";
+import Stores from "../stores";
+import Documents from "../../resources";
+import SidebarActions from "../../sidebar/actions";
+import testUtils from "../../../../../test/mocha/testUtils";
+import documentTestHelper from "../../tests/document-test-helper";
+var assert = testUtils.assert;
+var restore = testUtils.restore;
+var store;
+
+var createDocColumn = documentTestHelper.createDocColumn;
+
+describe('#deleteSelected', function () {
+  var confirmStub;
+  var bulkDeleteCollection;
+
+  beforeEach(function () {
+    Stores.indexResultsStore = new Stores.IndexResultsStore();
+    Stores.indexResultsStore.dispatchToken = FauxtonAPI.dispatcher.register(Stores.indexResultsStore.dispatch);
+    store = Stores.indexResultsStore;
+    store.reset();
+
+    bulkDeleteCollection = new Documents.BulkDeleteDocCollection([], {databaseId: '1'});
+    store._bulkDeleteDocCollection = bulkDeleteCollection;
+    store._collection = createDocColumn([{_id: 'testId1'}, {_id: 'testId2'}]);
+
+    store._selectedItems = {
+      'testId1': true,
+      'testId2': true
+    };
+
+    confirmStub = sinon.stub(window, 'confirm');
+    confirmStub.returns(true);
+
+  });
+
+  afterEach(function () {
+    restore(window.confirm);
+    restore(FauxtonAPI.addNotification);
+    restore(Actions.reloadResultsList);
+    restore(SidebarActions.refresh);
+    restore(Actions.newResultsList);
+  });
+
+  it('doesn\'t delete if user denies confirmation', function () {
+    window.confirm.restore();
+
+    var stub = sinon.stub(window, 'confirm');
+    stub.returns(false);
+
+    var spy = sinon.spy(bulkDeleteCollection, 'bulkDelete');
+
+    Actions.deleteSelected(bulkDeleteCollection, 1);
+
+    assert.notOk(spy.calledOnce);
+  });
+
+  it('on success notifies all deleted', function (done) {
+    var spy = sinon.spy(FauxtonAPI, 'addNotification');
+    var sidebarSpy = sinon.spy(SidebarActions, 'refresh');
+    var promise = FauxtonAPI.Deferred();
+    var ids = {
+      errorIds: []
+    };
+    var bulkDelete = {
+      bulkDelete: function () {
+        promise.resolve(ids);
+        return promise;
+      },
+      reset: function () {
+        done();
+      }
+    };
+
+    var reloadResultsListStub = sinon.stub(Actions, 'reloadResultsList');
+    var stubPromise = FauxtonAPI.Deferred();
+    stubPromise.resolve();
+    reloadResultsListStub.returns(stubPromise);
+
+    Actions.deleteSelected(bulkDelete, 1);
+
+    assert.ok(spy.calledOnce);
+    assert.ok(sidebarSpy.calledOnce);
   });
 });

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ca35da7/app/addons/documents/index-results/tests/index-results.componentsSpec.react.jsx
----------------------------------------------------------------------
diff --git a/app/addons/documents/index-results/tests/index-results.componentsSpec.react.jsx b/app/addons/documents/index-results/tests/index-results.componentsSpec.react.jsx
index 3092d62..11bf3a3 100644
--- a/app/addons/documents/index-results/tests/index-results.componentsSpec.react.jsx
+++ b/app/addons/documents/index-results/tests/index-results.componentsSpec.react.jsx
@@ -9,325 +9,322 @@
 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 // License for the specific language governing permissions and limitations under
 // the License.
-define([
-  '../../../../core/api',
-  '../index-results.components.react',
-  '../actions',
-  '../stores',
-  '../../resources',
-  '../../../databases/resources',
-  '../../tests/document-test-helper',
-  '../../../../../test/mocha/testUtils',
-  "react",
-  'react-dom',
-  'react-addons-test-utils',
-  'sinon'
-], function (FauxtonAPI, Views, IndexResultsActions, Stores, Documents, Databases, documentTestHelper, utils, React, ReactDOM, TestUtils,
-  sinon) {
-  FauxtonAPI.router = new FauxtonAPI.Router([]);
-
-  var assert = utils.assert;
-  var store = Stores.indexResultsStore;
-  var createDocColumn = documentTestHelper.createDocColumn;
-  var createMangoIndexDocColumn = documentTestHelper.createMangoIndexDocColumn;
-
-  describe('Index Results', function () {
-    var container, instance;
-
-    describe('no results text', function () {
-      beforeEach(function () {
-        container = document.createElement('div');
-        store.reset();
-      });
+import FauxtonAPI from "../../../../core/api";
+import Views from "../index-results.components.react";
+import IndexResultsActions from "../actions";
+import Stores from "../stores";
+import Documents from "../../resources";
+import Databases from "../../../databases/resources";
+import documentTestHelper from "../../tests/document-test-helper";
+import utils from "../../../../../test/mocha/testUtils";
+import React from "react";
+import ReactDOM from "react-dom";
+import TestUtils from "react-addons-test-utils";
+import sinon from "sinon";
+
+FauxtonAPI.router = new FauxtonAPI.Router([]);
+
+var assert = utils.assert;
+var store = Stores.indexResultsStore;
+var createDocColumn = documentTestHelper.createDocColumn;
+var createMangoIndexDocColumn = documentTestHelper.createMangoIndexDocColumn;
+
+describe('Index Results', function () {
+  var container, instance;
+
+  describe('no results text', function () {
+    beforeEach(function () {
+      container = document.createElement('div');
+      store.reset();
+    });
+
+    afterEach(function () {
+      ReactDOM.unmountComponentAtNode(ReactDOM.findDOMNode(instance).parentNode);
+      store.reset();
+    });
 
-      afterEach(function () {
-        ReactDOM.unmountComponentAtNode(ReactDOM.findDOMNode(instance).parentNode);
-        store.reset();
+    it('renders a default text', function () {
+      IndexResultsActions.newResultsList({
+        collection: [],
+        bulkCollection: new Documents.BulkDeleteDocCollection([], {databaseId: '1'}),
       });
+      IndexResultsActions.resultsListReset();
 
-      it('renders a default text', function () {
-        IndexResultsActions.newResultsList({
-          collection: [],
-          bulkCollection: new Documents.BulkDeleteDocCollection([], {databaseId: '1'}),
-        });
-        IndexResultsActions.resultsListReset();
+      instance = TestUtils.renderIntoDocument(<Views.List />, container);
+      var $el = $(ReactDOM.findDOMNode(instance));
+      assert.equal($el.text(), 'No Documents Found');
+    });
 
-        instance = TestUtils.renderIntoDocument(<Views.List />, container);
-        var $el = $(ReactDOM.findDOMNode(instance));
-        assert.equal($el.text(), 'No Documents Found');
+    it('you can change the default text', function () {
+      IndexResultsActions.newResultsList({
+        collection: {
+          forEach: function () {},
+          filter: function () { return []; },
+          fetch: function () {
+            return {
+              then: function (cb) {
+                cb();
+              }
+            };
+          }
+        },
+        bulkCollection: new Documents.BulkDeleteDocCollection([], {databaseId: '1'}),
+        textEmptyIndex: 'I <3 Hamburg'
       });
 
-      it('you can change the default text', function () {
-        IndexResultsActions.newResultsList({
-          collection: {
-            forEach: function () {},
-            filter: function () { return []; },
-            fetch: function () {
-              return {
-                then: function (cb) {
-                  cb();
-                }
-              };
-            }
-          },
-          bulkCollection: new Documents.BulkDeleteDocCollection([], {databaseId: '1'}),
-          textEmptyIndex: 'I <3 Hamburg'
-        });
-
-
-        instance = TestUtils.renderIntoDocument(<Views.List />, container);
-        var $el = $(ReactDOM.findDOMNode(instance));
-        assert.equal($el.text(), 'I <3 Hamburg');
-      });
+
+      instance = TestUtils.renderIntoDocument(<Views.List />, container);
+      var $el = $(ReactDOM.findDOMNode(instance));
+      assert.equal($el.text(), 'I <3 Hamburg');
     });
+  });
 
-    describe('checkbox rendering', function () {
-      var opts = {
-        params: {},
-        database: {
-          safeID: function () { return '1';}
-        }
-      };
-
-      beforeEach(function () {
-        container = document.createElement('div');
-        store.reset();
-      });
+  describe('checkbox rendering', function () {
+    var opts = {
+      params: {},
+      database: {
+        safeID: function () { return '1';}
+      }
+    };
+
+    beforeEach(function () {
+      container = document.createElement('div');
+      store.reset();
+    });
 
-      afterEach(function () {
-        ReactDOM.unmountComponentAtNode(ReactDOM.findDOMNode(instance).parentNode);
-        store.reset();
+    afterEach(function () {
+      ReactDOM.unmountComponentAtNode(ReactDOM.findDOMNode(instance).parentNode);
+      store.reset();
+    });
+
+    it('does not render checkboxes for elements with just the special index (Mango Index List)', function () {
+      IndexResultsActions.sendMessageNewResultList({
+        collection: createMangoIndexDocColumn([{foo: 'testId1', type: 'special'}]),
+        bulkCollection: new Documents.BulkDeleteDocCollection([], {databaseId: '1'}),
       });
 
-      it('does not render checkboxes for elements with just the special index (Mango Index List)', function () {
-        IndexResultsActions.sendMessageNewResultList({
-          collection: createMangoIndexDocColumn([{foo: 'testId1', type: 'special'}]),
-          bulkCollection: new Documents.BulkDeleteDocCollection([], {databaseId: '1'}),
-        });
+      store.toggleTableView({enable: true});
 
-        store.toggleTableView({enable: true});
+      IndexResultsActions.resultsListReset();
 
-        IndexResultsActions.resultsListReset();
+      instance = TestUtils.renderIntoDocument(
+        <Views.List />,
+        container
+      );
 
-        instance = TestUtils.renderIntoDocument(
-          <Views.List />,
-          container
-        );
+      var $el = $(ReactDOM.findDOMNode(instance));
 
-        var $el = $(ReactDOM.findDOMNode(instance));
+      assert.ok($el.find('.tableview-checkbox-cell input').length === 0);
+    });
 
-        assert.ok($el.find('.tableview-checkbox-cell input').length === 0);
+    it('renders checkboxes for elements with more than just the the special index (Mango Index List)', function () {
+      IndexResultsActions.sendMessageNewResultList({
+        collection: createMangoIndexDocColumn([{
+          ddoc: null,
+          name: 'biene',
+          type: 'json',
+          def: {fields: [{_id: 'desc'}]}
+        },
+        {
+          ddoc: null,
+          name: 'biene',
+          type: 'special',
+          def: {fields: [{_id: 'desc'}]}
+        }]),
+        bulkCollection: new Documents.BulkDeleteDocCollection([], {databaseId: '1'}),
       });
 
-      it('renders checkboxes for elements with more than just the the special index (Mango Index List)', function () {
-        IndexResultsActions.sendMessageNewResultList({
-          collection: createMangoIndexDocColumn([{
-            ddoc: null,
-            name: 'biene',
-            type: 'json',
-            def: {fields: [{_id: 'desc'}]}
-          },
-          {
-            ddoc: null,
-            name: 'biene',
-            type: 'special',
-            def: {fields: [{_id: 'desc'}]}
-          }]),
-          bulkCollection: new Documents.BulkDeleteDocCollection([], {databaseId: '1'}),
-        });
-
-        store.toggleTableView({enable: true});
-
-        IndexResultsActions.resultsListReset();
-
-        instance = TestUtils.renderIntoDocument(
-          <Views.List />,
-          container
-        );
-
-        var $el = $(ReactDOM.findDOMNode(instance));
-
-        assert.ok($el.find('.tableview-checkbox-cell input').length > 0);
+      store.toggleTableView({enable: true});
+
+      IndexResultsActions.resultsListReset();
+
+      instance = TestUtils.renderIntoDocument(
+        <Views.List />,
+        container
+      );
+
+      var $el = $(ReactDOM.findDOMNode(instance));
+
+      assert.ok($el.find('.tableview-checkbox-cell input').length > 0);
+    });
+
+    it('does not render checkboxes for elements with no id in a table (usual docs)', function () {
+      IndexResultsActions.sendMessageNewResultList({
+        collection: createDocColumn([{
+          ddoc: null,
+          name: 'biene',
+          type: 'special',
+          def: {fields: [{_id: 'desc'}]}
+        }]),
+        bulkCollection: new Documents.BulkDeleteDocCollection([], {databaseId: '1'}),
       });
 
-      it('does not render checkboxes for elements with no id in a table (usual docs)', function () {
-        IndexResultsActions.sendMessageNewResultList({
-          collection: createDocColumn([{
-            ddoc: null,
-            name: 'biene',
-            type: 'special',
-            def: {fields: [{_id: 'desc'}]}
-          }]),
-          bulkCollection: new Documents.BulkDeleteDocCollection([], {databaseId: '1'}),
-        });
+      store.toggleTableView({enable: true});
 
-        store.toggleTableView({enable: true});
+      IndexResultsActions.resultsListReset();
 
-        IndexResultsActions.resultsListReset();
+      instance = TestUtils.renderIntoDocument(
+        <Views.List />,
+        container
+      );
 
-        instance = TestUtils.renderIntoDocument(
-          <Views.List />,
-          container
-        );
+      var $el = $(ReactDOM.findDOMNode(instance));
 
-        var $el = $(ReactDOM.findDOMNode(instance));
+      assert.ok($el.find('.tableview-checkbox-cell input').length === 0);
+    });
 
-        assert.ok($el.find('.tableview-checkbox-cell input').length === 0);
+    it('does not render checkboxes for elements with no rev in a table (usual docs)', function () {
+      IndexResultsActions.sendMessageNewResultList({
+        collection: createDocColumn([{id: '1', foo: 'testId1'}, {id: '1', bar: 'testId1'}]),
+        bulkCollection: new Documents.BulkDeleteDocCollection([], {databaseId: '1'}),
       });
 
-      it('does not render checkboxes for elements with no rev in a table (usual docs)', function () {
-        IndexResultsActions.sendMessageNewResultList({
-          collection: createDocColumn([{id: '1', foo: 'testId1'}, {id: '1', bar: 'testId1'}]),
-          bulkCollection: new Documents.BulkDeleteDocCollection([], {databaseId: '1'}),
-        });
+      store.toggleTableView({enable: true});
 
-        store.toggleTableView({enable: true});
+      IndexResultsActions.resultsListReset();
 
-        IndexResultsActions.resultsListReset();
+      instance = TestUtils.renderIntoDocument(
+        <Views.List />,
+        container
+      );
 
-        instance = TestUtils.renderIntoDocument(
-          <Views.List />,
-          container
-        );
+      var $el = $(ReactDOM.findDOMNode(instance));
 
-        var $el = $(ReactDOM.findDOMNode(instance));
+      assert.ok($el.find('.tableview-checkbox-cell input').length === 0);
+    });
 
-        assert.ok($el.find('.tableview-checkbox-cell input').length === 0);
+    it('renders checkboxes for elements with an id and rev in a table (usual docs)', function () {
+      IndexResultsActions.sendMessageNewResultList({
+        collection: createDocColumn([{id: '1', foo: 'testId1', rev: 'foo'}, {bar: 'testId1', rev: 'foo'}]),
+        bulkCollection: new Documents.BulkDeleteDocCollection([], {databaseId: '1'}),
       });
 
-      it('renders checkboxes for elements with an id and rev in a table (usual docs)', function () {
-        IndexResultsActions.sendMessageNewResultList({
-          collection: createDocColumn([{id: '1', foo: 'testId1', rev: 'foo'}, {bar: 'testId1', rev: 'foo'}]),
-          bulkCollection: new Documents.BulkDeleteDocCollection([], {databaseId: '1'}),
-        });
+      store.toggleTableView({enable: true});
 
-        store.toggleTableView({enable: true});
+      IndexResultsActions.resultsListReset();
 
-        IndexResultsActions.resultsListReset();
+      instance = TestUtils.renderIntoDocument(
+        <Views.List />,
+        container
+      );
 
-        instance = TestUtils.renderIntoDocument(
-          <Views.List />,
-          container
-        );
+      var $el = $(ReactDOM.findDOMNode(instance));
 
-        var $el = $(ReactDOM.findDOMNode(instance));
+      assert.ok($el.find('.tableview-checkbox-cell input').length > 0);
+    });
 
-        assert.ok($el.find('.tableview-checkbox-cell input').length > 0);
+    it('renders checkboxes for elements with an id and rev in a json view (usual docs)', function () {
+      IndexResultsActions.sendMessageNewResultList({
+        collection: createDocColumn([{id: '1', emma: 'testId1', rev: 'foo'}, {bar: 'testId1'}]),
+        bulkCollection: new Documents.BulkDeleteDocCollection([], {databaseId: '1'}),
       });
 
-      it('renders checkboxes for elements with an id and rev in a json view (usual docs)', function () {
-        IndexResultsActions.sendMessageNewResultList({
-          collection: createDocColumn([{id: '1', emma: 'testId1', rev: 'foo'}, {bar: 'testId1'}]),
-          bulkCollection: new Documents.BulkDeleteDocCollection([], {databaseId: '1'}),
-        });
+      IndexResultsActions.resultsListReset();
 
-        IndexResultsActions.resultsListReset();
+      store.toggleTableView({enable: false});
 
-        store.toggleTableView({enable: false});
+      instance = TestUtils.renderIntoDocument(
+        <Views.List />,
+        container
+      );
 
-        instance = TestUtils.renderIntoDocument(
-          <Views.List />,
-          container
-        );
+      var $el = $(ReactDOM.findDOMNode(instance));
+      assert.ok($el.find('.js-row-select').length > 0);
+    });
 
-        var $el = $(ReactDOM.findDOMNode(instance));
-        assert.ok($el.find('.js-row-select').length > 0);
+    it('does not render checkboxes for elements with that are not deletable in a json view (usual docs)', function () {
+      IndexResultsActions.sendMessageNewResultList({
+        collection: createDocColumn([{foo: 'testId1', rev: 'foo'}, {bar: 'testId1'}]),
+        bulkCollection: new Documents.BulkDeleteDocCollection([], {databaseId: '1'}),
       });
 
-      it('does not render checkboxes for elements with that are not deletable in a json view (usual docs)', function () {
-        IndexResultsActions.sendMessageNewResultList({
-          collection: createDocColumn([{foo: 'testId1', rev: 'foo'}, {bar: 'testId1'}]),
-          bulkCollection: new Documents.BulkDeleteDocCollection([], {databaseId: '1'}),
-        });
+      IndexResultsActions.resultsListReset();
 
-        IndexResultsActions.resultsListReset();
+      store.toggleTableView({enable: false});
 
-        store.toggleTableView({enable: false});
+      instance = TestUtils.renderIntoDocument(
+        <Views.List />,
+        container
+      );
 
-        instance = TestUtils.renderIntoDocument(
-          <Views.List />,
-          container
-        );
+      var $el = $(ReactDOM.findDOMNode(instance));
 
-        var $el = $(ReactDOM.findDOMNode(instance));
+      assert.notOk($el.hasClass('show-select'));
+    });
 
-        assert.notOk($el.hasClass('show-select'));
-      });
+  });
 
+  describe('cellcontent', function () {
+    beforeEach(function () {
+      container = document.createElement('div');
+      store.reset();
     });
 
-    describe('cellcontent', function () {
-      beforeEach(function () {
-        container = document.createElement('div');
-        store.reset();
-      });
+    afterEach(function () {
+      ReactDOM.unmountComponentAtNode(ReactDOM.findDOMNode(instance).parentNode);
+      store.reset();
+    });
 
-      afterEach(function () {
-        ReactDOM.unmountComponentAtNode(ReactDOM.findDOMNode(instance).parentNode);
-        store.reset();
-      });
+    it('formats title elements for better readability', function () {
+      var doc = {object: {a: 1, foo: [1, 2, 3]}};
 
-      it('formats title elements for better readability', function () {
-        var doc = {object: {a: 1, foo: [1, 2, 3]}};
+      IndexResultsActions.sendMessageNewResultList({
+        collection: createDocColumn([doc]),
+        bulkCollection: new Documents.BulkDeleteDocCollection([], {databaseId: '1'}),
+      });
 
-        IndexResultsActions.sendMessageNewResultList({
-          collection: createDocColumn([doc]),
-          bulkCollection: new Documents.BulkDeleteDocCollection([], {databaseId: '1'}),
-        });
+      store.toggleTableView({enable: true});
 
-        store.toggleTableView({enable: true});
+      IndexResultsActions.resultsListReset();
 
-        IndexResultsActions.resultsListReset();
+      instance = TestUtils.renderIntoDocument(
+        <Views.List />,
+        container
+      );
 
-        instance = TestUtils.renderIntoDocument(
-          <Views.List />,
-          container
-        );
+      var $el = $(ReactDOM.findDOMNode(instance));
+      var $targetNode = $el.find('td.tableview-el-last').prev();
 
-        var $el = $(ReactDOM.findDOMNode(instance));
-        var $targetNode = $el.find('td.tableview-el-last').prev();
+      var formattedDoc = JSON.stringify(doc.object, null, '  ');
+      assert.equal($targetNode.attr('title'), formattedDoc);
+    });
 
-        var formattedDoc = JSON.stringify(doc.object, null, '  ');
-        assert.equal($targetNode.attr('title'), formattedDoc);
-      });
+  });
 
+  describe('loading', function () {
+    beforeEach(function () {
+      container = document.createElement('div');
+      store.reset();
     });
 
-    describe('loading', function () {
-      beforeEach(function () {
-        container = document.createElement('div');
-        store.reset();
-      });
-
-      afterEach(function () {
-        ReactDOM.unmountComponentAtNode(ReactDOM.findDOMNode(instance).parentNode);
-        store.reset();
-      });
+    afterEach(function () {
+      ReactDOM.unmountComponentAtNode(ReactDOM.findDOMNode(instance).parentNode);
+      store.reset();
+    });
 
-      it('should show loading component', function () {
-        var results = {results: []};
-        instance = TestUtils.renderIntoDocument(
-          <Views.ResultsScreen results={results} isLoading={true} />,
-          container
-        );
+    it('should show loading component', function () {
+      var results = {results: []};
+      instance = TestUtils.renderIntoDocument(
+        <Views.ResultsScreen results={results} isLoading={true} />,
+        container
+      );
 
-        var $el = $(ReactDOM.findDOMNode(instance));
+      var $el = $(ReactDOM.findDOMNode(instance));
 
-        assert.ok($el.find('.loading-lines').length === 1);
-      });
+      assert.ok($el.find('.loading-lines').length === 1);
+    });
 
-      it('should not show loading component', function () {
-        var results = {results: []};
-        instance = TestUtils.renderIntoDocument(
-          <Views.ResultsScreen results={results} isLoading={false} />,
-          container
-        );
+    it('should not show loading component', function () {
+      var results = {results: []};
+      instance = TestUtils.renderIntoDocument(
+        <Views.ResultsScreen results={results} isLoading={false} />,
+        container
+      );
 
-        var $el = $(ReactDOM.findDOMNode(instance));
+      var $el = $(ReactDOM.findDOMNode(instance));
 
-        assert.ok($el.find('.loading-lines').length === 0);
-      });
+      assert.ok($el.find('.loading-lines').length === 0);
     });
-
   });
+
 });


Mime
View raw message