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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
YUI.add('lp.app.errors', function(Y) {
var namespace = Y.namespace('lp.app.errors');
/*
* Create a form button for canceling an error form
* that won't reload the page on submit.
*
* @method cancel_form_button
* @return button {Node} The form's cancel button.
*/
var cancel_form_button = function() {
var button = Y.Node.create('<button>OK</button>');
button.on('click', function(e) {
e.preventDefault();
error_overlay.hide();
});
return button;
};
var error_overlay;
/*
* Create the form overlay to use when encountering errors.
*
* @method create_error_overlay
*/
var create_error_overlay = function() {
// If the error_overlay has never been instantiated, or if it no longer
// is in the DOM (probably because of a previous test cleanup)...
if (error_overlay === undefined ||
!Y.Lang.isValue(error_overlay.get('boundingBox').get('parentNode'))) {
// ...make one and set it up.
error_overlay = new Y.lazr.FormOverlay({
headerContent: '<h2>Error</h2>',
form_header: '',
form_content: '',
form_submit_button: Y.Node.create(
'<button style="display:none"></button>'),
form_cancel_button: cancel_form_button(),
centered: true,
visible: false
});
error_overlay.render();
}
};
/**
* Run a callback, optionally flashing a specified node red beforehand.
*
* If the supplied node evaluates false, the callback is invoked immediately.
*
* @method maybe_red_flash
* @param flash_node The node to flash red, or null for no flash.
* @param callback The callback to invoke.
*/
var maybe_red_flash = function(flash_node, callback)
{
if (flash_node) {
var anim = Y.lp.anim.red_flash({ node: flash_node });
anim.on('end', callback);
anim.run();
} else {
callback();
}
};
/*
* Take an error message and display in an overlay (creating it if necessary).
*
* @method display_error
* @param flash_node {Node} The node to red flash.
* @param msg {String} The message to display.
*/
namespace.display_error = function(flash_node, msg) {
create_error_overlay();
maybe_red_flash(flash_node, function(){
error_overlay.showError(msg);
error_overlay.show();
});
};
var info_overlay;
/*
* Display the form overlay for non-error informational messages.
*
* @method display_info
* @param msg {String} The message to display.
*/
namespace.display_info = function(msg) {
if (info_overlay === undefined) {
info_overlay = new Y.lazr.PrettyOverlay({
centered: true,
visible: false
});
info_overlay.render();
}
var content = Y.Node.create(
'<div style="background: url(/@@/info-large) no-repeat; ' +
'min-height: 32px; padding-left: 40px; padding-top: 16px"/></div>');
content.appendChild(Y.Node.create(msg));
var button_div = Y.Node.create('<div style="text-align: right"></div>');
var ok_button = Y.Node.create('<button>OK</button>');
ok_button.on('click', function(e) {
info_overlay.fire('cancel');
});
button_div.appendChild(ok_button);
content.appendChild(button_div);
info_overlay.set('bodyContent', content);
info_overlay.show();
};
}, "0.1", {"requires":["lazr.formoverlay", "lazr.overlay", "lp.anim"]});
|