Search in sources :

Example 1 with RowsSelect

use of db.RowsSelect 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 2 with RowsSelect

use of db.RowsSelect in project common by zenlunatics.

the class MethodForm method write.

// --------------------------------------------------------------------------
// write generic form based on method parameters
private void write(Method method, Request request) throws IOException {
    HTMLWriter writer = request.writer;
    open(method.getName(), request);
    String[] labels = method.getAnnotation(AdminTask.class).value();
    int label = 0;
    Class<?>[] parameter_types = method.getParameterTypes();
    Table table = new Table(writer);
    for (int i = 0; i < parameter_types.length; i++) if (labels.length > label && labels[label].equals("_owner_")) {
        table.tr().td();
        ++label;
        writer.write("_owner_");
        table.td();
        new RowsSelect("arg" + i, "SELECT id,first,last FROM people ORDER BY first,last", "first,last", "id", request).write(request);
    } else if (parameter_types[i] == boolean.class) {
        table.tr().td().td();
        writer.checkbox("arg" + i, labels.length > label ? labels[label++] : null, null, false, false);
    } else if (parameter_types[i] == Calendar.class) {
        table.tr().td().td();
        writer.dateInput("arg" + i, null);
    } else if (parameter_types[i] == String.class || parameter_types[i] == int.class || parameter_types[i] == float.class) {
        table.tr().td();
        if (labels.length > label)
            writer.write(labels[label++]);
        table.td();
        writer.write("<textarea name=\"arg" + i + "\"></textarea>");
    } else if (parameter_types[i] == FileItem.class) {
        table.tr().td();
        if (labels.length > label)
            writer.write(labels[label++]);
        table.td();
        writer.fileInput("arg" + i);
    }
    table.close();
    close(writer);
}
Also used : FileItem(org.apache.commons.fileupload.FileItem) HTMLWriter(web.HTMLWriter) Table(web.Table) Calendar(java.util.Calendar) AdminTask(web.AdminTask) RowsSelect(db.RowsSelect)

Aggregations

RowsSelect (db.RowsSelect)2 Person (app.Person)1 Calendar (java.util.Calendar)1 FileItem (org.apache.commons.fileupload.FileItem)1 AdminTask (web.AdminTask)1 HTMLWriter (web.HTMLWriter)1 Select (web.Select)1 Table (web.Table)1