Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / print_preview / data / destination.js
index 8918263..e37427c 100644 (file)
@@ -19,7 +19,8 @@ cr.define('print_preview', function() {
    * @param {{tags: Array.<string>,
    *          isOwned: ?boolean,
    *          lastAccessTime: ?number,
-   *          isTosAccepted: ?boolean}=} opt_params Optional parameters for the
+   *          isTosAccepted: ?boolean,
+   *          cloudID: ?string}=} opt_params Optional parameters for the
    *     destination.
    * @constructor
    */
@@ -112,6 +113,13 @@ cr.define('print_preview', function() {
      * @private
      */
     this.isTosAccepted_ = (opt_params && opt_params.isTosAccepted) || false;
+
+    /**
+     * Cloud ID for privet printers
+     * @type {?string}
+     * @private
+     */
+    this.cloudID_ = (opt_params && opt_params.cloudID) || '';
   };
 
   /**
@@ -149,7 +157,8 @@ cr.define('print_preview', function() {
     LOCAL: 'local',
     COOKIES: 'cookies',
     PROFILE: 'profile',
-    DEVICE: 'device'
+    DEVICE: 'device',
+    PRIVET: 'privet'
   };
 
   /**
@@ -160,7 +169,8 @@ cr.define('print_preview', function() {
     DORMANT: 'DORMANT',
     OFFLINE: 'OFFLINE',
     ONLINE: 'ONLINE',
-    UNKNOWN: 'UNKNOWN'
+    UNKNOWN: 'UNKNOWN',
+    UNREGISTERED: 'UNREGISTERED'
   };
 
   /**
@@ -225,7 +235,15 @@ cr.define('print_preview', function() {
 
     /** @return {boolean} Whether the destination is local or cloud-based. */
     get isLocal() {
-      return this.origin_ == Destination.Origin.LOCAL;
+      return this.origin_ == Destination.Origin.LOCAL ||
+             (this.origin_ == Destination.Origin.PRIVET &&
+              this.connectionStatus_ !=
+              Destination.ConnectionStatus.UNREGISTERED);
+    },
+
+    /** @return {boolean} Whether the destination is a privet local printer */
+    get isPrivet() {
+      return this.origin_ == Destination.Origin.PRIVET;
     },
 
     /**
@@ -234,6 +252,7 @@ cr.define('print_preview', function() {
      */
     get location() {
       if (this.location_ == null) {
+        this.location_ = '';
         for (var tag, i = 0; tag = this.tags_[i]; i++) {
           if (tag.indexOf(Destination.LOCATION_TAG_PREFIX) == 0) {
             this.location_ = tag.substring(
@@ -250,6 +269,11 @@ cr.define('print_preview', function() {
       return this.tags_.slice(0);
     },
 
+    /** @return {string} Cloud ID associated with the destination */
+    get cloudID() {
+      return this.cloudID_;
+    },
+
     /** @return {print_preview.Cdd} Print capabilities of the destination. */
     get capabilities() {
       return this.capabilities_;
@@ -279,6 +303,32 @@ cr.define('print_preview', function() {
       this.connectionStatus_ = status;
     },
 
+    /** @return {boolean} Whether the destination is considered offline. */
+    get isOffline() {
+      return arrayContains([print_preview.Destination.ConnectionStatus.OFFLINE,
+                            print_preview.Destination.ConnectionStatus.DORMANT],
+                            this.connectionStatus_);
+    },
+
+    /** @return {string} Human readable status for offline destination. */
+    get offlineStatusText() {
+      if (!this.isOffline) {
+        return '';
+      }
+      var offlineDurationMs = Date.now() - this.lastAccessTime_;
+      var offlineMessageId;
+      if (offlineDurationMs > 31622400000.0) {  // One year.
+        offlineMessageId = 'offlineForYear';
+      } else if (offlineDurationMs > 2678400000.0) {  // One month.
+        offlineMessageId = 'offlineForMonth';
+      } else if (offlineDurationMs > 604800000.0) {  // One week.
+        offlineMessageId = 'offlineForWeek';
+      } else {
+        offlineMessageId = 'offline';
+      }
+      return localStrings.getString(offlineMessageId);
+    },
+
     /**
      * @return {number} Number of milliseconds since the epoch when the printer
      *     was last accessed.