home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 March / Chip_2011.03_CD.iso / Tools / yabar.msi / fil8B34879761963DD402AB9F812871DD39 < prev    next >
Encoding:
Text File  |  2010-04-16  |  3.7 KB  |  134 lines

  1. var YaCity = {
  2.   nsIYa: Components.classes["@yandex.ru/yasearch;1"]
  3.                    .getService(Components.interfaces.nsIYaSearch)
  4.                    .wrappedJSObject,
  5.   
  6.   nsIYaAutoComplete: Components.classes["@mozilla.org/autocomplete/search;1?name=YasearchCity"]
  7.                                .getService(Components.interfaces.nsIYaCityAComplete)
  8.                                .wrappedJSObject,
  9.   
  10.   get yaCityComponent() {
  11.     return this.nsIYa.yaCity;
  12.   },
  13.   
  14.   _autoCity: {id: 0, label: ""},
  15.   
  16.   _res: 0,
  17.   
  18.   accepted: false,
  19.   
  20.   init: function() {
  21.     this.stringBundleSet = document.getElementById("yasearch-string-bundle-city");
  22.     
  23.     this.toolbarButtonId = window.arguments[0];
  24.     
  25.     this.removeButtonOnCancel = !!window.arguments[1];
  26.     
  27.     this.textLabel = document.getElementById("yasearch-city-city");
  28.     
  29.     setTimeout(function(me) {
  30.       me.nsIYaAutoComplete.prepeareForNewSearch();
  31.       me.refreshCitiesList(me.yaCityComponent.citiesData);
  32.     }, 0, this);
  33.   },
  34.   
  35.   handleCityChange: function(event) {
  36.     let city = event.target;
  37.     
  38.     if (city.hasAttribute("gid") && city.nodeName == "label")
  39.       this.setCity(city.getAttribute("gid"), city.value);
  40.   },
  41.   
  42.   onSearchComplete: function() {
  43.     this._res = this.nsIYaAutoComplete.lastResult.id;
  44.   },
  45.   
  46.   onTextChanged: function(aType) {
  47.     let lastResult = this.nsIYaAutoComplete.lastResult;
  48.     this._res = this.textLabel.value == lastResult.city ? lastResult.id : "0";
  49.     return true;
  50.   },
  51.   
  52.   setCity: function(aId, aLabel) {
  53.     this._res = aId;
  54.     this.textLabel.value = aLabel;
  55.     
  56.     this.nsIYaAutoComplete.lastResult = {id: aId, city: aLabel};
  57.   },
  58.   
  59.   setAutoCity: function(aCity) {
  60.     if (YaCity.textLabel.value != "")
  61.       return;
  62.     
  63.     var cityObj = aCity || this._autoCity;
  64.     this.setCity(cityObj.id, cityObj.label);
  65.   },
  66.   
  67.   refreshCitiesList: function(aData) {
  68.     if (typeof YaCity != "undefined") {
  69.       if (!aData)
  70.         return false;
  71.       
  72.       YaCity.textLabel.disabled = false;
  73.       
  74.       var buttonProps = YaCity.yaCityComponent.getCityProps(YaCity.toolbarButtonId);
  75.       
  76.       if (buttonProps.cityId) {
  77.         var cityElement = aData..region.(@id == buttonProps.cityId)[0];
  78.         if (cityElement) {
  79.           YaCity.setAutoCity({id: buttonProps.cityId, label: cityElement.@name.toString()});
  80.           return true;
  81.         }
  82.       }
  83.     }
  84.     
  85.     return true;
  86.   },
  87.   
  88.   get _subPrefs() {
  89.     return (window.opener && "YaSubPrefs" in window.opener) ? window.opener.YaSubPrefs : null;
  90.   },
  91.   
  92.   onDialogAccept: function() {
  93.     if (!this._res) {
  94.       this.nsIYa.promptService.alert(window,
  95.           YaCity.stringBundleSet.getString("ErrorNoCityTitle"),
  96.           YaCity.stringBundleSet.getString("ErrorNoCity"));
  97.       return false;
  98.     }
  99.     
  100.     this.accepted = true;
  101.     
  102.     let cityId = this._res,
  103.         label = this.textLabel.value;
  104.     
  105.     if (cityId == "0")
  106.       cityId = label = "";
  107.     
  108.     this.yaCityComponent.updateButtonProps(this.toolbarButtonId,
  109.       {
  110.         cityId: cityId,
  111.         label: label,
  112.         weatherEnabledValue: "",
  113.         trafficEnabledValue: ""
  114.       }
  115.     );
  116.     
  117.     let prefs = this._subPrefs;
  118.     if (prefs && ("changeLabelFromCityWindow" in prefs))
  119.       prefs.changeLabelFromCityWindow(this.toolbarButtonId, label);
  120.     
  121.     this.yaCityComponent.updateCityInfo(this.toolbarButtonId, true);
  122.     
  123.     return true;
  124.   },
  125.   
  126.   onDialogUnload: function() {
  127.     if (this.removeButtonOnCancel && !this.accepted && this.toolbarButtonId)
  128.       this.yaCityComponent.removeToolbaritem(this.toolbarButtonId);
  129.     
  130.     let prefs = this._subPrefs;
  131.     if (prefs && ("resizeWindow" in prefs))
  132.       prefs.resizeWindow();
  133.   }
  134. };