Skip to content

Commit

Permalink
Search Load is working (serverside unneeded).
Browse files Browse the repository at this point in the history
  • Loading branch information
Goran Topic committed Mar 19, 2012
1 parent 2a64c4a commit 264b106
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
44 changes: 37 additions & 7 deletions client/src/visualizer_ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var VisualizerUI = (function($, window, undefined) {
var documentListing = null; // always documents of current collection
var selectorData = null; // can be search results when available
var searchActive = false; // whether search results received and in use
var loadedSearchData = null;

var currentForm;
var spanTypes = null;
Expand Down Expand Up @@ -504,7 +505,7 @@ var VisualizerUI = (function($, window, undefined) {
var $fileBrowserButtonset = fileBrowser.
parent().find('.ui-dialog-buttonpane .ui-dialog-buttonset').prepend(' ');
$('<a href="ajax.cgi?action=downloadSearchFile" id="save_search">Save</a>').
prependTo($fileBrowserButtonset).button();
prependTo($fileBrowserButtonset).button().css('display', 'none');

var docInputHandler = function(evt) {
selectElementInTable('#document_select', $(this).val());
Expand Down Expand Up @@ -990,6 +991,15 @@ var VisualizerUI = (function($, window, undefined) {
});
$('#search_form').find('.radio_group').buttonset();

var applySearchResults = function(response) {
if (!searchActive) {
collectionSortOrder = sortOrder;
}
dispatcher.post('searchResultsReceived', [response]);
searchActive = true;
updateSearchButton();
};

var searchForm = $('#search_form');

var searchFormSubmit = function(evt) {
Expand Down Expand Up @@ -1042,6 +1052,9 @@ var VisualizerUI = (function($, window, undefined) {
opts.type = $('#search_form_note_type').val() || '';
opts.text = $('#search_form_note_text').val() || '';
break;
case 'searchLoad':
applySearchResults(loadedSearchData);
return false;
}

// fill in scope of search ("document" / "collection")
Expand Down Expand Up @@ -1071,17 +1084,32 @@ var VisualizerUI = (function($, window, undefined) {
dispatcher.post('messages', [[['No matches to search.', 'comment']]]);
dispatcher.post('clearSearch', [true]);
} else {
if (!searchActive) {
collectionSortOrder = sortOrder;
}
dispatcher.post('searchResultsReceived', [response]);
searchActive = true;
updateSearchButton();
applySearchResults(response);
}
}]);
return false;
};

$('#search_form_load_file').change(function(evt) {
var $file = $('#search_form_load_file');
var file = $file[0].files[0];
var reader = new FileReader();
reader.onerror = function(evt) {
dispatcher.post('messages', [[['The file could not be read.', 'error']]]);
};
reader.onloadend = function(evt) {
try {
loadedSearchData = JSON.parse(evt.target.result);
// TODO XXX check for validity of contents, not just whether
// it's valid JSON or not; throw something if not
} catch (x) {
dispatcher.post('messages', [[['The file contains invalid data.', 'error']]]);
return;
}
};
reader.readAsText(file);
});

searchForm.submit(searchFormSubmit);

initForm(searchForm, {
Expand Down Expand Up @@ -1345,6 +1373,7 @@ var VisualizerUI = (function($, window, undefined) {
var item = response.items[0];
dispatcher.post('setDocument', [item[2], item[1]]);
}
$('#save_search').css('display', 'inline-block');
}
};

Expand All @@ -1353,6 +1382,7 @@ var VisualizerUI = (function($, window, undefined) {

// back off to document collection
if (searchActive) {
$('#save_search').css('display', 'none');
selectorData = documentListing;
sortOrder = collectionSortOrder;
selectorData.items.sort(docSortFunction);
Expand Down
3 changes: 2 additions & 1 deletion index.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@
<tr>
<td>File:</td>
<td>
<input type="file" id="search_form_load_file" class="fullwidth"/>
<input type="file" name="file" id="search_form_load_file" class="fullwidth"/>
<input type="hidden" name="action" value="searchLoad"/>
</td>
</tr>
</table>
Expand Down
4 changes: 0 additions & 4 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -633,10 +633,6 @@ div.scroll_wrapper_upper div.scroller {
width: 100%; /* deal with overflowing selectboxes */
}

#search_form_note_type_row {
display: none;
}

.scroll_fset {
height: 200px;
}
Expand Down

0 comments on commit 264b106

Please sign in to comment.