Search in sources :

Example 96 with HTMLWriter

use of web.HTMLWriter 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)

Example 97 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class FileManager method writeFileEditor.

// --------------------------------------------------------------------------
private void writeFileEditor(String file, Request request) throws IOException {
    HTMLWriter writer = request.writer;
    web.Form form = new web.Form("edit file", null, writer);
    form.open();
    writer.hiddenInput("action", "write file");
    writer.hiddenInput("file", file);
    writer.setAttribute("id", "data");
    writer.setAttribute("name", "data");
    writer.setAttribute("style", "width:100%;height:100%;");
    writer.tagOpen("textarea");
    writer.write(new File(request.site.getBaseFilePath().append(file).toString()), true);
    writer.tagClose();
    writer.js("code_mirror('data','" + (file.endsWith("css") ? "css" : file.endsWith("js") ? "javascript" : "xml") + "',true);");
    form.close();
}
Also used : HTMLWriter(web.HTMLWriter) File(java.io.File)

Example 98 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class FileManager method write.

// --------------------------------------------------------------------------
public void write(Request request) throws IOException {
    HTMLWriter writer = request.writer;
    writer.setAttribute("id", "upload");
    writer.aOnClickOpen("var d=prompt('enter directory name');if(d)new Request.HTML({method:'post',url:context+'/FileManager/'+fm_dir,onComplete:function(){change_dir(fm_dir==''?d:fm_dir+'/'+d);}}).send('action=mkdir&dir='+d);");
    writer.setAttribute("style", "padding-right:3px;margin-bottom:-2px;");
    writer.img("folder.png").write("Create Directory").tagClose();
    writer.nbsp();
    writer.aOnClickOpen("dialog_upload(context+'/FileManager/'+fm_dir,function(){$('fm').replace();},{action:'upload'})");
    writer.setAttribute("style", "padding-right:3px;margin-bottom:-2px;");
    writer.img("upload.png").write("Upload").tagClose();
    writer.hr();
    writer.js("var fm_dir='';");
    writer.write("<div id=\"fm\">");
    writeDirectory("", request);
    writer.write("</div>");
    writer.scriptOpen();
    writer.jsFunction("change_dir", "dir", "fm_dir=dir;$('fm').replace(context+'/FileManager'+(fm_dir==''?'':'/'+fm_dir),dir);");
    writer.write("Asset.css(context+'/codemirror-3.21/lib/codemirror.css');Asset.css(context+'/codemirror-3.21/css/codemirror-ui.css');Asset.javascript(context+'/codemirror-3.21/lib/codemirror.js');Asset.javascript(context+'/codemirror-3.21/mode/xml/xml.js');Asset.javascript(context+'/codemirror-3.21/js/codemirror-ui.js');Asset.javascript(context+'/codemirror-3.21/mode/javascript/javascript.js');Asset.javascript(context+'/codemirror-3.21/mode/css/css.js');");
    writer.scriptClose();
}
Also used : HTMLWriter(web.HTMLWriter)

Example 99 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class Module method writeAdminPane.

// --------------------------------------------------------------------------
public void writeAdminPane(String[] column_names, boolean show_tasks, boolean show_object, Request request) throws IOException {
    HTMLWriter writer = request.writer;
    try {
        writeSettingsForm(column_names, false, request);
        if (show_tasks) {
            boolean first = true;
            Class<?> c = getClass();
            Map<String, Method> methods = new TreeMap<String, Method>();
            for (Method method : c.getMethods()) if (method.isAnnotationPresent(AdminTask.class))
                methods.put(method.getName(), method);
            for (Method method : methods.values()) {
                boolean has_form;
                try {
                    c.getMethod(method.getName() + "Form", Request.class);
                    has_form = true;
                } catch (NoSuchMethodException e) {
                    has_form = false;
                }
                if (!has_form)
                    for (Class<?> type : method.getParameterTypes()) if (type == boolean.class || type == int.class || type == float.class || type == String.class || type == Calendar.class) {
                        has_form = true;
                        break;
                    }
                if (first) {
                    writer.h3("Tasks");
                    writer.tagOpen("table");
                    writer.write("<tr><td style=\"vertical-align:top;\">");
                    first = false;
                }
                writer.tagOpen("p");
                if (has_form)
                    writer.aOnClick(method.getName() + "...", "this.ancestor('td').getNext().replace('admin?action=get_method_form&module=" + m_name + "&method=" + method.getName() + "')");
                else
                    writer.aOnClick(method.getName(), "var td=this.ancestor('td').getNext();td.empty();new Request.HTML({url:context+'/admin',method:'post',data:'method=" + method.getName() + "&module=" + m_name + "',evalScripts:true,update:td}).send();");
                writer.tagClose();
            }
            if (!first) {
                writer.write("</td><td id=\"form_td\" style=\"vertical-align:top;\"></td></tr>");
                writer.tagClose();
            }
        }
        if (show_object) {
            writer.h3("Object");
            DBObject.write(this, writer);
        }
    } catch (SecurityException e) {
        throw new RuntimeException(e);
    }
}
Also used : HTMLWriter(web.HTMLWriter) Calendar(java.util.Calendar) Method(java.lang.reflect.Method) AdminTask(web.AdminTask) TreeMap(java.util.TreeMap)

Example 100 with HTMLWriter

use of web.HTMLWriter in project common by zenlunatics.

the class Person method write.

// --------------------------------------------------------------------------
public static void write(int id, String name, String picture, boolean keep_space, int max_size, Request request) throws IOException {
    HTMLWriter writer = request.writer;
    boolean logged_in = request.getUser() != null;
    if (logged_in) {
        writer.setAttribute("style", "text-decoration:none");
        writer.aOnClickOpen("new Dialog({url:context+'/People/" + id + "'})");
    }
    if (picture != null)
        writer.write("<img src=\"").write(request.getContext()).write("/people/").write(id).write("/").write(picture).write("\" style=\"max-height:").write(max_size).write("px;max-width:").write(max_size).write("px;\" />&nbsp;");
    else if (keep_space)
        writer.write("<div style=\"display:inline-block;width:").write(max_size).write("px;\">&nbsp;</div>&nbsp;");
    writer.write(name);
    if (logged_in)
        writer.tagClose();
}
Also used : HTMLWriter(web.HTMLWriter)

Aggregations

HTMLWriter (web.HTMLWriter)109 Select (db.Select)18 SQLException (java.sql.SQLException)16 ResultSet (java.sql.ResultSet)14 Table (web.Table)12 JDBCTable (db.JDBCTable)10 Person (app.Person)7 Calendar (java.util.Calendar)7 ArrayList (java.util.ArrayList)6 JDBCColumn (db.JDBCColumn)5 View (db.View)5 DBObject (db.DBObject)4 Form (db.Form)4 File (java.io.File)4 AdminTask (web.AdminTask)4 FilePathStringBuilder (web.FilePathStringBuilder)4 Select (web.Select)4 Mode (db.View.Mode)3 IOException (java.io.IOException)3 NumberFormat (java.text.NumberFormat)3