Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / print_preview / settings / destination_settings.js
index 294cf79..d2a60d5 100644 (file)
@@ -14,10 +14,10 @@ cr.define('print_preview', function() {
    * @param {!print_preview.DestinationStore} destinationStore Used to determine
    *     the selected destination.
    * @constructor
-   * @extends {print_preview.Component}
+   * @extends {print_preview.SettingsSection}
    */
   function DestinationSettings(destinationStore) {
-    print_preview.Component.call(this);
+    print_preview.SettingsSection.call(this);
 
     /**
      * Used to determine the selected destination.
@@ -58,13 +58,25 @@ cr.define('print_preview', function() {
     ICON_MOBILE: 'destination-settings-icon-mobile',
     ICON_MOBILE_SHARED: 'destination-settings-icon-mobile-shared',
     LOCATION: 'destination-settings-location',
-    NAME: 'destination-settings-name'
+    NAME: 'destination-settings-name',
+    STALE: 'stale',
+    THOBBER_NAME: 'destination-throbber-name'
   };
 
   DestinationSettings.prototype = {
-    __proto__: print_preview.Component.prototype,
+    __proto__: print_preview.SettingsSection.prototype,
 
-    /** @param {boolean} Whether the component is enabled. */
+    /** @override */
+    isAvailable: function() {
+      return true;
+    },
+
+    /** @override */
+    hasCollapsibleContent: function() {
+      return false;
+    },
+
+    /** @override */
     set isEnabled(isEnabled) {
       var changeButton = this.getElement().getElementsByClassName(
           DestinationSettings.Classes_.CHANGE_BUTTON)[0];
@@ -73,7 +85,7 @@ cr.define('print_preview', function() {
 
     /** @override */
     enterDocument: function() {
-      print_preview.Component.prototype.enterDocument.call(this);
+      print_preview.SettingsSection.prototype.enterDocument.call(this);
       var changeButton = this.getElement().getElementsByClassName(
           DestinationSettings.Classes_.CHANGE_BUTTON)[0];
       this.tracker.add(
@@ -82,6 +94,11 @@ cr.define('print_preview', function() {
           this.destinationStore_,
           print_preview.DestinationStore.EventType.DESTINATION_SELECT,
           this.onDestinationSelect_.bind(this));
+      this.tracker_.add(
+          this.destinationStore_,
+          print_preview.DestinationStore.EventType.
+              CACHED_SELECTED_DESTINATION_INFO_READY,
+          this.onSelectedDestinationNameSet_.bind(this));
     },
 
     /**
@@ -99,24 +116,52 @@ cr.define('print_preview', function() {
      * @private
      */
     onDestinationSelect_: function() {
-      var destination = this.destinationStore_.selectedDestination;
-      var nameEl = this.getElement().getElementsByClassName(
-          DestinationSettings.Classes_.NAME)[0];
-      nameEl.textContent = destination.displayName;
-      nameEl.title = destination.displayName;
+      var destinationSettingsBoxEl =
+          this.getChildElement('.destination-settings-box');
 
-      var iconEl = this.getElement().getElementsByClassName(
-          DestinationSettings.Classes_.ICON)[0];
-      iconEl.src = destination.iconUrl;
-
-      var locationEl = this.getElement().getElementsByClassName(
-          DestinationSettings.Classes_.LOCATION)[0];
-      locationEl.textContent = destination.location;
-      locationEl.title = destination.location;
+      var destination = this.destinationStore_.selectedDestination;
+      if (destination != null) {
+        var nameEl = this.getElement().getElementsByClassName(
+            DestinationSettings.Classes_.NAME)[0];
+        nameEl.textContent = destination.displayName;
+        nameEl.title = destination.displayName;
+
+        var iconEl = this.getElement().getElementsByClassName(
+            DestinationSettings.Classes_.ICON)[0];
+        iconEl.src = destination.iconUrl;
+
+        var hint = destination.hint;
+        var locationEl = this.getElement().getElementsByClassName(
+            DestinationSettings.Classes_.LOCATION)[0];
+        locationEl.textContent = hint;
+        locationEl.title = hint;
+
+        var offlineStatusText = destination.offlineStatusText;
+        var offlineStatusEl =
+            this.getChildElement('.destination-settings-offline-status');
+        offlineStatusEl.textContent = offlineStatusText;
+        offlineStatusEl.title = offlineStatusText;
+
+        var isOffline = destination.isOffline;
+        destinationSettingsBoxEl.classList.toggle(
+            DestinationSettings.Classes_.STALE, isOffline);
+        setIsVisible(locationEl, !isOffline);
+        setIsVisible(offlineStatusEl, isOffline);
+      }
 
-      setIsVisible(this.getElement().querySelector('.throbber'), false);
       setIsVisible(
-          this.getElement().querySelector('.destination-settings-box'), true);
+          this.getChildElement('.throbber-container'),
+          this.destinationStore_.isAutoSelectDestinationInProgress);
+      setIsVisible(destinationSettingsBoxEl, !!destination);
+    },
+
+    onSelectedDestinationNameSet_: function() {
+      var destinationName =
+          this.destinationStore_.selectedDestination.displayName;
+      var nameEl = this.getElement().getElementsByClassName(
+          DestinationSettings.Classes_.THOBBER_NAME)[0];
+      nameEl.textContent = destinationName;
+      nameEl.title = destinationName;
     }
   };