saveprofile.js
Go to the documentation of this file.
1 /* saveprofile.js
2  * This will be loaded into the save profile dialog. It provides the dialog's
3  * controller.
4  */
5 // Make a namespace.
6 if (typeof foldersync == 'undefined') {
7  var foldersync = {};
8 };
9 
10 /* Save Profile Dialog Controller
11  * Responsible for all stuff that is related to the Save Profile Dialog
12  */
13 foldersync.saveprofile = {
14  // If we cleared the name field already
15  _clearedName: false,
16 
17  // Startup code for the save profile dialog
18  onLoad: function(e){
19  // Update en-/disabled state of controls
20  this.onRChange();
21  this.reloadProfiles();
22  },
23 
24  // En-/Disables controls depending on current selection
25  onRChange: function(e){
26  var rGroup = document.getElementById("foldersync-saveprofile-radio");
27  var nName = document.getElementById("foldersync-saveprofile-new-name");
28  var uList = document.getElementById("foldersync-savedprofile-" +
29  "update-profile");
30  if (rGroup.selectedIndex == 0){ // new profile
31  nName.disabled = false;
32  uList.disabled = true;
33  } else { // update profile
34  nName.disabled = true;
35  uList.disabled = false;
36  }
37  },
38 
39  // Writes the result to window's arguments, return null. Called on accepting
40  onAccept: function(){
41  var rGroup = document.getElementById("foldersync-saveprofile-radio");
42  var nName = document.getElementById("foldersync-saveprofile-new-name");
43  var uList = document.getElementById("foldersync-savedprofile-" +
44  "update-profile");
45  window.arguments[0].action = rGroup.selectedIndex == 0 ? "new" : "update";
46  window.arguments[0].profile = uList.selectedItem.value;
47  window.arguments[0].name = nName.value;
48  return true;
49  },
50 
51  // Clears the name textbox
52  onNameFocus: function(){
53  if (!this._clearedName){
54  document.getElementById("foldersync-saveprofile-new-name").value = "";
55  this._clearedName = true;
56  }
57  },
58 
59  // Load Profiles in menupopup of profile combo box; restore old selection
60  reloadProfiles: function(){
61  try {
62  var uList = document.getElementById("foldersync-savedprofile-" +
63  "update-profile");
64  var popup = document.getElementById("foldersync-savedprofile-" +
65  "update-profile-popup");
66  // Get the current selection, if any
67  var cSelection = null;
68  var cIndex = uList.selectedIndex;
69  if (cIndex >= 0)
70  cSelection = popup.childNodes[cIndex].value;
71  // Clear popup
72  while (popup.childNodes.length > 0)
73  popup.removeChild(popup.childNodes[0]);
74  // Add all profiles
75  var selected = false; // we selected the prior selected profile?
76  var profiles = foldersync.preferences.getProfiles();
77  for each (var profile in profiles){
78  if (!profile.visible)
79  continue; // We don't want to show invisible profiles
80  var node = document.createElement("menuitem");
81  node.value = profile.GUID;
82  node.setAttribute("label", profile.name);
83  popup.appendChild(node);
84  // Restore selection
85  if (cSelection == node.value){
86  uList.selectedItem = node;
87  selected = true;
88  }
89  }
90  // Select first if the profile just got deleted / we're starting
91  if (!selected)
92  uList.selectedIndex = 0;
93  } catch (e){
94  foldersync.central.logEvent("saveprofile",
95  "Loading Profiles failed:\n\n" + e, 1,
96  "chrome://foldersync/content/" +
97  "dialogs/saveprofile.js", e.lineNumber);
98  }
99  },
100 
101  // Shutdown code for the save profile dialog
102  onUnload: function(e){
103 
104  },
105 };
106 
107 window.addEventListener("load",
108  function(e){
109  foldersync.saveprofile.onLoad(e);
110  },
111  false);
112 window.addEventListener("unload",
113  function(e){
114  foldersync.saveprofile.onUnload(e);
115  },
116  false);
let window
Lastfm onLoad
Definition: mini.js:36
return null
Definition: FeedWriter.js:1143
let node
function onUnload()
onUnload - called when the cover preview window unloads.
Definition: coverPreview.js:36