Skip to content

Commit

Permalink
optional in-widget wait spinner; working towards completing kltm/amig…
Browse files Browse the repository at this point in the history
…o#69
  • Loading branch information
kltm committed May 6, 2014
1 parent fcaaf42 commit 1e52775
Showing 1 changed file with 68 additions and 51 deletions.
119 changes: 68 additions & 51 deletions lib/bbop/widget/live_filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ bbop.widget.live_filters = function(golr_loc, golr_conf_obj,
// Our argument default hash.
var default_hash =
{
'meta_label': 'Documents: ',
'display_meta_p': true,
'display_free_text_p': true,
'free_text_placeholder': 'Free-text filter',
'display_accordion_p': true,
'minimum_free_text_length': 3, // wait for three characters or more
'on_update_callback': function(){}
Expand All @@ -84,7 +86,9 @@ bbop.widget.live_filters = function(golr_loc, golr_conf_obj,
//
this._interface_id = interface_id;
this._display_meta_p = arg_hash['display_meta_p'];
this._meta_label = arg_hash['meta_label'];
this._display_free_text_p = arg_hash['display_free_text_p'];
this._free_text_placeholder = arg_hash['free_text_placeholder'];
this._display_accordion_p = arg_hash['display_accordion_p'];
this._minimum_free_text_length = arg_hash['minimum_free_text_length'];
this._on_update_callback = arg_hash['on_update_callback'];
Expand Down Expand Up @@ -158,16 +162,6 @@ bbop.widget.live_filters = function(golr_loc, golr_conf_obj,
// ui_spinner_search_source,
// spinner_args);
// }
// function _spin_up(){
// if( spinner ){
// spinner.start_wait();
// }
// }
// function _spin_down(){
// if( spinner ){
// spinner.finish_wait();
// }
// }

// // Additional id hooks for easy callbacks. While these are not as
// // easily changable as the above, we use them often enough and
Expand All @@ -177,8 +171,22 @@ bbop.widget.live_filters = function(golr_loc, golr_conf_obj,
// // These pointers are used in multiple functions (e.g. both
// // *_setup and *_draw).
var filter_accordion_widget = null;
var spinner_div = null;
// //var current_filters_div = null;

function _spin_up(){
if( spinner_div ){
jQuery('#' + spinner_div.get_id()).removeClass('hidden');
jQuery('#' + spinner_div.get_id()).addClass('active');
}
}
function _spin_down(){
if( spinner_div ){
jQuery('#' + spinner_div.get_id()).addClass('hidden');
jQuery('#' + spinner_div.get_id()).removeClass('active');
}
}

/*
* Function: establish_display
*
Expand Down Expand Up @@ -220,32 +228,35 @@ bbop.widget.live_filters = function(golr_loc, golr_conf_obj,
var ms_attrs = {
id: meta_count_id,
//'class': 'label label-default pull-right'
'class': 'label label-default'
//'class': 'label label-default'
'class': 'badge'
};
var ms = new bbop.html.tag('div', ms_attrs, 'n/a');
var ms = new bbop.html.tag('span', ms_attrs, 'n/a');

// Get a progress bar assembled.
var inspan = new bbop.html.tag('span', {'class': 'sr-only'},
'Loading...');
// Get a progress bar assembled.
var inspan = new bbop.html.tag('span', {'class': 'sr-only'}, '...');
var indiv = new bbop.html.tag('div', {'class': 'progress-bar',
'role': 'progressbar',
'aria-valuenow': '100',
'aria-valuemin': '0',
'aria-valuemax': '100',
'style': 'width: 100%;'},
inspan);
var prog =
spinner_div =
new bbop.html.tag('div',
{'class': 'progress progress-striped active'
},//'style': '3em;'},
{'generate_id': true,
'class':
'progress progress-striped active pull-right',
'style': 'width: 3em;'},
indiv);

// The container area.
// The container area; add in the label and count.
var mdiv_args = {
'class': 'well well-sm',
'id': meta_div_id
};
var mdiv = new bbop.html.tag('div', mdiv_args, [ms]);
var mdiv = new bbop.html.tag('div', mdiv_args,
[this._meta_label, ms, spinner_div]);

jQuery('#' + container_div.get_id()).append(mdiv.to_string());
};
Expand All @@ -258,13 +269,13 @@ bbop.widget.live_filters = function(golr_loc, golr_conf_obj,
//
// If no icon_clear_source is defined, icon_clear_label will be
// used as the defining text.
this.setup_query = function(label_str){
this.setup_query = function(){
ll('setup_query for: ' + query_input_div_id);

// Some defaults.
if( ! label_str ){ label_str = ''; }
// if( ! icon_clear_label ){ icon_clear_label = ''; }
// if( ! icon_clear_source ){ icon_clear_source = ''; }
// // Some defaults.
// if( ! label_str ){ label_str = ''; }
// // if( ! icon_clear_label ){ icon_clear_label = ''; }
// // if( ! icon_clear_source ){ icon_clear_source = ''; }

// The incoming label.
var query_label_attrs = {
Expand All @@ -275,7 +286,7 @@ bbop.widget.live_filters = function(golr_loc, golr_conf_obj,
// The text area.
var ta_args = {
//'class': 'bbop-js-search-pane-textarea',
'placeholder': label_str,
'placeholder': this._free_text_placeholder,
'class': 'form-control',
'id': query_input_div_id
};
Expand Down Expand Up @@ -310,8 +321,7 @@ bbop.widget.live_filters = function(golr_loc, golr_conf_obj,
jQuery('#' + container_div.get_id()).append(gen_div.to_string());
};
if( this._display_free_text_p ){
this.setup_query('Foo!');
//this.setup_query();
this.setup_query();
}

// Setup sticky filters display under contructed tags for later
Expand Down Expand Up @@ -541,7 +551,7 @@ bbop.widget.live_filters = function(golr_loc, golr_conf_obj,
manager.search();

// We are now searching--show it.
//_spin_up();
_spin_up();
}else{
ll('rolling back query: ' + tmp_q);
manager.set_query(tmp_q);
Expand All @@ -558,7 +568,7 @@ bbop.widget.live_filters = function(golr_loc, golr_conf_obj,
anchor.set_query_field('');
manager.search();
// We are now searching--show it.
//_spin_up();
_spin_up();
});
};
if( this._display_free_text_p ){
Expand Down Expand Up @@ -830,7 +840,7 @@ bbop.widget.live_filters = function(golr_loc, golr_conf_obj,
[call_polarity]);
manager.search();
// We are now searching--show it.
//_spin_up();
_spin_up();
});
}

Expand Down Expand Up @@ -1004,7 +1014,7 @@ bbop.widget.live_filters = function(golr_loc, golr_conf_obj,
manager.reset_query_filters();
manager.search();
// We are now searching--show it.
//_spin_up();
_spin_up();
}
);

Expand Down Expand Up @@ -1037,7 +1047,7 @@ bbop.widget.live_filters = function(golr_loc, golr_conf_obj,
manager.remove_query_filter(field, value);
manager.search();
// We are now searching--show it.
//_spin_up();
_spin_up();
});
});
}
Expand Down Expand Up @@ -1104,6 +1114,31 @@ bbop.widget.live_filters = function(golr_loc, golr_conf_obj,
this.draw_sticky_filters, 3);
}

/*
* Function: draw_error
*
* Somehow report an error to the user.
*
* Parameters:
* error_message - a string(?) describing the error
* manager - <bbop.golr.manager> that we initially registered with
*
* Returns:
* n/a
*/
this.draw_error = function(error_message, manager){
ll("draw_error: " + error_message);
alert("Runtime error: " + error_message);
_spin_down();
};
anchor.register('error', 'error_first', this.draw_error, 0);

//
function spin_down_wait(){
_spin_down();
}
anchor.register('search', 'donedonedone', spin_down_wait, -100);

///
// /// Things to do on every reset event. Essentially re-draw
// /// everything.
Expand Down Expand Up @@ -1216,24 +1251,6 @@ bbop.widget.live_filters = function(golr_loc, golr_conf_obj,
// anchor.draw_query(response, manager);
// };

// /*
// * Function: draw_error
// *
// * Somehow report an error to the user.
// *
// * Parameters:
// * error_message - a string(?) describing the error
// * manager - <bbop.golr.manager> that we initially registered with
// *
// * Returns:
// * n/a
// */
// this.draw_error = function(error_message, manager){
// ll("draw_error: " + error_message);
// alert("Runtime error: " + error_message);
// _spin_down();
// };

// /*
// * Function: set_query_field
// *
Expand Down

0 comments on commit 1e52775

Please sign in to comment.