options.js
Go to the documentation of this file.
1 if (typeof Cc == 'undefined')
2  var Cc = Components.classes;
3 if (typeof Ci == 'undefined')
4  var Ci = Components.interfaces;
5 
6 #ifdef METRICS_ENABLED
7 if (typeof(gMetrics) == "undefined")
8  var gMetrics = Cc["@songbirdnest.com/Songbird/Metrics;1"]
9  .createInstance(Ci.sbIMetrics);
10 #endif
11 
12 Components.utils.import("resource://app/jsmodules/sbColumnSpecParser.jsm");
13 
15  pCountry : null,
16  pState : null,
17  pCity : null,
18 
19  init : function() {
20  this.pCountry =
21  Application.prefs.getValue("extensions.concerts.country", 1);
22  this.pState =
23  Application.prefs.getValue("extensions.concerts.state", 0);
24  this.pCity =
25  Application.prefs.getValue("extensions.concerts.city", 0);
26 
27  var countryDropdown = document.getElementById("menulist-country");
28  var statesDropdown = document.getElementById("menulist-state");
29  var citiesDropdown = document.getElementById("menulist-city");
30 
31  // Get our Songkick & JSON XPCOM components
32  this.skSvc = Cc["@songbirdnest.com/Songbird/Concerts/Songkick;1"]
33  .getService(Ci.sbISongkick);
34  this.json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
35 
36  if (!this.skSvc.gotLocationInfo()) {
37  this.skSvc.refreshLocations();
38 
39  var self = this;
40  var interval = setInterval(function () {
41  if (!this.skSvc.locationRefreshRunning) {
42  // Clear the interval so we are not called anymore.
43  clearInterval(interval);
44 
45  // Check again to see if we have the location info, if not show the error.
46  if ( !this.skSvc.gotLocationInfo() ) {
47  ConcertTicketing.showTimeoutError();
48  }
49  else {
50  self._populateInformation();
51  }
52  }
53  }, 100); // Checking every 100ms
54  }
55 
56  this._populateInformation();
57  },
58 
59  _populateInformation: function() {
60  // Populate the countries dropdown and pre-select our saved pref
61  this._populateCountries(this.pCountry);
62 
63  // Populate the states dropdown and pre-select our saved pref
64  this._populateStates(this.pCountry, this.pState);
65 
66  // Populate the cities dropdown and pre-select our saved pref
67  this._populateCities(this.pState, this.pCity);
68  },
69 
70  _populateCountries : function(selectedCountry) {
71  var countries = this.json.decode(this.skSvc.getLocationCountries());
72  var countryDropdown = document.getElementById("menulist-country");
73  countryDropdown.removeAllItems();
74  var idx = 0;
75  for (var i=0; i<countries.length; i++) {
76  var country = countries[i].name;
77  if (country == "US")
78  country = "United States";
79  else if (country == "UK")
80  country = "United Kingdom";
81  countryDropdown.appendItem(country, countries[i].id);
82  if (countries[i].id == selectedCountry)
83  idx = i;
84  }
85  countryDropdown.selectedIndex = idx;
86  },
87 
88  _populateStates : function(inCountry, selectedState) {
89  this._states =
90  this.json.decode(this.skSvc.getLocationStates(inCountry));
91  this._states.sort( function(a, b) {
92  return (a.name > b.name); })
93  var stateDropdown = document.getElementById("menulist-state");
94  stateDropdown.removeAllItems();
95  // catch the UK/New Zealand case where there are no "states"
96  if (this._states.length == 1 &&
97  (this._states[0].name == "" ||
98  this._states[0].name.indexOf("&lt;countrywide&gt;")))
99  {
100  // The "state" is the whole country
101  stateDropdown.disabled = true;
102  this._populateCities(this._states[0].id);
103  this.pState = this._states[0].id;
104  } else {
105  // Multiple states
106  stateDropdown.disabled = false;
107  var idx = 0;
108  for (let i=0; i<this._states.length; i++) {
109  stateDropdown.appendItem(this._states[i].name,
110  this._states[i].id);
111  if (this._states[i].id == selectedState)
112  idx = i;
113  }
114  stateDropdown.selectedIndex = idx;
115  this._populateCities(stateDropdown.selectedItem.value);
116  }
117  },
118 
119  _populateCities : function(inState, selectedCity) {
120  var cities = this.json.decode(this.skSvc.getLocationCities(inState));
121  cities.sort( function(a, b) {
122  return (a.name > b.name); })
123  var citiesDropdown = document.getElementById("menulist-city");
124  citiesDropdown.removeAllItems();
125  var idx = 0;
126  for (let i=0; i<cities.length; i++) {
127  citiesDropdown.appendItem(cities[i].name, cities[i].id);
128  if (cities[i].id == selectedCity)
129  idx = i;
130  }
131  citiesDropdown.selectedIndex = idx;
132  },
133 
134  changeCountry : function(list) {
135  var countryId = list.selectedItem.value;
136  this._populateStates(countryId);
137  },
138 
139  changeState : function(list) {
140  var stateId = list.selectedItem.value;
141  this._populateCities(stateId);
142  },
143 
144  changeCity : function(list) {
145  },
146 
147  cancel : function() {
148  var deck = document.getElementById("concerts-deck");
149  var prev = 0;
150  if (deck.hasAttribute("previous-selected-deck"))
151  prev = deck.getAttribute("previous-selected-deck");
152  deck.setAttribute("selectedIndex", prev);
153  },
154 
155  save : function() {
156  var countryDropdown = document.getElementById("menulist-country");
157  var statesDropdown = document.getElementById("menulist-state");
158  var citiesDropdown = document.getElementById("menulist-city");
159 
160  // only save city to a temporary, and make the preference
161  // permanent only in _processConcerts
162  var country = parseInt(countryDropdown.selectedItem.value);
163  var city = parseInt(citiesDropdown.selectedItem.value);
164 
165  // unless this is firstrun, then let's save it permanently
166  if (Application.prefs.getValue("extensions.concerts.firstrun", false)) {
167  Application.prefs.setValue("extensions.concerts.country", country);
168  Application.prefs.setValue("extensions.concerts.city", city);
169  if (!statesDropdown.disabled) {
170  var state = parseInt(statesDropdown.selectedItem.value);
171  Application.prefs.setValue("extensions.concerts.state", state);
172  }
173  }
174 
175 #ifdef METRICS_ENABLED
176  gMetrics.metricsInc("concerts", "change.location", "");
177 #endif
178  var box = document.getElementById("library-ontour-box");
179  if (box.style.visibility != "hidden") {
180  var check = document.getElementById("checkbox-library-integration");
181  if (check.checked) {
182 #ifdef METRICS_ENABLED
183  gMetrics.metricsInc("concerts", "library.ontour.checked", "");
184 #endif
185  // Get the library colspec. If it's not null, then append
186  // the On Tour image property to it
187  var parser = new ColumnSpecParser(LibraryUtils.mainLibrary, null, null,
188  "audio");
189  var foundProperty = false;
190  // Scan to see if the concerts property is there already.
191  for each (var column in parser.columnMap) {
192  if (column.property == this.skSvc.onTourImgProperty) {
193  foundProperty = true;
194  break;
195  }
196  }
197 
198  // Only add the property if it's not already there
199  if (!foundProperty) {
200  // Make room for it
201  ColumnSpecParser.reduceWidthsProportionally(parser.columnMap, 58);
202  // Turn the colspec into a proper string
203  var colspec = "";
204  for each (var column in parser.columnMap) {
205  colspec += column.property + " " +
206  column.width + " ";
207  if (column.property == parser.sortID) {
208  if (parser.sortIsAscending)
209  colspec += "a ";
210  else
211  colspec += "d ";
212  }
213  }
214  colspec += this.skSvc.onTourImgProperty + " 58";
215  var property = SBProperties.columnSpec + "+(audio)";
216  LibraryUtils.mainLibrary.setProperty(property, colspec);
217  }
218  }
219  }
220  ConcertTicketing.loadConcertData(city);
221  },
222 };
const Cc
var Application
Definition: sbAboutDRM.js:37
_window init
Definition: FeedWriter.js:1144
var ConcertOptions
Definition: options.js:14
return null
Definition: FeedWriter.js:1143
function check(ch, cx)
const Ci
Javascript wrappers for common library tasks.
_getSelectedPageStyle s i