use of de.geeksfactory.opacclient.searchfields.TextSearchField in project opacclient by opacapp.
the class SearchFragment method saveQuery.
public Map<String, String> saveQuery() {
if (app.getLibrary() == null) {
return null;
}
saveHomeBranch();
Map<String, String> query = new HashMap<>();
if (fields == null) {
SearchFieldDataSource dataSource = new JsonSearchFieldDataSource(app);
int versionCode = 0;
try {
versionCode = app.getPackageManager().getPackageInfo(app.getPackageName(), 0).versionCode;
} catch (NameNotFoundException e) {
// should not happen
e.printStackTrace();
}
if (dataSource.hasSearchFields(app.getLibrary().getIdent()) && dataSource.getLastSearchFieldUpdateVersion(app.getLibrary().getIdent()) == versionCode) {
if (task != null && !task.isCancelled()) {
task.cancel(true);
}
fields = dataSource.getSearchFields(app.getLibrary().getIdent());
if (fields == null) {
return null;
}
} else {
return null;
}
}
for (SearchField field : fields) {
if (!field.isVisible()) {
continue;
}
if (field instanceof TextSearchField && ((TextSearchField) field).isFreeSearch()) {
query.put(field.getId(), etSimpleSearch.getEditableText().toString());
continue;
}
ViewGroup v = (ViewGroup) view.findViewWithTag(field.getId());
if (v == null) {
continue;
}
if (field instanceof TextSearchField) {
EditText text = (EditText) v.findViewById(R.id.edittext);
query.put(field.getId(), text.getEditableText().toString());
} else if (field instanceof BarcodeSearchField) {
EditText text = (EditText) v.findViewById(R.id.edittext);
query.put(field.getId(), text.getEditableText().toString());
} else if (field instanceof DropdownSearchField) {
Spinner spinner = (Spinner) v.findViewById(R.id.spinner);
if (spinner.getSelectedItemPosition() > 0) {
query.put(field.getId(), ((DropdownSearchField) field).getDropdownValues().get(spinner.getSelectedItemPosition()).getKey());
}
} else if (field instanceof CheckboxSearchField) {
CheckBox checkbox = (CheckBox) v.findViewById(R.id.checkbox);
query.put(field.getId(), String.valueOf(checkbox.isChecked()));
}
}
return query;
}
use of de.geeksfactory.opacclient.searchfields.TextSearchField in project opacclient by opacapp.
the class WebOpacNet method parseSearchFields.
@Override
public List<SearchField> parseSearchFields() throws IOException, JSONException {
List<SearchField> fields = new ArrayList<>();
// Text fields
String html = httpGet(opac_url + "/de/mobile/default.aspx", getDefaultEncoding());
Document doc = Jsoup.parse(html);
Elements options = doc.select("#drpOptSearchT option");
for (Element option : options) {
TextSearchField field = new TextSearchField();
field.setDisplayName(option.text());
field.setId(option.attr("value"));
field.setData(new JSONObject("{\"filter\":false}"));
field.setHint("");
fields.add(field);
}
// Dropdowns
String text = httpGet(opac_url + "/de/mobile/GetRestrictions.ashx", getDefaultEncoding());
JSONArray filters = new JSONObject(text).getJSONArray("restrcontainers");
for (int i = 0; i < filters.length(); i++) {
JSONObject filter = filters.getJSONObject(i);
if (filter.getString("querytyp").equals("EJ")) {
// Querying by year also works for other years than the ones
// listed
// -> Make it a text field instead of a dropdown
TextSearchField field = new TextSearchField();
field.setDisplayName(filter.getString("kopf"));
field.setId(filter.getString("querytyp"));
field.setData(new JSONObject("{\"filter\":true}"));
field.setHint("");
fields.add(field);
} else {
DropdownSearchField field = new DropdownSearchField();
field.setId(filter.getString("querytyp"));
field.setDisplayName(filter.getString("kopf"));
JSONArray restrictions = filter.getJSONArray("restrictions");
field.addDropdownValue("", "Alle");
for (int j = 0; j < restrictions.length(); j++) {
JSONObject restriction = restrictions.getJSONObject(j);
field.addDropdownValue(restriction.getString("id"), restriction.getString("bez"));
}
field.setData(new JSONObject("{\"filter\":true}"));
fields.add(field);
}
}
return fields;
}
use of de.geeksfactory.opacclient.searchfields.TextSearchField in project opacclient by opacapp.
the class WinBiap method parseSearchFields.
@Override
public List<SearchField> parseSearchFields() throws IOException {
// extract branches and categories
String html = httpGet(opac_url + "/search.aspx", getDefaultEncoding());
Document doc = Jsoup.parse(html);
Elements mediaGroupOptions = doc.select("[id$=ListBoxMediagroups_ListBoxMultiselection] option");
Elements branchOptions = doc.select("[id$=MultiSelectionBranch_ListBoxMultiselection] option");
final DropdownSearchField mediaGroups = new DropdownSearchField(KEY_SEARCH_QUERY_CATEGORY, "Mediengruppe", false, null);
mediaGroups.setMeaning(Meaning.CATEGORY);
final DropdownSearchField branches = new DropdownSearchField(KEY_SEARCH_QUERY_BRANCH, "Zweigstelle", false, null);
branches.setMeaning(Meaning.BRANCH);
mediaGroups.addDropdownValue("", "Alle");
branches.addDropdownValue("", "Alle");
for (Element option : mediaGroupOptions) {
mediaGroups.addDropdownValue(option.attr("value"), option.text());
}
for (Element option : branchOptions) {
branches.addDropdownValue(option.attr("value"), option.text());
}
List<SearchField> searchFields = new ArrayList<>();
SearchField field = new TextSearchField(KEY_SEARCH_QUERY_FREE, "", false, false, "Beliebig", true, false);
field.setMeaning(Meaning.FREE);
searchFields.add(field);
field = new TextSearchField(KEY_SEARCH_QUERY_AUTHOR, "Autor", false, false, "Nachname, Vorname", false, false);
field.setMeaning(Meaning.AUTHOR);
searchFields.add(field);
field = new TextSearchField(KEY_SEARCH_QUERY_TITLE, "Titel", false, false, "Stichwort", false, false);
field.setMeaning(Meaning.TITLE);
searchFields.add(field);
field = new TextSearchField(KEY_SEARCH_QUERY_KEYWORDA, "Schlagwort", true, false, "", false, false);
field.setMeaning(Meaning.KEYWORD);
searchFields.add(field);
field = new TextSearchField(KEY_SEARCH_QUERY_AUDIENCE, "Interessenkreis", true, false, "", false, false);
field.setMeaning(Meaning.AUDIENCE);
searchFields.add(field);
field = new TextSearchField(KEY_SEARCH_QUERY_SYSTEM, "Systematik", true, false, "", false, false);
field.setMeaning(Meaning.SYSTEM);
searchFields.add(field);
field = new BarcodeSearchField(KEY_SEARCH_QUERY_ISBN, "Strichcode", false, false, "ISBN");
field.setMeaning(Meaning.ISBN);
searchFields.add(field);
field = new TextSearchField(KEY_SEARCH_QUERY_PUBLISHER, "Verlag", false, false, "", false, false);
field.setMeaning(Meaning.PUBLISHER);
searchFields.add(field);
field = new BarcodeSearchField(KEY_SEARCH_QUERY_BARCODE, "Strichcode", false, true, "Mediennummer");
field.setMeaning(Meaning.BARCODE);
searchFields.add(field);
field = new TextSearchField(KEY_SEARCH_QUERY_YEAR_RANGE_START, "Jahr", false, false, "von", false, true);
field.setMeaning(Meaning.YEAR);
searchFields.add(field);
field = new TextSearchField(KEY_SEARCH_QUERY_YEAR_RANGE_END, "Jahr", false, true, "bis", false, true);
field.setMeaning(Meaning.YEAR);
searchFields.add(field);
searchFields.add(branches);
searchFields.add(mediaGroups);
return searchFields;
}
use of de.geeksfactory.opacclient.searchfields.TextSearchField in project opacclient by opacapp.
the class Zones method parseSearchFields.
@Override
public List<SearchField> parseSearchFields() throws IOException {
if (!initialised)
start();
List<SearchField> fields = new ArrayList<>();
String html = httpGet(opac_url + "/APS_ZONES?fn=AdvancedSearch&Style=Portal3&SubStyle=&Lang=GER" + "&ResponseEncoding=utf-8", getDefaultEncoding());
Document doc = Jsoup.parse(html);
// find text fields
Elements txt_opts = doc.select("#formSelectTerm_1 option");
for (Element opt : txt_opts) {
TextSearchField field = new TextSearchField();
field.setId(opt.attr("value"));
field.setHint("");
field.setDisplayName(opt.text());
fields.add(field);
}
// find filters
String filtersQuery = version18 ? ".inSearchLimits .floatingBox" : ".TabRechAv .limitBlock";
Elements filters = doc.select(filtersQuery);
int i = 0;
for (Element filter : filters) {
DropdownSearchField dropdown = new DropdownSearchField();
dropdown.addDropdownValue("", "Alle");
// All dropdowns use "q.limits.limit" as URL param, but they must not have the same ID
dropdown.setId("dropdown_" + i);
if (version18) {
dropdown.setDisplayName(filter.select("tr").get(0).text().trim());
Elements opts = filter.select("tr").get(1).select("table td:has(input)");
for (Element opt : opts) {
dropdown.addDropdownValue(opt.select("input").attr("value"), opt.text().trim());
}
} else {
dropdown.setDisplayName(filter.parent().previousElementSibling().text().trim());
Elements opts = filter.select(".limitChoice label");
for (Element opt : opts) {
dropdown.addDropdownValue(opt.attr("for"), opt.text().trim());
}
}
fields.add(dropdown);
i++;
}
return fields;
}
use of de.geeksfactory.opacclient.searchfields.TextSearchField in project opacclient by opacapp.
the class Zones method addParameters.
private int addParameters(SearchQuery query, List<NameValuePair> params, int index) {
if (query.getValue().equals("")) {
return index;
}
if (query.getSearchField() instanceof TextSearchField) {
if (index != 1) {
params.add(new BasicNameValuePair(".form.t" + index + ".logic", "and"));
}
params.add(new BasicNameValuePair("q.form.t" + index + ".term", query.getKey()));
params.add(new BasicNameValuePair("q.form.t" + index + ".expr", query.getValue()));
return index + 1;
} else if (query.getSearchField() instanceof DropdownSearchField) {
params.add(new BasicNameValuePair("q.limits.limit", query.getValue()));
}
return index;
}
Aggregations