~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/app/javascript/picker.js

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-03-01 06:54:09 UTC
  • mfrom: (12435.3.3 recipe-picker-spinners)
  • Revision ID: launchpad@pqm.canonical.com-20110301065409-r51k1ai7c58n6bb9
[r=thumper][bug=719785] Add "Loading..." spinner to vocab picker
        widgets which eagerly load the entire vocab up front.

Show diffs side-by-side

added added

removed removed

Lines of Context:
181
181
    }
182
182
    picker.set('footer_slot', extra_buttons);
183
183
 
 
184
    // If we are to pre-load the vocab, we need a spinner.
 
185
    // We set it up here because we only want to do it once and the
 
186
    // activator.subscribe callback below is called each time the picker
 
187
    // is activated.
 
188
    if( !show_search_box ) {
 
189
        // The spinner displays a "Loading..." message while vocab loads.
 
190
        config.temp_spinner = create_temporary_spinner(picker);
 
191
    }
 
192
 
184
193
    activator.subscribe('act', function (e) {
185
194
        if (!show_search_box) {
 
195
          config.temp_spinner.removeClass('unseen');
186
196
          picker.set('min_search_chars', 0);
187
197
          picker.fire('search', '');
188
198
          picker.get('contentBox').one('.yui3-picker-search-box').addClass('unseen');
196
206
    return picker;
197
207
};
198
208
 
 
209
/*
 
210
 * Show the Loading.... spinner (used when we preload the entire vocab).
 
211
 */
 
212
function create_temporary_spinner(picker) {
 
213
    var node = picker.get('contentBox').one('.yui3-picker-batches');
 
214
    var temp_spinner = Y.Node.create([
 
215
    '<div class="unseen" align="center">',
 
216
    '<img src="/@@/spinner"/>Loading...',
 
217
    '</div>'].join(''));
 
218
    node.insert(temp_spinner, node);
 
219
    return temp_spinner;
 
220
}
 
221
 
 
222
/*
 
223
 * Remove the Loading.... spinner (if it exists).
 
224
 */
 
225
function hide_temporary_spinner(temp_spinner) {
 
226
    if( temp_spinner != null )
 
227
        temp_spinner.addClass('unseen');
 
228
}
 
229
 
199
230
/**
200
231
  * Creates a picker widget that has already been rendered and hidden.
201
232
  *
272
303
            var start = entry.start;
273
304
            var results = entry.entries;
274
305
 
 
306
            hide_temporary_spinner(config.temp_spinner);
275
307
            if (total_size > (MAX_BATCHES * BATCH_SIZE))  {
276
308
                picker.set('error',
277
309
                    'Too many matches. Please try to narrow your search.');
317
349
            on: {
318
350
                success: success_handler,
319
351
                failure: function (arg) {
 
352
                    hide_temporary_spinner(config.temp_spinner);
320
353
                    picker.set('error', 'Loading results failed.');
321
354
                    picker.set('search_mode', false);
322
355
                    Y.log("Loading " + uri + " failed.");