Search in sources :

Example 1 with Select

use of web.Select in project common by zenlunatics.

the class EnumRenderer method writeInput.

// --------------------------------------------------------------------------
@SuppressWarnings("rawtypes")
@Override
public boolean writeInput(View view, Form form, ColumnBase<?> column, View.Mode mode, String default_value, Request request) throws IOException {
    ArrayList<String> names_list = new ArrayList<String>();
    for (Object e : m_type.getEnumConstants()) names_list.add(((Enum) e).name());
    String[] names = names_list.toArray(new String[names_list.size()]);
    String[] values = new String[names_list.size()];
    for (int i = 0; i < names.length; i++) {
        values[i] = m_type.getName() + "." + names[i];
        names[i] = names[i].toLowerCase().replace('_', ' ');
    }
    Select select = new Select(column.getName(), names, values);
    if (mode == View.Mode.EDIT_FORM) {
        String value = view.data().getString(column.getName());
        if (value != null)
            select.setSelectedOption(value.substring(value.lastIndexOf('.') + 1).toLowerCase().replace('_', ' '), value);
    }
    select.write(request);
    return true;
}
Also used : ArrayList(java.util.ArrayList) Select(web.Select)

Example 2 with Select

use of web.Select in project common by zenlunatics.

the class PicturesView method writePictures.

// --------------------------------------------------------------------------
private void writePictures() throws IOException {
    m_view_def.getFrom();
    Person user = m_request.getUser();
    m_writer.write("<table width=\"100%\">");
    // if (m_state.filter != null) {
    // if (m_state.filter.indexOf("tags") != -1) {
    // m_select_from = from + " JOIN " + from + "_" + from + "_tags ON " + from + ".id=" + from + "_" + from + "_tags." + from + "_id";
    // m_writer.write("<tr><td style=\"text-align:center;font-size:x-large\">");
    // m_writer.write(m_request.db.lookupString("tag", m_view_def.getName() + "_tags", Integer.parseInt(m_state.filter.substring(m_state.filter.indexOf('=') + 1))));
    // m_writer.write("</td></tr>");
    // //				setSelectRelationships(true);
    // } else {
    // m_writer.write("<tr><td style=\"text-align:center\">posted by <span style=\"font-size:x-large\">");
    // m_writer.write(m_request.site.lookupName(Integer.parseInt(m_state.filter.substring(m_state.filter.indexOf('=') + 1)), m_request.db));
    // m_writer.write("</span></td></tr>");
    // }
    // m_writer.write("<tr><td style=\"text-align:center\">");
    // m_writer.aButtonOnClick("view all pictures", "XHR_post(context+'/db','db_cmd=clear_filter&db_view_def=pictures',function(){c_(this).replace();}.bind(this))");
    // m_writer.write("</td></tr>");
    // }
    m_writer.write("<tr><td><div class=\"well well-sm\">");
    m_writer.addStyle("float:right");
    writeButtonAdd();
    int rwc_id = writeRowWindowControlsSpan();
    m_writer.write(" posted by: ");
    StringBuilder query = new StringBuilder("SELECT DISTINCT people.id,first || ' ' || last AS name FROM people JOIN pictures ON people.id=pictures._owner_");
    if (m_where != null)
        query.append(" WHERE ").append(m_where);
    query.append(" ORDER BY 2");
    Select select = new RowsSelect(null, query.toString(), "name", "id", m_request).addFirstOption("Anyone", "").setOnChange("var self=this;var v=this.options[this.selectedIndex].value;XHR_post(context+'/ViewStates/pictures',v?'filter=_owner_='+v:'filter=',function(){c_(self).replace(context + '/Views/pictures?db_mode=" + View.Mode.LIST + "');})");
    String filter = getState().filter;
    if (filter != null) {
        int index = filter.indexOf("_owner_");
        if (index != -1)
            if (filter.charAt(index + 7) == '=')
                select.setSelectedOption(null, filter.substring(index + 8));
            else
                select.setSelectedOption(null, "null");
    }
    select.write(m_request);
    m_writer.write(" tagged: ");
    query = new StringBuilder("SELECT DISTINCT ON(lower(tag)) pictures_tags.id,tag FROM pictures_tags JOIN pictures_pictures_tags ON pictures_tags.id=pictures_pictures_tags.pictures_tags_id JOIN pictures ON pictures_pictures_tags.pictures_id=pictures.id");
    if (m_where != null)
        query.append(" WHERE ").append(m_where);
    query.append(" ORDER BY lower(tag)");
    select = new RowsSelect(null, query.toString(), "tag", "id", m_request).addFirstOption("Any", "").setOnChange("var self=this;var v=this.options[this.selectedIndex].value;XHR_post(context+'/ViewStates/pictures',v?'filter=EXISTS(SELECT 1 FROM pictures_pictures_tags WHERE pictures_id=pictures.id AND pictures_tags_id='+v+')':'filter=',function(){c_(self).replace(context + '/Views/pictures?db_mode=" + View.Mode.LIST + "');})");
    filter = getState().filter;
    if (filter != null && filter.startsWith("EXISTS")) {
        int index = filter.lastIndexOf('=');
        if (index != -1)
            select.setSelectedOption(null, filter.substring(index + 1, filter.length() - 1));
        else
            select.setSelectedOption(null, "null");
    }
    select.write(m_request);
    m_writer.write("</div></td></tr></table>");
    setAddOneColumns(false);
    select();
    skip();
    m_writer.write("<table style=\"width:100%\"><tr>");
    while (next()) {
        String row = Integer.toString(m_data.getRow() - 1);
        if (m_num_rows % 5 == 0)
            m_writer.write("</tr><tr>");
        m_writer.write("<td align=\"center\" valign=\"bottom\"><table><tr><td align=\"center\">");
        m_writer.setAttribute("id", "pic" + row);
        m_writer.aOnClickOpen("Gallery.open(" + row + ")");
        m_writer.write("<div class=\"gallery_img\">").img("thumbs/" + m_data.getString("file"), m_pictures_url).write("</div>");
        m_writer.tagClose();
        m_writer.write("</td></tr><tr><td align=\"center\">");
        m_writer.write(m_data.getString("caption"));
        if (m_view_def.getAccessPolicy().showEditButtonForRow(this, m_request) || user != null && user.isAdministrator()) {
            m_writer.br();
            m_writer.addStyle("cursor:pointer");
            m_writer.setAttribute("onclick", "Gallery.rotate('counterclockwise'," + row + ")");
            m_writer.img("gallery/rotate_counterclockwise.png");
            m_writer.space();
            m_writer.addStyle("cursor:pointer");
            m_writer.setAttribute("onclick", "Gallery.rotate('clockwise'," + row + ")");
            m_writer.img("gallery/rotate_clockwise.png");
            m_writer.space();
            writeButtons();
        }
        m_writer.write("</td></tr></table></td>");
        ++m_num_rows;
        if (isRowWindowLast())
            break;
    }
    m_writer.write("</tr>");
    m_writer.write("</table>");
    writeRowWindowControls(rwc_id);
    m_writer.scriptOpen();
    ArrayList<String> ids = writeFiles();
    String show_picture_id = m_request.getParameter("db_key_value");
    if (show_picture_id != null) {
        int show_picture_index = -1;
        for (int i = 0, n = ids.size(); i < n; i++) if (ids.get(i).equals(show_picture_id)) {
            show_picture_index = i;
            break;
        }
        if (show_picture_index != -1) {
            m_writer.write("Gallery.open(");
            m_writer.write(show_picture_index);
            String db_comment_id = m_request.getParameter("db_comment_id");
            if (db_comment_id != null) {
                m_writer.write(',');
                m_writer.write(db_comment_id);
            }
            m_writer.write(");");
        }
    }
    m_writer.scriptClose();
}
Also used : RowsSelect(db.RowsSelect) Select(web.Select) RowsSelect(db.RowsSelect) Person(app.Person)

Example 3 with Select

use of web.Select in project common by zenlunatics.

the class MenuItemsInputRenderer method writeInput.

// --------------------------------------------------------------------------
@Override
public boolean writeInput(View view, Form form, ColumnBase<?> column, View.Mode mode, String default_value, Request request) throws IOException {
    HTMLWriter writer = request.writer;
    if (mode == View.Mode.ADD_FORM) {
        writer.jsFunction("handle_menu_choice", "s", "if(s.selectedIndex==s.options.length-1){" + "s.style.display='none';" + "$('hidden_name').setProperty('name','');" + "$('name_input').setProperty('name','name');" + "$('hidden_name').style.display='none';" + "$('hidden_url').setProperty('name','');" + "$('url_input').setProperty('name','url');" + "$('hidden_url').style.display='none';" + "$('miir').style.display='';" + "}else{" + "$('hidden_name').value=s.options[s.selectedIndex].text;" + "$('hidden_url').value=s.options[s.selectedIndex].value;" + "}");
        writer.write("<table id=\"miir\" border=\"0\" style=\"display:none\"><tr><td class=\"form_label\">name</td><td>");
        writer.setAttribute("id", "name_input");
        writer.textInput(null, "30", null);
        writer.write("</td></tr><tr><td class=\"form_label\">url</td><td>");
        writer.setAttribute("id", "url_input");
        writer.textInput(null, null, null);
        writer.write("</tr></table>");
        writer.setAttribute("id", "hidden_name");
        Page page = m_all_pages.iterator().next();
        writer.hiddenInput("name", page.getName());
        writer.setAttribute("id", "hidden_url");
        writer.hiddenInput("url", page.getURL());
        new Select(null, m_all_pages).setOnChange("handle_menu_choice(this)").write(request);
    } else {
        writer.write("<table border=\"0\"><tr><td class=\"form_label\">name</td><td>");
        writer.textInput("name", "30", view.data().getString("name"));
        writer.write("</td></tr><tr><td class=\"form_label\">url</td><td>");
        writer.textInput("url", null, view.data().getString("url"));
        writer.write("</tr></table>");
    }
    return true;
}
Also used : HTMLWriter(web.HTMLWriter) Select(web.Select) Page(app.Page)

Example 4 with Select

use of web.Select in project common by zenlunatics.

the class Admin method writeColumnForm.

// --------------------------------------------------------------------------
private void writeColumnForm(String table, JDBCColumn jdbc_column, Request request) throws IOException {
    HTMLWriter writer = request.writer;
    web.Form form = new web.Form(null, null, writer).setButtonsLocation(web.Form.Location.NONE).open();
    writer.hiddenInput("table", table);
    if (jdbc_column == null) {
        writer.hiddenInput("action", "column_add");
        form.rowOpen("name");
        writer.write("<input type=\"text\" name=\"column\" />");
    } else {
        writer.hiddenInput("action", "set column type");
        writer.hiddenInput("column", jdbc_column.name);
    }
    form.rowOpen("type");
    Select types = new Select("type", JDBCColumn.types);
    if (jdbc_column != null)
        types.setSelectedOption(jdbc_column.type_name, null);
    types.write(request);
    form.rowOpen("size");
    if (jdbc_column != null && jdbc_column.type_name.endsWith("char") && jdbc_column.size > 0 && jdbc_column.size < 1000)
        writer.textInput("size", "3", Integer.toString(jdbc_column.size));
    else
        writer.textInput("size", "3", null);
    if (jdbc_column == null) {
        form.rowOpen("references");
        new Select("reftable", request.db.getTableNames(false)).setAllowNoSelection(true).write(request);
    }
    form.close();
}
Also used : HTMLWriter(web.HTMLWriter) Form(db.Form) Select(web.Select)

Example 5 with Select

use of web.Select in project common by zenlunatics.

the class ReminderWhenColumn method writeInput.

// --------------------------------------------------------------------------
@Override
protected void writeInput(Mode mode, String default_value, View view, Form form, Request request) throws IOException {
    HTMLWriter writer = request.writer;
    boolean can_repeat = m_always_can_repeat;
    if (m_events_can_repeat && !can_repeat) {
        int one_id;
        if (mode == Mode.ADD_FORM) {
            ViewState state = (ViewState) request.getState(ViewState.class, m_event_provider_name);
            one_id = Integer.parseInt(state.key_value);
        } else
            one_id = view.data().getInt(m_event_table + "_id");
        String repeat = request.db.lookupString(new db.Select("repeat").from(m_event_table).whereIdEquals(one_id));
        can_repeat = repeat != null && !repeat.equals("never");
    }
    int num = 0;
    if (mode != Mode.ADD_FORM)
        num = view.data().getInt("num");
    boolean on_the_day = mode == Mode.ADD_FORM || "day".equals(view.data().getString("unit")) && num == 0;
    String id = UUID.randomUUID().toString();
    writer.setAttribute("id", id);
    writer.select("num", (String[]) null, null).space();
    if (m_events_have_time)
        new Select("unit", num == 1 ? new String[] { "day", "hour", "minute", "week" } : new String[] { "days", "hours", "minutes", "weeks" }, new String[] { "day", "hour", "minute", "week" }).setSelectedOption(null, mode == Mode.ADD_FORM ? "day" : view.data().getString("unit")).write(request);
    else
        new Select("unit", num == 1 ? new String[] { "day", "week" } : new String[] { "days", "weeks" }, new String[] { "day", "week" }).setSelectedOption(null, mode == Mode.ADD_FORM ? "day" : view.data().getString("unit")).write(request);
    writer.space();
    String on_the_day_label = can_repeat ? "on the day of" : "on the day";
    new Select("before", new String[] { on_the_day_label, "before", "after" }, new String[] { on_the_day_label, "true", "false" }).setSelectedOption(on_the_day ? on_the_day_label : mode == Mode.ADD_FORM ? "before" : view.data().getBoolean("before") ? "before" : "after", null).write(request);
    if (can_repeat)
        writer.space().select("repeat_days", new String[] { "each event", "first event", "last event" }, mode == Mode.ADD_FORM ? "each event" : view.data().getString("repeat_days"));
    writer.js("new ReminderWhen('" + id + "'," + (mode == Mode.ADD_FORM ? 0 : view.data().getInt("num")) + ");");
}
Also used : HTMLWriter(web.HTMLWriter) Select(web.Select) ViewState(db.ViewState)

Aggregations

Select (web.Select)6 HTMLWriter (web.HTMLWriter)4 Page (app.Page)1 Person (app.Person)1 Form (db.Form)1 RowsSelect (db.RowsSelect)1 ViewState (db.ViewState)1 AccessPolicy (db.access.AccessPolicy)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 SelectOption (web.SelectOption)1