Search in sources :

Example 1 with JDBCColumn

use of db.JDBCColumn in project common by zenlunatics.

the class MailLists method init.

// --------------------------------------------------------------------------
@Override
public void init(DBConnection db) {
    JDBCTable table_def = new JDBCTable().add(new JDBCColumn("active", Types.BOOLEAN).setDefaultValue(true)).add(new JDBCColumn("allow_from_outside", Types.BOOLEAN).setDefaultValue(false)).add(new JDBCColumn("allow_from_outside_subscribers", Types.BOOLEAN).setDefaultValue(false)).add(new JDBCColumn("announce_only", Types.BOOLEAN)).add(new JDBCColumn("archive", Types.BOOLEAN).setDefaultValue(true)).add(new JDBCColumn("archives_public", Types.BOOLEAN).setDefaultValue(true)).add(new JDBCColumn("footer", Types.VARCHAR)).add(new JDBCColumn("host", Types.VARCHAR)).add(new JDBCColumn("name", Types.VARCHAR)).add(new JDBCColumn("password", Types.VARCHAR)).add(new JDBCColumn("send_to", Types.VARCHAR)).add(new JDBCColumn("store_on_disk", Types.BOOLEAN)).add(new JDBCColumn("username", Types.VARCHAR));
    db.getTable("mail_lists", true).createMissingColumns(table_def, db).dropExtraColumns(table_def, db);
    db.createManyToManyLinkTable("mail_lists", "people");
    db.createTable("mail_lists_digest", false, "mail_lists_id INTEGER REFERENCES mail_lists ON DELETE CASCADE,people_id INTEGER REFERENCES people ON DELETE CASCADE", null, false);
    db.createManyTable("mail_lists", "subscribers", "email VARCHAR(60)");
    table_def = new JDBCTable().add(new JDBCColumn("people")).add(new JDBCColumn("email", Types.VARCHAR, 60));
    db.getTable("additional_emails", true).createMissingColumns(table_def, db).dropExtraColumns(table_def, db);
    Roles.add("mail", m_site, db);
    m_site.addUserDropdownItem(new Page("Edit Mail Lists", m_site) {

        @Override
        public void write(Request request) throws IOException {
            request.site.writePageOpen("Edit Mail Lists", request);
            request.site.newView("mail_lists", request).writeComponent();
            request.close();
        }
    }.setRole("mail"), db);
}
Also used : JDBCTable(db.JDBCTable) Request(app.Request) JDBCColumn(db.JDBCColumn) Page(app.Page)

Example 2 with JDBCColumn

use of db.JDBCColumn in project common by zenlunatics.

the class ColumnBase method writeInputWithDropdown.

// --------------------------------------------------------------------------
protected static void writeInputWithDropdown(String name, List<String> values, View view, String default_value, Request request) throws IOException {
    JDBCColumn jdbc_column = request.db.getTable(view.getViewDef().getFrom()).getColumn(name);
    HTMLWriter writer = request.writer;
    // flex display is to prevent firefox from expanding div to 100% width
    writer.write("<div class=\"input-group\" style=\"display:flex\">");
    String id = UUID.randomUUID().toString();
    writer.setAttribute("id", id);
    if (values.size() > 0)
        writer.setAttribute("onkeyup", "fill_choice(this,$(this).getNext().getElement('ul'))");
    writer.textInput(name, Integer.toString(jdbc_column.size), getValue(jdbc_column, default_value, view, request));
    if (values.size() > 0) {
        Dropdown dropdown = new Dropdown(null, "dropdown-toggle", request.writer).setDivClass("input-group-btn").setDropdownMenuRight(true).open();
        for (String value : values) dropdown.aOnClick(value, "$(this).ancestor('DIV').getPrevious().value=this.get('text');");
        dropdown.close();
    }
    writer.write("</div>");
}
Also used : HTMLWriter(web.HTMLWriter) Dropdown(web.Dropdown) JDBCColumn(db.JDBCColumn)

Example 3 with JDBCColumn

use of db.JDBCColumn in project common by zenlunatics.

the class ColumnBase method writeInput.

// --------------------------------------------------------------------------
// normally other column types override this method
protected void writeInput(Mode mode, String default_value, View view, Form form, Request request) throws IOException {
    JDBCColumn jdbc_column = request.db.getTable(view.getViewDef().getFrom()).getColumn(m_name);
    HTMLWriter writer = request.writer;
    if (jdbc_column != null && jdbc_column.isBoolean()) {
        writer.write("<div class=\"checkbox\" style=\"margin:0;min-height:0;padding-top:0;\"><label style=\"margin:0;\"");
        if (m_title != null)
            writer.writeAttribute("title", m_title);
        writer.write('>');
        writer.checkbox(m_name, null, null, mode == View.Mode.EDIT_FORM && view.data().getBoolean(m_name) || mode == View.Mode.ADD_FORM && ("yes".equals(default_value) || "true".equals(default_value)), true);
        writer.hiddenInput("db_boolean" + writer.newID(), m_name);
        writer.space();
        writeLabel(request);
        writer.write("</label></div>");
    } else {
        if (m_title != null)
            writer.setAttribute("title", m_title);
        writeInput(m_name, default_value, view, request);
    }
}
Also used : HTMLWriter(web.HTMLWriter) JDBCColumn(db.JDBCColumn)

Example 4 with JDBCColumn

use of db.JDBCColumn in project common by zenlunatics.

the class ColumnBase method _init_.

// --------------------------------------------------------------------------
public static void _init_(DBConnection db) {
    JDBCTable table_def = new JDBCTable().add(new JDBCColumn("_views_")).add(new JDBCColumn("type", Types.VARCHAR)).add(new JDBCColumn("type_args", Types.VARCHAR));
    DBObject.addColumns(table_def, ColumnBase.class);
    db.getTable("_columns_", true).createMissingColumns(table_def, db).dropExtraColumns(table_def, db);
}
Also used : JDBCTable(db.JDBCTable) JDBCColumn(db.JDBCColumn)

Example 5 with JDBCColumn

use of db.JDBCColumn in project common by zenlunatics.

the class Documents method _newViewDef.

// --------------------------------------------------------------------------
@Override
public ViewDef _newViewDef(String name, Site site) {
    if (name.equals("documents")) {
        ViewDef view_def = new ViewDef(name);
        view_def.setAccessPolicy(new RoleAccessPolicy("docs").add().delete().edit());
        view_def.setCenter(false);
        view_def.setDefaultOrderBy("title");
        view_def.setDialogModes(View.Mode.ADD_FORM, View.Mode.EDIT_FORM, View.Mode.READ_ONLY_FORM);
        view_def.setRecordName("Document");
        view_def.setRichTextEditId("db_filename_text");
        view_def.setShowDoneLink(true);
        view_def.setTimestampRecords(true);
        ArrayList<String> column_names = new ArrayList<String>();
        column_names.add("title");
        column_names.add("type");
        column_names.add("filename");
        if (m_extra_columns != null)
            for (JDBCColumn column : m_extra_columns) column_names.add(column.name);
        view_def.setColumnNamesForm(column_names.toArray(new String[column_names.size()]));
        view_def.setColumnNamesTable(new String[] { "filename" });
        FileColumn file_column = new FileColumn("filename", view_def, "documents").setTitleColumn("title");
        if (m_dir_column != null)
            file_column.setDirColumn(m_dir_column);
        view_def.setColumn(file_column.setDisplayName("document").setPrintUrl("/Documents?db_key_value="));
        view_def.setColumn(new Column("title").setIsRequired(true).setOrderBy("lower(title)"));
        view_def.setColumn(((Options) site.getObjects("documents_types")).newColumn("type"));
        return addHooks(view_def);
    }
    if (name.equals("documents_types"))
        return site.getObjects(name).newViewDef(name, site).setRecordName("Type").setShowNumRecords(false).setColumn(new Column("text").setIsRequired(true));
    return null;
}
Also used : FileColumn(db.column.FileColumn) JDBCColumn(db.JDBCColumn) Column(db.column.Column) ArrayList(java.util.ArrayList) JDBCColumn(db.JDBCColumn) ViewDef(db.ViewDef) RoleAccessPolicy(db.access.RoleAccessPolicy) FileColumn(db.column.FileColumn)

Aggregations

JDBCColumn (db.JDBCColumn)20 JDBCTable (db.JDBCTable)14 Select (db.Select)5 HTMLWriter (web.HTMLWriter)4 Page (app.Page)3 Request (app.Request)3 ViewDef (db.ViewDef)3 NameValuePairs (db.NameValuePairs)2 Options (db.Options)2 RoleAccessPolicy (db.access.RoleAccessPolicy)2 Column (db.column.Column)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 Pages (app.Pages)1 LinkValueRenderer (db.LinkValueRenderer)1 ManyToMany (db.ManyToMany)1 AccessPolicy (db.access.AccessPolicy)1 RecordOwnerAccessPolicy (db.access.RecordOwnerAccessPolicy)1 FileColumn (db.column.FileColumn)1