-
Notifications
You must be signed in to change notification settings - Fork 208
/
Copy pathzero_chooser.js
207 lines (153 loc) · 5.55 KB
/
zero_chooser.js
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
* CC0
* zero_chooser.js
*
* copyright 2007-2008, Creative Commons, Nathan R. Yergler
* licensed to the public under the GNU GPL v2
*
*/
YAHOO.namespace("cc.zero");
YAHOO.cc.zero._show_panel = function(e, index) {
e.preventDefault();
// push the current item onto the stack
YAHOO.cc.zero.chooser_path.push(this.getLayout().activeItem);
// show the specified item
this.getLayout().setActiveItem(index);
this.getBottomToolbar().items.get('move-back').setDisabled(false);
} // _show_panel
YAHOO.cc.zero._back = function() {
// pop the last place off the stack
last = YAHOO.cc.zero.chooser_path.pop();
// show the last page
YAHOO.cc.zero.chooser.getLayout().setActiveItem(last);
// see if we need to disable the back button
if (YAHOO.cc.zero.chooser_path.length == 0) {
YAHOO.cc.zero.chooser.getBottomToolbar().items.get('move-back').setDisabled(true);
}
} // _back
YAHOO.cc.zero._enable_button = function(e, btn_id) {
Ext.get(btn_id).dom.disabled = !(e.target.checked);
} // _enable_button
YAHOO.cc.zero.enable_button_assertion = function(e) {
// enable the continue button if one or more of the reason
// checkboxes is selected.
var disabled = true;
function is_checked(el, scope, index) {
// bail out if we've already found a reason to enable
if (!disabled) return;
// special case the "other" check box
if (el.dom.id == 'enable_other_assertion_reason') {
if (Ext.get("other_assertion_reason").dom.value.trim() != '') {
disabled = false;
}
} else if (el.dom.checked) {
disabled = false;
}
} // is_checked
Ext.select(".reason").each(is_checked);
Ext.get("details-submit").dom.disabled = disabled;
} // enable_button_assertion
YAHOO.cc.zero.on_show_form = function(e) {
if (Ext.get("confirm_details"))
Ext.get("confirm_details").dom.checked = false;
Ext.get("details-submit").dom.disabled= true;
} // on_show_form
YAHOO.cc.zero.on_show_results = function(e) {
// get the HTML + RDFa
var mgr = Ext.get("results-preview").getUpdater();
mgr.formUpdate("form-details", "/license/get-rdfa",
false, function (el, success, response) {
if (success) {
Ext.get("results-html").dom.value = response.responseText;
}
});
} // on_show_results
function swapbutton(buttonurl) {
//document.getElementById('licensebutton').setAttribute('src',buttonurl);
e = document.getElementById('results-html');
var codetocopy = e.value;
var newcodetocopy = codetocopy.replace(/src=".*?"/, 'src="'+buttonurl+'"');
e.value = newcodetocopy;
Ext.get("results-preview").dom.innerHTML = newcodetocopy;
}
YAHOO.cc.zero.init = function() {
YAHOO.cc.zero.chooser_path = new Array();
YAHOO.cc.zero.chooser = new Ext.Panel({
layout:'card',
activeItem: 0,
renderTo:'zero-wizard',
autoWidth:true,
height:450,
border:false,
defaults: {
// applied to each contained panel
border:false,
bodyStyle:"padding:10px",
title:' ',
},
bbar: [
{
id: 'move-back',
text: '<< Back',
handler: YAHOO.cc.zero._back,
disabled: true
},
],
// the panels (or "cards") within the layout
items: [
{contentEl:'page-welcome', id:'page-welcome',},
{contentEl:'page-details', id:'page-details'},
{contentEl:'page-confirmation', id:'page-confirmation'},
{contentEl:'page-results', id: 'page-results', autoScroll:true},
{contentEl:'page-bailout', id: 'page-bailout'},
]
});
// initalize the title/headers
// -- we do this here so Zope can handle i18n
for (i = 0; i < YAHOO.cc.zero.chooser.items.length; i++) {
var current = YAHOO.cc.zero.chooser.items.get(i);
hd = current.getEl().down("div .hd");
if (hd && hd.dom.innerHTML) {
current.setTitle(hd.dom.innerHTML);
hd.remove();
} // if a .hd was found
} // for each panel...
// init the path buttons
Ext.get("do-begin").on("click",
YAHOO.cc.zero._show_panel.createDelegate(YAHOO.cc.zero.chooser,
['page-details'], 1));
// forward-movement handlers
Ext.get("details-submit").on("click",
YAHOO.cc.zero._show_panel.createDelegate(YAHOO.cc.zero.chooser,
['page-confirmation'], 1));
Ext.get("confirm-submit").on("click",
YAHOO.cc.zero._show_panel.createDelegate(YAHOO.cc.zero.chooser,
['page-results'], 1));
Ext.get("decline-submit").on("click",
YAHOO.cc.zero._show_panel.createDelegate(YAHOO.cc.zero.chooser,
['page-bailout'], 1));
// add listeners for the "agreement" checkboxes
if (Ext.get("confirm_details"))
Ext.get("confirm_details").on("click",
YAHOO.cc.zero._enable_button.createDelegate(this,
["details-submit"],
1));
Ext.select(".reason").on("click", YAHOO.cc.zero.enable_button_assertion);
if (Ext.get("enable_other_assertion_reason")) {
Ext.get("other_assertion_reason").on("keyup",
YAHOO.cc.zero.enable_button_assertion);
Ext.get("other_assertion_reason").dom.disabled = true;
Ext.get("enable_other_assertion_reason").on("click",
function (e) {
Ext.get("other_assertion_reason").dom.disabled =
!e.target.checked;
});
}
// add panel-show listeners
YAHOO.cc.zero.chooser.items.get('page-results').on("show",
YAHOO.cc.zero.on_show_results);
YAHOO.cc.zero.chooser.items.get('page-details').on('show',
YAHOO.cc.zero.on_show_form);
} // init
// hook for initialization
Ext.EventManager.onDocumentReady(YAHOO.cc.zero.init);