|
1 /*! |
|
2 \file prompt.js This module contains the promptDialog class which |
|
3 displays messages. |
|
4 */ |
|
5 |
|
6 function promptDialog() { |
|
7 var onChromeComplete = function() |
|
8 { |
|
9 // Get external mouse events. |
|
10 snippets.PromptChromeId.externalMouseEvent.connect(this.handleExternalMouseEvent.bind(this)); |
|
11 |
|
12 // Watch for page load errors. |
|
13 |
|
14 window.pageController.databaseQuotaExceeded.connect( |
|
15 function() { |
|
16 update(); |
|
17 showPrompt(); |
|
18 } |
|
19 ); |
|
20 |
|
21 } |
|
22 |
|
23 //! Add text to the given DOM element, truncate it at the given width (in pixels). |
|
24 //! Returns the remainder of the string. |
|
25 function truncateTextToWidth(element, text, width) |
|
26 { |
|
27 element.innerHTML = '<span style="white-space:nowrap;">' + text + '</span>'; |
|
28 if(element.offsetWidth > width) |
|
29 { |
|
30 var i = 1; |
|
31 element.innerHTML = ''; |
|
32 while(element.offsetWidth < (width) && i < text.length) |
|
33 { |
|
34 element.innerHTML = text.substr(0,i); |
|
35 i++; |
|
36 } |
|
37 return text.substr(i-1); |
|
38 } |
|
39 return ""; |
|
40 } |
|
41 |
|
42 //! Update text elements with error info. |
|
43 var update = function() |
|
44 { |
|
45 // Set URL. Two lines of it are displayed, the first wraps to the second and the second |
|
46 // is truncated with an ellipsis appended by CSS. |
|
47 document.getElementById("promptTextUrl2Id").innerHTML = pageController.promptReserved; |
|
48 |
|
49 // Set error message. |
|
50 if(pageController.promptMsg != undefined && pageController.promptMsg != "") { |
|
51 document.getElementById("promptTextMsgId").innerHTML = pageController.promptMsg; |
|
52 } |
|
53 else { |
|
54 document.getElementById("promptTextMsgId").innerHTML = window.localeDelegate.translateText("txt_browser_error_generic_error_msg"); |
|
55 } |
|
56 } |
|
57 |
|
58 //! Handles external mouse events - dismisses status dialog. |
|
59 /*! |
|
60 \param type the type of event |
|
61 \param name the name of event |
|
62 \param description event description |
|
63 */ |
|
64 this.handleExternalMouseEvent = function(type, name, description) |
|
65 { |
|
66 if (name == "QGraphicsSceneMousePressEvent") { |
|
67 this.hidePrompt(); |
|
68 } |
|
69 } |
|
70 |
|
71 //! Show the dialog and shaded overlay. |
|
72 var showPrompt = function(){ |
|
73 |
|
74 var snippet = snippets.PromptChromeId; |
|
75 snippet.updateOwnerArea(); |
|
76 snippet.show(true); |
|
77 snippet.zValue = 1; |
|
78 snippet.repaint(); |
|
79 |
|
80 } |
|
81 |
|
82 //! Hide the dialog and shaded overlay. |
|
83 this.hidePrompt = function(){ |
|
84 snippets.PromptChromeId.hide(); |
|
85 } |
|
86 |
|
87 //! Create the DOM elements for the dialog. |
|
88 this.setupPage = function(){ |
|
89 var html = |
|
90 '<div class="promptBox">' + |
|
91 '<ul>' + |
|
92 '<li>' + |
|
93 '<img src="prompt.snippet/icons/icon_dialog_error.png"/> ' + |
|
94 '<span class="promptText">' + |
|
95 window.localeDelegate.translateText("txt_browser_info_message") + |
|
96 '</span>' + |
|
97 '</li>' + |
|
98 '<li id="promptTextUrlParent">' + |
|
99 '<span class="promptText" id="promptTextUrl1Id"></span><br/>' + |
|
100 '<div class="promptText2" id="promptTextUrl2Id"></div>' + |
|
101 '</li>' + |
|
102 '<li>' + |
|
103 '<span class="promptText" id="promptTextMsgId"/>' + |
|
104 '</li>' + |
|
105 '<li>' + |
|
106 '<center><img id="prompt_okId" class="promptOkButton"/></center>' + |
|
107 '</li>' + |
|
108 '</ul>' + |
|
109 '</div>'; |
|
110 document.write(html); |
|
111 new SimpleButton("prompt_okId", |
|
112 "prompt.snippet/icons/button_dialog_ok_wait.png", |
|
113 "prompt.snippet/icons/button_dialog_ok_press.png", |
|
114 "", |
|
115 this.onOkPressed.bind(this)); |
|
116 } |
|
117 |
|
118 this.onOkPressed = function() { |
|
119 this.hidePrompt(); |
|
120 } |
|
121 |
|
122 this.setupPage(); |
|
123 |
|
124 chrome.chromeComplete.connect(onChromeComplete.bind(this)); |
|
125 } |