Search in sources :

Example 16 with DropdownSearchField

use of de.geeksfactory.opacclient.searchfields.DropdownSearchField in project opacclient by opacapp.

the class SearchFragment method loadQuery.

public void loadQuery(Bundle query) {
    if (query == null) {
        return;
    }
    for (SearchField field : fields) {
        if (!field.isVisible()) {
            continue;
        }
        ViewGroup v = (ViewGroup) view.findViewWithTag(field.getId());
        if (v == null) {
            continue;
        }
        if (field instanceof TextSearchField) {
            EditText text;
            if (((TextSearchField) field).isFreeSearch()) {
                text = etSimpleSearch;
            } else {
                text = (EditText) v.findViewById(R.id.edittext);
            }
            text.setText(query.getString(field.getId()));
        } else if (field instanceof BarcodeSearchField) {
            EditText text = (EditText) v.findViewById(R.id.edittext);
            text.setText(query.getString(field.getId()));
        } else if (field instanceof DropdownSearchField) {
            Spinner spinner = (Spinner) v.findViewById(R.id.spinner);
            int i = 0;
            if (((DropdownSearchField) field).getDropdownValues() == null) {
                continue;
            }
            for (DropdownSearchField.Option map : ((DropdownSearchField) field).getDropdownValues()) {
                if (map.getKey().equals(query.getString(field.getId()))) {
                    spinner.setSelection(i);
                    break;
                }
                i++;
            }
        } else if (field instanceof CheckboxSearchField) {
            CheckBox checkbox = (CheckBox) v.findViewById(R.id.checkbox);
            checkbox.setChecked(Boolean.valueOf(query.getString(field.getId())));
        }
    }
    if (barcodeScanningField != null && scanResult != null) {
        ViewGroup v = (ViewGroup) view.findViewWithTag(barcodeScanningField);
        EditText text = (EditText) v.findViewById(R.id.edittext);
        text.setText(scanResult.getContents());
        barcodeScanningField = null;
        scanResult = null;
    }
}
Also used : EditText(android.widget.EditText) BarcodeSearchField(de.geeksfactory.opacclient.searchfields.BarcodeSearchField) SearchField(de.geeksfactory.opacclient.searchfields.SearchField) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) CheckboxSearchField(de.geeksfactory.opacclient.searchfields.CheckboxSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField) CheckboxSearchField(de.geeksfactory.opacclient.searchfields.CheckboxSearchField) BarcodeSearchField(de.geeksfactory.opacclient.searchfields.BarcodeSearchField) ViewGroup(android.view.ViewGroup) Spinner(android.widget.Spinner) CheckBox(android.widget.CheckBox) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField)

Example 17 with DropdownSearchField

use of de.geeksfactory.opacclient.searchfields.DropdownSearchField in project opacclient by opacapp.

the class Littera method addAdvancedSearchFields.

protected void addAdvancedSearchFields(List<SearchField> fields) throws IOException, JSONException {
    final String html = httpGet(getApiUrl() + "&mode=a", getDefaultEncoding());
    final Document doc = Jsoup.parse(html);
    final Elements options = doc.select("select#adv_search_crit_0").first().select("option");
    for (final Element option : options) {
        final SearchField field;
        if (SEARCH_FIELDS_FOR_DROPDOWN.contains(option.val())) {
            field = new DropdownSearchField();
            addDropdownValuesForField(((DropdownSearchField) field), option.val());
        } else {
            field = new TextSearchField();
            ((TextSearchField) field).setHint("");
        }
        field.setDisplayName(option.text());
        field.setId(option.val());
        field.setData(new JSONObject());
        field.getData().put("meaning", field.getId());
        fields.add(field);
    }
}
Also used : TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField) SearchField(de.geeksfactory.opacclient.searchfields.SearchField) JSONObject(org.json.JSONObject) Element(org.jsoup.nodes.Element) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField)

Example 18 with DropdownSearchField

use of de.geeksfactory.opacclient.searchfields.DropdownSearchField in project opacclient by opacapp.

the class Littera method addSortingSearchFields.

protected void addSortingSearchFields(List<SearchField> fields) throws IOException, JSONException {
    final String html = httpGet(getApiUrl() + "&mode=a", getDefaultEncoding());
    final Document doc = Jsoup.parse(html);
    for (int i = 0; i < 3; i++) {
        final Element tr = doc.select("#sort_editor tr.sort_" + i).first();
        final DropdownSearchField field = new DropdownSearchField();
        field.setMeaning(SearchField.Meaning.ORDER);
        field.setId("sort_" + i);
        field.setDisplayName(tr.select("td").first().text());
        field.addDropdownValue("", "");
        for (final Element option : tr.select(".crit option")) {
            if (option.hasAttr("selected")) {
                field.addDropdownValue(0, option.attr("value"), option.text());
            } else {
                field.addDropdownValue(option.attr("value"), option.text());
            }
        }
        fields.add(field);
    }
}
Also used : Element(org.jsoup.nodes.Element) Document(org.jsoup.nodes.Document) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField)

Example 19 with DropdownSearchField

use of de.geeksfactory.opacclient.searchfields.DropdownSearchField in project opacclient by opacapp.

the class Pica method addParameters.

protected int addParameters(SearchQuery query, List<NameValuePair> params, int index) throws JSONException {
    if (query.getValue().equals("") || query.getValue().equals("false")) {
        return index;
    }
    if (query.getSearchField() instanceof TextSearchField || query.getSearchField() instanceof BarcodeSearchField) {
        if (query.getSearchField().getData().getBoolean("ADI")) {
            params.add(new BasicNameValuePair(query.getKey(), query.getValue()));
        } else {
            if (index == 0) {
                params.add(new BasicNameValuePair("ACT" + index, "SRCH"));
            } else {
                params.add(new BasicNameValuePair("ACT" + index, "*"));
            }
            params.add(new BasicNameValuePair("IKT" + index, query.getKey()));
            params.add(new BasicNameValuePair("TRM" + index, query.getValue()));
            return index + 1;
        }
    } else if (query.getSearchField() instanceof CheckboxSearchField) {
        boolean checked = Boolean.valueOf(query.getValue());
        if (checked) {
            params.add(new BasicNameValuePair(query.getKey(), "Y"));
        }
    } else if (query.getSearchField() instanceof DropdownSearchField) {
        params.add(new BasicNameValuePair(query.getKey(), query.getValue()));
    }
    return index;
}
Also used : CheckboxSearchField(de.geeksfactory.opacclient.searchfields.CheckboxSearchField) BarcodeSearchField(de.geeksfactory.opacclient.searchfields.BarcodeSearchField) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField)

Example 20 with DropdownSearchField

use of de.geeksfactory.opacclient.searchfields.DropdownSearchField in project opacclient by opacapp.

the class SISIS method parseDropdown.

private void parseDropdown(Element dropdownElement, List<SearchField> fields) throws JSONException {
    Elements options = dropdownElement.select("option");
    DropdownSearchField dropdown = new DropdownSearchField();
    if (dropdownElement.parent().select("input[type=hidden]").size() > 0) {
        dropdown.setId(dropdownElement.parent().select("input[type=hidden]").attr("value"));
        dropdown.setData(new JSONObject("{\"restriction\": true}"));
    } else {
        dropdown.setId(dropdownElement.attr("name"));
        dropdown.setData(new JSONObject("{\"restriction\": false}"));
    }
    for (Element option : options) {
        dropdown.addDropdownValue(option.attr("value"), option.text());
    }
    dropdown.setDisplayName(dropdownElement.parent().select("label").text());
    fields.add(dropdown);
}
Also used : JSONObject(org.json.JSONObject) Element(org.jsoup.nodes.Element) Elements(org.jsoup.select.Elements) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField)

Aggregations

DropdownSearchField (de.geeksfactory.opacclient.searchfields.DropdownSearchField)32 TextSearchField (de.geeksfactory.opacclient.searchfields.TextSearchField)27 SearchField (de.geeksfactory.opacclient.searchfields.SearchField)21 Element (org.jsoup.nodes.Element)21 ArrayList (java.util.ArrayList)17 Document (org.jsoup.nodes.Document)17 Elements (org.jsoup.select.Elements)16 BarcodeSearchField (de.geeksfactory.opacclient.searchfields.BarcodeSearchField)13 CheckboxSearchField (de.geeksfactory.opacclient.searchfields.CheckboxSearchField)10 JSONObject (org.json.JSONObject)10 ViewGroup (android.view.ViewGroup)6 Spinner (android.widget.Spinner)6 SearchQuery (de.geeksfactory.opacclient.searchfields.SearchQuery)6 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)6 CheckBox (android.widget.CheckBox)5 EditText (android.widget.EditText)5 Matcher (java.util.regex.Matcher)4 Pattern (java.util.regex.Pattern)4 NotReachableException (de.geeksfactory.opacclient.networking.NotReachableException)3 NameValuePair (org.apache.http.NameValuePair)3