{"size": 1881, "ext": "js", "max_stars_repo_path": "src/collections/PasswordProtectedCollectionBase.js", "max_stars_repo_name": "Acidburn0zzz/SpiderOakMobileClient", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/collections/PasswordProtectedCollectionBase.js", "max_issues_repo_name": "Acidburn0zzz/SpiderOakMobileClient", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/collections/PasswordProtectedCollectionBase.js", "max_forks_repo_name": "Acidburn0zzz/SpiderOakMobileClient", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 30.8360655738, "max_line_length": 75, "alphanum_fraction": 0.6081871345}
/**
 * PasswordProtectedCollectionBase.js
 */
(function (spiderOakApp, window, undefined) {
  "use strict";
  var console = window.console || {};
  console.log = console.log || function(){};
  var Backbone    = window.Backbone,
      _           = window._,
      $           = window.$;

  /** Provide for password-protected remote collections of items.
   *
   * Unlike password-protected models, we behave unquivocally according to
   * the presence of a password in the object, and temporarily adjust the
   * app's basic authentication accordingly.
   */
  var cb = spiderOakApp.CollectionBase;
  spiderOakApp.PasswordProtectedCollectionBase = cb.extend({
    sync: function (method, model, options) {
      if (this.getPassword()) {
        /* Temporarily set basic auth for the item password, and restore
           the prevailing basic auth upon return. */
        var bam = spiderOakApp.accountModel.basicAuthManager;
        bam.setAlternateBasicAuth(
          "blank",            // Doesn't matter - username is not regarded.
          this.getPassword()  // The salient thing is the password.
        );
        try {
          return cb.prototype.sync.apply(this, arguments);
        }
        finally {
          bam.resumeAccountBasicAuth();
        }
      }
      else {
        return cb.prototype.sync.apply(this, arguments);
      }
    },
    setPassword: function (password) {
      if (this.getPassword() !== password) {
        this.password = password;
      }
    },
    getPassword: function() {
      return this.password;
    },
    removePassword: function () {
      if (this.getPassword()) {
        this.setPassword("");
      }
    },
    clear: function () {
      this.removePassword();
      cb.prototype.clear.call(this);
    },
    which: "PasswordProtectedCollectionBase"
  });

})(window.spiderOakApp = window.spiderOakApp || {}, window);
