// See Purple/license.txt for Google BSD license
// Copyright 2011 Google, Inc. johnjbarton@johnjbarton.com

define(['lib/Base', 'lib/part', 'lib/q/q', 'lib/Assembly'], 
function (   Base, PurplePart,         Q,       Assembly) {
  
  var LogBase = Base.extend(PurplePart.prototype);
    
  LogBase.initialize = function(name) {
    PurplePart.apply(this, [name]);
    Assembly.addListenerContainer(this);
    this.implementsFeature('Log'); // proxy for enable
  };
  
  LogBase.connect = function(remoteCategory) {
    this.remoteCategory = remoteCategory;
  };
  
  LogBase.disconnect = function() {
    delete this.remoteCategory;
  };

  LogBase.getRemoteCategory = function() {
    if (!this.remoteCategory) {
      throw new Error("Connect before using remote category");
    }
    return this.remoteCategory;
  };
  
  LogBase.toggleEnable = function() {
    var abler = this.getRemoteCategory().enable;
    if (this.enabled) {
      abler = this.getRemoteCategory().disable;
    }
    
    var promiseAbled = abler.apply(this.getRemoteCategory, []);
    
    var log = this;
    Q.end(
      Q.when(promiseAbled, function(promiseAbled) {
        log.enabled = !log.enabled;
        log.toEachListener({type: 'logEnable', enabled: log.enabled});
        return this.enabled;
      }, function(err) {
        console.error("Enable FAILED: "+err, {stack: err.stack});
      })
    );
  };
    
  return LogBase;
});
@@ -495,66 +495,72 @@
 ion(
-remoteCategory) %7B%0A    this.remoteCategory = remoteCategory
+hasEnableDisable) %7B%0A    this.hasEnableDisable = hasEnableDisable
 ;%0A  
@@ -613,38 +613,40 @@
 delete this.
-remoteCategory
+hasEnableDisable
 ;%0A  %7D;%0A%0A  Lo
@@ -654,30 +654,32 @@
 Base.get
-RemoteCategory
+HasEnableDisable
  = funct
@@ -700,30 +700,32 @@
  (!this.
-remoteCategory
+hasEnableDisable
 ) %7B%0A    
@@ -809,22 +809,24 @@
 his.
-remoteCategory
+hasEnableDisable
 ;%0A  
@@ -893,30 +893,32 @@
 this.get
-RemoteCategory
+HasEnableDisable
 ().enabl
@@ -966,30 +966,32 @@
 this.get
-RemoteCategory
+HasEnableDisable
 ().disab
@@ -1052,22 +1052,24 @@
 .get
-RemoteCategory
+HasEnableDisable
 , %5B%5D

rename remoteCategory to more abstract hasEnableDisable