options.js
Go to the documentation of this file.
1 /* options.js
2  * This will be loaded into the options dialog. It provides the dialog's
3  * controller.
4  */
5 // Make a namespace.
6 if (typeof foldersync == 'undefined') {
7  var foldersync = {};
8 };
9 
10 /* Option Dialog Controller
11  * Responsible for all stuff that is related to the Options Dialog
12  */
13 foldersync.options = {
14  // The init code for the dialog
15  onLoad: function(e){
16  // Get current preferences
17  this._getPref();
18  // En- / disable areas
19  this.onChange();
20  },
21 
22  // Updates all Preference UI elements with data from preference controller
23  _getPref: function(){
24  try{
25  // Helper for textboxes
26  var tx = function(id, value){
27  document.getElementById(id).value = value;
28  };
29  // Helper for checkboxes
30  var ck = function(id, value){
31  document.getElementById(id).checked = value;
32  };
33 
34  // Default tags
35  var dtags = foldersync.preferences.getDefaultTags();
36  for (var tagname in dtags)
37  tx("foldersync-options-tags-" + tagname, dtags[tagname]);
38  // Fallback
39  var fallbacks = foldersync.preferences.getFallbacks();
40  for (var tagname in fallbacks)
41  ck("foldersync-options-tags-" + tagname + "-fallback",
42  fallbacks[tagname]);
43  // UI
44  var ui = foldersync.preferences.getUIPrefs();
45  ck("foldersync-options-ui-notification", ui.notifications.isEnabled);
46  ck("foldersync-options-ui-notification-exclusive", ui.notifications.
47  onlyExclusive);
48  ck("foldersync-options-ui-show-favorite", ui.show.favorites);
49  ck("foldersync-options-ui-show-help", ui.show.help);
50  } catch(e){
51  foldersync.central.logEvent("options",
52  "Getting preferences failed:\n\n" + e, 1,
53  "chrome://foldersync/content/dialogs/" +
54  "options.js", e.lineNumber);
55  }
56  },
57 
58  // Writes all Preference UI element values to preference controller
59  _setPref: function(){
60  try{
61  // Helper for textboxes
62  var tx = function(id){
63  return document.getElementById(id).value;
64  };
65  // Helper for checkboxes
66  var ck = function(id){
67  return document.getElementById(id).checked;
68  };
69 
70  // Default tags
71  var dtags = foldersync.preferences.getDefaultTags();
72  for (var tagname in dtags)
73  dtags[tagname] = tx("foldersync-options-tags-" + tagname);
74  // Fallbacks
75  var fallbacks = foldersync.preferences.getFallbacks();
76  for (var tagname in fallbacks)
77  fallbacks[tagname] = ck("foldersync-options-tags-" + tagname +
78  "-fallback");
79  // UI
80  var ui = foldersync.preferences.getUIPrefs();
81  ui.notifications.isEnabled = ck("foldersync-options-ui-notification");
82  ui.notifications.onlyExclusive = ck("foldersync-options-ui-" +
83  "notification-exclusive");
84  ui.show.favorites = ck("foldersync-options-ui-show-favorite");
85  ui.show.help = ck("foldersync-options-ui-show-help");
86  } catch(e){
87  foldersync.central.logEvent("options",
88  "Setting preferences failed:\n\n" + e, 1,
89  "chrome://foldersync/content/dialogs/" +
90  "options.js", e.lineNumber);
91  }
92  },
93 
94  // Called on changes in relevant elements, en- and disables areas.
95  onChange: function(){
96  document.getElementById("foldersync-options-ui-notification-exclusive").
97  disabled = !document.getElementById("foldersync-options-ui-" +
98  "notification").checked;
99  document.getElementById("foldersync-options-tags-albumartist").
100  disabled = document.getElementById("foldersync-options-tags-" +
101  "albumartist-fallback").
102  checked;
103  },
104 
105  // Called on accepting dialog, must return true for the dialog to close
106  onAccept: function(){
107  // Save changes
108  this._setPref();
109  return true;
110  },
111 
112  // Shutdown code for the dialog
113  onUnload: function(e){
114  // on OS without Accept button: simulate accept on closing
115  if (window.navigator.platform.slice(0,3) != "Win")
116  this.onAccept();
117  },
118 }
119 
120 window.addEventListener("load",
121  function(e){
122  foldersync.options.onLoad(e);
123  },
124  false);
125 window.addEventListener("unload",
126  function(e){
127  foldersync.options.onUnload(e);
128  },
129  false);
menuItem id
Definition: FeedWriter.js:971
let window
Lastfm onLoad
Definition: mini.js:36
countRef value
Definition: FeedWriter.js:1423
function onUnload()
onUnload - called when the cover preview window unloads.
Definition: coverPreview.js:36