git-svn-id: svn://euphorik.ch/pompage@45 02bbb61a-6d21-0410-aba0-cb053bdfd66a
[pompage.git] / doc / webdeveloper / common / prompt.js
1 // Shows a clear confirmation
2 function webdeveloper_clearConfirmation(message)
3 {
4 var stringBundle = document.getElementById("webdeveloper-string-bundle");
5
6 return webdeveloper_confirmationDialog(stringBundle.getString("webdeveloper_clearConfirmation"), message, stringBundle.getString("webdeveloper_clear"));
7 }
8
9 // Shows a close confirmation
10 function webdeveloper_closeConfirmation(message)
11 {
12 var stringBundle = document.getElementById("webdeveloper-string-bundle");
13
14 return webdeveloper_confirmationDialog(stringBundle.getString("webdeveloper_closeConfirmation"), message, stringBundle.getString("webdeveloper_close"));
15 }
16
17 // Shows a confirmation dialog
18 function webdeveloper_confirmationDialog(title, message, buttonText)
19 {
20 // If the hide confirmation dialogs preference is not set to true
21 if(!webdeveloper_getBooleanPreference("webdeveloper.confirmation.dialogs.hide", true))
22 {
23 var checkBox = {value: false};
24 var promptServiceInterface = Components.interfaces.nsIPromptService;
25 var result = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(promptServiceInterface).confirmEx(null, title, message, promptServiceInterface.BUTTON_TITLE_IS_STRING * promptServiceInterface.BUTTON_POS_0 + promptServiceInterface.BUTTON_TITLE_CANCEL * promptServiceInterface.BUTTON_POS_1, buttonText, null, null, document.getElementById("webdeveloper-string-bundle").getString("webdeveloper_stopConfirmation"), checkBox);
26
27 // If the check box was checked
28 if(checkBox.value)
29 {
30 webdeveloper_setBooleanPreference("webdeveloper.confirmation.dialogs.hide", true);
31 }
32
33 // If the delete is confirmed
34 if(result == 0)
35 {
36 return true;
37 }
38
39 return false;
40 }
41
42 return true;
43 }
44
45 // Shows a delete confirmation
46 function webdeveloper_deleteConfirmation(message)
47 {
48 var stringBundle = document.getElementById("webdeveloper-string-bundle");
49
50 return webdeveloper_confirmationDialog(stringBundle.getString("webdeveloper_deleteConfirmation"), message, stringBundle.getString("webdeveloper_delete"));
51 }
52
53 // Shows an error message
54 function webdeveloper_error(message)
55 {
56 Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService).alert(null, document.getElementById("webdeveloper-string-bundle").getString("webdeveloper_errorMessage"), message);
57 }
58
59 // Shows an informational dialog
60 function webdeveloper_informationalDialog(title, message)
61 {
62 var checkBox = {value: false};
63 var promptServiceInterface = Components.interfaces.nsIPromptService;
64 var stringBundle = document.getElementById("webdeveloper-string-bundle");
65 var result = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(promptServiceInterface).alertCheck(null, title, message, stringBundle.getString("webdeveloper_stopInformational"), checkBox);
66
67 // If the check box was checked
68 if(checkBox.value)
69 {
70 webdeveloper_setBooleanPreference("webdeveloper.informational.dialogs.hide", true);
71 }
72 }
73
74 // Shows a message
75 function webdeveloper_message(title, message)
76 {
77 Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService).alert(null, title, message);
78 }