~launchpad-pqm/launchpad/devel

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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
<html
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:tal="http://xml.zope.org/namespaces/tal"
  xmlns:metal="http://xml.zope.org/namespaces/metal"
  xmlns:i18n="http://xml.zope.org/namespaces/i18n"
  metal:use-macro="view/macro:page/main_only"
>
<body>
  <div metal:fill-slot="main">

  <script type="text/javascript">
/*
 * When step 2 of this wizard has search results, we want to hide the
 * details widgets until the user states that the project they are
 * registering is not a duplicate.
 */
LPS.use('node', 'lazr.effects', function(Y) {
    Y.on('domready', function() {
        /* These two regexps serve slightly different purposes.  The first
         * finds the leftmost run of valid url characters for the autofill
         * operation.  The second validates the entire string, used for
         * explicit entry into the URL field.  These are simple enough to keep
         * in sync so it doesn't bother me that we repeat most of it.  Note
         * that while both ignore case, only the first one should be global in
         * order to utilize the RegExp.lastIndex behavior of .exec().
         */
        var valid_urls = new RegExp('^[a-z0-9][-.+a-z0-9]*', 'ig');
        var valid_char = new RegExp('^[a-z0-9][-.+a-z0-9]*$', 'i');

        /* Handle key presses in the Name field for autofilling the URL
         * field.  By ensuring that field.name exists, we only do this when
         * we're on step 1 of the wizard.
         *
         * XXX BarryWarsaw 12-May-2009
         * http://yuilibrary.com/projects/yui3/ticket/2423101
         * Note that we have to use the more verbose way of getting field.name
         * because Y.one() doesn't like the dots in the Zope field names.
         */
        var url_field = Y.one(Y.DOM.byId('field.name'));
        if (url_field) {
            var name_field = Y.one(Y.DOM.byId('field.displayname'));
            function autofill(e) {
                var name_value = name_field.get('value');
                if (name_value == '') {
                    /* When Name is empty, clear URL. */
                    url_field.set('value', '');
                }
                else {
                    /* Fill the URL field with as much of the left part of the
                     * string as matches the regexp.  If the regexp doesn't
                     * match (say because there's illegal stuff at the front),
                     * don't change the current URL field.  We have to reset
                     * lastIndex each time we get here so that search begins
                     * at the front of the string.
                     */
                    valid_urls.lastIndex = 0;
                    var match = valid_urls.exec(name_value);
                    if (match) {
                        var slice = name_value.slice(0, valid_urls.lastIndex);
                        url_field.set('value', slice);
                    }
                }
            }
            name_field.on('keyup', autofill);
            /* Prevent invalid characters from being input into the URL field.
             */
            url_field.on('keypress', function(e) {
                /* Handling key events is madness.  For a glimpse, see
                 * http://unixpapa.com/js/key.html
                 *
                 * Additional spice for the insanity stew is given by the
                 * rhino book, page 428.  This code is basically a rip and
                 * remix of those two texts.
                 */
                var event = e || window.event;
                var code = e.charCode || e.keyCode;

                if (/* Check for special characters. */
                    e.which == 0 || e.which == null ||
                    /* Check for function keys (Firefox only). */
                    e.charCode == 0 ||
                    /* Check for ctrl or alt held down. */
                    e.ctrlKey || e.altKey ||
                    /* Check for ASCII control character */
                    32 > code)
                {
                    return true;
                }
                var char = String.fromCharCode(code);
                var new_value = url_field.get('value') + char;
                if (new_value.search(valid_char) >= 0) {
                    /* The character is valid. */
                    return true;
                }
                e.preventDefault();
                e.returnValue = false;
                return false;
            });
            /* Explicitly typing into the URL field disables autofilling. */
            url_field.on('keyup', function(e) {
                if (url_field.get('value') == '') {
                    /* The user cleared the URL field; turn on autofill. */
                    name_field.attach('keyup', autofill);
                }
                else {
                    /* Honor the user's URL; turn off autofill. */
                    name_field.detach('keyup', autofill);
                }
            });
        }

        /* Handle the reveals when there are search results. */
        var details_buttons = Y.one('#registration-details-buttons');
        var form_actions = Y.one('#launchpad-form-actions');
        var form_widgets = Y.one('#launchpad-form-widgets');
        var search_results = Y.one('#search-results');
        var step_title = Y.one('#step-title');
        var title = Y.one('#registration-details-title');

        /* This is the magic hidden widget used by the MultiStepView. */
        var marker = Y.one(Y.DOM.byId('field.__visited_steps__'));

        var separator = Y.one('#registration-separator');
        function show_separator(flag) {
            if (!separator) {
                /* The separator is not on the page, because there were no
                 * search results.
                 */
                return;
            }
            if (flag) {
                separator.removeClass('unseen');
            }
            else {
                separator.addClass('unseen');
            }
        }

        /* When the 'No' button is clicked, we swap in the registration
         * details for the search results.  It really doesn't look good
         * to leave the search results there.
         */
        function complete_registration(e) {
            var expander = Y.one('#search-results-expander');

            /* Slide in the search results and hide them under a link. */
            expander.removeClass('unseen');
            expander.on('click', function(e) {
                e.preventDefault();

                var arrow = Y.one('#search-results-arrow');
                if (arrow.getAttribute('src') == '/@@/treeCollapsed') {
                    /* The search results are currently hidden.  Slide them
                     * out and turn the arrow to point downward.
                     */
                    arrow.setAttribute('src', '/@@/treeExpanded');
                    arrow.setAttribute('title', 'Hide search results');
                    arrow.setAttribute('alt', 'Hide search results');
                    Y.lazr.effects.slide_out(search_results).run();
                    show_separator(true);
                }
                else {
                    /* The search results are currently displayed.  Slide them
                     * in and turn the arrow to point rightward.
                     */
                    arrow.setAttribute('src', '/@@/treeCollapsed');
                    arrow.setAttribute('title', 'Show search results');
                    arrow.setAttribute('alt', 'Show search results');
                    Y.lazr.effects.slide_in(search_results).run();
                    show_separator(false);
                }
            });

            /* Hide the 'No' button, but slide out the search results, so the
             * user has a clue that Something Is Happening.
             */
            details_buttons.addClass('unseen');

            /* Slide out the registration details widgets, but add an 'end'
             * event handler so that the height style left by lazr.effects is
             * removed when the animation is done.  We're never going to slide
             * the form widgets back in, and the height style causes the
             * license widget to dive under the Complete Registration button.
             * See bug 391138 for details.
             */
            var anim = Y.lazr.effects.slide_out(form_widgets);
            anim.on('end', function() {
                form_widgets.setStyle('height', null);
            });
            anim.run();

            /* Toggle the visibility of the various other widgets. */
            form_actions.removeClass('unseen');
            title.removeClass('unseen');

            /* Set the H2 title to something more appropriate for the
             * selected task.
             */
            step_title.set('innerHTML', 'Step 2 (of 2) Registration details');

            var reset_height = search_results.getComputedStyle('height');
            search_results.setStyle('height', reset_height);
            Y.lazr.effects.slide_in(search_results).run();

            /* Append a special marker to the hidden state widget.  See
             * ProjectAddStepTwo.search_results_count() for details.
             */
            var steps = marker.getAttribute('value');
            if (0 > steps.search(new RegExp('hidesearch'))) {
                marker.setAttribute('value', steps + "|hidesearch");
            }
        }

        /* The details button is only visible when JavaScript is enabled, but
         * the H3 separator is only visible when JavaScript is disabled.
         * Neither is displayed on the step 1 page.
         */
        show_separator(false);

        if (details_buttons) {
            details_buttons.removeClass('unseen');
            details_buttons.on('click', complete_registration);
        }

        /* If there are search results, hide the registration details. */
        if (search_results) {
            form_widgets.addClass('unseen');
            form_actions.addClass('unseen');
            title.addClass('unseen');
        }

        /* Finally, if we've been here before (e.g. there was an error in
         * submitting step 2), jump to continuing the registration.
         */
         if (marker.getAttribute('value').search(/hidesearch/) >= 0) {
            complete_registration(null);
         }
    })
});
  </script>

    <div style="font-size: larger; background: #e0f0d0;
        padding: 0.3em; -moz-border-radius: 5px; -o-border-radius: 5px;
       -webkit-border-radius: 5px; margin-bottom: 1em;">
      <strong>Requesting Ubuntu CDs</strong> is done at <a
      href="https://shipit.ubuntu.com/">shipit.ubuntu.com</a>
      <form style="display: inline; font-size: smaller"
            action="https://shipit.ubuntu.com/">
        <input type="submit" value="Oh, I want Ubuntu CDs" />
      </form>
    </div>

    <div metal:use-macro="context/@@launchpad_form/form">
      <metal:step fill-slot="extra_info">
      <div style="text-align: right;">Not sure what to do?
        <a href="https://help.launchpad.net/Feedback">Contact us</a>
      </div>
      <h2 class="legend" id="step-title">Step
          <tal:step_number tal:replace="view/step_number"/>
          (of <tal:total_steps tal:replace="view/total_steps"/>):
          <tal:step_description tal:replace="view/step_description"/></h2>
      </metal:step>

      <metal:extra metal:fill-slot="extra_top">
        <a href="" id="search-results-expander" class="js-action unseen">
          <img id="search-results-arrow" src="/@@/treeCollapsed"
               title="Show search results" alt="Show search results"/>
          Possible duplicate projects
        </a>

        <div tal:condition="view/search_results_count"
             id="search-results">
          <div style="font-size: larger; margin-bottom: 1em; max-width: 60em;">
          <img src="/@@/info" />
          There are similar projects already registered in Launchpad.
          Is project
          <strong><tal:displayname tal:replace="view/request/displayname" />
          (<tal:name  tal:replace="view/request/name" />)</strong>
          one of these?
          </div>

          <table tal:define="results view/search_results">
            <tbody>
              <tr tal:repeat="pillar_name results"
                  tal:replace="structure pillar_name/@@+listing-simple">
              </tr>
            </tbody>
          </table>
          <div id="registration-details-buttons" class="unseen">
            <input type="button"
                   value="No, this is a new project"/>
            or <a tal:attributes="href view/cancel_url">Cancel</a>
          </div>
        </div>

        <div id="registration-details-title"
             style="font-size: larger; max-width: 60em;"
             tal:condition="python: view.step_number == 2">
          <h3 id="registration-separator"
              style="margin-top: 3em;"
              tal:condition="view/search_results_count"
              >Registration details</h3>
          Select the licenses for project
          <strong><tal:displayname tal:replace="view/request/displayname" />
          (<tal:name  tal:replace="view/request/name" />)</strong>
          and complete the registration.  You may also update the project's
          title and summary.
        </div>
      </metal:extra>
    </div>

  </div>
</body>
</html>