Search in sources :

Example 1 with LinkValueRenderer

use of db.LinkValueRenderer in project common by zenlunatics.

the class Pictures method _newViewDef.

// --------------------------------------------------------------------------
@Override
public ViewDef _newViewDef(String name, Site site) {
    if (name.equals(m_table)) {
        ViewDef view_def = new ViewDef(name) {

            @Override
            public View newView(Request p) {
                return new PicturesView(this, m_where, p);
            }

            @Override
            public void afterInsert(NameValuePairs name_value_pairs, int row_id, Request request) {
                ViewState.setFilter(m_name, null, request);
                super.afterInsert(name_value_pairs, row_id, request);
            }
        };
        view_def.setAccessPolicy(new RecordOwnerAccessPolicy().add().delete().edit());
        view_def.setCenter(false);
        view_def.setDefaultOrderBy("_timestamp_ DESC");
        view_def.setDialogModes(View.Mode.ADD_FORM, View.Mode.EDIT_FORM);
        view_def.setOnDelete("document.location=document.location");
        view_def.setOnSuccessAfter("XHR_post(context+'/db','db_cmd=clear_filter&db_view_def=pictures',function(){var p=$('c_pictures');if(p)p.replace();}.bind(this))");
        view_def.setRecordName("Picture");
        view_def.setRowWindowSize(25);
        view_def.setTimestampRecords(true);
        ArrayList<String> columns = new ArrayList<String>();
        columns.add("file");
        columns.add("caption");
        columns.add("tags");
        for (JDBCColumn column : m_additional_columns) columns.add(column.name);
        view_def.setColumnNamesForm(columns.toArray(new String[columns.size()]));
        view_def.setColumnNamesFormTable(new String[] { "caption" });
        PictureColumn picture_column = new PictureColumn("file", view_def, m_table, m_thumb_size, 1024).setSizeIsMaxSide(false);
        if (m_base_file_path != null)
            picture_column.setBaseFilePath(m_base_file_path);
        view_def.setColumn(picture_column.setGenerateFileNames(true).setIsRequired(true));
        view_def.setColumn(new TagsColumn("tags", "pictures", view_def));
        view_def.setColumn(new LookupColumn("_owner_", "people", "first,last").setOnClick("XHR_post(context+'/ViewStates/pictures','filter=_owner_=", "',function(){$('c_pictures').replace(context + '/Views/pictures?db_mode=" + View.Mode.LIST + "');Gallery.close();})"));
        view_def.addRelationshipDef(new ManyToMany(m_table + "_tags", m_table + "_" + m_table + "_tags", "tag").setManyTableColumn("tag").setShowOnForm(false));
        view_def.getViewTheme().setDeleteImg("delete.png").setEditImg("pencil.png");
        return addHooks(view_def);
    }
    if (name.equals(m_table + " add"))
        return _newViewDef(m_table, site).setFrom(m_table).setName(m_table + " add").setOnSuccessAfter(null);
    if (name.equals(m_table + " owners"))
        return new ViewDef(name).setAccessPolicy(new AccessPolicy()).setFrom(m_table + " JOIN people ON people.id=" + m_table + "._owner_").setDefaultOrderBy("first,last").setShowColumnHeads(false).setShowHead(false).setCenter(false).setColumnNamesTable(new String[] { "_owner_" }).setColumn(new Column("_owner_").setValueRenderer(new LinkValueRenderer().setHrefColumn("_owner_").setOnClick("XHR_post(context+'/ViewStates/pictures','filter=_owner_=", "',function(){$('c_pictures').replace(context + '/Views/pictures?db_mode=" + View.Mode.LIST + "');})").setValueRenderer(new MultiColumnRenderer(new String[] { "first", "last" }, true, false)), false));
    if (// for nav list
    name.equals(m_table + " tags"))
        return new ViewDef(name) {

            @Override
            public View newView(Request request) {
                return super.newView(request).setSelectDistinct(true, "tag");
            }
        }.setAccessPolicy(new AccessPolicy()).setDefaultOrderBy("lower(tag)").setFrom(m_table + "_tags").setRecordName("Tag").setShowColumnHeads(false).setShowHead(false).setCenter(false).setColumnNamesTable(new String[] { "tag" }).setColumn(new Column("tag").setValueRenderer(new LinkValueRenderer().setHrefColumn("id").setOnClick("XHR_post(context+'/ViewStates/pictures','filter=pictures_tags_id=", "',function(){$('c_pictures').replace(context + '/Views/pictures?db_mode=" + View.Mode.LIST + "');})").setTextColumn("tag"), false));
    if (name.equals(m_table + "_tags"))
        return new ViewDef(name).setDefaultOrderBy("lower(tag)").setRecordName("Tag").setColumn(new Column("tag").setValueRenderer(new LinkValueRenderer().setHrefColumn("id").setOnClick("XHR_post(context+'/ViewStates/pictures','filter=pictures_tags_id=", "',function(){$('c_pictures').replace(context + '/Views/pictures?db_mode=" + View.Mode.LIST + "');Gallery.close();})").setTextColumn("tag"), false));
    return null;
}
Also used : LinkValueRenderer(db.LinkValueRenderer) NameValuePairs(db.NameValuePairs) Request(app.Request) ArrayList(java.util.ArrayList) ManyToMany(db.ManyToMany) JDBCColumn(db.JDBCColumn) ViewDef(db.ViewDef) AccessPolicy(db.access.AccessPolicy) RecordOwnerAccessPolicy(db.access.RecordOwnerAccessPolicy) RecordOwnerAccessPolicy(db.access.RecordOwnerAccessPolicy) LookupColumn(db.column.LookupColumn) JDBCColumn(db.JDBCColumn) LookupColumn(db.column.LookupColumn) PictureColumn(db.column.PictureColumn) Column(db.column.Column) PictureColumn(db.column.PictureColumn) MultiColumnRenderer(db.column.MultiColumnRenderer)

Example 2 with LinkValueRenderer

use of db.LinkValueRenderer in project common by zenlunatics.

the class Surveys method write.

// ----------------------------------------------------------------------
public static void write(Request request) throws IOException {
    int take_survey_id = request.getInt("take", 0);
    int view_survey_id = request.getInt("view", 0);
    if (take_survey_id != 0)
        new Survey(take_survey_id, request.db).setPageNum(0, request).writeForm(request);
    else if (view_survey_id != 0 && request.db.lookupBoolean(new Select("show_answers").from("surveys").whereIdEquals(view_survey_id)))
        new Survey(view_survey_id, request.db).writeAnswers(request);
    else
        request.site.newView("surveys", request).setColumn(new Column("view").setDisplayName("").setValueRenderer(new LinkValueRenderer().setNamesAndValuesColumns(new String[] { "view" }, new String[] { "id" }).setText("view answers"), false)).writeComponent();
}
Also used : LinkValueRenderer(db.LinkValueRenderer) LookupColumn(db.column.LookupColumn) BooleanColumn(db.column.BooleanColumn) Column(db.column.Column) TextAreaColumn(db.column.TextAreaColumn) Select(db.Select)

Example 3 with LinkValueRenderer

use of db.LinkValueRenderer in project common by zenlunatics.

the class Surveys method _newViewDef.

// ----------------------------------------------------------------------
@Override
public ViewDef _newViewDef(String name, Site site) {
    if (name.startsWith("survey_answers"))
        return newAnswersViewDef(name, site);
    if (name.equals("survey_questions")) {
        ViewDef view_def = new ViewDef(name) {

            @Override
            public int insert(NameValuePairs name_value_pairs, Request request) {
                combineValues(name_value_pairs);
                int id = super.insert(name_value_pairs, request);
                String answer_table = "survey_answers" + name_value_pairs.getString("surveys_id");
                if (request.db.tableExists(answer_table)) {
                    addAnswerTableColumn(answer_table, Integer.toString(id), name_value_pairs.getString("answer_type"), name_value_pairs.getString("type_data"), request.db);
                    request.releaseViewDef(answer_table);
                }
                return id;
            }

            @Override
            public void update(int id, NameValuePairs name_value_pairs, Request request) {
                request.releaseViewDef("survey_answers" + request.db.lookupString("surveys_id", "survey_questions", id));
                combineValues(name_value_pairs);
                super.update(id, name_value_pairs, request);
            }
        };
        view_def.addFormHook(new FormHook() {

            @Override
            public void after(View view, View.Mode mode, boolean printer_friendly, Request p) throws IOException {
                p.writer.js("update_answer_type();");
            }
        });
        view_def.setReorderable(new Reorderable());
        view_def.setRecordName("Question");
        view_def.setColumnNamesForm(new String[] { "answer_type", "question", "pre_text", "post_text", "required" });
        view_def.setColumnNamesTable(new String[] { "answer_type", "question", "required" });
        view_def.setColumn(new Column("answer_type").setInputAndValueRenderers(new AnswerTypeRenderer(), false));
        view_def.setColumn(new Column("pre_text").setDisplayName("text before input"));
        view_def.setColumn(new Column("post_text").setDisplayName("text after input"));
        view_def.setColumn(new Column("question").setDisplayName("question text"));
        return view_def;
    }
    if (name.equals("surveys"))
        return new ViewDef(name).setAccessPolicy(new RecordOwnerAccessPolicy().add().delete().edit()).setDefaultOrderBy("title").setRecordName(m_record_name).setColumnNamesForm(new String[] { "title", "description", "number_questions", "one_answer", "show_answers", "show_names", "show_title" }).setColumnNamesTable(new String[] { "title" }).setColumn(new BooleanColumn("number_questions", true)).setColumn(new BooleanColumn("one_answer", true).setDisplayName("one answer per participant")).setColumn(new BooleanColumn("show_answers", true).setDisplayName("allow participants to see each other's answers").setValueRenderer(new LinkValueRenderer().setNamesAndValuesColumns(new String[] { "view" }, new String[] { "id" }).setShowIfSetColumn("show_answers").setText("view answers"), false)).setColumn(new BooleanColumn("show_names", true).setDisplayName("show participant's names with their answers")).setColumn(new BooleanColumn("show_title", true)).setColumn(new Column("take").setValueRenderer(new LinkValueRenderer().setNamesAndValuesColumns(new String[] { "take" }, new String[] { "id" }).setText("answer questions"), false)).setColumn(new Column("title").setIsRequired(true)).addRelationshipDef(new OneToMany("survey_questions"));
    return null;
}
Also used : LinkValueRenderer(db.LinkValueRenderer) NameValuePairs(db.NameValuePairs) Request(app.Request) BooleanColumn(db.column.BooleanColumn) ViewDef(db.ViewDef) IOException(java.io.IOException) OneToMany(db.OneToMany) View(db.View) RecordOwnerAccessPolicy(db.access.RecordOwnerAccessPolicy) LookupColumn(db.column.LookupColumn) BooleanColumn(db.column.BooleanColumn) Column(db.column.Column) TextAreaColumn(db.column.TextAreaColumn) FormHook(db.FormHook) Reorderable(db.Reorderable)

Example 4 with LinkValueRenderer

use of db.LinkValueRenderer in project common by zenlunatics.

the class Admin method writeAccordion.

// --------------------------------------------------------------------------
private void writeAccordion(Request request) throws IOException {
    Accordion accordion = new Accordion(request.writer);
    accordion.open();
    Collection<Module> modules_list = request.site.getModules();
    accordion.heading("modules");
    // accordion.aOnClick("- add module -", "new_tab('Add Module','get_add_module_form')");
    for (Module module : modules_list) if (module.showOnAdminPage())
        accordion.aOnClick(module.getName(), "new_tab('" + HTMLWriter.escapeJSString(module.getName()) + "','get_module&module=" + HTMLWriter.escapeJSString(module.getName()) + "')");
    Collection<DBObjects<?>> objects_list = request.site.getAllObjects();
    if (objects_list.size() > 0) {
        accordion.heading("objects");
        for (DBObjects<?> objects : objects_list) accordion.aOnClick(objects.getName(), "new_tab('" + HTMLWriter.escapeJSString(objects.getName()) + "','get_object&object=" + HTMLWriter.escapeJSString(objects.getName()) + "')");
    }
    accordion.heading("tables");
    accordion.aOnClick("- create table -", "new_tab('Create Table','get_table_create_form')");
    accordion.aOnClick("- create many to many link table -", "new_tab('Create Many To Many Link Table','get_many_to_many_link_table_create_form')");
    String[] tables = request.db.getTableNames(false);
    if (tables != null)
        for (String table : tables) accordion.aOnClick(table, "new_tab('" + table + "','get_table&table=" + table + "')");
    accordion.heading("table defs");
    accordion.aOnClick("- create table def -", "create_table_def()");
    View table_defs = request.site.newView("_tables_", request);
    table_defs.select();
    if (table_defs.data().isBeforeFirst()) {
        table_defs.setColumn(new Column("name").setValueRenderer(new LinkValueRenderer().setHrefColumn("id").setTextColumn("name").setOnClick("new_tab('<%name%>','get_table_def&db_key_value=", "')"), false));
        writeRows(accordion, table_defs, new String[] { "name" }, request.writer);
    }
    accordion.heading("views");
    accordion.aOnClick("- create view -", "create_view()");
    View views = request.site.newView("_views_", request);
    views.select();
    if (views.data().isBeforeFirst()) {
        views.setColumn(new Column("name").setValueRenderer(new LinkValueRenderer().setHrefColumn("id").setTextColumn("name").setOnClick("new_tab('<%name%>','get_view&db_key_value=", "')"), false));
        writeRows(accordion, views, new String[] { "name" }, request.writer);
    }
    writeAccordionItems(accordion, request.site.getDisplayName(), request.site.getClass());
    Class<?>[] classes = request.site.getClasses();
    if (classes != null)
        for (Class<?> c : classes) writeAccordionItems(accordion, c.getSimpleName() + " tasks", c);
    String display = request.getParameter("display");
    if (display != null)
        if (Character.isDigit(display.charAt(0)))
            accordion.setActiveGroup(Integer.parseInt(display));
        else
            accordion.setActiveGroup(display);
    accordion.close();
}
Also used : LinkValueRenderer(db.LinkValueRenderer) View(db.View) DBObjects(db.DBObjects) Accordion(web.Accordion) JDBCColumn(db.JDBCColumn) LookupColumn(db.column.LookupColumn) Column(db.column.Column) Module(app.Module)

Aggregations

LinkValueRenderer (db.LinkValueRenderer)4 Column (db.column.Column)4 LookupColumn (db.column.LookupColumn)4 Request (app.Request)2 JDBCColumn (db.JDBCColumn)2 NameValuePairs (db.NameValuePairs)2 View (db.View)2 ViewDef (db.ViewDef)2 RecordOwnerAccessPolicy (db.access.RecordOwnerAccessPolicy)2 BooleanColumn (db.column.BooleanColumn)2 TextAreaColumn (db.column.TextAreaColumn)2 Module (app.Module)1 DBObjects (db.DBObjects)1 FormHook (db.FormHook)1 ManyToMany (db.ManyToMany)1 OneToMany (db.OneToMany)1 Reorderable (db.Reorderable)1 Select (db.Select)1 AccessPolicy (db.access.AccessPolicy)1 MultiColumnRenderer (db.column.MultiColumnRenderer)1