summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/base/content/newFolderDialog.js
blob: 2476f198b000d944a42afe41d46704b20c1cc15c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

var FOLDERS = 1;
var MESSAGES = 2;
var dialog;

window.addEventListener("DOMContentLoaded", onLoad);
document.addEventListener("dialogaccept", onOK);

function onLoad() {
  var windowArgs = window.arguments[0];

  dialog = {};

  dialog.nameField = document.getElementById("name");
  dialog.nameField.focus();

  // call this when OK is pressed
  dialog.okCallback = windowArgs.okCallback;

  // pre select the folderPicker, based on what they selected in the folder pane
  dialog.folder = windowArgs.folder;
  try {
    document
      .getElementById("MsgNewFolderPopup")
      .selectFolder(windowArgs.folder);
  } catch (ex) {
    // selected a child folder
    document
      .getElementById("msgNewFolderPicker")
      .setAttribute("label", windowArgs.folder.prettyName);
  }

  // can folders contain both folders and messages?
  if (windowArgs.dualUseFolders) {
    dialog.folderType = FOLDERS | MESSAGES;

    // hide the section when folder contain both folders and messages.
    var newFolderTypeBox = document.getElementById("newFolderTypeBox");
    newFolderTypeBox.setAttribute("hidden", "true");
  } else {
    // set our folder type by calling the default selected type's oncommand
    document.getElementById("folderGroup").selectedItem.doCommand();
  }

  doEnabling();
}

function onFolderSelect(event) {
  dialog.folder = event.target._folder;
  document
    .getElementById("msgNewFolderPicker")
    .setAttribute("label", dialog.folder.prettyName);
}

function onOK() {
  var name = dialog.nameField.value;

  // do name validity check?

  // make sure name ends in  "/" if folder to create can only contain folders
  if (dialog.folderType == FOLDERS && !name.endsWith("/")) {
    dialog.okCallback(name + "/", dialog.folder);
  } else {
    dialog.okCallback(name, dialog.folder);
  }
}

function onFoldersOnly() {
  dialog.folderType = FOLDERS;
}

function onMessagesOnly() {
  dialog.folderType = MESSAGES;
}

function doEnabling() {
  document.querySelector("dialog").getButton("accept").disabled =
    !dialog.nameField.value;
}